]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
a90f709f707897bec1a0b75825475f35bb86876a
[tmp/jakarta-migration.git] /
1 /**
2  *  This document is a part of the source code and related artifacts
3  *  for CollectionSpace, an open source collections management system
4  *  for museums and related institutions:
5
6  *  http://www.collectionspace.org
7  *  http://wiki.collectionspace.org
8
9  *  Copyright 2009 University of California at Berkeley
10
11  *  Licensed under the Educational Community License (ECL), Version 2.0.
12  *  You may not use this file except in compliance with this License.
13
14  *  You may obtain a copy of the ECL 2.0 License at
15
16  *  https://source.collectionspace.org/collection-space/LICENSE.txt
17
18  *  Unless required by applicable law or agreed to in writing, software
19  *  distributed under the License is distributed on an "AS IS" BASIS,
20  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  *  See the License for the specific language governing permissions and
22  *  limitations under the License.
23  */
24 package org.collectionspace.services.publicitem.nuxeo;
25
26 import javax.ws.rs.core.UriInfo;
27
28 import org.collectionspace.services.PublicitemsCommonJAXBSchema;
29 import org.collectionspace.services.article.PublicitemsCommon;
30 import org.collectionspace.services.client.PublicItemClient;
31 import org.collectionspace.services.common.document.DocumentWrapper;
32 import org.collectionspace.services.nuxeo.client.java.DocHandlerBase;
33 import org.nuxeo.ecm.core.api.DocumentModel;
34
35 /** ArticleDocumentModelHandler
36  *  $LastChangedRevision$
37  *  $LastChangedDate$
38  */
39 public class PublicItemDocumentModelHandler
40         extends DocHandlerBase<PublicitemsCommon> {
41         
42         @Override
43         public void fillAllParts(DocumentWrapper<DocumentModel> wrapDoc, Action action) throws Exception {
44                 //
45                 // Call our parent's implementation first to fill out most of the document model properties
46                 //
47                 super.fillAllParts(wrapDoc, action);
48                 
49                 //
50                 // Since we didn't know the CSID when we created the publicly accessible URL we need to
51                 // add it now.
52                 //
53                 DocumentModel documentModel = wrapDoc.getWrappedObject();
54                 String url = (String) documentModel.getProperty(PublicItemClient.SERVICE_COMMON_PART_NAME,
55                                 PublicitemsCommonJAXBSchema.ITEM_CONTENT_URI);
56                 url = url.replace(PublicItemClient.CSID_PATH_PARAM_VAR, documentModel.getName());
57                 documentModel.setProperty(PublicItemClient.SERVICE_COMMON_PART_NAME,
58                                 PublicitemsCommonJAXBSchema.ITEM_CONTENT_URI, url);
59         }
60         
61     @Override
62     public void extractAllParts(DocumentWrapper<DocumentModel> wrapDoc)
63             throws Exception {
64         //
65         // Replace the URI with a fully qualified URL
66         //
67         DocumentModel documentModel = wrapDoc.getWrappedObject();
68                 String itemContentUri = (String) documentModel.getProperty(PublicItemClient.SERVICE_COMMON_PART_NAME,
69                                 PublicitemsCommonJAXBSchema.ITEM_CONTENT_URI);        
70         UriInfo uriInfo = this.getServiceContext().getUriInfo();
71         String baseUrl = uriInfo.getBaseUri().toString();
72         String url = String.format("%s%s", baseUrl, itemContentUri);
73                 documentModel.setProperty(PublicItemClient.SERVICE_COMMON_PART_NAME,
74                                 PublicitemsCommonJAXBSchema.ITEM_CONTENT_URI, url);
75     }   
76 }
77