Mercurial > dive4elements > framework
comparison artifact-database/src/main/java/de/intevation/artifactdatabase/rest/ServicesResource.java @ 72:b01e47317a78
Added '/services' url to web server to list the available services in XML.
artifacts/trunk@600 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 22 Jan 2010 11:40:26 +0000 |
parents | |
children | 48d1a9a082c2 |
comparison
equal
deleted
inserted
replaced
71:c99da6837be0 | 72:b01e47317a78 |
---|---|
1 package de.intevation.artifactdatabase.rest; | |
2 | |
3 import de.intevation.artifactdatabase.XMLUtils.ElementCreator; | |
4 | |
5 import de.intevation.artifactdatabase.XMLUtils; | |
6 | |
7 import de.intevation.artifacts.ArtifactDatabase; | |
8 import de.intevation.artifacts.ArtifactNamespaceContext; | |
9 | |
10 import org.apache.log4j.Logger; | |
11 | |
12 import org.restlet.data.MediaType; | |
13 | |
14 import org.restlet.ext.xml.DomRepresentation; | |
15 | |
16 import org.restlet.representation.Representation; | |
17 | |
18 import org.restlet.resource.ResourceException; | |
19 | |
20 import org.w3c.dom.Document; | |
21 import org.w3c.dom.Element; | |
22 | |
23 /** | |
24 * @author Sascha L. Teichmann (sascha.teichmann@intevation) | |
25 */ | |
26 public class ServicesResource | |
27 extends BaseResource | |
28 { | |
29 private static Logger logger = Logger.getLogger(ServicesResource.class); | |
30 | |
31 public static final String PATH = "/services"; | |
32 | |
33 protected Representation innerGet() | |
34 throws ResourceException | |
35 { | |
36 Document document = XMLUtils.newDocument(); | |
37 | |
38 ElementCreator ec = new ElementCreator( | |
39 document, | |
40 ArtifactNamespaceContext.NAMESPACE_URI, | |
41 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
42 | |
43 ArtifactDatabase db = (ArtifactDatabase)getContext() | |
44 .getAttributes().get("database"); | |
45 | |
46 Element root = ec.create("result"); | |
47 document.appendChild(root); | |
48 | |
49 Element type = ec.create("type"); | |
50 ec.addAttr(type, "name", "service-list"); | |
51 root.appendChild(type); | |
52 | |
53 Element factories = ec.create("services"); | |
54 root.appendChild(factories); | |
55 | |
56 String [][] factoryNames = db.serviceNamesAndDescriptions(); | |
57 | |
58 for (int i = 0; i < factoryNames.length; ++i) { | |
59 String [] nd = factoryNames[i]; | |
60 Element factoryElement = ec.create("service"); | |
61 ec.addAttr(factoryElement, "name", nd[0]); | |
62 ec.addAttr(factoryElement, "description", nd[1]); | |
63 factories.appendChild(factoryElement); | |
64 } | |
65 | |
66 document.normalizeDocument(); | |
67 | |
68 return new DomRepresentation( | |
69 MediaType.APPLICATION_XML, document); | |
70 } | |
71 } | |
72 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |