Example usage for javax.xml.xpath XPath evaluate

List of usage examples for javax.xml.xpath XPath evaluate

Introduction

In this page you can find the example usage for javax.xml.xpath XPath evaluate.

Prototype

public Object evaluate(String expression, InputSource source, QName returnType) throws XPathExpressionException;

Source Link

Document

Evaluate an XPath expression in the context of the specified InputSource and return the result as the specified type.

Usage

From source file:it.imtech.metadata.MetaUtility.java

private void addClassificationToMetadata(String panelname) {
    try {/*from   ww  w .j ava  2 s .co  m*/
        DocumentBuilder dBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document doc;

        XPathFactory factory = XPathFactory.newInstance();
        XPath xpath = factory.newXPath();

        //File backupmetadata = new File(Globals.SESSION_METADATA);
        File backupmetadata = new File(Globals.DUPLICATION_FOLDER_SEP + "session" + panelname);
        doc = dBuilder.parse(backupmetadata);

        String expression = "//*[@ID='22']";
        NodeList nodeList = (NodeList) xpath.evaluate(expression, doc, XPathConstants.NODESET);
        int maxseq = 0;
        int tmpseq;

        for (int i = 0; i < nodeList.getLength(); i++) {
            NamedNodeMap attr = nodeList.item(i).getAttributes();
            Node nodeAttr = attr.getNamedItem("sequence");
            tmpseq = Integer.parseInt(nodeAttr.getNodeValue());

            if (tmpseq > maxseq) {
                maxseq = tmpseq;
            }
        }
        maxseq++;

        Node newNode = nodeList.item(0).cloneNode(true);
        Element nodetocopy = (Element) newNode;
        NamedNodeMap attr = nodeList.item(0).getAttributes();
        Node nodeAttr = attr.getNamedItem("sequence");
        nodeAttr.setTextContent(Integer.toString(maxseq));

        Node copyOfn = doc.importNode(nodetocopy, true);
        nodeList.item(0).getParentNode().appendChild(copyOfn);

        Element root = doc.getDocumentElement();
        NodeList firstlevelnodes = root.getChildNodes();

        for (int i = 0; i < firstlevelnodes.getLength(); i++) {
            if (firstlevelnodes.item(i).getNodeType() == Node.ELEMENT_NODE) {
                Element node = (Element) firstlevelnodes.item(i);
                Integer sequence = Integer.parseInt(node.getAttribute("sequence"));
                if (!node.getAttribute("ID").equals("22") && sequence >= maxseq) {
                    node.setAttribute("sequence", Integer.toString(sequence + 1));
                }
            }
        }

        XMLUtil.xmlWriter(doc, Globals.DUPLICATION_FOLDER_SEP + "session" + panelname);
    } catch (ParserConfigurationException ex) {
        logger.error(ex.getMessage());
    } catch (SAXException ex) {
        logger.error(ex.getMessage());
    } catch (IOException ex) {
        logger.error(ex.getMessage());
    } catch (XPathExpressionException ex) {
        logger.error(ex.getMessage());
    }
}

From source file:it.imtech.metadata.MetaUtility.java

