Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java @ 2594:226c360febae
Remove unnecessary outputs from attributes instead of copying outs to
new attribute element.
flys-artifacts/trunk@4156 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Fri, 16 Mar 2012 09:32:29 +0000 |
parents | a71fc8f2030c |
children | 306b9d0f0fb3 |
comparison
equal
deleted
inserted
replaced
2593:fafc9247fe06 | 2594:226c360febae |
---|---|
147 return cAttribute; | 147 return cAttribute; |
148 } | 148 } |
149 | 149 |
150 | 150 |
151 protected Document removeAttributes(Document attrs, CallContext context) { | 151 protected Document removeAttributes(Document attrs, CallContext context) { |
152 Node outs = (Node) XMLUtils.xpath( | |
153 attrs, | |
154 "/art:attribute/art:outputs", | |
155 XPathConstants.NODE, | |
156 ArtifactNamespaceContext.INSTANCE); | |
157 | |
158 NodeList nodes = (NodeList) XMLUtils.xpath( | |
159 attrs, | |
160 "/art:attribute/art:outputs/art:output", | |
161 XPathConstants.NODESET, | |
162 ArtifactNamespaceContext.INSTANCE); | |
163 | |
164 if (nodes != null) { | |
165 for (int i = 0; i < nodes.getLength(); i++) { | |
166 Element e = (Element)nodes.item(i); | |
167 if(!outputExists(e.getAttribute("name"), context)) { | |
168 outs.removeChild(e); | |
169 } | |
170 } | |
171 } | |
172 return attrs; | |
173 } | |
174 | |
175 | |
176 protected boolean outputExists(String name, CallContext context) { | |
152 FLYSArtifact master = getMasterArtifact(context); | 177 FLYSArtifact master = getMasterArtifact(context); |
153 List<Output> outList = master.getOutputs(context); | 178 List<Output> outList = master.getOutputs(context); |
154 | 179 |
155 Document doc = XMLUtils.newDocument(); | 180 for (Output o : outList) { |
156 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( | 181 if (name.equals(o.getName())) { |
157 doc, | 182 return true; |
158 ArtifactNamespaceContext.NAMESPACE_URI, | 183 } |
159 ArtifactNamespaceContext.NAMESPACE_PREFIX); | 184 } |
160 | 185 return false; |
161 Element root = ec.create("attribute"); | |
162 doc.appendChild(root); | |
163 | |
164 if (outList.size() > 0) { | |
165 Element outs = ec.create("outputs"); | |
166 root.appendChild(outs); | |
167 | |
168 for (Output o : outList) { | |
169 Node n = (Node) XMLUtils.xpath( | |
170 attrs, | |
171 "/art:attribute/art:outputs/art:output[@name='" + o.getName() + "']", | |
172 XPathConstants.NODE, | |
173 ArtifactNamespaceContext.INSTANCE); | |
174 if (n != null) { | |
175 Node clone = doc.importNode(n, true); | |
176 outs.appendChild(clone); | |
177 } | |
178 } | |
179 } | |
180 | |
181 return doc; | |
182 } | 186 } |
183 | 187 |
184 /** | 188 /** |
185 * @param db The ArtifactDatabase which is required to save the attribute | 189 * @param db The ArtifactDatabase which is required to save the attribute |
186 * into. | 190 * into. |