01: /**********************************************************************************
02: * $URL:https://source.sakaiproject.org/svn/osp/trunk/common/api-impl/src/java/org/theospi/portfolio/shared/mgt/ContentWrappedArtifactFinder.java $
03: * $Id:ContentWrappedArtifactFinder.java 9134 2006-05-08 20:28:42Z chmaurer@iupui.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2005, 2006 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.theospi.portfolio.shared.mgt;
21:
22: import org.sakaiproject.content.api.ContentResource;
23: import org.sakaiproject.metaobj.shared.mgt.ContentEntityUtil;
24: import org.sakaiproject.metaobj.shared.mgt.ContentEntityWrapper;
25: import org.sakaiproject.metaobj.shared.mgt.impl.FileArtifactFinder;
26: import org.sakaiproject.metaobj.shared.model.Artifact;
27: import org.sakaiproject.metaobj.shared.model.ContentResourceArtifact;
28: import org.sakaiproject.metaobj.shared.model.Id;
29: import org.theospi.portfolio.shared.intf.EntityContextFinder;
30:
31: /**
32: * Created by IntelliJ IDEA.
33: * User: John Ellis
34: * Date: Nov 7, 2005
35: * Time: 4:49:49 PM
36: * To change this template use File | Settings | File Templates.
37: */
38: public class ContentWrappedArtifactFinder extends FileArtifactFinder
39: implements EntityContextFinder {
40:
41: public Artifact load(Id artifactId) {
42: return super .load(artifactId);
43: }
44:
45: public Artifact loadInContext(Id artifactId, String context,
46: String siteId, String contextId) {
47: Artifact art = super .load(artifactId);
48:
49: if (art instanceof ContentResourceArtifact) {
50: return wrap((ContentResourceArtifact) art, context, siteId,
51: contextId);
52: }
53:
54: return art;
55: }
56:
57: protected Artifact wrap(
58: ContentResourceArtifact contentResourceArtifact,
59: String context, String siteId, String contextId) {
60: ContentResource resource = contentResourceArtifact.getBase();
61:
62: ContentResource wrapped = new ContentEntityWrapper(resource,
63: buildRef(context, siteId, contextId, resource));
64:
65: contentResourceArtifact.setBase(wrapped);
66:
67: return contentResourceArtifact;
68: }
69:
70: protected String buildRef(String context, String siteId,
71: String contextId, ContentResource resource) {
72: return ContentEntityUtil.getInstance().buildRef(context,
73: siteId, contextId, resource.getReference());
74: }
75:
76: }
|