if (ns != null && ns != Namespace.NO_NAMESPACE && ns != Namespace.XML_NAMESPACE) { String prefix = ns.getPrefix(); String uri = namespaceStack.getURI(prefix); if (!ns.getURI().equals(uri)) { // output a new namespace declaration writeNamespace(ns); namespaceStack.push(ns); if (attName.startsWith("xmlns:")) { String prefix = attName.substring(6); if (namespaceStack.getNamespaceForPrefix(prefix) == null) { String uri = attribute.getValue(); namespaceStack.push(prefix, uri); writeNamespace(prefix, uri); if (namespaceStack.getDefaultNamespace() == null) { String uri = attribute.getValue(); namespaceStack.push(null, uri); writeNamespace(null, uri);
writer.write(qualifiedName); int previouslyDeclaredNamespaces = namespaceStack.size(); Namespace ns = element.getNamespace(); if (isNamespaceDeclaration( ns ) ) { namespaceStack.push(ns); writeNamespace(ns); Namespace additional = (Namespace) node; if (isNamespaceDeclaration( additional ) ) { namespaceStack.push(additional); writeNamespace(additional); while (namespaceStack.size() > previouslyDeclaredNamespaces) { namespaceStack.pop();
protected void readElement(org.w3c.dom.Node node, Branch current) { int previouslyDeclaredNamespaces = namespaceStack.size(); QName qName = namespaceStack.getQName(namespaceUri, node.getLocalName(), node.getNodeName()); Element element = current.addElement(qName); String uri = attribute.getNodeValue(); Namespace namespace = namespaceStack.addNamespace(prefix, uri); element.add(namespace); org.w3c.dom.Node attribute = (org.w3c.dom.Node) attributes .get(i); QName attributeQName = namespaceStack.getQName(attribute .getNamespaceURI(), attribute.getLocalName(), attribute .getNodeName()); while (namespaceStack.size() > previouslyDeclaredNamespaces) { namespaceStack.pop();
/** * DOCUMENT ME! * * @param namespace * DOCUMENT ME! * * @return true if the given prefix is in the stack. */ public boolean contains(Namespace namespace) { String prefix = namespace.getPrefix(); Namespace current; if ((prefix == null) || (prefix.length() == 0)) { current = getDefaultNamespace(); } else { current = getNamespaceForPrefix(prefix); } if (current == null) { return false; } if (current == namespace) { return true; } return namespace.getURI().equals(current.getURI()); }
/** * Add all namespaces declared before the startElement() SAX event to the * current element so that they are available to child elements and * attributes * * @param element * DOCUMENT ME! */ protected void addDeclaredNamespaces(Element element) { Namespace elementNamespace = element.getNamespace(); for (int size = namespaceStack.size(); declaredNamespaceIndex < size; declaredNamespaceIndex++) { Namespace namespace = namespaceStack .getNamespace(declaredNamespaceIndex); // if ( namespace != elementNamespace ) { element.add(namespace); // } } }
public XMLWriter(Writer writer, OutputFormat format) { this.writer = writer; this.format = format; namespaceStack.push(Namespace.NO_NAMESPACE); }
public SAXContentHandler(DocumentFactory documentFactory, ElementHandler elementHandler, ElementStack elementStack) { this.documentFactory = documentFactory; this.elementHandler = elementHandler; this.elementStack = elementStack; this.namespaceStack = new NamespaceStack(documentFactory); }
/** * DOCUMENT ME! * * @param prefix * DOCUMENT ME! * * @return the URI for the given prefix or null if it could not be found. */ public String getURI(String prefix) { Namespace namespace = getNamespaceForPrefix(prefix); return (namespace != null) ? namespace.getURI() : null; }
public void endDocument() throws SAXException { namespaceStack.clear(); elementStack.clear(); currentElement = null; textBuffer = null; }
protected boolean isNamespaceDeclaration( Namespace ns ) { if (ns != null && ns != Namespace.XML_NAMESPACE) { String uri = ns.getURI(); if ( uri != null ) { if ( ! namespaceStack.contains( ns ) ) { return true; } } } return false; }
protected void write(Element element, NamespaceStack namespaceStack) throws SAXException { int stackSize = namespaceStack.size(); AttributesImpl namespaceAttributes = startPrefixMapping(element, namespaceStack); startElement(element, namespaceAttributes); writeContent(element, namespaceStack); endElement(element); endPrefixMapping(namespaceStack, stackSize); }
protected void readElement(org.w3c.dom.Node node, Branch current) { int previouslyDeclaredNamespaces = namespaceStack.size(); QName qName = namespaceStack.getQName(namespaceUri, node.getLocalName(), node.getNodeName()); Element element = current.addElement(qName); String uri = attribute.getNodeValue(); Namespace namespace = namespaceStack.addNamespace(prefix, uri); element.add(namespace); org.w3c.dom.Node attribute = (org.w3c.dom.Node) attributes .get(i); QName attributeQName = namespaceStack.getQName(attribute .getNamespaceURI(), attribute.getLocalName(), attribute .getNodeName()); while (namespaceStack.size() > previouslyDeclaredNamespaces) { namespaceStack.pop();
/** * DOCUMENT ME! * * @param namespace * DOCUMENT ME! * * @return true if the given prefix is in the stack. */ public boolean contains(Namespace namespace) { String prefix = namespace.getPrefix(); Namespace current; if ((prefix == null) || (prefix.length() == 0)) { current = getDefaultNamespace(); } else { current = getNamespaceForPrefix(prefix); } if (current == null) { return false; } if (current == namespace) { return true; } return namespace.getURI().equals(current.getURI()); }
protected void addDeclaredNamespaces(Element element) { for (int size = namespaceStack.size(); declaredNamespaceIndex < size; declaredNamespaceIndex++) { Namespace namespace = namespaceStack .getNamespace(declaredNamespaceIndex); String attributeName = attributeNameForNamespace(namespace); ((DOMElement)element).setAttribute(attributeName, namespace.getURI()); } }
public XMLWriter() throws UnsupportedEncodingException { this.format = DEFAULT_FORMAT; this.writer = new BufferedWriter( new OutputStreamWriter( System.out, StandardCharsets.UTF_8) ); this.autoFlush = true; namespaceStack.push(Namespace.NO_NAMESPACE); }
public DOMReader(DocumentFactory factory) { this.factory = factory; this.namespaceStack = new NamespaceStack(factory); }