rem
stringlengths
0
477k
add
stringlengths
0
313k
context
stringlengths
6
599k
out.write(APOS);
out.write(0x22);
private void doSerialize(final Node node, final OutputStream out, boolean convertToCdata) throws IOException { if (out == null) { throw new NullPointerException("no output stream"); } String value, prefix; Node children; String uri = node.getNamespaceURI(); boolean defined = false; short nt = node.getNodeType(); if (convertToCdata && nt == Node.TEXT_NODE) { nt = Node.CDATA_SECTION_NODE; } switch (nt) { case Node.ATTRIBUTE_NODE: prefix = node.getPrefix(); if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(uri) || XMLConstants.XMLNS_ATTRIBUTE.equals(prefix) || (prefix != null && prefix.startsWith("xmlns:"))) { String nsuri = node.getNodeValue(); if (isDefined(nsuri)) { break; } String name = node.getLocalName(); if (name == null) { name = node.getNodeName(); } define(nsuri, name); } else if (uri != null && !isDefined(uri)) { prefix = define(uri, prefix); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(nsvalue.getBytes(encoding)); defined = true; } out.write(SPACE); String a_nodeName = node.getNodeName(); out.write(encodeText(a_nodeName)); String a_nodeValue = node.getNodeValue(); if (mode == Stylesheet.OUTPUT_HTML && a_nodeName.equals(a_nodeValue) && isHTMLBoolean((Attr) node, a_nodeName)) { break; } out.write(EQ); value = "'" + encode(a_nodeValue, true, true) + "'"; out.write(encodeText(value)); break; case Node.ELEMENT_NODE: value = node.getNodeName(); out.write(BRA); out.write(encodeText(value)); if (uri != null && !isDefined(uri)) { prefix = define(uri, node.getPrefix()); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(encodeText(nsvalue)); defined = true; } NamedNodeMap attrs = node.getAttributes(); if (attrs != null) { int len = attrs.getLength(); for (int i = 0; i < len; i++) { Attr attr = (Attr) attrs.item(i); if (discardDefaultContent && !attr.getSpecified()) { // NOOP } else { serialize(attr, out, false); } } } convertToCdata = cdataSectionElements.contains(value); children = node.getFirstChild(); if (children == null) { out.write(SLASH); out.write(KET); } else { out.write(KET); serialize(children, out, convertToCdata); out.write(BRA); out.write(SLASH); out.write(encodeText(value)); out.write(KET); } break; case Node.TEXT_NODE: value = node.getNodeValue(); if (!"yes".equals(node.getUserData("disable-output-escaping"))) { value = encode(value, false, false); } out.write(encodeText(value)); break; case Node.CDATA_SECTION_NODE: value = "<![CDATA[" + node.getNodeValue() + "]]>"; out.write(encodeText(value)); break; case Node.COMMENT_NODE: value = "<!--" + node.getNodeValue() + "-->"; out.write(encodeText(value)); Node cp = node.getParentNode(); if (cp != null && cp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: if (mode == Stylesheet.OUTPUT_XML) { if ("UTF-16".equalsIgnoreCase(encoding)) { out.write(0xfe); out.write(0xff); } if (!"yes".equals(node.getUserData("omit-xml-declaration")) && xmlDeclaration) { Document doc = (node instanceof Document) ? (Document) node : null; String version = (doc != null) ? doc.getXmlVersion() : null; if (version == null) { version = (String) node.getUserData("version"); } if (version == null) { version = "1.0"; } out.write(BRA); out.write(0x3f); out.write("xml version='".getBytes("US-ASCII")); out.write(version.getBytes("US-ASCII")); out.write(APOS); if (!("UTF-8".equalsIgnoreCase(encoding))) { out.write(" encoding='".getBytes("US-ASCII")); out.write(encoding.getBytes("US-ASCII")); out.write(APOS); } if ((doc != null && doc.getXmlStandalone()) || "yes".equals(node.getUserData("standalone"))) { out.write(" standalone='yes'".getBytes("US-ASCII")); } out.write(0x3f); out.write(KET); out.write(encodeText(eol)); } // TODO warn if not outputting the declaration would be a // problem } else if (mode == Stylesheet.OUTPUT_HTML) { // Ensure that encoding is accessible String mediaType = (String) node.getUserData("media-type"); if (mediaType == null) { mediaType = "text/html"; } String contentType = mediaType + "; charset=" + ((encoding.indexOf(' ') != -1) ? "\"" + encoding + "\"" : encoding); Document doc = (node instanceof Document) ? (Document) node : node.getOwnerDocument(); Node html = null; for (Node ctx = node.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { html = ctx; break; } } if (html == null) { html = doc.createElement("html"); node.appendChild(html); } Node head = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("head".equalsIgnoreCase(name)) { head = ctx; break; } } } if (head == null) { head = doc.createElement("head"); Node c1 = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { c1 = ctx; break; } } if (c1 != null) { html.insertBefore(head, c1); } else { html.appendChild(head); } } Node meta = null; Node metaContent = null; for (Node ctx = head.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("meta".equalsIgnoreCase(name)) { NamedNodeMap metaAttrs = ctx.getAttributes(); int len = metaAttrs.getLength(); String httpEquiv = null; Node content = null; for (int i = 0; i < len; i++) { Node attr = metaAttrs.item(i); String attrName = attr.getNodeName(); if ("http-equiv".equalsIgnoreCase(attrName)) { httpEquiv = attr.getNodeValue(); } else if ("content".equalsIgnoreCase(attrName)) { content = attr; } } if ("Content-Type".equalsIgnoreCase(httpEquiv)) { meta = ctx; metaContent = content; break; } } } } if (meta == null) { meta = doc.createElement("meta"); // Insert first Node first = head.getFirstChild(); if (first == null) { head.appendChild(meta); } else { head.insertBefore(meta, first); } Node metaHttpEquiv = doc.createAttribute("http-equiv"); meta.getAttributes().setNamedItem(metaHttpEquiv); metaHttpEquiv.setNodeValue("Content-Type"); } if (metaContent == null) { metaContent = doc.createAttribute("content"); meta.getAttributes().setNamedItem(metaContent); } metaContent.setNodeValue(contentType); // phew } children = node.getFirstChild(); if (children != null) { serialize(children, out, convertToCdata); } break; case Node.DOCUMENT_TYPE_NODE: DocumentType doctype = (DocumentType) node; out.write(BRA); out.write(BANG); out.write(encodeText("DOCTYPE ")); value = doctype.getNodeName(); out.write(encodeText(value)); String publicId = doctype.getPublicId(); if (publicId != null) { out.write(encodeText(" PUBLIC ")); out.write(APOS); out.write(encodeText(publicId)); out.write(APOS); } String systemId = doctype.getSystemId(); if (systemId != null) { out.write(encodeText(" SYSTEM ")); out.write(APOS); out.write(encodeText(systemId)); out.write(APOS); } String internalSubset = doctype.getInternalSubset(); if (internalSubset != null) { out.write(encodeText(internalSubset)); } out.write(KET); out.write(eol.getBytes(encoding)); break; case Node.ENTITY_REFERENCE_NODE: value = "&" + node.getNodeValue() + ";"; out.write(encodeText(value)); break; case Node.PROCESSING_INSTRUCTION_NODE: value = "<?" + node.getNodeName() + " " + node.getNodeValue() + "?>"; out.write(encodeText(value)); Node pp = node.getParentNode(); if (pp != null && pp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; } if (defined) { undefine(uri); } }
out.write(" encoding='".getBytes("US-ASCII"));
out.write(" encoding=\"".getBytes("US-ASCII"));
private void doSerialize(final Node node, final OutputStream out, boolean convertToCdata) throws IOException { if (out == null) { throw new NullPointerException("no output stream"); } String value, prefix; Node children; String uri = node.getNamespaceURI(); boolean defined = false; short nt = node.getNodeType(); if (convertToCdata && nt == Node.TEXT_NODE) { nt = Node.CDATA_SECTION_NODE; } switch (nt) { case Node.ATTRIBUTE_NODE: prefix = node.getPrefix(); if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(uri) || XMLConstants.XMLNS_ATTRIBUTE.equals(prefix) || (prefix != null && prefix.startsWith("xmlns:"))) { String nsuri = node.getNodeValue(); if (isDefined(nsuri)) { break; } String name = node.getLocalName(); if (name == null) { name = node.getNodeName(); } define(nsuri, name); } else if (uri != null && !isDefined(uri)) { prefix = define(uri, prefix); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(nsvalue.getBytes(encoding)); defined = true; } out.write(SPACE); String a_nodeName = node.getNodeName(); out.write(encodeText(a_nodeName)); String a_nodeValue = node.getNodeValue(); if (mode == Stylesheet.OUTPUT_HTML && a_nodeName.equals(a_nodeValue) && isHTMLBoolean((Attr) node, a_nodeName)) { break; } out.write(EQ); value = "'" + encode(a_nodeValue, true, true) + "'"; out.write(encodeText(value)); break; case Node.ELEMENT_NODE: value = node.getNodeName(); out.write(BRA); out.write(encodeText(value)); if (uri != null && !isDefined(uri)) { prefix = define(uri, node.getPrefix()); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(encodeText(nsvalue)); defined = true; } NamedNodeMap attrs = node.getAttributes(); if (attrs != null) { int len = attrs.getLength(); for (int i = 0; i < len; i++) { Attr attr = (Attr) attrs.item(i); if (discardDefaultContent && !attr.getSpecified()) { // NOOP } else { serialize(attr, out, false); } } } convertToCdata = cdataSectionElements.contains(value); children = node.getFirstChild(); if (children == null) { out.write(SLASH); out.write(KET); } else { out.write(KET); serialize(children, out, convertToCdata); out.write(BRA); out.write(SLASH); out.write(encodeText(value)); out.write(KET); } break; case Node.TEXT_NODE: value = node.getNodeValue(); if (!"yes".equals(node.getUserData("disable-output-escaping"))) { value = encode(value, false, false); } out.write(encodeText(value)); break; case Node.CDATA_SECTION_NODE: value = "<![CDATA[" + node.getNodeValue() + "]]>"; out.write(encodeText(value)); break; case Node.COMMENT_NODE: value = "<!--" + node.getNodeValue() + "-->"; out.write(encodeText(value)); Node cp = node.getParentNode(); if (cp != null && cp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: if (mode == Stylesheet.OUTPUT_XML) { if ("UTF-16".equalsIgnoreCase(encoding)) { out.write(0xfe); out.write(0xff); } if (!"yes".equals(node.getUserData("omit-xml-declaration")) && xmlDeclaration) { Document doc = (node instanceof Document) ? (Document) node : null; String version = (doc != null) ? doc.getXmlVersion() : null; if (version == null) { version = (String) node.getUserData("version"); } if (version == null) { version = "1.0"; } out.write(BRA); out.write(0x3f); out.write("xml version='".getBytes("US-ASCII")); out.write(version.getBytes("US-ASCII")); out.write(APOS); if (!("UTF-8".equalsIgnoreCase(encoding))) { out.write(" encoding='".getBytes("US-ASCII")); out.write(encoding.getBytes("US-ASCII")); out.write(APOS); } if ((doc != null && doc.getXmlStandalone()) || "yes".equals(node.getUserData("standalone"))) { out.write(" standalone='yes'".getBytes("US-ASCII")); } out.write(0x3f); out.write(KET); out.write(encodeText(eol)); } // TODO warn if not outputting the declaration would be a // problem } else if (mode == Stylesheet.OUTPUT_HTML) { // Ensure that encoding is accessible String mediaType = (String) node.getUserData("media-type"); if (mediaType == null) { mediaType = "text/html"; } String contentType = mediaType + "; charset=" + ((encoding.indexOf(' ') != -1) ? "\"" + encoding + "\"" : encoding); Document doc = (node instanceof Document) ? (Document) node : node.getOwnerDocument(); Node html = null; for (Node ctx = node.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { html = ctx; break; } } if (html == null) { html = doc.createElement("html"); node.appendChild(html); } Node head = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("head".equalsIgnoreCase(name)) { head = ctx; break; } } } if (head == null) { head = doc.createElement("head"); Node c1 = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { c1 = ctx; break; } } if (c1 != null) { html.insertBefore(head, c1); } else { html.appendChild(head); } } Node meta = null; Node metaContent = null; for (Node ctx = head.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("meta".equalsIgnoreCase(name)) { NamedNodeMap metaAttrs = ctx.getAttributes(); int len = metaAttrs.getLength(); String httpEquiv = null; Node content = null; for (int i = 0; i < len; i++) { Node attr = metaAttrs.item(i); String attrName = attr.getNodeName(); if ("http-equiv".equalsIgnoreCase(attrName)) { httpEquiv = attr.getNodeValue(); } else if ("content".equalsIgnoreCase(attrName)) { content = attr; } } if ("Content-Type".equalsIgnoreCase(httpEquiv)) { meta = ctx; metaContent = content; break; } } } } if (meta == null) { meta = doc.createElement("meta"); // Insert first Node first = head.getFirstChild(); if (first == null) { head.appendChild(meta); } else { head.insertBefore(meta, first); } Node metaHttpEquiv = doc.createAttribute("http-equiv"); meta.getAttributes().setNamedItem(metaHttpEquiv); metaHttpEquiv.setNodeValue("Content-Type"); } if (metaContent == null) { metaContent = doc.createAttribute("content"); meta.getAttributes().setNamedItem(metaContent); } metaContent.setNodeValue(contentType); // phew } children = node.getFirstChild(); if (children != null) { serialize(children, out, convertToCdata); } break; case Node.DOCUMENT_TYPE_NODE: DocumentType doctype = (DocumentType) node; out.write(BRA); out.write(BANG); out.write(encodeText("DOCTYPE ")); value = doctype.getNodeName(); out.write(encodeText(value)); String publicId = doctype.getPublicId(); if (publicId != null) { out.write(encodeText(" PUBLIC ")); out.write(APOS); out.write(encodeText(publicId)); out.write(APOS); } String systemId = doctype.getSystemId(); if (systemId != null) { out.write(encodeText(" SYSTEM ")); out.write(APOS); out.write(encodeText(systemId)); out.write(APOS); } String internalSubset = doctype.getInternalSubset(); if (internalSubset != null) { out.write(encodeText(internalSubset)); } out.write(KET); out.write(eol.getBytes(encoding)); break; case Node.ENTITY_REFERENCE_NODE: value = "&" + node.getNodeValue() + ";"; out.write(encodeText(value)); break; case Node.PROCESSING_INSTRUCTION_NODE: value = "<?" + node.getNodeName() + " " + node.getNodeValue() + "?>"; out.write(encodeText(value)); Node pp = node.getParentNode(); if (pp != null && pp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; } if (defined) { undefine(uri); } }
{ out.write(" standalone='yes'".getBytes("US-ASCII")); }
out.write(" standalone=\"yes\"".getBytes("US-ASCII"));
private void doSerialize(final Node node, final OutputStream out, boolean convertToCdata) throws IOException { if (out == null) { throw new NullPointerException("no output stream"); } String value, prefix; Node children; String uri = node.getNamespaceURI(); boolean defined = false; short nt = node.getNodeType(); if (convertToCdata && nt == Node.TEXT_NODE) { nt = Node.CDATA_SECTION_NODE; } switch (nt) { case Node.ATTRIBUTE_NODE: prefix = node.getPrefix(); if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(uri) || XMLConstants.XMLNS_ATTRIBUTE.equals(prefix) || (prefix != null && prefix.startsWith("xmlns:"))) { String nsuri = node.getNodeValue(); if (isDefined(nsuri)) { break; } String name = node.getLocalName(); if (name == null) { name = node.getNodeName(); } define(nsuri, name); } else if (uri != null && !isDefined(uri)) { prefix = define(uri, prefix); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(nsvalue.getBytes(encoding)); defined = true; } out.write(SPACE); String a_nodeName = node.getNodeName(); out.write(encodeText(a_nodeName)); String a_nodeValue = node.getNodeValue(); if (mode == Stylesheet.OUTPUT_HTML && a_nodeName.equals(a_nodeValue) && isHTMLBoolean((Attr) node, a_nodeName)) { break; } out.write(EQ); value = "'" + encode(a_nodeValue, true, true) + "'"; out.write(encodeText(value)); break; case Node.ELEMENT_NODE: value = node.getNodeName(); out.write(BRA); out.write(encodeText(value)); if (uri != null && !isDefined(uri)) { prefix = define(uri, node.getPrefix()); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(encodeText(nsvalue)); defined = true; } NamedNodeMap attrs = node.getAttributes(); if (attrs != null) { int len = attrs.getLength(); for (int i = 0; i < len; i++) { Attr attr = (Attr) attrs.item(i); if (discardDefaultContent && !attr.getSpecified()) { // NOOP } else { serialize(attr, out, false); } } } convertToCdata = cdataSectionElements.contains(value); children = node.getFirstChild(); if (children == null) { out.write(SLASH); out.write(KET); } else { out.write(KET); serialize(children, out, convertToCdata); out.write(BRA); out.write(SLASH); out.write(encodeText(value)); out.write(KET); } break; case Node.TEXT_NODE: value = node.getNodeValue(); if (!"yes".equals(node.getUserData("disable-output-escaping"))) { value = encode(value, false, false); } out.write(encodeText(value)); break; case Node.CDATA_SECTION_NODE: value = "<![CDATA[" + node.getNodeValue() + "]]>"; out.write(encodeText(value)); break; case Node.COMMENT_NODE: value = "<!--" + node.getNodeValue() + "-->"; out.write(encodeText(value)); Node cp = node.getParentNode(); if (cp != null && cp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: if (mode == Stylesheet.OUTPUT_XML) { if ("UTF-16".equalsIgnoreCase(encoding)) { out.write(0xfe); out.write(0xff); } if (!"yes".equals(node.getUserData("omit-xml-declaration")) && xmlDeclaration) { Document doc = (node instanceof Document) ? (Document) node : null; String version = (doc != null) ? doc.getXmlVersion() : null; if (version == null) { version = (String) node.getUserData("version"); } if (version == null) { version = "1.0"; } out.write(BRA); out.write(0x3f); out.write("xml version='".getBytes("US-ASCII")); out.write(version.getBytes("US-ASCII")); out.write(APOS); if (!("UTF-8".equalsIgnoreCase(encoding))) { out.write(" encoding='".getBytes("US-ASCII")); out.write(encoding.getBytes("US-ASCII")); out.write(APOS); } if ((doc != null && doc.getXmlStandalone()) || "yes".equals(node.getUserData("standalone"))) { out.write(" standalone='yes'".getBytes("US-ASCII")); } out.write(0x3f); out.write(KET); out.write(encodeText(eol)); } // TODO warn if not outputting the declaration would be a // problem } else if (mode == Stylesheet.OUTPUT_HTML) { // Ensure that encoding is accessible String mediaType = (String) node.getUserData("media-type"); if (mediaType == null) { mediaType = "text/html"; } String contentType = mediaType + "; charset=" + ((encoding.indexOf(' ') != -1) ? "\"" + encoding + "\"" : encoding); Document doc = (node instanceof Document) ? (Document) node : node.getOwnerDocument(); Node html = null; for (Node ctx = node.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { html = ctx; break; } } if (html == null) { html = doc.createElement("html"); node.appendChild(html); } Node head = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("head".equalsIgnoreCase(name)) { head = ctx; break; } } } if (head == null) { head = doc.createElement("head"); Node c1 = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { c1 = ctx; break; } } if (c1 != null) { html.insertBefore(head, c1); } else { html.appendChild(head); } } Node meta = null; Node metaContent = null; for (Node ctx = head.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("meta".equalsIgnoreCase(name)) { NamedNodeMap metaAttrs = ctx.getAttributes(); int len = metaAttrs.getLength(); String httpEquiv = null; Node content = null; for (int i = 0; i < len; i++) { Node attr = metaAttrs.item(i); String attrName = attr.getNodeName(); if ("http-equiv".equalsIgnoreCase(attrName)) { httpEquiv = attr.getNodeValue(); } else if ("content".equalsIgnoreCase(attrName)) { content = attr; } } if ("Content-Type".equalsIgnoreCase(httpEquiv)) { meta = ctx; metaContent = content; break; } } } } if (meta == null) { meta = doc.createElement("meta"); // Insert first Node first = head.getFirstChild(); if (first == null) { head.appendChild(meta); } else { head.insertBefore(meta, first); } Node metaHttpEquiv = doc.createAttribute("http-equiv"); meta.getAttributes().setNamedItem(metaHttpEquiv); metaHttpEquiv.setNodeValue("Content-Type"); } if (metaContent == null) { metaContent = doc.createAttribute("content"); meta.getAttributes().setNamedItem(metaContent); } metaContent.setNodeValue(contentType); // phew } children = node.getFirstChild(); if (children != null) { serialize(children, out, convertToCdata); } break; case Node.DOCUMENT_TYPE_NODE: DocumentType doctype = (DocumentType) node; out.write(BRA); out.write(BANG); out.write(encodeText("DOCTYPE ")); value = doctype.getNodeName(); out.write(encodeText(value)); String publicId = doctype.getPublicId(); if (publicId != null) { out.write(encodeText(" PUBLIC ")); out.write(APOS); out.write(encodeText(publicId)); out.write(APOS); } String systemId = doctype.getSystemId(); if (systemId != null) { out.write(encodeText(" SYSTEM ")); out.write(APOS); out.write(encodeText(systemId)); out.write(APOS); } String internalSubset = doctype.getInternalSubset(); if (internalSubset != null) { out.write(encodeText(internalSubset)); } out.write(KET); out.write(eol.getBytes(encoding)); break; case Node.ENTITY_REFERENCE_NODE: value = "&" + node.getNodeValue() + ";"; out.write(encodeText(value)); break; case Node.PROCESSING_INSTRUCTION_NODE: value = "<?" + node.getNodeName() + " " + node.getNodeValue() + "?>"; out.write(encodeText(value)); Node pp = node.getParentNode(); if (pp != null && pp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; } if (defined) { undefine(uri); } }
if (ctx.getNodeType() == Node.ELEMENT_NODE)
if (ctx.getNodeType() == Node.ELEMENT_NODE && isHTMLElement(ctx, "html"))
private void doSerialize(final Node node, final OutputStream out, boolean convertToCdata) throws IOException { if (out == null) { throw new NullPointerException("no output stream"); } String value, prefix; Node children; String uri = node.getNamespaceURI(); boolean defined = false; short nt = node.getNodeType(); if (convertToCdata && nt == Node.TEXT_NODE) { nt = Node.CDATA_SECTION_NODE; } switch (nt) { case Node.ATTRIBUTE_NODE: prefix = node.getPrefix(); if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(uri) || XMLConstants.XMLNS_ATTRIBUTE.equals(prefix) || (prefix != null && prefix.startsWith("xmlns:"))) { String nsuri = node.getNodeValue(); if (isDefined(nsuri)) { break; } String name = node.getLocalName(); if (name == null) { name = node.getNodeName(); } define(nsuri, name); } else if (uri != null && !isDefined(uri)) { prefix = define(uri, prefix); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(nsvalue.getBytes(encoding)); defined = true; } out.write(SPACE); String a_nodeName = node.getNodeName(); out.write(encodeText(a_nodeName)); String a_nodeValue = node.getNodeValue(); if (mode == Stylesheet.OUTPUT_HTML && a_nodeName.equals(a_nodeValue) && isHTMLBoolean((Attr) node, a_nodeName)) { break; } out.write(EQ); value = "'" + encode(a_nodeValue, true, true) + "'"; out.write(encodeText(value)); break; case Node.ELEMENT_NODE: value = node.getNodeName(); out.write(BRA); out.write(encodeText(value)); if (uri != null && !isDefined(uri)) { prefix = define(uri, node.getPrefix()); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(encodeText(nsvalue)); defined = true; } NamedNodeMap attrs = node.getAttributes(); if (attrs != null) { int len = attrs.getLength(); for (int i = 0; i < len; i++) { Attr attr = (Attr) attrs.item(i); if (discardDefaultContent && !attr.getSpecified()) { // NOOP } else { serialize(attr, out, false); } } } convertToCdata = cdataSectionElements.contains(value); children = node.getFirstChild(); if (children == null) { out.write(SLASH); out.write(KET); } else { out.write(KET); serialize(children, out, convertToCdata); out.write(BRA); out.write(SLASH); out.write(encodeText(value)); out.write(KET); } break; case Node.TEXT_NODE: value = node.getNodeValue(); if (!"yes".equals(node.getUserData("disable-output-escaping"))) { value = encode(value, false, false); } out.write(encodeText(value)); break; case Node.CDATA_SECTION_NODE: value = "<![CDATA[" + node.getNodeValue() + "]]>"; out.write(encodeText(value)); break; case Node.COMMENT_NODE: value = "<!--" + node.getNodeValue() + "-->"; out.write(encodeText(value)); Node cp = node.getParentNode(); if (cp != null && cp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: if (mode == Stylesheet.OUTPUT_XML) { if ("UTF-16".equalsIgnoreCase(encoding)) { out.write(0xfe); out.write(0xff); } if (!"yes".equals(node.getUserData("omit-xml-declaration")) && xmlDeclaration) { Document doc = (node instanceof Document) ? (Document) node : null; String version = (doc != null) ? doc.getXmlVersion() : null; if (version == null) { version = (String) node.getUserData("version"); } if (version == null) { version = "1.0"; } out.write(BRA); out.write(0x3f); out.write("xml version='".getBytes("US-ASCII")); out.write(version.getBytes("US-ASCII")); out.write(APOS); if (!("UTF-8".equalsIgnoreCase(encoding))) { out.write(" encoding='".getBytes("US-ASCII")); out.write(encoding.getBytes("US-ASCII")); out.write(APOS); } if ((doc != null && doc.getXmlStandalone()) || "yes".equals(node.getUserData("standalone"))) { out.write(" standalone='yes'".getBytes("US-ASCII")); } out.write(0x3f); out.write(KET); out.write(encodeText(eol)); } // TODO warn if not outputting the declaration would be a // problem } else if (mode == Stylesheet.OUTPUT_HTML) { // Ensure that encoding is accessible String mediaType = (String) node.getUserData("media-type"); if (mediaType == null) { mediaType = "text/html"; } String contentType = mediaType + "; charset=" + ((encoding.indexOf(' ') != -1) ? "\"" + encoding + "\"" : encoding); Document doc = (node instanceof Document) ? (Document) node : node.getOwnerDocument(); Node html = null; for (Node ctx = node.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { html = ctx; break; } } if (html == null) { html = doc.createElement("html"); node.appendChild(html); } Node head = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("head".equalsIgnoreCase(name)) { head = ctx; break; } } } if (head == null) { head = doc.createElement("head"); Node c1 = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { c1 = ctx; break; } } if (c1 != null) { html.insertBefore(head, c1); } else { html.appendChild(head); } } Node meta = null; Node metaContent = null; for (Node ctx = head.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("meta".equalsIgnoreCase(name)) { NamedNodeMap metaAttrs = ctx.getAttributes(); int len = metaAttrs.getLength(); String httpEquiv = null; Node content = null; for (int i = 0; i < len; i++) { Node attr = metaAttrs.item(i); String attrName = attr.getNodeName(); if ("http-equiv".equalsIgnoreCase(attrName)) { httpEquiv = attr.getNodeValue(); } else if ("content".equalsIgnoreCase(attrName)) { content = attr; } } if ("Content-Type".equalsIgnoreCase(httpEquiv)) { meta = ctx; metaContent = content; break; } } } } if (meta == null) { meta = doc.createElement("meta"); // Insert first Node first = head.getFirstChild(); if (first == null) { head.appendChild(meta); } else { head.insertBefore(meta, first); } Node metaHttpEquiv = doc.createAttribute("http-equiv"); meta.getAttributes().setNamedItem(metaHttpEquiv); metaHttpEquiv.setNodeValue("Content-Type"); } if (metaContent == null) { metaContent = doc.createAttribute("content"); meta.getAttributes().setNamedItem(metaContent); } metaContent.setNodeValue(contentType); // phew } children = node.getFirstChild(); if (children != null) { serialize(children, out, convertToCdata); } break; case Node.DOCUMENT_TYPE_NODE: DocumentType doctype = (DocumentType) node; out.write(BRA); out.write(BANG); out.write(encodeText("DOCTYPE ")); value = doctype.getNodeName(); out.write(encodeText(value)); String publicId = doctype.getPublicId(); if (publicId != null) { out.write(encodeText(" PUBLIC ")); out.write(APOS); out.write(encodeText(publicId)); out.write(APOS); } String systemId = doctype.getSystemId(); if (systemId != null) { out.write(encodeText(" SYSTEM ")); out.write(APOS); out.write(encodeText(systemId)); out.write(APOS); } String internalSubset = doctype.getInternalSubset(); if (internalSubset != null) { out.write(encodeText(internalSubset)); } out.write(KET); out.write(eol.getBytes(encoding)); break; case Node.ENTITY_REFERENCE_NODE: value = "&" + node.getNodeValue() + ";"; out.write(encodeText(value)); break; case Node.PROCESSING_INSTRUCTION_NODE: value = "<?" + node.getNodeName() + " " + node.getNodeValue() + "?>"; out.write(encodeText(value)); Node pp = node.getParentNode(); if (pp != null && pp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; } if (defined) { undefine(uri); } }
if (html == null) { html = doc.createElement("html"); node.appendChild(html); }
if (html != null) {
private void doSerialize(final Node node, final OutputStream out, boolean convertToCdata) throws IOException { if (out == null) { throw new NullPointerException("no output stream"); } String value, prefix; Node children; String uri = node.getNamespaceURI(); boolean defined = false; short nt = node.getNodeType(); if (convertToCdata && nt == Node.TEXT_NODE) { nt = Node.CDATA_SECTION_NODE; } switch (nt) { case Node.ATTRIBUTE_NODE: prefix = node.getPrefix(); if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(uri) || XMLConstants.XMLNS_ATTRIBUTE.equals(prefix) || (prefix != null && prefix.startsWith("xmlns:"))) { String nsuri = node.getNodeValue(); if (isDefined(nsuri)) { break; } String name = node.getLocalName(); if (name == null) { name = node.getNodeName(); } define(nsuri, name); } else if (uri != null && !isDefined(uri)) { prefix = define(uri, prefix); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(nsvalue.getBytes(encoding)); defined = true; } out.write(SPACE); String a_nodeName = node.getNodeName(); out.write(encodeText(a_nodeName)); String a_nodeValue = node.getNodeValue(); if (mode == Stylesheet.OUTPUT_HTML && a_nodeName.equals(a_nodeValue) && isHTMLBoolean((Attr) node, a_nodeName)) { break; } out.write(EQ); value = "'" + encode(a_nodeValue, true, true) + "'"; out.write(encodeText(value)); break; case Node.ELEMENT_NODE: value = node.getNodeName(); out.write(BRA); out.write(encodeText(value)); if (uri != null && !isDefined(uri)) { prefix = define(uri, node.getPrefix()); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(encodeText(nsvalue)); defined = true; } NamedNodeMap attrs = node.getAttributes(); if (attrs != null) { int len = attrs.getLength(); for (int i = 0; i < len; i++) { Attr attr = (Attr) attrs.item(i); if (discardDefaultContent && !attr.getSpecified()) { // NOOP } else { serialize(attr, out, false); } } } convertToCdata = cdataSectionElements.contains(value); children = node.getFirstChild(); if (children == null) { out.write(SLASH); out.write(KET); } else { out.write(KET); serialize(children, out, convertToCdata); out.write(BRA); out.write(SLASH); out.write(encodeText(value)); out.write(KET); } break; case Node.TEXT_NODE: value = node.getNodeValue(); if (!"yes".equals(node.getUserData("disable-output-escaping"))) { value = encode(value, false, false); } out.write(encodeText(value)); break; case Node.CDATA_SECTION_NODE: value = "<![CDATA[" + node.getNodeValue() + "]]>"; out.write(encodeText(value)); break; case Node.COMMENT_NODE: value = "<!--" + node.getNodeValue() + "-->"; out.write(encodeText(value)); Node cp = node.getParentNode(); if (cp != null && cp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: if (mode == Stylesheet.OUTPUT_XML) { if ("UTF-16".equalsIgnoreCase(encoding)) { out.write(0xfe); out.write(0xff); } if (!"yes".equals(node.getUserData("omit-xml-declaration")) && xmlDeclaration) { Document doc = (node instanceof Document) ? (Document) node : null; String version = (doc != null) ? doc.getXmlVersion() : null; if (version == null) { version = (String) node.getUserData("version"); } if (version == null) { version = "1.0"; } out.write(BRA); out.write(0x3f); out.write("xml version='".getBytes("US-ASCII")); out.write(version.getBytes("US-ASCII")); out.write(APOS); if (!("UTF-8".equalsIgnoreCase(encoding))) { out.write(" encoding='".getBytes("US-ASCII")); out.write(encoding.getBytes("US-ASCII")); out.write(APOS); } if ((doc != null && doc.getXmlStandalone()) || "yes".equals(node.getUserData("standalone"))) { out.write(" standalone='yes'".getBytes("US-ASCII")); } out.write(0x3f); out.write(KET); out.write(encodeText(eol)); } // TODO warn if not outputting the declaration would be a // problem } else if (mode == Stylesheet.OUTPUT_HTML) { // Ensure that encoding is accessible String mediaType = (String) node.getUserData("media-type"); if (mediaType == null) { mediaType = "text/html"; } String contentType = mediaType + "; charset=" + ((encoding.indexOf(' ') != -1) ? "\"" + encoding + "\"" : encoding); Document doc = (node instanceof Document) ? (Document) node : node.getOwnerDocument(); Node html = null; for (Node ctx = node.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { html = ctx; break; } } if (html == null) { html = doc.createElement("html"); node.appendChild(html); } Node head = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("head".equalsIgnoreCase(name)) { head = ctx; break; } } } if (head == null) { head = doc.createElement("head"); Node c1 = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { c1 = ctx; break; } } if (c1 != null) { html.insertBefore(head, c1); } else { html.appendChild(head); } } Node meta = null; Node metaContent = null; for (Node ctx = head.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("meta".equalsIgnoreCase(name)) { NamedNodeMap metaAttrs = ctx.getAttributes(); int len = metaAttrs.getLength(); String httpEquiv = null; Node content = null; for (int i = 0; i < len; i++) { Node attr = metaAttrs.item(i); String attrName = attr.getNodeName(); if ("http-equiv".equalsIgnoreCase(attrName)) { httpEquiv = attr.getNodeValue(); } else if ("content".equalsIgnoreCase(attrName)) { content = attr; } } if ("Content-Type".equalsIgnoreCase(httpEquiv)) { meta = ctx; metaContent = content; break; } } } } if (meta == null) { meta = doc.createElement("meta"); // Insert first Node first = head.getFirstChild(); if (first == null) { head.appendChild(meta); } else { head.insertBefore(meta, first); } Node metaHttpEquiv = doc.createAttribute("http-equiv"); meta.getAttributes().setNamedItem(metaHttpEquiv); metaHttpEquiv.setNodeValue("Content-Type"); } if (metaContent == null) { metaContent = doc.createAttribute("content"); meta.getAttributes().setNamedItem(metaContent); } metaContent.setNodeValue(contentType); // phew } children = node.getFirstChild(); if (children != null) { serialize(children, out, convertToCdata); } break; case Node.DOCUMENT_TYPE_NODE: DocumentType doctype = (DocumentType) node; out.write(BRA); out.write(BANG); out.write(encodeText("DOCTYPE ")); value = doctype.getNodeName(); out.write(encodeText(value)); String publicId = doctype.getPublicId(); if (publicId != null) { out.write(encodeText(" PUBLIC ")); out.write(APOS); out.write(encodeText(publicId)); out.write(APOS); } String systemId = doctype.getSystemId(); if (systemId != null) { out.write(encodeText(" SYSTEM ")); out.write(APOS); out.write(encodeText(systemId)); out.write(APOS); } String internalSubset = doctype.getInternalSubset(); if (internalSubset != null) { out.write(encodeText(internalSubset)); } out.write(KET); out.write(eol.getBytes(encoding)); break; case Node.ENTITY_REFERENCE_NODE: value = "&" + node.getNodeValue() + ";"; out.write(encodeText(value)); break; case Node.PROCESSING_INSTRUCTION_NODE: value = "<?" + node.getNodeName() + " " + node.getNodeValue() + "?>"; out.write(encodeText(value)); Node pp = node.getParentNode(); if (pp != null && pp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; } if (defined) { undefine(uri); } }
if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("head".equalsIgnoreCase(name))
if (isHTMLElement(ctx, "head"))
private void doSerialize(final Node node, final OutputStream out, boolean convertToCdata) throws IOException { if (out == null) { throw new NullPointerException("no output stream"); } String value, prefix; Node children; String uri = node.getNamespaceURI(); boolean defined = false; short nt = node.getNodeType(); if (convertToCdata && nt == Node.TEXT_NODE) { nt = Node.CDATA_SECTION_NODE; } switch (nt) { case Node.ATTRIBUTE_NODE: prefix = node.getPrefix(); if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(uri) || XMLConstants.XMLNS_ATTRIBUTE.equals(prefix) || (prefix != null && prefix.startsWith("xmlns:"))) { String nsuri = node.getNodeValue(); if (isDefined(nsuri)) { break; } String name = node.getLocalName(); if (name == null) { name = node.getNodeName(); } define(nsuri, name); } else if (uri != null && !isDefined(uri)) { prefix = define(uri, prefix); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(nsvalue.getBytes(encoding)); defined = true; } out.write(SPACE); String a_nodeName = node.getNodeName(); out.write(encodeText(a_nodeName)); String a_nodeValue = node.getNodeValue(); if (mode == Stylesheet.OUTPUT_HTML && a_nodeName.equals(a_nodeValue) && isHTMLBoolean((Attr) node, a_nodeName)) { break; } out.write(EQ); value = "'" + encode(a_nodeValue, true, true) + "'"; out.write(encodeText(value)); break; case Node.ELEMENT_NODE: value = node.getNodeName(); out.write(BRA); out.write(encodeText(value)); if (uri != null && !isDefined(uri)) { prefix = define(uri, node.getPrefix()); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(encodeText(nsvalue)); defined = true; } NamedNodeMap attrs = node.getAttributes(); if (attrs != null) { int len = attrs.getLength(); for (int i = 0; i < len; i++) { Attr attr = (Attr) attrs.item(i); if (discardDefaultContent && !attr.getSpecified()) { // NOOP } else { serialize(attr, out, false); } } } convertToCdata = cdataSectionElements.contains(value); children = node.getFirstChild(); if (children == null) { out.write(SLASH); out.write(KET); } else { out.write(KET); serialize(children, out, convertToCdata); out.write(BRA); out.write(SLASH); out.write(encodeText(value)); out.write(KET); } break; case Node.TEXT_NODE: value = node.getNodeValue(); if (!"yes".equals(node.getUserData("disable-output-escaping"))) { value = encode(value, false, false); } out.write(encodeText(value)); break; case Node.CDATA_SECTION_NODE: value = "<![CDATA[" + node.getNodeValue() + "]]>"; out.write(encodeText(value)); break; case Node.COMMENT_NODE: value = "<!--" + node.getNodeValue() + "-->"; out.write(encodeText(value)); Node cp = node.getParentNode(); if (cp != null && cp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: if (mode == Stylesheet.OUTPUT_XML) { if ("UTF-16".equalsIgnoreCase(encoding)) { out.write(0xfe); out.write(0xff); } if (!"yes".equals(node.getUserData("omit-xml-declaration")) && xmlDeclaration) { Document doc = (node instanceof Document) ? (Document) node : null; String version = (doc != null) ? doc.getXmlVersion() : null; if (version == null) { version = (String) node.getUserData("version"); } if (version == null) { version = "1.0"; } out.write(BRA); out.write(0x3f); out.write("xml version='".getBytes("US-ASCII")); out.write(version.getBytes("US-ASCII")); out.write(APOS); if (!("UTF-8".equalsIgnoreCase(encoding))) { out.write(" encoding='".getBytes("US-ASCII")); out.write(encoding.getBytes("US-ASCII")); out.write(APOS); } if ((doc != null && doc.getXmlStandalone()) || "yes".equals(node.getUserData("standalone"))) { out.write(" standalone='yes'".getBytes("US-ASCII")); } out.write(0x3f); out.write(KET); out.write(encodeText(eol)); } // TODO warn if not outputting the declaration would be a // problem } else if (mode == Stylesheet.OUTPUT_HTML) { // Ensure that encoding is accessible String mediaType = (String) node.getUserData("media-type"); if (mediaType == null) { mediaType = "text/html"; } String contentType = mediaType + "; charset=" + ((encoding.indexOf(' ') != -1) ? "\"" + encoding + "\"" : encoding); Document doc = (node instanceof Document) ? (Document) node : node.getOwnerDocument(); Node html = null; for (Node ctx = node.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { html = ctx; break; } } if (html == null) { html = doc.createElement("html"); node.appendChild(html); } Node head = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("head".equalsIgnoreCase(name)) { head = ctx; break; } } } if (head == null) { head = doc.createElement("head"); Node c1 = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { c1 = ctx; break; } } if (c1 != null) { html.insertBefore(head, c1); } else { html.appendChild(head); } } Node meta = null; Node metaContent = null; for (Node ctx = head.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("meta".equalsIgnoreCase(name)) { NamedNodeMap metaAttrs = ctx.getAttributes(); int len = metaAttrs.getLength(); String httpEquiv = null; Node content = null; for (int i = 0; i < len; i++) { Node attr = metaAttrs.item(i); String attrName = attr.getNodeName(); if ("http-equiv".equalsIgnoreCase(attrName)) { httpEquiv = attr.getNodeValue(); } else if ("content".equalsIgnoreCase(attrName)) { content = attr; } } if ("Content-Type".equalsIgnoreCase(httpEquiv)) { meta = ctx; metaContent = content; break; } } } } if (meta == null) { meta = doc.createElement("meta"); // Insert first Node first = head.getFirstChild(); if (first == null) { head.appendChild(meta); } else { head.insertBefore(meta, first); } Node metaHttpEquiv = doc.createAttribute("http-equiv"); meta.getAttributes().setNamedItem(metaHttpEquiv); metaHttpEquiv.setNodeValue("Content-Type"); } if (metaContent == null) { metaContent = doc.createAttribute("content"); meta.getAttributes().setNamedItem(metaContent); } metaContent.setNodeValue(contentType); // phew } children = node.getFirstChild(); if (children != null) { serialize(children, out, convertToCdata); } break; case Node.DOCUMENT_TYPE_NODE: DocumentType doctype = (DocumentType) node; out.write(BRA); out.write(BANG); out.write(encodeText("DOCTYPE ")); value = doctype.getNodeName(); out.write(encodeText(value)); String publicId = doctype.getPublicId(); if (publicId != null) { out.write(encodeText(" PUBLIC ")); out.write(APOS); out.write(encodeText(publicId)); out.write(APOS); } String systemId = doctype.getSystemId(); if (systemId != null) { out.write(encodeText(" SYSTEM ")); out.write(APOS); out.write(encodeText(systemId)); out.write(APOS); } String internalSubset = doctype.getInternalSubset(); if (internalSubset != null) { out.write(encodeText(internalSubset)); } out.write(KET); out.write(eol.getBytes(encoding)); break; case Node.ENTITY_REFERENCE_NODE: value = "&" + node.getNodeValue() + ";"; out.write(encodeText(value)); break; case Node.PROCESSING_INSTRUCTION_NODE: value = "<?" + node.getNodeName() + " " + node.getNodeValue() + "?>"; out.write(encodeText(value)); Node pp = node.getParentNode(); if (pp != null && pp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; } if (defined) { undefine(uri); } }
} if (head == null) { head = doc.createElement("head"); Node c1 = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE)
if (head != null)
private void doSerialize(final Node node, final OutputStream out, boolean convertToCdata) throws IOException { if (out == null) { throw new NullPointerException("no output stream"); } String value, prefix; Node children; String uri = node.getNamespaceURI(); boolean defined = false; short nt = node.getNodeType(); if (convertToCdata && nt == Node.TEXT_NODE) { nt = Node.CDATA_SECTION_NODE; } switch (nt) { case Node.ATTRIBUTE_NODE: prefix = node.getPrefix(); if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(uri) || XMLConstants.XMLNS_ATTRIBUTE.equals(prefix) || (prefix != null && prefix.startsWith("xmlns:"))) { String nsuri = node.getNodeValue(); if (isDefined(nsuri)) { break; } String name = node.getLocalName(); if (name == null) { name = node.getNodeName(); } define(nsuri, name); } else if (uri != null && !isDefined(uri)) { prefix = define(uri, prefix); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(nsvalue.getBytes(encoding)); defined = true; } out.write(SPACE); String a_nodeName = node.getNodeName(); out.write(encodeText(a_nodeName)); String a_nodeValue = node.getNodeValue(); if (mode == Stylesheet.OUTPUT_HTML && a_nodeName.equals(a_nodeValue) && isHTMLBoolean((Attr) node, a_nodeName)) { break; } out.write(EQ); value = "'" + encode(a_nodeValue, true, true) + "'"; out.write(encodeText(value)); break; case Node.ELEMENT_NODE: value = node.getNodeName(); out.write(BRA); out.write(encodeText(value)); if (uri != null && !isDefined(uri)) { prefix = define(uri, node.getPrefix()); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(encodeText(nsvalue)); defined = true; } NamedNodeMap attrs = node.getAttributes(); if (attrs != null) { int len = attrs.getLength(); for (int i = 0; i < len; i++) { Attr attr = (Attr) attrs.item(i); if (discardDefaultContent && !attr.getSpecified()) { // NOOP } else { serialize(attr, out, false); } } } convertToCdata = cdataSectionElements.contains(value); children = node.getFirstChild(); if (children == null) { out.write(SLASH); out.write(KET); } else { out.write(KET); serialize(children, out, convertToCdata); out.write(BRA); out.write(SLASH); out.write(encodeText(value)); out.write(KET); } break; case Node.TEXT_NODE: value = node.getNodeValue(); if (!"yes".equals(node.getUserData("disable-output-escaping"))) { value = encode(value, false, false); } out.write(encodeText(value)); break; case Node.CDATA_SECTION_NODE: value = "<![CDATA[" + node.getNodeValue() + "]]>"; out.write(encodeText(value)); break; case Node.COMMENT_NODE: value = "<!--" + node.getNodeValue() + "-->"; out.write(encodeText(value)); Node cp = node.getParentNode(); if (cp != null && cp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: if (mode == Stylesheet.OUTPUT_XML) { if ("UTF-16".equalsIgnoreCase(encoding)) { out.write(0xfe); out.write(0xff); } if (!"yes".equals(node.getUserData("omit-xml-declaration")) && xmlDeclaration) { Document doc = (node instanceof Document) ? (Document) node : null; String version = (doc != null) ? doc.getXmlVersion() : null; if (version == null) { version = (String) node.getUserData("version"); } if (version == null) { version = "1.0"; } out.write(BRA); out.write(0x3f); out.write("xml version='".getBytes("US-ASCII")); out.write(version.getBytes("US-ASCII")); out.write(APOS); if (!("UTF-8".equalsIgnoreCase(encoding))) { out.write(" encoding='".getBytes("US-ASCII")); out.write(encoding.getBytes("US-ASCII")); out.write(APOS); } if ((doc != null && doc.getXmlStandalone()) || "yes".equals(node.getUserData("standalone"))) { out.write(" standalone='yes'".getBytes("US-ASCII")); } out.write(0x3f); out.write(KET); out.write(encodeText(eol)); } // TODO warn if not outputting the declaration would be a // problem } else if (mode == Stylesheet.OUTPUT_HTML) { // Ensure that encoding is accessible String mediaType = (String) node.getUserData("media-type"); if (mediaType == null) { mediaType = "text/html"; } String contentType = mediaType + "; charset=" + ((encoding.indexOf(' ') != -1) ? "\"" + encoding + "\"" : encoding); Document doc = (node instanceof Document) ? (Document) node : node.getOwnerDocument(); Node html = null; for (Node ctx = node.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { html = ctx; break; } } if (html == null) { html = doc.createElement("html"); node.appendChild(html); } Node head = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("head".equalsIgnoreCase(name)) { head = ctx; break; } } } if (head == null) { head = doc.createElement("head"); Node c1 = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { c1 = ctx; break; } } if (c1 != null) { html.insertBefore(head, c1); } else { html.appendChild(head); } } Node meta = null; Node metaContent = null; for (Node ctx = head.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("meta".equalsIgnoreCase(name)) { NamedNodeMap metaAttrs = ctx.getAttributes(); int len = metaAttrs.getLength(); String httpEquiv = null; Node content = null; for (int i = 0; i < len; i++) { Node attr = metaAttrs.item(i); String attrName = attr.getNodeName(); if ("http-equiv".equalsIgnoreCase(attrName)) { httpEquiv = attr.getNodeValue(); } else if ("content".equalsIgnoreCase(attrName)) { content = attr; } } if ("Content-Type".equalsIgnoreCase(httpEquiv)) { meta = ctx; metaContent = content; break; } } } } if (meta == null) { meta = doc.createElement("meta"); // Insert first Node first = head.getFirstChild(); if (first == null) { head.appendChild(meta); } else { head.insertBefore(meta, first); } Node metaHttpEquiv = doc.createAttribute("http-equiv"); meta.getAttributes().setNamedItem(metaHttpEquiv); metaHttpEquiv.setNodeValue("Content-Type"); } if (metaContent == null) { metaContent = doc.createAttribute("content"); meta.getAttributes().setNamedItem(metaContent); } metaContent.setNodeValue(contentType); // phew } children = node.getFirstChild(); if (children != null) { serialize(children, out, convertToCdata); } break; case Node.DOCUMENT_TYPE_NODE: DocumentType doctype = (DocumentType) node; out.write(BRA); out.write(BANG); out.write(encodeText("DOCTYPE ")); value = doctype.getNodeName(); out.write(encodeText(value)); String publicId = doctype.getPublicId(); if (publicId != null) { out.write(encodeText(" PUBLIC ")); out.write(APOS); out.write(encodeText(publicId)); out.write(APOS); } String systemId = doctype.getSystemId(); if (systemId != null) { out.write(encodeText(" SYSTEM ")); out.write(APOS); out.write(encodeText(systemId)); out.write(APOS); } String internalSubset = doctype.getInternalSubset(); if (internalSubset != null) { out.write(encodeText(internalSubset)); } out.write(KET); out.write(eol.getBytes(encoding)); break; case Node.ENTITY_REFERENCE_NODE: value = "&" + node.getNodeValue() + ";"; out.write(encodeText(value)); break; case Node.PROCESSING_INSTRUCTION_NODE: value = "<?" + node.getNodeName() + " " + node.getNodeValue() + "?>"; out.write(encodeText(value)); Node pp = node.getParentNode(); if (pp != null && pp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; } if (defined) { undefine(uri); } }
c1 = ctx; break; } } if (c1 != null) { html.insertBefore(head, c1); } else { html.appendChild(head); } }
private void doSerialize(final Node node, final OutputStream out, boolean convertToCdata) throws IOException { if (out == null) { throw new NullPointerException("no output stream"); } String value, prefix; Node children; String uri = node.getNamespaceURI(); boolean defined = false; short nt = node.getNodeType(); if (convertToCdata && nt == Node.TEXT_NODE) { nt = Node.CDATA_SECTION_NODE; } switch (nt) { case Node.ATTRIBUTE_NODE: prefix = node.getPrefix(); if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(uri) || XMLConstants.XMLNS_ATTRIBUTE.equals(prefix) || (prefix != null && prefix.startsWith("xmlns:"))) { String nsuri = node.getNodeValue(); if (isDefined(nsuri)) { break; } String name = node.getLocalName(); if (name == null) { name = node.getNodeName(); } define(nsuri, name); } else if (uri != null && !isDefined(uri)) { prefix = define(uri, prefix); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(nsvalue.getBytes(encoding)); defined = true; } out.write(SPACE); String a_nodeName = node.getNodeName(); out.write(encodeText(a_nodeName)); String a_nodeValue = node.getNodeValue(); if (mode == Stylesheet.OUTPUT_HTML && a_nodeName.equals(a_nodeValue) && isHTMLBoolean((Attr) node, a_nodeName)) { break; } out.write(EQ); value = "'" + encode(a_nodeValue, true, true) + "'"; out.write(encodeText(value)); break; case Node.ELEMENT_NODE: value = node.getNodeName(); out.write(BRA); out.write(encodeText(value)); if (uri != null && !isDefined(uri)) { prefix = define(uri, node.getPrefix()); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(encodeText(nsvalue)); defined = true; } NamedNodeMap attrs = node.getAttributes(); if (attrs != null) { int len = attrs.getLength(); for (int i = 0; i < len; i++) { Attr attr = (Attr) attrs.item(i); if (discardDefaultContent && !attr.getSpecified()) { // NOOP } else { serialize(attr, out, false); } } } convertToCdata = cdataSectionElements.contains(value); children = node.getFirstChild(); if (children == null) { out.write(SLASH); out.write(KET); } else { out.write(KET); serialize(children, out, convertToCdata); out.write(BRA); out.write(SLASH); out.write(encodeText(value)); out.write(KET); } break; case Node.TEXT_NODE: value = node.getNodeValue(); if (!"yes".equals(node.getUserData("disable-output-escaping"))) { value = encode(value, false, false); } out.write(encodeText(value)); break; case Node.CDATA_SECTION_NODE: value = "<![CDATA[" + node.getNodeValue() + "]]>"; out.write(encodeText(value)); break; case Node.COMMENT_NODE: value = "<!--" + node.getNodeValue() + "-->"; out.write(encodeText(value)); Node cp = node.getParentNode(); if (cp != null && cp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: if (mode == Stylesheet.OUTPUT_XML) { if ("UTF-16".equalsIgnoreCase(encoding)) { out.write(0xfe); out.write(0xff); } if (!"yes".equals(node.getUserData("omit-xml-declaration")) && xmlDeclaration) { Document doc = (node instanceof Document) ? (Document) node : null; String version = (doc != null) ? doc.getXmlVersion() : null; if (version == null) { version = (String) node.getUserData("version"); } if (version == null) { version = "1.0"; } out.write(BRA); out.write(0x3f); out.write("xml version='".getBytes("US-ASCII")); out.write(version.getBytes("US-ASCII")); out.write(APOS); if (!("UTF-8".equalsIgnoreCase(encoding))) { out.write(" encoding='".getBytes("US-ASCII")); out.write(encoding.getBytes("US-ASCII")); out.write(APOS); } if ((doc != null && doc.getXmlStandalone()) || "yes".equals(node.getUserData("standalone"))) { out.write(" standalone='yes'".getBytes("US-ASCII")); } out.write(0x3f); out.write(KET); out.write(encodeText(eol)); } // TODO warn if not outputting the declaration would be a // problem } else if (mode == Stylesheet.OUTPUT_HTML) { // Ensure that encoding is accessible String mediaType = (String) node.getUserData("media-type"); if (mediaType == null) { mediaType = "text/html"; } String contentType = mediaType + "; charset=" + ((encoding.indexOf(' ') != -1) ? "\"" + encoding + "\"" : encoding); Document doc = (node instanceof Document) ? (Document) node : node.getOwnerDocument(); Node html = null; for (Node ctx = node.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { html = ctx; break; } } if (html == null) { html = doc.createElement("html"); node.appendChild(html); } Node head = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("head".equalsIgnoreCase(name)) { head = ctx; break; } } } if (head == null) { head = doc.createElement("head"); Node c1 = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { c1 = ctx; break; } } if (c1 != null) { html.insertBefore(head, c1); } else { html.appendChild(head); } } Node meta = null; Node metaContent = null; for (Node ctx = head.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("meta".equalsIgnoreCase(name)) { NamedNodeMap metaAttrs = ctx.getAttributes(); int len = metaAttrs.getLength(); String httpEquiv = null; Node content = null; for (int i = 0; i < len; i++) { Node attr = metaAttrs.item(i); String attrName = attr.getNodeName(); if ("http-equiv".equalsIgnoreCase(attrName)) { httpEquiv = attr.getNodeValue(); } else if ("content".equalsIgnoreCase(attrName)) { content = attr; } } if ("Content-Type".equalsIgnoreCase(httpEquiv)) { meta = ctx; metaContent = content; break; } } } } if (meta == null) { meta = doc.createElement("meta"); // Insert first Node first = head.getFirstChild(); if (first == null) { head.appendChild(meta); } else { head.insertBefore(meta, first); } Node metaHttpEquiv = doc.createAttribute("http-equiv"); meta.getAttributes().setNamedItem(metaHttpEquiv); metaHttpEquiv.setNodeValue("Content-Type"); } if (metaContent == null) { metaContent = doc.createAttribute("content"); meta.getAttributes().setNamedItem(metaContent); } metaContent.setNodeValue(contentType); // phew } children = node.getFirstChild(); if (children != null) { serialize(children, out, convertToCdata); } break; case Node.DOCUMENT_TYPE_NODE: DocumentType doctype = (DocumentType) node; out.write(BRA); out.write(BANG); out.write(encodeText("DOCTYPE ")); value = doctype.getNodeName(); out.write(encodeText(value)); String publicId = doctype.getPublicId(); if (publicId != null) { out.write(encodeText(" PUBLIC ")); out.write(APOS); out.write(encodeText(publicId)); out.write(APOS); } String systemId = doctype.getSystemId(); if (systemId != null) { out.write(encodeText(" SYSTEM ")); out.write(APOS); out.write(encodeText(systemId)); out.write(APOS); } String internalSubset = doctype.getInternalSubset(); if (internalSubset != null) { out.write(encodeText(internalSubset)); } out.write(KET); out.write(eol.getBytes(encoding)); break; case Node.ENTITY_REFERENCE_NODE: value = "&" + node.getNodeValue() + ";"; out.write(encodeText(value)); break; case Node.PROCESSING_INSTRUCTION_NODE: value = "<?" + node.getNodeName() + " " + node.getNodeValue() + "?>"; out.write(encodeText(value)); Node pp = node.getParentNode(); if (pp != null && pp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; } if (defined) { undefine(uri); } }
if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("meta".equalsIgnoreCase(name))
if (isHTMLElement(ctx, "meta"))
private void doSerialize(final Node node, final OutputStream out, boolean convertToCdata) throws IOException { if (out == null) { throw new NullPointerException("no output stream"); } String value, prefix; Node children; String uri = node.getNamespaceURI(); boolean defined = false; short nt = node.getNodeType(); if (convertToCdata && nt == Node.TEXT_NODE) { nt = Node.CDATA_SECTION_NODE; } switch (nt) { case Node.ATTRIBUTE_NODE: prefix = node.getPrefix(); if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(uri) || XMLConstants.XMLNS_ATTRIBUTE.equals(prefix) || (prefix != null && prefix.startsWith("xmlns:"))) { String nsuri = node.getNodeValue(); if (isDefined(nsuri)) { break; } String name = node.getLocalName(); if (name == null) { name = node.getNodeName(); } define(nsuri, name); } else if (uri != null && !isDefined(uri)) { prefix = define(uri, prefix); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(nsvalue.getBytes(encoding)); defined = true; } out.write(SPACE); String a_nodeName = node.getNodeName(); out.write(encodeText(a_nodeName)); String a_nodeValue = node.getNodeValue(); if (mode == Stylesheet.OUTPUT_HTML && a_nodeName.equals(a_nodeValue) && isHTMLBoolean((Attr) node, a_nodeName)) { break; } out.write(EQ); value = "'" + encode(a_nodeValue, true, true) + "'"; out.write(encodeText(value)); break; case Node.ELEMENT_NODE: value = node.getNodeName(); out.write(BRA); out.write(encodeText(value)); if (uri != null && !isDefined(uri)) { prefix = define(uri, node.getPrefix()); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(encodeText(nsvalue)); defined = true; } NamedNodeMap attrs = node.getAttributes(); if (attrs != null) { int len = attrs.getLength(); for (int i = 0; i < len; i++) { Attr attr = (Attr) attrs.item(i); if (discardDefaultContent && !attr.getSpecified()) { // NOOP } else { serialize(attr, out, false); } } } convertToCdata = cdataSectionElements.contains(value); children = node.getFirstChild(); if (children == null) { out.write(SLASH); out.write(KET); } else { out.write(KET); serialize(children, out, convertToCdata); out.write(BRA); out.write(SLASH); out.write(encodeText(value)); out.write(KET); } break; case Node.TEXT_NODE: value = node.getNodeValue(); if (!"yes".equals(node.getUserData("disable-output-escaping"))) { value = encode(value, false, false); } out.write(encodeText(value)); break; case Node.CDATA_SECTION_NODE: value = "<![CDATA[" + node.getNodeValue() + "]]>"; out.write(encodeText(value)); break; case Node.COMMENT_NODE: value = "<!--" + node.getNodeValue() + "-->"; out.write(encodeText(value)); Node cp = node.getParentNode(); if (cp != null && cp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: if (mode == Stylesheet.OUTPUT_XML) { if ("UTF-16".equalsIgnoreCase(encoding)) { out.write(0xfe); out.write(0xff); } if (!"yes".equals(node.getUserData("omit-xml-declaration")) && xmlDeclaration) { Document doc = (node instanceof Document) ? (Document) node : null; String version = (doc != null) ? doc.getXmlVersion() : null; if (version == null) { version = (String) node.getUserData("version"); } if (version == null) { version = "1.0"; } out.write(BRA); out.write(0x3f); out.write("xml version='".getBytes("US-ASCII")); out.write(version.getBytes("US-ASCII")); out.write(APOS); if (!("UTF-8".equalsIgnoreCase(encoding))) { out.write(" encoding='".getBytes("US-ASCII")); out.write(encoding.getBytes("US-ASCII")); out.write(APOS); } if ((doc != null && doc.getXmlStandalone()) || "yes".equals(node.getUserData("standalone"))) { out.write(" standalone='yes'".getBytes("US-ASCII")); } out.write(0x3f); out.write(KET); out.write(encodeText(eol)); } // TODO warn if not outputting the declaration would be a // problem } else if (mode == Stylesheet.OUTPUT_HTML) { // Ensure that encoding is accessible String mediaType = (String) node.getUserData("media-type"); if (mediaType == null) { mediaType = "text/html"; } String contentType = mediaType + "; charset=" + ((encoding.indexOf(' ') != -1) ? "\"" + encoding + "\"" : encoding); Document doc = (node instanceof Document) ? (Document) node : node.getOwnerDocument(); Node html = null; for (Node ctx = node.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { html = ctx; break; } } if (html == null) { html = doc.createElement("html"); node.appendChild(html); } Node head = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("head".equalsIgnoreCase(name)) { head = ctx; break; } } } if (head == null) { head = doc.createElement("head"); Node c1 = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { c1 = ctx; break; } } if (c1 != null) { html.insertBefore(head, c1); } else { html.appendChild(head); } } Node meta = null; Node metaContent = null; for (Node ctx = head.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("meta".equalsIgnoreCase(name)) { NamedNodeMap metaAttrs = ctx.getAttributes(); int len = metaAttrs.getLength(); String httpEquiv = null; Node content = null; for (int i = 0; i < len; i++) { Node attr = metaAttrs.item(i); String attrName = attr.getNodeName(); if ("http-equiv".equalsIgnoreCase(attrName)) { httpEquiv = attr.getNodeValue(); } else if ("content".equalsIgnoreCase(attrName)) { content = attr; } } if ("Content-Type".equalsIgnoreCase(httpEquiv)) { meta = ctx; metaContent = content; break; } } } } if (meta == null) { meta = doc.createElement("meta"); // Insert first Node first = head.getFirstChild(); if (first == null) { head.appendChild(meta); } else { head.insertBefore(meta, first); } Node metaHttpEquiv = doc.createAttribute("http-equiv"); meta.getAttributes().setNamedItem(metaHttpEquiv); metaHttpEquiv.setNodeValue("Content-Type"); } if (metaContent == null) { metaContent = doc.createAttribute("content"); meta.getAttributes().setNamedItem(metaContent); } metaContent.setNodeValue(contentType); // phew } children = node.getFirstChild(); if (children != null) { serialize(children, out, convertToCdata); } break; case Node.DOCUMENT_TYPE_NODE: DocumentType doctype = (DocumentType) node; out.write(BRA); out.write(BANG); out.write(encodeText("DOCTYPE ")); value = doctype.getNodeName(); out.write(encodeText(value)); String publicId = doctype.getPublicId(); if (publicId != null) { out.write(encodeText(" PUBLIC ")); out.write(APOS); out.write(encodeText(publicId)); out.write(APOS); } String systemId = doctype.getSystemId(); if (systemId != null) { out.write(encodeText(" SYSTEM ")); out.write(APOS); out.write(encodeText(systemId)); out.write(APOS); } String internalSubset = doctype.getInternalSubset(); if (internalSubset != null) { out.write(encodeText(internalSubset)); } out.write(KET); out.write(eol.getBytes(encoding)); break; case Node.ENTITY_REFERENCE_NODE: value = "&" + node.getNodeValue() + ";"; out.write(encodeText(value)); break; case Node.PROCESSING_INSTRUCTION_NODE: value = "<?" + node.getNodeName() + " " + node.getNodeValue() + "?>"; out.write(encodeText(value)); Node pp = node.getParentNode(); if (pp != null && pp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; } if (defined) { undefine(uri); } }
htmlEncoded = true; } }
private void doSerialize(final Node node, final OutputStream out, boolean convertToCdata) throws IOException { if (out == null) { throw new NullPointerException("no output stream"); } String value, prefix; Node children; String uri = node.getNamespaceURI(); boolean defined = false; short nt = node.getNodeType(); if (convertToCdata && nt == Node.TEXT_NODE) { nt = Node.CDATA_SECTION_NODE; } switch (nt) { case Node.ATTRIBUTE_NODE: prefix = node.getPrefix(); if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(uri) || XMLConstants.XMLNS_ATTRIBUTE.equals(prefix) || (prefix != null && prefix.startsWith("xmlns:"))) { String nsuri = node.getNodeValue(); if (isDefined(nsuri)) { break; } String name = node.getLocalName(); if (name == null) { name = node.getNodeName(); } define(nsuri, name); } else if (uri != null && !isDefined(uri)) { prefix = define(uri, prefix); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(nsvalue.getBytes(encoding)); defined = true; } out.write(SPACE); String a_nodeName = node.getNodeName(); out.write(encodeText(a_nodeName)); String a_nodeValue = node.getNodeValue(); if (mode == Stylesheet.OUTPUT_HTML && a_nodeName.equals(a_nodeValue) && isHTMLBoolean((Attr) node, a_nodeName)) { break; } out.write(EQ); value = "'" + encode(a_nodeValue, true, true) + "'"; out.write(encodeText(value)); break; case Node.ELEMENT_NODE: value = node.getNodeName(); out.write(BRA); out.write(encodeText(value)); if (uri != null && !isDefined(uri)) { prefix = define(uri, node.getPrefix()); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(encodeText(nsvalue)); defined = true; } NamedNodeMap attrs = node.getAttributes(); if (attrs != null) { int len = attrs.getLength(); for (int i = 0; i < len; i++) { Attr attr = (Attr) attrs.item(i); if (discardDefaultContent && !attr.getSpecified()) { // NOOP } else { serialize(attr, out, false); } } } convertToCdata = cdataSectionElements.contains(value); children = node.getFirstChild(); if (children == null) { out.write(SLASH); out.write(KET); } else { out.write(KET); serialize(children, out, convertToCdata); out.write(BRA); out.write(SLASH); out.write(encodeText(value)); out.write(KET); } break; case Node.TEXT_NODE: value = node.getNodeValue(); if (!"yes".equals(node.getUserData("disable-output-escaping"))) { value = encode(value, false, false); } out.write(encodeText(value)); break; case Node.CDATA_SECTION_NODE: value = "<![CDATA[" + node.getNodeValue() + "]]>"; out.write(encodeText(value)); break; case Node.COMMENT_NODE: value = "<!--" + node.getNodeValue() + "-->"; out.write(encodeText(value)); Node cp = node.getParentNode(); if (cp != null && cp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: if (mode == Stylesheet.OUTPUT_XML) { if ("UTF-16".equalsIgnoreCase(encoding)) { out.write(0xfe); out.write(0xff); } if (!"yes".equals(node.getUserData("omit-xml-declaration")) && xmlDeclaration) { Document doc = (node instanceof Document) ? (Document) node : null; String version = (doc != null) ? doc.getXmlVersion() : null; if (version == null) { version = (String) node.getUserData("version"); } if (version == null) { version = "1.0"; } out.write(BRA); out.write(0x3f); out.write("xml version='".getBytes("US-ASCII")); out.write(version.getBytes("US-ASCII")); out.write(APOS); if (!("UTF-8".equalsIgnoreCase(encoding))) { out.write(" encoding='".getBytes("US-ASCII")); out.write(encoding.getBytes("US-ASCII")); out.write(APOS); } if ((doc != null && doc.getXmlStandalone()) || "yes".equals(node.getUserData("standalone"))) { out.write(" standalone='yes'".getBytes("US-ASCII")); } out.write(0x3f); out.write(KET); out.write(encodeText(eol)); } // TODO warn if not outputting the declaration would be a // problem } else if (mode == Stylesheet.OUTPUT_HTML) { // Ensure that encoding is accessible String mediaType = (String) node.getUserData("media-type"); if (mediaType == null) { mediaType = "text/html"; } String contentType = mediaType + "; charset=" + ((encoding.indexOf(' ') != -1) ? "\"" + encoding + "\"" : encoding); Document doc = (node instanceof Document) ? (Document) node : node.getOwnerDocument(); Node html = null; for (Node ctx = node.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { html = ctx; break; } } if (html == null) { html = doc.createElement("html"); node.appendChild(html); } Node head = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("head".equalsIgnoreCase(name)) { head = ctx; break; } } } if (head == null) { head = doc.createElement("head"); Node c1 = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { c1 = ctx; break; } } if (c1 != null) { html.insertBefore(head, c1); } else { html.appendChild(head); } } Node meta = null; Node metaContent = null; for (Node ctx = head.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("meta".equalsIgnoreCase(name)) { NamedNodeMap metaAttrs = ctx.getAttributes(); int len = metaAttrs.getLength(); String httpEquiv = null; Node content = null; for (int i = 0; i < len; i++) { Node attr = metaAttrs.item(i); String attrName = attr.getNodeName(); if ("http-equiv".equalsIgnoreCase(attrName)) { httpEquiv = attr.getNodeValue(); } else if ("content".equalsIgnoreCase(attrName)) { content = attr; } } if ("Content-Type".equalsIgnoreCase(httpEquiv)) { meta = ctx; metaContent = content; break; } } } } if (meta == null) { meta = doc.createElement("meta"); // Insert first Node first = head.getFirstChild(); if (first == null) { head.appendChild(meta); } else { head.insertBefore(meta, first); } Node metaHttpEquiv = doc.createAttribute("http-equiv"); meta.getAttributes().setNamedItem(metaHttpEquiv); metaHttpEquiv.setNodeValue("Content-Type"); } if (metaContent == null) { metaContent = doc.createAttribute("content"); meta.getAttributes().setNamedItem(metaContent); } metaContent.setNodeValue(contentType); // phew } children = node.getFirstChild(); if (children != null) { serialize(children, out, convertToCdata); } break; case Node.DOCUMENT_TYPE_NODE: DocumentType doctype = (DocumentType) node; out.write(BRA); out.write(BANG); out.write(encodeText("DOCTYPE ")); value = doctype.getNodeName(); out.write(encodeText(value)); String publicId = doctype.getPublicId(); if (publicId != null) { out.write(encodeText(" PUBLIC ")); out.write(APOS); out.write(encodeText(publicId)); out.write(APOS); } String systemId = doctype.getSystemId(); if (systemId != null) { out.write(encodeText(" SYSTEM ")); out.write(APOS); out.write(encodeText(systemId)); out.write(APOS); } String internalSubset = doctype.getInternalSubset(); if (internalSubset != null) { out.write(encodeText(internalSubset)); } out.write(KET); out.write(eol.getBytes(encoding)); break; case Node.ENTITY_REFERENCE_NODE: value = "&" + node.getNodeValue() + ";"; out.write(encodeText(value)); break; case Node.PROCESSING_INSTRUCTION_NODE: value = "<?" + node.getNodeName() + " " + node.getNodeValue() + "?>"; out.write(encodeText(value)); Node pp = node.getParentNode(); if (pp != null && pp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; } if (defined) { undefine(uri); } }
} if (defined) { undefine(uri);
default: System.err.println("Unhandled node type: "+nt);
private void doSerialize(final Node node, final OutputStream out, boolean convertToCdata) throws IOException { if (out == null) { throw new NullPointerException("no output stream"); } String value, prefix; Node children; String uri = node.getNamespaceURI(); boolean defined = false; short nt = node.getNodeType(); if (convertToCdata && nt == Node.TEXT_NODE) { nt = Node.CDATA_SECTION_NODE; } switch (nt) { case Node.ATTRIBUTE_NODE: prefix = node.getPrefix(); if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(uri) || XMLConstants.XMLNS_ATTRIBUTE.equals(prefix) || (prefix != null && prefix.startsWith("xmlns:"))) { String nsuri = node.getNodeValue(); if (isDefined(nsuri)) { break; } String name = node.getLocalName(); if (name == null) { name = node.getNodeName(); } define(nsuri, name); } else if (uri != null && !isDefined(uri)) { prefix = define(uri, prefix); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(nsvalue.getBytes(encoding)); defined = true; } out.write(SPACE); String a_nodeName = node.getNodeName(); out.write(encodeText(a_nodeName)); String a_nodeValue = node.getNodeValue(); if (mode == Stylesheet.OUTPUT_HTML && a_nodeName.equals(a_nodeValue) && isHTMLBoolean((Attr) node, a_nodeName)) { break; } out.write(EQ); value = "'" + encode(a_nodeValue, true, true) + "'"; out.write(encodeText(value)); break; case Node.ELEMENT_NODE: value = node.getNodeName(); out.write(BRA); out.write(encodeText(value)); if (uri != null && !isDefined(uri)) { prefix = define(uri, node.getPrefix()); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(encodeText(nsvalue)); defined = true; } NamedNodeMap attrs = node.getAttributes(); if (attrs != null) { int len = attrs.getLength(); for (int i = 0; i < len; i++) { Attr attr = (Attr) attrs.item(i); if (discardDefaultContent && !attr.getSpecified()) { // NOOP } else { serialize(attr, out, false); } } } convertToCdata = cdataSectionElements.contains(value); children = node.getFirstChild(); if (children == null) { out.write(SLASH); out.write(KET); } else { out.write(KET); serialize(children, out, convertToCdata); out.write(BRA); out.write(SLASH); out.write(encodeText(value)); out.write(KET); } break; case Node.TEXT_NODE: value = node.getNodeValue(); if (!"yes".equals(node.getUserData("disable-output-escaping"))) { value = encode(value, false, false); } out.write(encodeText(value)); break; case Node.CDATA_SECTION_NODE: value = "<![CDATA[" + node.getNodeValue() + "]]>"; out.write(encodeText(value)); break; case Node.COMMENT_NODE: value = "<!--" + node.getNodeValue() + "-->"; out.write(encodeText(value)); Node cp = node.getParentNode(); if (cp != null && cp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: if (mode == Stylesheet.OUTPUT_XML) { if ("UTF-16".equalsIgnoreCase(encoding)) { out.write(0xfe); out.write(0xff); } if (!"yes".equals(node.getUserData("omit-xml-declaration")) && xmlDeclaration) { Document doc = (node instanceof Document) ? (Document) node : null; String version = (doc != null) ? doc.getXmlVersion() : null; if (version == null) { version = (String) node.getUserData("version"); } if (version == null) { version = "1.0"; } out.write(BRA); out.write(0x3f); out.write("xml version='".getBytes("US-ASCII")); out.write(version.getBytes("US-ASCII")); out.write(APOS); if (!("UTF-8".equalsIgnoreCase(encoding))) { out.write(" encoding='".getBytes("US-ASCII")); out.write(encoding.getBytes("US-ASCII")); out.write(APOS); } if ((doc != null && doc.getXmlStandalone()) || "yes".equals(node.getUserData("standalone"))) { out.write(" standalone='yes'".getBytes("US-ASCII")); } out.write(0x3f); out.write(KET); out.write(encodeText(eol)); } // TODO warn if not outputting the declaration would be a // problem } else if (mode == Stylesheet.OUTPUT_HTML) { // Ensure that encoding is accessible String mediaType = (String) node.getUserData("media-type"); if (mediaType == null) { mediaType = "text/html"; } String contentType = mediaType + "; charset=" + ((encoding.indexOf(' ') != -1) ? "\"" + encoding + "\"" : encoding); Document doc = (node instanceof Document) ? (Document) node : node.getOwnerDocument(); Node html = null; for (Node ctx = node.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { html = ctx; break; } } if (html == null) { html = doc.createElement("html"); node.appendChild(html); } Node head = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("head".equalsIgnoreCase(name)) { head = ctx; break; } } } if (head == null) { head = doc.createElement("head"); Node c1 = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { c1 = ctx; break; } } if (c1 != null) { html.insertBefore(head, c1); } else { html.appendChild(head); } } Node meta = null; Node metaContent = null; for (Node ctx = head.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("meta".equalsIgnoreCase(name)) { NamedNodeMap metaAttrs = ctx.getAttributes(); int len = metaAttrs.getLength(); String httpEquiv = null; Node content = null; for (int i = 0; i < len; i++) { Node attr = metaAttrs.item(i); String attrName = attr.getNodeName(); if ("http-equiv".equalsIgnoreCase(attrName)) { httpEquiv = attr.getNodeValue(); } else if ("content".equalsIgnoreCase(attrName)) { content = attr; } } if ("Content-Type".equalsIgnoreCase(httpEquiv)) { meta = ctx; metaContent = content; break; } } } } if (meta == null) { meta = doc.createElement("meta"); // Insert first Node first = head.getFirstChild(); if (first == null) { head.appendChild(meta); } else { head.insertBefore(meta, first); } Node metaHttpEquiv = doc.createAttribute("http-equiv"); meta.getAttributes().setNamedItem(metaHttpEquiv); metaHttpEquiv.setNodeValue("Content-Type"); } if (metaContent == null) { metaContent = doc.createAttribute("content"); meta.getAttributes().setNamedItem(metaContent); } metaContent.setNodeValue(contentType); // phew } children = node.getFirstChild(); if (children != null) { serialize(children, out, convertToCdata); } break; case Node.DOCUMENT_TYPE_NODE: DocumentType doctype = (DocumentType) node; out.write(BRA); out.write(BANG); out.write(encodeText("DOCTYPE ")); value = doctype.getNodeName(); out.write(encodeText(value)); String publicId = doctype.getPublicId(); if (publicId != null) { out.write(encodeText(" PUBLIC ")); out.write(APOS); out.write(encodeText(publicId)); out.write(APOS); } String systemId = doctype.getSystemId(); if (systemId != null) { out.write(encodeText(" SYSTEM ")); out.write(APOS); out.write(encodeText(systemId)); out.write(APOS); } String internalSubset = doctype.getInternalSubset(); if (internalSubset != null) { out.write(encodeText(internalSubset)); } out.write(KET); out.write(eol.getBytes(encoding)); break; case Node.ENTITY_REFERENCE_NODE: value = "&" + node.getNodeValue() + ";"; out.write(encodeText(value)); break; case Node.PROCESSING_INSTRUCTION_NODE: value = "<?" + node.getNodeName() + " " + node.getNodeValue() + "?>"; out.write(encodeText(value)); Node pp = node.getParentNode(); if (pp != null && pp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; } if (defined) { undefine(uri); } }
{
String encode(String text, boolean encodeCtl, boolean inAttr) { int len = text.length(); StringBuffer buf = null; for (int i = 0; i < len; i++) { char c = text.charAt(i); if (c == '<') { if (buf == null) { buf = new StringBuffer(text.substring(0, i)); } buf.append("&lt;"); } else if (c == '>') { if (buf == null) { buf = new StringBuffer(text.substring(0, i)); } buf.append("&gt;"); } else if (c == '&') { if (mode == Stylesheet.OUTPUT_HTML && (i + 1) < len && text.charAt(i + 1) == '{') { if (buf != null) { buf.append(c); } } else { if (buf == null) { buf = new StringBuffer(text.substring(0, i)); } buf.append("&amp;"); } } else if (c == '\'' && inAttr) { if (buf == null) { buf = new StringBuffer(text.substring(0, i)); } if (mode == Stylesheet.OUTPUT_HTML) // HTML does not define &apos;, use character entity ref buf.append("&#x27;"); else buf.append("&apos;"); } else if (c == '"' && inAttr) { if (buf == null) { buf = new StringBuffer(text.substring(0, i)); } buf.append("&quot;"); } else if (encodeCtl) { if (c < 0x20) { if (buf == null) { buf = new StringBuffer(text.substring(0, i)); } buf.append('&'); buf.append('#'); buf.append((int) c); buf.append(';'); } else if (buf != null) { buf.append(c); } } else if (buf != null) { buf.append(c); } } return (buf == null) ? text : buf.toString(); }
}
String encode(String text, boolean encodeCtl, boolean inAttr) { int len = text.length(); StringBuffer buf = null; for (int i = 0; i < len; i++) { char c = text.charAt(i); if (c == '<') { if (buf == null) { buf = new StringBuffer(text.substring(0, i)); } buf.append("&lt;"); } else if (c == '>') { if (buf == null) { buf = new StringBuffer(text.substring(0, i)); } buf.append("&gt;"); } else if (c == '&') { if (mode == Stylesheet.OUTPUT_HTML && (i + 1) < len && text.charAt(i + 1) == '{') { if (buf != null) { buf.append(c); } } else { if (buf == null) { buf = new StringBuffer(text.substring(0, i)); } buf.append("&amp;"); } } else if (c == '\'' && inAttr) { if (buf == null) { buf = new StringBuffer(text.substring(0, i)); } if (mode == Stylesheet.OUTPUT_HTML) // HTML does not define &apos;, use character entity ref buf.append("&#x27;"); else buf.append("&apos;"); } else if (c == '"' && inAttr) { if (buf == null) { buf = new StringBuffer(text.substring(0, i)); } buf.append("&quot;"); } else if (encodeCtl) { if (c < 0x20) { if (buf == null) { buf = new StringBuffer(text.substring(0, i)); } buf.append('&'); buf.append('#'); buf.append((int) c); buf.append(';'); } else if (buf != null) { buf.append(c); } } else if (buf != null) { buf.append(c); } } return (buf == null) ? text : buf.toString(); }
if (!encoder.canEncode(text))
boolean htmlNeedingEncoding = (mode == Stylesheet.OUTPUT_HTML && !htmlEncoded); if (!encoder.canEncode(text) || htmlNeedingEncoding)
final byte[] encodeText(String text) throws IOException { encoder.reset(); if (!encoder.canEncode(text)) { // Check each character StringBuffer buf = new StringBuffer(); int len = text.length(); for (int i = 0; i < len; i++) { char c = text.charAt(i); if (encoder.canEncode(c)) { buf.append(c); } else { // Replace with character entity reference String hex = Integer.toHexString((int) c); buf.append("&#x"); buf.append(hex); buf.append(';'); } } text = buf.toString(); } ByteBuffer encoded = encoder.encode(CharBuffer.wrap(text)); int len = encoded.limit() - encoded.position(); if (encoded.hasArray()) { byte[] ret = encoded.array(); if (ret.length > len) { // Why? byte[] ret2 = new byte[len]; System.arraycopy(ret, 0, ret2, 0, len); ret = ret2; } return ret; } encoded.flip(); byte[] ret = new byte[len]; encoded.get(ret, 0, len); return ret; }
if (encoder.canEncode(c)) { buf.append(c); } else
if (!encoder.canEncode(c))
final byte[] encodeText(String text) throws IOException { encoder.reset(); if (!encoder.canEncode(text)) { // Check each character StringBuffer buf = new StringBuffer(); int len = text.length(); for (int i = 0; i < len; i++) { char c = text.charAt(i); if (encoder.canEncode(c)) { buf.append(c); } else { // Replace with character entity reference String hex = Integer.toHexString((int) c); buf.append("&#x"); buf.append(hex); buf.append(';'); } } text = buf.toString(); } ByteBuffer encoded = encoder.encode(CharBuffer.wrap(text)); int len = encoded.limit() - encoded.position(); if (encoded.hasArray()) { byte[] ret = encoded.array(); if (ret.length > len) { // Why? byte[] ret2 = new byte[len]; System.arraycopy(ret, 0, ret2, 0, len); ret = ret2; } return ret; } encoded.flip(); byte[] ret = new byte[len]; encoded.get(ret, 0, len); return ret; }
else if (htmlNeedingEncoding) { String entityName = getHTMLCharacterEntity(c); if (entityName != null) { buf.append('&'); buf.append(entityName); buf.append(';'); } else buf.append(c); } else buf.append(c);
final byte[] encodeText(String text) throws IOException { encoder.reset(); if (!encoder.canEncode(text)) { // Check each character StringBuffer buf = new StringBuffer(); int len = text.length(); for (int i = 0; i < len; i++) { char c = text.charAt(i); if (encoder.canEncode(c)) { buf.append(c); } else { // Replace with character entity reference String hex = Integer.toHexString((int) c); buf.append("&#x"); buf.append(hex); buf.append(';'); } } text = buf.toString(); } ByteBuffer encoded = encoder.encode(CharBuffer.wrap(text)); int len = encoded.limit() - encoded.position(); if (encoded.hasArray()) { byte[] ret = encoded.array(); if (ret.length > len) { // Why? byte[] ret2 = new byte[len]; System.arraycopy(ret, 0, ret2, 0, len); ret = ret2; } return ret; } encoded.flip(); byte[] ret = new byte[len]; encoded.get(ret, 0, len); return ret; }
boolean isDefined(String uri)
boolean isDefined(String uri, String prefix)
boolean isDefined(String uri) { return XMLConstants.XML_NS_URI.equals(uri) || XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(uri) || namespaces.containsKey(uri); }
return XMLConstants.XML_NS_URI.equals(uri) || XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(uri) || namespaces.containsKey(uri);
if (XMLConstants.XML_NS_URI.equals(uri)) return "xml".equals(prefix); if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(uri)) return "xmlns".equals(prefix); if (prefix == null) prefix = ""; for (Iterator i = namespaces.iterator(); i.hasNext(); ) { Map ctx = (Map) i.next(); String val = (String) ctx.get(uri); if (val != null && val.equals(prefix)) return true; } return false;
boolean isDefined(String uri) { return XMLConstants.XML_NS_URI.equals(uri) || XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(uri) || namespaces.containsKey(uri); }
if (old != null) { BoundedRangeModel model = old.getModel(); if (model != null) model.removeChangeListener(scrollListener); } if (h != null) { BoundedRangeModel model = h.getModel(); if (model != null) model.addChangeListener(scrollListener); }
public void setHorizontalScrollBar(JScrollBar h) { if (horizontalScrollBar == h) return; JScrollBar old = horizontalScrollBar; removeNonNull(old); horizontalScrollBar = h; addNonNull(h, JScrollPane.HORIZONTAL_SCROLLBAR); firePropertyChange("horizontalScrollBar", old, h); sync(); if (old != null) { BoundedRangeModel model = old.getModel(); if (model != null) model.removeChangeListener(scrollListener); } if (h != null) { BoundedRangeModel model = h.getModel(); if (model != null) model.addChangeListener(scrollListener); } }
revalidate();
public void setHorizontalScrollBarPolicy(int h) { if (horizontalScrollBarPolicy == h) return; if (h != HORIZONTAL_SCROLLBAR_AS_NEEDED && h != HORIZONTAL_SCROLLBAR_NEVER && h != HORIZONTAL_SCROLLBAR_ALWAYS) throw new IllegalArgumentException("unknown horizontal scrollbar policy"); int old = horizontalScrollBarPolicy; horizontalScrollBarPolicy = h; firePropertyChange("horizontalScrollBarPolicy", old, h); sync(); }
if (old != null) { BoundedRangeModel model = old.getModel(); if (model != null) model.removeChangeListener(scrollListener); } if (v != null) { BoundedRangeModel model = v.getModel(); if (model != null) model.addChangeListener(scrollListener); }
public void setVerticalScrollBar(JScrollBar v) { if (verticalScrollBar == v) return; JScrollBar old = verticalScrollBar; removeNonNull(old); verticalScrollBar = v; addNonNull(v, JScrollPane.VERTICAL_SCROLLBAR); firePropertyChange("verticalScrollBar", old, v); sync(); if (old != null) { BoundedRangeModel model = old.getModel(); if (model != null) model.removeChangeListener(scrollListener); } if (v != null) { BoundedRangeModel model = v.getModel(); if (model != null) model.addChangeListener(scrollListener); } }
revalidate();
public void setVerticalScrollBarPolicy(int v) { if (verticalScrollBarPolicy == v) return; if (v != VERTICAL_SCROLLBAR_AS_NEEDED && v != VERTICAL_SCROLLBAR_NEVER && v != VERTICAL_SCROLLBAR_ALWAYS) throw new IllegalArgumentException("unknown vertical scrollbar policy"); int old = verticalScrollBarPolicy; verticalScrollBarPolicy = v; firePropertyChange("verticalScrollBarPolicy", old, v); sync(); }
if (old != null) old.removeChangeListener(scrollListener);
public void setViewport(JViewport v) { if (viewport == v) return; JViewport old = viewport; removeNonNull(old); if (old != null) old.removeChangeListener(scrollListener); viewport = v; if (v != null) v.addChangeListener(scrollListener); addNonNull(v, JScrollPane.VIEWPORT); revalidate(); repaint(); firePropertyChange("viewport", old, v); sync(); }
if (v != null) v.addChangeListener(scrollListener);
public void setViewport(JViewport v) { if (viewport == v) return; JViewport old = viewport; removeNonNull(old); if (old != null) old.removeChangeListener(scrollListener); viewport = v; if (v != null) v.addChangeListener(scrollListener); addNonNull(v, JScrollPane.VIEWPORT); revalidate(); repaint(); firePropertyChange("viewport", old, v); sync(); }
public Insets getBorderInsets(Component c);
Insets getBorderInsets(Component c);
public Insets getBorderInsets(Component c);
public void addAttribute(Object name, Object value);
void addAttribute(Object name, Object value);
public void addAttribute(Object name, Object value);
public void addAttributes(AttributeSet attributes);
void addAttributes(AttributeSet attributes);
public void addAttributes(AttributeSet attributes);
public void removeAttribute(Object name);
void removeAttribute(Object name);
public void removeAttribute(Object name);
public void removeAttributes(AttributeSet attributes);
void removeAttributes(Enumeration names);
public void removeAttributes(AttributeSet attributes);
public void setResolveParent(AttributeSet parent);
void setResolveParent(AttributeSet parent);
public void setResolveParent(AttributeSet parent);
BadLocationException() { }
public BadLocationException (String str, int offset) { super (str); this.offset = offset; }
BadLocationException() { }
for (int i = 0; i < listenerList.length; i += 2)
for (int i = listenerList.length - 2; i >= 0; i -= 2)
public EventListener[] getListeners(Class c) { int count, f; EventListener[] result; count = getListenerCount(c); result = (EventListener[]) Array.newInstance(c, count); f = 0; for (int i = 0; i < listenerList.length; i += 2) if (listenerList[i] == c) result[f++] = (EventListener) listenerList[i + 1]; return result; }
public InetAddress(byte[] ipaddr, String hostname) { this(ipaddr, hostname, null);
public InetAddress(byte[] ipaddr) { this(ipaddr, null, null);
public InetAddress(byte[] ipaddr, String hostname) { this(ipaddr, hostname, null); }
if (i == 4) { return (new InetAddress(ip)); }
if (i == 4) { return (new Inet4Address(ip)); }
public static InetAddress getByName(String hostname) throws UnknownHostException { // Default to current host if necessary if (hostname == null) return getLocalHost(); // First, check to see if it is an IP address. If so, then don't // do a DNS lookup. StringTokenizer st = new StringTokenizer(hostname, "."); if (st.countTokens() == 4) { int i; byte[] ip = new byte[ 4]; for (i = 0; i < 4; i++) { try { ip[ i] = Byte.parseByte(st.nextToken()); if ((ip[ i] < 0) || (ip[ 1] > 255)) break; } catch (NumberFormatException e) { break; } } if (i == 4) { return (new InetAddress(ip)); } } // Wasn't an IP, so try the lookup InetAddress[] addresses = getAllByName(hostname); return addresses[ 0]; }
public UnknownHostException(String message)
public UnknownHostException()
public UnknownHostException(String message) { super(message); }
super(message);
public UnknownHostException(String message) { super(message); }
super(addr, host, null);
super(addr, host);
Inet6Address(byte[] addr, String host) { super(addr, host, null); this.ipaddress = addr; }
if (isHorizontalIn(parent)) layoutAlgorithm(parent, HORIZONTAL, VERTICAL);
Component[] children = container.getComponents(); SizeRequirements[] hSizeReqs = new SizeRequirements[children.length]; SizeRequirements[] vSizeReqs = new SizeRequirements[children.length]; getSizeRequirements(hSizeReqs, vSizeReqs); int[] hSpans = new int[children.length]; int[] hOffsets = new int[children.length]; int[] vSpans = new int[children.length]; int[] vOffsets = new int[children.length]; Insets insets = container.getInsets(); int width = container.getWidth() - insets.left - insets.right - 1; int height = container.getHeight() - insets.top - insets.bottom - 1; if (isHorizontalIn(container)) { SizeRequirements.calculateTiledPositions(width, null, hSizeReqs, hOffsets, hSpans); SizeRequirements.calculateAlignedPositions(height, null, vSizeReqs, vOffsets, vSpans); }
public void layoutContainer(Container parent) { if (isHorizontalIn(parent)) layoutAlgorithm(parent, HORIZONTAL, VERTICAL); else layoutAlgorithm(parent, VERTICAL, HORIZONTAL); }
layoutAlgorithm(parent, VERTICAL, HORIZONTAL);
{ SizeRequirements.calculateTiledPositions(height, null, vSizeReqs, vOffsets, vSpans); SizeRequirements.calculateAlignedPositions(width, null, hSizeReqs, hOffsets, hSpans); } for (int i = 0; i < children.length; i++) { Component child = children[i]; child.setBounds(hOffsets[i] + insets.left, vOffsets[i] + insets.top, hSpans[i], vSpans[i]); }
public void layoutContainer(Container parent) { if (isHorizontalIn(parent)) layoutAlgorithm(parent, HORIZONTAL, VERTICAL); else layoutAlgorithm(parent, VERTICAL, HORIZONTAL); }
Insets insets = parent.getInsets(); int x = insets.left + insets.right; int y = insets.top + insets.bottom;
public Dimension maximumLayoutSize(Container parent) { if (parent != container) throw new AWTError("invalid parent"); Insets insets = parent.getInsets(); int x = insets.left + insets.right; int y = insets.top + insets.bottom; List children = AWTUtilities.getVisibleChildren(parent); if (isHorizontalIn(parent)) { // sum up preferred widths of components, find maximum of preferred // heights for (Iterator i = children.iterator(); i.hasNext();) { Component comp = (Component) i.next(); Dimension sz = comp.getMaximumSize(); x += sz.width; // Check for overflow. if (x < 0) x = Integer.MAX_VALUE; y = Math.max(y, sz.height); } } else { // sum up preferred heights of components, find maximum of // preferred widths for (Iterator i = children.iterator(); i.hasNext();) { Component comp = (Component) i.next(); Dimension sz = comp.getMaximumSize(); y += sz.height; // Check for overflow if (y < 0) y = Integer.MAX_VALUE; x = Math.max(x, sz.width); } } return new Dimension(x, y); }
List children = AWTUtilities.getVisibleChildren(parent); if (isHorizontalIn(parent))
Component[] children = container.getComponents(); SizeRequirements[] hSizeReqs = new SizeRequirements[children.length]; SizeRequirements[] vSizeReqs = new SizeRequirements[children.length]; getSizeRequirements(hSizeReqs, vSizeReqs); SizeRequirements hReq; SizeRequirements vReq; if (isHorizontalIn(container))
public Dimension maximumLayoutSize(Container parent) { if (parent != container) throw new AWTError("invalid parent"); Insets insets = parent.getInsets(); int x = insets.left + insets.right; int y = insets.top + insets.bottom; List children = AWTUtilities.getVisibleChildren(parent); if (isHorizontalIn(parent)) { // sum up preferred widths of components, find maximum of preferred // heights for (Iterator i = children.iterator(); i.hasNext();) { Component comp = (Component) i.next(); Dimension sz = comp.getMaximumSize(); x += sz.width; // Check for overflow. if (x < 0) x = Integer.MAX_VALUE; y = Math.max(y, sz.height); } } else { // sum up preferred heights of components, find maximum of // preferred widths for (Iterator i = children.iterator(); i.hasNext();) { Component comp = (Component) i.next(); Dimension sz = comp.getMaximumSize(); y += sz.height; // Check for overflow if (y < 0) y = Integer.MAX_VALUE; x = Math.max(x, sz.width); } } return new Dimension(x, y); }
for (Iterator i = children.iterator(); i.hasNext();) { Component comp = (Component) i.next(); Dimension sz = comp.getMaximumSize(); x += sz.width; if (x < 0) x = Integer.MAX_VALUE; y = Math.max(y, sz.height); }
hReq = SizeRequirements.getTiledSizeRequirements(hSizeReqs); vReq = SizeRequirements.getAlignedSizeRequirements(vSizeReqs);
public Dimension maximumLayoutSize(Container parent) { if (parent != container) throw new AWTError("invalid parent"); Insets insets = parent.getInsets(); int x = insets.left + insets.right; int y = insets.top + insets.bottom; List children = AWTUtilities.getVisibleChildren(parent); if (isHorizontalIn(parent)) { // sum up preferred widths of components, find maximum of preferred // heights for (Iterator i = children.iterator(); i.hasNext();) { Component comp = (Component) i.next(); Dimension sz = comp.getMaximumSize(); x += sz.width; // Check for overflow. if (x < 0) x = Integer.MAX_VALUE; y = Math.max(y, sz.height); } } else { // sum up preferred heights of components, find maximum of // preferred widths for (Iterator i = children.iterator(); i.hasNext();) { Component comp = (Component) i.next(); Dimension sz = comp.getMaximumSize(); y += sz.height; // Check for overflow if (y < 0) y = Integer.MAX_VALUE; x = Math.max(x, sz.width); } } return new Dimension(x, y); }
for (Iterator i = children.iterator(); i.hasNext();) { Component comp = (Component) i.next(); Dimension sz = comp.getMaximumSize(); y += sz.height; if (y < 0) y = Integer.MAX_VALUE; x = Math.max(x, sz.width); } } return new Dimension(x, y);
hReq = SizeRequirements.getAlignedSizeRequirements(hSizeReqs); vReq = SizeRequirements.getTiledSizeRequirements(vSizeReqs); } return new Dimension(hReq.maximum, vReq.maximum);
public Dimension maximumLayoutSize(Container parent) { if (parent != container) throw new AWTError("invalid parent"); Insets insets = parent.getInsets(); int x = insets.left + insets.right; int y = insets.top + insets.bottom; List children = AWTUtilities.getVisibleChildren(parent); if (isHorizontalIn(parent)) { // sum up preferred widths of components, find maximum of preferred // heights for (Iterator i = children.iterator(); i.hasNext();) { Component comp = (Component) i.next(); Dimension sz = comp.getMaximumSize(); x += sz.width; // Check for overflow. if (x < 0) x = Integer.MAX_VALUE; y = Math.max(y, sz.height); } } else { // sum up preferred heights of components, find maximum of // preferred widths for (Iterator i = children.iterator(); i.hasNext();) { Component comp = (Component) i.next(); Dimension sz = comp.getMaximumSize(); y += sz.height; // Check for overflow if (y < 0) y = Integer.MAX_VALUE; x = Math.max(x, sz.width); } } return new Dimension(x, y); }
Insets insets = parent.getInsets(); int x = insets.left + insets.right; int y = insets.bottom + insets.top;
public Dimension minimumLayoutSize(Container parent) { if (parent != container) throw new AWTError("invalid parent"); Insets insets = parent.getInsets(); int x = insets.left + insets.right; int y = insets.bottom + insets.top; List children = AWTUtilities.getVisibleChildren(parent); if (isHorizontalIn(parent)) { // sum up preferred widths of components, find maximum of preferred // heights for (Iterator i = children.iterator(); i.hasNext();) { Component comp = (Component) i.next(); Dimension sz = comp.getMinimumSize(); x += sz.width; y = Math.max(y, sz.height); } } else { // sum up preferred heights of components, find maximum of // preferred widths for (Iterator i = children.iterator(); i.hasNext();) { Component comp = (Component) i.next(); Dimension sz = comp.getMinimumSize(); y += sz.height; x = Math.max(x, sz.width); } } return new Dimension(x, y); }
List children = AWTUtilities.getVisibleChildren(parent); if (isHorizontalIn(parent))
Component[] children = container.getComponents(); SizeRequirements[] hSizeReqs = new SizeRequirements[children.length]; SizeRequirements[] vSizeReqs = new SizeRequirements[children.length]; getSizeRequirements(hSizeReqs, vSizeReqs); SizeRequirements hReq; SizeRequirements vReq; if (isHorizontalIn(container))
public Dimension minimumLayoutSize(Container parent) { if (parent != container) throw new AWTError("invalid parent"); Insets insets = parent.getInsets(); int x = insets.left + insets.right; int y = insets.bottom + insets.top; List children = AWTUtilities.getVisibleChildren(parent); if (isHorizontalIn(parent)) { // sum up preferred widths of components, find maximum of preferred // heights for (Iterator i = children.iterator(); i.hasNext();) { Component comp = (Component) i.next(); Dimension sz = comp.getMinimumSize(); x += sz.width; y = Math.max(y, sz.height); } } else { // sum up preferred heights of components, find maximum of // preferred widths for (Iterator i = children.iterator(); i.hasNext();) { Component comp = (Component) i.next(); Dimension sz = comp.getMinimumSize(); y += sz.height; x = Math.max(x, sz.width); } } return new Dimension(x, y); }
for (Iterator i = children.iterator(); i.hasNext();) { Component comp = (Component) i.next(); Dimension sz = comp.getMinimumSize(); x += sz.width; y = Math.max(y, sz.height); }
hReq = SizeRequirements.getTiledSizeRequirements(hSizeReqs); vReq = SizeRequirements.getAlignedSizeRequirements(vSizeReqs);
public Dimension minimumLayoutSize(Container parent) { if (parent != container) throw new AWTError("invalid parent"); Insets insets = parent.getInsets(); int x = insets.left + insets.right; int y = insets.bottom + insets.top; List children = AWTUtilities.getVisibleChildren(parent); if (isHorizontalIn(parent)) { // sum up preferred widths of components, find maximum of preferred // heights for (Iterator i = children.iterator(); i.hasNext();) { Component comp = (Component) i.next(); Dimension sz = comp.getMinimumSize(); x += sz.width; y = Math.max(y, sz.height); } } else { // sum up preferred heights of components, find maximum of // preferred widths for (Iterator i = children.iterator(); i.hasNext();) { Component comp = (Component) i.next(); Dimension sz = comp.getMinimumSize(); y += sz.height; x = Math.max(x, sz.width); } } return new Dimension(x, y); }
for (Iterator i = children.iterator(); i.hasNext();) { Component comp = (Component) i.next(); Dimension sz = comp.getMinimumSize(); y += sz.height; x = Math.max(x, sz.width); }
hReq = SizeRequirements.getAlignedSizeRequirements(hSizeReqs); vReq = SizeRequirements.getTiledSizeRequirements(vSizeReqs);
public Dimension minimumLayoutSize(Container parent) { if (parent != container) throw new AWTError("invalid parent"); Insets insets = parent.getInsets(); int x = insets.left + insets.right; int y = insets.bottom + insets.top; List children = AWTUtilities.getVisibleChildren(parent); if (isHorizontalIn(parent)) { // sum up preferred widths of components, find maximum of preferred // heights for (Iterator i = children.iterator(); i.hasNext();) { Component comp = (Component) i.next(); Dimension sz = comp.getMinimumSize(); x += sz.width; y = Math.max(y, sz.height); } } else { // sum up preferred heights of components, find maximum of // preferred widths for (Iterator i = children.iterator(); i.hasNext();) { Component comp = (Component) i.next(); Dimension sz = comp.getMinimumSize(); y += sz.height; x = Math.max(x, sz.width); } } return new Dimension(x, y); }
return new Dimension(x, y);
return new Dimension(hReq.minimum, vReq.minimum);
public Dimension minimumLayoutSize(Container parent) { if (parent != container) throw new AWTError("invalid parent"); Insets insets = parent.getInsets(); int x = insets.left + insets.right; int y = insets.bottom + insets.top; List children = AWTUtilities.getVisibleChildren(parent); if (isHorizontalIn(parent)) { // sum up preferred widths of components, find maximum of preferred // heights for (Iterator i = children.iterator(); i.hasNext();) { Component comp = (Component) i.next(); Dimension sz = comp.getMinimumSize(); x += sz.width; y = Math.max(y, sz.height); } } else { // sum up preferred heights of components, find maximum of // preferred widths for (Iterator i = children.iterator(); i.hasNext();) { Component comp = (Component) i.next(); Dimension sz = comp.getMinimumSize(); y += sz.height; x = Math.max(x, sz.width); } } return new Dimension(x, y); }
Insets insets = parent.getInsets(); int x = 0; int y = 0;
public Dimension preferredLayoutSize(Container parent) { if (parent != container) throw new AWTError("invalid parent"); Insets insets = parent.getInsets(); int x = 0; int y = 0; List children = AWTUtilities.getVisibleChildren(parent); if (isHorizontalIn(parent)) { x = insets.left + insets.right; // sum up preferred widths of components, find maximum of preferred // heights for (Iterator i = children.iterator(); i.hasNext();) { Component comp = (Component) i.next(); Dimension sz = comp.getPreferredSize(); x += sz.width; y = Math.max(y, sz.height); } y += insets.bottom + insets.top; } else { y = insets.top + insets.bottom; // sum up preferred heights of components, find maximum of // preferred widths for (Iterator i = children.iterator(); i.hasNext();) { Component comp = (Component) i.next(); Dimension sz = comp.getPreferredSize(); y += sz.height; x = Math.max(x, sz.width); } x += insets.left + insets.right; } return new Dimension(x, y); }
List children = AWTUtilities.getVisibleChildren(parent); if (isHorizontalIn(parent)) { x = insets.left + insets.right; for (Iterator i = children.iterator(); i.hasNext();) { Component comp = (Component) i.next(); Dimension sz = comp.getPreferredSize(); x += sz.width; y = Math.max(y, sz.height); } y += insets.bottom + insets.top; } else { y = insets.top + insets.bottom; for (Iterator i = children.iterator(); i.hasNext();) { Component comp = (Component) i.next(); Dimension sz = comp.getPreferredSize(); y += sz.height; x = Math.max(x, sz.width); } x += insets.left + insets.right;
Component[] children = container.getComponents(); SizeRequirements[] hSizeReqs = new SizeRequirements[children.length]; SizeRequirements[] vSizeReqs = new SizeRequirements[children.length]; getSizeRequirements(hSizeReqs, vSizeReqs); SizeRequirements hReq; SizeRequirements vReq; if (isHorizontalIn(container)) { hReq = SizeRequirements.getTiledSizeRequirements(hSizeReqs); vReq = SizeRequirements.getAlignedSizeRequirements(vSizeReqs);
public Dimension preferredLayoutSize(Container parent) { if (parent != container) throw new AWTError("invalid parent"); Insets insets = parent.getInsets(); int x = 0; int y = 0; List children = AWTUtilities.getVisibleChildren(parent); if (isHorizontalIn(parent)) { x = insets.left + insets.right; // sum up preferred widths of components, find maximum of preferred // heights for (Iterator i = children.iterator(); i.hasNext();) { Component comp = (Component) i.next(); Dimension sz = comp.getPreferredSize(); x += sz.width; y = Math.max(y, sz.height); } y += insets.bottom + insets.top; } else { y = insets.top + insets.bottom; // sum up preferred heights of components, find maximum of // preferred widths for (Iterator i = children.iterator(); i.hasNext();) { Component comp = (Component) i.next(); Dimension sz = comp.getPreferredSize(); y += sz.height; x = Math.max(x, sz.width); } x += insets.left + insets.right; } return new Dimension(x, y); }
return new Dimension(x, y);
else { hReq = SizeRequirements.getAlignedSizeRequirements(hSizeReqs); vReq = SizeRequirements.getTiledSizeRequirements(vSizeReqs); } return new Dimension(hReq.preferred, vReq.preferred);
public Dimension preferredLayoutSize(Container parent) { if (parent != container) throw new AWTError("invalid parent"); Insets insets = parent.getInsets(); int x = 0; int y = 0; List children = AWTUtilities.getVisibleChildren(parent); if (isHorizontalIn(parent)) { x = insets.left + insets.right; // sum up preferred widths of components, find maximum of preferred // heights for (Iterator i = children.iterator(); i.hasNext();) { Component comp = (Component) i.next(); Dimension sz = comp.getPreferredSize(); x += sz.width; y = Math.max(y, sz.height); } y += insets.bottom + insets.top; } else { y = insets.top + insets.bottom; // sum up preferred heights of components, find maximum of // preferred widths for (Iterator i = children.iterator(); i.hasNext();) { Component comp = (Component) i.next(); Dimension sz = comp.getPreferredSize(); y += sz.height; x = Math.max(x, sz.width); } x += insets.left + insets.right; } return new Dimension(x, y); }
public _IDLTypeStub(Delegate delegate)
public _IDLTypeStub()
public _IDLTypeStub(Delegate delegate) { _set_delegate(delegate); }
_set_delegate(delegate);
public _IDLTypeStub(Delegate delegate) { _set_delegate(delegate); }
public void setSystemId(String systemID);
public void setSystemId(String systemId);
public void setSystemId(String systemID);
public TransformerException(String msg) { super(msg);
public TransformerException(String msg) { this(msg, null, null);
public TransformerException(String msg) { super(msg); }
if (transform != null)
if (transform == null)
public TransformAttribute (AffineTransform transform) { if (transform != null) { this.affineTransform = new AffineTransform (transform); } }
this.affineTransform = new AffineTransform (transform);
throw new IllegalArgumentException("Null 'transform' not permitted.");
public TransformAttribute (AffineTransform transform) { if (transform != null) { this.affineTransform = new AffineTransform (transform); } }
this.affineTransform = new AffineTransform (transform);
public TransformAttribute (AffineTransform transform) { if (transform != null) { this.affineTransform = new AffineTransform (transform); } }
return affineTransform;
return (AffineTransform) affineTransform.clone();
public AffineTransform getTransform () { return affineTransform; }
return 16;
return 16 + getAdditionalHeight();
public int getIconHeight() { return 16; }
return new MetalCheckBoxIcon();
if (checkBoxIcon == null) checkBoxIcon = new MetalCheckBoxIcon(); return checkBoxIcon;
public static Icon getCheckBoxIcon() { return new MetalCheckBoxIcon(); }
return new CheckBoxMenuItemIcon();
if (checkBoxMenuItemIcon == null) checkBoxMenuItemIcon = new CheckBoxMenuItemIcon(); return checkBoxMenuItemIcon;
public static Icon getCheckBoxMenuItemIcon() { return new CheckBoxMenuItemIcon(); }
return new FileChooserDetailViewIcon();
if (fileChooserDetailViewIcon == null) fileChooserDetailViewIcon = new FileChooserDetailViewIcon(); return fileChooserDetailViewIcon;
public static Icon getFileChooserDetailViewIcon() { return new FileChooserDetailViewIcon(); }
return new FileChooserHomeFolderIcon();
if (fileChooserHomeFolderIcon == null) fileChooserHomeFolderIcon = new FileChooserHomeFolderIcon(); return fileChooserHomeFolderIcon;
public static Icon getFileChooserHomeFolderIcon() { return new FileChooserHomeFolderIcon(); }
return new FileChooserListViewIcon();
if (fileChooserListViewIcon == null) fileChooserListViewIcon = new FileChooserListViewIcon(); return fileChooserListViewIcon;
public static Icon getFileChooserListViewIcon() { return new FileChooserListViewIcon(); }
return new FileChooserNewFolderIcon();
if (fileChooserNewFolderIcon == null) fileChooserNewFolderIcon = new FileChooserNewFolderIcon(); return fileChooserNewFolderIcon;
public static Icon getFileChooserNewFolderIcon() { return new FileChooserNewFolderIcon(); }
return new FileChooserUpFolderIcon();
if (fileChooserUpFolderIcon == null) fileChooserUpFolderIcon = new FileChooserUpFolderIcon(); return fileChooserUpFolderIcon;
public static Icon getFileChooserUpFolderIcon() { return new FileChooserUpFolderIcon(); }
return new InternalFrameDefaultMenuIcon();
if (internalFrameDefaultMenuIcon == null) internalFrameDefaultMenuIcon = new InternalFrameDefaultMenuIcon(); return internalFrameDefaultMenuIcon;
public static Icon getInternalFrameDefaultMenuIcon() { return new InternalFrameDefaultMenuIcon(); }
return new RadioButtonMenuItemIcon();
if (radioButtonMenuItemIcon == null) radioButtonMenuItemIcon = new RadioButtonMenuItemIcon(); return radioButtonMenuItemIcon;
public static Icon getRadioButtonMenuItemIcon() { return new RadioButtonMenuItemIcon(); }
return new TreeComputerIcon();
if (treeComputerIcon == null) treeComputerIcon = new TreeComputerIcon(); return treeComputerIcon;
public static Icon getTreeComputerIcon() { return new TreeComputerIcon(); }
return new TreeFloppyDriveIcon();
if (treeFloppyDriveIcon == null) treeFloppyDriveIcon = new TreeFloppyDriveIcon(); return treeFloppyDriveIcon;
public static Icon getTreeFloppyDriveIcon() { return new TreeFloppyDriveIcon(); }
return new TreeHardDriveIcon();
if (treeHardDriveIcon == null) treeHardDriveIcon = new TreeHardDriveIcon(); return treeHardDriveIcon;
public static Icon getTreeHardDriveIcon() { return new TreeHardDriveIcon(); }
public Polygon(int[] xpoints, int[] ypoints, int npoints)
public Polygon()
public Polygon(int[] xpoints, int[] ypoints, int npoints) { this.xpoints = new int[npoints]; this.ypoints = new int[npoints]; System.arraycopy(xpoints, 0, this.xpoints, 0, npoints); System.arraycopy(ypoints, 0, this.ypoints, 0, npoints); this.npoints = npoints; }
this.xpoints = new int[npoints]; this.ypoints = new int[npoints]; System.arraycopy(xpoints, 0, this.xpoints, 0, npoints); System.arraycopy(ypoints, 0, this.ypoints, 0, npoints); this.npoints = npoints;
xpoints = new int[4]; ypoints = new int[4];
public Polygon(int[] xpoints, int[] ypoints, int npoints) { this.xpoints = new int[npoints]; this.ypoints = new int[npoints]; System.arraycopy(xpoints, 0, this.xpoints, 0, npoints); System.arraycopy(ypoints, 0, this.ypoints, 0, npoints); this.npoints = npoints; }
public void fillPolygon(Polygon polygon) { fillPolygon(polygon.xpoints, polygon.ypoints, polygon.npoints); }
public abstract void fillPolygon(int xPoints[], int yPoints[], int npoints);
public void fillPolygon(Polygon polygon) { fillPolygon(polygon.xpoints, polygon.ypoints, polygon.npoints); }
public void setMargin(Insets m) { margin = m; revalidate(); repaint(); }
public void setMargin(Insets m) { Insets old = margin; margin = m; if (m != old) { firePropertyChange(MARGIN_CHANGED_PROPERTY, old, m); revalidate(); repaint(); } }
public void setMargin(Insets m) { margin = m; revalidate(); repaint(); }
public boolean isEnabled();
boolean isEnabled();
public boolean isEnabled();
public void setMnemonic(int mne) { getModel().setMnemonic(mne); }
public void setMnemonic(char mne) { int old = getModel().getMnemonic(); getModel().setMnemonic(mne); if (old != getModel().getMnemonic()) { firePropertyChange(MNEMONIC_CHANGED_PROPERTY, old, (int) mne); revalidate(); repaint(); } }
public void setMnemonic(int mne) { getModel().setMnemonic(mne); }
public void putValue(String key, Object value);
void putValue(String key, Object value);
public void putValue(String key, Object value);
public void setEnabled(boolean b);
void setEnabled(boolean b);
public void setEnabled(boolean b);
public abstract FontMetrics getFontMetrics(Font font);
public FontMetrics getFontMetrics() { return getFontMetrics(getFont()); }
public abstract FontMetrics getFontMetrics(Font font);
public void setIcon(Icon defaultIcon) { if (default_icon == defaultIcon) return; default_icon = defaultIcon; if (default_icon != null) { } revalidate(); repaint(); }
public void setIcon(Icon i) { Icon old = default_icon; default_icon = i; if (old != i) { firePropertyChange(ICON_CHANGED_PROPERTY, old, i); revalidate(); repaint(); } }
public void setIcon(Icon defaultIcon) { if (default_icon == defaultIcon) return; default_icon = defaultIcon; if (default_icon != null) { // XXX FIXME - icons do not know their parent // default_icon.setParent(this); } revalidate(); repaint(); }
public JScrollPane(Component view, int vsbPolicy, int hsbPolicy)
public JScrollPane()
public JScrollPane(Component view, int vsbPolicy, int hsbPolicy) { scrollListener = createScrollListener(); setVerticalScrollBarPolicy(vsbPolicy); setVerticalScrollBar(createVerticalScrollBar()); setHorizontalScrollBarPolicy(hsbPolicy); setHorizontalScrollBar(createHorizontalScrollBar()); setViewportView(view); setLayout(new ScrollPaneLayout()); setOpaque(false); updateUI(); }
scrollListener = createScrollListener(); setVerticalScrollBarPolicy(vsbPolicy); setVerticalScrollBar(createVerticalScrollBar()); setHorizontalScrollBarPolicy(hsbPolicy); setHorizontalScrollBar(createHorizontalScrollBar()); setViewportView(view); setLayout(new ScrollPaneLayout()); setOpaque(false); updateUI();
this(null);
public JScrollPane(Component view, int vsbPolicy, int hsbPolicy) { scrollListener = createScrollListener(); setVerticalScrollBarPolicy(vsbPolicy); setVerticalScrollBar(createVerticalScrollBar()); setHorizontalScrollBarPolicy(hsbPolicy); setHorizontalScrollBar(createHorizontalScrollBar()); setViewportView(view); setLayout(new ScrollPaneLayout()); setOpaque(false); updateUI(); }
public Image createImage(int width, int height)
public Image createImage(ImageProducer prod)
public Image createImage(int width, int height) { Component parent = awtComponent.getParent(); ComponentPeer parentPeer = parent.getPeer(); return parentPeer.createImage(width, height); }
Component parent = awtComponent.getParent(); ComponentPeer parentPeer = parent.getPeer(); return parentPeer.createImage(width, height);
Image image = Toolkit.getDefaultToolkit().createImage(prod); return image;
public Image createImage(int width, int height) { Component parent = awtComponent.getParent(); ComponentPeer parentPeer = parent.getPeer(); return parentPeer.createImage(width, height); }
throw new Error("Please report a bug", e);
public void replaceRange(String text, int start, int end) { Document doc = getDocument(); if (start > end || start < doc.getStartPosition().getOffset() || end >= doc.getEndPosition().getOffset()) throw new IllegalArgumentException(); try { doc.remove(start, end - start); doc.insertString(start, text, null); } catch (BadLocationException e) { // This cannot happen as we check offset above. throw new Error("Please report a bug", e); } }
public BeanDescriptor(Class beanClass, Class customizerClass) { this.beanClass = beanClass; this.customizerClass = customizerClass;
public BeanDescriptor(Class beanClass) { this(beanClass,null);
public BeanDescriptor(Class beanClass, Class customizerClass) { this.beanClass = beanClass; this.customizerClass = customizerClass; }
private Pattern (String regex)
private Pattern (String regex, int flags)
private Pattern (String regex) throws PatternSyntaxException { this (regex, 0); }
this (regex, 0);
this.regex = regex; this.flags = flags; int gnuFlags = 0; if ((flags & CASE_INSENSITIVE) != 0) gnuFlags |= RE.REG_ICASE; if ((flags & MULTILINE) != 0) gnuFlags |= RE.REG_MULTILINE; if ((flags & DOTALL) != 0) gnuFlags |= RE.REG_DOT_NEWLINE; RESyntax syntax = RESyntax.RE_SYNTAX_PERL5; if ((flags & UNIX_LINES) != 0) { syntax = new RESyntax(syntax); syntax.setLineSeparator("\n"); } if ((flags & COMMENTS) != 0) { } try { this.re = new RE(regex, gnuFlags, syntax); } catch (REException e) { throw new PatternSyntaxException(e.getMessage(), regex, e.getPosition());
private Pattern (String regex) throws PatternSyntaxException { this (regex, 0); }
}
private Pattern (String regex) throws PatternSyntaxException { this (regex, 0); }
public RESyntax(RESyntax other) { bits = (BitSet) other.bits.clone();
public RESyntax() { bits = new BitSet(BIT_TOTAL);
public RESyntax(RESyntax other) { bits = (BitSet) other.bits.clone(); }
public RE(Object pattern, int cflags, RESyntax syntax) throws REException { this(pattern,cflags,syntax,0,0);
public RE(Object pattern) throws REException { this(pattern,0,RESyntax.RE_SYNTAX_PERL5,0,0);
public RE(Object pattern, int cflags, RESyntax syntax) throws REException { this(pattern,cflags,syntax,0,0); }
public Number parse (String sourceStr) throws ParseException { ParsePosition pp = new ParsePosition (0); Number r = parse (sourceStr, pp); if (r == null) { int index = pp.getErrorIndex(); if (index < 0) index = pp.getIndex(); throw new ParseException ("couldn't parse number", index); } return r; }
public abstract Number parse (String sourceStr, ParsePosition pos);
public Number parse (String sourceStr) throws ParseException { ParsePosition pp = new ParsePosition (0); Number r = parse (sourceStr, pp); if (r == null) { int index = pp.getErrorIndex(); if (index < 0) index = pp.getIndex(); throw new ParseException ("couldn't parse number", index); } return r; }
return new gnu.java.awt.peer.GLightweightPeer (target);
return new GLightweightPeer(target);
protected LightweightPeer createComponent(Component target) { return new gnu.java.awt.peer.GLightweightPeer (target); }
int ic = popupMenu.getItemCount(); for(int i = 0; i < ic ; i++){ MenuItem mi = popupMenu.getItem(i); JMenuItem jmi = new JMenuItem(mi.getLabel());
int item_count = popupMenu.getItemCount(); for(int i = 0; i < item_count; i++){ MenuItem menu_item = popupMenu.getItem(i); menu_item.addNotify(); jComponent.add(((SwingMenuComponentPeer)menu_item.getPeer()).jComponent);
public SwingPopupMenuPeer(SwingToolkit toolkit, PopupMenu popupMenu) { super(toolkit, popupMenu, new JPopupMenu()); int ic = popupMenu.getItemCount(); for(int i = 0; i < ic ; i++){ MenuItem mi = popupMenu.getItem(i); JMenuItem jmi = new JMenuItem(mi.getLabel()); } }
public BAD_OPERATION()
public BAD_OPERATION(String message)
public BAD_OPERATION() { super("", 0, CompletionStatus.COMPLETED_NO); }
super("", 0, CompletionStatus.COMPLETED_NO);
super(message, 0, CompletionStatus.COMPLETED_NO);
public BAD_OPERATION() { super("", 0, CompletionStatus.COMPLETED_NO); }
closeEntry();
private void readManifest(boolean verify) throws IOException { firstEntry = (JarEntry) super.getNextEntry(); while ((firstEntry != null) && firstEntry.getName().startsWith("META-INF/")) { if (firstEntry.getName().equals(JarFile.MANIFEST_NAME)) { manifest = new Manifest(this); } firstEntry = (JarEntry) super.getNextEntry(); } closeEntry(); if (verify) { // XXX } }
public JarEntry(ZipEntry entry)
public JarEntry(String name) throws NullPointerException, IllegalArgumentException
public JarEntry(ZipEntry entry) { super(entry); attr = null; certs = null; }