# HG changeset patch # User Ingo Weinzierl # Date 1311001520 0 # Node ID e5bc48dc3ec366149c24bf5f8c879e53beda5d00 # Parent b530e83acf2e68f0a2946d8f3d99ea37d937cb34 Facets can write its internal representation to XML using a toXML() method now. artifacts/trunk@2352 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r b530e83acf2e -r e5bc48dc3ec3 ChangeLog --- 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 + + * 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 * artifacts/src/main/java/de/intevation/artifacts/Hook.java: The Hook's diff -r b530e83acf2e -r e5bc48dc3ec3 artifact-database/src/main/java/de/intevation/artifactdatabase/ProtocolUtils.java --- 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 outputs) + Document doc, + Element out, + List 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 facets) + Document doc, + Element facet, + List 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); + } } } } diff -r b530e83acf2e -r e5bc48dc3ec3 artifact-database/src/main/java/de/intevation/artifactdatabase/state/DefaultFacet.java --- 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 : diff -r b530e83acf2e -r e5bc48dc3ec3 artifact-database/src/main/java/de/intevation/artifactdatabase/state/Facet.java --- 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 :