List of usage examples for org.dom4j.io XMLWriter startPrefixMapping
public void startPrefixMapping(String prefix, String uri) throws SAXException
From source file:org.alfresco.repo.admin.patch.util.ImportFileUpdater.java
License:Open Source License
private void outputCurrentElement(XmlPullParser reader, XMLWriter writer, Work work, boolean checkForCallbacks) throws Exception { if (checkForCallbacks == false || checkForCallbacks(reader, writer) == false) { // Get the name details of the element String name = reader.getName(); String namespace = reader.getNamespace(); String prefix = reader.getPrefix(); // Sort out namespaces Map<String, String> nss = new HashMap<String, String>(); int nsStart = reader.getNamespaceCount(reader.getDepth() - 1); int nsEnd = reader.getNamespaceCount(reader.getDepth()); for (int i = nsStart; i < nsEnd; i++) { String nsPrefix = reader.getNamespacePrefix(i); String ns = reader.getNamespaceUri(i); nss.put(nsPrefix, ns);/*from w ww. j av a 2s .c o m*/ } // Sort out attributes AttributesImpl attributes = new AttributesImpl(); for (int i = 0; i < reader.getAttributeCount(); i++) { String attributeName = reader.getAttributeName(i); String attributeNamespace = reader.getAttributeNamespace(i); String attributePrefix = reader.getAttributePrefix(i); String attributeType = reader.getAttributeType(i); String attributeValue = reader.getAttributeValue(i); attributes.addAttribute(attributeNamespace, attributeName, attributePrefix + ":" + attributeName, attributeType, attributeValue); } // Start the namespace prefixes for (Map.Entry<String, String> entry : nss.entrySet()) { writer.startPrefixMapping(entry.getKey(), entry.getValue()); } // Write the start of the element writer.startElement(namespace, name, prefix + ":" + name, attributes); // Do the work work.doWork(reader, writer); // Write the end of the element writer.endElement(namespace, name, prefix + ":" + name); // End the namespace prefixes for (String nsPrefix : nss.keySet()) { writer.endPrefixMapping(nsPrefix); } } }