List of usage examples for org.w3c.dom Node getLocalName
public String getLocalName();
From source file:de.betterform.xml.xforms.XFormsElement.java
/** * returns the list of all attributes that are not in 'known' namespaces and do not have the null (default?) namespace * * /* w ww. ja va 2 s .com*/ * @return the key-value-pair of the attributes */ public Map<String, String> getCustomMIPAttributes() { HashMap<String, String> customMIPAttributes = new HashMap<String, String>(); NamedNodeMap nnm = element.getAttributes(); for (int i = 0; i < nnm.getLength(); i++) { Node attribute = nnm.item(i); if (attribute.getNamespaceURI() != null && !NamespaceConstants.BETTERFORM_NS.equals(attribute.getNamespaceURI()) && !NamespaceConstants.XFORMS_NS.equals(attribute.getNamespaceURI()) && !NamespaceConstants.XHTML_NS.equals(attribute.getNamespaceURI()) && !NamespaceConstants.XMLNS_NS.equals(attribute.getNamespaceURI()) && !NamespaceConstants.XMLSCHEMA_INSTANCE_NS.equals(attribute.getNamespaceURI()) && !NamespaceConstants.XMLEVENTS_NS.equals(attribute.getNamespaceURI())) { customMIPAttributes.put(attribute.getPrefix() + WordUtils.capitalize(attribute.getLocalName()), attribute.getTextContent()); } } return customMIPAttributes; }
From source file:com.espertech.esper.event.EventAdapterServiceImpl.java
public EventBean adapterForDOM(Node node) { Node namedNode; if (node instanceof Document) { namedNode = ((Document) node).getDocumentElement(); } else if (node instanceof Element) { namedNode = node;//from ww w.j a v a 2s . co m } else { throw new EPException("Unexpected DOM node of type '" + node.getClass() + "' encountered, please supply a Document or Element node"); } String rootElementName = namedNode.getLocalName(); if (rootElementName == null) { rootElementName = namedNode.getNodeName(); } EventType eventType = xmldomRootElementNames.get(rootElementName); if (eventType == null) { throw new EventAdapterException( "DOM event root element name '" + rootElementName + "' has not been configured"); } return new XMLEventBean(namedNode, eventType); }
From source file:com.silverwrist.venice.std.TrackbackManager.java
/** * Loads the HTTP content at the specified URL, scans it for RDF description blocks, and adds those blocks * as {@link com.silverwrist.venice.std.TrackbackItem TrackbackItem}s to our internal cache. Uses modification * detection to keep from reloading a page unless necessary. * * @param url The URL of the resource to be loaded. * @param attrs The attributes of the specified page; if this is <code>null</code>, we'll check the page * cache for the right attributes. * @return <code>true</code> if the page data was loaded and scanned for trackback items; <code>false</code> * if no data was loaded (because it was not modified since the last time we loaded it, for instance). * @exception com.silverwrist.venice.except.TrackbackException If there was an error loading or interpreting * the page data.//from ww w .ja va2 s.com */ private synchronized boolean load(URL url, PageAttributes attrs) throws TrackbackException { if (attrs == null) attrs = (PageAttributes) (m_page_cache.get(url)); // Create the GET method and set its headers. String s = url.toString(); int x = s.lastIndexOf('#'); if (x >= 0) s = s.substring(0, x); GetMethod getter = new GetMethod(s); HttpMethodParams params = getter.getParams(); getter.setDoAuthentication(false); getter.setFollowRedirects(true); getter.setRequestHeader("User-Agent", USER_AGENT); getter.setRequestHeader("Accept", "text/*"); getter.setRequestHeader("Accept-Encoding", "identity"); params.setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler()); getter.setParams(params); boolean get_resp = false; PageAttributes newattrs = null; ContentType ctype = null; byte[] rawdata = null; try { // set the Last-Modified date as an If-Modified-Since header on the request java.util.Date lmod = null; if (attrs != null) lmod = attrs.getLastModified(); if (lmod != null) getter.setRequestHeader("If-Modified-Since", s_httpdate_format.format(lmod)); // execute the Get method! int rc = m_http_client.executeMethod(getter); get_resp = true; if ((lmod != null) && (rc == HttpStatus.SC_NOT_MODIFIED)) return false; // we were not modified if (rc == HttpStatus.SC_NO_CONTENT) return false; // there's no content there if (rc != HttpStatus.SC_OK) // this is farked! throw new TrackbackException("GET of " + url + " returned " + rc); // Get the new page attributes and save them off. newattrs = new PageAttributes(getter); m_page_cache.put(url, newattrs); // Get the Content-Type header and see if it's valid. Header hdr = getter.getResponseHeader("Content-Type"); if (hdr != null) s = hdr.getValue(); else s = "text/plain"; // necessary assumption ctype = new ContentType(s); if (!(ctype.getPrimaryType().equals("text"))) throw new TrackbackException("URL " + url + " does not point to a text-based resource"); // Load the resource in as byte data; we will determine the right character set for it later. rawdata = getter.getResponseBody(); get_resp = false; } // end try catch (IOException e) { // IO error getting the page throw new TrackbackException("I/O error retrieving " + url + ": " + e.getMessage(), e); } // end catch catch (javax.mail.internet.ParseException e) { // translate into TrackbackException throw new TrackbackException("invalid Content-Type received for URL " + url, e); } // end catch finally { // release the connection if possible try { // need to get the message body if (get_resp) getter.getResponseBody(); } // end try catch (IOException e) { // ignore these } // end catch getter.releaseConnection(); } // end finally // make a first guess at the charset from the HTTP header Content-Type String cset = ctype.getParameter("charset"); if (cset == null) cset = "US-ASCII"; String content = null; try { // interpret the content content = new String(rawdata, cset); } // end try catch (UnsupportedEncodingException e) { // fall back and try just using US-ASCII cset = null; try { // interpret the content content = new String(rawdata, "US-ASCII"); } // end try catch (UnsupportedEncodingException e2) { // can't happen logger.debug("WTF? US-ASCII should damn well be a supported character set!", e2); } // end catch } // end catch // Look for <META HTTP-EQUIV=...> tags in the content. Map http_attrs = extractHttpEquivTags(content); // Try to get a Content-Type attribute from there. s = (String) (http_attrs.get("CONTENT-TYPE")); String cset2 = null; if (s != null) { // look for the content type try { // parse into Content-Type ContentType c = new ContentType(s); if (c.getPrimaryType().equals("text")) cset2 = c.getParameter("charset"); } // end try catch (javax.mail.internet.ParseException e) { // can't get a second Content-Type logger.debug("parse of Content-Type from META tags failed", e); cset2 = null; } // end catch } // end if if ((cset == null) && (cset2 == null)) throw new TrackbackException("unable to determine character set for " + url); if ((cset2 != null) && ((cset == null) || !(cset.equalsIgnoreCase(cset2)))) { // reinterpret content in new character set try { // reinterpret content in new character set s = new String(rawdata, cset2); content = s; // the contents of the HTTP-EQUIV tags may have changed as a result http_attrs = extractHttpEquivTags(content); } // end try catch (UnsupportedEncodingException e) { // just use original character set if (cset == null) throw new TrackbackException("unable to determine character set for " + url); } // end catch } // end if newattrs.updateFromPage(http_attrs); // update the page attributes from the META tag data // Search the page content for RDF blocks. RE m = new RE(s_rdf_start, RE.MATCH_NORMAL); int pos = 0; while (m.match(content, pos)) { // look for the end of this RDF block RE m2 = new RE(getEndRecognizer(m.getParen(1)), RE.MATCH_NORMAL); if (m2.match(content, m.getParenEnd(0))) { // we now have a block to feed to the XML parser try { // run the block through the XML parser InputSource isrc = new InputSource( new StringReader(content.substring(m.getParenStart(0), m2.getParenEnd(0)))); Document doc = m_rdf_parser.parse(isrc); // examine topmost element, which should be rdf:RDF Element root = doc.getDocumentElement(); if (NS_RDF.equals(root.getNamespaceURI()) && (root.getLocalName() != null) && root.getLocalName().equals("RDF")) { // this is most definitely an rdf:RDF node...look for rdf:Description nodes under it NodeList nl = root.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { // check each node in the list Node n = nl.item(i); if ((n.getNodeType() == Node.ELEMENT_NODE) && NS_RDF.equals(n.getNamespaceURI()) && (n.getLocalName() != null) && n.getLocalName().equals("Description")) { // we've got an rdf:Description node...extract the attributes from it Element elt = (Element) n; try { // look for the item and trackback URLs URL item = null, trackback = null; s = elt.getAttributeNS(NS_DC, "identifier"); if ((s != null) && (s.length() > 0)) item = new URL(s); s = elt.getAttributeNS(NS_TRACKBACK, "ping"); if ((s != null) && (s.length() > 0)) trackback = new URL(s); if ((item != null) && (trackback != null)) { // create the item s = elt.getAttributeNS(NS_DC, "title"); m_item_cache.put(item, new MyTrackbackItem(item, trackback, s, newattrs)); } // end if } // end try catch (MalformedURLException e) { // this means skip this item logger.warn("URL parse failure", e); } // end catch } // end if } // end for } // end if } // end try catch (IOException e) { // disregard this block logger.warn("RDF block parse failure", e); } // end catch catch (SAXException e) { // disregard this block logger.warn("RDF block parse failure", e); } // end catch } // end if // else ignore this possible block pos = m.getParenEnd(0); } // end while return true; }
From source file:com.gargoylesoftware.htmlunit.html.DomElement.java
/** * {@inheritDoc}//from w ww . j a va 2 s . c om */ @Override public DomAttr setNamedItem(final Node node) { return put(node.getLocalName(), (DomAttr) node); }
From source file:it.cnr.icar.eric.server.profile.ws.wsdl.cataloger.WSDLCatalogerEngine.java
/** * Catalogs XMLSchema when submitted as an ExtrinsicObject - RepositoryItem pair. * *///from w w w.java 2 s . c o m private void catalogXMLSchemaExtrinsicObject(RegistryObjectType ro, InputSource source) throws CatalogingException { try { registryObjects.add(ro); Document document = parseXML(source); Element schemaElement = document.getDocumentElement(); String documentLocalName = schemaElement.getLocalName(); String documentNamespaceURI = schemaElement.getNamespaceURI(); if (documentLocalName.equalsIgnoreCase("schema") && documentNamespaceURI.endsWith("XMLSchema")) { Attr attribute = schemaElement.getAttributeNode("targetNamespace"); String namespaceURI = attribute.getValue(); // Set the id for the XMLSchema EO updateRegistryObjectId(namespaceURI, ro, false); // Check if this XSD file imports another file (usually XSD) NodeList nodeList = schemaElement.getChildNodes(); int length = nodeList.getLength(); for (int i = 0; i < length; i++) { Node node = nodeList.item(i); String localName = node.getLocalName(); if (localName != null && localName.equalsIgnoreCase("import")) { // This XSD imports another file NamedNodeMap importNamedNodeMap = node.getAttributes(); Node namespaceNode = importNamedNodeMap.getNamedItem("namespace"); String importNamespace = null; if (namespaceNode != null) { importNamespace = namespaceNode.getNodeValue(); } String schemaLocation = null; Node schemaLocationNode = importNamedNodeMap.getNamedItem("schemaLocation"); if (schemaLocationNode != null) { schemaLocation = schemaLocationNode.getNodeValue(); } RegistryObjectType importedObject = catalogImportStatement(ro, importNamespace, schemaLocation); createImportsAssociation(ro, importedObject); } } } } catch (CatalogingException e) { throw e; } catch (Exception e) { log.error(e, e); CatalogingException ce = new CatalogingException(e); throw ce; } }
From source file:com.amalto.core.util.Util.java
/** * Get a node list from an xPath//from w w w .ja v a 2s . c o m * * @throws XtentisException */ public static NodeList getNodeList(Node contextNode, String xPath) throws XtentisException { try { XPathFactory xPathFactory = XPathFactory.newInstance(); XPath xPathParser = xPathFactory.newXPath(); xPathParser.setNamespaceContext(new NamespaceContext() { @Override public String getNamespaceURI(String s) { if ("xsd".equals(s)) { //$NON-NLS-1$ return XMLConstants.W3C_XML_SCHEMA_NS_URI; } return null; } @Override public String getPrefix(String s) { if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(s)) { return "xsd"; //$NON-NLS-1$ } return null; } @Override public Iterator getPrefixes(String s) { return Collections.singletonList(s).iterator(); } }); return (NodeList) xPathParser.evaluate(xPath, contextNode, XPathConstants.NODESET); } catch (Exception e) { String err = "Unable to get the Nodes List for xpath '" + xPath + "'" + ((contextNode == null) ? "" : " for Node " + contextNode.getLocalName()) + ": " + e.getLocalizedMessage(); throw new XtentisException(err, e); } }
From source file:com.marklogic.dom.NodeImpl.java
protected NodeList getElementsByTagNameNSOrNodeName(String namespaceURI, String name, final boolean nodeName) { final String tagname = name; final String ns = namespaceURI; final Node thisNode = this; return new NodeList() { protected ArrayList<Node> elementList = new ArrayList<Node>(); protected boolean done = false; protected void init() { if (done) return; Stack<Node> childrenStack = new Stack<Node>(); childrenStack.push(thisNode); boolean root = true; while (!childrenStack.isEmpty()) { Node curr = childrenStack.pop(); NodeList children = curr.getChildNodes(); for (int childi = children.getLength() - 1; childi >= 0; childi--) if (children.item(childi).getNodeType() == Node.ELEMENT_NODE) childrenStack.push(children.item(childi)); if (root) { root = false;/*www . j a v a 2 s . c o m*/ continue; } if (nodeName) { if (curr.getNodeName().equals(tagname) || tagname.equals("*")) elementList.add(curr); } else { // do nothing if only one of the two is null if ("*".equals(ns) && "*".equals(tagname)) { elementList.add(curr); continue; } if (ns != null) { if ((ns.equals("*") || ns.equals(curr.getNamespaceURI())) && (tagname.equals("*") || tagname.equals(curr.getLocalName()))) elementList.add(curr); } else if (tagname.equals("*") || tagname.equals(curr.getLocalName())) elementList.add(curr); } } done = true; } public int getLength() { init(); return elementList.size(); } public Node item(int index) { init(); return (index < getLength()) ? elementList.get(index) : null; } }; }
From source file:eu.europa.ec.markt.dss.validation102853.xades.XAdESSignature.java
/** * Creates the hash sent to the TSA (messageImprint) computed on the XAdES-X-L form of the electronic signature and * the signed data objects, i.e. on the sequence formed as explained below:<br> * <p/>/*w ww. jav a 2 s .c o m*/ * One HashDataInfo element for each data object signed by the [XMLDSIG] signature. The result of application of the * transforms specified each HashDataInfo must be exactly the same as the octet stream that was originally used for * computing the digest value of the corresponding ds:Reference.<br> * <p/> * One HashDataInfo element for the ds:SignedInfo element. The result of application of the transforms specified in * this HashDataInfo must be exactly the same as the octet stream that was originally used for computing the * signature value of the [XMLDSIG] signature.<br> * <p/> * One HashDataInfo element for the SignedSignatureProperties element.<br> * One HashDataInfo element for the SignedDataObjectProperties element.<br> * One HashDataInfo element for the ds:SignatureValue element.<br> * One HashDataInfo element per each SignatureTimeStamp property.<br> * One HashDataInfo element for the CompleteCertificateRefs property.<br> * One HashDataInfo element for the CompleteRevocationRefs property.<br> * One HashDataInfo element for the CertificatesValues property (add this property previously if not already * present).<br> * One HashDataInfo element for the RevocationValues property (add this property previously if not already present).<br> * One HashDataInfo element per each SigAndRefsTimeStamp property (if present).<br> * One HashDataInfo element per each property RefsOnlyTimeStamp (if present).<br> * One HashDataInfo element per each any previous XAdESArchiveTimestamp property (if present). * * @see AdvancedSignature#getArchiveTimestampData(eu.europa.ec.markt.dss.validation102853.TimestampToken) */ @Override public byte[] getArchiveTimestampData(TimestampToken timestampToken) { String canonicalizationMethod = timestampToken == null ? XMLDSIG_DEFAULT_CANONICALIZATION_METHOD : timestampToken.getCanonicalizationMethod(); byte[] canonicalizedValue = null; /** * 8.2.1 Not distributed case<br> * * When xadesv141:ArchiveTimeStamp and all the unsigned properties covered by its time-stamp token have the same * parent, this property uses the Implicit mechanism for all the time-stamped data objects. The input to the * computation of the digest value MUST be built as follows: */ try { /** * 1) Initialize the final octet stream as an empty octet stream. */ ByteArrayOutputStream buffer = new ByteArrayOutputStream(); /** * 2) Take all the ds:Reference elements in their order of appearance within ds:SignedInfo referencing whatever * the signer wants to sign including the SignedProperties element. Process each one as indicated below:<br> * - Process the retrieved ds:Reference element according to the reference processing model of XMLDSIG.<br> * - If the result is a XML node set, canonicalize it. If ds:Canonicalization is present, the algorithm * indicated by this element is used. If not, the standard canonicalization method specified by XMLDSIG is * used.<br> * - Concatenate the resulting octets to the final octet stream. */ /** * The references are already calculated {@see #checkIntegrity()} */ InputStream decodedInput = new ByteArrayInputStream((referencesDigestOutputStream).toByteArray()); IOUtils.copy(decodedInput, buffer); /** * 3) Take the following XMLDSIG elements in the order they are listed below, canonicalize each one and * concatenate each resulting octet stream to the final octet stream:<br> * - The ds:SignedInfo element.<br> * - The ds:SignatureValue element.<br> * - The ds:KeyInfo element, if present. */ Element signedInfo = DSSXMLUtils.getElement(signatureElement, XPATH_SIGNED_INFO); canonicalizedValue = getC14nValue(signedInfo, canonicalizationMethod); buffer.write(canonicalizedValue); Element signatureValue = DSSXMLUtils.getElement(signatureElement, XPATH_SIGNATURE_VALUE); canonicalizedValue = getC14nValue(signatureValue, canonicalizationMethod); buffer.write(canonicalizedValue); Element keyInfo = DSSXMLUtils.getElement(signatureElement, XPATH_KEY_INFO); canonicalizedValue = getC14nValue(keyInfo, canonicalizationMethod); buffer.write(canonicalizedValue); /** * 4) Take the unsigned signature properties that appear before the current xadesv141:ArchiveTimeStamp in the * order they appear within the xades:UnsignedSignatureProperties, canonicalize each one and concatenate each * resulting octet stream to the final octet stream. While concatenating the following rules apply: */ Element unsignedSignaturePropertiesNode = getUnsignedSignatureProperties(signatureElement); // The archive timestamp need to be identified to know if it must be taken into account or not. int archiveTimeStampCount = 0; NodeList unsignedProperties = unsignedSignaturePropertiesNode.getChildNodes(); for (int ii = 0; ii < unsignedProperties.getLength(); ii++) { Node node = unsignedProperties.item(ii); String localName = node.getLocalName(); if (localName.equals("CertificateValues")) { /** * - The xades:CertificateValues property MUST be added if it is not already present and the ds:KeyInfo * element does not contain the full set of certificates used to validate the electronic signature. */ } else if (localName.equals("RevocationValues")) { /** * - The xades:RevocationValues property MUST be added if it is not already present and the ds:KeyInfo * element does not contain the revocation information that has to be shipped with the electronic * signature */ } else if (localName.equals("AttrAuthoritiesCertValues")) { /** * - The xades:AttrAuthoritiesCertValues property MUST be added if not already present and the following * conditions are true: there exist an attribute certificate in the signature AND a number of * certificates that have been used in its validation do not appear in CertificateValues. Its content * will satisfy with the rules specified in clause 7.6.3. */ } else if (localName.equals("AttributeRevocationValues")) { /** * - The xades:AttributeRevocationValues property MUST be added if not already present and there the * following conditions are true: there exist an attribute certificate AND some revocation data that have * been used in its validation do not appear in RevocationValues. Its content will satisfy with the rules * specified in clause 7.6.4. */ } else if (XMLE_ARCHIVE_TIME_STAMP.equals(localName) || XMLE_ARCHIVE_TIME_STAMP_V2.equals(localName)) { if (timestampToken == null || timestampToken.getDSSId() <= archiveTimeStampCount) { break; } archiveTimeStampCount++; } canonicalizedValue = getC14nValue(node, canonicalizationMethod); buffer.write(canonicalizedValue); } /** * 5) Take all the ds:Object elements except the one containing xades:QualifyingProperties element. * Canonicalize each one and concatenate each resulting octet stream to the final octet stream. If * ds:Canonicalization is present, the algorithm indicated by this element is used. If not, the standard * canonicalization method specified by XMLDSIG is used. */ boolean xades141 = true; if (timestampToken != null && ArchiveTimestampType.XAdES.equals(timestampToken.getArchiveTimestampType())) { xades141 = false; } if (xades141) { NodeList objects = getObjects(); for (int ii = 0; ii < objects.getLength(); ii++) { Node node = objects.item(ii); Node qualifyingProperties = DSSXMLUtils.getElement(node, "./xades:QualifyingProperties"); if (qualifyingProperties != null) { continue; } canonicalizedValue = getC14nValue(node, canonicalizationMethod); buffer.write(canonicalizedValue); } } // *** Log ArchiveTimestamp canonicalised string // if (LOG.isLoggable(Level.INFO)) LOG.info("ArchiveTimestamp canonicalised string:\n" + buffer.toString()); return buffer.toByteArray(); } catch (IOException e) { throw new DSSException("Error when computing the archive data", e); } }
From source file:edu.uams.clara.webapp.xml.processor.impl.DefaultXmlProcessorImpl.java
private synchronized boolean isEqualNode(final Node original, final Node patch) { if (patch == original) { return true; }/* w w w . ja v a 2s. c o m*/ if (patch.getNodeType() != original.getNodeType()) { return false; } if (original.getNodeName() == null) { if (patch.getNodeName() != null) { return false; } } else if (!original.getNodeName().equals(patch.getNodeName())) { return false; } if (original.getLocalName() == null) { if (patch.getLocalName() != null) { return false; } } else if (!original.getLocalName().equals(patch.getLocalName())) { return false; } if (original.getNamespaceURI() == null) { if (patch.getNamespaceURI() != null) { return false; } } else if (!original.getNamespaceURI().equals(patch.getNamespaceURI())) { return false; } if (original.getPrefix() == null) { if (patch.getPrefix() != null) { return false; } } else if (!original.getPrefix().equals(patch.getPrefix())) { return false; } if (original.getNodeValue() == null) { if (patch.getNodeValue() != null) { return false; } } else if (!original.getNodeValue().equals(patch.getNodeValue())) { return false; } if (original.getTextContent() == null) { if (patch.getTextContent() != null) { return false; } } else if (!original.getTextContent().equals(patch.getTextContent())) { return false; } return true; }