Package javax.xml.xpath

Examples of javax.xml.xpath.XPathExpression


      {
         // System.setProperty("javax.xml.xpath.XPathFactory",
         // "com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl") ;
         // XPathFactory xpfactory = XPathFactory.newInstance() ;
         XPath xpath = XPathFactory.newInstance().newXPath();
         XPathExpression clientTypeExp = xpath.compile("/clients-type/client-type");
         XPathExpression nameExp = xpath.compile("name/text()");
         XPathExpression userAgentPatternExp = xpath.compile("userAgentPattern/text()");
         XPathExpression preferredMimeTypeExp = xpath.compile("preferredMimeType/text()");
         XPathExpression rendererExp = xpath.compile("renderer/text()");
         ClassLoader cl = Thread.currentThread().getContextClassLoader();
         java.net.URL url = cl.getResource("conf/portal/clients-type.xml");
         // S ystem.setProperty("javax.xml.parsers.DocumentBuilderFactory",
         // "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl") ;
         // S ystem.out.println("==================> " +
         // System.getProperty("javax.xml.parsers.DocumentBuilderFactory")) ;
         // S ystem.out.println("==================>" +
         // DocumentBuilderFactory.newInstance());
         Iterator itr = System.getProperties().entrySet().iterator();
         while (itr.hasNext())
         {
            Map.Entry entry = (Map.Entry)itr.next();
            String key = (String)entry.getKey();
            if (key.startsWith("javax"))
            {
               // System .out.println(key + " = " + entry.getValue());
            }
         }

         DocumentBuilderFactory finstance = DocumentBuilderFactory.newInstance();
         DocumentBuilder builder = finstance.newDocumentBuilder();
         Document document = builder.parse(url.openStream());
         NodeList nodes = (NodeList)clientTypeExp.evaluate(document, XPathConstants.NODESET);
         for (int i = 0; i < nodes.getLength(); i++)
         {
            Node node = nodes.item(i);
            String name = (String)nameExp.evaluate(node, XPathConstants.STRING);
            String userAgentPattern = (String)userAgentPatternExp.evaluate(node, XPathConstants.STRING);
            String preferredMimeType = (String)preferredMimeTypeExp.evaluate(node, XPathConstants.STRING);
            String renderer = (String)rendererExp.evaluate(node, XPathConstants.STRING);
            HttpClientType clientInfo;
            if (renderer != null && renderer.length() > 0)
            {
               clientInfo = new HttpClientType(name, userAgentPattern, preferredMimeType, renderer);
            }
View Full Code Here


            DocumentBuilder builder = domFactory.newDocumentBuilder();
            Document doc = builder.parse(applicationConfigStream);

            XPathFactory factory = XPathFactory.newInstance();
            XPath xpath = factory.newXPath();
            XPathExpression expr = xpath.compile(RECENT_CONNECTIONS_FACTORIES_XPATH);

            Object result = expr.evaluate(doc, XPathConstants.NODESET);
            NodeList nodes = (NodeList) result;
            for (int i = 0; i < nodes.getLength(); i++) {
                String nodeValue = nodes.item(i).getNodeValue();
                resultList.add(nodeValue);
            }
View Full Code Here

   * Apply an XPath query to an XML document.
   */
  public IterableElementList xpath(Node doc, String query) throws XPathExpressionException {
    XPathFactory factory = XPathFactory.newInstance();
    XPath xpath = factory.newXPath();
    XPathExpression expr = xpath.compile(query);
    NodeList result = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
    return new IterableElementList(result);
  }
View Full Code Here

   * @throws XPathExpressionException
   */
  private static Object getQNameFromXPathExpression( Document document, String xPathExpression, QName type ) throws XPathExpressionException
  {
    XPath xpath = XPathFactory.newInstance().newXPath();
    XPathExpression expression = xpath.compile( xPathExpression );
   
    return expression.evaluate( document.getDocumentElement(), type );
  }
View Full Code Here

                String s = r.getAttributeValue(null, "schemaLocation");
                if (StringUtils.isEmpty(s)) {
                    Document d = StaxUtils.read(r);
                    XPath p = XPathUtils.getFactory().newXPath();
                    p.setNamespaceContext(new W3CNamespaceContext(d.getDocumentElement()));
                    XPathExpression xpe = p.compile(d.getDocumentElement().getAttribute("node"));
                    for (XmlSchema schema : schemas.getXmlSchemas()) {
                        if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(schema.getTargetNamespace())) {
                            continue;
                        }
                        Object src = getSchemaNode(schema, schemas);
                        NodeList nodes = (NodeList)xpe.evaluate(src, XPathConstants.NODESET);
                        if (nodes.getLength() > 0) {
                            String key = schema.getSourceURI();
                            binding = convertToTmpInputSource(d.getDocumentElement(), key);
                            opts.addBindFile(binding);
                            binding = null;
View Full Code Here

    private String updateMetricTemplatesImportConfiguration(String exportXML) throws Exception {
        XPath xpath = XPathFactory.newInstance().newXPath();
        xpath.setNamespaceContext(SynchronizationConstants.createConfigurationExportNamespaceContext());

        XPathExpression overridesPath = xpath
            .compile("/:configuration-export/:entities[@id='org.rhq.enterprise.server.sync.MetricTemplateSynchronizer']/:default-configuration/ci:list-property[@name='metricUpdateOverrides']");

        Element overrides = (Element) overridesPath.evaluate(new InputSource(new StringReader(exportXML)),
            XPathConstants.NODE);

        Document doc = overrides.getOwnerDocument();

        String ns = SynchronizationConstants.CONFIGURATION_INSTANCE_NAMESPACE;
        String prefix = SynchronizationConstants.CONFIGURATION_INSTANCE_NAMESPACE_PREFIX;

        Element values = doc.createElementNS(ns, prefix + ":values");
        overrides.appendChild(values);

        Element mapValue = doc.createElementNS(ns, prefix + ":map-value");
        values.appendChild(mapValue);

        addSimpleValue(mapValue, "metricName", METRIC_NAME);
        addSimpleValue(mapValue, "resourceTypeName", RESOURCE_TYPE_NAME);
        addSimpleValue(mapValue, "resourceTypePlugin", PLUGIN_NAME);
        addSimpleValue(mapValue, "updateSchedules", "true");

        exportXML = documentToString(doc);

        //now redefine the collection interval of the above metric so that we can see the change after the import
        XPathExpression distroNameMetricPath = xpath
            .compile("/:configuration-export/:entities[@id='org.rhq.enterprise.server.sync.MetricTemplateSynchronizer']/:entity/:data/metricTemplate[@metricName='"
                + METRIC_NAME + "']");

        Element metric = (Element) distroNameMetricPath.evaluate(new InputSource(new StringReader(exportXML)),
            XPathConstants.NODE);

        doc = metric.getOwnerDocument();

        metric.setAttribute("defaultInterval", "30000");
View Full Code Here

    private String updateSystemSettingsImportConfiguration(String exportXML) throws Exception {
        XPath xpath = XPathFactory.newInstance().newXPath();
        xpath.setNamespaceContext(SynchronizationConstants.createConfigurationExportNamespaceContext());

        XPathExpression systemSettingsConfigurationPath = xpath
            .compile("/:configuration-export/:entities[@id='org.rhq.enterprise.server.sync.SystemSettingsSynchronizer']/:default-configuration/ci:simple-property[@name='propertiesToImport']");

        XPathExpression baseUrlSettingPath = xpath
            .compile("/:configuration-export/:entities[@id='org.rhq.enterprise.server.sync.SystemSettingsSynchronizer']/:entity/:data/systemSettings/entry[@key='CAM_BASE_URL']");

        Element systemSettingsConfiguration = (Element) systemSettingsConfigurationPath.evaluate(new InputSource(
            new StringReader(exportXML)), XPathConstants.NODE);
        String propsToImport = systemSettingsConfiguration.getAttribute("value");

        propsToImport += ", CAM_BASE_URL";

        systemSettingsConfiguration.setAttribute("value", propsToImport);

        exportXML = documentToString(systemSettingsConfiguration.getOwnerDocument());

        Element baseUrlSetting = (Element) baseUrlSettingPath.evaluate(new InputSource(new StringReader(exportXML)),
            XPathConstants.NODE);

        baseUrlSetting.setTextContent("http://testing.domain:7080");

        return documentToString(baseUrlSetting.getOwnerDocument());
View Full Code Here

        return hp;
    }

    private NodeList findMatchingElements(String expression) {
        try {
            XPathExpression xPathExpression = xpathFactory.newXPath().compile(expression);
            return (NodeList) xPathExpression.evaluate(document, XPathConstants.NODESET);
        } catch (XPathExpressionException e) {
            throw new RuntimeException(e);
        }
    }
View Full Code Here

     * @throws IllegalArgumentException if hostXml is null
     */
    public String obtainXmlPropertyViaXPath(String xpathExpression) {
        XPath xpath = this.xpathFactory.newXPath();
        try {
            XPathExpression expr = xpath.compile(xpathExpression);
            Object result = expr.evaluate(this.document, XPathConstants.STRING);
            return result.toString();
        } catch (XPathExpressionException e) {
            log.error("Evaluation of XPath expression failed: " + e.getMessage());
            return null;
        }
View Full Code Here

    /**
     * Evaluates the expression as the given result type
     */
    protected Object evaluateAs(Exchange exchange, QName resultQName) {
        // pool a pre compiled expression from pool
        XPathExpression xpathExpression = pool.poll();
        if (xpathExpression == null) {
            LOG.trace("Creating new XPathExpression as none was available from pool");
            // no avail in pool then create one
            try {
                xpathExpression = createXPathExpression();
View Full Code Here

TOP

Related Classes of javax.xml.xpath.XPathExpression

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.