List of usage examples for org.w3c.dom Element getLocalName
public String getLocalName();
From source file:org.apache.ode.il.epr.WSAEndpoint.java
public boolean accept(Node node) { if (node == null) { return false; }/* w w w .java2 s . c om*/ if (node.getNodeType() == Node.ELEMENT_NODE) { Element elmt = (Element) node; if (elmt.getLocalName().equals(SERVICE_REF_QNAME.getLocalPart()) && elmt.getNamespaceURI().equals(SERVICE_REF_QNAME.getNamespaceURI())) elmt = DOMUtils.getFirstChildElement(elmt); if (elmt != null && elmt.getLocalName().equals("EndpointReference") && elmt.getNamespaceURI().equals(Namespaces.WS_ADDRESSING_NS)) return true; } return false; }
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/*from w w w . j a va 2 s .com*/ 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.ode.jbi.EndpointReferenceContextImpl.java
public EndpointReference resolveEndpointReference(Element epr) { QName elname = new QName(epr.getNamespaceURI(), epr.getLocalName()); if (__log.isDebugEnabled()) { __log.debug("resolveEndpointReference:\n" + prettyPrint(epr)); }/*ww w . j a va 2 s .c o m*/ if (!elname.equals(EndpointReference.SERVICE_REF_QNAME)) throw new IllegalArgumentException( "EPR root element " + elname + " should be " + EndpointReference.SERVICE_REF_QNAME); Document doc = DOMUtils.newDocument(); DocumentFragment fragment = doc.createDocumentFragment(); NodeList children = epr.getChildNodes(); for (int i = 0; i < children.getLength(); ++i) if (children.item(i) instanceof Element) fragment.appendChild(doc.importNode(children.item(i), true)); ServiceEndpoint se = _ode.getContext().resolveEndpointReference(fragment); if (se == null) return null; return new JbiEndpointReference(se); }
From source file:org.apache.ode.jbi.util.SchemaCollection.java
protected void handleImports(Schema schema) throws Exception { NodeList children = schema.getRoot().getChildNodes(); List imports = new ArrayList(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child instanceof Element) { Element ce = (Element) child; if ("http://www.w3.org/2001/XMLSchema".equals(ce.getNamespaceURI()) && "import".equals(ce.getLocalName())) { imports.add(ce);/* ww w . ja v a 2 s .co m*/ } } } for (Iterator iter = imports.iterator(); iter.hasNext();) { Element ce = (Element) iter.next(); String namespace = ce.getAttribute("namespace"); if (schemas.get(namespace) == null) { String location = ce.getAttribute("schemaLocation"); if (location != null && !"".equals(location)) { read(location, schema.getSourceUri()); } } schema.addImport(namespace); schema.getRoot().removeChild(ce); } }
From source file:org.apache.ode.utils.DOMUtils.java
/** * Perform a naive check to see if a document is a WSDL document * based on the root element name and namespace URI. * @param d the {@link Document} to check * @return <code>true</code> if the root element appears correct */// w w w . ja va2s . c om public static boolean isWsdlDocument(Document d) { Element e = d.getDocumentElement(); String uri = e.getNamespaceURI(); String localName = e.getLocalName(); if (uri == null || localName == null) { return false; } return uri.equals(WSDL_NS) && localName.equals(WSDL_ROOT_ELEMENT); }
From source file:org.apache.ode.utils.DOMUtils.java
/** * Perform a naive check to see if a document is an XML schema document * based on the root element name and namespace URI. * @param d the {@link Document} to check * @return <code>true</code> if the root element appears correct */// w w w . j a v a 2 s. c o m public static boolean isXmlSchemaDocument(Document d) { Element e = d.getDocumentElement(); String uri = e.getNamespaceURI(); String localName = e.getLocalName(); if (uri == null || localName == null) { return false; } return uri.equals(XSD_NS) && localName.equals(XSD_ROOT_ELEMENT); }
From source file:org.apache.oozie.cli.OozieCLI.java
private Properties parseDocument(Document doc, Properties conf) throws IOException { try {/* w w w .j a v a2s . c o m*/ Element root = doc.getDocumentElement(); if (!"configuration".equals(root.getLocalName())) { throw new RuntimeException("bad conf file: top-level element not <configuration>"); } NodeList props = root.getChildNodes(); for (int i = 0; i < props.getLength(); i++) { Node propNode = props.item(i); if (!(propNode instanceof Element)) { continue; } Element prop = (Element) propNode; if (!"property".equals(prop.getLocalName())) { throw new RuntimeException("bad conf file: element not <property>"); } NodeList fields = prop.getChildNodes(); String attr = null; String value = null; for (int j = 0; j < fields.getLength(); j++) { Node fieldNode = fields.item(j); if (!(fieldNode instanceof Element)) { continue; } Element field = (Element) fieldNode; if ("name".equals(field.getLocalName()) && field.hasChildNodes()) { attr = ((Text) field.getFirstChild()).getData(); } if ("value".equals(field.getLocalName()) && field.hasChildNodes()) { value = ((Text) field.getFirstChild()).getData(); } } if (attr != null && value != null) { conf.setProperty(attr, value); } } return conf; } catch (DOMException e) { throw new IOException(e); } }
From source file:org.apache.openaz.xacml.pdp.policy.dom.DOMExpression.java
/** * Creates a new <code>Expression</code> of the appropriate sub-type based on the name of the given * <code>Node</code>.//from ww w.j a v a 2 s .com * * @param nodeExpression the <code>Node</code> to parse * @param policy the {@link org.apache.openaz.xacml.pdp.policy.Policy} containing the Expression element * @return a new <code>Expression</code> parsed from the given <code>Node</code> * @throws DOMStructureException if there is an error parsing the <code>Node</code> */ public static Expression newInstance(Node nodeExpression, Policy policy) throws DOMStructureException { Element elementExpression = DOMUtil.getElement(nodeExpression); boolean bLenient = DOMProperties.isLenient(); if (DOMUtil.isInNamespace(elementExpression, XACML3.XMLNS)) { if (elementExpression.getLocalName().equals(XACML3.ELEMENT_APPLY)) { return DOMApply.newInstance(elementExpression, policy); } else if (elementExpression.getLocalName().equals(XACML3.ELEMENT_ATTRIBUTEDESIGNATOR)) { return DOMAttributeDesignator.newInstance(elementExpression); } else if (elementExpression.getLocalName().equals(XACML3.ELEMENT_ATTRIBUTESELECTOR)) { return DOMAttributeSelector.newInstance(elementExpression); } else if (elementExpression.getLocalName().equals(XACML3.ELEMENT_ATTRIBUTEVALUE)) { AttributeValue<?> attributeValue = null; try { attributeValue = DOMAttributeValue.newInstance(elementExpression, null); } catch (DOMStructureException ex) { return new AttributeValueExpression(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, ex.getMessage()); } return new AttributeValueExpression(attributeValue); } else if (elementExpression.getLocalName().equals(XACML3.ELEMENT_FUNCTION)) { return new Function(DOMUtil.getIdentifierAttribute(elementExpression, XACML3.ATTRIBUTE_FUNCTIONID)); } else if (elementExpression.getLocalName().equals(XACML3.ELEMENT_VARIABLEREFERENCE)) { return new VariableReference(policy, DOMUtil.getStringAttribute(elementExpression, XACML3.ATTRIBUTE_VARIABLEID)); } else if (!bLenient) { throw DOMUtil.newUnexpectedElementException(nodeExpression); } else { return null; } } else if (!bLenient) { throw DOMUtil.newUnexpectedElementException(nodeExpression); } else { return null; } }
From source file:org.apache.openaz.xacml.pdp.policy.dom.DOMExpression.java
public static boolean repair(Node nodeExpression) throws DOMStructureException { Element elementExpression = DOMUtil.getElement(nodeExpression); if (DOMUtil.isInNamespace(elementExpression, XACML3.XMLNS)) { if (elementExpression.getLocalName().equals(XACML3.ELEMENT_APPLY)) { return DOMApply.repair(elementExpression); } else if (elementExpression.getLocalName().equals(XACML3.ELEMENT_ATTRIBUTEDESIGNATOR)) { return DOMAttributeDesignator.repair(elementExpression); } else if (elementExpression.getLocalName().equals(XACML3.ELEMENT_ATTRIBUTESELECTOR)) { return DOMAttributeSelector.repair(elementExpression); } else if (elementExpression.getLocalName().equals(XACML3.ELEMENT_ATTRIBUTEVALUE)) { return DOMAttributeValue.repair(elementExpression); } else if (elementExpression.getLocalName().equals(XACML3.ELEMENT_FUNCTION)) { return DOMUtil.repairIdentifierAttribute(elementExpression, XACML3.ATTRIBUTE_FUNCTIONID, XACML3.ID_FUNCTION_STRING_EQUAL, logger); } else if (elementExpression.getLocalName().equals(XACML3.ELEMENT_VARIABLEREFERENCE)) { return DOMUtil.repairStringAttribute(elementExpression, XACML3.ATTRIBUTE_VARIABLEID, "variableId", logger);// www . j ava 2s .c o m } else { throw DOMUtil.newUnexpectedElementException(nodeExpression); } } else { throw DOMUtil.newUnexpectedElementException(nodeExpression); } }
From source file:org.apache.rampart.PolicyBasedResultsValidator.java
protected void validateSignedPartsHeaders(ValidatorData data, Vector signatureParts, Vector results) throws RampartException { RampartMessageData rmd = data.getRampartMessageData(); Node envelope = rmd.getDocument().getFirstChild(); WSSecurityEngineResult[] actionResults = fetchActionResults(results, WSConstants.SIGN); // Find elements that are signed Vector actuallySigned = new Vector(); if (actionResults != null) { for (int j = 0; j < actionResults.length; j++) { WSSecurityEngineResult actionResult = actionResults[j]; List wsDataRefs = (List) actionResult.get(WSSecurityEngineResult.TAG_DATA_REF_URIS); // if header was encrypted before it was signed, protected // element is 'EncryptedHeader.' the actual element is // first child element for (Iterator k = wsDataRefs.iterator(); k.hasNext();) { WSDataRef wsDataRef = (WSDataRef) k.next(); Element protectedElement = wsDataRef.getProtectedElement(); if (protectedElement.getLocalName().equals("EncryptedHeader")) { NodeList nodeList = protectedElement.getChildNodes(); for (int x = 0; x < nodeList.getLength(); x++) { if (nodeList.item(x).getNodeType() == Node.ELEMENT_NODE) { String ns = ((Element) nodeList.item(x)).getNamespaceURI(); String ln = ((Element) nodeList.item(x)).getLocalName(); actuallySigned.add(new QName(ns, ln)); break; }/* ww w . ja v a 2 s. co m*/ } } else { String ns = protectedElement.getNamespaceURI(); String ln = protectedElement.getLocalName(); actuallySigned.add(new QName(ns, ln)); } } } } for (int i = 0; i < signatureParts.size(); i++) { WSEncryptionPart wsep = (WSEncryptionPart) signatureParts.get(i); if (wsep.getType() == WSConstants.PART_TYPE_BODY) { QName bodyQName; if (WSConstants.URI_SOAP11_ENV.equals(envelope.getNamespaceURI())) { bodyQName = new SOAP11Constants().getBodyQName(); } else { bodyQName = new SOAP12Constants().getBodyQName(); } if (!actuallySigned.contains(bodyQName) && !rmd.getPolicyData().isSignBodyOptional()) { // soap body is not signed throw new RampartException("bodyNotSigned"); } } else if (wsep.getType() == WSConstants.PART_TYPE_HEADER || wsep.getType() == WSConstants.PART_TYPE_ELEMENT) { Element element = (Element) WSSecurityUtil.findElement(envelope, wsep.getName(), wsep.getNamespace()); if (element == null) { // The signedpart header or element we are checking is not present in // soap envelope - this is allowed continue; } // header or the element present in soap envelope - verify that it is part of // signature if (actuallySigned.contains(new QName(element.getNamespaceURI(), element.getLocalName()))) { continue; } String msg = wsep.getType() == WSConstants.PART_TYPE_HEADER ? "signedPartHeaderNotSigned" : "signedElementNotSigned"; // header or the element defined in policy is present but not signed throw new RampartException(msg, new String[] { wsep.getNamespace() + ":" + wsep.getName() }); } } }