| java.lang.Object org.openlaszlo.xml.DataEncoder
DataEncoder | public class DataEncoder implements org.xml.sax.ContentHandler(Code) | | API to compile XML-like data sets to SWF bytecode format.
This class implements the SAX ContentHandler API, and could possibly be used
directly with a SAX Parser, but is designed to be used manually as shown below.
Example usage:
import org.xml.sax.helpers.AttributesImpl;
// send simple row data as node with attributes
InputStream getDataInputStream(Request req, Response resp) {
Connection conn = DriverManager.getConnection(ConnectionPoolManager.URL_PREFIX + alias, null, null);
Statement stmt = conn.createStatement();
ResultSet resultset = stmt.executeQuery("SELECT NAME, AGE, ID FROM EMPLOYEES");
AttributesImpl emptyAttr = new AttributesImpl();
DataEncoder db = new DataEncoder();
db.startDocument();
db.startElement("results", emptyAttr);
while (resultset.next()) {
AttributesImpl attrs = new AttributesImpl();
//Output the values as attributes
attrs.addAttribute("", "name", "", "CDATA", resultset.getString("name"));
attrs.addAttribute("", "age", "", "CDATA", resultset.getString("age"));
attrs.addAttribute("", "id", "", "CDATA", resultset.getString("id"));
db.startElement("row", attrs);
db.endElement();
}
db.endElement();
db.endDocument();
OutputStream out = resp.getOutputStream();
return db.getInputStream();
}
|
Constructor Summary | |
public | DataEncoder() Constructs an empty DataEncoder. | public | DataEncoder(int initsize) Constructs a DataEncoder with a buffer allocation size hint. |
Method Summary | |
public void | _startElement(String localName) A lower level call than startElement(); attributes must be supplied by
individual calls to addAttribute(). | public void | addAttribute(String attrName, String attrVal) A low level call to add an attribute, must be preceded by call to
_startElement() for a given element. | public void | buildFromDocument(Document doc) | public void | buildFromElement(Element e) Build from a DOM Element. | public void | characters(char[] ch, int start, int length) Receive notification of character data. | public void | characters(String text) Receive notification of string data. | public void | endDocument() Receive notification of the end of a document. | public void | endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName) Receive notification of the end of an element. | public void | endElement() Receive notification of the end of an element. | public void | endPrefixMapping(java.lang.String prefix) End the scope of a prefix-URI mapping. | String | getAttributeType(Attribute attr) | public InputStream | getInputStream() Get the compiled data swf program byte codes. | String | getQualifiedName(Attribute attr) | public long | getSize() Return the size of the output object; only valid after endDocument
DataEncoder.endDocument endDocument() has been called. | public void | ignorableWhitespace(char[] ch, int start, int length) Receive notification of ignorable whitespace in element content. | public void | processingInstruction(java.lang.String target, java.lang.String data) Receive notification of a processing instruction. | public void | setDocumentLocator(Locator locator) Receive an object for locating the origin of SAX document events. | public void | skippedEntity(java.lang.String name) Receive notification of a skipped entity. | public void | startDocument() Receive notification of the beginning of a document. | public void | startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, Attributes atts) Receive notification of the beginning of an element. | public void | startElement(java.lang.String localName, Attributes atts) Receive notification of the beginning of an element.
Parameters: localName - the local name (without prefix), or the empty string ifNamespace processing is not being performed. Parameters: atts - the attributes attached to the element. | public void | startPrefixMapping(java.lang.String prefix, java.lang.String uri) Begin the scope of a prefix-URI Namespace mapping. |
mFlashVersion | int mFlashVersion(Code) | | |
DataEncoder | public DataEncoder()(Code) | | Constructs an empty DataEncoder.
|
DataEncoder | public DataEncoder(int initsize)(Code) | | Constructs a DataEncoder with a buffer allocation size hint.
Parameters: initsize - hint to allocate buffer size large enough to hold output. |
_startElement | public void _startElement(String localName)(Code) | | A lower level call than startElement(); attributes must be supplied by
individual calls to addAttribute(). This method is unimplemented.
Parameters: localName - the element name. |
addAttribute | public void addAttribute(String attrName, String attrVal)(Code) | | A low level call to add an attribute, must be preceded by call to
_startElement() for a given element. This method is unimplemented.
|
buildFromDocument | public void buildFromDocument(Document doc) throws DataEncoderException(Code) | | Parse a DOM Document and pass it to DataEncoder via JDOM SAXOutputter
Parameters: doc - DOM Document to build. throws: DataCompilerException - if there was a problem compiling the Document. |
buildFromElement | public void buildFromElement(Element e)(Code) | | Build from a DOM Element.
Parameters: e - DOM Element. |
characters | public void characters(char[] ch, int start, int length)(Code) | | Receive notification of character data.
Parameters: ch - the characters from the XML document. Parameters: start - the start position in the array. Parameters: length - the number of characters to read from the array. See Also: DataEncoder.characters(String) See Also: characters(String) |
endElement | public void endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName)(Code) | | Receive notification of the end of an element. This method is equivalent
to calling
DataEncoder.endElement() endElement() -- the input parameters are
ignored.
Parameters: uri - the Namespace URI, or the empty string if the element has noNamespace URI or if Namespace processing is not being performed. Parameters: localName - the local name (without prefix), or the empty string ifNamespace processing is not being performed. Parameters: qName - the qualified XML 1.0 name (with prefix), or the emptystring if qualified names are not available. See Also: DataEncoder.endElement() See Also: endElement() |
endPrefixMapping | public void endPrefixMapping(java.lang.String prefix)(Code) | | End the scope of a prefix-URI mapping. This method is unimplemented.
Parameters: prefix - the prefix that was being mapped. |
getAttributeType | String getAttributeType(Attribute attr)(Code) | | |
getQualifiedName | String getQualifiedName(Attribute attr)(Code) | | |
ignorableWhitespace | public void ignorableWhitespace(char[] ch, int start, int length)(Code) | | Receive notification of ignorable whitespace in element content. This
method is unimplemented.
Parameters: ch - the characters from the XML document. Parameters: start - the start position in the array. Parameters: length - the number of characters to read from the array. |
processingInstruction | public void processingInstruction(java.lang.String target, java.lang.String data)(Code) | | Receive notification of a processing instruction. This method is
unimplemented.
Parameters: target - the processing instruction target. Parameters: data - the processing instruction data, or null if none wassupplied. The data does not include any whitespace separating it from thetarget. |
setDocumentLocator | public void setDocumentLocator(Locator locator)(Code) | | Receive an object for locating the origin of SAX document events. This
method is unimplemented.
Parameters: locator - an object that can return the location of any SAX documentevent. |
skippedEntity | public void skippedEntity(java.lang.String name)(Code) | | Receive notification of a skipped entity. This method is unimplemented.
Parameters: name - the name of the skipped entity. If it is a parameter entity,the name will begin with '%', and if it is the external DTD subset, itwill be the string "[dtd]". |
startDocument | public void startDocument()(Code) | | Receive notification of the beginning of a document.
See Also: DataEncoder.endDocument() See Also: endDocument() |
startElement | public void startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, Attributes atts)(Code) | | Receive notification of the beginning of an element. This method is
equivalent to calling
DataEncoder.startElement(String,Attributes)startElement(String, Attributes) -- the uri and qName parameters are
ignored.
Parameters: uri - the Namespace URI, or the empty string if the element has noNamespace URI or if Namespace processing is not being performed. Parameters: localName - the local name (without prefix), or the empty string ifNamespace processing is not being performed. Parameters: qName - the qualified name (with prefix), or the empty string ifqualified names are not available. Parameters: atts - the attributes attached to the element. If there are noattributes, it shall be an empty Attributes object. See Also: DataEncoder.startElement(String,Attributes) See Also: startElement(String, Attributes) |
startElement | public void startElement(java.lang.String localName, Attributes atts)(Code) | | Receive notification of the beginning of an element.
Parameters: localName - the local name (without prefix), or the empty string ifNamespace processing is not being performed. Parameters: atts - the attributes attached to the element. If there are noattributes, it shall be an empty Attributes object. See Also: DataEncoder.startElement(String,String,String,Attributes) See Also: startElement(String, String, String, Attributes) |
startPrefixMapping | public void startPrefixMapping(java.lang.String prefix, java.lang.String uri)(Code) | | Begin the scope of a prefix-URI Namespace mapping. This method is
unimplemented.
Parameters: prefix - the Namespace prefix being declared. Parameters: uri - the Namespace URI the prefix is mapped to. |
|
|