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.pentaho.reporting.platform.plugin.ParameterXmlContentHandlerTest.java
/** * Creates simple parameter xml. Output should look like: * <p>/*w w w . ja v a2 s . com*/ * <pre> * {@code * * <parameter is-list="true" is-mandatory="false" is-multi-select="true" is-strict="true" name="name" * type="java.lang.String"> * <attribute name="role" namespace="http://reporting.pentaho.org/namespaces/engine/parameter-attributes/core" * value="user"/> * <attribute name="must-validate-on-server" namespace="http://reporting.pentaho * .org/namespaces/engine/parameter-attributes/server" value="true"/> * <attribute name="has-downstream-dependent-parameter" namespace="http://reporting.pentaho * .org/namespaces/engine/parameter-attributes/server" value="true"/> * <values> * <value label="c20" null="false" selected="false" type="java.lang.String" value="c10"/> * <value label="c21" null="false" selected="false" type="java.lang.String" value="c11"/> * </values> * <dependencies> * <name>dep1</name> * <name>dep2</name> * </dependencies> * </parameter> * } * </pre> * * @throws BeanException * @throws ReportDataFactoryException * @throws ParserConfigurationException * @throws XPathExpressionException */ @Test public void createParameterWithDependenciesTest() throws BeanException, ReportDataFactoryException, ParserConfigurationException, XPathExpressionException { final DefaultListParameter parameter = new DefaultListParameter("query", "c1", "c2", "name", true, true, String.class); final ParameterContext context = getTestParameterContext(); handler.document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); final HashNMap<String, String> dependencies = new HashNMap<>(); dependencies.add("name", "dep0"); dependencies.add("name", "dep1"); final Element element = handler.createParameterElement(parameter, context, null, dependencies, false); assertNotNull(element); handler.document.appendChild(element); handler.createParameterDependencies(element, parameter, dependencies); examineStandardXml(handler.document); assertTrue(isThereAttributes(handler.document)); final String xml = toString(handler.document); // test dependencies specific elements: final XPath xpath = xpathFactory.newXPath(); final NodeList list = (NodeList) xpath.evaluate("/parameter/dependencies/name", handler.document, XPathConstants.NODESET); assertNotNull(list); assertEquals(2, list.getLength()); for (int i = 0; i < list.getLength(); i++) { final Node node = list.item(i); assertNotNull(node); assertEquals("dep" + i, node.getTextContent()); } // specific attributes: must-validate-on-server Node attr1 = (Node) xpath.evaluate("/parameter/attribute[@name='must-validate-on-server']", handler.document, XPathConstants.NODE); assertNotNull(attr1); Element elAttr1 = (Element) attr1; assertEquals("true", elAttr1.getAttribute("value")); // specific attributes: has-downstream-dependent-parameter attr1 = (Node) xpath.evaluate("/parameter/attribute[@name='has-downstream-dependent-parameter']", handler.document, XPathConstants.NODE); assertNotNull(attr1); elAttr1 = (Element) attr1; assertEquals("true", elAttr1.getAttribute("value")); }
From source file:org.rdv.ConfigurationManager.java
/** * Load the configuration file from the specified URL and configure the * application.// w ww . j a v a 2 s .co m * * @param configURL the URL of the file to load the configuration from */ private static void loadConfigurationWorker(URL configURL) { if (configURL == null) { DataViewer.alertError("The configuration file does not exist."); return; } RBNBController rbnb = RBNBController.getInstance(); LocalChannelManager localChannelManager = LocalChannelManager.getInstance(); DataPanelManager dataPanelManager = DataPanelManager.getInstance(); if (rbnb.getState() != RBNBController.STATE_DISCONNECTED) { rbnb.pause(); } dataPanelManager.closeAllDataPanels(); Document document; try { DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); document = documentBuilder.parse(configURL.openStream()); } catch (FileNotFoundException e) { DataViewer.alertError( "The configuration file does not exist." + System.getProperty("line.separator") + configURL); return; } catch (IOException e) { DataViewer.alertError("Error loading configuration file."); return; } catch (Exception e) { DataViewer.alertError("The configuration file is corrupt."); return; } XPath xp = XPathFactory.newInstance().newXPath(); try { Node rbnbNode = (Node) xp.evaluate("/rdv/rbnb[1]", document, XPathConstants.NODE); NodeList rbnbNodes = rbnbNode.getChildNodes(); String host = findChildNodeText(rbnbNodes, "host"); int port = Integer.parseInt(findChildNodeText(rbnbNodes, "port")); if (!rbnb.getRBNBHostName().equals(host) || rbnb.getRBNBPortNumber() != port) { rbnb.disconnect(); int RETRY_LIMIT = 240; int tries = 0; while (tries++ < RETRY_LIMIT && rbnb.getState() != RBNBController.STATE_DISCONNECTED) { try { Thread.sleep(250); } catch (InterruptedException e) { } } if (tries >= RETRY_LIMIT) { return; } rbnb.setRBNBHostName(host); rbnb.setRBNBPortNumber(port); } else { localChannelManager.removeAllChannels(); } double timeScale = Double.parseDouble(findChildNodeText(rbnbNodes, "timeScale")); rbnb.setTimeScale(timeScale); double playbackRate = Double.parseDouble(findChildNodeText(rbnbNodes, "playbackRate")); rbnb.setPlaybackRate(playbackRate); int state = RBNBController.getState(findChildNodeText(rbnbNodes, "state")); if (state != RBNBController.STATE_DISCONNECTED) { if (!rbnb.connect(true)) { return; } } NodeList localChannelNodes = (NodeList) xp.evaluate("/rdv/localChannel", document, XPathConstants.NODESET); for (int i = 0; i < localChannelNodes.getLength(); i++) { Node localChannelNode = localChannelNodes.item(i); String name = localChannelNode.getAttributes().getNamedItem("name").getNodeValue(); Node unitNode = localChannelNode.getAttributes().getNamedItem("unit"); String unit = (unitNode != null) ? unitNode.getNodeValue() : null; String formula = localChannelNode.getAttributes().getNamedItem("formula").getNodeValue(); Map<String, String> variables = new HashMap<String, String>(); NodeList variableNodes = (NodeList) xp.evaluate("variable", localChannelNode, XPathConstants.NODESET); for (int j = 0; j < variableNodes.getLength(); j++) { Node variableNode = variableNodes.item(j); String variableName = variableNode.getAttributes().getNamedItem("name").getNodeValue(); String variableChannel = variableNode.getAttributes().getNamedItem("channel").getNodeValue(); variables.put(variableName, variableChannel); } try { LocalChannel localChannel = new LocalChannel(name, unit, variables, formula); LocalChannelManager.getInstance().addChannel(localChannel); } catch (Exception e) { log.error("Failed to add local channel: " + name + "."); } } NodeList dataPanelNodes = (NodeList) xp.evaluate("/rdv/dataPanel", document, XPathConstants.NODESET); for (int i = 0; i < dataPanelNodes.getLength(); i++) { Node dataPanelNode = dataPanelNodes.item(i); String id = dataPanelNode.getAttributes().getNamedItem("id").getNodeValue(); DataPanel dataPanel; try { dataPanel = dataPanelManager.createDataPanel(id); } catch (Exception e) { continue; } NodeList entryNodes = (NodeList) xp.evaluate("properties/entry", dataPanelNode, XPathConstants.NODESET); for (int j = 0; j < entryNodes.getLength(); j++) { String key = entryNodes.item(j).getAttributes().getNamedItem("key").getNodeValue(); String value = entryNodes.item(j).getTextContent(); dataPanel.setProperty(key, value); } NodeList channelNodes = (NodeList) xp.evaluate("channels/channel", dataPanelNode, XPathConstants.NODESET); for (int j = 0; j < channelNodes.getLength(); j++) { String channel = channelNodes.item(j).getTextContent(); boolean added; if (dataPanel.supportsMultipleChannels()) { added = dataPanel.addChannel(channel); } else { added = dataPanel.setChannel(channel); } if (!added) { log.error("Failed to add channel " + channel + "."); } } } rbnb.setState(state); } catch (XPathExpressionException e) { e.printStackTrace(); } }
From source file:org.rdv.DockingDataPanelManager.java
@Override public void setConfigurationXML(Document document) throws Exception { XPath xp = XPathFactory.newInstance().newXPath(); Node layoutNode = (Node) xp.evaluate("windowLayout/serialState", document, XPathConstants.NODE); final CDATASection cdata = (CDATASection) layoutNode.getFirstChild(); SwingUtilities.invokeLater(new Runnable() { public void run() { try { byte layoutData[] = new sun.misc.BASE64Decoder().decodeBuffer(cdata.getData()); ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(layoutData)); rootWindow_.read(in, true); in.close();//from w ww. j av a 2 s.c om } catch (Exception e) { e.printStackTrace(); } } }); }
From source file:org.rhq.modules.plugins.jbossas7.helper.JBossCliConfiguration.java
/** * Setup SSL configuration properties by reading it from HostConfiguration (XML File) and expecting VAULT * to be present. // w w w. j a va2s .com * @param hostConfig * @return */ public String configureSecurityUsingVault(HostConfiguration hostConfig) { Map<String, String> vaultOptions = hostConfig.getVault(); if (vaultOptions == null) { return "Vault definition was not found in server configuration file"; } TruststoreConfig serverIdentity = hostConfig.getServerIdentityKeystore(); if (serverIdentity == null) { return "Could not find ssl configuration for management interface"; } JBossCliConstants constants = getCliConstants(); if (constants.version().compareTo("1.3") < 0) { return "Cannot store truststore passwords using vault, because it is not supported by this version of EAP"; } Node sslNode = (Node) xpathExpression("/jboss-cli/ssl", XPathConstants.NODE); // clean-up existing ssl node if (sslNode != null) { this.document.getDocumentElement().removeChild(sslNode); } sslNode = addChildElement(document.getDocumentElement(), "ssl"); sslNode.appendChild(createComment()); Node vaultNode = this.document.createElement("vault"); sslNode.appendChild(vaultNode); for (Entry<String, String> vaultOpt : vaultOptions.entrySet()) { Element opt = addChildElement(vaultNode, "vault-option"); opt.setAttribute("name", vaultOpt.getKey()); opt.setAttribute("value", vaultOpt.getValue()); } addChildElement(sslNode, constants.alias(), serverIdentity.getAlias()); addChildElement(sslNode, constants.truststore(), serverIdentity.getPath()); // in standalone.xml vault value is referred as ${VAULT:...} we need to strip it for jboss-cli.xml addChildElement(sslNode, constants.truststorePassword(), stripBrackets(serverIdentity.getKeystorePassword())); TruststoreConfig clientKeystore = hostConfig.getClientAuthenticationTruststore(); if (clientKeystore != null) { // 2-way authentication properties addChildElement(sslNode, constants.keystore(), clientKeystore.getPath()); addChildElement(sslNode, constants.keystorePassword(), stripBrackets(clientKeystore.getKeystorePassword())); addChildElement(sslNode, constants.keyPassword(), stripBrackets(clientKeystore.getKeyPassword())); } return null; }
From source file:org.rhq.modules.plugins.jbossas7.helper.JBossCliConfiguration.java
/** * Setup SSL configuration properties by reading it from ServerPluginConfiguration and writing it as plain text * @return null if any configuration change has been made, otherwise message indicating reason why it was not changed *//*from w w w.j a v a 2 s.c o m*/ public String configureSecurity() { if (serverConfig.isSecure()) { if (serverConfig.getTruststore() != null) { Node sslNode = (Node) xpathExpression("/jboss-cli/ssl", XPathConstants.NODE); // clean-up existing ssl node if (sslNode != null) { this.document.getDocumentElement().removeChild(sslNode); } sslNode = addChildElement(document.getDocumentElement(), "ssl"); sslNode.appendChild(createComment()); JBossCliConstants constants = getCliConstants(); addChildElement(sslNode, constants.truststore(), serverConfig.getTruststore()); addChildElement(sslNode, constants.truststorePassword(), serverConfig.getTruststorePassword()); if (serverConfig.isClientcertAuthentication()) { addChildElement(sslNode, constants.keystore(), serverConfig.getKeystore()); addChildElement(sslNode, constants.keystorePassword(), serverConfig.getKeystorePassword()); addChildElement(sslNode, constants.keyPassword(), serverConfig.getKeyPassword()); } return null; } return "Truststore path is not set"; } return "Secure connection is not enabled"; }
From source file:org.rhq.modules.plugins.jbossas7.helper.JBossCliConfiguration.java
/** * Setup controller host and port defaults * @return null if any configuration change has been made, otherwise message indicating reason why it was not changed *///from www. j av a 2 s. com public String configureDefaultController() { Node ctrlNode = this.document.createElement("default-controller"); ctrlNode.appendChild(createComment()); addChildElement(ctrlNode, "host", serverConfig.getNativeHost()); addChildElement(ctrlNode, "port", String.valueOf(serverConfig.getNativePort())); Node existing = (Node) xpathExpression("/jboss-cli/default-controller", XPathConstants.NODE); if (existing != null) { this.document.getDocumentElement().replaceChild(ctrlNode, existing); } return null; }
From source file:org.rhq.modules.plugins.wildfly10.helper.HostConfiguration.java
/** * read server SSL key-store information * @return null if not present/*from w w w . j a va 2 s . co m*/ */ public TruststoreConfig getServerIdentityKeystore() { String mgmtRealm = getManagementSecurityRealm(); if (mgmtRealm != null) { Node keyStoreNode = (Node) xpathExpression("//management/security-realms/security-realm[@name='" + mgmtRealm + "']/server-identities/ssl/keystore", XPathConstants.NODE); return TruststoreConfig.fromXmlNode(keyStoreNode); } return null; }
From source file:org.rhq.modules.plugins.wildfly10.helper.HostConfiguration.java
/** * read trust-store information for 2-way authentication * @return null if not present/*from w ww. j a v a 2s. c om*/ */ public TruststoreConfig getClientAuthenticationTruststore() { String mgmtRealm = getManagementSecurityRealm(); if (mgmtRealm != null) { Node keyStoreNode = (Node) xpathExpression("//management/security-realms/security-realm[@name='" + mgmtRealm + "']/authentication/truststore", XPathConstants.NODE); return TruststoreConfig.fromXmlNode(keyStoreNode); } return null; }
From source file:org.rhq.modules.plugins.wildfly10.helper.HostConfiguration.java
/** * read vault configuration/*from w w w . j a v a 2 s . co m*/ * @return vault configuration (key,value of vault-options) or null if vault is not present */ public Map<String, String> getVault() { Node vaultNode = (Node) xpathExpression("//vault", XPathConstants.NODE); if (vaultNode == null) { return null; } Map<String, String> vault = new LinkedHashMap<String, String>(); NodeList vaultOptions = (NodeList) xpathExpression("//vault/vault-option", XPathConstants.NODESET); for (int i = 0; i < vaultOptions.getLength(); i++) { Node option = vaultOptions.item(i); vault.put(option.getAttributes().getNamedItem("name").getNodeValue(), option.getAttributes().getNamedItem("value").getNodeValue()); } return vault; }
From source file:org.rhq.modules.plugins.wildfly10.helper.JBossCliConfiguration.java
/** * Setup controller host and port defaults * @return null if any configuration change has been made, otherwise message indicating reason why it was not changed *///from www . j a va 2 s .com public String configureDefaultController() { Node ctrlNode = this.document.createElement("default-controller"); ctrlNode.appendChild(createComment()); addChildElement(ctrlNode, "host", serverConfig.getHostname()); addChildElement(ctrlNode, "port", String.valueOf(serverConfig.getPort())); Node existing = (Node) xpathExpression("/jboss-cli/default-controller", XPathConstants.NODE); if (existing != null) { this.document.getDocumentElement().replaceChild(ctrlNode, existing); } return null; }