Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/meta/Builder.java @ 963:f48cef242e7f
Datacage: recommendation mechanism now accepts nodes to append results.
flys-artifacts/trunk@2382 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 20 Jul 2011 22:03:50 +0000 |
parents | 2de1808503be |
children | 0c8aca463bd4 |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/meta/Builder.java Wed Jul 20 20:51:13 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/meta/Builder.java Wed Jul 20 22:03:50 2011 +0000 @@ -39,15 +39,22 @@ protected Document template; + protected static Document getOwnerDocument(Node node) { + Document document = node.getOwnerDocument(); + return document != null ? document : (Document)node; + } + + public class BuildHelper { - protected Document output; + protected Node output; + protected Document owner; protected StackFrames frames; protected Connection connection; protected Map<String, CompiledStatement> statements; public BuildHelper( - Document output, + Node output, Connection connection, Map<String, Object> parameters ) { @@ -55,6 +62,7 @@ this.connection = connection; frames = new StackFrames(parameters); statements = new HashMap<String, CompiledStatement>(); + owner = getOwnerDocument(output); } public void build(List<Node> elements) throws SQLException { @@ -146,7 +154,7 @@ return; } - Element element = output.createElement(attr); + Element element = owner.createElement(attr); NodeList children = current.getChildNodes(); for (int i = 0, N = children.getLength(); i < N; ++i) { @@ -161,7 +169,7 @@ { log.debug("dc:text"); String value = expand(current.getTextContent()); - parent.appendChild(output.createTextNode(value)); + parent.appendChild(owner.createTextNode(value)); } @@ -368,7 +376,7 @@ } } - Node copy = output.importNode(current, false); + Node copy = owner.importNode(current, false); NodeList children = current.getChildNodes(); for (int i = 0, N = children.getLength(); i < N; ++i) { @@ -386,23 +394,7 @@ this.template = template; } - public Document build(Connection connection) - throws SQLException - { - return build(connection, XMLUtils.newDocument(), null); - } - - public Document build( - Connection connection, - Document output, - Map<String, Object> parameters - ) - throws SQLException - { - NodeList roots = template.getElementsByTagNameNS( - DC_NAMESPACE_URI, "template"); - - BuildHelper helper = new BuildHelper(output, connection, parameters); + protected static List<Node> rootsToList(NodeList roots) { List<Node> elements = new ArrayList<Node>(); @@ -415,9 +407,23 @@ } } } - helper.build(elements); - return output; + return elements; + } + + public void build( + Connection connection, + Node output, + Map<String, Object> parameters + ) + throws SQLException + { + BuildHelper helper = new BuildHelper(output, connection, parameters); + + NodeList roots = template.getElementsByTagNameNS( + DC_NAMESPACE_URI, "template"); + + helper.build(rootsToList(roots)); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :