public Traffic read(Class<? extends Traffic> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException { Traffic traffic = new Traffic(); try { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputMessage.getBody()); XPathExpression titlesXp = XPathExpressionFactory.createXPathExpression("/ResultSet/Result[@type='incident']/Title"); List<Node> titles = titlesXp.evaluateAsNodeList(document); XPathExpression descXp = XPathExpressionFactory.createXPathExpression("/ResultSet/Result[@type='incident']/Description"); List<Node> description = descXp.evaluateAsNodeList(document); int counter = 0; for (Node node : titles) { traffic.addIncident(((Element)node).getTextContent(), ((Element)description.get(counter++)).getTextContent()); } } catch (Exception e) { throw new HttpMessageConversionException("Failed to convert response to: " + clazz, e); } return traffic; }
public Object evaluateXPath(XPathExpression expression, Node node) { return expression.evaluateAsNodeList(node); } };
private Object splitNode(Node node) throws ParserConfigurationException { if (this.iterator) { try { NodeList nodeList = (NodeList) this.jaxpExpression.evaluate(node, XPathConstants.NODESET); return new NodeListIterator(nodeList); } catch (XPathExpressionException e) { throw new XPathException("Could not evaluate XPath expression:" + e.getMessage(), e); } } else { List<Node> nodeList = this.xpathExpression.evaluateAsNodeList(node); if (this.createDocuments) { return convertNodesToDocuments(nodeList); } return nodeList; } }
/** Given a ReplyTo, FaultTo, or From node, returns an endpoint reference. */ private EndpointReference getEndpointReference(Node node) { if (node == null) { return null; } URI address = getUri(node, addressExpression); if (address == null) { return null; } List<Node> referenceProperties = referencePropertiesExpression != null ? referencePropertiesExpression.evaluateAsNodeList(node) : Collections.<Node>emptyList(); List<Node> referenceParameters = referenceParametersExpression != null ? referenceParametersExpression.evaluateAsNodeList(node) : Collections.<Node>emptyList(); return new EndpointReference(address, referenceProperties, referenceParameters); }
/** Given a ReplyTo, FaultTo, or From node, returns an endpoint reference. */ private EndpointReference getEndpointReference(Node node) { if (node == null) { return null; } URI address = getUri(node, addressExpression); if (address == null) { return null; } List<Node> referenceProperties = referencePropertiesExpression != null ? referencePropertiesExpression.evaluateAsNodeList(node) : Collections.<Node>emptyList(); List<Node> referenceParameters = referenceParametersExpression != null ? referenceParametersExpression.evaluateAsNodeList(node) : Collections.<Node>emptyList(); return new EndpointReference(address, referenceProperties, referenceParameters); }
/** Given a ReplyTo, FaultTo, or From node, returns an endpoint reference. */ private EndpointReference getEndpointReference(Node node) { if (node == null) { return null; } URI address = getUri(node, addressExpression); if (address == null) { return null; } List<Node> referenceProperties = referencePropertiesExpression != null ? referencePropertiesExpression.evaluateAsNodeList(node) : Collections.<Node>emptyList(); List<Node> referenceParameters = referenceParametersExpression != null ? referenceParametersExpression.evaluateAsNodeList(node) : Collections.<Node>emptyList(); return new EndpointReference(address, referenceProperties, referenceParameters); }
/** Given a ReplyTo, FaultTo, or From node, returns an endpoint reference. */ private EndpointReference getEndpointReference(Node node) { if (node == null) { return null; } URI address = getUri(node, addressExpression); if (address == null) { return null; } List<Node> referenceProperties = referencePropertiesExpression != null ? referencePropertiesExpression.evaluateAsNodeList(node) : Collections.<Node>emptyList(); List<Node> referenceParameters = referenceParametersExpression != null ? referenceParametersExpression.evaluateAsNodeList(node) : Collections.<Node>emptyList(); return new EndpointReference(address, referenceProperties, referenceParameters); }
/** * Transforms the locations of the given definition document using the given XPath expression. * @param xPathExpression the XPath expression * @param definitionDocument the definition document * @param request the request, used to determine the location to transform to */ protected void transformLocations(XPathExpression xPathExpression, Document definitionDocument, HttpServletRequest request) { Assert.notNull(xPathExpression, "'xPathExpression' must not be null"); Assert.notNull(definitionDocument, "'definitionDocument' must not be null"); Assert.notNull(request, "'request' must not be null"); List<Node> locationNodes = xPathExpression.evaluateAsNodeList(definitionDocument); for (Node locationNode : locationNodes) { if (locationNode instanceof Attr) { Attr location = (Attr) locationNode; if (StringUtils.hasLength(location.getValue())) { String newLocation = transformLocation(location.getValue(), request); if (logger.isDebugEnabled()) { logger.debug("Transforming [" + location.getValue() + "] to [" + newLocation + "]"); } location.setValue(newLocation); } } } }
/** * Transforms all <code>location</code> attributes to reflect the server name given <code>HttpServletRequest</code>. * Determines the suitable attributes by evaluating the defined XPath expression, and delegates to * <code>transformLocation</code> to do the transformation for all attributes that match. * <p/> * This method is only called when the <code>transformLocations</code> property is true. * * @see #setLocationExpression(String) * @see #setTransformLocations(boolean) * @see #transformLocation(String,javax.servlet.http.HttpServletRequest) */ protected void transformLocations(Document definitionDocument, HttpServletRequest request) throws Exception { List<Node> locationNodes = locationXPathExpression.evaluateAsNodeList(definitionDocument); for (Node locationNode : locationNodes) { if (locationNode instanceof Attr) { Attr location = (Attr) locationNode; if (StringUtils.hasLength(location.getValue())) { String newLocation = transformLocation(location.getValue(), request); if (logger.isDebugEnabled()) { logger.debug("Transforming [" + location.getValue() + "] to [" + newLocation + "]"); } location.setValue(newLocation); } } } } }
/** * Transforms the locations of the given definition document using the given XPath expression. * @param xPathExpression the XPath expression * @param definitionDocument the definition document * @param request the request, used to determine the location to transform to */ protected void transformLocations(XPathExpression xPathExpression, Document definitionDocument, HttpServletRequest request) { Assert.notNull(xPathExpression, "'xPathExpression' must not be null"); Assert.notNull(definitionDocument, "'definitionDocument' must not be null"); Assert.notNull(request, "'request' must not be null"); List<Node> locationNodes = xPathExpression.evaluateAsNodeList(definitionDocument); for (Node locationNode : locationNodes) { if (locationNode instanceof Attr) { Attr location = (Attr) locationNode; if (StringUtils.hasLength(location.getValue())) { String newLocation = transformLocation(location.getValue(), request); if (logger.isDebugEnabled()) { logger.debug("Transforming [" + location.getValue() + "] to [" + newLocation + "]"); } location.setValue(newLocation); } } } }
/** * Transforms the locations of the given definition document using the given XPath expression. * @param xPathExpression the XPath expression * @param definitionDocument the definition document * @param request the request, used to determine the location to transform to */ protected void transformLocations(XPathExpression xPathExpression, Document definitionDocument, HttpServletRequest request) { Assert.notNull(xPathExpression, "'xPathExpression' must not be null"); Assert.notNull(definitionDocument, "'definitionDocument' must not be null"); Assert.notNull(request, "'request' must not be null"); List<Node> locationNodes = xPathExpression.evaluateAsNodeList(definitionDocument); for (Node locationNode : locationNodes) { if (locationNode instanceof Attr) { Attr location = (Attr) locationNode; if (StringUtils.hasLength(location.getValue())) { String newLocation = transformLocation(location.getValue(), request); if (logger.isDebugEnabled()) { logger.debug("Transforming [" + location.getValue() + "] to [" + newLocation + "]"); } location.setValue(newLocation); } } } }