public void endElement(String namespaceURI, String localName, String qName) throws SAXException { try { charsAdded = false; --indentLevel; if (lastElementClosed) { writePrintln(); indent(); } // XXXX: need to determine this using a stack and checking for // content / children boolean hadContent = true; if (hadContent) { writeClose(qName); } else { writeEmptyElementClose(qName); } lastOutputNodeType = Node.ELEMENT_NODE; lastElementClosed = true; super.endElement(namespaceURI, localName, qName); } catch (IOException e) { handleException(e); } }
public void startDocument() throws SAXException { try { writeDeclaration(); super.startDocument(); } catch (IOException e) { handleException(e); } }
public void startEntity(String name) throws SAXException { try { writeEntityRef(name); } catch (IOException e) { handleException(e); } if (lexicalHandler != null) { lexicalHandler.startEntity(name); } }
public void endCDATA() throws SAXException { try { writer.write("]]>"); } catch (IOException e) { handleException(e); } if (lexicalHandler != null) { lexicalHandler.endCDATA(); } }
public void startCDATA() throws SAXException { try { writer.write("<![CDATA["); } catch (IOException e) { handleException(e); } if (lexicalHandler != null) { lexicalHandler.startCDATA(); } }
// LexicalHandler interface // ------------------------------------------------------------------------- public void startDTD(String name, String publicID, String systemID) throws SAXException { inDTD = true; try { writeDocType(name, publicID, systemID); } catch (IOException e) { handleException(e); } if (lexicalHandler != null) { lexicalHandler.startDTD(name, publicID, systemID); } }
public void characters(char[] ch, int start, int length) throws SAXException { if ((ch == null) || (ch.length == 0) || (length <= 0)) { return; } try { /* * we can't use the writeString method here because it's possible we * don't receive all characters at once and calling writeString * would cause unwanted spaces to be added in between these chunks * of character arrays. */ String string = String.valueOf(ch, start, length); if (escapeText) { string = escapeElementEntities(string); } if (format.isTrimText()) { if ((lastOutputNodeType == Node.TEXT_NODE) && !charsAdded) { writer.write(' '); } else if (charsAdded && Character.isWhitespace(lastChar)) { writer.write(' '); } else if (lastOutputNodeType == Node.ELEMENT_NODE && format.isPadText() && lastElementClosed && Character.isWhitespace(ch[0])) { writer.write(PAD_TEXT); } String delim = ""; StringTokenizer tokens = new StringTokenizer(string); while (tokens.hasMoreTokens()) { writer.write(delim); writer.write(tokens.nextToken()); delim = " "; } } else { writer.write(string); } charsAdded = true; lastChar = ch[(start + length) - 1]; lastOutputNodeType = Node.TEXT_NODE; super.characters(ch, start, length); } catch (IOException e) { handleException(e); } }
public void comment(char[] ch, int start, int length) throws SAXException { if (showCommentsInDTDs || !inDTD) { try { charsAdded = false; writeComment(new String(ch, start, length)); } catch (IOException e) { handleException(e); } } if (lexicalHandler != null) { lexicalHandler.comment(ch, start, length); } }
public void processingInstruction(String target, String data) throws SAXException { try { indent(); writer.write("<?"); writer.write(target); writer.write(" "); writer.write(data); writer.write("?>"); writePrintln(); lastOutputNodeType = Node.PROCESSING_INSTRUCTION_NODE; super.processingInstruction(target, data); } catch (IOException e) { handleException(e); } }
public void startElement( String namespaceURI, String localName, String qName, Attributes attributes) throws SAXException { try { charsAdded = false; writePrintln(); indent(); writer.write("<"); writer.write(qName); writeNamespaces(); writeAttributes(attributes); writer.write(">"); ++indentLevel; lastOutputNodeType = Node.ELEMENT_NODE; lastElementClosed = false; super.startElement(namespaceURI, localName, qName, attributes); } catch (IOException e) { handleException(e); } }