private void removeClassificationToMetadata(String panelname) {
    try {/*  w  ww  . java 2 s .  c  o  m*/
        System.out.println("Search for lest classification..");

        DocumentBuilder dBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document doc;

        XPathFactory factory = XPathFactory.newInstance();
        XPath xpath = factory.newXPath();

        //File backupmetadata = new File(Globals.SESSION_METADATA);
        File backupmetadata = new File(Globals.DUPLICATION_FOLDER_SEP + "session" + panelname);
        doc = dBuilder.parse(backupmetadata);

        String expression = "//*[@ID='22']";
        NodeList nodeList = (NodeList) xpath.evaluate(expression, doc, XPathConstants.NODESET);
        int maxseq = 0;
        int tmpseq;

        for (int i = 0; i < nodeList.getLength(); i++) {
            NamedNodeMap attr = nodeList.item(i).getAttributes();
            Node nodeAttr = attr.getNamedItem("sequence");
            tmpseq = Integer.parseInt(nodeAttr.getNodeValue());

            if (tmpseq > maxseq) {
                maxseq = tmpseq;
            }
        }

        int nLast, idLast, counter = 0;

        for (int i = 0; i < nodeList.getLength(); i++) {
            NamedNodeMap attr = nodeList.item(i).getAttributes();
            Node nodeAttr = attr.getNamedItem("sequence");
            if (maxseq == Integer.parseInt(nodeAttr.getNodeValue())) {
                nLast = counter;
                nodeAttr = attr.getNamedItem("ID");
                idLast = Integer.parseInt(nodeAttr.getNodeValue());
                nodeList.item(i).getParentNode().removeChild(nodeList.item(i));
            }
            counter++;
        }

        Element root = doc.getDocumentElement(); // ripristino sequenze esatte
        NodeList firstlevelnodes = root.getChildNodes();

        for (int i = 0; i < firstlevelnodes.getLength(); i++) {
            if (firstlevelnodes.item(i).getNodeType() == Node.ELEMENT_NODE) {
                Element node = (Element) firstlevelnodes.item(i);
                Integer sequence = Integer.parseInt(node.getAttribute("sequence"));
                if (!node.getAttribute("ID").equals("22") && sequence >= maxseq) {
                    node.setAttribute("sequence", Integer.toString(sequence - 1));
                }
            }
        }

        XMLUtil.xmlWriter(doc, Globals.DUPLICATION_FOLDER_SEP + "session" + panelname);
    } catch (ParserConfigurationException ex) {
        logger.error(ex.getMessage());
    } catch (SAXException ex) {
        logger.error(ex.getMessage());
    } catch (IOException ex) {
        logger.error(ex.getMessage());
    } catch (XPathExpressionException ex) {
        logger.error(ex.getMessage());
    }
}

From source file:com.photon.phresco.framework.actions.applications.Quality.java

