Search in sources :

Example 96 with XPathExpressionException

use of javax.xml.xpath.XPathExpressionException in project opennms by OpenNMS.

the class AbstractXmlCollectionHandler method getTimeStamp.

/**
     * Gets the time stamp.
     * 
     * @param doc the doc
     * @param xpath the xpath
     * @param group the group
     * @return the time stamp
     * @throws XPathExpressionException the x path expression exception
     */
protected Date getTimeStamp(Document doc, XPath xpath, XmlGroup group) throws XPathExpressionException {
    if (group.getTimestampXpath() == null) {
        return null;
    }
    String pattern = group.getTimestampFormat() == null ? "yyyy-MM-dd HH:mm:ss" : group.getTimestampFormat();
    LOG.debug("getTimeStamp: retrieving custom timestamp to be used when updating RRDs using XPATH {} and pattern {}", group.getTimestampXpath(), pattern);
    Node tsNode = (Node) xpath.evaluate(group.getTimestampXpath(), doc, XPathConstants.NODE);
    if (tsNode == null) {
        LOG.warn("getTimeStamp: can't find the custom timestamp using XPATH {}", group.getTimestampXpath());
        return null;
    }
    Date date = null;
    String value = tsNode.getNodeValue() == null ? tsNode.getTextContent() : tsNode.getNodeValue();
    LOG.debug("getTimeStamp: time stamp value is {}", value);
    try {
        DateTimeFormatter dtf = DateTimeFormat.forPattern(pattern);
        DateTime dateTime = dtf.parseDateTime(value);
        date = dateTime.toDate();
    } catch (Exception e) {
        LOG.warn("getTimeStamp: can't convert custom timetime {} using pattern {}", value, pattern);
    }
    return date;
}
Also used : Node(org.w3c.dom.Node) OnmsNode(org.opennms.netmgt.model.OnmsNode) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) Date(java.util.Date) DateTime(org.joda.time.DateTime) XPathExpressionException(javax.xml.xpath.XPathExpressionException) CollectionException(org.opennms.netmgt.collection.api.CollectionException) ParseException(java.text.ParseException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException)

Example 97 with XPathExpressionException

use of javax.xml.xpath.XPathExpressionException in project OpenAM by OpenRock.

the class SchemaResourceNamesStep method perform.

@Override
public void perform() throws UpgradeException {
    for (Map.Entry<String, Function<Document, Boolean, XPathExpressionException>> service : serviceModifications.entrySet()) {
        try {
            long startTime = System.currentTimeMillis();
            UpgradeProgress.reportStart(PROGRESS, service.getKey());
            DEBUG.message("Found resource names for {}. Applying now.", service.getKey());
            new ServiceSchemaManager(service.getKey(), getAdminToken()).modifySchema(service.getValue());
            DEBUG.message("Completed ({}ms)", System.currentTimeMillis() - startTime);
            UpgradeProgress.reportEnd("upgrade.success");
        } catch (XPathExpressionException | SMSException | SSOException e) {
            throw new UpgradeException(e);
        }
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) Function(org.forgerock.util.Function) SMSException(com.sun.identity.sm.SMSException) XPathExpressionException(javax.xml.xpath.XPathExpressionException) SSOException(com.iplanet.sso.SSOException) HashMap(java.util.HashMap) Map(java.util.Map) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager)

Example 98 with XPathExpressionException

use of javax.xml.xpath.XPathExpressionException in project Activiti by Activiti.

the class ProcessDiagramLayoutFactory method fixFlowNodePositionsIfModelFromAdonis.

