List of usage examples for org.w3c.dom Element getNamespaceURI
public String getNamespaceURI();
null
if it is unspecified (see ). From source file:org.jbpm.bpel.xml.BpelReader.java
protected void read(BpelProcessDefinition processDefinition, Element processElem, ProcessWsdlLocator wsdlLocator) { // see if the bpel document requires updating if (BpelConstants.NS_BPEL_1_1.equals(processElem.getNamespaceURI())) { try {//from ww w. j a va 2 s .c o m // create bpel upgrader Transformer bpelUpgrader = getBpelUpgradeTemplates().newTransformer(); // install our problem handler as transformer's error listener bpelUpgrader.setErrorListener(problemHandler.asTraxErrorListener()); // upgrade into dom document Document resultDocument = XmlUtil.createDocument(); bpelUpgrader.transform(new DOMSource(processElem.getOwnerDocument()), new DOMResult(resultDocument)); processElem = resultDocument.getDocumentElement(); log.debug("upgraded bpel document: " + processDefinition.getLocation()); } catch (TransformerException e) { Problem problem = new Problem(Problem.LEVEL_ERROR, "bpel upgrade failed", e); problem.setResource(processDefinition.getLocation()); problemHandler.add(problem); } // halt on transform errors if (problemHandler.getProblemCount() > 0) return; } // read attributes in the process element readProcessAttributes(processElem, processDefinition); // read imported documents ImportDefinition importDefinition = processDefinition.getImportDefinition(); readImports(processElem, importDefinition, wsdlLocator); // halt on import parse errors if (problemHandler.getProblemCount() > 0) return; try { // registration gets the query language from the process definition registerPropertyAliases(importDefinition); // finally read the global scope readScope(processElem, processDefinition.getGlobalScope()); log.debug("read bpel document: " + processDefinition.getLocation()); } catch (BpelException e) { problemHandler.add(new Problem(Problem.LEVEL_ERROR, "bpel process is invalid", e)); } }
From source file:org.jbpm.bpel.xml.util.XmlUtil.java
public static String toTraceString(Element elem) { String namespace = elem.getNamespaceURI(); String localName = elem.getLocalName(); // easy way out: no namespace if (namespace == null || namespace.length() == 0) return localName; StringBuffer traceBuffer = new StringBuffer(namespace.length() + localName.length()); traceBuffer.append('{').append(namespace).append('}'); String prefix = elem.getPrefix(); if (prefix != null && prefix.length() > 0) traceBuffer.append(prefix).append(':'); return traceBuffer.append(localName).toString(); }
From source file:org.jbpm.bpel.xml.util.XmlUtil.java
public static void ensureOwnNamespaceDeclared(Element elem) { ensureNamespaceDeclared(elem, elem.getNamespaceURI(), elem.getPrefix()); }
From source file:org.jzkit.search.util.RecordModel.XMLRecord.java
private String deriveSchemaFromDoc() { String result = null;//from w w w . j ava2 s. co m try { Document d = getDocument(); Element root_element = d.getDocumentElement(); String root_tag = root_element.getTagName(); // String tag_prefix = root_element.getPrefix(); String tag_namespace_uri = root_element.getNamespaceURI(); // log.debug("root_tag: "+root_tag); // log.debug("tag_prefix: "+tag_prefix); // log.debug("tag_namespace_uri: "+tag_namespace_uri); // If tag_namespace_uri we need to resolve it into a local name and then look up a canonical single // name for the schema. For now, we will just default to the root tag, but that is a bit pants. // result = ( tag_namespace_uri != null ? tag_namespace_uri+":"+root_tag : root_tag ); result = root_tag; } catch (Exception e) { log.debug("Problem: " + e); } return result; }
From source file:org.kalypsodeegree.xml.XMLTools.java
/** * Returns the specified child element of the given elemen. If there are more than one with the same name, the first * one is returned./*www. j av a2 s. co m*/ * <p> * * @param name * name of the child element * @param namespace * namespace of the child element * @param node * current element * @return the element or null, if it is missing * @throws XMLParsingException * specified child element is missing and required is true */ public static Element getRequiredChildByName(final String name, final String namespace, final Node node) throws XMLParsingException { final NodeList nl = node.getChildNodes(); Element element = null; Element result = null; if (nl != null && nl.getLength() > 0) { for (int i = 0; i < nl.getLength(); i++) { if (nl.item(i) instanceof Element) { element = (Element) nl.item(i); final String s = element.getNamespaceURI(); if (s == null && namespace == null || namespace != null && namespace.equals(s)) { if (element.getLocalName().equals(name)) { result = element; break; } } } } } if (result == null) { throw new XMLParsingException( "Required child-element '" + name + "' of element '" + node.getNodeName() + "' is missing!"); } return result; }
From source file:org.kalypsodeegree.xml.XMLTools.java
/** * Returns the specified child element of the given elemen. If there are more than one with the same name, the first * one is returned.//from w w w .j a va 2 s . c o m * <p> * * @param name * name of the child element * @param namespace * namespace of the child element * @param node * current element * @return the element or null, if it is missing */ public static Element getChildByName(final String name, final String namespace, final Node node) { final NodeList nl = node.getChildNodes(); if (nl != null && nl.getLength() > 0) { for (int i = 0; i < nl.getLength(); i++) { if (nl.item(i) instanceof Element) { final Element element = (Element) nl.item(i); final String s = element.getNamespaceURI(); if (s == null && namespace == null || namespace != null && namespace.equals(s)) { if (element.getLocalName().equals(name)) return element; } } } } return null; }
From source file:org.kalypsodeegree.xml.XMLTools.java
/** * Returns the specified child elements of the given element. * <p>// ww w .j a v a2s. c o m * * @param name * name of the child elements * @param namespace * namespace of the child elements * @param node * current element * @return the list of matching child elements */ public static ElementList getChildElementsByName(final String name, final String namespace, final Node node) { final NodeList nl = node.getChildNodes(); Element element = null; final ElementList elementList = new ElementList(); if (nl != null && nl.getLength() > 0) { for (int i = 0; i < nl.getLength(); i++) { if (nl.item(i) instanceof Element) { element = (Element) nl.item(i); final String s = element.getNamespaceURI(); if (s == null && namespace == null || namespace != null && namespace.equals(s)) { if (element.getLocalName().equals(name)) { elementList.addElement(element); } } } } } return elementList; }
From source file:org.kalypsodeegree.xml.XMLTools.java
/** * Returns the first child element of the submitted node that matches the given namespace and name. *//*from w ww . j av a 2 s .co m*/ public static Element getNamedChild(final Node node, final String namespace, final String name) { // Debug.debugMethodBegin( "XMLTools", "getNamedChild" ); final NodeList nl = node.getChildNodes(); Element element = null; Element return_ = null; if (nl != null && nl.getLength() > 0) { for (int i = 0; i < nl.getLength(); i++) { if (nl.item(i) instanceof Element) { element = (Element) nl.item(i); final String s = element.getNamespaceURI(); if (namespace == null && s == null || namespace.equals(s)) { if (element.getLocalName().equals(name)) { return_ = element; break; } } } } } // Debug.debugMethodEnd(); return return_; }
From source file:org.kalypsodeegree_impl.graphics.sld.SLDFactory.java
/** * Reads an sld file from an {@link InputStream}.<br> * The type of the returned element may be any of the top-level types defined in the sld-schema. * /*from w ww . j a v a 2s.c o m*/ * @throws XMLParsingException * if a syntactic or semantic error in the XML document is encountered * @return The read top-Level element */ public static Object readSLD(final IUrlResolver2 urlResolver, final InputStream is) throws XMLParsingException { try { final Document doc = XMLTools.parse(is); final Element element = doc.getDocumentElement(); final String namespaceURI = element.getNamespaceURI(); if (!NS_SLD.equals(namespaceURI)) throw new XMLParsingException(String.format("Root-Element must be of namespace '%s'", NS_SLD)); final String localName = element.getLocalName(); if ("StyledLayerDescriptor".equals(localName))//$NON-NLS-1$ return SLDFactory.createStyledLayerDescriptor(urlResolver, element); if ("NamedLayer".equals(localName))//$NON-NLS-1$ return SLDFactory.createNamedLayer(urlResolver, element); if ("UserLayer".equals(localName))//$NON-NLS-1$ return SLDFactory.createUserLayer(urlResolver, element); if ("UserStyle".equals(localName))//$NON-NLS-1$ return SLDFactory.createUserStyle(urlResolver, element); if ("FeatureTypeStyle".equals(localName))//$NON-NLS-1$ return SLDFactory.createFeatureTypeStyle(urlResolver, element); throw new XMLParsingException(String.format("Unable to parse Root-Element: '%s'", localName)); } catch (final IOException e) { throw new XMLParsingException("IOException encountered while parsing SLD-Document: " + e.getMessage(), e); } catch (final SAXException e) { throw new XMLParsingException("SAXException encountered while parsing SLD-Document: " + e.getMessage(), e); } }
From source file:org.kalypsodeegree_impl.graphics.sld.SLDFactory.java
/** * Creates a <tt>LabelPlacement</tt> -instance according to the contents of the DOM-subtree starting at the given * 'LabelPlacement'- <tt>Element</tt>. * <p>//from w w w. j av a2s . co m * * @param element * the 'LabelPlacement'- <tt>Element</tt> * @throws XMLParsingException * if a syntactic or semantic error in the DOM-subtree is encountered * @return the constructed <tt>LabelPlacement</tt> -instance */ private static LabelPlacement createLabelPlacement(final Element element) throws XMLParsingException { LabelPlacement labelPlacement = null; // required: <PointPlacement> / <LinePlacement> final NodeList nodelist = element.getChildNodes(); PointPlacement pPlacement = null; LinePlacement lPlacement = null; for (int i = 0; i < nodelist.getLength(); i++) if (nodelist.item(i) instanceof Element) { final Element child = (Element) nodelist.item(i); final String namespace = child.getNamespaceURI(); if (!NS.SLD.equals(namespace)) { continue; } final String childName = child.getLocalName(); if ("PointPlacement".equals(childName))//$NON-NLS-1$ { pPlacement = SLDFactory.createPointPlacement(child); } else if ("LinePlacement".equals(childName))//$NON-NLS-1$ { lPlacement = SLDFactory.createLinePlacement(child); } } if (pPlacement != null && lPlacement == null) { labelPlacement = new LabelPlacement_Impl(pPlacement); } else if (pPlacement == null && lPlacement != null) { labelPlacement = new LabelPlacement_Impl(lPlacement); } else throw new XMLParsingException("Element 'LabelPlacement' must contain exactly one " + "'PointPlacement'- or one 'LinePlacement'-element!"); return labelPlacement; }