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);
}
}
}
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 + "\"");
}
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;
}
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;
}
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);
}
}
Aggregations