1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.properties.admin.resources.controller;
17
18 import java.io.IOException;
19
20 import javax.annotation.security.RolesAllowed;
21 import javax.servlet.http.HttpServletRequest;
22 import javax.ws.rs.GET;
23 import javax.ws.rs.Path;
24 import javax.ws.rs.PathParam;
25 import javax.ws.rs.Produces;
26 import javax.ws.rs.core.Context;
27 import javax.ws.rs.core.MediaType;
28 import javax.ws.rs.core.Response;
29 import javax.ws.rs.core.Response.Status;
30 import javax.ws.rs.core.UriInfo;
31
32 import de.smartics.properties.admin.domain.model.ManagedApplication;
33 import de.smartics.properties.admin.domain.model.Paths;
34 import de.smartics.properties.admin.domain.model.Roles;
35 import de.smartics.properties.api.core.domain.PropertyDescriptor;
36 import de.smartics.properties.api.core.domain.PropertyDescriptorRegistry;
37
38
39
40
41 @Path("")
42 @RolesAllowed(Roles.VIEW)
43 public class PropertyDescriptorResource
44 {
45
46
47
48
49
50
51
52
53
54 @Context
55 private HttpServletRequest request;
56
57
58
59
60 @Context
61 private UriInfo uriInfo;
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84 @GET
85 @Path(Paths.PATH_PROPERTY_DESCRIPTOR + ".xml")
86 @Produces(MediaType.WILDCARD)
87 public Response getAsDotXml(
88 @PathParam(Paths.PARAM_PROPERTY_KEY) final String propertyKey)
89 throws IOException
90 {
91 final Response response = getAsXml(propertyKey);
92 return response;
93 }
94
95
96
97
98
99
100
101
102 @GET
103 @Path(Paths.PATH_PROPERTY_DESCRIPTOR)
104 @Produces({ MediaType.APPLICATION_XML, MediaType.TEXT_XML })
105 public Response getAsXml(
106 @PathParam(Paths.PARAM_PROPERTY_KEY) final String propertyKey)
107 throws IOException
108 {
109 final ManagedApplication app = ManagedApplication.getApplication();
110 final PropertyDescriptorRegistry registry = app.getDescriptorRegistry();
111 final PropertyDescriptor descriptor = registry.get(propertyKey);
112
113 if (descriptor == null)
114 {
115 final Response response = Response.status(Status.NOT_FOUND).build();
116 return response;
117 }
118
119 final Response response =
120 Response.ok().type(MediaType.TEXT_XML_TYPE).entity(descriptor).build();
121 return response;
122 }
123
124
125
126
127
128
129
130
131 @GET
132 @Path(Paths.PATH_PROPERTY_DESCRIPTOR)
133 @Produces({ MediaType.TEXT_HTML })
134 public Response getAsHtml(
135 @PathParam(Paths.PARAM_PROPERTY_KEY) final String propertyKey)
136 throws IOException
137 {
138 final ManagedApplication app = ManagedApplication.getApplication();
139 final PropertyDescriptorRegistry registry = app.getDescriptorRegistry();
140 final PropertyDescriptor descriptor = registry.get(propertyKey);
141 if (descriptor == null && propertyKey.endsWith(".xml"))
142 {
143 return getAsDotXml(propertyKey.substring(0, propertyKey.length() - 4));
144 }
145 else if (descriptor == null)
146 {
147 final Response response = Response.status(Status.NOT_FOUND).build();
148 return response;
149 }
150
151 final Response response = Response.ok().entity(descriptor).build();
152 return response;
153 }
154
155
156
157 }