comparison artifact-database/src/main/java/org/dive4elements/artifactdatabase/rest/FactoriesResource.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/FactoriesResource.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 factories.
32 * @author <a href="mailto:sascha.teichmann@intevation">Sascha L. Teichmann</a>
33 */
34 public class FactoriesResource
35 extends BaseResource
36 {
37 private static Logger logger = Logger.getLogger(FactoriesResource.class);
38
39 /**
40 * server URL where to reach the resource.
41 */
42 public static final String PATH = "/factories";
43
44 @Override
45 protected Representation innerGet()
46 throws ResourceException
47 {
48 Document document = XMLUtils.newDocument();
49
50 ElementCreator ec = new ElementCreator(
51 document,
52 ArtifactNamespaceContext.NAMESPACE_URI,
53 ArtifactNamespaceContext.NAMESPACE_PREFIX);
54
55 ArtifactDatabase db = (ArtifactDatabase)getContext()
56 .getAttributes().get("database");
57
58 Element root = ec.create("result");
59 document.appendChild(root);
60
61 Element type = ec.create("type");
62 ec.addAttr(type, "name", "factory-list");
63 root.appendChild(type);
64
65 Element factories = ec.create("factories");
66 root.appendChild(factories);
67
68 String [][] factoryNames = db.artifactFactoryNamesAndDescriptions();
69
70 for (int i = 0; i < factoryNames.length; ++i) {
71 String [] nd = factoryNames[i];
72 Element factoryElement = ec.create("factory");
73 ec.addAttr(factoryElement, "name", nd[0]);
74 ec.addAttr(factoryElement, "description", nd[1]);
75 factories.appendChild(factoryElement);
76 }
77
78 document.normalizeDocument();
79
80 return new DomRepresentation(
81 MediaType.APPLICATION_XML, document);
82 }
83 }
84 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org