This project has retired. For details please refer to its
Attic page.
AtomEntry xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.chemistry.opencmis.server.impl.atompub;
20
21 import static org.apache.chemistry.opencmis.commons.impl.Converter.convert;
22
23 import javax.xml.bind.JAXBException;
24 import javax.xml.stream.XMLStreamException;
25 import javax.xml.stream.XMLStreamWriter;
26
27 import org.apache.chemistry.opencmis.commons.data.ObjectData;
28 import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
29 import org.apache.chemistry.opencmis.commons.impl.Constants;
30 import org.apache.chemistry.opencmis.commons.impl.JaxBHelper;
31 import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisObjectType;
32 import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisTypeDefinitionType;
33 import org.apache.chemistry.opencmis.commons.server.ObjectInfo;
34
35
36
37
38 public class AtomEntry extends AtomDocumentBase {
39
40 private static final String DEFAULT_AUTHOR = "unknown";
41
42
43
44
45 public AtomEntry() {
46 }
47
48
49
50
51 public AtomEntry(XMLStreamWriter writer) {
52 setWriter(writer);
53 }
54
55
56
57
58 public void startEntry(boolean isRoot) throws XMLStreamException {
59 getWriter().writeStartElement(Constants.NAMESPACE_ATOM, "entry");
60
61 if (isRoot) {
62 writeNamespace(Constants.NAMESPACE_ATOM);
63 writeNamespace(Constants.NAMESPACE_CMIS);
64 writeNamespace(Constants.NAMESPACE_RESTATOM);
65 writeNamespace(Constants.NAMESPACE_APP);
66 }
67 }
68
69
70
71
72 public void endEntry() throws XMLStreamException {
73 getWriter().writeEndElement();
74 }
75
76
77
78
79 public void writeObject(ObjectData object, ObjectInfo info, String contentSrc, String contentType,
80 String pathSegment, String relativePathSegment) throws XMLStreamException, JAXBException {
81 CmisObjectType objectJaxb = convert(object);
82 if (objectJaxb == null) {
83 return;
84 }
85
86 writeAuthor(info.getCreatedBy());
87 writeId(generateAtomId(info.getId()));
88 writePublished(info.getCreationDate());
89 writeTitle(info.getName());
90 writeUpdated(info.getLastModificationDate());
91
92 writeContent(contentSrc, contentType);
93
94 JaxBHelper.marshal(JaxBHelper.CMIS_EXTRA_OBJECT_FACTORY.createObject(objectJaxb), getWriter(), true);
95
96 writePathSegment(pathSegment);
97 writeRelativePathSegment(relativePathSegment);
98 }
99
100
101
102
103 public void writeDeletedObject(ObjectData object) throws XMLStreamException, JAXBException {
104 CmisObjectType objectJaxb = convert(object);
105 if (objectJaxb == null) {
106 return;
107 }
108
109 long now = System.currentTimeMillis();
110
111 writeAuthor(DEFAULT_AUTHOR);
112 writeId(generateAtomId(object.getId()));
113 writePublished(now);
114 writeTitle(object.getId());
115 writeUpdated(now);
116
117 JaxBHelper.marshal(JaxBHelper.CMIS_EXTRA_OBJECT_FACTORY.createObject(objectJaxb), getWriter(), true);
118 }
119
120
121
122
123
124
125 public void writeType(TypeDefinition type) throws XMLStreamException, JAXBException {
126 CmisTypeDefinitionType typeJaxb = convert(type);
127 if (typeJaxb == null) {
128 return;
129 }
130
131 long now = System.currentTimeMillis();
132
133 writeAuthor(DEFAULT_AUTHOR);
134 writeId(generateAtomId(type.getId()));
135 writeTitle(type.getDisplayName());
136 writeUpdated(now);
137
138 JaxBHelper.marshal(JaxBHelper.CMIS_EXTRA_OBJECT_FACTORY.createTypeDefinition(typeJaxb), getWriter(), true);
139 }
140
141
142
143
144 public void writeContent(String src, String type) throws XMLStreamException {
145 if (src == null) {
146 return;
147 }
148
149 XMLStreamWriter xsw = getWriter();
150 xsw.writeStartElement(Constants.NAMESPACE_ATOM, "content");
151
152 xsw.writeAttribute("src", src);
153 if (type != null) {
154 xsw.writeAttribute("type", type);
155 }
156
157 xsw.writeEndElement();
158 }
159 }