Search in sources :

Example 36 with XPath

use of javax.xml.xpath.XPath in project gwt-test-utils by gwt-test-utils.

the class ModuleData method parseModule.

private void parseModule(String moduleName) {
    try {
        Document document = createDocument(moduleName);
        XPath xpath = XPathFactory.newInstance().newXPath();
        parseModuleFile(moduleName, document, xpath);
        alias = getModuleAlias(document, xpath);
    } catch (Exception e) {
        if (GwtTestException.class.isInstance(e)) {
            throw (GwtTestException) e;
        } else {
            throw new GwtTestConfigurationException("Error while parsing GWT module '" + moduleName + "'", e);
        }
    }
}
Also used : XPath(javax.xml.xpath.XPath) GwtTestException(com.googlecode.gwt.test.exceptions.GwtTestException) GwtTestConfigurationException(com.googlecode.gwt.test.exceptions.GwtTestConfigurationException) Document(org.w3c.dom.Document) XPathExpressionException(javax.xml.xpath.XPathExpressionException) GwtTestException(com.googlecode.gwt.test.exceptions.GwtTestException) FileNotFoundException(java.io.FileNotFoundException) GwtTestConfigurationException(com.googlecode.gwt.test.exceptions.GwtTestConfigurationException)

Example 37 with XPath

use of javax.xml.xpath.XPath in project jdk8u_jdk by JetBrains.

the class XPathExFuncTest method evaluate.

void evaluate(boolean enableExt) throws XPathFactoryConfigurationException, XPathExpressionException {
    Document document = getDocument();
    XPathFactory xPathFactory = XPathFactory.newInstance();
    /**
         * Use of the extension function 'http://exslt.org/strings:tokenize' is
         * not allowed when the secure processing feature is set to true.
         * Attempt to use the new property to enable extension function
         */
    if (enableExt) {
        boolean isExtensionSupported = enableExtensionFunction(xPathFactory);
    }
    xPathFactory.setXPathFunctionResolver(new MyXPathFunctionResolver());
    if (System.getSecurityManager() == null) {
        xPathFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, false);
    }
    XPath xPath = xPathFactory.newXPath();
    xPath.setNamespaceContext(new MyNamespaceContext());
    String xPathResult = xPath.evaluate(XPATH_EXPRESSION, document);
    System.out.println("XPath result (enableExtensionFunction == " + enableExt + ") = \"" + xPathResult + "\"");
}
Also used : XPath(javax.xml.xpath.XPath) XPathFactory(javax.xml.xpath.XPathFactory) Document(org.w3c.dom.Document)

Example 38 with XPath

use of javax.xml.xpath.XPath in project c4sg-services by Code4SocialGood.

the class CoordinatesUtil method getCoordinates.

/**@param{Object} Address- The physical address of a location
	  * This method returns Geocode coordinates of the Address object.Geocoding is the process of converting addresses (like "1600 Amphitheatre Parkway,
	  * Mountain View, CA") into geographic coordinates (like latitude 37.423021 and longitude -122.083739).Please give all the physical Address values 
	  * for a precise coordinate. setting none of the values will give a null value for the Latitude and Longitude. 
	  */
