Mercurial > dive4elements > framework
comparison artifact-database/src/main/java/org/dive4elements/artifactdatabase/rest/ServicesResource.java @ 473:d0ac790a6c89 dive4elements-move
Moved directories to org.dive4elements
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 10:57:18 +0200 |
parents | artifact-database/src/main/java/de/intevation/artifactdatabase/rest/ServicesResource.java@b2115f484edb |
children | 415df0fc4fa1 |
comparison
equal
deleted
inserted
replaced
472:783cc1b6b615 | 473:d0ac790a6c89 |
---|---|
1 /* | |
2 * Copyright (c) 2010 by Intevation GmbH | |
3 * | |
4 * This program is free software under the LGPL (>=v2.1) | |
5 * Read the file LGPL.txt coming with the software for details | |
6 * or visit http://www.gnu.org/licenses/ if it does not exist. | |
7 */ | |
8 | |
9 package de.intevation.artifactdatabase.rest; | |
10 | |
11 import de.intevation.artifacts.common.utils.XMLUtils; | |
12 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; | |
13 | |
14 import de.intevation.artifacts.ArtifactDatabase; | |
15 import de.intevation.artifacts.ArtifactNamespaceContext; | |
16 | |
17 import org.apache.log4j.Logger; | |
18 | |
19 import org.restlet.data.MediaType; | |
20 | |
21 import org.restlet.ext.xml.DomRepresentation; | |
22 | |
23 import org.restlet.representation.Representation; | |
24 | |
25 import org.restlet.resource.ResourceException; | |
26 | |
27 import org.w3c.dom.Document; | |
28 import org.w3c.dom.Element; | |
29 | |
30 /** | |
31 * Resource to list the available service offered by the artifact database. | |
32 * | |
33 * @author <a href="mailto:sascha.teichmann@intevation">Sascha L. Teichmann</a> | |
34 */ | |
35 public class ServicesResource | |
36 extends BaseResource | |
37 { | |
38 private static Logger logger = Logger.getLogger(ServicesResource.class); | |
39 | |
40 /** | |
41 * server URL where to reach the resource. | |
42 */ | |
43 public static final String PATH = "/services"; | |
44 | |
45 @Override | |
46 protected Representation innerGet() | |
47 throws ResourceException | |
48 { | |
49 Document document = XMLUtils.newDocument(); | |
50 | |
51 ElementCreator ec = new ElementCreator( | |
52 document, | |
53 ArtifactNamespaceContext.NAMESPACE_URI, | |
54 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
55 | |
56 ArtifactDatabase db = (ArtifactDatabase)getContext() | |
57 .getAttributes().get("database"); | |
58 | |
59 Element root = ec.create("result"); | |
60 document.appendChild(root); | |
61 | |
62 Element type = ec.create("type"); | |
63 ec.addAttr(type, "name", "service-list"); | |
64 root.appendChild(type); | |
65 | |
66 Element factories = ec.create("services"); | |
67 root.appendChild(factories); | |
68 | |
69 String [][] factoryNames = db.serviceNamesAndDescriptions(); | |
70 | |
71 for (int i = 0; i < factoryNames.length; ++i) { | |
72 String [] nd = factoryNames[i]; | |
73 Element factoryElement = ec.create("service"); | |
74 ec.addAttr(factoryElement, "name", nd[0]); | |
75 ec.addAttr(factoryElement, "description", nd[1]); | |
76 factories.appendChild(factoryElement); | |
77 } | |
78 | |
79 document.normalizeDocument(); | |
80 | |
81 return new DomRepresentation( | |
82 MediaType.APPLICATION_XML, document); | |
83 } | |
84 } | |
85 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |