List of usage examples for org.dom4j Namespace getURI
public String getURI()
From source file:org.orbeon.oxf.xml.dom4j.Dom4jUtils.java
License:Open Source License
/** * Return a Map of namespaces in scope on the given element. *//*w w w. j av a 2 s. c om*/ public static Map<String, String> getNamespaceContext(Element element) { final Map<String, String> namespaces = new HashMap<String, String>(); for (Element currentNode = element; currentNode != null; currentNode = currentNode.getParent()) { final List currentNamespaces = currentNode.declaredNamespaces(); for (Iterator j = currentNamespaces.iterator(); j.hasNext();) { final Namespace namespace = (Namespace) j.next(); if (!namespaces.containsKey(namespace.getPrefix())) { namespaces.put(namespace.getPrefix(), namespace.getURI()); // TODO: Intern namespace strings to save memory; should use NamePool later // namespaces.put(namespace.getPrefix().intern(), namespace.getURI().intern()); } } } // It seems that by default this may not be declared. However, it should be: "The prefix xml is by definition // bound to the namespace name http://www.w3.org/XML/1998/namespace. It MAY, but need not, be declared, and MUST // NOT be bound to any other namespace name. Other prefixes MUST NOT be bound to this namespace name, and it // MUST NOT be declared as the default namespace." namespaces.put(XMLConstants.XML_PREFIX, XMLConstants.XML_URI); return namespaces; }
From source file:org.orbeon.saxon.dom4j.NodeWrapper.java
License:Open Source License
/** * Get all namespace undeclarations and undeclarations defined on this element. * * @param buffer If this is non-null, and the result array fits in this buffer, then the result * may overwrite the contents of this array, to avoid the cost of allocating a new array on the heap. * @return An array of integers representing the namespace declarations and undeclarations present on * this element. For a node other than an element, return null. Otherwise, the returned array is a * sequence of namespace codes, whose meaning may be interpreted by reference to the name pool. The * top half word of each namespace code represents the prefix, the bottom half represents the URI. * If the bottom half is zero, then this is a namespace undeclaration rather than a declaration. * The XML namespace is never included in the list. If the supplied array is larger than required, * then the first unused entry will be set to -1. * <p/>/*from www . j a v a2 s .c om*/ * <p>For a node other than an element, the method returns null.</p> */ public int[] getDeclaredNamespaces(int[] buffer) { if (node instanceof Element) { final Element elem = (Element) node; final List namespaces = elem.declaredNamespaces(); if (namespaces == null || namespaces.isEmpty()) { return EMPTY_NAMESPACE_LIST; } final int count = namespaces.size(); if (count == 0) { return EMPTY_NAMESPACE_LIST; } else { int[] result = (buffer == null || count > buffer.length ? new int[count] : buffer); NamePool pool = getNamePool(); int n = 0; for (Iterator i = namespaces.iterator(); i.hasNext();) { final Namespace namespace = (Namespace) i.next(); final String prefix = namespace.getPrefix(); final String uri = namespace.getURI(); result[n++] = pool.allocateNamespaceCode(prefix, uri); } if (count < result.length) { result[count] = -1; } return result; } } else { return null; } }
From source file:org.pentaho.di.trans.steps.getxmldata.GetXMLData.java
License:Apache License
public void prepareNSMap(Element l) { @SuppressWarnings("unchecked") List<Namespace> namespacesList = l.declaredNamespaces(); for (Namespace ns : namespacesList) { if (ns.getPrefix().trim().length() == 0) { data.NAMESPACE.put("pre" + data.NSPath.size(), ns.getURI()); String path = ""; Element element = l;//from w w w . j a va2s . com while (element != null) { if (element.getNamespacePrefix() != null && element.getNamespacePrefix().length() > 0) { path = GetXMLDataMeta.N0DE_SEPARATOR + element.getNamespacePrefix() + ":" + element.getName() + path; } else { path = GetXMLDataMeta.N0DE_SEPARATOR + element.getName() + path; } element = element.getParent(); } data.NSPath.add(path); } else { data.NAMESPACE.put(ns.getPrefix(), ns.getURI()); } } @SuppressWarnings("unchecked") List<Element> elementsList = l.elements(); for (Element e : elementsList) { prepareNSMap(e); } }
From source file:org.talend.camel.designer.ui.wizards.export.RouteJavaScriptOSGIForESBManager.java
License:Open Source License
private static void moveNamespace(Element treeRoot, String oldNspURI, String newNspURI) { Namespace oldNsp = treeRoot.getNamespace(); if (oldNspURI.equals(oldNsp.getURI())) { Namespace newNsp = Namespace.get(oldNsp.getPrefix(), newNspURI); treeRoot.setQName(QName.get(treeRoot.getName(), newNsp)); treeRoot.remove(oldNsp);// w w w.j a v a 2s . co m } moveNamespaceInChildren(treeRoot, oldNspURI, newNspURI); }
From source file:org.talend.camel.designer.ui.wizards.export.RouteJavaScriptOSGIForESBManager.java
License:Open Source License
private static void moveNamespaceInChildren(Element treeRoot, String oldNspURI, String newNspURI) { for (Iterator<?> i = treeRoot.elementIterator(); i.hasNext();) { Element e = (Element) i.next(); Namespace oldNsp = e.getNamespace(); if (oldNspURI.equals(oldNsp.getURI())) { Namespace newNsp = Namespace.get(oldNsp.getPrefix(), newNspURI); e.setQName(QName.get(e.getName(), newNsp)); e.remove(oldNsp);/* ww w.ja v a 2 s . c o m*/ } moveNamespaceInChildren(e, oldNspURI, newNspURI); } }
From source file:org.xmlactions.mapping.bean_to_xml.Bean.java
License:Apache License
public Element processBean(BeanToXml map, Object obj) { Element element = DocumentHelper.createElement(BeanToXmlUtils.buildName(getPrefix(), getName())); for (Namespace namespace : map.getNamespaces()) { element.addNamespace(namespace.getPrefix(), namespace.getUri()); }//from w w w. ja v a 2s. c o m for (MapperAttribute attribute : getAttributes()) { attribute.buildXml(map, element, obj); } for (MapperElement node : getElements()) { node.buildXml(map, element, obj); } return element; }
From source file:org.zenonpagetemplates.onePhaseImpl.PageTemplateImpl.java
License:Open Source License
@SuppressWarnings({ "unchecked" }) private void defaultContent(Element element, ContentHandler contentHandler, LexicalHandler lexicalHandler, EvaluationHelper evaluationHelper, Stack<Map<String, Slot>> slotStack) throws SAXException, PageTemplateException, IOException, EvaluationException { // Use default template content for (Iterator<Node> i = element.nodeIterator(); i.hasNext();) { Node node = i.next();/* w w w . j av a 2s .co m*/ switch (node.getNodeType()) { case Node.ELEMENT_NODE: processElement((Element) node, contentHandler, lexicalHandler, evaluationHelper, slotStack); break; case Node.TEXT_NODE: char[] text = node.getText().toCharArray(); contentHandler.characters(text, 0, text.length); break; case Node.COMMENT_NODE: char[] comment = node.getText().toCharArray(); lexicalHandler.comment(comment, 0, comment.length); break; case Node.CDATA_SECTION_NODE: lexicalHandler.startCDATA(); char[] cdata = node.getText().toCharArray(); contentHandler.characters(cdata, 0, cdata.length); lexicalHandler.endCDATA(); break; case Node.NAMESPACE_NODE: Namespace declared = (Namespace) node; //System.err.println( "Declared namespace: " + declared.getPrefix() + ":" + declared.getURI() ); this.namespaces.put(declared.getPrefix(), declared.getURI()); //if ( declared.getURI().equals( TAL_NAMESPACE_URI ) ) { // this.talNamespacePrefix = declared.getPrefix(); //} //else if (declared.getURI().equals( METAL_NAMESPACE_URI ) ) { // this.metalNamespacePrefix = declared.getPrefix(); //} break; case Node.ATTRIBUTE_NODE: // Already handled break; case Node.DOCUMENT_TYPE_NODE: case Node.ENTITY_REFERENCE_NODE: case Node.PROCESSING_INSTRUCTION_NODE: default: //System.err.println( "WARNING: Node type not supported: " + node.getNodeTypeName() ); } } }
From source file:org.zenonpagetemplates.onePhaseImpl.PageTemplateImpl.java
License:Open Source License
@SuppressWarnings("unchecked") AttributesImpl getAttributes(Element element, Expressions expressions) throws PageTemplateException { AttributesImpl attributes = new AttributesImpl(); for (Iterator<Attribute> i = element.attributeIterator(); i.hasNext();) { Attribute attribute = i.next(); Namespace namespace = attribute.getNamespace(); String name = attribute.getName(); // Handle ZPT attributes if (TAL_NAMESPACE_URI.equals(namespace.getURI())) { // tal:define if (name.equals(TAL_DEFINE)) { expressions.define = attribute.getValue(); }/*www. j av a 2 s .c om*/ // tal:condition else if (name.equals(TAL_CONDITION)) { expressions.condition = attribute.getValue(); } // tal:repeat else if (name.equals(TAL_REPEAT)) { expressions.repeat = attribute.getValue(); } // tal:content else if (name.equals(TAL_CONTENT)) { expressions.content = attribute.getValue(); } // tal:replace else if (name.equals(TAL_REPLACE)) { if (expressions.omitTag == null) { expressions.omitTag = VOID_STRING; } expressions.content = attribute.getValue(); } // tal:attributes else if (name.equals(TAL_ATTRIBUTES)) { expressions.attributes = attribute.getValue(); } // tal:omit-tag else if (name.equals(TAL_OMIT_TAG)) { expressions.omitTag = attribute.getValue(); } // tal:on-error else if (name.equals(TAL_ON_ERROR)) { expressions.onError = attribute.getValue(); } // tal:tag else if (name.equals(TAL_TAG)) { expressions.tag = attribute.getValue(); } // error else { throw new PageTemplateException( "Unknown tal attribute: " + name + " in '" + this.template.getName() + "' template"); } } else if (METAL_NAMESPACE_URI.equals(namespace.getURI())) { // metal:use-macro if (name.equals(METAL_USE_MACRO)) { expressions.useMacro = attribute.getValue(); } // metal:define-slot else if (name.equals(METAL_DEFINE_SLOT)) { expressions.defineSlot = attribute.getValue(); } // metal:define-macro // metal:fill-slot else if (name.equals(METAL_DEFINE_MACRO) || name.equals(METAL_FILL_SLOT)) { // these are ignored here, as they don't affect processing of current // template, but are called from other templates } // error else { throw new PageTemplateException( "Unknown metal attribute: " + name + " in '" + this.template.getName() + "' template"); } } else if (I18N_NAMESPACE_URI.equals(namespace.getURI())) { // i18n:domain if (name.equals(I18N_DOMAIN)) { expressions.i18nDomain = attribute.getValue(); } // i18n:define else if (name.equals(I18N_DEFINE)) { expressions.i18nDefine = attribute.getValue(); } // i18n:content else if (name.equals(I18N_CONTENT)) { expressions.i18nContent = attribute.getValue(); } // i18n:replace else if (name.equals(I18N_REPLACE)) { if (expressions.omitTag == null) { expressions.omitTag = VOID_STRING; } expressions.i18nContent = attribute.getValue(); } // i18n:attributes else if (name.equals(I18N_ATTRIBUTES)) { expressions.i18nAttributes = attribute.getValue(); } // i18n:params else if (name.equals(I18N_PARAMS)) { expressions.i18nParams = attribute.getValue(); } // i18n:on-error else if (name.equals(I18N_ON_ERROR)) { expressions.i18nOnError = attribute.getValue(); } // error else { throw new PageTemplateException( "Unknown i18n attribute: " + name + " in '" + this.template.getName() + "' template"); } } // Pass on all other attributes else { attributes.addAttribute(namespace.getURI(), name, attribute.getQualifiedName(), CDATA, attribute.getValue()); } } return attributes; }
From source file:org.zenonpagetemplates.onePhaseImpl.PageTemplateImpl.java
License:Open Source License
@SuppressWarnings({ "unchecked", "rawtypes" }) private void findMacros(Element element, Map<String, Macro> macros) { // Process any declared namespaces for (Iterator<Namespace> i = element.declaredNamespaces().iterator(); i.hasNext();) { Namespace namespace = i.next(); this.namespaces.put(namespace.getPrefix(), namespace.getURI()); }/*www . ja v a 2s . c o m*/ // Look for our attribute String name = element.attributeValue(METAL_DEFINE_MACRO); if (name != null) { macros.put(name, new MacroImpl(element)); } // Recurse into child elements for (Iterator i = element.elementIterator(); i.hasNext();) { findMacros((Element) i.next(), macros); } }
From source file:org.zenonpagetemplates.twoPhasesImpl.model.ZPTDocument.java
License:Open Source License
public void addNamespace(Namespace namespace) { this.namespaces.put(namespace.getPrefix(), namespace.getURI()); }