private List<TestCase> getTestCases(NodeList testSuites) throws TransformerException, PhrescoException {
    S_LOGGER.debug("Entering Method Quality.getTestCases(Document doc, String testSuiteName)");

    try {/*from   ww  w.j  av  a  2s.  c  o  m*/
        String testCasePath = null;
        String testSuitePath = null;
        FrameworkUtil frameworkUtil = FrameworkUtil.getInstance();
        ProjectAdministrator administrator = PhrescoFrameworkFactory.getProjectAdministrator();
        Project project = administrator.getProject(projectCode);
        getHttpRequest().setAttribute(REQ_PROJECT_CODE, projectCode);
        String techId = project.getProjectInfo().getTechnology().getId();

        if (APP_UNIT_TEST.equals(testType)) {
            testSuitePath = frameworkUtil.getUnitTestSuitePath(techId);
        } else if (APP_FUNCTIONAL_TEST.equals(testType)) {
            testSuitePath = frameworkUtil.getFunctionalTestSuitePath(techId);
        }
        testCasePath = frameworkUtil.getTestCasePath(project.getProjectInfo().getTechnology().getId());

        S_LOGGER.debug("Test suite path " + testSuitePath);
        S_LOGGER.debug("Test suite path " + testCasePath);

        StringBuilder sb = new StringBuilder(); //testsuites/testsuite[@name='yyy']/testcase
        //sb.append(XPATH_SINGLE_TESTSUITE);
        sb.append(testSuitePath);
        sb.append(NAME_FILTER_PREFIX);
        sb.append(testSuite);
        sb.append(NAME_FILTER_SUFIX);
        sb.append(testCasePath);

        XPath xpath = XPathFactory.newInstance().newXPath();
        NodeList nodelist = (NodeList) xpath.evaluate(sb.toString(), testSuites.item(0).getParentNode(),
                XPathConstants.NODESET);

        // For tehnologies like php and drupal duoe to plugin change xml testcase path modified
        if (nodelist.getLength() == 0) {
            StringBuilder sbMulti = new StringBuilder();
            sbMulti.append(testSuitePath);
            sbMulti.append(NAME_FILTER_PREFIX);
            sbMulti.append(testSuite);
            sbMulti.append(NAME_FILTER_SUFIX);
            sbMulti.append(XPATH_TESTSUTE_TESTCASE);
            nodelist = (NodeList) xpath.evaluate(sbMulti.toString(), testSuites.item(0).getParentNode(),
                    XPathConstants.NODESET);
        }

        // For technology sharepoint
        if (nodelist.getLength() == 0) {
            StringBuilder sbMulti = new StringBuilder(); //testsuites/testsuite[@name='yyy']/testcase
            sbMulti.append(XPATH_MULTIPLE_TESTSUITE);
            sbMulti.append(NAME_FILTER_PREFIX);
            sbMulti.append(testSuite);
            sbMulti.append(NAME_FILTER_SUFIX);
            sbMulti.append(testCasePath);
            nodelist = (NodeList) xpath.evaluate(sbMulti.toString(), testSuites.item(0).getParentNode(),
                    XPathConstants.NODESET);
        }

        List<TestCase> testCases = new ArrayList<TestCase>();

        int failureTestCases = 0;
        int errorTestCases = 0;

        for (int i = 0; i < nodelist.getLength(); i++) {
            Node node = nodelist.item(i);
            NodeList childNodes = node.getChildNodes();
            NamedNodeMap nameNodeMap = node.getAttributes();
            TestCase testCase = new TestCase();

            if (childNodes != null && childNodes.getLength() > 0) {

                for (int j = 0; j < childNodes.getLength(); j++) {
                    Node childNode = childNodes.item(j);

                    if (ELEMENT_FAILURE.equals(childNode.getNodeName())) {
                        failureTestCases++;
                        TestCaseFailure failure = getFailure(childNode);
                        if (failure != null) {
                            testCase.setTestCaseFailure(failure);
                        }
                    }

                    if (ELEMENT_ERROR.equals(childNode.getNodeName())) {
                        errorTestCases++;
                        TestCaseError error = getError(childNode);
                        if (error != null) {
                            testCase.setTestCaseError(error);
                        }
                    }
                }
            }

            for (int k = 0; k < nameNodeMap.getLength(); k++) {
                Node attribute = nameNodeMap.item(k);
                String attributeName = attribute.getNodeName();
                String attributeValue = attribute.getNodeValue();
                if (ATTR_NAME.equals(attributeName)) {
                    testCase.setName(attributeValue);
                } else if (ATTR_CLASS.equals(attributeName) || ATTR_CLASSNAME.equals(attributeName)) {
                    testCase.setTestClass(attributeValue);
                } else if (ATTR_FILE.equals(attributeName)) {
                    testCase.setFile(attributeValue);
                } else if (ATTR_LINE.equals(attributeName)) {
                    testCase.setLine(Float.parseFloat(attributeValue));
                } else if (ATTR_ASSERTIONS.equals(attributeName)) {
                    testCase.setAssertions(Float.parseFloat(attributeValue));
                } else if (ATTR_TIME.equals(attributeName)) {
                    testCase.setTime(attributeValue);
                }
            }
            testCases.add(testCase);
        }

        getHttpRequest().setAttribute(REQ_TESTSUITE_FAILURES, failureTestCases + "");
        getHttpRequest().setAttribute(REQ_TESTSUITE_ERRORS, errorTestCases + "");
        getHttpRequest().setAttribute(REQ_TESTSUITE_TESTS, nodelist.getLength() + "");
        getHttpRequest().setAttribute(REQ_PROJECT_CODE, projectCode);
        return testCases;
    } catch (PhrescoException e) {
        S_LOGGER.error("Entered into catch block of Quality.getTestCases()" + e);
        throw e;
    } catch (XPathExpressionException e) {
        S_LOGGER.error("Entered into XPathExpressionException catch block of Quality.getTestCases()" + e);
        throw new PhrescoException(e);
    }
}

From source file:lcmc.data.VMSXML.java

