Mercurial > dive4elements > framework
changeset 295:e5bc48dc3ec3
Facets can write its internal representation to XML using a toXML() method now.
artifacts/trunk@2352 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 18 Jul 2011 15:05:20 +0000 |
parents | b530e83acf2e |
children | a8e009ebe13c |
files | ChangeLog artifact-database/src/main/java/de/intevation/artifactdatabase/ProtocolUtils.java artifact-database/src/main/java/de/intevation/artifactdatabase/state/DefaultFacet.java artifact-database/src/main/java/de/intevation/artifactdatabase/state/Facet.java |
diffstat | 4 files changed, 72 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Thu Jul 14 14:41:00 2011 +0000 +++ b/ChangeLog Mon Jul 18 15:05:20 2011 +0000 @@ -1,3 +1,14 @@ +2011-07-18 Ingo Weinzierl <ingo@intevation.de> + + * artifact-database/src/main/java/de/intevation/artifactdatabase/state/Facet.java, + artifact-database/src/main/java/de/intevation/artifactdatabase/state/DefaultFacet.java: + A facet can write its internal representation to XML using a public + method toXML(Document). + + * artifact-database/src/main/java/de/intevation/artifactdatabase/ProtocolUtils.java: + Facets are appended using its toXML() method. Concrete facets can now + change its xml representation. + 2011-07-14 Ingo Weinzierl <ingo@intevation.de> * artifacts/src/main/java/de/intevation/artifacts/Hook.java: The Hook's
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/ProtocolUtils.java Thu Jul 14 14:41:00 2011 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/ProtocolUtils.java Mon Jul 18 15:05:20 2011 +0000 @@ -9,9 +9,14 @@ import java.util.List; +import org.w3c.dom.Document; import org.w3c.dom.Element; +import org.w3c.dom.Node; + +import de.intevation.artifacts.ArtifactNamespaceContext; import de.intevation.artifacts.common.utils.XMLUtils; +import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; import de.intevation.artifactdatabase.state.Facet; import de.intevation.artifactdatabase.state.Output; @@ -157,10 +162,15 @@ * @param outputs The list of reachable outputs. */ public static void appendOutputModes( - XMLUtils.ElementCreator creator, - Element out, - List<Output> outputs) + Document doc, + Element out, + List<Output> outputs) { + ElementCreator creator = new ElementCreator( + doc, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX); + for (Output o: outputs) { Element newOut = createArtNode( creator, @@ -173,7 +183,7 @@ o.getType() }); Element facets = createArtNode(creator, "facets", null, null); - appendFacets(creator, facets, o.getFacets()); + appendFacets(doc, facets, o.getFacets()); newOut.appendChild(facets); out.appendChild(newOut); @@ -190,26 +200,25 @@ * @param facets The list of facets. */ public static void appendFacets( - XMLUtils.ElementCreator creator, - Element facet, - List<Facet> facets) + Document doc, + Element facet, + List<Facet> facets) { if (facets == null || facets.size() == 0) { return; } + ElementCreator creator = new ElementCreator( + doc, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX); + for (Facet f: facets) { - Element newFacet = createArtNode( - creator, - "facet", - new String[] { "index", "name", "description" }, - new String[] { - String.valueOf(f.getIndex()), - f.getName(), - f.getDescription() - }); + Node node = f.toXML(doc); - facet.appendChild(newFacet); + if (node != null) { + facet.appendChild(node); + } } } }
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/state/DefaultFacet.java Thu Jul 14 14:41:00 2011 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/state/DefaultFacet.java Mon Jul 18 15:05:20 2011 +0000 @@ -1,8 +1,15 @@ package de.intevation.artifactdatabase.state; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + import de.intevation.artifacts.Artifact; +import de.intevation.artifacts.ArtifactNamespaceContext; import de.intevation.artifacts.CallContext; +import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; + /** * The default implementation of a Facet. @@ -72,5 +79,20 @@ .append(description).append("'") .toString(); } + + + public Node toXML(Document doc) { + ElementCreator ec = new ElementCreator( + doc, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX); + + Element facet = ec.create("facet"); + ec.addAttr(facet, "description", description, true); + ec.addAttr(facet, "name", name, true); + ec.addAttr(facet, "index", String.valueOf(index), true); + + return facet; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/state/Facet.java Thu Jul 14 14:41:00 2011 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/state/Facet.java Mon Jul 18 15:05:20 2011 +0000 @@ -2,6 +2,9 @@ import java.io.Serializable; +import org.w3c.dom.Document; +import org.w3c.dom.Node; + import de.intevation.artifacts.Artifact; import de.intevation.artifacts.CallContext; @@ -43,5 +46,15 @@ * @return the data. */ Object getData(Artifact artifact, CallContext context); + + + /** + * Write the internal representation of a facet to a node. + * + * @param doc A Document. + * + * @return the representation as Node. + */ + Node toXML(Document doc); } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :