Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   /*      */ package org.dom4j.io;
   /*      */ 
   /*      */ import java.io.BufferedWriter;
   /*      */ import java.io.IOException;
   /*      */ import java.io.OutputStream;
   /*      */ import java.io.OutputStreamWriter;
   /*      */ import java.io.UnsupportedEncodingException;
   /*      */ import java.io.Writer;
   /*      */ import java.util.HashMap;
  /*      */ import java.util.Iterator;
  /*      */ import java.util.List;
  /*      */ import java.util.Map;
  /*      */ import java.util.Map.Entry;
  /*      */ import java.util.Set;
  /*      */ import java.util.StringTokenizer;
  /*      */ import org.dom4j.Attribute;
  /*      */ import org.dom4j.CDATA;
  /*      */ import org.dom4j.Comment;
  /*      */ import org.dom4j.Document;
  /*      */ import org.dom4j.DocumentType;
  /*      */ import org.dom4j.Element;
  /*      */ import org.dom4j.Entity;
  /*      */ import org.dom4j.Namespace;
  /*      */ import org.dom4j.Node;
  /*      */ import org.dom4j.ProcessingInstruction;
  /*      */ import org.dom4j.Text;
  /*      */ import org.dom4j.tree.NamespaceStack;
  /*      */ import org.xml.sax.Attributes;
  /*      */ import org.xml.sax.InputSource;
  /*      */ import org.xml.sax.Locator;
  /*      */ import org.xml.sax.SAXException;
  /*      */ import org.xml.sax.SAXNotRecognizedException;
  /*      */ import org.xml.sax.SAXNotSupportedException;
  /*      */ import org.xml.sax.XMLReader;
  /*      */ import org.xml.sax.ext.LexicalHandler;
  /*      */ import org.xml.sax.helpers.XMLFilterImpl;
  /*      */ 
  /*      */ public class XMLWriter extends XMLFilterImpl
  /*      */   implements LexicalHandler
  /*      */ {
  /*      */   private static final String PAD_TEXT = " ";
  /*   74 */   protected static final String[] LEXICAL_HANDLER_NAMES = { "http://xml.org/sax/properties/lexical-handler""http://xml.org/sax/handlers/LexicalHandler" };
  /*      */ 
  /*   78 */   protected static final OutputFormat DEFAULT_FORMAT = new OutputFormat();
  /*      */ 
  /*   81 */   private boolean resolveEntityRefs = true;
  /*      */   protected int lastOutputNodeType;
  /*   93 */   private boolean lastElementClosed = false;
  /*      */ 
  /*   96 */   protected boolean preserve = false;
  /*      */   protected Writer writer;
  /*  102 */   private NamespaceStack namespaceStack = new NamespaceStack();
  /*      */   private OutputFormat format;
  /*  108 */   private boolean escapeText = true;
  /*      */ 
  /*  114 */   private int indentLevel = 0;
  /*      */ 
  /*  117 */   private StringBuffer buffer = new StringBuffer();
  /*      */ 
  /*  122 */   private boolean charsAdded = false;
  /*      */   private char lastChar;
  /*      */   private boolean autoFlush;
  /*      */   private LexicalHandler lexicalHandler;
  /*      */   private boolean showCommentsInDTDs;
  /*      */   private boolean inDTD;
  /*      */   private Map namespacesMap;
  /*      */   private int maximumAllowedCharacter;
  /*      */ 
  /*      */   public XMLWriter(Writer writer)
  /*      */   {
  /*  152 */     this(writer);
  /*      */   }
  /*      */ 
  /*      */   public XMLWriter(Writer writerOutputFormat format) {
  /*  156 */     this. = writer;
  /*  157 */     this. = format;
  /*  158 */     this..push(.);
  /*      */   }
  /*      */ 
  /*      */   public XMLWriter() {
  /*  162 */     this. = ;
  /*  163 */     this. = new BufferedWriter(new OutputStreamWriter(.));
  /*  164 */     this. = true;
  /*  165 */     this..push(.);
  /*      */   }
  /*      */ 
  /*      */   public XMLWriter(OutputStream outthrows UnsupportedEncodingException {
  /*  169 */     this. = ;
  /*  170 */     this. = createWriter(outthis..getEncoding());
  /*  171 */     this. = true;
  /*  172 */     this..push(.);
  /*      */   }
  /*      */ 
  /*      */   public XMLWriter(OutputStream outOutputFormat formatthrows UnsupportedEncodingException
  /*      */   {
  /*  177 */     this. = format;
  /*  178 */     this. = createWriter(outformat.getEncoding());
  /*  179 */     this. = true;
  /*  180 */     this..push(.);
 /*      */   }
 /*      */ 
 /*      */   public XMLWriter(OutputFormat formatthrows UnsupportedEncodingException {
 /*  184 */     this. = format;
 /*  185 */     this. = createWriter(.format.getEncoding());
 /*  186 */     this. = true;
 /*  187 */     this..push(.);
 /*      */   }
 /*      */ 
 /*      */   public void setWriter(Writer writer) {
 /*  191 */     this. = writer;
 /*  192 */     this. = false;
 /*      */   }
 /*      */ 
 /*      */   public void setOutputStream(OutputStream outthrows UnsupportedEncodingException
 /*      */   {
 /*  197 */     this. = createWriter(outthis..getEncoding());
 /*  198 */     this. = true;
 /*      */   }
 /*      */ 
 /*      */   public boolean isEscapeText()
 /*      */   {
 /*  209 */     return this.;
 /*      */   }
 /*      */ 
 /*      */   public void setEscapeText(boolean escapeText)
 /*      */   {
 /*  221 */     this. = escapeText;
 /*      */   }
 /*      */ 
 /*      */   public void setIndentLevel(int indentLevel)
 /*      */   {
 /*  233 */     this. = indentLevel;
 /*      */   }
 /*      */ 
 /*      */   public int getMaximumAllowedCharacter()
 /*      */   {
 /*  244 */     if (this. == 0) {
 /*  245 */       this. = defaultMaximumAllowedCharacter();
 /*      */     }
 /*      */ 
 /*  248 */     return this.;
 /*      */   }
 /*      */ 
 /*      */   public void setMaximumAllowedCharacter(int maximumAllowedCharacter)
 /*      */   {
 /*  262 */     this. = maximumAllowedCharacter;
 /*      */   }
 /*      */ 
 /*      */   public void flush()
 /*      */     throws IOException
 /*      */   {
 /*  272 */     this..flush();
 /*      */   }
 /*      */ 
 /*      */   public void close()
 /*      */     throws IOException
 /*      */   {
 /*  282 */     this..close();
 /*      */   }
 /*      */ 
 /*      */   public void println()
 /*      */     throws IOException
 /*      */   {
 /*  292 */     this..write(this..getLineSeparator());
 /*      */   }
 /*      */ 
 /*      */   public void write(Attribute attribute)
 /*      */     throws IOException
 /*      */   {
 /*  305 */     writeAttribute(attribute);
 /*      */ 
 /*  307 */     if (this.)
 /*  308 */       flush();
 /*      */   }
 /*      */ 
 /*      */   public void write(Document doc)
 /*      */     throws IOException
 /*      */   {
 /*  335 */     writeDeclaration();
 /*      */ 
 /*  337 */     if (doc.getDocType() != null) {
 /*  338 */       indent();
 /*  339 */       writeDocType(doc.getDocType());
 /*      */     }
 /*      */ 
 /*  342 */     int i = 0; for (int size = doc.nodeCount(); i < sizei++) {
 /*  343 */       Node node = doc.node(i);
 /*  344 */       writeNode(node);
 /*      */     }
 /*      */ 
 /*  347 */     writePrintln();
 /*      */ 
 /*  349 */     if (this.)
 /*  350 */       flush();
 /*      */   }
 /*      */ 
 /*      */   public void write(Element element)
 /*      */     throws IOException
 /*      */   {
 /*  369 */     writeElement(element);
 /*      */ 
 /*  371 */     if (this.)
 /*  372 */       flush();
 /*      */   }
 /*      */ 
 /*      */   public void write(CDATA cdata)
 /*      */     throws IOException
 /*      */   {
 /*  386 */     writeCDATA(cdata.getText());
 /*      */ 
 /*  388 */     if (this.)
 /*  389 */       flush();
 /*      */   }
 /*      */ 
 /*      */   public void write(Comment comment)
 /*      */     throws IOException
 /*      */   {
 /*  403 */     writeComment(comment.getText());
 /*      */ 
 /*  405 */     if (this.)
 /*  406 */       flush();
 /*      */   }
 /*      */ 
 /*      */   public void write(DocumentType docType)
 /*      */     throws IOException
 /*      */   {
 /*  420 */     writeDocType(docType);
 /*      */ 
 /*  422 */     if (this.)
 /*  423 */       flush();
 /*      */   }
 /*      */ 
 /*      */   public void write(Entity entity)
 /*      */     throws IOException
 /*      */   {
 /*  437 */     writeEntity(entity);
 /*      */ 
 /*  439 */     if (this.)
 /*  440 */       flush();
 /*      */   }
 /*      */ 
 /*      */   public void write(Namespace namespace)
 /*      */     throws IOException
 /*      */   {
 /*  454 */     writeNamespace(namespace);
 /*      */ 
 /*  456 */     if (this.)
 /*  457 */       flush();
 /*      */   }
 /*      */ 
 /*      */   public void write(ProcessingInstruction processingInstruction)
 /*      */     throws IOException
 /*      */   {
 /*  472 */     writeProcessingInstruction(processingInstruction);
 /*      */ 
 /*  474 */     if (this.)
 /*  475 */       flush();
 /*      */   }
 /*      */ 
 /*      */   public void write(String text)
 /*      */     throws IOException
 /*      */   {
 /*  492 */     writeString(text);
 /*      */ 
 /*  494 */     if (this.)
 /*  495 */       flush();
 /*      */   }
 /*      */ 
 /*      */   public void write(Text text)
 /*      */     throws IOException
 /*      */   {
 /*  509 */     writeString(text.getText());
 /*      */ 
 /*  511 */     if (this.)
 /*  512 */       flush();
 /*      */   }
 /*      */ 
 /*      */   public void write(Node node)
 /*      */     throws IOException
 /*      */   {
 /*  526 */     writeNode(node);
 /*      */ 
 /*  528 */     if (this.)
 /*  529 */       flush();
 /*      */   }
 /*      */ 
 /*      */   public void write(Object object)
 /*      */     throws IOException
 /*      */   {
 /*  544 */     if ((object instanceof Node)) {
 /*  545 */       write((Node)object);
 /*  546 */     } else if ((object instanceof String)) {
 /*  547 */       write((String)object);
 /*  548 */     } else if ((object instanceof List)) {
 /*  549 */       List list = (List)object;
 /*      */ 
 /*  551 */       int i = 0; for (int size = list.size(); i < sizei++)
 /*  552 */         write(list.get(i));
 /*      */     }
 /*  554 */     else if (object != null) {
 /*  555 */       throw new IOException("Invalid object: " + object);
 /*      */     }
 /*      */   }
 /*      */ 
 /*      */   public void writeOpen(Element element)
 /*      */     throws IOException
 /*      */   {
 /*  572 */     this..write("<");
 /*  573 */     this..write(element.getQualifiedName());
 /*  574 */     writeAttributes(element);
 /*  575 */     this..write(">");
 /*      */   }
 /*      */ 
 /*      */   public void writeClose(Element element)
 /*      */     throws IOException
 /*      */   {
 /*  590 */     writeClose(element.getQualifiedName());
 /*      */   }
 /*      */ 
 /*      */   public void parse(InputSource source)
 /*      */     throws IOExceptionSAXException
 /*      */   {
 /*  596 */     installLexicalHandler();
 /*  597 */     super.parse(source);
 /*      */   }
 /*      */ 
 /*      */   public void setProperty(String nameObject valuethrows SAXNotRecognizedExceptionSAXNotSupportedException
 /*      */   {
 /*  602 */     for (int i = 0; i < .i++) {
 /*  603 */       if ([i].equals(name)) {
 /*  604 */         setLexicalHandler((LexicalHandler)value);
 /*      */ 
 /*  606 */         return;
 /*      */       }
 /*      */     }
 /*      */ 
 /*  610 */     super.setProperty(namevalue);
 /*      */   }
 /*      */ 
 /*      */   public Object getProperty(String namethrows SAXNotRecognizedExceptionSAXNotSupportedException
 /*      */   {
 /*  615 */     for (int i = 0; i < .i++) {
 /*  616 */       if ([i].equals(name)) {
 /*  617 */         return getLexicalHandler();
 /*      */       }
 /*      */     }
 /*      */ 
 /*  621 */     return super.getProperty(name);
 /*      */   }
 /*      */ 
 /*      */   public void setLexicalHandler(LexicalHandler handler) {
 /*  625 */     if (handler == null) {
 /*  626 */       throw new NullPointerException("Null lexical handler");
 /*      */     }
 /*  628 */     this. = handler;
 /*      */   }
 /*      */ 
 /*      */   public LexicalHandler getLexicalHandler()
 /*      */   {
 /*  633 */     return this.;
 /*      */   }
 /*      */ 
 /*      */   public void setDocumentLocator(Locator locator)
 /*      */   {
 /*  639 */     super.setDocumentLocator(locator);
 /*      */   }
 /*      */ 
 /*      */   public void startDocument() throws SAXException {
 /*      */     try {
 /*  644 */       writeDeclaration();
 /*  645 */       super.startDocument();
 /*      */     } catch (IOException e) {
 /*  647 */       handleException(e);
 /*      */     }
 /*      */   }
 /*      */ 
 /*      */   public void endDocument() throws SAXException {
 /*  652 */     super.endDocument();
 /*      */ 
 /*  654 */     if (this.)
 /*      */       try {
 /*  656 */         flush();
 /*      */       }
 /*      */       catch (IOException e)
 /*      */       {
 /*      */       }
 /*      */   }
 /*      */ 
 /*      */   public void startPrefixMapping(String prefixString urithrows SAXException {
 /*  664 */     if (this. == null) {
 /*  665 */       this. = new HashMap();
 /*      */     }
 /*      */ 
 /*  668 */     this..put(prefixuri);
 /*  669 */     super.startPrefixMapping(prefixuri);
 /*      */   }
 /*      */ 
 /*      */   public void endPrefixMapping(String prefixthrows SAXException {
 /*  673 */     super.endPrefixMapping(prefix);
 /*      */   }
 /*      */ 
 /*      */   public void startElement(String namespaceURIString localNameString qNameAttributes attributesthrows SAXException
 /*      */   {
 /*      */     try {
 /*  679 */       this. = false;
 /*      */ 
 /*  681 */       writePrintln();
 /*  682 */       indent();
 /*  683 */       this..write("<");
 /*  684 */       this..write(qName);
 /*  685 */       writeNamespaces();
 /*  686 */       writeAttributes(attributes);
 /*  687 */       this..write(">");
 /*  688 */       this. += 1;
 /*  689 */       this. = 1;
 /*  690 */       this. = false;
 /*      */ 
 /*  692 */       super.startElement(namespaceURIlocalNameqNameattributes);
 /*      */     } catch (IOException e) {
 /*  694 */       handleException(e);
 /*      */     }
 /*      */   }
 /*      */ 
 /*      */   public void endElement(String namespaceURIString localNameString qNamethrows SAXException
 /*      */   {
 /*      */     try {
 /*  701 */       this. = false;
 /*  702 */       this. -= 1;
 /*      */ 
 /*  704 */       if (this.) {
 /*  705 */         writePrintln();
 /*  706 */         indent();
 /*      */       }
 /*      */ 
 /*  711 */       boolean hadContent = true;
 /*      */ 
 /*  713 */       if (hadContent)
 /*  714 */         writeClose(qName);
 /*      */       else {
 /*  716 */         writeEmptyElementClose(qName);
 /*      */       }
 /*      */ 
 /*  719 */       this. = 1;
 /*  720 */       this. = true;
 /*      */ 
 /*  722 */       super.endElement(namespaceURIlocalNameqName);
 /*      */     } catch (IOException e) {
 /*  724 */       handleException(e);
 /*      */     }
 /*      */   }
 /*      */ 
 /*      */   public void characters(char[] chint startint lengththrows SAXException
 /*      */   {
 /*  730 */     if ((ch == null) || (ch.length == 0) || (length <= 0)) {
 /*  731 */       return;
 /*      */     }
 /*      */ 
 /*      */     try
 /*      */     {
 /*  741 */       String string = String.valueOf(chstartlength);
 /*      */ 
 /*  743 */       if (this.) {
 /*  744 */         string = escapeElementEntities(string);
 /*      */       }
 /*      */ 
 /*  747 */       if (this..isTrimText()) {
 /*  748 */         if ((this. == 3) && (!this.))
 /*  749 */           this..write(32);
 /*  750 */         else if ((this.) && (Character.isWhitespace(this.)))
 /*  751 */           this..write(32);
 /*  752 */         else if ((this. == 1) && (this..isPadText()) && (this.) && (Character.isWhitespace(ch[0])))
 /*      */         {
 /*  755 */           this..write(" ");
 /*      */         }
 /*      */ 
 /*  758 */         String delim = "";
 /*  759 */         StringTokenizer tokens = new StringTokenizer(string);
 /*      */ 
 /*  761 */         while (tokens.hasMoreTokens()) {
 /*  762 */           this..write(delim);
 /*  763 */           this..write(tokens.nextToken());
 /*  764 */           delim = " ";
 /*      */         }
 /*      */       } else {
 /*  767 */         this..write(string);
 /*      */       }
 /*      */ 
 /*  770 */       this. = true;
 /*  771 */       this. = ch[(start + length - 1)];
 /*  772 */       this. = 3;
 /*      */ 
 /*  774 */       super.characters(chstartlength);
 /*      */     } catch (IOException e) {
 /*  776 */       handleException(e);
 /*      */     }
 /*      */   }
 /*      */ 
 /*      */   public void ignorableWhitespace(char[] chint startint lengththrows SAXException
 /*      */   {
 /*  782 */     super.ignorableWhitespace(chstartlength);
 /*      */   }
 /*      */ 
 /*      */   public void processingInstruction(String targetString datathrows SAXException
 /*      */   {
 /*      */     try {
 /*  788 */       indent();
 /*  789 */       this..write("<?");
 /*  790 */       this..write(target);
 /*  791 */       this..write(" ");
 /*  792 */       this..write(data);
 /*  793 */       this..write("?>");
 /*  794 */       writePrintln();
 /*  795 */       this. = 7;
 /*      */ 
 /*  797 */       super.processingInstruction(targetdata);
 /*      */     } catch (IOException e) {
 /*  799 */       handleException(e);
 /*      */     }
 /*      */   }
 /*      */ 
 /*      */   public void notationDecl(String nameString publicIDString systemID)
 /*      */     throws SAXException
 /*      */   {
 /*  807 */     super.notationDecl(namepublicIDsystemID);
 /*      */   }
 /*      */ 
 /*      */   public void unparsedEntityDecl(String nameString publicIDString systemIDString notationNamethrows SAXException
 /*      */   {
 /*  812 */     super.unparsedEntityDecl(namepublicIDsystemIDnotationName);
 /*      */   }
 /*      */ 
 /*      */   public void startDTD(String nameString publicIDString systemID)
 /*      */     throws SAXException
 /*      */   {
 /*  819 */     this. = true;
 /*      */     try
 /*      */     {
 /*  822 */       writeDocType(namepublicIDsystemID);
 /*      */     } catch (IOException e) {
 /*  824 */       handleException(e);
 /*      */     }
 /*      */ 
 /*  827 */     if (this. != null)
 /*  828 */       this..startDTD(namepublicIDsystemID);
 /*      */   }
 /*      */ 
 /*      */   public void endDTD() throws SAXException
 /*      */   {
 /*  833 */     this. = false;
 /*      */ 
 /*  835 */     if (this. != null)
 /*  836 */       this..endDTD();
 /*      */   }
 /*      */ 
 /*      */   public void startCDATA() throws SAXException
 /*      */   {
 /*      */     try {
 /*  842 */       this..write("<![CDATA[");
 /*      */     } catch (IOException e) {
 /*  844 */       handleException(e);
 /*      */     }
 /*      */ 
 /*  847 */     if (this. != null)
 /*  848 */       this..startCDATA();
 /*      */   }
 /*      */ 
 /*      */   public void endCDATA() throws SAXException
 /*      */   {
 /*      */     try {
 /*  854 */       this..write("]]>");
 /*      */     } catch (IOException e) {
 /*  856 */       handleException(e);
 /*      */     }
 /*      */ 
 /*  859 */     if (this. != null)
 /*  860 */       this..endCDATA();
 /*      */   }
 /*      */ 
 /*      */   public void startEntity(String namethrows SAXException
 /*      */   {
 /*      */     try {
 /*  866 */       writeEntityRef(name);
 /*      */     } catch (IOException e) {
 /*  868 */       handleException(e);
 /*      */     }
 /*      */ 
 /*  871 */     if (this. != null)
 /*  872 */       this..startEntity(name);
 /*      */   }
 /*      */ 
 /*      */   public void endEntity(String namethrows SAXException
 /*      */   {
 /*  877 */     if (this. != null)
 /*  878 */       this..endEntity(name);
 /*      */   }
 /*      */ 
 /*      */   public void comment(char[] chint startint lengththrows SAXException
 /*      */   {
 /*  883 */     if ((this.) || (!this.)) {
 /*      */       try {
 /*  885 */         this. = false;
 /*  886 */         writeComment(new String(chstartlength));
 /*      */       } catch (IOException e) {
 /*  888 */         handleException(e);
 /*      */       }
 /*      */     }
 /*      */ 
 /*  892 */     if (this. != null)
 /*  893 */       this..comment(chstartlength);
 /*      */   }
 /*      */ 
 /*      */   protected void writeElement(Element element)
 /*      */     throws IOException
 /*      */   {
 /*  900 */     int size = element.nodeCount();
 /*  901 */     String qualifiedName = element.getQualifiedName();
 /*      */ 
 /*  903 */     writePrintln();
 /*  904 */     indent();
 /*      */ 
 /*  906 */     this..write("<");
 /*  907 */     this..write(qualifiedName);
 /*      */ 
 /*  909 */     int previouslyDeclaredNamespaces = this..size();
 /*  910 */     Namespace ns = element.getNamespace();
 /*      */ 
 /*  912 */     if (isNamespaceDeclaration(ns)) {
 /*  913 */       this..push(ns);
 /*  914 */       writeNamespace(ns);
 /*      */     }
 /*      */ 
 /*  918 */     boolean textOnly = true;
 /*      */ 
 /*  920 */     for (int i = 0; i < sizei++) {
 /*  921 */       Node node = element.node(i);
 /*      */ 
 /*  923 */       if ((node instanceof Namespace)) {
 /*  924 */         Namespace additional = (Namespace)node;
 /*      */ 
 /*  926 */         if (isNamespaceDeclaration(additional)) {
 /*  927 */           this..push(additional);
 /*  928 */           writeNamespace(additional);
 /*      */         }
 /*  930 */       } else if ((node instanceof Element)) {
 /*  931 */         textOnly = false;
 /*  932 */       } else if ((node instanceof Comment)) {
 /*  933 */         textOnly = false;
 /*      */       }
 /*      */     }
 /*      */ 
 /*  937 */     writeAttributes(element);
 /*      */ 
 /*  939 */     this. = 1;
 /*      */ 
 /*  941 */     if (size <= 0) {
 /*  942 */       writeEmptyElementClose(qualifiedName);
 /*      */     } else {
 /*  944 */       this..write(">");
 /*      */ 
 /*  946 */       if (textOnly)
 /*      */       {
 /*  949 */         writeElementContent(element);
 /*      */       }
 /*      */       else {
 /*  952 */         this. += 1;
 /*      */ 
 /*  954 */         writeElementContent(element);
 /*      */ 
 /*  956 */         this. -= 1;
 /*      */ 
 /*  958 */         writePrintln();
 /*  959 */         indent();
 /*      */       }
 /*      */ 
 /*  962 */       this..write("</");
 /*  963 */       this..write(qualifiedName);
 /*  964 */       this..write(">");
 /*      */     }
 /*      */ 
 /*  968 */     while (this..size() > previouslyDeclaredNamespaces) {
 /*  969 */       this..pop();
 /*      */     }
 /*      */ 
 /*  972 */     this. = 1;
 /*      */   }
 /*      */ 
 /*      */   protected final boolean isElementSpacePreserved(Element element)
 /*      */   {
 /*  985 */     Attribute attr = element.attribute("space");
 /*  986 */     boolean preserveFound = this.;
 /*      */ 
 /*  988 */     if (attr != null) {
 /*  989 */       if (("xml".equals(attr.getNamespacePrefix())) && ("preserve".equals(attr.getText())))
 /*      */       {
 /*  991 */         preserveFound = true;
 /*      */       }
 /*  993 */       else preserveFound = false;
 /*      */ 
 /*      */     }
 /*      */ 
 /*  997 */     return preserveFound;
 /*      */   }
 /*      */ 
 /*      */   protected void writeElementContent(Element element)
 /*      */     throws IOException
 /*      */   {
 /* 1014 */     boolean trim = this..isTrimText();
 /* 1015 */     boolean oldPreserve = this.;
 /*      */ 
 /* 1017 */     if (trim) {
 /* 1018 */       this. = isElementSpacePreserved(element);
 /* 1019 */       trim = !this.;
 /*      */     }
 /*      */ 
 /* 1022 */     if (trim)
 /*      */     {
 /* 1025 */       Text lastTextNode = null;
 /* 1026 */       StringBuffer buff = null;
 /* 1027 */       boolean textOnly = true;
 /*      */ 
 /* 1029 */       int i = 0; for (int size = element.nodeCount(); i < sizei++) {
 /* 1030 */         Node node = element.node(i);
 /*      */ 
 /* 1032 */         if ((node instanceof Text)) {
 /* 1033 */           if (lastTextNode == null) {
 /* 1034 */             lastTextNode = (Text)node;
 /*      */           } else {
 /* 1036 */             if (buff == null) {
 /* 1037 */               buff = new StringBuffer(lastTextNode.getText());
 /*      */             }
 /*      */ 
 /* 1040 */             buff.append(((Text)node).getText());
 /*      */           }
 /*      */         } else {
 /* 1043 */           if ((!textOnly) && (this..isPadText()))
 /*      */           {
 /* 1046 */             char firstChar = 'a';
 /* 1047 */             if (buff != null)
 /* 1048 */               firstChar = buff.charAt(0);
 /* 1049 */             else if (lastTextNode != null) {
 /* 1050 */               firstChar = lastTextNode.getText().charAt(0);
 /*      */             }
 /*      */ 
 /* 1053 */             if (Character.isWhitespace(firstChar)) {
 /* 1054 */               this..write(" ");
 /*      */             }
 /*      */           }
 /*      */ 
 /* 1058 */           if (lastTextNode != null) {
 /* 1059 */             if (buff != null) {
 /* 1060 */               writeString(buff.toString());
 /* 1061 */               buff = null;
 /*      */             } else {
 /* 1063 */               writeString(lastTextNode.getText());
 /*      */             }
 /*      */ 
 /* 1066 */             if (this..isPadText())
 /*      */             {
 /* 1069 */               char lastTextChar = 'a';
 /* 1070 */               if (buff != null) {
 /* 1071 */                 lastTextChar = buff.charAt(buff.length() - 1);
 /* 1072 */               } else if (lastTextNode != null) {
 /* 1073 */                 String txt = lastTextNode.getText();
 /* 1074 */                 lastTextChar = txt.charAt(txt.length() - 1);
 /*      */               }
 /*      */ 
 /* 1077 */               if (Character.isWhitespace(lastTextChar)) {
 /* 1078 */                 this..write(" ");
 /*      */               }
 /*      */             }
 /*      */ 
 /* 1082 */             lastTextNode = null;
 /*      */           }
 /*      */ 
 /* 1085 */           textOnly = false;
 /* 1086 */           writeNode(node);
 /*      */         }
 /*      */       }
 /*      */ 
 /* 1090 */       if (lastTextNode != null) {
 /* 1091 */         if ((!textOnly) && (this..isPadText()))
 /*      */         {
 /* 1094 */           char firstChar = 'a';
 /* 1095 */           if (buff != null)
 /* 1096 */             firstChar = buff.charAt(0);
 /*      */           else {
 /* 1098 */             firstChar = lastTextNode.getText().charAt(0);
 /*      */           }
 /*      */ 
 /* 1101 */           if (Character.isWhitespace(firstChar)) {
 /* 1102 */             this..write(" ");
 /*      */           }
 /*      */         }
 /*      */ 
 /* 1106 */         if (buff != null) {
 /* 1107 */           writeString(buff.toString());
 /* 1108 */           buff = null;
 /*      */         } else {
 /* 1110 */           writeString(lastTextNode.getText());
 /*      */         }
 /*      */ 
 /* 1113 */         lastTextNode = null;
 /*      */       }
 /*      */     } else {
 /* 1116 */       Node lastTextNode = null;
 /*      */ 
 /* 1118 */       int i = 0; for (int size = element.nodeCount(); i < sizei++) {
 /* 1119 */         Node node = element.node(i);
 /*      */ 
 /* 1121 */         if ((node instanceof Text)) {
 /* 1122 */           writeNode(node);
 /* 1123 */           lastTextNode = node;
 /*      */         } else {
 /* 1125 */           if ((lastTextNode != null) && (this..isPadText()))
 /*      */           {
 /* 1128 */             String txt = lastTextNode.getText();
 /* 1129 */             char lastTextChar = txt.charAt(txt.length() - 1);
 /*      */ 
 /* 1131 */             if (Character.isWhitespace(lastTextChar)) {
 /* 1132 */               this..write(" ");
 /*      */             }
 /*      */           }
 /*      */ 
 /* 1136 */           writeNode(node);
 /*      */ 
 /* 1142 */           lastTextNode = null;
 /*      */         }
 /*      */       }
 /*      */     }
 /*      */ 
 /* 1147 */     this. = oldPreserve;
 /*      */   }
 /*      */ 
 /*      */   protected void writeCDATA(String textthrows IOException {
 /* 1151 */     this..write("<![CDATA[");
 /*      */ 
 /* 1153 */     if (text != null) {
 /* 1154 */       this..write(text);
 /*      */     }
 /*      */ 
 /* 1157 */     this..write("]]>");
 /*      */ 
 /* 1159 */     this. = 4;
 /*      */   }
 /*      */ 
 /*      */   protected void writeDocType(DocumentType docTypethrows IOException {
 /* 1163 */     if (docType != null) {
 /* 1164 */       docType.write(this.);
 /* 1165 */       writePrintln();
 /*      */     }
 /*      */   }
 /*      */ 
 /*      */   protected void writeNamespace(Namespace namespacethrows IOException {
 /* 1170 */     if (namespace != null)
 /* 1171 */       writeNamespace(namespace.getPrefix(), namespace.getURI());
 /*      */   }
 /*      */ 
 /*      */   protected void writeNamespaces()
 /*      */     throws IOException
 /*      */   {
 /* 1182 */     if (this. != null) {
 /* 1183 */       Iterator iter = this..entrySet().iterator();
 /* 1184 */       while (iter.hasNext()) {
 /* 1185 */         Map.Entry entry = (Map.Entry)iter.next();
 /* 1186 */         String prefix = (String)entry.getKey();
 /* 1187 */         String uri = (String)entry.getValue();
 /* 1188 */         writeNamespace(prefixuri);
 /*      */       }
 /*      */ 
 /* 1191 */       this. = null;
 /*      */     }
 /*      */   }
 /*      */ 
 /*      */   protected void writeNamespace(String prefixString uri)
 /*      */     throws IOException
 /*      */   {
 /* 1207 */     if ((prefix != null) && (prefix.length() > 0)) {
 /* 1208 */       this..write(" xmlns:");
 /* 1209 */       this..write(prefix);
 /* 1210 */       this..write("=\"");
 /*      */     } else {
 /* 1212 */       this..write(" xmlns=\"");
 /*      */     }
 /*      */ 
 /* 1215 */     this..write(uri);
 /* 1216 */     this..write("\"");
 /*      */   }
 /*      */ 
 /*      */   protected void writeProcessingInstruction(ProcessingInstruction pi)
 /*      */     throws IOException
 /*      */   {
 /* 1222 */     this..write("<?");
 /* 1223 */     this..write(pi.getName());
 /* 1224 */     this..write(" ");
 /* 1225 */     this..write(pi.getText());
 /* 1226 */     this..write("?>");
 /* 1227 */     writePrintln();
 /*      */ 
 /* 1229 */     this. = 7;
 /*      */   }
 /*      */ 
 /*      */   protected void writeString(String textthrows IOException {
 /* 1233 */     if ((text != null) && (text.length() > 0)) {
 /* 1234 */       if (this.) {
 /* 1235 */         text = escapeElementEntities(text);
 /*      */       }
 /*      */ 
 /* 1243 */       if (this..isTrimText()) {
 /* 1244 */         boolean first = true;
 /* 1245 */         StringTokenizer tokenizer = new StringTokenizer(text);
 /*      */ 
 /* 1247 */         while (tokenizer.hasMoreTokens()) {
 /* 1248 */           String token = tokenizer.nextToken();
 /*      */ 
 /* 1250 */           if (first) {
 /* 1251 */             first = false;
 /*      */ 
 /* 1253 */             if (this. == 3)
 /* 1254 */               this..write(" ");
 /*      */           }
 /*      */           else {
 /* 1257 */             this..write(" ");
 /*      */           }
 /*      */ 
 /* 1260 */           this..write(token);
 /* 1261 */           this. = 3;
 /* 1262 */           this. = token.charAt(token.length() - 1);
 /*      */         }
 /*      */       } else {
 /* 1265 */         this. = 3;
 /* 1266 */         this..write(text);
 /* 1267 */         this. = text.charAt(text.length() - 1);
 /*      */       }
 /*      */     }
 /*      */   }
 /*      */ 
 /*      */   protected void writeNodeText(Node node)
 /*      */     throws IOException
 /*      */   {
 /* 1283 */     String text = node.getText();
 /*      */ 
 /* 1285 */     if ((text != null) && (text.length() > 0)) {
 /* 1286 */       if (this.) {
 /* 1287 */         text = escapeElementEntities(text);
 /*      */       }
 /*      */ 
 /* 1290 */       this. = 3;
 /* 1291 */       this..write(text);
 /* 1292 */       this. = text.charAt(text.length() - 1);
 /*      */     }
 /*      */   }
 /*      */ 
 /*      */   protected void writeNode(Node nodethrows IOException {
 /* 1297 */     int nodeType = node.getNodeType();
 /*      */ 
 /* 1299 */     switch (nodeType) {
 /*      */     case 1:
 /* 1301 */       writeElement((Element)node);
 /*      */ 
 /* 1303 */       break;
 /*      */     case 2:
 /* 1306 */       writeAttribute((Attribute)node);
 /*      */ 
 /* 1308 */       break;
 /*      */     case 3:
 /* 1311 */       writeNodeText(node);
 /*      */ 
 /* 1314 */       break;
 /*      */     case 4:
 /* 1317 */       writeCDATA(node.getText());
 /*      */ 
 /* 1319 */       break;
 /*      */     case 5:
 /* 1322 */       writeEntity((Entity)node);
 /*      */ 
 /* 1324 */       break;
 /*      */     case 7:
 /* 1327 */       writeProcessingInstruction((ProcessingInstruction)node);
 /*      */ 
 /* 1329 */       break;
 /*      */     case 8:
 /* 1332 */       writeComment(node.getText());
 /*      */ 
 /* 1334 */       break;
 /*      */     case 9:
 /* 1337 */       write((Document)node);
 /*      */ 
 /* 1339 */       break;
 /*      */     case 10:
 /* 1342 */       writeDocType((DocumentType)node);
 /*      */ 
 /* 1344 */       break;
 /*      */     case 13:
 /* 1350 */       break;
 /*      */     case 6:
 /*      */     case 11:
 /*      */     case 12:
 /*      */     default:
 /* 1353 */       throw new IOException("Invalid node type: " + node);
/*      */     }
/*      */   }
/*      */ 
/*      */   protected void installLexicalHandler() {
/* 1358 */     XMLReader parent = getParent();
/*      */ 
/* 1360 */     if (parent == null) {
/* 1361 */       throw new NullPointerException("No parent for filter");
/*      */     }
/*      */ 
/* 1365 */     for (int i = 0; i < .i++)
/*      */       try {
/* 1367 */         parent.setProperty([i], this);
/*      */       }
/*      */       catch (SAXNotRecognizedException ex)
/*      */       {
/*      */       }
/*      */       catch (SAXNotSupportedException ex)
/*      */       {
/*      */       }
/*      */   }
/*      */ 
/*      */   protected void writeDocType(String nameString publicIDString systemID)
/*      */     throws IOException
/*      */   {
/* 1380 */     boolean hasPublic = false;
/*      */ 
/* 1382 */     this..write("<!DOCTYPE ");
/* 1383 */     this..write(name);
/*      */ 
/* 1385 */     if ((publicID != null) && (!publicID.equals(""))) {
/* 1386 */       this..write(" PUBLIC \"");
/* 1387 */       this..write(publicID);