List of usage examples for org.dom4j Namespace getURI
public String getURI()
From source file:eu.planets_project.pp.plato.services.characterisation.xcl.Comparator.java
License:Open Source License
/** * Generates a PCR for all <param>mappedProperties</param> and their metrics. * Note: All possible metrics are included. * /*from www . j av a 2s . c o m*/ * @param mappedProperties * @return */ private String generateConfig(Set<XCLObjectProperty> mappedProperties) { Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("pcRequest"); Namespace xsi = new Namespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); root.add(xsi); root.addAttribute(xsi.getPrefix() + ":schemaLocation", "http://www.planets-project.eu/xcl/schemas/xcl data/pp5/schemas/pcr/pcr.xsd"); Namespace xcl = new Namespace("", "http://www.planets-project.eu/xcl/schemas/xcl"); root.add(xcl); Element compSet = root.addElement("compSet", xcl.getURI()); compSet.addElement("source").addAttribute("name", "samplerecord"); compSet.addElement("target").addAttribute("name", "experimentresult"); /* Element root = doc.addElement("plans"); Namespace xsi = new Namespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); root.add(xsi); root.addAttribute(xsi.getPrefix()+":noNamespaceSchemaLocation", "http://www.ifs.tuwien.ac.at/dp/plato/schemas/plato-1.9.xsd"); */ for (XCLObjectProperty objectProperty : mappedProperties) { Element prop = compSet.addElement("property").addAttribute("id", objectProperty.getPropertyId()) .addAttribute("name", objectProperty.getName()); for (Metric metric : objectProperty.getMetrics()) { prop.addElement("metric").addAttribute("id", metric.getMetricId()).addAttribute("name", metric.getName()); } } return doc.asXML(); }
From source file:io.mashin.oep.hpdl.XMLReadUtils.java
License:Open Source License
public static void initSLAVersionFrom(Element node, HasSLAVersion model) { Namespace slaNamespace = node.getNamespaceForPrefix("sla"); String slaURI = slaNamespace != null ? slaNamespace.getURI() : ""; model.setSLAVersion(schemaVersion(slaURI)); //model.setSLAVersion(slaVersion(node)); }
From source file:net.sf.saxon.dom4j.NodeWrapper.java
License:Mozilla Public License
/** * Output all namespace nodes associated with this element. Does nothing if * the node is not an element./*from w ww . jav a 2s . c om*/ * @param out The relevant outputter * @param includeAncestors True if namespaces declared on ancestor elements must * be output; false if it is known that these are already on the result tree */ public void outputNamespaceNodes(Receiver out, boolean includeAncestors) throws XPathException { if (nodeKind == Type.ELEMENT) { NamePool pool = docWrapper.getNamePool(); AxisIterator enm = iterateAxis(Axis.NAMESPACE); while (true) { NodeWrapper wrapper = (NodeWrapper) enm.next(); if (wrapper == null) { break; } if (!includeAncestors && !wrapper.getParent().isSameNodeInfo(this)) { break; } Namespace ns = (Namespace) wrapper.node; int nscode = pool.allocateNamespaceCode(ns.getPrefix(), ns.getURI()); out.namespace(nscode, 0); } } }
From source file:net.sf.saxon.dom4j.NodeWrapper.java
License:Mozilla Public 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 w w w.j av a2s .c o m * <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.size() == 0) { return EMPTY_NAMESPACE_LIST; } final int count = namespaces.size(); if (count == 0) { return EMPTY_NAMESPACE_LIST; } else { int[] result = (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:net.sf.saxon.option.dom4j.NodeWrapper.java
License:Mozilla Public 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/>// ww w . ja v a2 s . c o m * <p>For a node other than an element, the method returns null.</p> */ public NamespaceBinding[] getDeclaredNamespaces(NamespaceBinding[] buffer) { if (node instanceof Element) { final Element elem = (Element) node; final List namespaces = elem.declaredNamespaces(); if (namespaces == null || namespaces.isEmpty()) { return NamespaceBinding.EMPTY_ARRAY; } final int count = namespaces.size(); if (count == 0) { return NamespaceBinding.EMPTY_ARRAY; } else { NamespaceBinding[] result = (buffer == null || count > buffer.length ? new NamespaceBinding[count] : buffer); 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++] = new NamespaceBinding(prefix, uri); } if (count < result.length) { result[count] = null; } return result; } } else { return null; } }
From source file:nl.tue.gale.ae.processor.XMLProcessor.java
License:Open Source License
public void traverse(Element element, Resource resource) throws ProcessorException { if (element == null) return;//from ww w . j av a 2s.co m Namespace ns = element.getNamespace(); String tag = null; if (ns != Namespace.NO_NAMESPACE) { tag = "{" + ns.getURI() + "}" + element.getName(); if (!moduleTable.containsKey(tag)) tag = null; } if (tag == null) tag = element.getName(); if (moduleTable.containsKey(tag)) { Module mod = moduleTable.get(tag); if (mod.getMimeToHandle().contains(GaleContext.mime(resource))) { try { element = moduleTable.get(tag).traverse(element, resource); } catch (Exception e) { e.printStackTrace(); element = (Element) GaleUtil.replaceNode(element, GaleUtil.createErrorElement("[" + e.getMessage() + "]")); } } } traverseChildren(element, resource); if ("text/xhtml".equals(GaleContext.mime(resource))) if (element != null) if ("http://www.w3.org/1999/xhtml".equals(element.getNamespaceURI())) element.setQName(DocumentFactory.getInstance().createQName(element.getName(), "", "http://www.w3.org/1999/xhtml")); }
From source file:org.apache.archiva.xml.XMLReader.java
License:Apache License
public String getDefaultNamespaceURI() { Namespace namespace = this.document.getRootElement().getNamespace(); return namespace.getURI(); }
From source file:org.apache.poi.openxml4j.opc.internal.unmarshallers.PackagePropertiesUnmarshaller.java
License:Apache License
/** * Check the element for the following OPC compliance rules: * <p>//from w w w . ja v a 2 s.c o m * Rule M4.2: A format consumer shall consider the use of the Markup * Compatibility namespace to be an error. * </p><p> * Rule M4.3: Producers shall not create a document element that contains * refinements to the Dublin Core elements, except for the two specified in * the schema: <dcterms:created> and <dcterms:modified> Consumers shall * consider a document element that violates this constraint to be an error. * </p><p> * Rule M4.4: Producers shall not create a document element that contains * the xml:lang attribute. Consumers shall consider a document element that * violates this constraint to be an error. * </p><p> * Rule M4.5: Producers shall not create a document element that contains * the xsi:type attribute, except for a <dcterms:created> or * <dcterms:modified> element where the xsi:type attribute shall be present * and shall hold the value dcterms:W3CDTF, where dcterms is the namespace * prefix of the Dublin Core namespace. Consumers shall consider a document * element that violates this constraint to be an error. * </p> */ public void checkElementForOPCCompliance(Element el) throws InvalidFormatException { // Check the current element @SuppressWarnings("unchecked") List<Namespace> declaredNamespaces = el.declaredNamespaces(); Iterator<Namespace> itNS = declaredNamespaces.iterator(); while (itNS.hasNext()) { Namespace ns = itNS.next(); // Rule M4.2 if (ns.getURI().equals(PackageNamespaces.MARKUP_COMPATIBILITY)) throw new InvalidFormatException( "OPC Compliance error [M4.2]: A format consumer shall consider the use of the Markup Compatibility namespace to be an error."); } // Rule M4.3 if (el.getNamespace().getURI().equals(PackageProperties.NAMESPACE_DCTERMS) && !(el.getName().equals(KEYWORD_CREATED) || el.getName().equals(KEYWORD_MODIFIED))) throw new InvalidFormatException( "OPC Compliance error [M4.3]: Producers shall not create a document element that contains refinements to the Dublin Core elements, except for the two specified in the schema: <dcterms:created> and <dcterms:modified> Consumers shall consider a document element that violates this constraint to be an error."); // Rule M4.4 if (el.attribute(new QName("lang", namespaceXML)) != null) throw new InvalidFormatException( "OPC Compliance error [M4.4]: Producers shall not create a document element that contains the xml:lang attribute. Consumers shall consider a document element that violates this constraint to be an error."); // Rule M4.5 if (el.getNamespace().getURI().equals(PackageProperties.NAMESPACE_DCTERMS)) { // DCTerms namespace only use with 'created' and 'modified' elements String elName = el.getName(); if (!(elName.equals(KEYWORD_CREATED) || elName.equals(KEYWORD_MODIFIED))) throw new InvalidFormatException("Namespace error : " + elName + " shouldn't have the following naemspace -> " + PackageProperties.NAMESPACE_DCTERMS); // Check for the 'xsi:type' attribute Attribute typeAtt = el.attribute(new QName("type", namespaceXSI)); if (typeAtt == null) throw new InvalidFormatException("The element '" + elName + "' must have the '" + namespaceXSI.getPrefix() + ":type' attribute present !"); // Check for the attribute value => 'dcterms:W3CDTF' if (!typeAtt.getValue().equals("dcterms:W3CDTF")) throw new InvalidFormatException("The element '" + elName + "' must have the '" + namespaceXSI.getPrefix() + ":type' attribute with the value 'dcterms:W3CDTF' !"); } // Check its children @SuppressWarnings("unchecked") Iterator<Element> itChildren = el.elementIterator(); while (itChildren.hasNext()) checkElementForOPCCompliance(itChildren.next()); }
From source file:org.arquillian.graphene.visual.testing.impl.JCRMaskHandler.java
private void addMasksToConfiguration(List<MaskFromREST> masks, Document doc) { Namespace ns = Namespace.get(RushEye.NAMESPACE_VISUAL_SUITE); String xPath = "/*[namespace-uri()=\"" + ns.getURI() + "\" and name()=\"visual-suite\"]/*[namespace-uri()=\"" + ns.getURI() + "\" and name()=\"global-configuration\"]"; Element configurationNode = (Element) doc.selectSingleNode(xPath); for (MaskFromREST mask : masks) { Element maskElement = configurationNode.addElement(QName.get("mask", ns)); maskElement.addAttribute("id", mask.getId()); maskElement.addAttribute("source", mask.getSourceUrl()); maskElement.addAttribute("type", mask.getMaskType().value()); }/*from w w w .j a v a 2 s . com*/ }
From source file:org.arquillian.graphene.visual.testing.impl.JCRMaskHandler.java
private void deleteMaskFromConfiguration(String maskID, Document doc) { Namespace ns = Namespace.get(RushEye.NAMESPACE_VISUAL_SUITE); String xPath = "/*[namespace-uri()=\"" + ns.getURI() + "\" and name()=\"visual-suite\"]/*[namespace-uri()=\"" + ns.getURI() + "\" and name()=\"global-configuration\"]/*[namespace-uri()=\"" + ns.getURI() + "\" and name()=\"mask\" and @id=\"" + maskID + "\"]"; Node maskElement = doc.selectSingleNode(xPath); maskElement.detach();//from w ww. j av a2s .c o m }