View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.chemistry.opencmis.server.impl.atompub;
20  
21  import org.apache.chemistry.opencmis.commons.data.RepositoryInfo;
22  import org.apache.chemistry.opencmis.commons.impl.Constants;
23  import static org.apache.chemistry.opencmis.commons.impl.Converter.convert;
24  import org.apache.chemistry.opencmis.commons.impl.JaxBHelper;
25  import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisRepositoryInfoType;
26  
27  import javax.xml.bind.JAXBException;
28  import javax.xml.stream.XMLStreamException;
29  import javax.xml.stream.XMLStreamWriter;
30  
31  
32  /**
33   * Service document class.
34   *
35   * @author <a href="mailto:fmueller@opentext.com">Florian M&uuml;ller</a>
36   *
37   */
38  public class ServiceDocument extends AtomDocumentBase
39  {
40      public ServiceDocument(  )
41      {
42      }
43  
44      public void startServiceDocument(  ) throws XMLStreamException
45      {
46          XMLStreamWriter xsw = getWriter(  );
47          xsw.writeStartElement( Constants.NAMESPACE_APP, "service" );
48          writeNamespace( Constants.NAMESPACE_APP );
49          writeNamespace( Constants.NAMESPACE_ATOM );
50          writeNamespace( Constants.NAMESPACE_CMIS );
51          writeNamespace( Constants.NAMESPACE_RESTATOM );
52      }
53  
54      public void endServiceDocument(  ) throws XMLStreamException
55      {
56          getWriter(  ).writeEndElement(  );
57      }
58  
59      public void startWorkspace( String title ) throws XMLStreamException
60      {
61          getWriter(  ).writeStartElement( Constants.NAMESPACE_APP, "workspace" );
62          writeSimpleTag( Constants.NAMESPACE_ATOM, "title", title );
63      }
64  
65      public void endWorkspace(  ) throws XMLStreamException
66      {
67          getWriter(  ).writeEndElement(  );
68      }
69  
70      public void writeRepositoryInfo( RepositoryInfo repInfo )
71          throws JAXBException
72      {
73          CmisRepositoryInfoType repInfoJaxb = convert( repInfo );
74  
75          if ( repInfoJaxb == null )
76          {
77              return;
78          }
79  
80          JaxBHelper.marshal( JaxBHelper.CMIS_EXTRA_OBJECT_FACTORY.createRepositoryInfo( repInfoJaxb ), getWriter(  ),
81              true );
82      }
83  
84      public void writeUriTemplate( String template, String type, String mediatype )
85          throws XMLStreamException
86      {
87          XMLStreamWriter xsw = getWriter(  );
88  
89          xsw.writeStartElement( Constants.NAMESPACE_RESTATOM, "uritemplate" );
90          writeSimpleTag( Constants.NAMESPACE_RESTATOM, "template", template );
91          writeSimpleTag( Constants.NAMESPACE_RESTATOM, "type", type );
92          writeSimpleTag( Constants.NAMESPACE_RESTATOM, "mediatype", mediatype );
93          xsw.writeEndElement(  );
94      }
95  }