protected Map<String, DiagramNode> fixFlowNodePositionsIfModelFromAdonis(Document bpmnModel, Map<String, DiagramNode> elementBoundsFromBpmnDi) {
    if (isExportedFromAdonis50(bpmnModel)) {
        Map<String, DiagramNode> mapOfFixedBounds = new HashMap<String, DiagramNode>();
        XPathFactory xPathFactory = XPathFactory.newInstance();
        XPath xPath = xPathFactory.newXPath();
        xPath.setNamespaceContext(new Bpmn20NamespaceContext());
        for (Entry<String, DiagramNode> entry : elementBoundsFromBpmnDi.entrySet()) {
            String elementId = entry.getKey();
            DiagramNode elementBounds = entry.getValue();
            String expression = "local-name(//bpmn:*[@id = '" + elementId + "'])";
            try {
                XPathExpression xPathExpression = xPath.compile(expression);
                String elementLocalName = xPathExpression.evaluate(bpmnModel);
                if (!"participant".equals(elementLocalName) && !"lane".equals(elementLocalName) && !"textAnnotation".equals(elementLocalName) && !"group".equals(elementLocalName)) {
                    elementBounds.setX(elementBounds.getX() - elementBounds.getWidth() / 2);
                    elementBounds.setY(elementBounds.getY() - elementBounds.getHeight() / 2);
                }
            } catch (XPathExpressionException e) {
                throw new ActivitiException("Error while evaluating the following XPath expression on a BPMN XML document: '" + expression + "'.", e);
            }
            mapOfFixedBounds.put(elementId, elementBounds);
        }
        return mapOfFixedBounds;
    } else {
        return elementBoundsFromBpmnDi;
    }
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpression(javax.xml.xpath.XPathExpression) XPathFactory(javax.xml.xpath.XPathFactory) DiagramNode(org.activiti.engine.repository.DiagramNode) ActivitiException(org.activiti.engine.ActivitiException) HashMap(java.util.HashMap) XPathExpressionException(javax.xml.xpath.XPathExpressionException)

Example 99 with XPathExpressionException

use of javax.xml.xpath.XPathExpressionException in project Asqatasun by Asqatasun.

the class HeritrixAttributeValueModifier method modifyDocument.

@Override
public Document modifyDocument(Document document, String value) {
    if (value == null || value.isEmpty()) {
        LOGGER.debug(" value is empty " + this.getClass());
        return document;
    }
    try {
        Node parentNode = getNodeFromXpath(document);
        NamedNodeMap attr = parentNode.getAttributes();
        Node nodeAttr = attr.getNamedItem(DEFAULT_ATTRIBUTE_NAME);
        if (StringUtils.isNotEmpty(value)) {
            nodeAttr.setTextContent(value);
        } else {
            parentNode.getParentNode().removeChild(parentNode);
        }
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Update " + getAttributeValue() + " attribute of bean " + getIdBeanParent() + " with value " + value);
        }
    } catch (XPathExpressionException ex) {
        LOGGER.warn(ex);
    }
    return document;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) XPathExpressionException(javax.xml.xpath.XPathExpressionException) Node(org.w3c.dom.Node)

Example 100 with XPathExpressionException

use of javax.xml.xpath.XPathExpressionException in project Asqatasun by Asqatasun.

the class HeritrixAttributeValueModifierAndEraser method modifyDocument.

@Override
public Document modifyDocument(Document document, String value) {
    try {
        Node parentNode = getNodeFromXpath(document);
        NamedNodeMap attr = parentNode.getAttributes();
        Node nodeAttr = attr.getNamedItem(DEFAULT_ATTRIBUTE_NAME);
        if (StringUtils.isNotEmpty(value)) {
            nodeAttr.setTextContent(value);
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Update " + getAttributeValue() + " attribute of bean " + getIdBeanParent() + " with value " + value);
            }
        } else {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Delete " + getAttributeValue() + " attribute of bean " + getIdBeanParent() + " because of null or empty value ");
            }
            parentNode.getParentNode().removeChild(parentNode);
        }
    } catch (XPathExpressionException ex) {
        Logger.getLogger(HeritrixParameterValueModifier.class.getName()).warn(ex);
    }
    return document;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) XPathExpressionException(javax.xml.xpath.XPathExpressionException) Node(org.w3c.dom.Node)

Aggregations

XPathExpressionException (javax.xml.xpath.XPathExpressionException)139 NodeList (org.w3c.dom.NodeList)65 XPath (javax.xml.xpath.XPath)64 Document (org.w3c.dom.Document)46 Node (org.w3c.dom.Node)46 IOException (java.io.IOException)42 XPathExpression (javax.xml.xpath.XPathExpression)38 SAXException (org.xml.sax.SAXException)27 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)25 XPathFactory (javax.xml.xpath.XPathFactory)23 ArrayList (java.util.ArrayList)22 HashMap (java.util.HashMap)18 Test (org.junit.Test)17 InputSource (org.xml.sax.InputSource)17 Element (org.w3c.dom.Element)16 Response (com.jayway.restassured.response.Response)12 ValidatableResponse (com.jayway.restassured.response.ValidatableResponse)12 DocumentBuilder (javax.xml.parsers.DocumentBuilder)12 AbstractIntegrationTest (org.codice.ddf.itests.common.AbstractIntegrationTest)12 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)11