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 org.apache.chemistry.opencmis.commons.data.ObjectData;
22  import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
23  import org.apache.chemistry.opencmis.commons.impl.Constants;
24  import static org.apache.chemistry.opencmis.commons.impl.Converter.convert;
25  import org.apache.chemistry.opencmis.commons.impl.JaxBHelper;
26  import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisObjectType;
27  import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisTypeDefinitionType;
28  import org.apache.chemistry.opencmis.commons.server.ObjectInfo;
29  
30  import javax.xml.bind.JAXBException;
31  import javax.xml.stream.XMLStreamException;
32  import javax.xml.stream.XMLStreamWriter;
33  
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  
52      public AtomEntry( XMLStreamWriter writer )
53      {
54          setWriter( writer );
55      }
56  
57      
58  
59  
60      public void startEntry( boolean isRoot ) throws XMLStreamException
61      {
62          getWriter(  ).writeStartElement( Constants.NAMESPACE_ATOM, "entry" );
63  
64          if ( isRoot )
65          {
66              writeNamespace( Constants.NAMESPACE_ATOM );
67              writeNamespace( Constants.NAMESPACE_CMIS );
68              writeNamespace( Constants.NAMESPACE_RESTATOM );
69              writeNamespace( Constants.NAMESPACE_APP );
70          }
71      }
72  
73      
74  
75  
76      public void endEntry(  ) throws XMLStreamException
77      {
78          getWriter(  ).writeEndElement(  );
79      }
80  
81      
82  
83  
84      public void writeObject( ObjectData object, ObjectInfo info, String contentSrc, String contentType,
85          String pathSegment, String relativePathSegment )
86          throws XMLStreamException, JAXBException
87      {
88          CmisObjectType objectJaxb = convert( object );
89  
90          if ( objectJaxb == null )
91          {
92              return;
93          }
94  
95          writeAuthor( info.getCreatedBy(  ) );
96          writeId( generateAtomId( info.getId(  ) ) );
97          writePublished( info.getCreationDate(  ) );
98          writeTitle( info.getName(  ) );
99          writeUpdated( info.getLastModificationDate(  ) );
100 
101         writeContent( contentSrc, contentType );
102 
103         JaxBHelper.marshal( JaxBHelper.CMIS_EXTRA_OBJECT_FACTORY.createObject( objectJaxb ), getWriter(  ), true );
104 
105         writePathSegment( pathSegment );
106         writeRelativePathSegment( relativePathSegment );
107     }
108 
109     
110 
111 
112     public void writeDeletedObject( ObjectData object )
113         throws XMLStreamException, JAXBException
114     {
115         CmisObjectType objectJaxb = convert( object );
116 
117         if ( objectJaxb == null )
118         {
119             return;
120         }
121 
122         long now = System.currentTimeMillis(  );
123 
124         writeAuthor( DEFAULT_AUTHOR );
125         writeId( generateAtomId( object.getId(  ) ) );
126         writePublished( now );
127         writeTitle( object.getId(  ) );
128         writeUpdated( now );
129 
130         JaxBHelper.marshal( JaxBHelper.CMIS_EXTRA_OBJECT_FACTORY.createObject( objectJaxb ), getWriter(  ), true );
131     }
132 
133     
134 
135 
136 
137 
138     public void writeType( TypeDefinition type ) throws XMLStreamException, JAXBException
139     {
140         CmisTypeDefinitionType typeJaxb = convert( type );
141 
142         if ( typeJaxb == null )
143         {
144             return;
145         }
146 
147         long now = System.currentTimeMillis(  );
148 
149         writeAuthor( DEFAULT_AUTHOR );
150         writeId( generateAtomId( type.getId(  ) ) );
151         writeTitle( type.getDisplayName(  ) );
152         writeUpdated( now );
153 
154         JaxBHelper.marshal( JaxBHelper.CMIS_EXTRA_OBJECT_FACTORY.createTypeDefinition( typeJaxb ), getWriter(  ), true );
155     }
156 
157     
158 
159 
160     public void writeContent( String src, String type )
161         throws XMLStreamException
162     {
163         if ( src == null )
164         {
165             return;
166         }
167 
168         XMLStreamWriter xsw = getWriter(  );
169         xsw.writeStartElement( Constants.NAMESPACE_ATOM, "content" );
170 
171         xsw.writeAttribute( "src", src );
172 
173         if ( type != null )
174         {
175             xsw.writeAttribute( "type", type );
176         }
177 
178         xsw.writeEndElement(  );
179     }
180 }