use of javax.xml.xpath.XPathFactory in project camel by apache.
the class BaseNexusRepository method indexNexus.
/**
* Runs the task to index nexus for new artifacts
*/
protected void indexNexus() throws Exception {
// must have q parameter so use component to find all component
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
factory.setIgnoringElementContentWhitespace(true);
factory.setIgnoringComments(true);
DocumentBuilder documentBuilder = factory.newDocumentBuilder();
URL url = createNexusUrl();
InputStream is = url.openStream();
try {
Document dom = documentBuilder.parse(is);
XPathFactory xpFactory = XPathFactory.newInstance();
XPath exp = xpFactory.newXPath();
NodeList list = (NodeList) exp.evaluate("//data/artifact", dom, XPathConstants.NODESET);
Set<NexusArtifactDto> newArtifacts = new LinkedHashSet<>();
for (int i = 0; i < list.getLength(); i++) {
Node node = list.item(i);
String g = getNodeText(node.getChildNodes(), "groupId");
String a = getNodeText(node.getChildNodes(), "artifactId");
String v = getNodeText(node.getChildNodes(), "version");
String l = getNodeText(node.getChildNodes(), "artifactLink");
if (g != null & a != null & v != null & l != null) {
NexusArtifactDto dto = new NexusArtifactDto();
dto.setGroupId(g);
dto.setArtifactId(a);
dto.setVersion(v);
dto.setArtifactLink(l);
log.debug("Found: {}:{}:{}", dto.getGroupId(), dto.getArtifactId(), dto.getVersion());
// is it a new artifact
boolean newArtifact = true;
for (NexusArtifactDto existing : indexedArtifacts) {
if (existing.getGroupId().equals(dto.getGroupId()) && existing.getArtifactId().equals(dto.getArtifactId()) && existing.getVersion().equals(dto.getVersion())) {
newArtifact = false;
break;
}
}
if (newArtifact) {
newArtifacts.add(dto);
}
}
}
// if there is any new artifacts then process them
if (!newArtifacts.isEmpty()) {
onNewArtifacts(newArtifacts);
}
} finally {
close(is);
}
}
use of javax.xml.xpath.XPathFactory in project gocd by gocd.
the class XpathUtils method nodeExists.
public static boolean nodeExists(InputSource inputSource, String xpath) throws XPathExpressionException {
XPathFactory factory = XPathFactory.newInstance();
XPathExpression expression = factory.newXPath().compile(xpath);
Boolean b = (Boolean) expression.evaluate(inputSource, XPathConstants.BOOLEAN);
return b != null && b;
}
use of javax.xml.xpath.XPathFactory in project jdbc-shards by wplatform.
the class XPathParser method commonConstructor.
private void commonConstructor(boolean validation, EntityResolver entityResolver) {
this.validation = validation;
this.entityResolver = entityResolver;
XPathFactory factory = XPathFactory.newInstance();
this.xpath = factory.newXPath();
}
use of javax.xml.xpath.XPathFactory 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.XPathFactory 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;
}
Aggregations