![]() |
![]() |
serializer16:52:48.280 INFO jd.cli.Main - Decompiling serializer.jar package org.apache.xml.serializer; import java.util.Hashtable; import org.xml.sax.Attributes; import org.xml.sax.helpers.AttributesImpl; public final class AttributesImplSerializer extends AttributesImpl { private final Hashtable m_indexFromQName = new Hashtable(); private final StringBuffer m_buff = new StringBuffer(); private static final int MAX = 12; private static final int MAXMinus1 = 11; public final int getIndex(String qname) { int index; if (super.getLength() < 12) { index = super.getIndex(qname); return index; } Integer i = (Integer)m_indexFromQName.get(qname); if (i == null) { index = -1; } else { index = i.intValue(); } return index; } public final void addAttribute(String uri, String local, String qname, String type, String val) { int index = super.getLength(); super.addAttribute(uri, local, qname, type, val); if (index < 11) { return; } if (index == 11) { switchOverToHash(12); } else { Integer i = new Integer(index); m_indexFromQName.put(qname, i); m_buff.setLength(0); m_buff.append('{').append(uri).append('}').append(local); String key = m_buff.toString(); m_indexFromQName.put(key, i); } } private void switchOverToHash(int numAtts) { for (int index = 0; index < numAtts; index++) { String qName = super.getQName(index); Integer i = new Integer(index); m_indexFromQName.put(qName, i); String uri = super.getURI(index); String local = super.getLocalName(index); m_buff.setLength(0); m_buff.append('{').append(uri).append('}').append(local); String key = m_buff.toString(); m_indexFromQName.put(key, i); } } public final void clear() { int len = super.getLength(); super.clear(); if (12 <= len) { m_indexFromQName.clear(); } } public final void setAttributes(Attributes atts) { super.setAttributes(atts); int numAtts = atts.getLength(); if (12 <= numAtts) { switchOverToHash(numAtts); } } public final int getIndex(String uri, String localName) { int index; if (super.getLength() < 12) { index = super.getIndex(uri, localName); return index; } m_buff.setLength(0); m_buff.append('{').append(uri).append('}').append(localName); String key = m_buff.toString(); Integer i = (Integer)m_indexFromQName.get(key); if (i == null) { index = -1; } else { index = i.intValue(); } return index; } } /* Location: * Qualified Name: org.apache.xml.serializer.AttributesImplSerializer * Java Class Version: 1.1 (45.3) * JD-Core Version: 0.7.1 */ package org.apache.xml.serializer; import java.security.PrivilegedAction; class CharInfo$1 implements PrivilegedAction { private final String val$entitiesFileName; private final String val$method; private final boolean val$internal; CharInfo$1(String val$entitiesFileName, String val$method, boolean val$internal) { this.val$entitiesFileName = val$entitiesFileName;this.val$method = val$method;this.val$internal = val$internal; } public Object run() { return new CharInfo(val$entitiesFileName, val$method, val$internal, null); } } /* Location: * Qualified Name: org.apache.xml.serializer.CharInfo.1 * Java Class Version: 1.1 (45.3) * JD-Core Version: 0.7.1 */ package org.apache.xml.serializer; class CharInfo$CharKey { private char m_char; public CharInfo$CharKey(char key) { m_char = key; } public CharInfo$CharKey() {} public final void setChar(char c) { m_char = c; } public final int hashCode() { return m_char; } public final boolean equals(Object obj) { return m_char == m_char; } } /* Location: * Qualified Name: org.apache.xml.serializer.CharInfo.CharKey * Java Class Version: 1.1 (45.3) * JD-Core Version: 0.7.1 */ package org.apache.xml.serializer; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.net.URL; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.Enumeration; import java.util.HashMap; import java.util.Hashtable; import java.util.ResourceBundle; import javax.xml.transform.TransformerException; import org.apache.xml.serializer.utils.Messages; import org.apache.xml.serializer.utils.SystemIDResolver; import org.apache.xml.serializer.utils.Utils; import org.apache.xml.serializer.utils.WrappedRuntimeException; final class CharInfo { private HashMap m_charToString; CharInfo(String x0, String x1, boolean x2, 1 x3) { this(x0, x1, x2); } public static final String HTML_ENTITIES_RESOURCE = SerializerBase.PKG_NAME + ".HTMLEntities"; public static final String XML_ENTITIES_RESOURCE = SerializerBase.PKG_NAME + ".XMLEntities"; static final char S_HORIZONAL_TAB = '\t'; static final char S_LINEFEED = '\n'; static final char S_CARRIAGERETURN = '\r'; static final char S_SPACE = ' '; static final char S_QUOTE = '"'; static final char S_LT = '<'; static final char S_GT = '>'; static final char S_NEL = '?'; static final char S_LINE_SEPARATOR = '?'; boolean onlyQuotAmpLtGt; static final int ASCII_MAX = 128; private final boolean[] shouldMapAttrChar_ASCII; private final boolean[] shouldMapTextChar_ASCII; private final int[] array_of_bits; private static final int SHIFT_PER_WORD = 5; private static final int LOW_ORDER_BITMASK = 31; private int firstWordNotUsed; private final CharKey m_charKey; private CharInfo() { array_of_bits = createEmptySetOfIntegers(65535); firstWordNotUsed = 0; shouldMapAttrChar_ASCII = new boolean['?']; shouldMapTextChar_ASCII = new boolean['?']; m_charKey = new CharKey(); onlyQuotAmpLtGt = true; } private CharInfo(String entitiesResource, String method, boolean internal) { this(); m_charToString = new HashMap(); ResourceBundle entities = null; boolean noExtraEntities = true; if (internal) { try { entities = ResourceBundle.getBundle(entitiesResource); } catch (Exception e) {} } if (entities != null) { Enumeration keys = entities.getKeys(); while (keys.hasMoreElements()) { String name = (String)keys.nextElement(); String value = entities.getString(name); int code = Integer.parseInt(value); boolean extra = defineEntity(name, (char)code); if (extra) { noExtraEntities = false; } } } else { InputStream is = null; try { if (internal) { is = CharInfo.class.getResourceAsStream(entitiesResource); } else { ClassLoader cl = ObjectFactory.findClassLoader(); if (cl == null) { is = ClassLoader.getSystemResourceAsStream(entitiesResource); } else { is = cl.getResourceAsStream(entitiesResource); } if (is == null) { try { URL url = new URL(entitiesResource); is = url.openStream(); } catch (Exception e) {} } } if (is == null) { throw new RuntimeException(Utils.messages.createMessage("ER_RESOURCE_COULD_NOT_FIND", new Object[] { entitiesResource, entitiesResource })); } BufferedReader reader; try { reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); } catch (UnsupportedEncodingException e) { reader = new BufferedReader(new InputStreamReader(is)); } String line = reader.readLine(); while (line != null) { if ((line.length() == 0) || (line.charAt(0) == '#')) { line = reader.readLine(); } else { int index = line.indexOf(' '); if (index > 1) { String name = line.substring(0, index); index++; if (index < line.length()) { String value = line.substring(index); index = value.indexOf(' '); if (index > 0) { value = value.substring(0, index); } int code = Integer.parseInt(value); boolean extra = defineEntity(name, (char)code); if (extra) { noExtraEntities = false; } } } line = reader.readLine(); } } is.close(); } catch (Exception e) { throw new RuntimeException(Utils.messages.createMessage("ER_RESOURCE_COULD_NOT_LOAD", new Object[] { entitiesResource, e.toString(), entitiesResource, e.toString() })); } finally { if (is != null) { try { is.close(); } catch (Exception except) {} } } } onlyQuotAmpLtGt = noExtraEntities; if ("xml".equals(method)) { shouldMapTextChar_ASCII[34] = false; } if ("html".equals(method)) { shouldMapAttrChar_ASCII[60] = false; shouldMapTextChar_ASCII[34] = false; } } private boolean defineEntity(String name, char value) { StringBuffer sb = new StringBuffer("&"); sb.append(name); sb.append(';'); String entityString = sb.toString(); boolean extra = defineChar2StringMapping(entityString, value); return extra; } String getOutputStringForChar(char value) { m_charKey.setChar(value); return (String)m_charToString.get(m_charKey); } final boolean shouldMapAttrChar(int value) { if (value < 128) { return shouldMapAttrChar_ASCII[value]; } return get(value); } final boolean shouldMapTextChar(int value) { if (value < 128) { return shouldMapTextChar_ASCII[value]; } return get(value); } private static CharInfo getCharInfoBasedOnPrivilege(String entitiesFileName, String method, boolean internal) { (CharInfo)AccessController.doPrivileged(new PrivilegedAction() { private final String val$entitiesFileName; private final String val$method; private final boolean val$internal; public Object run() { return new CharInfo(val$entitiesFileName, val$method, val$internal, null); } }); } static CharInfo getCharInfo(String entitiesFileName, String method) { CharInfo charInfo = (CharInfo)m_getCharInfoCache.get(entitiesFileName); if (charInfo != null) { return mutableCopyOf(charInfo); } try { charInfo = getCharInfoBasedOnPrivilege(entitiesFileName, method, true); m_getCharInfoCache.put(entitiesFileName, charInfo); return mutableCopyOf(charInfo); } catch (Exception e) { try { return getCharInfoBasedOnPrivilege(entitiesFileName, method, false); } catch (Exception e) { String absoluteEntitiesFileName; if (entitiesFileName.indexOf(':') < 0) { absoluteEntitiesFileName = SystemIDResolver.getAbsoluteURIFromRelative(entitiesFileName); } else { try { absoluteEntitiesFileName = SystemIDResolver.getAbsoluteURI(entitiesFileName, null); } catch (TransformerException te) { throw new WrappedRuntimeException(te); } } } } return getCharInfoBasedOnPrivilege(entitiesFileName, method, false); } private static CharInfo mutableCopyOf(CharInfo charInfo) { CharInfo copy = new CharInfo(); int max = array_of_bits.length; System.arraycopy(array_of_bits, 0, array_of_bits, 0, max); firstWordNotUsed = firstWordNotUsed; max = shouldMapAttrChar_ASCII.length; System.arraycopy(shouldMapAttrChar_ASCII, 0, shouldMapAttrChar_ASCII, 0, max); max = shouldMapTextChar_ASCII.length; System.arraycopy(shouldMapTextChar_ASCII, 0, shouldMapTextChar_ASCII, 0, max); m_charToString = ((HashMap)m_charToString.clone()); onlyQuotAmpLtGt = onlyQuotAmpLtGt; return copy; } private static Hashtable m_getCharInfoCache = new Hashtable(); private static int arrayIndex(int i) { return i >> 5; } private static int bit(int i) { int ret = 1 << (i & 0x1F); return ret; } private int[] createEmptySetOfIntegers(int max) { firstWordNotUsed = 0; int[] arr = new int[arrayIndex(max - 1) + 1]; return arr; } private final void set(int i) { setASCIItextDirty(i); setASCIIattrDirty(i); int j = i >> 5; int k = j + 1; if (firstWordNotUsed < k) { firstWordNotUsed = k; } array_of_bits[j] |= 1 << (i & 0x1F); } private final boolean get(int i) { boolean in_the_set = false; int j = i >> 5; if (j < firstWordNotUsed) { in_the_set = (array_of_bits[j] & 1 << (i & 0x1F)) != 0; } return in_the_set; } private boolean extraEntity(String outputString, int charToMap) { boolean extra = false; if (charToMap < 128) { switch (charToMap) { case 34: if (!outputString.equals(""")) { extra = true; } break; case 38: if (!outputString.equals("&")) { extra = true; } break; case 60: if (!outputString.equals("<")) { extra = true; } break; case 62: if (!outputString.equals(">")) { extra = true; } break; default: extra = true; } } return extra; } private void setASCIItextDirty(int j) { if ((0 <= j) && (j < 128)) { shouldMapTextChar_ASCII[j] = true; } } private void setASCIIattrDirty(int j) { if ((0 <= j) && (j < 128)) { shouldMapAttrChar_ASCII[j] = true; } } boolean defineChar2StringMapping(String outputString, char inputChar) { CharKey character = new CharKey(inputChar); m_charToString.put(character, outputString); set(inputChar); boolean extraMapping = extraEntity(outputString, inputChar); return extraMapping; } private static class CharKey { private char m_char; public CharKey(char key) { m_char = key; } public CharKey() {} public final void setChar(char c) { m_char = c; } public final int hashCode() { return m_char; } public final boolean equals(Object obj) { return m_char == m_char; } } } /* Location: * Qualified Name: org.apache.xml.serializer.CharInfo * Java Class Version: 1.1 (45.3) * JD-Core Version: 0.7.1 */ package org.apache.xml.serializer.dom3; import java.io.IOException; import org.apache.xml.serializer.DOM3Serializer; import org.apache.xml.serializer.SerializationHandler; import org.apache.xml.serializer.utils.WrappedRuntimeException; import org.w3c.dom.DOMErrorHandler; import org.w3c.dom.Node; import org.w3c.dom.ls.LSSerializerFilter; import org.xml.sax.SAXException; public final class DOM3SerializerImpl implements DOM3Serializer { private DOMErrorHandler fErrorHandler; private LSSerializerFilter fSerializerFilter; private String fNewLine; private SerializationHandler fSerializationHandler; public DOM3SerializerImpl(SerializationHandler handler) { fSerializationHandler = handler; } public DOMErrorHandler getErrorHandler() { return fErrorHandler; } public LSSerializerFilter getNodeFilter() { return fSerializerFilter; } public char[] getNewLine() { return fNewLine != null ? fNewLine.toCharArray() : null; } public void serializeDOM3(Node node) throws IOException { try { DOM3TreeWalker walker = new DOM3TreeWalker(fSerializationHandler, fErrorHandler, fSerializerFilter, fNewLine); walker.traverse(node); } catch (SAXException se) { throw new WrappedRuntimeException(se); } } public void setErrorHandler(DOMErrorHandler handler) { fErrorHandler = handler; } public void setNodeFilter(LSSerializerFilter filter) { fSerializerFilter = filter; } public void setSerializationHandler(SerializationHandler handler) { fSerializationHandler = handler; } public void setNewLine(char[] newLine) { fNewLine = (newLine != null ? new String(newLine) : null); } } /* Location: * Qualified Name: org.apache.xml.serializer.dom3.DOM3SerializerImpl * Java Class Version: 1.1 (45.3) * JD-Core Version: 0.7.1 */ package org.apache.xml.serializer.dom3; import java.io.File; import java.io.IOException; import java.io.Writer; import java.util.Enumeration; import java.util.Hashtable; import java.util.Properties; import org.apache.xml.serializer.ExtendedContentHandler; import org.apache.xml.serializer.SerializationHandler; import org.apache.xml.serializer.Serializer; import org.apache.xml.serializer.utils.Messages; import org.apache.xml.serializer.utils.Utils; import org.apache.xml.serializer.utils.XML11Char; import org.apache.xml.serializer.utils.XMLChar; import org.w3c.dom.Attr; import org.w3c.dom.CDATASection; import org.w3c.dom.CharacterData; import org.w3c.dom.Comment; import org.w3c.dom.DOMErrorHandler; import org.w3c.dom.DOMImplementation; import org.w3c.dom.Document; import org.w3c.dom.DocumentType; import org.w3c.dom.Element; import org.w3c.dom.Entity; import org.w3c.dom.EntityReference; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.w3c.dom.ProcessingInstruction; import org.w3c.dom.Text; import org.w3c.dom.TypeInfo; import org.w3c.dom.ls.LSSerializerFilter; import org.w3c.dom.traversal.NodeFilter; import org.xml.sax.ContentHandler; import org.xml.sax.Locator; import org.xml.sax.SAXException; import org.xml.sax.ext.LexicalHandler; import org.xml.sax.helpers.LocatorImpl; final class DOM3TreeWalker { private SerializationHandler fSerializer = null; private LocatorImpl fLocator = new LocatorImpl(); private DOMErrorHandler fErrorHandler = null; private LSSerializerFilter fFilter = null; private LexicalHandler fLexicalHandler = null; private int fWhatToShowFilter; private String fNewLine = null; private Properties fDOMConfigProperties = null; private boolean fInEntityRef = false; private String fXMLVersion = null; private boolean fIsXMLVersion11 = false; private boolean fIsLevel3DOM = false; private int fFeatures = 0; boolean fNextIsRaw = false; private static final String XMLNS_URI = "http://www.w3.org/2000/xmlns/"; private static final String XMLNS_PREFIX = "xmlns"; private static final String XML_URI = "http://www.w3.org/XML/1998/namespace"; private static final String XML_PREFIX = "xml"; protected NamespaceSupport fNSBinder; protected NamespaceSupport fLocalNSBinder; private int fElementDepth = 0; private static final int CANONICAL = 1; private static final int CDATA = 2; private static final int CHARNORMALIZE = 4; private static final int COMMENTS = 8; private static final int DTNORMALIZE = 16; private static final int ELEM_CONTENT_WHITESPACE = 32; private static final int ENTITIES = 64; private static final int INFOSET = 128; private static final int NAMESPACES = 256; private static final int NAMESPACEDECLS = 512; private static final int NORMALIZECHARS = 1024; private static final int SPLITCDATA = 2048; private static final int VALIDATE = 4096; private static final int SCHEMAVALIDATE = 8192; private static final int WELLFORMED = 16384; private static final int DISCARDDEFAULT = 32768; private static final int PRETTY_PRINT = 65536; private static final int IGNORE_CHAR_DENORMALIZE = 131072; private static final int XMLDECL = 262144; DOM3TreeWalker(SerializationHandler serialHandler, DOMErrorHandler errHandler, LSSerializerFilter filter, String newLine) { fSerializer = serialHandler; fErrorHandler = errHandler; fFilter = filter; fLexicalHandler = null; fNewLine = newLine; fNSBinder = new NamespaceSupport(); fLocalNSBinder = new NamespaceSupport(); fDOMConfigProperties = fSerializer.getOutputFormat(); fSerializer.setDocumentLocator(fLocator); initProperties(fDOMConfigProperties); try { fLocator.setSystemId(System.getProperty("user.dir") + File.separator + "dummy.xsl"); } catch (SecurityException se) {} } public void traverse(Node pos) throws SAXException { fSerializer.startDocument(); if (pos.getNodeType() != 9) { Document ownerDoc = pos.getOwnerDocument(); if ((ownerDoc != null) && (ownerDoc.getImplementation().hasFeature("Core", "3.0"))) { fIsLevel3DOM = true; } } else if (((Document)pos).getImplementation().hasFeature("Core", "3.0")) { fIsLevel3DOM = true; } if ((fSerializer instanceof LexicalHandler)) { fLexicalHandler = fSerializer; } if (fFilter != null) { fWhatToShowFilter = fFilter.getWhatToShow(); } Node top = pos; while (null != pos) { startNode(pos); Node nextNode = null; nextNode = pos.getFirstChild(); while (null == nextNode) { endNode(pos); if (top.equals(pos)) { break; } nextNode = pos.getNextSibling(); if (null == nextNode) { pos = pos.getParentNode(); if ((null == pos) || (top.equals(pos))) { if (null != pos) { endNode(pos); } nextNode = null; break; } } } pos = nextNode; } fSerializer.endDocument(); } public void traverse(Node pos, Node top) throws SAXException { fSerializer.startDocument(); if (pos.getNodeType() != 9) { Document ownerDoc = pos.getOwnerDocument(); if ((ownerDoc != null) && (ownerDoc.getImplementation().hasFeature("Core", "3.0"))) { fIsLevel3DOM = true; } } else if (((Document)pos).getImplementation().hasFeature("Core", "3.0")) { fIsLevel3DOM = true; } if ((fSerializer instanceof LexicalHandler)) { fLexicalHandler = fSerializer; } if (fFilter != null) { fWhatToShowFilter = fFilter.getWhatToShow(); } while (null != pos) { startNode(pos); Node nextNode = null; nextNode = pos.getFirstChild(); while (null == nextNode) { endNode(pos); if ((null != top) && (top.equals(pos))) { break; } nextNode = pos.getNextSibling(); if (null == nextNode) { pos = pos.getParentNode(); if ((null == pos) || ((null != top) && (top.equals(pos)))) { nextNode = null; break; } } } pos = nextNode; } fSerializer.endDocument(); } private final void dispatachChars(Node node) throws SAXException { if (fSerializer != null) { fSerializer.characters(node); } else { String data = ((Text)node).getData(); fSerializer.characters(data.toCharArray(), 0, data.length()); } } protected void startNode(Node node) throws SAXException { if ((node instanceof Locator)) { Locator loc = (Locator)node; fLocator.setColumnNumber(loc.getColumnNumber()); fLocator.setLineNumber(loc.getLineNumber()); fLocator.setPublicId(loc.getPublicId()); fLocator.setSystemId(loc.getSystemId()); } else { fLocator.setColumnNumber(0); fLocator.setLineNumber(0); } switch (node.getNodeType()) { case 10: serializeDocType((DocumentType)node, true); break; case 8: serializeComment((Comment)node); break; case 11: break; case 9: break; case 1: serializeElement((Element)node, true); break; case 7: serializePI((ProcessingInstruction)node); break; case 4: serializeCDATASection((CDATASection)node); break; case 3: serializeText((Text)node); break; case 5: serializeEntityReference((EntityReference)node, true); break; } } protected void endNode(Node node) throws SAXException { switch (node.getNodeType()) { case 9: break; case 10: serializeDocType((DocumentType)node, false); break; case 1: serializeElement((Element)node, false); break; case 4: break; case 5: serializeEntityReference((EntityReference)node, false); break; } } protected boolean applyFilter(Node node, int nodeType) { if ((fFilter != null) && ((fWhatToShowFilter & nodeType) != 0)) { short code = fFilter.acceptNode(node); switch (code) { case 2: case 3: return false; } } return true; } protected void serializeDocType(DocumentType node, boolean bStart) throws SAXException { String docTypeName = node.getNodeName(); String publicId = node.getPublicId(); String systemId = node.getSystemId(); String internalSubset = node.getInternalSubset(); if ((internalSubset != null) && (!"".equals(internalSubset))) { if (bStart) { try { Writer writer = fSerializer.getWriter(); StringBuffer dtd = new StringBuffer(); dtd.append("<!DOCTYPE "); dtd.append(docTypeName); if (null != publicId) { dtd.append(" PUBLIC \""); dtd.append(publicId); dtd.append('"'); } if (null != systemId) { if (null == publicId) { dtd.append(" SYSTEM \""); } else { dtd.append(" \""); } dtd.append(systemId); dtd.append('"'); } dtd.append(" [ "); dtd.append(fNewLine); dtd.append(internalSubset); dtd.append("]>"); dtd.append(new String(fNewLine)); writer.write(dtd.toString()); writer.flush(); } catch (IOException e) { throw new SAXException(Utils.messages.createMessage("ER_WRITING_INTERNAL_SUBSET", null), e); } } } else if (bStart) { if (fLexicalHandler != null) { fLexicalHandler.startDTD(docTypeName, publicId, systemId); } } else if (fLexicalHandler != null) { fLexicalHandler.endDTD(); } } protected void serializeComment(Comment node) throws SAXException { if ((fFeatures & 0x8) != 0) { String data = node.getData(); if ((fFeatures & 0x4000) != 0) { isCommentWellFormed(data); } if (fLexicalHandler != null) { if (!applyFilter(node, 128)) { return; } fLexicalHandler.comment(data.toCharArray(), 0, data.length()); } } } protected void serializeElement(Element node, boolean bStart) throws SAXException { if (bStart) { fElementDepth += 1; if ((fFeatures & 0x4000) != 0) { isElementWellFormed(node); } if (!applyFilter(node, 1)) { return; } if ((fFeatures & 0x100) != 0) { fNSBinder.pushContext(); fLocalNSBinder.reset(); recordLocalNSDecl(node); fixupElementNS(node); } fSerializer.startElement(node.getNamespaceURI(), node.getLocalName(), node.getNodeName()); serializeAttList(node); } else { fElementDepth -= 1; if (!applyFilter(node, 1)) { return; } fSerializer.endElement(node.getNamespaceURI(), node.getLocalName(), node.getNodeName()); if ((fFeatures & 0x100) != 0) { fNSBinder.popContext(); } } } protected void serializeAttList(Element node) throws SAXException { NamedNodeMap atts = node.getAttributes(); int nAttrs = atts.getLength(); for (int i = 0; i < nAttrs; i++) { Node attr = atts.item(i); String localName = attr.getLocalName(); String attrName = attr.getNodeName(); String attrPrefix = attr.getPrefix() == null ? "" : attr.getPrefix(); String attrValue = attr.getNodeValue(); String type = null; if (fIsLevel3DOM) { type = ((Attr)attr).getSchemaTypeInfo().getTypeName(); } type = type == null ? "CDATA" : type; String attrNS = attr.getNamespaceURI(); if ((attrNS != null) && (attrNS.length() == 0)) { attrNS = null; attrName = attr.getLocalName(); } boolean isSpecified = ((Attr)attr).getSpecified(); boolean addAttr = true; boolean applyFilter = false; boolean xmlnsAttr = (attrName.equals("xmlns")) || (attrName.startsWith("xmlns:")); if ((fFeatures & 0x4000) != 0) { isAttributeWellFormed(attr); } if (((fFeatures & 0x100) != 0) && (!xmlnsAttr)) { if (attrNS != null) { attrPrefix = attrPrefix == null ? "" : attrPrefix; String declAttrPrefix = fNSBinder.getPrefix(attrNS); String declAttrNS = fNSBinder.getURI(attrPrefix); if (("".equals(attrPrefix)) || ("".equals(declAttrPrefix)) || (!attrPrefix.equals(declAttrPrefix))) { if ((declAttrPrefix != null) && (!"".equals(declAttrPrefix))) { attrPrefix = declAttrPrefix; if (declAttrPrefix.length() > 0) { attrName = declAttrPrefix + ":" + localName; } else { attrName = localName; } } else if ((attrPrefix != null) && (!"".equals(attrPrefix)) && (declAttrNS == null)) { if ((fFeatures & 0x200) != 0) { fSerializer.addAttribute("http://www.w3.org/2000/xmlns/", attrPrefix, "xmlns:" + attrPrefix, "CDATA", attrNS); fNSBinder.declarePrefix(attrPrefix, attrNS); fLocalNSBinder.declarePrefix(attrPrefix, attrNS); } } else { int counter = 1; attrPrefix = "NS" + counter++; while (fLocalNSBinder.getURI(attrPrefix) != null) { attrPrefix = "NS" + counter++; } attrName = attrPrefix + ":" + localName; if ((fFeatures & 0x200) != 0) { fSerializer.addAttribute("http://www.w3.org/2000/xmlns/", attrPrefix, "xmlns:" + attrPrefix, "CDATA", attrNS); fNSBinder.declarePrefix(attrPrefix, attrNS); fLocalNSBinder.declarePrefix(attrPrefix, attrNS); } } } } else if (localName == null) { String msg = Utils.messages.createMessage("ER_NULL_LOCAL_ELEMENT_NAME", new Object[] { attrName }); if (fErrorHandler != null) { fErrorHandler.handleError(new DOMErrorImpl((short)2, msg, "ER_NULL_LOCAL_ELEMENT_NAME", null, null, null)); } } } if ((((fFeatures & 0x8000) != 0) && (isSpecified)) || ((fFeatures & 0x8000) == 0)) { applyFilter = true; } else { addAttr = false; } if (applyFilter) { if ((fFilter != null) && ((fFilter.getWhatToShow() & 0x2) != 0)) { if (!xmlnsAttr) { short code = fFilter.acceptNode(attr); switch (code) { case 2: case 3: addAttr = false; break; } } } } if ((addAttr) && (xmlnsAttr)) { if ((fFeatures & 0x200) != 0) { if ((localName != null) && (!"".equals(localName))) { fSerializer.addAttribute(attrNS, localName, attrName, type, attrValue); } } } else if ((addAttr) && (!xmlnsAttr)) { if (((fFeatures & 0x200) != 0) && (attrNS != null)) { fSerializer.addAttribute(attrNS, localName, attrName, type, attrValue); } else { fSerializer.addAttribute("", localName, attrName, type, attrValue); } } if ((xmlnsAttr) && ((fFeatures & 0x200) != 0)) { int index; String prefix = (index = attrName.indexOf(":")) < 0 ? "" : attrName.substring(index + 1); if (!"".equals(prefix)) { fSerializer.namespaceAfterStartElement(prefix, attrValue); } } } } protected void serializePI(ProcessingInstruction node) throws SAXException { ProcessingInstruction pi = node; String name = pi.getNodeName(); if ((fFeatures & 0x4000) != 0) { isPIWellFormed(node); } if (!applyFilter(node, 64)) { return; } if (name.equals("xslt-next-is-raw")) { fNextIsRaw = true; } else { fSerializer.processingInstruction(name, pi.getData()); } } protected void serializeCDATASection(CDATASection node) throws SAXException { if ((fFeatures & 0x4000) != 0) { isCDATASectionWellFormed(node); } if ((fFeatures & 0x2) != 0) { String nodeValue = node.getNodeValue(); int endIndex = nodeValue.indexOf("]]>"); if ((fFeatures & 0x800) != 0) { if (endIndex >= 0) { String relatedData = nodeValue.substring(0, endIndex + 2); String msg = Utils.messages.createMessage("cdata-sections-splitted", null); if (fErrorHandler != null) { fErrorHandler.handleError(new DOMErrorImpl((short)1, msg, "cdata-sections-splitted", null, relatedData, null)); } } } else if (endIndex >= 0) { String relatedData = nodeValue.substring(0, endIndex + 2); String msg = Utils.messages.createMessage("cdata-sections-splitted", null); if (fErrorHandler != null) { fErrorHandler.handleError(new DOMErrorImpl((short)2, msg, "cdata-sections-splitted")); } return; } if (!applyFilter(node, 8)) { return; } if (fLexicalHandler != null) { fLexicalHandler.startCDATA(); } dispatachChars(node); if (fLexicalHandler != null) { fLexicalHandler.endCDATA(); } } else { dispatachChars(node); } } protected void serializeText(Text node) throws SAXException { if (fNextIsRaw) { fNextIsRaw = false; fSerializer.processingInstruction("javax.xml.transform.disable-output-escaping", ""); dispatachChars(node); fSerializer.processingInstruction("javax.xml.transform.enable-output-escaping", ""); } else { boolean bDispatch = false; if ((fFeatures & 0x4000) != 0) { isTextWellFormed(node); } boolean isElementContentWhitespace = false; if (fIsLevel3DOM) { isElementContentWhitespace = node.isElementContentWhitespace(); } if (isElementContentWhitespace) { if ((fFeatures & 0x20) != 0) { bDispatch = true; } } else { bDispatch = true; } if (!applyFilter(node, 4)) { return; } if (bDispatch) { dispatachChars(node); } } } protected void serializeEntityReference(EntityReference node, boolean bStart) throws SAXException { if (bStart) { EntityReference eref = node; if ((fFeatures & 0x40) != 0) { if ((fFeatures & 0x4000) != 0) { isEntityReferneceWellFormed(node); } if ((fFeatures & 0x100) != 0) { checkUnboundPrefixInEntRef(node); } } if (fLexicalHandler != null) { fLexicalHandler.startEntity(eref.getNodeName()); } } else { EntityReference eref = node; if (fLexicalHandler != null) { fLexicalHandler.endEntity(eref.getNodeName()); } } } protected boolean isXMLName(String s, boolean xml11Version) { if (s == null) { return false; } if (!xml11Version) { return XMLChar.isValidName(s); } return XML11Char.isXML11ValidName(s); } protected boolean isValidQName(String prefix, String local, boolean xml11Version) { if (local == null) { return false; } boolean validNCName = false; if (!xml11Version) { validNCName = ((prefix == null) || (XMLChar.isValidNCName(prefix))) && (XMLChar.isValidNCName(local)); } else { validNCName = ((prefix == null) || (XML11Char.isXML11ValidNCName(prefix))) && (XML11Char.isXML11ValidNCName(local)); } return validNCName; } protected boolean isWFXMLChar(String chardata, Character refInvalidChar) { if ((chardata == null) || (chardata.length() == 0)) { return true; } char[] dataarray = chardata.toCharArray(); int datalength = dataarray.length; if (fIsXMLVersion11) { int i = 0; while (i < datalength) { if (XML11Char.isXML11Invalid(dataarray[(i++)])) { char ch = dataarray[(i - 1)]; if ((XMLChar.isHighSurrogate(ch)) && (i < datalength)) { char ch2 = dataarray[(i++)]; if ((XMLChar.isLowSurrogate(ch2)) && (XMLChar.isSupplemental(XMLChar.supplemental(ch, ch2)))) {} } else { refInvalidChar = new Character(ch); return false; } } } } else { int i = 0; while (i < datalength) { if (XMLChar.isInvalid(dataarray[(i++)])) { char ch = dataarray[(i - 1)]; if ((XMLChar.isHighSurrogate(ch)) && (i < datalength)) { char ch2 = dataarray[(i++)]; if ((XMLChar.isLowSurrogate(ch2)) && (XMLChar.isSupplemental(XMLChar.supplemental(ch, ch2)))) {} } else { refInvalidChar = new Character(ch); return false; } } } } return true; } protected Character isWFXMLChar(String chardata) { if ((chardata == null) || (chardata.length() == 0)) { return null; } char[] dataarray = chardata.toCharArray(); int datalength = dataarray.length; Character refInvalidChar; if (fIsXMLVersion11) { int i = 0; while (i < datalength) { if (XML11Char.isXML11Invalid(dataarray[(i++)])) { char ch = dataarray[(i - 1)]; if ((XMLChar.isHighSurrogate(ch)) && (i < datalength)) { char ch2 = dataarray[(i++)]; if ((XMLChar.isLowSurrogate(ch2)) && (XMLChar.isSupplemental(XMLChar.supplemental(ch, ch2)))) {} } else { refInvalidChar = new Character(ch); return refInvalidChar; } } } } else { int i = 0; while (i < datalength) { if (XMLChar.isInvalid(dataarray[(i++)])) { char ch = dataarray[(i - 1)]; if ((XMLChar.isHighSurrogate(ch)) && (i < datalength)) { char ch2 = dataarray[(i++)]; if ((XMLChar.isLowSurrogate(ch2 Further reading...For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.New!JAR listings
|