List of usage examples for org.w3c.dom Element getPrefix
public String getPrefix();
null
if it is unspecified. From source file:org.apache.ws.security.message.WSSecSignature.java
protected Set getInclusivePrefixes(Element target, boolean excludeVisible) { Set result = new HashSet(); Node parent = target;/*from w w w .j a va 2 s .c o m*/ while (!(parent.getParentNode() instanceof Document)) { parent = parent.getParentNode(); NamedNodeMap attributes = parent.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Node attribute = attributes.item(i); if (attribute.getNamespaceURI() != null && attribute.getNamespaceURI().equals(org.apache.ws.security.WSConstants.XMLNS_NS)) { if (attribute.getNodeName().equals("xmlns")) { result.add("#default"); } else { result.add(attribute.getLocalName()); } } } } if (excludeVisible == true) { NamedNodeMap attributes = target.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Node attribute = attributes.item(i); if (attribute.getNamespaceURI() != null && attribute.getNamespaceURI().equals(org.apache.ws.security.WSConstants.XMLNS_NS)) { if (attribute.getNodeName().equals("xmlns")) { result.remove("#default"); } else { result.remove(attribute.getLocalName()); } } if (attribute.getPrefix() != null) { result.remove(attribute.getPrefix()); } } if (target.getPrefix() == null) { result.remove("#default"); } else { result.remove(target.getPrefix()); } } return result; }
From source file:org.apache.ws.security.message.WSSecSignatureBase.java
/** * Get the List of inclusive prefixes from the DOM Element argument *//* w ww . j a va 2 s . co m*/ public List<String> getInclusivePrefixes(Element target, boolean excludeVisible) { List<String> result = new ArrayList<String>(); Node parent = target; while (parent.getParentNode() != null && !(Node.DOCUMENT_NODE == parent.getParentNode().getNodeType())) { parent = parent.getParentNode(); NamedNodeMap attributes = parent.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Node attribute = attributes.item(i); if (WSConstants.XMLNS_NS.equals(attribute.getNamespaceURI())) { if ("xmlns".equals(attribute.getNodeName())) { result.add("#default"); } else { result.add(attribute.getLocalName()); } } } } if (excludeVisible) { NamedNodeMap attributes = target.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Node attribute = attributes.item(i); if (WSConstants.XMLNS_NS.equals(attribute.getNamespaceURI())) { if ("xmlns".equals(attribute.getNodeName())) { result.remove("#default"); } else { result.remove(attribute.getLocalName()); } } if (attribute.getPrefix() != null) { result.remove(attribute.getPrefix()); } } if (target.getPrefix() == null) { result.remove("#default"); } else { result.remove(target.getPrefix()); } } return result; }
From source file:org.apache.ws.security.util.WSSecurityUtil.java
/** * create a new element in the same namespace <p/> * /*from www. j av a2 s. c o m*/ * @param parent for the new element * @param localName of the new element * @return the new element */ private static Element createElementInSameNamespace(Element parent, String localName) { String qName = localName; String prefix = parent.getPrefix(); if (prefix != null && prefix.length() > 0) { qName = prefix + ":" + localName; } String nsUri = parent.getNamespaceURI(); return parent.getOwnerDocument().createElementNS(nsUri, qName); }
From source file:org.apache.xml.security.c14n.implementations.Canonicalizer11.java
protected void handleParent(Element e, NameSpaceSymbTable ns) { if (!e.hasAttributes() && e.getNamespaceURI() == null) { return;/* ww w .j ava 2 s .com*/ } xmlattrStack.push(-1); NamedNodeMap attrs = e.getAttributes(); int attrsLength = attrs.getLength(); for (int i = 0; i < attrsLength; i++) { Attr attribute = (Attr) attrs.item(i); String NName = attribute.getLocalName(); String NValue = attribute.getNodeValue(); if (Constants.NamespaceSpecNS.equals(attribute.getNamespaceURI())) { if (!XML.equals(NName) || !Constants.XML_LANG_SPACE_SpecNS.equals(NValue)) { ns.addMapping(NName, NValue, attribute); } } else if (!"id".equals(NName) && XML_LANG_URI.equals(attribute.getNamespaceURI())) { xmlattrStack.addXmlnsAttr(attribute); } } if (e.getNamespaceURI() != null) { String NName = e.getPrefix(); String NValue = e.getNamespaceURI(); String Name; if (NName == null || NName.equals("")) { NName = "xmlns"; Name = "xmlns"; } else { Name = "xmlns:" + NName; } Attr n = e.getOwnerDocument().createAttributeNS("http://www.w3.org/2000/xmlns/", Name); n.setValue(NValue); ns.addMapping(NName, NValue, n); } }
From source file:org.chiba.xml.xforms.CustomElementFactory.java
public boolean isCustomActionElement(Element element) throws XFormsException { if (this.noCustomElements) { //no custom elements configured return false; }/*from www. jav a 2 s . co m*/ //key to search the Map for a custom element String key = getKeyForElement(element); if (ACTIONS_ELEMENTS.containsKey(key)) { //a match was found return true; } //if the element is not recognized but it has a //mustUnderstand attribute, throw an exception to //signal error according to the spec if (element.hasAttributeNS(NamespaceConstants.XFORMS_NS, MUST_UNDERSTAND_ATTRIBUTE)) { String elementId = element.getPrefix() + ":" + element.getLocalName(); throw new XFormsException("MustUnderstand Module failure at element " + elementId); } //no matching configuration was found return false; }
From source file:org.deegree.framework.xml.XMLFragment.java
/** * Returns the qualified name of the given element. * //from www .ja v a 2 s. c om * @param element * @return the qualified name of the given element. * @throws XMLParsingException */ protected QualifiedName getQualifiedName(Element element) throws XMLParsingException { // TODO check if we can use element.getNamespaceURI() instead URI nsURI = null; String prefix = element.getPrefix(); try { nsURI = XMLTools.getNamespaceForPrefix(prefix, element); } catch (URISyntaxException e) { String msg = Messages.format("ERROR_NSURI_NO_URI", element.getPrefix()); LOG.logError(msg, e); throw new XMLParsingException(msg, e); } QualifiedName ftName = new QualifiedName(prefix, element.getLocalName(), nsURI); return ftName; }
From source file:org.fireflow.model.io.Util4Serializer.java
/** * Add a child element with the specific name to the given parent * element and return the child element. This method will use the * namespace of the parent element for the child element's namespace. * // ww w . ja v a2s . c o m * @param parent The parent element * @param name The new child element name * @return The child element */ public static Element addElement(Element parent, String name) { Document doc = parent.getOwnerDocument(); String qualifiedName = name; if (!StringUtils.isEmpty(parent.getPrefix())) { qualifiedName = parent.getPrefix() + ":" + name; } Element child = doc.createElementNS(parent.getNamespaceURI(), qualifiedName); parent.appendChild(child); return child; }
From source file:org.globus.wsrf.tools.wsdl.TypesProcessor.java
public void addResourceProperties(QName portTypeName, Map resourcePropertyElements, Map schemaDocumentLocations) throws Exception { logger.debug("Starting to build resource properties element"); PortType portType = this.getPortType(portTypeName); QName resourceProperties = (QName) portType.getExtensionAttribute(RP); addPrefix(WSRP_NS, "wsrp"); Element schema = getSchema(); Document doc = schema.getOwnerDocument(); String schemaPrefix = ""; if (schema.getPrefix() != null) { schemaPrefix = schema.getPrefix() + ":"; }/*w w w .j a va 2 s .c o m*/ Element properties = null; if (resourceProperties == null) { resourceProperties = new QName(portType.getQName().getLocalPart() + "GTWSDLResourceProperties"); portType.setExtensionAttribute(RP, resourceProperties); properties = doc.createElementNS(XSD_NS, schemaPrefix + "element"); properties.setAttribute("name", resourceProperties.getLocalPart()); properties.appendChild(doc.createTextNode("\n ")); schema.appendChild(properties); schema.appendChild(doc.createTextNode("\n ")); } else { NodeList elementNodes = schema.getElementsByTagNameNS(XSD_NS, "element"); String name; Element element; for (int i = 0; i < elementNodes.getLength(); i++) { element = (Element) elementNodes.item(i); name = element.getAttribute("name"); if (name != null && XmlUtils.getFullQNameFromString(name, element).getLocalPart() .equals(resourceProperties.getLocalPart())) { properties = element; break; } } if (properties == null) { throw new Exception( "Unable to find '" + resourceProperties + "' element in WSDL schema section of '" + this.definition.getDocumentBaseURI() + "' document."); } } String type = properties.getAttribute("type"); NodeList complexTypeElements; Element complexType = null; if (type != null && !type.equals("")) { complexTypeElements = schema.getElementsByTagNameNS(XSD_NS, "complexType"); Element currentType; QName currentName; QName typeName = XmlUtils.getFullQNameFromString(type, properties); for (int i = 0; i < complexTypeElements.getLength(); i++) { currentType = (Element) complexTypeElements.item(i); currentName = XmlUtils.getFullQNameFromString(currentType.getAttribute("name"), currentType); if (currentName.getLocalPart().equals(typeName.getLocalPart())) { complexType = currentType; break; } } if (complexType == null) { throw new Exception("Unable to find type entry for '" + resourceProperties + "' element"); } } else { complexTypeElements = properties.getElementsByTagNameNS(XSD_NS, "complexType"); if (complexTypeElements.getLength() > 0) { complexType = (Element) complexTypeElements.item(0); } else { complexType = doc.createElementNS(XSD_NS, schemaPrefix + "complexType"); complexType.appendChild(doc.createTextNode("\n ")); properties.appendChild(complexType); properties.appendChild(doc.createTextNode("\n ")); } } NodeList sequenceElements = complexType.getElementsByTagNameNS(XSD_NS, "sequence"); Element sequence; if (sequenceElements.getLength() > 0) { sequence = (Element) sequenceElements.item(0); } else { sequence = doc.createElementNS(XSD_NS, schemaPrefix + "sequence"); complexType.appendChild(sequence); complexType.appendChild(doc.createTextNode("\n ")); } Collection resourcePropertiesList = resourcePropertyElements.values(); Iterator elementIterator = resourcePropertiesList.iterator(); int nsCounter = 0; while (elementIterator.hasNext()) { sequence.appendChild(doc.createTextNode("\n ")); Element resourcePropertyElement = doc.createElementNS(XSD_NS, schemaPrefix + "element"); XSParticle particle = (XSParticle) elementIterator.next(); XSElementDeclaration element = (XSElementDeclaration) particle.getTerm(); String prefix = XmlUtils.getPrefix(element.getNamespace(), schema); addSchemaDefinitions(element, schemaDocumentLocations, schema); if (prefix == null) { prefix = "rpns" + String.valueOf(nsCounter++); Attr nameSpace = doc.createAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:" + prefix); nameSpace.setValue(element.getNamespace()); schema.setAttributeNode(nameSpace); } resourcePropertyElement.setAttribute("ref", prefix + ":" + element.getName()); resourcePropertyElement.setAttribute("minOccurs", String.valueOf(particle.getMinOccurs())); if (particle.getMaxOccursUnbounded()) { resourcePropertyElement.setAttribute("maxOccurs", String.valueOf("unbounded")); } else { resourcePropertyElement.setAttribute("maxOccurs", String.valueOf(particle.getMaxOccurs())); } sequence.appendChild(resourcePropertyElement); } sequence.appendChild(doc.createTextNode("\n ")); logger.debug("Resource properties element: " + XmlUtils.getElementAsString(properties)); }
From source file:org.globus.wsrf.tools.wsdl.TypesProcessor.java
private void addSchemaDefinitions(String elementNS, Map schemaDocumentLocations, Element schema) throws Exception { Map map = (Map) schemaDocumentLocations.get(elementNS); if (map == null) { return;//from w w w. j a v a2 s .co m } Set locations = map.keySet(); Iterator locationsIterator = locations.iterator(); String targetNS = schema.getAttribute("targetNamespace"); Document owner = schema.getOwnerDocument(); String schemaPrefix = schema.getPrefix(); if (schemaPrefix == null) { schemaPrefix = ""; } else { schemaPrefix += ":"; } this.populateImportsMap(schema); this.populateIncludesMap(schema); while (locationsIterator.hasNext()) { String location = (String) locationsIterator.next(); if (!location.equals(definition.getDocumentBaseURI())) { location = WSDLPreprocessor.getRelativePath(definition.getDocumentBaseURI(), location); if (elementNS.equals(targetNS)) { Map includes = (Map) this.includes.get(elementNS); if (includes == null) { includes = new HashMap(); this.includes.put(elementNS, includes); } if (!includes.containsKey(location)) { Element include = owner.createElementNS(XSD_NS, schemaPrefix + "include"); include.setAttribute("schemaLocation", location); schema.insertBefore(owner.createTextNode("\n"), schema.getFirstChild()); schema.insertBefore(include, schema.getFirstChild()); schema.insertBefore(owner.createTextNode("\n"), schema.getFirstChild()); includes.put(location, null); } } else { Map imports = (Map) this.imports.get(elementNS); if (imports == null) { imports = new HashMap(); this.imports.put(elementNS, imports); } if (!imports.containsKey(location)) { Element xsdImport = owner.createElementNS(XSD_NS, schemaPrefix + "import"); xsdImport.setAttribute("namespace", elementNS); xsdImport.setAttribute("schemaLocation", location); schema.insertBefore(owner.createTextNode("\n"), schema.getFirstChild()); schema.insertBefore(xsdImport, schema.getFirstChild()); schema.insertBefore(owner.createTextNode("\n"), schema.getFirstChild()); imports.put(location, null); } } } } }
From source file:org.jbpm.bpel.integration.soap.SoapUtil.java
public static void copyChildElement(SOAPElement parent, Element source) throws SOAPException { String localName = source.getLocalName(); String prefix = source.getPrefix(); String namespaceURI = source.getNamespaceURI(); Name targetName;//from ww w.ja v a2 s . c o m SOAPEnvelope envelope = findEnvelope(parent); if (prefix == null || prefix.length() == 0) { // source has no prefix, distinguish between no namespace and default namespace if (namespaceURI == null || namespaceURI.length() == 0) { // no namespace targetName = envelope.createName(localName); if (traceEnabled) log.trace("appended element: " + localName); } else { // default namespace, look for existing prefix at target prefix = getPrefix(namespaceURI, parent); // no prefix for that namespace? if (prefix == null) { prefix = XmlUtil.generatePrefix(DEFAULT_NAMESPACE_PREFIX, source); } // BPEL-195 source maps prefix to another URI? else if (!namespaceURI.equals(source.getAttributeNS(BpelConstants.NS_XMLNS, prefix))) { prefix = XmlUtil.generatePrefix(prefix, source); } targetName = envelope.createName(localName, prefix, namespaceURI); if (traceEnabled) log.trace("added child element: {" + namespaceURI + '}' + prefix + ':' + localName); } } else { // source has prefix targetName = envelope.createName(localName, prefix, namespaceURI); if (traceEnabled) log.trace("added child element: {" + namespaceURI + '}' + prefix + ':' + localName); } SOAPElement target; if (parent instanceof SOAPBody) { /* * jboss-ws4ee throws ClassCastException upon calling the remote endpoint if child elements * other than SOAPBodyElements are added to SOAPBody */ SOAPBody body = (SOAPBody) parent; target = body.addBodyElement(targetName); } else target = parent.addChildElement(targetName); // namespaces copyNamespaces(target, source); ensureOwnNamespaceDeclared(target); // attributes copyAttributes(target, source); // child nodes copyChildNodes(target, source); }