01: private Object deserializeFromPacket(String packet)
02: throws Exception
03: {
04: String parser = null;
05: Object obj = null;
06: InputSource source = null;
07: WddxDeserializer deserializer = null;
08:
09: // check incoming argument
10: if(packet == null || packet.length() == 0)
11: {
12: // throw error
13: throw new Exception("The incoming packet is NULL or empty.");
14: }
15:
16: // TODO:
17: // setup configuration code for retrieving other possible SAX parsers
18:
19: // set parser value to internal
20: if(parser == null)
21: {
22: // use default parser
23: parser = this.DEFAULT_SAXPARSER;
24: }
25:
26: // attempt to load the parser for verification it is in CLASSPATH
27: try
28: {
29: Class.forName(parser).newInstance();
30: }
31: catch(Exception e)
32: {
33: throw new Exception("Unable to load SAX parser
class.
The system was unable to load the
required SAX parser classes: " + parser +
".
This might be because it are not in the
ColdFusion Server's Java CLASSPATH setting.
");
34: }
35:
36: // create input source for the XML parser
37: source = new InputSource(new StringReader(packet));
38:
39: // create a WDDX deserializer
40: deserializer = new WddxDeserializer(parser);
41:
42: // deserialize the WDDX packet
43: obj = deserializer.deserialize(source);
44:
45: return obj;
46: }
Listing 2
01: private String serializeToPacket(Object obj)
02: throws Exception
03: {
04: String parser = null;
05: WddxSerializer serializer = new WddxSerializer();
06: StringWriter buffer = new StringWriter();
07:
08: // check incoming argument
09: if(obj == null)
10: {
11: // throw error
12: throw new Exception("The incoming object is null.");
13: }
14:
15: // serialize object
16: serializer.serialize(obj, buffer);
17:
18: return buffer.toString();
19: }
Listing 3
01: <cfparam name="url.sheettype" default="html">
02: <cfset stylesheet =
GetDirectoryFromPath(GetBaseTemplatePath()) &
"booklist.#url.sheettype#.xsl">
03: <cfset booklist =
GetDirectoryFromPath(GetBaseTemplatePath()) &
"booklist.txt">
04: <cffile action="READ" file="#booklist#"
variable="books">
05: <cf_transformation stylesheet="#stylesheet#">
06: <cfoutput>
07: <booklist>
08: <cfloop index="idx" list="#books#">
09: <book>
10: <name>#ListGetAt(idx, 1, "|")#</name>
11: <link>#ListGetAt(idx, 2, "|")#</link>
12: </book>
13: </cfloop>
14: </booklist>
15: </cfoutput>
16: </cf_transformation>
Listing 4
// grab attribute collection
attribAttributesCollection =
request.getAttribute("ATTRIBUTESCOLLECTION", null);
if(attribAttributesCollection == null)
{
throw new Exception("Error! Missing required attribute:
ATTRIBUTESCOLLECTION");
}
mAttributesCollection =
(Hashtable)deserializeFromPacket(attribAttributesCollection);
// retrieve/default the incoming argument
attribStylesheet =
(String)mAttributesCollection.get("STYLESHEET");
attribSource =
(String)mAttributesCollection.get("SOURCE");
attribContent = (String)mAttributesCollection.get
("CONTENT");
attribResult =
(String)mAttributesCollection.get("RESULT");
Additional Code for this Article (~zip file) Strande0303.zip