List of usage examples for org.w3c.dom Node getLocalName
public String getLocalName();
From source file:com.centeractive.ws.builder.soap.XmlUtils.java
public static QName getQName(Node node) { if (node == null) return null; else if (node.getNamespaceURI() == null) return new QName(node.getNodeName()); else/*from w ww . j av a2 s . com*/ return new QName(node.getNamespaceURI(), node.getLocalName()); }
From source file:com.datos.vfs.provider.webdav.WebdavFileObject.java
private boolean isDirectory(final URLFileName name) throws IOException { try {/* ww w .jav a2s.c o m*/ final DavProperty property = getProperty(name, DavConstants.PROPERTY_RESOURCETYPE); Node node; if (property != null && (node = (Node) property.getValue()) != null) { return node.getLocalName().equals(DavConstants.XML_COLLECTION); } else { return false; } } catch (final FileNotFoundException fse) { throw new FileNotFolderException(name); } }
From source file:no.digipost.api.interceptors.Wss4jInterceptor.java
private boolean wasSigned(final Document doc, final List<WSSecurityEngineResult> results, final QName... qnamePath) { String path = "/" + doc.getDocumentElement().getPrefix() + ":Envelope"; for (QName qn : qnamePath) { Node n = doc.getDocumentElement().getElementsByTagNameNS(qn.getNamespaceURI(), qn.getLocalPart()) .item(0);/*w ww. j a v a 2s. c om*/ if (n == null) { return false; } path += "/" + n.getPrefix() + ":" + n.getLocalName(); } for (WSSecurityEngineResult r : results) { if (r.containsKey("data-ref-uris")) { List<WSDataRef> refs = (List<WSDataRef>) r.get("data-ref-uris"); for (WSDataRef ref : refs) { if (ref.getName().equals(qnamePath[qnamePath.length - 1])) { if (ref.getXpath().equals(path)) { return true; } } } } } return false; }
From source file:edu.sabanciuniv.sentilab.sare.controllers.aspect.AspectLexiconFactory.java
protected AspectLexiconFactory addXmlAspect(AspectLexicon lexicon, Node aspectNode) throws XPathExpressionException { Validate.notNull(lexicon, CannedMessages.NULL_ARGUMENT, "lexicon"); Validate.notNull(aspectNode, CannedMessages.NULL_ARGUMENT, "node"); XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newXPath(); // if the node is called "lexicon" then we're at the root, so we won't need to add an aspect and its expressions. AspectLexicon aspect = lexicon;//from www . j a v a2 s . c om if (!"aspect-lexicon".equalsIgnoreCase(aspectNode.getLocalName())) { String title = Validate.notEmpty( (String) xpath.compile("./@title").evaluate(aspectNode, XPathConstants.STRING), CannedMessages.EMPTY_ARGUMENT, "./aspect/@title"); ; // fetch or create aspect. aspect = lexicon.findAspect(title); if (aspect == null) { aspect = lexicon.addAspect(title); } // get all expressions or keywords, whatever they're called. NodeList expressionNodes = (NodeList) xpath.compile("./expressions/expression").evaluate(aspectNode, XPathConstants.NODESET); if (expressionNodes == null || expressionNodes.getLength() == 0) { expressionNodes = (NodeList) xpath.compile("./keywords/keyword").evaluate(aspectNode, XPathConstants.NODESET); } // add each of them if they don't exist. if (expressionNodes != null) { for (int index = 0; index < expressionNodes.getLength(); index++) { String expression = expressionNodes.item(index).getTextContent().trim(); if (!aspect.hasExpression(expression)) { aspect.addExpression(expression); } } } } // get all sub-aspects and add them recursively. NodeList subAspectNodes = (NodeList) xpath.compile("./aspects/aspect").evaluate(aspectNode, XPathConstants.NODESET); if (subAspectNodes != null) { for (int index = 0; index < subAspectNodes.getLength(); index++) { this.addXmlAspect(aspect, subAspectNodes.item(index)); } } return this; }
From source file:org.guanxi.sp.engine.service.shibboleth.AuthConsumerServiceThread.java
/** * Extracts the SAML Response from a SOAP message * * @param soapDoc The SOAP message containing the SAML Response * @return ResponseDocument/*from w w w . j a v a2s .c om*/ * @throws GuanxiException if an error occurs */ private ResponseDocument unmarshallSAML(EnvelopeDocument soapDoc) throws GuanxiException { // Rake through the SOAP to find the SAML Response... NodeList nodes = soapDoc.getEnvelope().getBody().getDomNode().getChildNodes(); Node samlResponseNode = null; for (int c = 0; c < nodes.getLength(); c++) { samlResponseNode = nodes.item(c); if (samlResponseNode.getLocalName() != null) { if (samlResponseNode.getLocalName().equals("Response")) break; } } // ...and parse it try { return ResponseDocument.Factory.parse(samlResponseNode); } catch (XmlException xe) { throw new GuanxiException("can't parse response: " + xe.getMessage()); } }
From source file:org.hdiv.config.xml.ConfigBeanDefinitionParser.java
private void processChilds(Element element, RootBeanDefinition bean) { NodeList nodeList = element.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { if (node.getLocalName().equalsIgnoreCase("startPages")) { this.processStartPages(node, bean); } else if (node.getLocalName().equalsIgnoreCase("startParameters")) { this.processStartParameters(node, bean); } else if (node.getLocalName().equalsIgnoreCase("paramsWithoutValidation")) { this.processParamsWithoutValidation(node, bean); } else if (node.getLocalName().equalsIgnoreCase("sessionExpired")) { this.processSessionExpired(node, bean); }/*from w ww. j av a 2s . c o m*/ } } }
From source file:com.rest4j.generator.Generator.java
public void generate() throws Exception { ApiFactory fac = new ApiFactory(apiXml, null, null); for (String className : preprocessors) { Preprocessor p = (Preprocessor) Class.forName(className).newInstance(); fac.addPreprocessor(p);// ww w. ja v a2 s .c o m } Document xml = fac.getDocument(); preprocess(xml); URL url = getStylesheet(); String filename = "index.html"; for (TemplateParam param : params) { if (param.getName().equals("filename")) { filename = param.getValue(); } } Document doc = transform(xml, url); cleanupBeforePostprocess(doc.getDocumentElement()); if (postprocessingXSLT != null) { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document composed = documentBuilder.newDocument(); org.w3c.dom.Element top = composed.createElementNS("http://rest4j.com/api-description", "top"); composed.appendChild(top); top.appendChild(composed.adoptNode(xml.getDocumentElement())); top.appendChild(composed.adoptNode(doc.getDocumentElement())); xml = null; doc = null; // free some mem doc = transform(composed, postprocessingXSLT); } if ("files".equals(doc.getDocumentElement().getLocalName())) { // break the result into files for (Node child : Util.it(doc.getDocumentElement().getChildNodes())) { if ("file".equals(child.getLocalName())) { if (child.getAttributes().getNamedItem("name") == null) { throw new IllegalArgumentException("Attribute name not found in <file>"); } String name = child.getAttributes().getNamedItem("name").getTextContent(); File file = new File(outputDir, name); file.getParentFile().mkdirs(); System.out.println("Write " + file.getAbsolutePath()); Attr copyFromAttr = (Attr) child.getAttributes().getNamedItem("copy-from"); if (copyFromAttr == null) { cleanupFinal((Element) child); if (child.getAttributes().getNamedItem("text") != null) { // plain-text output FileOutputStream fos = new FileOutputStream(file); try { IOUtils.write(child.getTextContent(), fos, "UTF-8"); } finally { IOUtils.closeQuietly(fos); } } else { output(child, file); } } else { String copyFrom = copyFromAttr.getValue(); URL asset = getClass().getClassLoader().getResource(copyFrom); if (asset == null) { asset = getClass().getResource(copyFrom); } if (asset == null) { File assetFile = new File(copyFrom); if (!assetFile.canRead()) { if (postprocessingXSLT != null) { asset = new URL(postprocessingXSLT, copyFrom); try { asset.openStream().close(); } catch (FileNotFoundException fnfe) { asset = null; } } if (asset == null) { asset = new URL(getStylesheet(), copyFrom); try { asset.openStream().close(); } catch (FileNotFoundException fnfe) { asset = null; } } if (asset == null) throw new IllegalArgumentException("File '" + copyFrom + "' specified by @copy-from not found in the classpath or filesystem"); } else { asset = assetFile.toURI().toURL(); } } InputStream is = asset.openStream(); OutputStream fos = new FileOutputStream(file); try { IOUtils.copy(is, fos); } finally { IOUtils.closeQuietly(is); IOUtils.closeQuietly(fos); } } } else if (child.getNodeType() == Node.ELEMENT_NODE) { throw new IllegalArgumentException("Something but <file> found inside <files>"); } } } else { File file = new File(outputDir, filename); System.out.println("Write " + file.getAbsolutePath()); cleanupFinal(doc.getDocumentElement()); DOMSource source = new DOMSource(doc); FileOutputStream fos = new FileOutputStream(file); try { StreamResult result = new StreamResult(fos); Transformer trans = tFactory.newTransformer(); trans.transform(source, result); } finally { IOUtils.closeQuietly(fos); } } }
From source file:org.hdiv.config.xml.ConfigBeanDefinitionParser.java
private void processParamsWithoutValidation(Node node, RootBeanDefinition bean) { NodeList nodeList = node.getChildNodes(); Map map = new Hashtable(); bean.getPropertyValues().addPropertyValue("paramsWithoutValidation", map); for (int i = 0; i < nodeList.getLength(); i++) { Node mappingNode = nodeList.item(i); if (mappingNode.getNodeType() == Node.ELEMENT_NODE) { if (mappingNode.getLocalName().equalsIgnoreCase("mapping")) { this.processMapping(mappingNode, map); }// w w w .jav a2s . c om } } }
From source file:se.kodapan.io.http.HttpAccessor.java
private boolean downloadFollowRedirects(final URI referer, final Request request, final Response response) throws IOException, SAXException { final URI requestURL = request.method.getURI(); response.finalURL = requestURL;//from www .j a v a 2s . co m if (log.isDebugEnabled()) { if (referer != null) { log.debug("Redirecting from " + referer + " to " + requestURL); } } if (!response.redirectChain.add(requestURL)) { throw new IOException("Circular redirection"); } if (response.redirectChain.size() > 10) { throw new IOException("Breaking at link depth " + response.redirectChain.size()); } if (!download(request, response)) { return false; } if (response.httpResponse.getStatusLine().getStatusCode() >= 300 && response.httpResponse.getStatusLine().getStatusCode() <= 399) { URI redirectURL = requestURL.resolve(response.httpResponse.getFirstHeader("Location").getValue()); // http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html if (response.httpResponse.getStatusLine().getStatusCode() == 303 && !(request.method instanceof HttpGet)) { // 303:s should be redirected as GET HttpGet get = new HttpGet(redirectURL); for (Header header : request.method.getAllHeaders()) { get.addHeader(header); } request.method = get; } else { request.method.setURI(redirectURL); } return downloadFollowRedirects(requestURL, request, response); } // attempt to follow html meta refresh redirect if (response.contentType != null && response.contentType.toLowerCase().startsWith("text/html")) { InputSource inputSource; if (response.contentEncoding != null) { inputSource = new InputSource( new InputStreamReader(new FileInputStream(response.contentFile), response.contentEncoding)); } else { inputSource = new InputSource(new FileInputStream(response.contentFile)); } DOMParser parser = new DOMParser(); parser.parse(inputSource); response.htmlDom = parser.getDocument(); return NekoHtmlTool.visitNodes(response.htmlDom, requestURL, new NekoHtmlTool.Visitor<Boolean>() { public Boolean visit(Node node, URI documentURI) { if ("META".equals(node.getLocalName())) { Node httpEquivNode = node.getAttributes().getNamedItem("http-equiv"); if (httpEquivNode != null) { String tmp = httpEquivNode.getTextContent(); if ("refresh".equalsIgnoreCase(tmp)) { node = node.getAttributes().getNamedItem("content"); if (node != null) { tmp = node.getTextContent(); Matcher matcher = pattern.matcher(tmp); if (matcher.matches()) { // 0;url= int seconds = Integer.valueOf(matcher.group(1)); URI redirectUrl; redirectUrl = requestURL.resolve(matcher.group(3)); if (!redirectUrl.equals(requestURL)) { try { HttpGet get = new HttpGet(redirectUrl); for (Header header : request.method.getAllHeaders()) { get.addHeader(header); } request.method = get; if (!downloadFollowRedirects(requestURL, request, response)) { log.error( "Expected a document as we have been redirected to it, but the new URL could not be retrieved. " + requestURL + " --> " + redirectUrl); return false; } return true; } catch (Exception e) { throw new RuntimeException(e); } } } } } } } return true; } }); } return true; }
From source file:it.cnr.icar.eric.common.SOAPMessenger.java
Reader processResponseBody(SOAPMessage response, String lookFor) throws JAXRException, SOAPException, TransformerConfigurationException, TransformerException { // grab info out of reply SOAPPart replyPart = response.getSOAPPart(); Source replySource = replyPart.getContent(); // transform//from ww w . ja v a 2s .com TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer xFormer = tFactory.newTransformer(); DOMResult domResult = new DOMResult(); xFormer.transform(replySource, domResult); org.w3c.dom.Node node = domResult.getNode(); while (node != null) { String nodeLocalName = node.getLocalName(); if ((nodeLocalName != null) && (nodeLocalName.endsWith(lookFor))) { break; } node = nextNode(node); } if (node == null) { node = domResult.getNode(); while (node != null) { String nodeLocalName = node.getLocalName(); if ((nodeLocalName != null) && (nodeLocalName.endsWith(lookFor))) { break; } node = nextNode(node); } throw new JAXRException(resourceBundle.getString("message.elementNotFound", new String[] { lookFor })); } return domNode2StringReader(node); }