# HG changeset patch # User Raimund Renkert # Date 1331890349 0 # Node ID 226c360febaeb1a49f1ef7a1b6eafffff9ae4864 # Parent fafc9247fe06231482768da14a5d717d119f94f9 Remove unnecessary outputs from attributes instead of copying outs to new attribute element. flys-artifacts/trunk@4156 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r fafc9247fe06 -r 226c360febae flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Fri Mar 16 07:12:40 2012 +0000 +++ b/flys-artifacts/ChangeLog Fri Mar 16 09:32:29 2012 +0000 @@ -1,3 +1,9 @@ +2012-03-16 Raimund Renkert + + * src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java: + Remove unnecessary outputs from attributes instead of copying outs to + new attribute element. + 2012-03-16 Ingo Weinzierl * Tagged module as 'pre2.7-2012-03-16'. diff -r fafc9247fe06 -r 226c360febae flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java --- a/flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java Fri Mar 16 07:12:40 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java Fri Mar 16 09:32:29 2012 +0000 @@ -149,36 +149,40 @@ protected Document removeAttributes(Document attrs, CallContext context) { + Node outs = (Node) XMLUtils.xpath( + attrs, + "/art:attribute/art:outputs", + XPathConstants.NODE, + ArtifactNamespaceContext.INSTANCE); + + NodeList nodes = (NodeList) XMLUtils.xpath( + attrs, + "/art:attribute/art:outputs/art:output", + XPathConstants.NODESET, + ArtifactNamespaceContext.INSTANCE); + + if (nodes != null) { + for (int i = 0; i < nodes.getLength(); i++) { + Element e = (Element)nodes.item(i); + if(!outputExists(e.getAttribute("name"), context)) { + outs.removeChild(e); + } + } + } + return attrs; + } + + + protected boolean outputExists(String name, CallContext context) { FLYSArtifact master = getMasterArtifact(context); List outList = master.getOutputs(context); - Document doc = XMLUtils.newDocument(); - XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( - doc, - ArtifactNamespaceContext.NAMESPACE_URI, - ArtifactNamespaceContext.NAMESPACE_PREFIX); - - Element root = ec.create("attribute"); - doc.appendChild(root); - - if (outList.size() > 0) { - Element outs = ec.create("outputs"); - root.appendChild(outs); - - for (Output o : outList) { - Node n = (Node) XMLUtils.xpath( - attrs, - "/art:attribute/art:outputs/art:output[@name='" + o.getName() + "']", - XPathConstants.NODE, - ArtifactNamespaceContext.INSTANCE); - if (n != null) { - Node clone = doc.importNode(n, true); - outs.appendChild(clone); - } + for (Output o : outList) { + if (name.equals(o.getName())) { + return true; } } - - return doc; + return false; } /**