List of usage examples for javax.xml.xpath XPathConstants NODE
QName NODE
To view the source code for javax.xml.xpath XPathConstants NODE.
Click Source Link
The XPath 1.0 NodeSet data type.
From source file:org.jboss.on.common.jbossas.JmxInvokerServiceConfiguration.java
private void parseDocument(Document doc) throws Exception { XPathFactory xPathFactory = XPathFactory.newInstance(); XPath xPath = xPathFactory.newXPath(); // Use a bunch of incremental XPath expressions rather than one big XPath expression, // so we can provide better log messages. Node invokerMBeanNode = (Node) xPath.evaluate( "//server/mbean[@name = 'jboss.jmx:type=adaptor,name=Invoker']", doc, XPathConstants.NODE); if (invokerMBeanNode == null) { // This is uncommon and therefore suspicious. log.warn("'jboss.jmx:type=adaptor,name=Invoker' mbean not found while parsing '" + this.source + "'."); return;//from ww w . ja v a 2s .c om } Node invokeOperationNode = (Node) xPath.evaluate("xmbean/operation[name = 'invoke']", invokerMBeanNode, XPathConstants.NODE); if (invokeOperationNode == null) { // This is uncommon and therefore suspicious. log.warn("'invoke' operation not found for 'jboss.jmx:type=adaptor,name=Invoker' mbean while parsing '" + this.source + "'."); return; } Node interceptorsNode = (Node) xPath.evaluate("descriptors/interceptors", invokeOperationNode, XPathConstants.NODE); if (interceptorsNode == null) { log.debug( "No interceptors are defined for 'invoke' operation for 'jboss.jmx:type=adaptor,name=Invoker' mbean while parsing '" + this.source + "'."); return; } Node authenticationInterceptorNode = (Node) xPath.evaluate( "interceptor[@code = 'org.jboss.jmx.connector.invoker.AuthenticationInterceptor']", interceptorsNode, XPathConstants.NODE); if (authenticationInterceptorNode == null) { // This is normal. It just means the authentication interceptor isn't enabled (typically it's commented out). return; } // e.g. "java:/jaas/jmx-console" String securityDomainJndiName; try { securityDomainJndiName = xPath.evaluate("@securityDomain", authenticationInterceptorNode); } catch (XPathExpressionException e) { throw new Exception( "'securityDomain' attribute not found on 'org.jboss.jmx.connector.invoker.AuthenticationInterceptor' interceptor while parsing '" + this.source + "'."); } // e.g. "jmx-console" this.securityDomain = securityDomainJndiName.replaceFirst("^java:/jaas/", ""); }
From source file:org.jboss.qa.jcontainer.tomcat.TomcatContainer.java
protected void configureServer() { try {// w w w .j a v a 2s . co m final File file = new File(configuration.getDirectory(), "conf" + File.separator + "server.xml"); final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); final DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); final Document doc = docBuilder.parse(file); final XPathFactory xPathfactory = XPathFactory.newInstance(); final XPath xpath = xPathfactory.newXPath(); final XPathExpression expr = xpath.compile("/Server/Service/Connector[@protocol='HTTP/1.1']"); final Node node = (Node) expr.evaluate(doc, XPathConstants.NODE); node.getAttributes().getNamedItem("port").setNodeValue(Integer.toString(configuration.getHttpPort())); // Write the content into xml file final TransformerFactory transformerFactory = TransformerFactory.newInstance(); final Transformer transformer = transformerFactory.newTransformer(); final DOMSource source = new DOMSource(doc); final StreamResult result = new StreamResult(file); transformer.transform(source, result); } catch (Exception e) { log.error("Ports was not configured", e); } }
From source file:org.jboss.tools.aerogear.hybrid.android.core.adt.AndroidProjectGenerator.java
private void updateAppName(String appName) throws CoreException { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true);/*from w ww .j a v a2s .c o m*/ DocumentBuilder db; try { db = dbf.newDocumentBuilder(); IPath stringsPath = new Path(getDestination().toString()).append(DIR_RES).append(DIR_VALUES) .append(FILE_XML_STRINGS); File strings = stringsPath.toFile(); Document configDocument = db.parse(strings); XPath xpath = XPathFactory.newInstance().newXPath(); try { XPathExpression expr = xpath.compile("//string[@name=\"app_name\"]"); Node node = (Node) expr.evaluate(configDocument, XPathConstants.NODE); node.setTextContent(appName); configDocument.setXmlStandalone(true); Source source = new DOMSource(configDocument); StreamResult result = new StreamResult(strings); // Write the DOM document to the file TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer xformer = transformerFactory.newTransformer(); xformer.transform(source, result); } catch (XPathExpressionException e) {//We continue because this affects the displayed app name // which is not a show stopper during development AndroidCore.log(IStatus.ERROR, "Error when updating the application name", e); } catch (TransformerConfigurationException e) { AndroidCore.log(IStatus.ERROR, "Error when updating the application name", e); } catch (TransformerException e) { AndroidCore.log(IStatus.ERROR, "Error when updating the application name", e); } } catch (ParserConfigurationException e) { throw new CoreException(new Status(IStatus.ERROR, HybridCore.PLUGIN_ID, "Parser error when parsing /res/values/strings.xml", e)); } catch (SAXException e) { throw new CoreException( new Status(IStatus.ERROR, HybridCore.PLUGIN_ID, "Parsing error on /res/values/strings.xml", e)); } catch (IOException e) { throw new CoreException(new Status(IStatus.ERROR, HybridCore.PLUGIN_ID, "IO error when parsing /res/values/strings.xml", e)); } }
From source file:org.jboss.windup.decorator.xml.ejb.EJBValidatingDecorator.java
@Override public void processMeta(XmlMetadata meta) { // first, find any relationship elements... Set<String> ejbNames = new HashSet<String>(); try {/*from w w w .j a v a2 s . c o m*/ Document doc = meta.getParsedDocument(); if (doc == null) { throw new NullPointerException(); } if (LOG.isDebugEnabled()) { LOG.debug("Processing: " + ejbRelationshipExpression); } final NodeList nodes = (NodeList) ejbRelationshipExpression.evaluate(doc, XPathConstants.NODESET); if (nodes != null) { if (LOG.isDebugEnabled()) { LOG.debug("Found results for: " + meta.getFilePointer().getAbsolutePath()); } for (int i = 0; i < nodes.getLength(); i++) { Element relationshipRoleSource = XmlElementUtil.getChildByTagName((Element) nodes.item(i), "relationship-role-source"); Element ejbName = XmlElementUtil.getChildByTagName(relationshipRoleSource, "ejb-name"); if (LOG.isDebugEnabled()) { LOG.debug("Found relationship: " + ejbName.getTextContent()); } ejbNames.add(ejbName.getTextContent()); } } // now, validate that all the EJBs provide local interfaces. for (String ejbName : ejbNames) { String ejbLookup = StringUtils.replace(XPATH_EJB_NAME_PROTOTYPE, "${entity-name}", ejbName); Element ejbEntityNode = (Element) xpath.evaluate(ejbLookup, doc, XPathConstants.NODE); Integer lineNumber = (Integer) LocationAwareXmlReader.getLineNumber(ejbEntityNode); // validate that the local and local-home tags exist. Element localTag = XmlElementUtil.getChildByTagName(ejbEntityNode, "local"); Element localHomeTag = XmlElementUtil.getChildByTagName(ejbEntityNode, "local-home"); if (LOG.isDebugEnabled()) { LOG.info("XPath: " + ejbLookup); LOG.debug("Line: " + lineNumber); LOG.debug("Local tag null: " + (localTag == null)); LOG.debug("Local-home tag null: " + (localHomeTag == null)); } if (localTag == null) { Line result = new Line(); result.setDescription("Entity: " + ejbName + " does not expose required local interface."); result.setLineNumber(lineNumber); result.setPattern("//entity[ejb-name]/local"); result.setEffort(new StoryPointEffort(1)); MarkdownHint simpleHint = new MarkdownHint(); simpleHint.setMarkdown( "Create a local interface for the Entity bean to support Container Managed Relationship (CMR)."); result.getHints().add(simpleHint); meta.getDecorations().add(result); } if (localHomeTag == null) { Line result = new Line(); result.setDescription("Entity: " + ejbName + " does not expose required local-home interface."); result.setLineNumber(lineNumber); result.setPattern("//entity[ejb-name]/local-home"); result.setEffort(new StoryPointEffort(1)); MarkdownHint simpleHint = new MarkdownHint(); simpleHint.setMarkdown( "Create a local-home interface for the Entity bean to support Container Managed Relationship (CMR)."); result.getHints().add(simpleHint); meta.getDecorations().add(result); } } } catch (Exception e) { LOG.error("Exception during XPath.", e); } }
From source file:org.jbpm.designer.server.service.DefaultDesignerAssetServiceTest.java
private Element getProcessElementFromXml(String content) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); ByteArrayInputStream input = new ByteArrayInputStream(content.getBytes("UTF-8")); Document xml = builder.parse(input); XPathExpression expr = xpath.compile("/definitions/process"); Element element = (Element) expr.evaluate(xml, XPathConstants.NODE); return element; }
From source file:org.jbpm.designer.server.service.DefaultDesignerAssetServiceTest.java
private Element getMetaDataElementFromXml(String content) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); ByteArrayInputStream input = new ByteArrayInputStream(content.getBytes("UTF-8")); Document xml = builder.parse(input); XPathExpression expr = xpath.compile("/definitions/process/extensionElements/metaData"); Element element = (Element) expr.evaluate(xml, XPathConstants.NODE); return element; }
From source file:org.jbpm.designer.server.service.DefaultDesignerAssetServiceTest.java
private Element getDefinitionsElementFromXml(String content) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); ByteArrayInputStream input = new ByteArrayInputStream(content.getBytes("UTF-8")); Document xml = builder.parse(input); XPathExpression expr = xpath.compile("/definitions"); Element element = (Element) expr.evaluate(xml, XPathConstants.NODE); return element; }
From source file:org.jembi.rhea.orchestration.SaveEncounterORU_R01ValidatorAndEnricher.java
private String getNodeContent(XPath xpath, Document document, String path) throws XPathExpressionException { XPathExpression expression = xpath.compile(path); Node givenNameNode = (Node) expression.evaluate(document, XPathConstants.NODE); return givenNameNode.getTextContent(); }
From source file:org.jvnet.hudson.plugins.m2release.nexus.StageClient.java
/** * Check if we have the required permissions for nexus staging. * /*from w w w .j a v a 2 s . c o m*/ * @return * @throws StageException if an exception occurred whilst checking the authorisation. */ public void checkAuthentication() throws StageException { try { URL url = new URL(nexusURL.toString() + "/service/local/status"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); addAuthHeader(conn); int status = conn.getResponseCode(); if (status == 200) { DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = builder.parse(conn.getInputStream()); /* * check for the following permissions: */ String[] requiredPerms = new String[] { "nexus:stagingprofiles", "nexus:stagingfinish", // "nexus:stagingpromote", "nexus:stagingdrop" }; XPath xpath = XPathFactory.newInstance().newXPath(); for (String perm : requiredPerms) { String expression = "//clientPermissions/permissions/permission[id=\"" + perm + "\"]/value"; Node node = (Node) xpath.evaluate(expression, doc, XPathConstants.NODE); if (node == null) { throw new StageException( "Invalid reponse from server - is the URL a Nexus Professional server?"); } int val = Integer.parseInt(node.getTextContent()); if (val == 0) { throw new StageException( "User has insufficient privaledges to perform staging actions (" + perm + ")"); } } } else { drainOutput(conn); if (status == HttpURLConnection.HTTP_UNAUTHORIZED) { throw new IOException("Incorrect username / password supplied."); } else if (status == HttpURLConnection.HTTP_NOT_FOUND) { throw new IOException("Service not found - is this a Nexus server?"); } else { throw new IOException("Server returned error code " + status + "."); } } } catch (IOException ex) { throw createStageExceptionForIOException(nexusURL, ex); } catch (XPathException ex) { throw new StageException(ex); } catch (ParserConfigurationException ex) { throw new StageException(ex); } catch (SAXException ex) { throw new StageException(ex); } }
From source file:org.kitodo.production.plugin.importer.massimport.PicaMassImport.java
/** * Get OPAC address./*from w w w. j a va2 s . c om*/ * * @return the address of the opac catalogue */ private String getOpacAddress() throws ImportPluginException { String address; try (FileInputStream istream = new FileInputStream(KitodoConfigFile.OPAC_CONFIGURATION.getFile())) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); DocumentBuilder builder = factory.newDocumentBuilder(); Document xmlDocument = builder.parse(istream); XPath xPath = XPathFactory.newInstance().newXPath(); Node node = (Node) xPath .compile("/opacCatalogues/catalogue[@title='" + this.getOpacCatalogue() + "']/config") .evaluate(xmlDocument, XPathConstants.NODE); address = node.getAttributes().getNamedItem("address").getNodeValue(); } catch (ParserConfigurationException | SAXException | IOException | XPathExpressionException e) { logger.error(e.getMessage(), e); throw new ImportPluginException(e); } return address; }