/** Remove XML from some device. */
private void removeXML(final String domainName, final Map<String, String> parametersMap, final String path,
        final VirtualHardwareComparator vhc, final String virshOptions) {
    final String configName = namesConfigsMap.get(domainName);
    if (configName == null) {
        return;// w  w  w .j  a  v a2  s .c  o m
    }
    final Node domainNode = getDomainNode(domainName);
    if (domainNode == null) {
        return;
    }
    final XPath xpath = XPathFactory.newInstance().newXPath();
    try {
        final NodeList nodes = (NodeList) xpath.evaluate(path, domainNode, XPathConstants.NODESET);
        final Element hwNode = vhc.getElement(nodes, parametersMap);
        if (hwNode != null) {
            hwNode.getParentNode().removeChild(hwNode);
        }
    } catch (final javax.xml.xpath.XPathExpressionException e) {
        Tools.appError("could not evaluate: ", e);
        return;
    }
    saveAndDefine(domainNode, domainName, virshOptions);
}

From source file:lcmc.data.VMSXML.java

/** Return devices node. */
private Node getDevicesNode(final XPath xpath, final Node domainNode) {
    final String devicesPath = "devices";
    try {/*w  ww. j a  v a2  s  .  c  om*/
        final NodeList devicesNodes = (NodeList) xpath.evaluate(devicesPath, domainNode,
                XPathConstants.NODESET);
        if (devicesNodes.getLength() != 1) {
            Tools.appWarning("devices nodes: " + devicesNodes.getLength());
            return null;
        }
        return devicesNodes.item(0);
    } catch (final javax.xml.xpath.XPathExpressionException e) {
        Tools.appError("could not evaluate: ", e);
        return null;
    }
}

From source file:marytts.tools.voiceimport.HTKLabeler.java

/**
 * Get phone sequence from a single feature file
 * @param basename/* w  w w. j  a v  a2  s.  co  m*/
 * @return String
 * @throws Exception
 */
private String getLineFromXML(String basename, boolean spause, boolean vpause) throws Exception {

    String line;
    String phoneSeq;
    Matcher matcher;
    Pattern pattern;
    StringBuilder alignBuff = new StringBuilder();
    //alignBuff.append(basename);
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document doc = builder.parse(new File(getProp(PROMPTALLOPHONESDIR) + "/" + basename + xmlExt));
    XPath xpath = XPathFactory.newInstance().newXPath();
    NodeList tokens = (NodeList) xpath.evaluate("//t | //boundary", doc, XPathConstants.NODESET);

    alignBuff.append(collectTranscription(tokens));
    phoneSeq = alignBuff.toString();
    pattern = Pattern.compile("pau ssil ");
    matcher = pattern.matcher(phoneSeq);
    phoneSeq = matcher.replaceAll("sil ");

    pattern = Pattern.compile(" ssil pau$");
    matcher = pattern.matcher(phoneSeq);
    phoneSeq = matcher.replaceAll(" sil");

    if (!vpause) {
        /* TODO: Extra code need to write
         * to maintain minimum number of short sil.
         * or consider word boundaries as ssil.
         */
        /* 
         * virtual silence on word boundaries
         * are matched in sp  
         */
        pattern = Pattern.compile("vssil");
        matcher = pattern.matcher(phoneSeq);
        phoneSeq = matcher.replaceAll("");
    } else {
        /* 
         * virtual silence on word boundaries
         * are matched in sp  
         */
        pattern = Pattern.compile("vssil");
        matcher = pattern.matcher(phoneSeq);
        phoneSeq = matcher.replaceAll("sp");
    }

    // checking
    if (!spause) {
        pattern = Pattern.compile("ssil");
        matcher = pattern.matcher(phoneSeq);
        phoneSeq = matcher.replaceAll("");
    }

    phoneSeq += " .";

    pattern = Pattern.compile("\\s+");
    matcher = pattern.matcher(phoneSeq);
    phoneSeq = matcher.replaceAll("\n");

    //System.out.println(phoneSeq);
    return phoneSeq;
}

From source file:marytts.tools.voiceimport.HTKLabeler.java

