Mercurial > dive4elements > framework
changeset 113:0344a20f8a93
Added the ArtifactNamespaceContext and a ClientProtocolUtils that helps working with the artifact protocol.
artifacts/trunk@1318 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 16 Feb 2011 15:26:38 +0000 |
parents | 2f35e8a84004 |
children | 19b86e27d0c3 |
files | ChangeLog artifacts-common/src/main/java/de/intevation/artifacts/common/ArtifactNamespaceContext.java artifacts-common/src/main/java/de/intevation/artifacts/common/utils/ClientProtocolUtils.java |
diffstat | 3 files changed, 160 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Thu Feb 10 07:40:09 2011 +0000 +++ b/ChangeLog Wed Feb 16 15:26:38 2011 +0000 @@ -1,3 +1,14 @@ +2011-02-16 Ingo Weinzierl <ingo@intevation.de> + + * artifacts-common/src/main/java/de/intevation/artifacts/common/ArtifactNamespaceContext.java: + New. Added the namespace context here to make it available in clients as + well. + + * artifacts-common/src/main/java/de/intevation/artifacts/common/utils/ClientProtocolUtils.java: + New. This class provides functions that help working with the artifact + protocol. Currently, there is just a single function to create a new + CREATE document. + 2011-02-10 Ingo Weinzierl <ingo@intevation.de> * artifacts-common/src/main/resources/de/intevation/artifacts/common/Common.gwt.xml:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts-common/src/main/java/de/intevation/artifacts/common/ArtifactNamespaceContext.java Wed Feb 16 15:26:38 2011 +0000 @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2010 by Intevation GmbH + * + * This program is free software under the LGPL (>=v2.1) + * Read the file LGPL.txt coming with the software for details + * or visit http://www.gnu.org/licenses/ if it does not exist. + */ + +package de.intevation.artifacts.common; + +import java.util.Iterator; + +import javax.xml.XMLConstants; + +import javax.xml.namespace.NamespaceContext; + +/** + * The namespace used in artifact documents. + * @author <a href="mailto:sascha.teichmann@intevation">Sascha L. Teichmann</a> + */ +public class ArtifactNamespaceContext +implements NamespaceContext +{ + /** + * The URI of the namespace of the artifacts. + */ + public final static String NAMESPACE_URI = + "http://www.intevation.de/2009/artifacts"; + + /** + * The XML prefix for the artifacts namespace. + */ + public final static String NAMESPACE_PREFIX = "art"; + + /** + * Final instance to be easily used to avoid creation + * of instances. + */ + public static final ArtifactNamespaceContext INSTANCE = + new ArtifactNamespaceContext(); + + /** + * The default constructor. + */ + public ArtifactNamespaceContext() { + } + + /** + * @see javax.xml.namespace.NamespaceContext#getNamespaceURI(String) + * @param prefix The prefix + * @return The corresponing URI + */ + public String getNamespaceURI(String prefix) { + + if (prefix == null) { + throw new NullPointerException("Null prefix"); + } + + if (NAMESPACE_PREFIX.equals(prefix)) { + return NAMESPACE_URI; + } + + if ("xml".equals(prefix)) { + return XMLConstants.XML_NS_URI; + } + + return XMLConstants.NULL_NS_URI; + } + + /** + * @see javax.xml.namespace.NamespaceContext#getPrefix(String) + * @param uri The URI + * @return nothing. + * @throws java.lang.UnsupportedOperationException + */ + public String getPrefix(String uri) { + throw new UnsupportedOperationException(); + } + + /** + * @see javax.xml.namespace.NamespaceContext#getPrefixes(java.lang.String) + * @param uri The URI + * @return nothing + * @throws java.lang.UnsupportedOperationException + */ + public Iterator getPrefixes(String uri) { + throw new UnsupportedOperationException(); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts-common/src/main/java/de/intevation/artifacts/common/utils/ClientProtocolUtils.java Wed Feb 16 15:26:38 2011 +0000 @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2011 by Intevation GmbH + * + * This program is free software under the LGPL (>=v2.1) + * Read the file LGPL.txt coming with the software for details + * or visit http://www.gnu.org/licenses/ if it does not exist. + */ +package de.intevation.artifacts.common.utils; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import de.intevation.artifacts.common.ArtifactNamespaceContext; + + +/** + * This class provides methods that help creating the artifact protocol + * documents DESCRIBE, FEED, ADVANCE and OUT. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class ClientProtocolUtils { + + /** + * It should not be necessary to create instances of this class. + */ + private ClientProtocolUtils() { + } + + + /** + * This method creates a new CREATE document. + * + * @return the CREATE document. + */ + public static Document newCreateDocument(String factory) { + Document doc = XMLUtils.newDocument(); + + XMLUtils.ElementCreator cr = new XMLUtils.ElementCreator( + doc, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX); + + Element action = cr.create("action"); + Element type = cr.create("type"); + Element fac = cr.create("factory"); + + type.setAttribute("name", "create"); + fac.setAttribute("name", factory); + + action.appendChild(type); + action.appendChild(fac); + + doc.appendChild(action); + + return doc; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :