throws FOPException {
/* most of this code is modified from John Cowan's */
Node currentNode;
AttributeListImpl currentAtts;
/* temporary array for making Strings into character arrays */
char[] array = null;
currentAtts = new AttributeListImpl();
/* start at the document element */
currentNode = document;
try {
while (currentNode != null) {
switch (currentNode.getNodeType()) {
case Node.DOCUMENT_NODE:
this.treeBuilder.startDocument();
break;
case Node.CDATA_SECTION_NODE:
case Node.TEXT_NODE:
String data = currentNode.getNodeValue();
int datalen = data.length();
if (array == null || array.length < datalen) {
/* if the array isn't big enough, make a new
one */
array = new char[datalen];
}
data.getChars(0, datalen, array, 0);
this.treeBuilder.characters(array, 0, datalen);
break;
case Node.PROCESSING_INSTRUCTION_NODE:
this.treeBuilder.processingInstruction(
currentNode.getNodeName(),
currentNode.getNodeValue());
break;
case Node.ELEMENT_NODE:
NamedNodeMap map = currentNode.getAttributes();
currentAtts.clear();
for (int i = map.getLength() - 1; i >= 0; i--) {
Attr att = (Attr)(map.item(i));
currentAtts.addAttribute(att.getName(),
"CDATA",
att.getValue());
}
this.treeBuilder.startElement(
currentNode.getNodeName(), currentAtts);