List of usage examples for org.w3c.dom Attr getLocalName
public String getLocalName();
From source file:org.apache.axis2.jaxws.message.util.impl.XMLStreamReaderFromDOM.java
public QName getAttributeName(int index) { Attr attr = (Attr) getAttributes().get(index); return new QName(attr.getNamespaceURI(), attr.getLocalName()); }
From source file:org.apache.axis2.jaxws.message.util.impl.XMLStreamReaderFromDOM.java
public String getAttributeLocalName(int index) { Attr attr = (Attr) getAttributes().get(index); return attr.getLocalName(); }
From source file:org.apache.cocoon.forms.util.DomHelper.java
private static Map addLocalNSDeclarations(Element elm, Map nsDeclarations) { NamedNodeMap atts = elm.getAttributes(); int attsSize = atts.getLength(); for (int i = 0; i < attsSize; i++) { Attr attr = (Attr) atts.item(i); if (XMLNS_URI.equals(attr.getNamespaceURI())) { String nsUri = attr.getValue(); String pfx = attr.getLocalName(); if (nsDeclarations == null) nsDeclarations = new HashMap(); nsDeclarations.put(nsUri, pfx); }//w ww .j a v a2 s. co m } return nsDeclarations; }
From source file:org.apache.ode.il.OMUtils.java
public static OMElement toOM(Element src, OMFactory omf, OMContainer parent) { OMElement omElement = parent == null ? omf.createOMElement(src.getLocalName(), null) : omf.createOMElement(src.getLocalName(), null, parent); if (src.getNamespaceURI() != null) { if (src.getPrefix() != null) omElement.setNamespace(omf.createOMNamespace(src.getNamespaceURI(), src.getPrefix())); else//w w w .ja va 2 s . c o m omElement.declareDefaultNamespace(src.getNamespaceURI()); } if (parent == null) { NSContext nscontext = DOMUtils.getMyNSContext(src); injectNamespaces(omElement, nscontext.toMap()); } else { Map<String, String> nss = DOMUtils.getMyNamespaces(src); injectNamespaces(omElement, nss); } NamedNodeMap attrs = src.getAttributes(); for (int i = 0; i < attrs.getLength(); ++i) { Attr attr = (Attr) attrs.item(i); if (attr.getLocalName().equals("xmlns") || (attr.getNamespaceURI() != null && attr.getNamespaceURI().equals(DOMUtils.NS_URI_XMLNS))) continue; OMNamespace attrOmNs = null; String attrNs = attr.getNamespaceURI(); String attrPrefix = attr.getPrefix(); if (attrNs != null) attrOmNs = omElement.findNamespace(attrNs, null); if (attrOmNs == null && attrPrefix != null) attrOmNs = omElement.findNamespace(null, attrPrefix); omElement.addAttribute(attr.getLocalName(), attr.getValue(), attrOmNs); } NodeList children = src.getChildNodes(); for (int i = 0; i < children.getLength(); ++i) { Node n = children.item(i); switch (n.getNodeType()) { case Node.CDATA_SECTION_NODE: omElement.addChild(omf.createOMText(((CDATASection) n).getTextContent(), XMLStreamConstants.CDATA)); break; case Node.TEXT_NODE: omElement.addChild(omf.createOMText(((Text) n).getTextContent(), XMLStreamConstants.CHARACTERS)); break; case Node.ELEMENT_NODE: toOM((Element) n, omf, omElement); break; } } return omElement; }
From source file:org.apache.openejb.server.axis.assembler.CommonsSchemaInfoBuilder.java
/** * Extract the nested component type of an Array from the XML Schema Type. * * @return the QName of the nested component type or null if the schema type can not be determined * @throws org.apache.openejb.OpenEJBException if the XML Schema Type can not represent an Array @param complexType *//*www.ja va 2s . c o m*/ private static QName extractSoapArrayComponentType(XmlSchemaComplexType complexType) { // Soap arrays are based on complex content restriction if (!isSoapArray(complexType)) { return null; } XmlSchemaComplexContentRestriction restriction = (XmlSchemaComplexContentRestriction) complexType .getContentModel().getContent(); //First, handle case that looks like this: // <complexType name="ArrayOfstring"> // <complexContent> // <restriction base="soapenc:Array"> // <attribute ref="soapenc:arrayType" wsdl:arrayType="xsd:string[]"/> // </restriction> // </complexContent> // </complexType> XmlSchemaObjectCollection attributes = restriction.getAttributes(); for (Iterator iterator = attributes.getIterator(); iterator.hasNext();) { Object item = iterator.next(); if (item instanceof XmlSchemaAttribute) { XmlSchemaAttribute attribute = (XmlSchemaAttribute) item; if (attribute.getRefName().equals(SOAP_ARRAY_TYPE)) { for (Attr attr : attribute.getUnhandledAttributes()) { QName attQName = new QName(attr.getNamespaceURI(), attr.getLocalName()); if (WSDL_ARRAY_TYPE.equals(attQName)) { // value is a namespace prefixed xsd type String value = attr.getValue(); // extract local part int pos = value.lastIndexOf(":"); QName componentType; if (pos < 0) { componentType = new QName("", value); } else { String localPart = value.substring(pos + 1); // resolve the namespace prefix String prefix = value.substring(0, pos); String namespace = getNamespaceForPrefix(prefix, attr.getOwnerElement()); componentType = new QName(namespace, localPart); } log.debug("determined component type from element type"); return componentType; } } } } } // If that didn't work, try to handle case like this: // <complexType name="ArrayOfstring1"> // <complexContent> // <restriction base="soapenc:Array"> // <sequence> // <element name="string1" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/> // </sequence> // </restriction> // </complexContent> // </complexType> XmlSchemaParticle particle = restriction.getParticle(); if (particle instanceof XmlSchemaSequence) { XmlSchemaSequence sequence = (XmlSchemaSequence) particle; if (sequence.getItems().getCount() != 1) { throw new IllegalArgumentException("more than one element inside array definition: " + complexType); } XmlSchemaObject item = sequence.getItems().getItem(0); if (item instanceof XmlSchemaElement) { XmlSchemaElement element = (XmlSchemaElement) item; QName componentType = element.getSchemaTypeName(); log.debug("determined component type from element type"); return componentType; } } return null; }
From source file:org.apache.openejb.server.axis.assembler.CommonsSchemaInfoBuilder.java
private static String getNamespaceForPrefix(String prefix, Element element) { NamedNodeMap attributes = element.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Node node = attributes.item(i); if (node instanceof Attr) { Attr attr = (Attr) node; if (XML_NS_NS.equals(attr.getNamespaceURI())) { // this is a namespace declaration, is it the one we are looking for? if (attr.getLocalName().equals(prefix)) { return attr.getValue(); }/* w w w. java2s .c o m*/ } } } // try parent if (element.getParentNode() instanceof Element) { return getNamespaceForPrefix(prefix, (Element) element.getParentNode()); } // didn't find it - just use prefix as the namespace return prefix; }
From source file:org.apache.sling.its.servlets.ItsImportServlet.java
/** * Creates the jcr node and appends the necessary properties. * * @param absPath//from w w w . jav a 2 s.co m * absolute path of the node. * @param attr * attribute of the element * @param textContent * text content of the element. */ private void output(final String absPath, final Attr attr, final String textContent) { javax.jcr.Node node = null; try { if (this.session.itemExists(absPath) && attr == null && textContent == null) { node = (javax.jcr.Node) this.session.getItem(absPath); node.remove(); } node = JcrResourceUtil.createPath(absPath, "nt:unstructured", "nt:unstructured", this.session, false); if (textContent != null) { node.setProperty(SlingItsConstants.TEXT_CONTENT, textContent); } if (attr != null) { if (attr.getNodeName().startsWith(XMLConstants.XMLNS_ATTRIBUTE)) { node.setProperty(attr.getLocalName(), attr.getNodeValue()); if (node.hasProperty(SlingItsConstants.NAMESPACE_DECLARATION)) { final ArrayList<String> prefixes = new ArrayList<String>(ValueUtils.convertToArrayList( node.getProperty(SlingItsConstants.NAMESPACE_DECLARATION).getValues())); if (!prefixes.contains(attr.getLocalName())) { prefixes.add(attr.getLocalName()); node.setProperty(SlingItsConstants.NAMESPACE_DECLARATION, prefixes.toArray(new String[prefixes.size()])); } } else { node.setProperty(SlingItsConstants.NAMESPACE_DECLARATION, new String[] { attr.getLocalName() }); } } else if (StringUtils.equals(attr.getNodeName(), SlingItsConstants.XML_PRIMARY_TYPE_PROP) || StringUtils.equals(attr.getNodeName(), SlingItsConstants.HTML_PRIMARY_TYPE_PROP)) { node.setPrimaryType(attr.getNodeValue()); } else if (StringUtils.equals(attr.getNodeName(), SlingItsConstants.HTML_RESOURCE_TYPE_PROP)) { node.setProperty(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY, attr.getNodeValue()); } else { node.setProperty(attr.getNodeName(), attr.getNodeValue()); } } this.session.save(); } catch (final RepositoryException e) { LOG.error("Unable to access repository to access or create node. Stack Trace: ", e); } }
From source file:org.apache.woden.internal.DOMWSDLReader.java
protected void parseExtensionAttributes(XMLElement extEl, Class wsdlClass, WSDLElement wsdlObj, DescriptionElement desc) throws WSDLException { Element domEl = (Element) extEl.getSource(); NamedNodeMap nodeMap = domEl.getAttributes(); int length = nodeMap.getLength(); for (int i = 0; i < length; i++) { Attr domAttr = (Attr) nodeMap.item(i); String localName = domAttr.getLocalName(); String namespaceURI = domAttr.getNamespaceURI(); String prefix = domAttr.getPrefix(); QName attrType = new QName(namespaceURI, localName, (prefix != null ? prefix : emptyString)); String attrValue = domAttr.getValue(); if (namespaceURI != null && !namespaceURI.equals(Constants.NS_STRING_WSDL20)) { if (!namespaceURI.equals(Constants.NS_STRING_XMLNS) && !namespaceURI.equals(Constants.NS_STRING_XSI)) //TODO handle xsi attrs elsewhere, without need to register {/*from ww w . ja va 2 s .c om*/ //TODO reg namespaces at appropriate element scope, not just at desc. //DOMUtils.registerUniquePrefix(prefix, namespaceURI, desc); ExtensionRegistry extReg = fWsdlContext.extensionRegistry; XMLAttr xmlAttr = extReg.createExtAttribute(wsdlClass, attrType, extEl, attrValue); if (xmlAttr != null) //TODO use an 'UnknownAttr' class in place of null { wsdlObj.setExtensionAttribute(attrType, xmlAttr); } } else { //TODO parse xmlns namespace declarations - here or elsewhere? } } else { //TODO confirm non-native attrs in WSDL 2.0 namespace will be detected by schema validation, //so no need to handle error here. } } }
From source file:org.apache.woden.internal.DOMWSDLReader.java
protected void parseNamespaceDeclarations(XMLElement xmlElem, WSDLElement wsdlElem) throws WSDLException { Element elem = (Element) xmlElem.getSource(); NamedNodeMap attrs = elem.getAttributes(); int size = attrs.getLength(); for (int i = 0; i < size; i++) { Attr attr = (Attr) attrs.item(i); String namespaceURI = attr.getNamespaceURI(); String localPart = attr.getLocalName(); String value = attr.getValue(); if ((Constants.NS_STRING_XMLNS).equals(namespaceURI)) { if (!(Constants.ATTR_XMLNS).equals(localPart)) { wsdlElem.addNamespace(localPart, getURI(value)); //a prefixed namespace } else { wsdlElem.addNamespace(null, getURI(value)); //the default namespace }//from ww w. j a v a 2 s. co m } } }
From source file:org.apache.ws.security.message.WSSecEncrypt.java
private Vector doEncryption(Document doc, SecretKey secretKey, KeyInfo keyInfo, Vector references) throws WSSecurityException { XMLCipher xmlCipher = null;/*from w w w. j av a 2 s .c o m*/ try { xmlCipher = XMLCipher.getInstance(symEncAlgo); } catch (XMLEncryptionException e3) { throw new WSSecurityException(WSSecurityException.UNSUPPORTED_ALGORITHM, null, null, e3); } Vector encDataRef = new Vector(); boolean cloneKeyInfo = false; for (int part = 0; part < references.size(); part++) { WSEncryptionPart encPart = (WSEncryptionPart) references.get(part); String idToEnc = encPart.getId(); String elemName = encPart.getName(); String nmSpace = encPart.getNamespace(); String modifier = encPart.getEncModifier(); // // Third step: get the data to encrypt. // Element body = null; if (idToEnc != null) { body = WSSecurityUtil.findElementById(document.getDocumentElement(), idToEnc, WSConstants.WSU_NS); if (body == null) { body = WSSecurityUtil.findElementById(document.getDocumentElement(), idToEnc, null); } } else { body = (Element) WSSecurityUtil.findElement(document, elemName, nmSpace); } if (body == null) { throw new WSSecurityException(WSSecurityException.FAILURE, "noEncElement", new Object[] { "{" + nmSpace + "}" + elemName }); } boolean content = modifier.equals("Content") ? true : false; String xencEncryptedDataId = wssConfig.getIdAllocator().createId("EncDataId-", body); encPart.setEncId(xencEncryptedDataId); cloneKeyInfo = true; if (keyInfo == null) { keyInfo = new KeyInfo(document); SecurityTokenReference secToken = new SecurityTokenReference(document); if (useKeyIdentifier && SecurityTokenReference.SAML_ID_URI.equals(customReferenceValue)) { secToken.setSAMLKeyIdentifier((encKeyIdDirectId ? "" : "#") + encKeyId); } else { Reference ref = new Reference(document); if (encKeyIdDirectId) { ref.setURI(encKeyId); } else { ref.setURI("#" + encKeyId); } if (encKeyValueType != null) { ref.setValueType(encKeyValueType); } secToken.setReference(ref); } keyInfo.addUnknownElement(secToken.getElement()); Element keyInfoElement = keyInfo.getElement(); keyInfoElement.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:" + WSConstants.SIG_PREFIX, WSConstants.SIG_NS); } // // Fourth step: encrypt data, and set necessary attributes in // xenc:EncryptedData // try { if (modifier.equals("Header")) { Element elem = doc.createElementNS(WSConstants.WSSE11_NS, "wsse11:" + WSConstants.ENCRYPTED_HEADER); WSSecurityUtil.setNamespace(elem, WSConstants.WSSE11_NS, WSConstants.WSSE11_PREFIX); String wsuPrefix = WSSecurityUtil.setNamespace(elem, WSConstants.WSU_NS, WSConstants.WSU_PREFIX); elem.setAttributeNS(WSConstants.WSU_NS, wsuPrefix + ":Id", wssConfig.getIdAllocator().createId("EncHeader-", body)); NamedNodeMap map = body.getAttributes(); for (int i = 0; i < map.getLength(); i++) { Attr attr = (Attr) map.item(i); if (attr.getNamespaceURI().equals(WSConstants.URI_SOAP11_ENV) || attr.getNamespaceURI().equals(WSConstants.URI_SOAP12_ENV)) { String soapEnvPrefix = WSSecurityUtil.setNamespace(elem, attr.getNamespaceURI(), WSConstants.DEFAULT_SOAP_PREFIX); elem.setAttributeNS(attr.getNamespaceURI(), soapEnvPrefix + ":" + attr.getLocalName(), attr.getValue()); } } xmlCipher.init(XMLCipher.ENCRYPT_MODE, secretKey); EncryptedData encData = xmlCipher.getEncryptedData(); encData.setId(xencEncryptedDataId); encData.setKeyInfo(keyInfo); xmlCipher.doFinal(doc, body, content); Element encDataElem = WSSecurityUtil.findElementById(document.getDocumentElement(), xencEncryptedDataId, null); Node clone = encDataElem.cloneNode(true); elem.appendChild(clone); encDataElem.getParentNode().appendChild(elem); encDataElem.getParentNode().removeChild(encDataElem); } else { xmlCipher.init(XMLCipher.ENCRYPT_MODE, secretKey); EncryptedData encData = xmlCipher.getEncryptedData(); encData.setId(xencEncryptedDataId); encData.setKeyInfo(keyInfo); xmlCipher.doFinal(doc, body, content); } if (cloneKeyInfo) { keyInfo = new KeyInfo((Element) keyInfo.getElement().cloneNode(true), null); } } catch (Exception e2) { throw new WSSecurityException(WSSecurityException.FAILED_ENCRYPTION, null, null, e2); } encDataRef.add("#" + xencEncryptedDataId); } return encDataRef; }