Mercurial > dive4elements > framework
annotate artifact-database/src/main/java/de/intevation/artifactdatabase/rest/ServicesResource.java @ 300:0035e2511342
CREATE documents for Artifact creation might contain db-ids now.
artifacts/trunk@2388 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 21 Jul 2011 15:05:49 +0000 |
parents | b2115f484edb |
children |
rev | line source |
---|---|
100
933bbc9fc11f
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
89
diff
changeset
|
1 /* |
933bbc9fc11f
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
89
diff
changeset
|
2 * Copyright (c) 2010 by Intevation GmbH |
933bbc9fc11f
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
89
diff
changeset
|
3 * |
933bbc9fc11f
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
89
diff
changeset
|
4 * This program is free software under the LGPL (>=v2.1) |
933bbc9fc11f
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
89
diff
changeset
|
5 * Read the file LGPL.txt coming with the software for details |
933bbc9fc11f
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
89
diff
changeset
|
6 * or visit http://www.gnu.org/licenses/ if it does not exist. |
933bbc9fc11f
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
89
diff
changeset
|
7 */ |
933bbc9fc11f
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
89
diff
changeset
|
8 |
72
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 package de.intevation.artifactdatabase.rest; |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 |
207
b2115f484edb
Move Config and XMLUtils totally to commons package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
100
diff
changeset
|
11 import de.intevation.artifacts.common.utils.XMLUtils; |
b2115f484edb
Move Config and XMLUtils totally to commons package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
100
diff
changeset
|
12 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; |
72
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 import de.intevation.artifacts.ArtifactDatabase; |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 import de.intevation.artifacts.ArtifactNamespaceContext; |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 import org.apache.log4j.Logger; |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 import org.restlet.data.MediaType; |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 import org.restlet.ext.xml.DomRepresentation; |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 import org.restlet.representation.Representation; |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 import org.restlet.resource.ResourceException; |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 import org.w3c.dom.Document; |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 import org.w3c.dom.Element; |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 /** |
88
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
31 * Resource to list the available service offered by the artifact database. |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
32 * |
77
48d1a9a082c2
Bring @author javadoc tags in form '@author <a href="john.doe@example.com">John Doe</a>'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
72
diff
changeset
|
33 * @author <a href="mailto:sascha.teichmann@intevation">Sascha L. Teichmann</a> |
72
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 */ |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 public class ServicesResource |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 extends BaseResource |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 { |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 private static Logger logger = Logger.getLogger(ServicesResource.class); |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 |
88
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
40 /** |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
41 * server URL where to reach the resource. |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
42 */ |
72
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 public static final String PATH = "/services"; |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 |
89
d348fe1fd822
More javadoc (fixes small glitches, too).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
88
diff
changeset
|
45 @Override |
72
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 protected Representation innerGet() |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 throws ResourceException |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 { |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 Document document = XMLUtils.newDocument(); |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 ElementCreator ec = new ElementCreator( |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 document, |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 ArtifactNamespaceContext.NAMESPACE_URI, |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 ArtifactNamespaceContext.NAMESPACE_PREFIX); |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 ArtifactDatabase db = (ArtifactDatabase)getContext() |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 .getAttributes().get("database"); |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 Element root = ec.create("result"); |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 document.appendChild(root); |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 Element type = ec.create("type"); |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 ec.addAttr(type, "name", "service-list"); |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 root.appendChild(type); |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 Element factories = ec.create("services"); |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 root.appendChild(factories); |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 String [][] factoryNames = db.serviceNamesAndDescriptions(); |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 for (int i = 0; i < factoryNames.length; ++i) { |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 String [] nd = factoryNames[i]; |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 Element factoryElement = ec.create("service"); |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 ec.addAttr(factoryElement, "name", nd[0]); |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 ec.addAttr(factoryElement, "description", nd[1]); |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 factories.appendChild(factoryElement); |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 } |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
79 document.normalizeDocument(); |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
80 |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
81 return new DomRepresentation( |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 MediaType.APPLICATION_XML, document); |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 } |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
84 } |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
85 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |