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.resources.representation.share.BreadcrumbHelper;
24 import de.smartics.properties.admin.resources.representation.xml.share.AbstractXmlRepresentationRenderer;
25 import de.smartics.properties.api.core.domain.PropertyComment;
26 import de.smartics.properties.api.core.domain.PropertyDescriptor;
27 import de.smartics.properties.api.core.domain.PropertyProjectdoc;
28 import de.smartics.properties.api.core.domain.SourceInfo;
29 import de.smartics.properties.report.data.PropertyReportItem;
30 import de.smartics.properties.reports.XmlPropertyItemReport;
31 import de.smartics.resteasy.hypermedia.renderer.LinkDescriptor;
32 import de.smartics.resteasy.hypermedia.renderer.ResourceContext;
33
34
35
36
37 public final class PropertyDescriptorXmlRepresentationRenderer extends
38 AbstractXmlRepresentationRenderer<PropertyDescriptor>
39 {
40
41
42
43
44
45
46
47
48
49 private final PropertyDescriptor domainObject;
50
51
52
53
54
55
56
57
58
59
60
61
62 public PropertyDescriptorXmlRepresentationRenderer(
63 final ResourceContext context, final PropertyDescriptor domainObject,
64 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 PropertyReportItem.Builder builder = new PropertyReportItem.Builder();
101
102 final Locale locale = context.getL7nProvider().getLocale();
103 final PropertyProjectdoc projectdoc =
104 domainObject.getDocumentMetaData(locale);
105 final SourceInfo sourceInfo = projectdoc.getSourceInfo();
106 final PropertyComment propertyComment = projectdoc.getComment();
107 builder.with(domainObject).with(sourceInfo).with(propertyComment);
108
109 final PropertyReportItem reportItem = builder.build();
110 return reportItem;
111 }
112
113 @Override
114 protected List<LinkDescriptor> hyperLinks()
115 {
116 return BreadcrumbHelper.adjustSelf(breadcrumb.descriptor(domainObject
117 .getKey().toString()));
118 }
119
120 @Override
121 protected void close()
122 {
123 }
124
125
126
127 }