return new NodeListModel(node.getAttributes(), this); } else if (key.equals(AtAtKey.START_TAG.getKey())) { NodeOutputter nodeOutputter = new NodeOutputter(node); return new SimpleScalar(nodeOutputter.getOpeningTag((Element) node)); } else if (key.equals(AtAtKey.END_TAG.getKey())) { NodeOutputter nodeOutputter = new NodeOutputter(node); return new SimpleScalar(nodeOutputter.getClosingTag((Element) node)); } else if (key.equals(AtAtKey.ATTRIBUTES_MARKUP.getKey())) { StringBuilder buf = new StringBuilder(); NodeOutputter nu = new NodeOutputter(node); nu.outputContent(node.getAttributes(), buf); return new SimpleScalar(buf.toString().trim()); } else if (key.equals(AtAtKey.PREVIOUS_SIBLING_ELEMENT.getKey())) {
private void setContext(Element contextNode) { this.contextNode = contextNode; this.env = Environment.getCurrentEnvironment(); this.defaultNS = env.getDefaultNS(); this.hasDefaultNS = defaultNS != null && defaultNS.length() > 0; namespacesToPrefixLookup.put(null, ""); namespacesToPrefixLookup.put("", ""); buildPrefixLookup(contextNode); if (!explicitDefaultNSPrefix && hasDefaultNS) { namespacesToPrefixLookup.put(defaultNS, ""); } constructNamespaceDecl(); }
String getOpeningTag(Element element) { StringBuilder buf = new StringBuilder(); buf.append('<'); outputQualifiedName(element, buf); buf.append(namespaceDecl); outputContent(element.getAttributes(), buf); buf.append('>'); return buf.toString(); }
} else if (key.equals(AtAtKey.MARKUP.getKey())) { StringBuilder buf = new StringBuilder(); NodeOutputter nu = new NodeOutputter(node); nu.outputContent(node, buf); return new SimpleScalar(buf.toString()); } else if (key.equals(AtAtKey.NESTED_MARKUP.getKey())) { StringBuilder buf = new StringBuilder(); NodeOutputter nu = new NodeOutputter(node); nu.outputContent(node.getChildNodes(), buf); return new SimpleScalar(buf.toString()); } else if (key.equals(AtAtKey.QNAME.getKey())) {
void outputContent(NodeList nodes, StringBuilder buf) { for (int i = 0; i < nodes.getLength(); ++i) { outputContent(nodes.item(i), buf); } }
NodeOutputter(Node node) { if (node instanceof Element) { setContext((Element) node); } else if (node instanceof Attr) { setContext(((Attr) node).getOwnerElement()); } else if (node instanceof Document) { setContext(((Document) node).getDocumentElement()); } }
String getClosingTag(Element element) { StringBuilder buf = new StringBuilder(); buf.append("</"); outputQualifiedName(element, buf); buf.append('>'); return buf.toString(); } }
private void buildPrefixLookup(Node n) { String nsURI = n.getNamespaceURI(); if (nsURI != null && nsURI.length() > 0) { String prefix = env.getPrefixForNamespace(nsURI); if (prefix == null) { prefix = namespacesToPrefixLookup.get(nsURI); if (prefix == null) { // Assign a generated prefix: do { prefix = StringUtil.toLowerABC(nextGeneratedPrefixNumber++); } while (env.getNamespaceForPrefix(prefix) != null); } } namespacesToPrefixLookup.put(nsURI, prefix); } else if (hasDefaultNS && n.getNodeType() == Node.ELEMENT_NODE) { namespacesToPrefixLookup.put(defaultNS, Template.DEFAULT_NAMESPACE_PREFIX); explicitDefaultNSPrefix = true; } else if (n.getNodeType() == Node.ATTRIBUTE_NODE && hasDefaultNS && defaultNS.equals(nsURI)) { namespacesToPrefixLookup.put(defaultNS, Template.DEFAULT_NAMESPACE_PREFIX); explicitDefaultNSPrefix = true; } NodeList childNodes = n.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { buildPrefixLookup(childNodes.item(i)); } }
NodeOutputter nu = new NodeOutputter(node); nu.outputContent(node, buf); return new SimpleScalar(buf.toString()); NodeOutputter nu = new NodeOutputter(node); nu.outputContent(node.getChildNodes(), buf); return new SimpleScalar(buf.toString());
void outputContent(NamedNodeMap nodes, StringBuilder buf) { for (int i = 0; i < nodes.getLength(); ++i) { Node n = nodes.item(i); if (n.getNodeType() != Node.ATTRIBUTE_NODE || (!n.getNodeName().startsWith("xmlns:") && !n.getNodeName().equals("xmlns"))) { outputContent(n, buf); } } }
NodeOutputter(Node node) { if (node instanceof Element) { setContext((Element) node); } else if (node instanceof Attr) { setContext(((Attr) node).getOwnerElement()); } else if (node instanceof Document) { setContext(((Document) node).getDocumentElement()); } }
String getClosingTag(Element element) { StringBuilder buf = new StringBuilder(); buf.append("</"); outputQualifiedName(element, buf); buf.append('>'); return buf.toString(); } }
private void buildPrefixLookup(Node n) { String nsURI = n.getNamespaceURI(); if (nsURI != null && nsURI.length() >0) { String prefix = env.getPrefixForNamespace(nsURI); namespacesToPrefixLookup.put(nsURI, prefix); } else if (hasDefaultNS && n.getNodeType() == Node.ELEMENT_NODE) { namespacesToPrefixLookup.put(defaultNS, Template.DEFAULT_NAMESPACE_PREFIX); explicitDefaultNSPrefix = true; } else if (n.getNodeType() == Node.ATTRIBUTE_NODE && hasDefaultNS && defaultNS.equals(nsURI)) { namespacesToPrefixLookup.put(defaultNS, Template.DEFAULT_NAMESPACE_PREFIX); explicitDefaultNSPrefix = true; } NodeList childNodes = n.getChildNodes(); for (int i = 0; i<childNodes.getLength(); i++) { buildPrefixLookup(childNodes.item(i)); } }
NodeOutputter nodeOutputter = new NodeOutputter(node); return new SimpleScalar(nodeOutputter.getOpeningTag((Element) node)); NodeOutputter nodeOutputter = new NodeOutputter(node); return new SimpleScalar(nodeOutputter.getClosingTag((Element) node)); NodeOutputter nu = new NodeOutputter(node); nu.outputContent(node.getAttributes(), buf); return new SimpleScalar(buf.toString().trim());
if (((Attr) n).getSpecified()) { buf.append(' '); outputQualifiedName(n, buf); buf.append("=\"") .append(StringUtil.XMLEncQAttr(n.getNodeValue())) outputContent(n.getChildNodes(), buf); break; outputQualifiedName(n, buf); if (n == contextNode) { buf.append(namespaceDecl); outputContent(n.getAttributes(), buf); NodeList children = n.getChildNodes(); if (children.getLength() == 0) { } else { buf.append('>'); outputContent(n.getChildNodes(), buf); buf.append("</"); outputQualifiedName(n, buf); buf.append('>'); outputContent(n.getChildNodes(), buf); break;
private void setContext(Element contextNode) { this.contextNode = contextNode; this.env = Environment.getCurrentEnvironment(); this.defaultNS = env.getDefaultNS(); this.hasDefaultNS = defaultNS != null && defaultNS.length() >0; namespacesToPrefixLookup.put(null, ""); namespacesToPrefixLookup.put("", ""); buildPrefixLookup(contextNode); if (!explicitDefaultNSPrefix && hasDefaultNS) { namespacesToPrefixLookup.put(defaultNS, ""); } constructNamespaceDecl(); }
} else if (key.equals(AtAtKey.MARKUP.getKey())) { StringBuilder buf = new StringBuilder(); NodeOutputter nu = new NodeOutputter(node); nu.outputContent(node, buf); return new SimpleScalar(buf.toString()); } else if (key.equals(AtAtKey.NESTED_MARKUP.getKey())) { StringBuilder buf = new StringBuilder(); NodeOutputter nu = new NodeOutputter(node); nu.outputContent(node.getChildNodes(), buf); return new SimpleScalar(buf.toString()); } else if (key.equals(AtAtKey.QNAME.getKey())) {
void outputContent(NodeList nodes, StringBuilder buf) { for (int i = 0; i < nodes.getLength(); ++i) { outputContent(nodes.item(i), buf); } }
NodeOutputter(Node node) { if (node instanceof Element) { setContext((Element) node); } else if (node instanceof Attr) { setContext(((Attr) node).getOwnerElement()); } else if (node instanceof Document) { setContext(((Document) node).getDocumentElement()); } }
String getClosingTag(Element element) { StringBuilder buf = new StringBuilder(); buf.append("</"); outputQualifiedName(element, buf); buf.append('>'); return buf.toString(); } }