Example usage for javax.xml.xpath XPathConstants STRING

List of usage examples for javax.xml.xpath XPathConstants STRING

Introduction

In this page you can find the example usage for javax.xml.xpath XPathConstants STRING.

Prototype

QName STRING

To view the source code for javax.xml.xpath XPathConstants STRING.

Click Source Link

Document

The XPath 1.0 string data type.

Maps to Java String .

Usage

From source file:org.glimpse.server.news.dom.DomServerNewsChannelBuilder.java

private String getAtomLink(Document doc) throws XPathExpressionException {
    XPath xpath = XPathFactory.newInstance().newXPath();
    return (String) xpath.evaluate("/feed/link[@rel='alternate']/@href", doc, XPathConstants.STRING);
}

From source file:org.jenkinsci.plugins.tibco.installation.TibcoInstallation.java

/**
 * find Tibco executable fo exec name. actually it finds only ant wrapper
 * TODO add a registry wher lookup for exec name and version
 * @param home// w  w w .  ja  v  a 2  s .c  om
 * @param execName
 * @return File executable
 */
private File findTibcoExecutable(String home, String execName) {
    String installPath = "";
    File installInfo = new File(home, "_installInfo");
    if (execName.startsWith("amx_eclipse_ant")) {

        WildcardFileFilter filter = new WildcardFileFilter("amx-design_*_prodInfo.xml");
        String[] list = installInfo.list(filter);

        javax.xml.xpath.XPathFactory xpathFactory = javax.xml.xpath.XPathFactory.newInstance();
        XPath xpath = xpathFactory.newXPath();

        try {
            //for(int i = 0; i<list.length;i++){
            InputSource source = new InputSource(new FileInputStream(new File(installInfo, list[0])));//TODO add combo with more exec version for installation
            installPath = (String) xpath.evaluate(
                    "/TIBCOInstallerFeatures/installerFeature[@name=\"sds-core\"]/assemblyList/assembly[@uid=\"product_tibco_com_tibco_amx_eclipse_ant\"]/@installLocation",
                    source, XPathConstants.STRING);
            //String execVersion= (String)xpath.evaluate("/TIBCOInstallerFeatures/installerFeature[@name=\"sds-core\"]/assemblyList/assembly[@uid=\"product_tibco_com_tibco_amx_eclipse_ant\"]/@version", source,XPathConstants.STRING);
            //TibcoExecVersion version = new TibcoExecVersion(i, installPath, execName, execVersion);
            //this.addTibcoExecVersion(version);
            //}
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (XPathExpressionException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } else {//TODO fixme it doesn't really good. i need to find a way to lookup a studio tools installation

        WildcardFileFilter filter = new WildcardFileFilter("businessevents-standard_*_prodInfo.xml");
        String[] list = installInfo.list(filter);

        javax.xml.xpath.XPathFactory xpathFactory = javax.xml.xpath.XPathFactory.newInstance();
        XPath xpath = xpathFactory.newXPath();

        try {
            //for(int i = 0; i<list.length;i++){
            installPath += getHome();
            installPath += "/";
            InputSource source = new InputSource(new FileInputStream(new File(installInfo, list[0])));
            installPath += (String) xpath.evaluate(
                    "/TIBCOInstallerFeatures/productDef[@compatDisplayName=\"TIBCO BusinessEvents\"]/@installDir",
                    source, XPathConstants.STRING);
            installPath += "/studio/bin";
            //String execVersion ="5.1";//(String)xpath.evaluate("/TIBCOInstallerFeatures/productDef/featureConfigInclude/include[@id=\"be-studio\"]/@version", source,XPathConstants.STRING);
            //TibcoExecVersion version = new TibcoExecVersion(i, installPath, execName, execVersion);
            //this.addTibcoExecVersion(version);
            //}
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (XPathExpressionException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    return new File(installPath, execName);
}

From source file:org.jfrog.build.extractor.maven.BuildInfoRecorder.java

private boolean isTestsFailed(List<File> surefireReports) {

    for (File report : surefireReports) {
        FileInputStream stream = null;
        try {/*w w  w . j a  va2 s  .  c  o m*/
            stream = new FileInputStream(report);
            setXpathPattern();
            Object evaluate = xPathExpression.evaluate(new InputSource(stream), XPathConstants.STRING);
            if (evaluate != null && StringUtils.isNotBlank(evaluate.toString())
                    && evaluate.toString().equals("true")) {
                return true;
            }
        } catch (FileNotFoundException e) {
            logger.error("File '" + report.getAbsolutePath() + "' does not exist.");
        } catch (XPathExpressionException e) {
            logger.error("Expression '/testsuite/@failures>0 or /testsuite/@errors>0' is invalid.");
        } finally {
            IOUtils.closeQuietly(stream);
        }
    }
    return false;
}

From source file:org.kuali.coeus.common.framework.krms.KcRulesEngineExecuter.java

protected String getElementValue(String docContent, String xpathExpression) {
    try {//from w w  w .ja  v a2s. co  m
        Document document = XmlHelper.trimXml(new ByteArrayInputStream(docContent.getBytes()));

        XPath xpath = XPathHelper.newXPath();
        String value = (String) xpath.evaluate(xpathExpression, document, XPathConstants.STRING);

        return value;

    } catch (Exception e) {
        throw new RiceRuntimeException(e.getMessage(), e);
    }
}

From source file:org.kuali.coeus.common.impl.krms.KcKrmsFactBuilderServiceHelper.java

protected String getElementValue(String docContent, String xpathExpression) {
    try {/* ww  w.  ja va 2s .  c  om*/
        Document document = XmlHelper.trimXml(new ByteArrayInputStream(docContent.getBytes()));

        XPath xpath = XPathHelper.newXPath();
        String value = (String) xpath.evaluate(xpathExpression, document, XPathConstants.STRING);

        return value;

    } catch (Exception e) {
        throw new RiceRuntimeException();
    }
}

From source file:org.kuali.kpme.core.document.calendar.rules.CalendarDocumentFactBuilderServiceImpl.java

protected String getElementValue(String docContent, String xpathExpression) {
    try {/*from  ww  w. j  av  a  2 s . c o  m*/
        Document document = XmlHelper.trimXml(new ByteArrayInputStream(docContent.getBytes()));

        XPath xpath = XPathHelper.newXPath();
        String value = (String) xpath.evaluate(xpathExpression, document, XPathConstants.STRING);

        return value;

    } catch (Exception e) {
        throw new RiceRuntimeException(e);
    }
}

From source file:org.kuali.kpme.core.payroll.service.PayrollPeopleFlowTypeServiceImpl.java

protected String getElementValue(String docContent, String xpathExpression) {
    try {/*from w  ww . j ava 2  s.c  o  m*/
        org.w3c.dom.Document document = XmlHelper.trimXml(new ByteArrayInputStream(docContent.getBytes()));

        XPath xpath = XPathHelper.newXPath();
        return (String) xpath.evaluate(xpathExpression, document, XPathConstants.STRING);

    } catch (Exception e) {
        throw new RiceRuntimeException();
    }
}

From source file:org.kuali.rice.edl.framework.workflow.EDocLitePostProcessor.java

private static String getURL(Document edlDoc) throws XPathExpressionException {
    XPath xpath = XPathFactory.newInstance().newXPath();
    return (String) xpath.evaluate("//edlContent/edl/eventNotificationURL", edlDoc, XPathConstants.STRING);
}

From source file:org.kuali.rice.edl.impl.components.NoteConfigComponent.java

public void saveNote(NoteForm form, EDLContext edlContext, Document dom) throws Exception {
    Note noteToSave = null;// w  ww.  jav  a2s.c  o m
    if (form.getShowEdit() != null && form.getShowEdit().equals("yes")) {
        //LOG.debug(form.getNoteIdNumber());
        noteToSave = getNoteService().getNoteByNoteId(form.getNoteIdNumber());
        String noteText = form.getNoteText();
        if (noteText != null) {
            noteToSave.setNoteText(noteText);
        }
        //LOG.debug(noteToSave);
        //LOG.debug(noteToSave.getNoteCreateDate());
        //noteToSave.setNoteCreateDate(new Timestamp(noteToSave.getNoteCreateLongDate().longValue()));
    } else {
        noteToSave = new Note();
        noteToSave.setNoteId(null);
        noteToSave.setDocumentId(form.getDocId());
        noteToSave.setNoteCreateDate(new Timestamp((new Date()).getTime()));
        noteToSave.setNoteAuthorWorkflowId(edlContext.getUserSession().getPrincipalId());
        noteToSave.setNoteText(form.getAddText());
    }
    CustomNoteAttribute customNoteAttribute = null;
    DocumentRouteHeaderValue routeHeader = getRouteHeaderService().getRouteHeader(noteToSave.getDocumentId());
    boolean canEditNote = false;
    boolean canAddNotes = false;
    if (routeHeader != null) {
        customNoteAttribute = routeHeader.getCustomNoteAttribute();
        if (customNoteAttribute != null) {
            customNoteAttribute.setUserSession(edlContext.getUserSession());
            canAddNotes = customNoteAttribute.isAuthorizedToAddNotes();
            canEditNote = customNoteAttribute.isAuthorizedToEditNote(noteToSave);
        }
    }
    if ((form.getShowEdit() != null && form.getShowEdit().equals("yes") && canEditNote)
            || ((form.getShowEdit() == null || !form.getShowEdit().equals("yes")) && canAddNotes)) {
        FileItem uploadedFile = (FileItem) form.getFile();
        if (uploadedFile != null && org.apache.commons.lang.StringUtils.isNotBlank(uploadedFile.getName())) {
            Attachment attachment = new Attachment();
            attachment.setAttachedObject(uploadedFile.getInputStream());
            String internalFileIndicator = uploadedFile.getName();
            int indexOfSlash = internalFileIndicator.lastIndexOf("/");
            int indexOfBackSlash = internalFileIndicator.lastIndexOf("\\");
            if (indexOfSlash >= 0) {
                internalFileIndicator = internalFileIndicator.substring(indexOfSlash + 1);
            } else {
                if (indexOfBackSlash >= 0) {
                    internalFileIndicator = internalFileIndicator.substring(indexOfBackSlash + 1);
                }
            }
            attachment.setFileName(internalFileIndicator);
            LOG.debug(internalFileIndicator);
            attachment.setMimeType(uploadedFile.getContentType());
            attachment.setNote(noteToSave);
            noteToSave.getAttachments().add(attachment);
        }
        if (org.apache.commons.lang.StringUtils.isEmpty(noteToSave.getNoteText())
                && noteToSave.getAttachments().size() == 0) {
            if (form.getShowEdit() != null && form.getShowEdit().equals("yes")) {
                form.setNote(new Note());
            } else {
                form.setAddText(null);
            }
            form.setShowEdit("no");
            form.setNoteIdNumber(null);
            //              throw new Exception("Note has empty content");
            EDLXmlUtils.addGlobalErrorMessage(dom, "Note has empty content");
            return;
        }
        getNoteService().saveNote(noteToSave);

        // add ability to send emails when a note is saved. 
        boolean sendEmailOnNoteSave = false;
        // Check if edoclite specifies <param name="sendEmailOnNoteSave">
        Document edlDom = EdlServiceLocator.getEDocLiteService()
                .getDefinitionXml(edlContext.getEdocLiteAssociation());
        XPath xpath = edlContext.getXpath();
        String xpathExpression = "//config/param[@name='sendEmailOnNoteSave']";
        try {
            String match = (String) xpath.evaluate(xpathExpression, edlDom, XPathConstants.STRING);
            if (!StringUtils.isBlank(match) && match.equals("true")) {
                sendEmailOnNoteSave = true;
            }
        } catch (XPathExpressionException e) {
            throw new WorkflowRuntimeException(
                    "Unable to evaluate sendEmailOnNoteSave xpath expression in NoteConfigComponent saveNote method"
                            + xpathExpression,
                    e);
        }

        if (sendEmailOnNoteSave) {
            xpathExpression = "//data/version[@current='true']/field[@name='emailTo']/value";
            String emailTo = xpath.evaluate(xpathExpression, dom);
            if (StringUtils.isBlank(emailTo)) {
                EDLXmlUtils.addGlobalErrorMessage(dom,
                        "No email notifications were sent because EmailTo field was empty.");
                return;
            }
            // Actually send the emails.
            if (isProduction()) {
                this.to = stringToList(emailTo);
            } else {
                String testAddress = getTestAddress(edlDom);
                if (StringUtils.isBlank(testAddress)) {
                    EDLXmlUtils.addGlobalErrorMessage(dom,
                            "No email notifications were sent because testAddress edl param was empty or not specified in a non production environment");
                    return;
                }
                this.to = stringToList(getTestAddress(edlDom));
            }
            if (!isEmailListValid(this.to)) {
                EDLXmlUtils.addGlobalErrorMessage(dom,
                        "No email notifications were sent because emailTo field contains invalid email address.");
                return;
            }
            String noteEmailStylesheet = "";
            xpathExpression = "//config/param[@name='noteEmailStylesheet']";
            try {
                noteEmailStylesheet = (String) xpath.evaluate(xpathExpression, edlDom, XPathConstants.STRING);
                if (StringUtils.isBlank(noteEmailStylesheet)) {
                    EDLXmlUtils.addGlobalErrorMessage(dom,
                            "No email notifications were sent because noteEmailStylesheet edl param was empty or not specified.");
                    return;
                }
            } catch (XPathExpressionException e) {
                throw new WorkflowRuntimeException(
                        "Unable to evaluate noteEmailStylesheet xpath expression in NoteConfigComponent method"
                                + xpathExpression,
                        e);
            }
            this.styleName = noteEmailStylesheet;
            this.from = DEFAULT_EMAIL_FROM_ADDRESS;
            Document document = generateXmlInput(form, edlContext, edlDom);
            if (LOG.isDebugEnabled()) {
                LOG.debug("XML input for email tranformation:\n" + XmlJotter.jotNode(document));
            }
            Templates style = loadStyleSheet(styleName);
            EmailContent emailContent = emailStyleHelper.generateEmailContent(style, document);
            if (!this.to.isEmpty()) {
                CoreApiServiceLocator.getMailer().sendEmail(new EmailFrom(from), new EmailToList(this.to),
                        new EmailSubject(emailContent.getSubject()), new EmailBody(emailContent.getBody()),
                        new EmailCcList(this.cc), new EmailBcList(this.bc), emailContent.isHtml());
            }
        }

    }
    if (form.getShowEdit() != null && form.getShowEdit().equals("yes")) {
        form.setNote(new Note());
    } else {
        form.setAddText(null);
    }
    form.setShowEdit("no");
    form.setNoteIdNumber(null);
}

From source file:org.kuali.rice.edl.impl.components.NoteConfigComponent.java

protected String getTestAddress(Document edlDom) {
    String testAddress = "";
    XPath xpath = XPathFactory.newInstance().newXPath();
    String xpathExpression = "//config/param[@name='testAddress']";
    try {/*from w w w.ja  va 2  s .c o m*/
        testAddress = (String) xpath.evaluate(xpathExpression, edlDom, XPathConstants.STRING);
    } catch (XPathExpressionException e) {
        throw new WorkflowRuntimeException(
                "Unable to evaluate testAddressAttributeFound xpath expression in NoteConfigComponent getTestAddress method"
                        + xpathExpression,
                e);
    }
    return testAddress;
}