1 23 24 package org.enhydra.xml.xmlc.dom.lazydom; 25 26 import org.enhydra.xml.io.DOMFormatter; 27 import org.enhydra.xml.io.Formatter; 28 import org.enhydra.xml.io.HTMLElements; 29 import org.enhydra.xml.io.OutputOptions; 30 import org.enhydra.xml.xmlc.codegen.JavaCode; 31 import org.enhydra.xml.xmlc.dom.XMLCDocument; 32 import org.w3c.dom.Element ; 33 import org.w3c.dom.Node ; 34 35 43 class PreFormatter { 44 45 private Formatter fFormatter; 46 47 48 private boolean fIsHtmlDocument; 49 50 51 private OutputOptions fOptions; 52 53 56 public PreFormatter(XMLCDocument xmlcDoc) { 57 61 fOptions = DOMFormatter.getDefaultOutputOptions(xmlcDoc.getDocument()); 62 String encoding = xmlcDoc.getEncoding(); 63 if (encoding != null) { 64 fOptions.setEncoding(encoding); 65 } 66 67 fIsHtmlDocument = xmlcDoc.isHtmlDocument(); 68 fFormatter = DOMFormatter.getFormatter(xmlcDoc.getDocument(), fOptions, true); 69 } 70 71 76 private boolean isHtmlFormatProtected(Node node) { 77 if (!(node instanceof Element )) { 78 Node parent = node.getParentNode(); 80 while ((parent != null) && (!(parent instanceof Element ))) { 81 parent = parent.getParentNode(); 82 } 83 if ((parent != null) && HTMLElements.isScriptStyle((Element )parent)) { 84 return true; 85 } 86 } 87 return false; 88 } 89 90 95 public String preFormatNode(Node node) { 96 if (fIsHtmlDocument && isHtmlFormatProtected(node)) { 97 return null; 98 } else { 99 return fFormatter.preFormatNode(node); 100 } 101 } 102 103 106 public String getMIMEEncoding() { 107 return fFormatter.getMIMEEncoding(); 108 } 109 110 113 public void createOutputOptionsCodeGenerator(String varName, 114 JavaCode code) { 115 fOptions.createCodeGenerator(varName, true, code); 116 } 117 } 118 | Popular Tags |