/**
* Get word sequence from a single feature file
* @param basename//from   w w w. j  ava 2s . com
* @return String
* @throws Exception
*/
private String getWordLineFromXML(String basename, boolean spause, boolean vpause) throws Exception {

    String line;
    String phoneSeq;
    Matcher matcher;
    Pattern pattern;
    StringBuilder alignBuff = new StringBuilder();
    //alignBuff.append(basename);
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document doc = builder.parse(new File(getProp(PROMPTALLOPHONESDIR) + "/" + basename + xmlExt));
    XPath xpath = XPathFactory.newInstance().newXPath();
    NodeList tokens = (NodeList) xpath.evaluate("//t | //boundary", doc, XPathConstants.NODESET);

    alignBuff.append(collectWordTranscription(tokens));
    phoneSeq = alignBuff.toString();
    pattern = Pattern.compile("pau ssil ");
    matcher = pattern.matcher(phoneSeq);
    phoneSeq = matcher.replaceAll("sil ");

    pattern = Pattern.compile(" ssil pau$");
    matcher = pattern.matcher(phoneSeq);
    phoneSeq = matcher.replaceAll(" sil");

    if (!vpause) {
        /* TODO: Extra code need to write
         * to maintain minimum number of short sil.
         * or consider word boundaries as ssil.
         */
        /* 
         * virtual silence on word boundaries
         * are matched in sp  
         */
        pattern = Pattern.compile("vssil");
        matcher = pattern.matcher(phoneSeq);
        phoneSeq = matcher.replaceAll("");
    } else {
        /* 
         * virtual silence on word boundaries
         * are matched in sp  
         */
        pattern = Pattern.compile("vssil");
        matcher = pattern.matcher(phoneSeq);
        phoneSeq = matcher.replaceAll("");
    }

    // checking
    if (!spause) {
        pattern = Pattern.compile("ssil");
        matcher = pattern.matcher(phoneSeq);
        phoneSeq = matcher.replaceAll("");
    }

    phoneSeq += " .";

    pattern = Pattern.compile("\\s+");
    matcher = pattern.matcher(phoneSeq);
    phoneSeq = matcher.replaceAll("\n");

    //System.out.println(phoneSeq);
    return phoneSeq;
}

From source file:marytts.tools.voiceimport.HTKLabeler.java

/**
 * Get word and phone sequence from a single feature file
 * @param basename//ww  w . j  av a  2  s. co  m
 * @return String
 * @throws Exception
 */
private String getWordandPhoneLineFromXML(String basename, boolean spause, boolean vpause) throws Exception {

    String line;
    String phoneSeq;
    Matcher matcher;
    Pattern pattern;
    StringBuilder alignBuff = new StringBuilder();
    //alignBuff.append(basename);
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document doc = builder.parse(new File(getProp(PROMPTALLOPHONESDIR) + "/" + basename + xmlExt));
    XPath xpath = XPathFactory.newInstance().newXPath();
    NodeList tokens = (NodeList) xpath.evaluate("//t | //boundary", doc, XPathConstants.NODESET);

    alignBuff.append(collectTranscriptionAndWord(tokens));
    phoneSeq = alignBuff.toString();
    pattern = Pattern.compile("pau ssil ");
    matcher = pattern.matcher(phoneSeq);
    phoneSeq = matcher.replaceAll("sil ");

    pattern = Pattern.compile(" ssil pau$");
    matcher = pattern.matcher(phoneSeq);
    phoneSeq = matcher.replaceAll(" sil");

    if (!vpause) {
        /* TODO: Extra code need to write
         * to maintain minimum number of short sil.
         * or consider word boundaries as ssil.
         */
        /* 
         * virtual silence on word boundaries
         * are matched in sp  
         */
        pattern = Pattern.compile("vssil");
        matcher = pattern.matcher(phoneSeq);
        phoneSeq = matcher.replaceAll("");
    } else {
        /* 
         * virtual silence on word boundaries
         * are matched in sp  
         */
        pattern = Pattern.compile("vssil");
        matcher = pattern.matcher(phoneSeq);
        phoneSeq = matcher.replaceAll("sp");
    }

    // checking
    if (!spause) {
        pattern = Pattern.compile("ssil");
        matcher = pattern.matcher(phoneSeq);
        phoneSeq = matcher.replaceAll("");
    }

    phoneSeq += " .";

    pattern = Pattern.compile("\\s+");
    matcher = pattern.matcher(phoneSeq);
    phoneSeq = matcher.replaceAll("\n");

    pattern = Pattern.compile("-");
    matcher = pattern.matcher(phoneSeq);
    phoneSeq = matcher.replaceAll(" ");

    //System.out.println(phoneSeq);
    return phoneSeq;
}

