List of usage examples for org.w3c.dom Element getNamespaceURI
public String getNamespaceURI();
null
if it is unspecified (see ). From source file:org.openestate.io.openimmo.converters.OpenImmo_1_2_1Test.java
@Test public void testDowngradeXmlNamespace() { try {//from ww w .j a v a 2s. c om Document doc = buildTransferDocumentForDowngrade(); Element root; String ns; //System.out.println( "----------------------------" ); //System.out.println( "DOCUMENT BEFORE CONVERSION:" ); //DocumentUtils.write( doc, System.out ); //System.out.println( "----------------------------" ); root = XmlUtils.getRootElement(doc); ns = (root != null) ? StringUtils.trimToEmpty(root.getNamespaceURI()) : null; Assert.assertEquals("XML namespace before conversion.", StringUtils.EMPTY, ns); new OpenImmo_1_2_1().downgradeXmlNamespace(doc); //System.out.println( "----------------------------" ); //System.out.println( "DOCUMENT AFTER CONVERSION:" ); //DocumentUtils.write( doc, System.out ); //System.out.println( "----------------------------" ); root = XmlUtils.getRootElement(doc); ns = (root != null) ? StringUtils.trimToEmpty(root.getNamespaceURI()) : null; Assert.assertEquals("XML namespace after conversion.", OpenImmoUtils.OLD_NAMESPACE, ns); } catch (Exception ex) { LOGGER.error("Test of OpenImmo_1_2_1.downgradeXmlNamespace failed!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); Assert.fail("Test of OpenImmo_1_2_1.downgradeXmlNamespace failed!"); } }
From source file:org.openestate.io.openimmo.converters.OpenImmo_1_2_1Test.java
@Test public void testUpgradeXmlNamespace() { try {/*www .j a v a2 s . c om*/ Document doc = buildTransferDocumentForUpgrade(); Element root; String ns; //System.out.println( "----------------------------" ); //System.out.println( "DOCUMENT BEFORE CONVERSION:" ); //DocumentUtils.write( doc, System.out ); //System.out.println( "----------------------------" ); root = XmlUtils.getRootElement(doc); ns = (root != null) ? StringUtils.trimToEmpty(root.getNamespaceURI()) : null; Assert.assertEquals("XML namespace before conversion.", OpenImmoUtils.OLD_NAMESPACE, ns); new OpenImmo_1_2_1().upgradeXmlNamespace(doc); //System.out.println( "----------------------------" ); //System.out.println( "DOCUMENT AFTER CONVERSION:" ); //DocumentUtils.write( doc, System.out ); //System.out.println( "----------------------------" ); root = XmlUtils.getRootElement(doc); ns = (root != null) ? StringUtils.trimToEmpty(root.getNamespaceURI()) : null; Assert.assertEquals("XML namespace after conversion.", StringUtils.EMPTY, ns); } catch (Exception ex) { LOGGER.error("Test of OpenImmo_1_2_1.upgradeXmlNamespace failed!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); Assert.fail("Test of OpenImmo_1_2_1.upgradeXmlNamespace failed!"); } }
From source file:org.openestate.io.openimmo.OpenImmoFeedbackDocument.java
@Override public OpenImmoVersion getDocumentVersion() { String version;// w w w . j a v a2s . c o m try { Document doc = this.getDocument(); Element node = (Element) XmlUtils.newXPath("/io:openimmo_feedback/io:version", doc) .selectSingleNode(doc); // versions older then 1.2.4 do not support the <version> element // - version 1.2.3 is assumed, when no <version> element is present and // an empty namespace is used // - version 1.2.0 is assumed, when no <version> element is present and // the old namespace is used if (node == null) { Element root = XmlUtils.getRootElement(doc); return (OpenImmoUtils.OLD_NAMESPACE.equalsIgnoreCase(root.getNamespaceURI())) ? OpenImmoVersion.V1_2_0 : OpenImmoVersion.V1_2_3; } version = StringUtils.trimToNull(node.getTextContent()); if (version == null) { LOGGER.warn("Can't find version informations in the XML document!"); //System.out.println( "----------------------------" ); //try //{ // DocumentUtils.write( doc, System.out ); //} //catch (Exception ex) //{ // LOGGER.error( "Can't write XML document!" ); // LOGGER.error( "> " + ex.getLocalizedMessage(), ex ); //} //System.out.println( "----------------------------" ); return null; } } catch (JaxenException ex) { LOGGER.error("Can't evaluate XPath expression!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); return null; } OpenImmoVersion v = OpenImmoVersion.detectFromString(version); if (v != null) return v; LOGGER.warn("The provided version (" + version + ") is not supported!"); return null; }
From source file:org.openmrs.projectbuendia.webservices.rest.XformResource.java
/** * Removes the relationship nodes added (unconditionally) by xforms. If * XFRM-189 is fixed, this method can go away. *//*from w w w . j a v a2 s . c om*/ static String removeRelationshipNodes(String xml) throws IOException, SAXException { Document doc = XmlUtil.parse(xml); removeBinding(doc, "patient_relative"); removeBinding(doc, "patient_relative.person"); removeBinding(doc, "patient_relative.relationship"); for (Element relative : toElementIterable(doc.getElementsByTagNameNS("", "patient_relative"))) { removeNode(relative); } // Remove every parent of a label element with a text of // "RELATIONSHIPS". (Easiest way to find the ones added...) for (Element label : toElementIterable(doc.getElementsByTagNameNS(XFORMS_NAMESPACE, "label"))) { Element parent = (Element) label.getParentNode(); if (XFORMS_NAMESPACE.equals(parent.getNamespaceURI()) && parent.getLocalName().equals("group") && "RELATIONSHIPS".equals(label.getTextContent())) { removeNode(parent); // We don't need to find other labels now, especially if they // may already have been removed. break; } } return XformsUtil.doc2String(doc); }
From source file:org.osaf.caldav4j.methods.PropFindMethod.java
/** * A lot of this code had to be copied from the parent XMLResponseMethodBase, since it's * initHashtable doesn't allow for new types of Responses. * // w w w.j av a2 s.co m * Of course, the same mistake is being made here, so it is a TODO to fix that * */ @SuppressWarnings("unchecked") private void initHashtable() { responseHashtable = new Hashtable<String, CalDAVResponse>(); responseURLs = new Vector<String>(); // Also accept OK sent by buggy servers in reply to a PROPFIND // or REPORT (Xythos, Catacomb, ...?). int statusCode = getStatusCode(); if (statusCode == WebdavStatus.SC_MULTI_STATUS) { Document rdoc = getResponseDocument(); NodeList list = null; if (rdoc != null) { Element multistatus = getResponseDocument().getDocumentElement(); list = multistatus.getChildNodes(); } if (list != null) { for (int i = 0; i < list.getLength(); i++) { try { Element child = (Element) list.item(i); String name = DOMUtils.getElementLocalName(child); String namespace = DOMUtils.getElementNamespaceURI(child); if (Response.TAG_NAME.equals(name) && "DAV:".equals(namespace)) { CalDAVResponse response = new CalDAVResponse(child); String href = response.getHref(); responseHashtable.put(href, response); responseURLs.add(href); } } catch (ClassCastException e) { } } } } else if (statusCode == WebdavStatus.SC_CONFLICT || statusCode == WebdavStatus.SC_FORBIDDEN) { Document rdoc = getResponseDocument(); Element errorElement = rdoc.getDocumentElement(); // first make sure that the element is actually an error. if (!errorElement.getNamespaceURI().equals(NS_DAV) || !errorElement.getLocalName().equals(ELEMENT_ERROR)) { Node condition = errorElement.getChildNodes().item(0); error = errorMap.get(new QName(condition.getNamespaceURI(), condition.getLocalName())); } } }
From source file:org.osaf.cosmo.xml.DomWriter.java
private static void writeElement(Element e, XMLStreamWriter writer) throws XMLStreamException { //if (log.isDebugEnabled()) //log.debug("Writing element " + e.getNodeName()); String local = e.getLocalName(); if (local == null) local = e.getNodeName();//from w ww .j a va 2s. co m String ns = e.getNamespaceURI(); if (ns != null) { String prefix = e.getPrefix(); if (prefix != null) { writer.writeStartElement(prefix, local, ns); writer.writeNamespace(prefix, ns); } else { writer.setDefaultNamespace(ns); writer.writeStartElement(ns, local); writer.writeDefaultNamespace(ns); } } else { writer.writeStartElement(local); } NamedNodeMap attributes = e.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) writeAttribute((Attr) attributes.item(i), writer); NodeList children = e.getChildNodes(); for (int i = 0; i < children.getLength(); i++) writeNode(children.item(i), writer); writer.writeEndElement(); }
From source file:org.owasp.webscarab.plugin.saml.SamlModel.java
public static Element findProtocolSignatureElement(Document document) { Element documentElement = document.getDocumentElement(); NodeList documentChildNodes = documentElement.getChildNodes(); int documentNodeCount = documentChildNodes.getLength(); for (int nodeIdx = 0; nodeIdx < documentNodeCount; nodeIdx++) { Node node = documentChildNodes.item(nodeIdx); if (Node.ELEMENT_NODE == node.getNodeType()) { Element element = (Element) node; if (false == "http://www.w3.org/2000/09/xmldsig#".equals(element.getNamespaceURI())) { continue; }//ww w . j a v a 2 s.c o m if (false == "Signature".equals(element.getLocalName())) { continue; } return element; } } return null; }
From source file:org.owasp.webscarab.plugin.saml.SamlModel.java
public static Element findAssertionSignatureElement(Document document) { NodeList assertionNodeList = document.getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion", "Assertion"); if (0 == assertionNodeList.getLength()) { assertionNodeList = document.getElementsByTagNameNS("urn:oasis:names:tc:SAML:1.0:assertion", "Assertion"); if (0 == assertionNodeList.getLength()) { return null; }/* w ww . j a v a 2s. c o m*/ } Node assertionNode = assertionNodeList.item(0); NodeList assertionChildrenNodeList = assertionNode.getChildNodes(); int assertionChildrenNodeCount = assertionChildrenNodeList.getLength(); for (int nodeIdx = 0; nodeIdx < assertionChildrenNodeCount; nodeIdx++) { Node node = assertionChildrenNodeList.item(nodeIdx); if (Node.ELEMENT_NODE == node.getNodeType()) { Element element = (Element) node; if (false == "http://www.w3.org/2000/09/xmldsig#".equals(element.getNamespaceURI())) { continue; } if (false == "Signature".equals(element.getLocalName())) { continue; } return element; } } return null; }
From source file:org.springframework.ide.eclipse.osgi.blueprint.internal.BlueprintParser.java
/** * Parse a value, ref or collection sub-element of a property or * constructor-arg element. This method is called from several places to * handle reusable elements such as idref, ref, null, value and so on. * /*w ww . jav a 2s . c o m*/ * In fact, this method is the main reason why the * BeanDefinitionParserDelegate is not used in full since the element * namespace becomes important as mixed rfc124/bean content can coexist. * * @param ele * subelement of property element; we don't know which yet * @param defaultValueType * the default type (class name) for any * <code><value></code> tag that might be created */ private Object parsePropertySubElement(Element ele, BeanDefinition bd, String defaultValueType) { // skip other namespace String namespaceUri = ele.getNamespaceURI(); // check Spring own namespace if (parserContext.getDelegate().isDefaultNamespace(namespaceUri)) { return parserContext.getDelegate().parsePropertySubElement(ele, bd); } // let the delegate handle other ns else if (!NAMESPACE_URI.equals(namespaceUri)) { return parserContext.getDelegate().parseCustomElement(ele); } // else { if (DomUtils.nodeNameEquals(ele, BEAN)) { BeanDefinitionHolder bdHolder = parseComponentDefinitionElement(ele, bd); if (bdHolder != null) { bdHolder = ParsingUtils.decorateBeanDefinitionIfRequired(ele, bdHolder, parserContext); } return bdHolder; } if (DomUtils.nodeNameEquals(ele, BeanDefinitionParserDelegate.REF_ELEMENT)) { return parseRefElement(ele); } else if (DomUtils.nodeNameEquals(ele, BeanDefinitionParserDelegate.IDREF_ELEMENT)) { return parseIdRefElement(ele); } else if (DomUtils.nodeNameEquals(ele, BeanDefinitionParserDelegate.VALUE_ELEMENT)) { return parseValueElement(ele, defaultValueType); } else if (DomUtils.nodeNameEquals(ele, BeanDefinitionParserDelegate.NULL_ELEMENT)) { // It's a distinguished null value. Let's wrap it in a // TypedStringValue // object in order to preserve the source location. TypedStringValue nullHolder = new TypedStringValue(null); nullHolder.setSource(parserContext.extractSource(ele)); return nullHolder; } else if (DomUtils.nodeNameEquals(ele, BeanDefinitionParserDelegate.ARRAY_ELEMENT)) { return parseArrayElement(ele, bd); } else if (DomUtils.nodeNameEquals(ele, BeanDefinitionParserDelegate.LIST_ELEMENT)) { return parseListElement(ele, bd); } else if (DomUtils.nodeNameEquals(ele, BeanDefinitionParserDelegate.SET_ELEMENT)) { return parseSetElement(ele, bd); } else if (DomUtils.nodeNameEquals(ele, BeanDefinitionParserDelegate.MAP_ELEMENT)) { return parseMapElement(ele, bd); } else if (DomUtils.nodeNameEquals(ele, BeanDefinitionParserDelegate.PROPS_ELEMENT)) { return parsePropsElement(ele); } // maybe it's a nested service/reference/ref-list/ref-set return parserContext.getDelegate().parseCustomElement(ele, bd); } }
From source file:org.springframework.ws.wsdl.wsdl11.provider.DefaultMessagesProvider.java
/** * Indicates whether the given element should be includes as {@link Message} in the definition. * <p/>/*from w w w .j av a 2s.com*/ * Default implementation checks whether the element has the XML Schema namespace, and if it has the local name * "element". * * @param element the element elligable for being a message * @return <code>true</code> if to be included as message; <code>false</code> otherwise */ protected boolean isMessageElement(Element element) { return "element".equals(element.getLocalName()) && "http://www.w3.org/2001/XMLSchema".equals(element.getNamespaceURI()); }