Java XPath Get getORSVersion()

Here you can find the source of getORSVersion()

Description

get ORS Version

License

Apache License

Declaration

public synchronized static final String getORSVersion() 

Method Source Code


//package com.java2s;
/*/*ww w  .ja  v a2 s. com*/
 *  Licensed to GIScience Research Group, Heidelberg University (GIScience)
 *
 *       http://www.giscience.uni-hd.de
 *       http://www.heigit.org
 *
 *  under one or more contributor license agreements. See the NOTICE file 
 *  distributed with this work for additional information regarding copyright 
 *  ownership. The GIScience licenses this file to you under the Apache License, 
 *  Version 2.0 (the "License"); you may not use this file except in compliance 
 *  with the License. You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;
import org.w3c.dom.Document;

public class Main {
    public synchronized static final String getORSVersion() {

        String version = null;

        try {
            String curDir = System.getProperty("user.dir");
            Path pomFile = Paths.get(Paths.get(curDir).getParent().toString(), "openrouteservice")
                    .resolve("pom.xml");

            try (InputStream is = Files.newInputStream(pomFile)) {
                Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(is);
                doc.getDocumentElement().normalize();
                version = (String) XPathFactory.newInstance().newXPath().compile("/project/version").evaluate(doc,
                        XPathConstants.STRING);
                if (version != null) {
                    version = version.trim();
                }
            }
        } catch (Exception e) {
        }

        return version;
    }
}

Related

  1. getNodesByXPath(Element parent, String name)
  2. getNodesListXpathNode(final String xPath, final Node node)
  3. getNodeText(XPath xpath, String xp, Node n)
  4. getNodeTextByXPath(Document doc, String xpath)
  5. getNogeList(String path, Node node)
  6. getProcessIdFromBpmn(final String bpmn)
  7. getPublicKeyFromKeyInfo(Node keyInfoNode)
  8. getResultXpathstring(String expr, InputSource inputSource)
  9. getScrProperties(String componentName)