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;
}
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);
}
}
}
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;
}
}
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;
}
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;
}
Aggregations