1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.properties.admin.resources.representation.xml;
17
18 import java.io.IOException;
19 import java.io.OutputStream;
20 import java.util.List;
21 import java.util.Locale;
22
23 import de.smartics.properties.admin.domain.model.ConfigurationProperty;
24 import de.smartics.properties.admin.resources.representation.share.BreadcrumbHelper;
25 import de.smartics.properties.admin.resources.representation.xml.share.AbstractXmlRepresentationRenderer;
26 import de.smartics.properties.api.core.domain.PropertyComment;
27 import de.smartics.properties.api.core.domain.PropertyDescriptor;
28 import de.smartics.properties.api.core.domain.PropertyProjectdoc;
29 import de.smartics.properties.api.core.domain.SourceInfo;
30 import de.smartics.properties.report.data.PropertyReportItem;
31 import de.smartics.properties.reports.XmlPropertyItemReport;
32 import de.smartics.resteasy.hypermedia.renderer.LinkDescriptor;
33 import de.smartics.resteasy.hypermedia.renderer.ResourceContext;
34
35
36
37
38 public final class PropertyXmlRepresentationRenderer extends
39 AbstractXmlRepresentationRenderer<ConfigurationProperty>
40 {
41
42
43
44
45
46
47
48
49
50 private final ConfigurationProperty domainObject;
51
52
53
54
55
56
57
58
59
60
61
62
63 public PropertyXmlRepresentationRenderer(final ResourceContext context,
64 final ConfigurationProperty domainObject, final OutputStream entityStream)
65 {
66 super(context, entityStream);
67 this.domainObject = domainObject;
68 }
69
70
71
72
73
74
75
76
77
78
79
80 @Override
81 protected void httpBody()
82 {
83 final XmlPropertyItemReport report =
84 new XmlPropertyItemReport(characterEncoding);
85
86 final PropertyReportItem reportItem = createReportItem();
87 try
88 {
89 report.write(reportItem, entityStream);
90 }
91 catch (final IOException e)
92 {
93
94 throw new IllegalStateException("Cannot render to the stream.", e);
95 }
96 }
97
98 private PropertyReportItem createReportItem()
99 {
100 final Object value = domainObject.getPropertyValue();
101
102 final PropertyDescriptor descriptor = domainObject.getDescriptor();
103
104 final PropertyReportItem.Builder builder = new PropertyReportItem.Builder();
105 final Locale locale = context.getL7nProvider().getLocale();
106 final PropertyProjectdoc projectdoc =
107 descriptor.getDocumentMetaData(locale);
108 final SourceInfo sourceInfo = projectdoc.getSourceInfo();
109 final PropertyComment propertyComment = projectdoc.getComment();
110 builder.with(descriptor).with(sourceInfo).with(propertyComment);
111
112 final PropertyReportItem reportItem = builder.build();
113 reportItem.setValue(value);
114 return reportItem;
115 }
116
117 @Override
118 protected List<LinkDescriptor> hyperLinks()
119 {
120 return BreadcrumbHelper.adjustSelf(breadcrumb.property(
121 domainObject.getConfigurationKey(), domainObject.getPropertyKey()));
122 }
123
124 @Override
125 protected void close()
126 {
127 }
128
129
130
131 }