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.DESCRIPTOR;
19
20 import java.io.OutputStream;
21 import java.net.URI;
22 import java.util.List;
23 import java.util.Locale;
24
25 import org.apache.commons.lang3.StringUtils;
26
27 import de.smartics.html5.jatl.HtmlResourceContext;
28 import de.smartics.properties.admin.domain.model.PropertyDescriptors;
29 import de.smartics.properties.admin.resources.controller.PropertyDescriptorResource;
30 import de.smartics.properties.admin.resources.representation.html.share.AbstractHtmlRepresentationRenderer;
31 import de.smartics.properties.api.core.domain.PropertyDescriptor;
32 import de.smartics.properties.api.core.domain.PropertyKey;
33 import de.smartics.properties.api.core.domain.PropertySetProjectdoc;
34 import de.smartics.resteasy.hypermedia.renderer.LinkDescriptor;
35
36
37
38
39
40 public final class PropertyDescriptorsHtmlRepresentationRenderer extends
41 AbstractHtmlRepresentationRenderer<PropertyDescriptors>
42 {
43
44
45
46
47
48
49
50 private static final String TITLE = "Property Descriptors";
51
52
53
54
55
56
57 private final PropertyDescriptors domainObject;
58
59
60
61
62
63
64
65
66
67
68
69
70 public PropertyDescriptorsHtmlRepresentationRenderer(
71 final HtmlResourceContext htmlContext,
72 final PropertyDescriptors domainObject, final OutputStream entityStream)
73 {
74 super(htmlContext, entityStream);
75 this.domainObject = domainObject;
76 }
77
78
79
80
81
82
83
84
85
86 @Override
87 protected String getTitle()
88 {
89 return TITLE;
90 }
91
92
93
94 @Override
95 protected void bodyContents()
96 {
97 renderPageTitle(">>>");
98
99 html.p()
100 .text(
101 "The following list shows the property descriptors registered in the application.")
102 .end();
103
104 renderRegistry();
105 }
106
107 private void renderRegistry()
108 {
109 for (final String propertySet : domainObject.getPropertyKeys())
110 {
111 final List<PropertyDescriptor> descriptors =
112 domainObject.get(propertySet);
113
114 html.h2().text(propertySet).end();
115 html.table().classAttr("table table-striped descriptors");
116
117 if (!descriptors.isEmpty())
118 {
119 final Locale locale =
120 this.htmlContext.getContext().getResponse().getLocale();
121 final PropertyDescriptor descriptor = descriptors.get(0);
122 final PropertySetProjectdoc projectdoc =
123 descriptor.getDocumentMetaDataProjectSet(locale);
124 final String comment = projectdoc.getComment();
125 if (StringUtils.isNotBlank(comment))
126 {
127 html.raw(comment);
128 }
129 }
130
131 html.tr();
132 html.th().classAttr("no").text("#").end();
133 html.th().classAttr("descriptorName").text("Name").end();
134 html.th().classAttr("download").text("Download").end();
135 html.end();
136 int counter = 0;
137 for (final PropertyDescriptor descriptor : descriptors)
138 {
139 counter++;
140 renderRow(counter, descriptor);
141 }
142 html.end();
143 }
144 }
145
146 private void renderRow(final int counter, final PropertyDescriptor descriptor)
147 {
148 final PropertyKey key = descriptor.getKey();
149 final String keyString = key.toString();
150 html.tr();
151 html.td().text(String.valueOf(counter)).end();
152
153 final URI url = createUrl(keyString);
154 html.td();
155 html.a().id(keyString).rel(DESCRIPTOR).href(url.toString())
156 .text(key.getName()).end();
157 html.end();
158 html.td();
159 final URI downloadUrl = createDownloadUrl(keyString);
160 html.a().id(keyString + "asXml").rel(DESCRIPTOR)
161 .href(downloadUrl.toString()).icon("icon-download-alt").text("XML")
162 .end();
163 html.end();
164 html.end();
165 }
166
167 private URI createUrl(final String key)
168 {
169 final URI url =
170 htmlContext.getContext().getUriInfo().getBaseUriBuilder()
171 .path(PropertyDescriptorResource.class, "getAsHtml")
172 .build(new Object[] { key }, false);
173 return url;
174 }
175
176 private URI createDownloadUrl(final String key)
177 {
178 final URI url =
179 htmlContext.getContext().getUriInfo().getBaseUriBuilder()
180 .path(PropertyDescriptorResource.class, "getAsDotXml")
181 .build(new Object[] { key }, false);
182 return url;
183 }
184
185 @Override
186 protected List<LinkDescriptor> breadcrumbLinks()
187 {
188 return breadcrumb.descriptors();
189 }
190
191
192
193 }