# HG changeset patch # User Sascha L. Teichmann # Date 1308068899 0 # Node ID c7301a701da9f953389e7a5e119937632e0b465f # Parent 1d20533a4ae3e659bb7e29de7ff153af8e718671 DistanceInfoService: Got rid of namespace. Use DOM instead of XPath. flys-client/trunk@2118 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 1d20533a4ae3 -r c7301a701da9 flys-client/ChangeLog --- a/flys-client/ChangeLog Tue Jun 14 15:46:31 2011 +0000 +++ b/flys-client/ChangeLog Tue Jun 14 16:28:19 2011 +0000 @@ -1,3 +1,8 @@ +2011-06-14 Sascha L. Teichmann + + * src/main/java/de/intevation/flys/client/server/DistanceInfoServiceImpl.java: + Got rid of namespace. Use DOM instead of XPath. + 2011-06-14 Sascha L. Teichmann * src/main/java/de/intevation/flys/client/shared/model/DistanceInfoRecord.java: diff -r 1d20533a4ae3 -r c7301a701da9 flys-client/src/main/java/de/intevation/flys/client/server/DistanceInfoServiceImpl.java --- a/flys-client/src/main/java/de/intevation/flys/client/server/DistanceInfoServiceImpl.java Tue Jun 14 15:46:31 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/DistanceInfoServiceImpl.java Tue Jun 14 16:28:19 2011 +0000 @@ -89,15 +89,10 @@ protected DistanceInfoObject[] extractDistanceInfoObjects(Document result) throws ServerException { - NodeList list = (NodeList) XMLUtils.xpath( - result, - XPATH_DISTANCES, - XPathConstants.NODESET, - ArtifactNamespaceContext.INSTANCE); + NodeList list = result.getElementsByTagName("distance"); if (list == null || list.getLength() == 0) { System.err.println("No distance info found."); - throw new ServerException(ERROR_NO_DISTANCEINFO_FOUND); } @@ -108,7 +103,8 @@ new ArrayList(num); for (int i = 0; i < num; i++) { - DistanceInfoObject obj = buildDistanceInfoObject(list.item(i)); + DistanceInfoObject obj = buildDistanceInfoObject( + (Element)list.item(i)); if (obj != null) { objects.add(obj); @@ -130,43 +126,21 @@ * * @return a valid DistanceInfoObject. */ - protected DistanceInfoObject buildDistanceInfoObject(Node node) { - - // XXX: Using XPath here is much too expensive. DOM will do! - - String desc = XMLUtils.xpathString( - node, "@art:description", ArtifactNamespaceContext.INSTANCE); - - String from = XMLUtils.xpathString( - node, "@art:from", ArtifactNamespaceContext.INSTANCE); - - String to = XMLUtils.xpathString( - node, "@art:to", ArtifactNamespaceContext.INSTANCE); - - String riverside = XMLUtils.xpathString( - node, "@art:riverside", ArtifactNamespaceContext.INSTANCE); + protected DistanceInfoObject buildDistanceInfoObject(Element node) { - String bottom = XMLUtils.xpathString( - node, "@art:bottom", ArtifactNamespaceContext.INSTANCE); - - String top = XMLUtils.xpathString( - node, "@art:top", ArtifactNamespaceContext.INSTANCE); - - if (desc != null && from != null) { - try { - Double f = new Double(from); + String desc = node.getAttribute("description").trim(); + String from = node.getAttribute("from").trim(); + String to = node.getAttribute("to").trim(); + String riverside = node.getAttribute("riverside").trim(); + String bottom = node.getAttribute("bottom").trim(); + String top = node.getAttribute("top").trim(); - Double t = to != null && (to=to.trim()).length() > 0 - ? new Double(to) - : null; - - Double tp = top != null && (top=top.trim()).length() > 0 - ? new Double(top) - : null; - - Double b = bottom != null && (bottom=bottom.trim()).length() > 0 - ? new Double(bottom) - : null; + if (desc.length() > 0 && from.length() > 0) { + try { + Double f = new Double(from); + Double t = to .length() > 0 ? new Double(to) : null; + Double b = bottom.length() > 0 ? new Double(bottom) : null; + Double tp = top .length() > 0 ? new Double(top) : null; return new DistanceInfoObjectImpl(desc, f, t, riverside, b, tp); }