From source file:org.ala.harvester.MorphbankHarvester.java

/**
 * Process a single image, do the document mapping etc
 * //  w  w  w. j av a2 s  . co  m
 * @param infosourceId
 * @param imageIndex
 * @param currentResDom
 * @throws Exception
 */
private void processSingleImage(int infosourceId, int imageIndex, Document currentResDom) throws Exception {

    XPathFactory factory = XPathFactory.newInstance();
    XPath xpath = factory.newXPath();
    ParsedDocument pd = new ParsedDocument();
    ParsedDocument imageDoc = new ParsedDocument();

    String subject = MappingUtils.getSubject();

    String xPathToIdentifier = "/response/object[" + imageIndex + "]/detailPageUrl/text()";
    String xPathToScientificName = "/response/object[" + imageIndex + "]/ScientificName/text()";
    String xPathToLatitude = "/response/object[" + imageIndex + "]/DecimalLatitude/text()";
    String xPathToLongitude = "/response/object[" + imageIndex + "]/DecimalLongitude/text()";
    String xPathToImageUrl = "/response/object[" + imageIndex + "]/thumbUrl/text()";
    String xPathToLicense = "/response/object[" + imageIndex + "]/copyrightText/text()";
    String xPathToKingdom = "/response/object[" + imageIndex + "]/Kingdom/text()";
    String xPathToPhylum = "/response/object[" + imageIndex + "]/Phylum/text()";
    String xPathToClass = "/response/object[" + imageIndex + "]/Class/text()";
    String xPathToOrder = "/response/object[" + imageIndex + "]/Order/text()";
    String xPathToFamily = "/response/object[" + imageIndex + "]/Family/text()";
    String xPathToGenus = "/response/object[" + imageIndex + "]/Genus/text()";
    String xPathToSpecificEpithet = "/response/object[" + imageIndex + "]/SpecificEpithet/text()";
    String xPathToCountry = "/response/object[" + imageIndex + "]/Country/text()";
    String xPathToLocality = "/response/object[" + imageIndex + "]/Locality/text()";

    String identifier = null;
    String scientificName = null;
    String latitude = null;
    String longitude = null;
    String imageUrl = null;
    String license = null;
    String kingdom = null;
    String phylum = null;
    String klass = null;
    String order = null;
    String family = null;
    String genus = null;
    String specificEpithet = null;
    String country = null;
    String locality = null;

    try {
        identifier = (String) xpath.evaluate(xPathToIdentifier, currentResDom, XPathConstants.STRING);
        scientificName = (String) xpath.evaluate(xPathToScientificName, currentResDom, XPathConstants.STRING);
        latitude = (String) xpath.evaluate(xPathToLatitude, currentResDom, XPathConstants.STRING);
        longitude = (String) xpath.evaluate(xPathToLongitude, currentResDom, XPathConstants.STRING);
        imageUrl = (String) xpath.evaluate(xPathToImageUrl, currentResDom, XPathConstants.STRING);
        license = (String) xpath.evaluate(xPathToLicense, currentResDom, XPathConstants.STRING);
        kingdom = (String) xpath.evaluate(xPathToKingdom, currentResDom, XPathConstants.STRING);
        phylum = (String) xpath.evaluate(xPathToPhylum, currentResDom, XPathConstants.STRING);
        klass = (String) xpath.evaluate(xPathToClass, currentResDom, XPathConstants.STRING);
        order = (String) xpath.evaluate(xPathToOrder, currentResDom, XPathConstants.STRING);
        family = (String) xpath.evaluate(xPathToFamily, currentResDom, XPathConstants.STRING);
        genus = (String) xpath.evaluate(xPathToGenus, currentResDom, XPathConstants.STRING);
        specificEpithet = (String) xpath.evaluate(xPathToSpecificEpithet, currentResDom, XPathConstants.STRING);
        country = (String) xpath.evaluate(xPathToCountry, currentResDom, XPathConstants.STRING);
        locality = (String) xpath.evaluate(xPathToLocality, currentResDom, XPathConstants.STRING);

    } catch (XPathExpressionException getPageFragmentationError) {
        String errMsg = "Failed to obtain Morphbank's Detail Page Url";
        logger.error(errMsg);
        throw new Exception(errMsg, getPageFragmentationError);
    }

    //      System.out.println("Index: " + imageIndex);

    identifier = identifier.replaceAll("\\-svc", "");
    System.out.println(imageIndex + ", PHOTO URL:" + identifier);

    List<Triple<String, String, String>> triples = pd.getTriples();
    Map<String, String> dcs = pd.getDublinCore();

    pd.setGuid(identifier);
    pd.setContent(getContent(identifier));
    pd.setContentType(contentType);

    dcs.put(Predicates.DC_TITLE.toString(), scientificName);
    dcs.put(Predicates.DC_IDENTIFIER.toString(), identifier);
    dcs.put(Predicates.LATITUDE.toString(), latitude);
    dcs.put(Predicates.LONGITUDE.toString(), longitude);
    dcs.put(Predicates.DC_LICENSE.toString(),
            "Creative Commons Attribution-Non Commercial 3.0 Australia License, http://creativecommons.org/licenses/by-nc/3.0/au/deed.en");
    dcs.put(Predicates.DC_CREATOR.toString(), license);
    if (isCoral) {
        dcs.put(Predicates.DC_RIGHTS.toString(), "J. Veron Coral Reef Research");
    } else {
        if (license != null && !"".equals(license)) {
            dcs.put(Predicates.DC_RIGHTS.toString(), license);
        } else {
            dcs.put(Predicates.DC_RIGHTS.toString(), "Copyright by Morphbank");
        }
    }
    dcs.put(Predicates.COUNTRY.toString(), country);
    dcs.put(Predicates.LOCALITY.toString(), locality);

    triples.add(new Triple(subject, Predicates.SCIENTIFIC_NAME.toString(), scientificName));
    triples.add(new Triple(subject, Predicates.KINGDOM.toString(), kingdom));
    triples.add(new Triple(subject, Predicates.PHYLUM.toString(), phylum));
    triples.add(new Triple(subject, Predicates.CLASS.toString(), klass));
    triples.add(new Triple(subject, Predicates.ORDER.toString(), order));
    triples.add(new Triple(subject, Predicates.FAMILY.toString(), family));
    triples.add(new Triple(subject, Predicates.GENUS.toString(), genus));
    triples.add(new Triple(subject, Predicates.SPECIFIC_EPITHET.toString(), specificEpithet));

    if (imageUrl != null && !"".equals(imageUrl)) {
        imageUrl = imageUrl.replaceAll("thumb", "jpg");
        imageUrl = imageUrl.replaceAll("images\\.morphbank\\.net", "morphbank-images.ala.org.au");
        imageDoc = MappingUtils.retrieveImageDocument(pd, imageUrl);
        //         debugParsedDoc(imageDoc);
    }

    //      debugParsedDoc(pd);

    if (pd != null) {
        this.repository.storeDocument(infosourceId, pd);
    }
    if (imageDoc != null) {
        this.repository.storeDocument(infosourceId, imageDoc);
    }
}

From source file:lcmc.data.VMSXML.java

/** Returns xml node of the specified domain. */
public Node getDomainNode(final String domainName) {
    mXMLDocumentReadLock.lock();/*from  w ww  . j  av  a  2  s  .  c  om*/
    final Document document = xmlDocument;
    mXMLDocumentReadLock.unlock();
    final XPath xpath = XPathFactory.newInstance().newXPath();
    Node domainNode = null;
    try {
        final String path = "//vms/vm[@name='" + domainName + "']/config/domain";
        final NodeList domainNodes = (NodeList) xpath.evaluate(path, document, XPathConstants.NODESET);
        if (domainNodes.getLength() == 1) {
            domainNode = domainNodes.item(0);
        } else if (domainNodes.getLength() >= 1) {
            Tools.appError(domainNodes.getLength() + " supposedly unique " + domainName + " configs.");
            return null;
        } else {
            Tools.appWarning("could not find xml for " + domainName);
            return null;
        }
    } catch (final javax.xml.xpath.XPathExpressionException e) {
        Tools.appError("could not evaluate: ", e);
        return null;
    }
    return domainNode;
}