1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.properties.admin.resources.representation.html;
17
18 import static de.smartics.properties.admin.domain.model.AppRelations.PROPERTY;
19
20 import java.io.OutputStream;
21 import java.net.URI;
22 import java.util.List;
23
24 import org.apache.commons.lang.ObjectUtils;
25
26 import de.smartics.html5.jatl.HtmlResourceContext;
27 import de.smartics.properties.admin.domain.model.PropertiesConfiguration;
28 import de.smartics.properties.admin.resources.controller.PropertyResource;
29 import de.smartics.properties.admin.resources.representation.html.share.AbstractHtmlRepresentationRenderer;
30 import de.smartics.properties.admin.resources.representation.html.share.ApplicationHtmlRenderingHelper;
31 import de.smartics.properties.api.config.domain.DescribedProperty;
32 import de.smartics.properties.api.config.domain.ValidatedProperty;
33 import de.smartics.properties.api.config.domain.key.ConfigurationKey;
34 import de.smartics.resteasy.hypermedia.renderer.LinkDescriptor;
35
36
37
38
39
40 public final class PropertyKeysHtmlRepresentationRenderer extends
41 AbstractHtmlRepresentationRenderer<PropertiesConfiguration>
42 {
43
44
45
46
47
48
49
50 private static final String TITLE = "Property Keys";
51
52
53
54
55
56
57 private final PropertiesConfiguration domainObject;
58
59
60
61
62
63
64
65
66
67
68
69
70 public PropertyKeysHtmlRepresentationRenderer(
71 final HtmlResourceContext htmlContext,
72 final PropertiesConfiguration domainObject,
73 final OutputStream entityStream)
74 {
75 super(htmlContext, entityStream);
76 this.domainObject = domainObject;
77 }
78
79
80
81
82
83
84
85
86
87 @Override
88 protected String getTitle()
89 {
90 return TITLE;
91 }
92
93
94
95 @Override
96 protected void bodyContents()
97 {
98 renderPageTitle(">>>");
99
100 html.p()
101 .text(
102 "The following list shows the property keys available in the configuration "
103 + domainObject.getKey()
104 + " of the application with the attached data source.").end();
105 final ApplicationHtmlRenderingHelper helper =
106 new ApplicationHtmlRenderingHelper(html, pathHelper,
107 domainObject.getApplication());
108 helper.addApplication();
109
110 renderRegistry();
111 }
112
113 private void renderRegistry()
114 {
115 html.table().classAttr("table table-striped");
116
117 html.tr();
118 html.th().text("#").end();
119
120 html.th().text("Name").end();
121 html.th().text("Value").end();
122 html.th().text("Source").end();
123 html.end();
124
125 int counter = 0;
126 for (final DescribedProperty property : domainObject.getProperties())
127 {
128 counter++;
129 renderRow(counter, property);
130 }
131
132 html.end();
133 }
134
135 private void renderRow(final int counter, final DescribedProperty property)
136 {
137 final String key = property.getName();
138 final URI url = createUrl(key);
139 html.tr();
140 html.td().text(String.valueOf(counter)).end();
141
142 if (property instanceof ValidatedProperty)
143 {
144
145 final String value =
146 ObjectUtils.toString(((ValidatedProperty) property)
147 .getValidatedValue());
148 html.td();
149 html.a().id(key).rel(PROPERTY).href(url.toString()).text(key).end();
150 html.end();
151 html.td().text(value).end();
152 }
153 else
154 {
155 final String value = property.getValue();
156 final String label;
157 final String css;
158
159 if (null == value)
160 {
161 css = "muted";
162
163 label = " (unset)";
164 }
165 else
166 {
167 css = "text-error";
168
169 label =
170 " = " + value + " (unresolvable)" + createConfigSource(property);
171 }
172
173
174 html.td().a().id(key).rel(PROPERTY).href(url.toString()).text(key).end()
175 .end();
176 html.td().span().classAttr(css).text(label).end().end();
177 }
178 html.td().span().classAttr("configKey").text(createConfigSource(property))
179 .end().end();
180 html.end();
181 }
182
183 private String createConfigSource(final DescribedProperty property)
184 {
185 final ConfigurationKey<?> configurationKey = property.getConfigurationKey();
186 final String label =
187 configurationKey == null ? "default" : configurationKey.toString();
188 return label;
189 }
190
191 private URI createUrl(final String key)
192 {
193 final URI url =
194 htmlContext.getContext().getUriInfo().getBaseUriBuilder()
195 .path(PropertyResource.class, "getAsHtml")
196 .build(new Object[] { domainObject.getKey(), key }, false);
197 return url;
198 }
199
200 @Override
201 protected List<LinkDescriptor> breadcrumbLinks()
202 {
203 return breadcrumb.configuration(domainObject.getKey());
204 }
205
206
207
208 }