# HG changeset patch # User Sascha L. Teichmann # Date 1264160426 0 # Node ID b01e47317a7872ad14dcef5c25a6f425049943f4 # Parent c99da6837be071636a42480675ab532e0e817b8d Added '/services' url to web server to list the available services in XML. artifacts/trunk@600 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r c99da6837be0 -r b01e47317a78 ChangeLog --- a/ChangeLog Fri Jan 22 11:27:57 2010 +0000 +++ b/ChangeLog Fri Jan 22 11:40:26 2010 +0000 @@ -1,3 +1,12 @@ +2010-01-22 Sascha L. Teichmann + + * artifact-database/src/main/java/de/intevation/artifactdatabase/rest/ServicesResource.java: + New. Serves a list of available services under '/services' as XML. Structure + is much like '/factories' with 's/artifact/service/'. + + * artifact-database/src/main/java/de/intevation/artifactdatabase/rest/RestApp.java: + Register new resource to web server. + 2010-01-22 Sascha L. Teichmann * artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java: diff -r c99da6837be0 -r b01e47317a78 artifact-database/src/main/java/de/intevation/artifactdatabase/rest/RestApp.java --- a/artifact-database/src/main/java/de/intevation/artifactdatabase/rest/RestApp.java Fri Jan 22 11:27:57 2010 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/rest/RestApp.java Fri Jan 22 11:40:26 2010 +0000 @@ -35,6 +35,7 @@ Router router = new Router(context); + router.attach(ServicesResource.PATH, ServicesResource.class); router.attach(FactoriesResource.PATH, FactoriesResource.class); router.attach(CreateResource.PATH, CreateResource.class); router.attach(ArtifactResource.PATH, ArtifactResource.class); diff -r c99da6837be0 -r b01e47317a78 artifact-database/src/main/java/de/intevation/artifactdatabase/rest/ServicesResource.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/rest/ServicesResource.java Fri Jan 22 11:40:26 2010 +0000 @@ -0,0 +1,72 @@ +package de.intevation.artifactdatabase.rest; + +import de.intevation.artifactdatabase.XMLUtils.ElementCreator; + +import de.intevation.artifactdatabase.XMLUtils; + +import de.intevation.artifacts.ArtifactDatabase; +import de.intevation.artifacts.ArtifactNamespaceContext; + +import org.apache.log4j.Logger; + +import org.restlet.data.MediaType; + +import org.restlet.ext.xml.DomRepresentation; + +import org.restlet.representation.Representation; + +import org.restlet.resource.ResourceException; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * @author Sascha L. Teichmann (sascha.teichmann@intevation) + */ +public class ServicesResource +extends BaseResource +{ + private static Logger logger = Logger.getLogger(ServicesResource.class); + + public static final String PATH = "/services"; + + protected Representation innerGet() + throws ResourceException + { + Document document = XMLUtils.newDocument(); + + ElementCreator ec = new ElementCreator( + document, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX); + + ArtifactDatabase db = (ArtifactDatabase)getContext() + .getAttributes().get("database"); + + Element root = ec.create("result"); + document.appendChild(root); + + Element type = ec.create("type"); + ec.addAttr(type, "name", "service-list"); + root.appendChild(type); + + Element factories = ec.create("services"); + root.appendChild(factories); + + String [][] factoryNames = db.serviceNamesAndDescriptions(); + + for (int i = 0; i < factoryNames.length; ++i) { + String [] nd = factoryNames[i]; + Element factoryElement = ec.create("service"); + ec.addAttr(factoryElement, "name", nd[0]); + ec.addAttr(factoryElement, "description", nd[1]); + factories.appendChild(factoryElement); + } + + document.normalizeDocument(); + + return new DomRepresentation( + MediaType.APPLICATION_XML, document); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :