Mercurial > dive4elements > river
diff flys-client/src/main/java/de/intevation/flys/client/server/DescribeCollectionServiceImpl.java @ 581:210339fd1a34
Removed more expensive XPath.
flys-client/trunk@2169 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 20 Jun 2011 16:25:48 +0000 |
parents | 5277f46a63c2 |
children | 78907f0fb939 |
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/server/DescribeCollectionServiceImpl.java Mon Jun 20 10:32:54 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/DescribeCollectionServiceImpl.java Mon Jun 20 16:25:48 2011 +0000 @@ -113,22 +113,16 @@ "art:artifact-collection/@art:uuid", ArtifactNamespaceContext.INSTANCE); - if (uuid == null || uuid.equals("")) { + if (uuid == null || uuid.length() == 0) { System.err.println("Found an invalid Collection!"); return null; } Map<String, ThemeList> themeList = parseThemeLists(description); - Collection c = null; - - if (themeList != null) { - c = new DefaultCollection(uuid, themeList); - //c = new DefaultCollection(uuid); - } - else { - c = new DefaultCollection(uuid); - } + Collection c = !themeList.isEmpty() + ? new DefaultCollection(uuid, themeList) + : new DefaultCollection(uuid); NodeList items = (NodeList) XMLUtils.xpath( description, @@ -145,7 +139,7 @@ int size = items.getLength(); for (int i = 0; i < size; i++) { - CollectionItem item = parseCollectionItem(items.item(i)); + CollectionItem item = parseCollectionItem((Element)items.item(i)); if (item != null) { c.addItem(item); @@ -173,16 +167,18 @@ Map<String, ThemeList> themeList = new HashMap<String, ThemeList>(num); - for (int i = 0; i < num; i++) { - Node node = lists.item(i); + String uri = ArtifactNamespaceContext.NAMESPACE_URI; - String outName = XMLUtils.xpathString( - node, "@name", ArtifactNamespaceContext.INSTANCE); + for (int i = 0; i < num; i++) { + Element node = (Element)lists.item(i); - ThemeList list = parseThemeList(node); + String outName = node.getAttribute("name"); - if (list != null) { - themeList.put(outName, list); + if (outName.length() > 0) { + ThemeList list = parseThemeList(node); + if (list.getThemeCount() > 0) { + themeList.put(outName, list); + } } } @@ -190,21 +186,19 @@ } - protected ThemeList parseThemeList(Node node) { + protected ThemeList parseThemeList(Element node) { System.out.println("DescribeCollectionServiceImpl.parseThemeList"); - NodeList themes = (NodeList) XMLUtils.xpath( - node, - "art:theme", - XPathConstants.NODESET, - ArtifactNamespaceContext.INSTANCE); + NodeList themes = node.getElementsByTagNameNS( + ArtifactNamespaceContext.NAMESPACE_URI, + "theme"); int num = themes != null ? themes.getLength() : 0; List<Theme> themeList = new ArrayList<Theme>(num); for (int i = 0; i < num; i++) { - Theme theme = parseTheme((Element) themes.item(i)); + Theme theme = parseTheme((Element)themes.item(i)); if (theme != null) { themeList.add(theme); @@ -227,8 +221,8 @@ String desc = ele.getAttributeNS(uri, "description"); String strIdx = ele.getAttributeNS(uri, "index"); - if (strAct != null && art != null && fac != null - && strPos != null && strIdx != null) + if (strAct.length() > 0 && art.length() > 0 && fac.length() > 0 + && strPos.length() > 0 && strIdx.length() > 0) { try { int pos = Integer.valueOf(strPos); @@ -254,7 +248,7 @@ * * @return a CollectionItem. */ - protected CollectionItem parseCollectionItem(Node node) { + protected CollectionItem parseCollectionItem(Element node) { System.out.println("AddArtifactServiceImpl.parseCollectionItem"); if (node == null) { @@ -262,23 +256,25 @@ return null; } - String uuid = XMLUtils.xpathString( - node, "@art:uuid", ArtifactNamespaceContext.INSTANCE); + String uri = ArtifactNamespaceContext.NAMESPACE_URI; - String hash = XMLUtils.xpathString( - node, "@art:hash", ArtifactNamespaceContext.INSTANCE); + String uuid = node.getAttributeNS(uri, "uuid"); + String hash = node.getAttributeNS(uri, "hash"); - if (uuid == null || uuid.equals("")) { + if (uuid.length() == 0) { System.err.println("Found an invalid CollectionItem!"); + return null; } - Node outputmodes = (Node) XMLUtils.xpath( - node, - "art:outputmodes", - XPathConstants.NODE, - ArtifactNamespaceContext.INSTANCE); + NodeList outputmodes = node.getElementsByTagNameNS(uri, "outputmodes"); - List<OutputMode> modes = parseOutputModes(outputmodes); + if (outputmodes.getLength() < 1) { + return null; + } + + Element om = (Element)outputmodes.item(0); + + List<OutputMode> modes = parseOutputModes(om); return new DefaultCollectionItem(uuid, hash, modes); } @@ -292,7 +288,7 @@ * * @return a list of OutputModes. */ - protected List<OutputMode> parseOutputModes(Node node) { + protected List<OutputMode> parseOutputModes(Element node) { System.out.println("AddArtifactServiceImpl.parseOutputModes"); if (node == null) { @@ -300,33 +296,28 @@ return null; } - NodeList list = (NodeList) XMLUtils.xpath( - node, - "art:output", - XPathConstants.NODESET, - ArtifactNamespaceContext.INSTANCE); + String uri = ArtifactNamespaceContext.NAMESPACE_URI; - if (list == null || list.getLength() == 0) { + NodeList list = node.getElementsByTagNameNS(uri, "output"); + + int size = list.getLength(); + + if (size == 0) { System.err.println("No outputmode nodes found!"); return null; } - int size = list.getLength(); - List<OutputMode> modes = new ArrayList<OutputMode>(size); for (int i = 0; i < size; i++) { - Node tmp = list.item(i); - String name = XMLUtils.xpathString( - tmp, "@art:name", ArtifactNamespaceContext.INSTANCE); - String desc = XMLUtils.xpathString( - tmp, "@art:description", ArtifactNamespaceContext.INSTANCE); - String mime = XMLUtils.xpathString( - tmp, "@art:mime-type", ArtifactNamespaceContext.INSTANCE); + Element tmp = (Element)list.item(i); - if (name == null || name.equals("")) { + String name = tmp.getAttributeNS(uri, "name"); + String desc = tmp.getAttributeNS(uri, "description"); + String mime = tmp.getAttributeNS(uri, "mime-type"); + + if (name.length() == 0) { System.err.println("Found an invalid output mode."); - continue; } @@ -347,7 +338,7 @@ } - protected static List<Facet> extractFacets(Node outmode) { + protected static List<Facet> extractFacets(Element outmode) { System.out.println("ArtifactDescriptionFactory - extractFacets()"); NodeList facetList = (NodeList) XMLUtils.xpath(