public static GeoCode getCoordinates(Address address) throws Exception {
    GeoCode geo = new GeoCode();
    String physicalAddress = (address.getAddress1() == null ? "" : address.getAddress1() + ",") + (address.getAddress2() == null ? "" : address.getAddress2() + ",") + (address.getCityName() == null ? "" : address.getCityName() + ",") + (address.getState() == null ? "" : address.getState() + "-") + (address.getZip() == null ? "" : address.getZip() + ",") + (address.getCountry() == null ? "" : address.getCountry());
    String api = GMAPADDRESS + URLEncoder.encode(physicalAddress, "UTF-8") + SENSOR;
    URL url = new URL(api);
    HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection();
    httpConnection.connect();
    int responseCode = httpConnection.getResponseCode();
    if (responseCode == 200) {
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document document = builder.parse(httpConnection.getInputStream());
        XPathFactory xPathfactory = XPathFactory.newInstance();
        XPath xpath = xPathfactory.newXPath();
        XPathExpression expr = xpath.compile(STATUS);
        String status = (String) expr.evaluate(document, XPathConstants.STRING);
        if (status.equals("OK")) {
            expr = xpath.compile(LATITUDE);
            String latitude = (String) expr.evaluate(document, XPathConstants.STRING);
            expr = xpath.compile(LONGITUDE);
            String longitude = (String) expr.evaluate(document, XPathConstants.STRING);
            geo.setLatitude(latitude);
            geo.setLongitude(longitude);
        }
    } else {
        throw new Exception("Fail to Convert to Geocode");
    }
    return geo;
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpression(javax.xml.xpath.XPathExpression) XPathFactory(javax.xml.xpath.XPathFactory) HttpURLConnection(java.net.HttpURLConnection) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Document(org.w3c.dom.Document) URL(java.net.URL)

Example 39 with XPath

use of javax.xml.xpath.XPath in project azure-tools-for-java by Microsoft.

the class AILibraryHandler method isAIWebFilterConfigured.

public boolean isAIWebFilterConfigured() throws Exception {
    if (webXMLDoc == null) {
        return false;
    }
    String exprFilter = Messages.exprConst;
    XPath xpath = XPathFactory.newInstance().newXPath();
    Element eleFilter = (Element) xpath.evaluate(exprFilter, webXMLDoc, XPathConstants.NODE);
    if (eleFilter != null) {
        return true;
    }
    return false;
}
Also used : XPath(javax.xml.xpath.XPath) Element(org.w3c.dom.Element)

Example 40 with XPath

use of javax.xml.xpath.XPath in project azure-tools-for-java by Microsoft.

the class AILibraryHandler method setFilterDef.

private void setFilterDef() {
    if (webXMLDoc == null) {
        return;
    }
    try {
        String exprFilter = Messages.exprConst;
        XPath xpath = XPathFactory.newInstance().newXPath();
        Element eleFilter = (Element) xpath.evaluate(exprFilter, webXMLDoc, XPathConstants.NODE);
        if (eleFilter == null) {
            Element filter = webXMLDoc.createElement(Messages.filterTag);
            Element filterName = webXMLDoc.createElement(Messages.filterEle);
            filterName.setTextContent(Messages.aiWebfilter);
            filter.appendChild(filterName);
            Element fClass = webXMLDoc.createElement("filter-class");
            fClass.setTextContent(Messages.aiWebFilterClassName);
            filter.appendChild(fClass);
            NodeList existingFilterNodeList = webXMLDoc.getElementsByTagName(Messages.filterTag);
            Node existingFilterNode = existingFilterNodeList != null & existingFilterNodeList.getLength() > 0 ? existingFilterNodeList.item(0) : null;
            webXMLDoc.getDocumentElement().insertBefore(filter, existingFilterNode);
        }
    } catch (Exception ex) {
        Activator.getDefault().log(ex.getMessage(), ex);
    }
}
Also used : XPath(javax.xml.xpath.XPath) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) IOException(java.io.IOException)

Aggregations

XPath (javax.xml.xpath.XPath)197 Document (org.w3c.dom.Document)107 NodeList (org.w3c.dom.NodeList)99 XPathExpressionException (javax.xml.xpath.XPathExpressionException)70 Node (org.w3c.dom.Node)70 XPathExpression (javax.xml.xpath.XPathExpression)69 XPathFactory (javax.xml.xpath.XPathFactory)59 DocumentBuilder (javax.xml.parsers.DocumentBuilder)45 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)37 IOException (java.io.IOException)32 Element (org.w3c.dom.Element)32 Test (org.junit.Test)25 InputSource (org.xml.sax.InputSource)23 SAXException (org.xml.sax.SAXException)21 File (java.io.File)19 ArrayList (java.util.ArrayList)19 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)18 HashMap (java.util.HashMap)16 InputStream (java.io.InputStream)12 PBXNativeTarget (com.facebook.buck.apple.xcode.xcodeproj.PBXNativeTarget)11