001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/metaobj/tags/sakai_2-4-1/metaobj-impl/api-impl/src/java/org/sakaiproject/metaobj/shared/mgt/EntityProducerBase.java $
003: * $Id: EntityProducerBase.java 15104 2006-09-21 13:40:06Z ggolden@umich.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.metaobj.shared.mgt;
021:
022: import java.util.Collection;
023: import java.util.List;
024: import java.util.Map;
025: import java.util.Set;
026: import java.util.Stack;
027:
028: import org.sakaiproject.component.cover.ServerConfigurationService;
029: import org.sakaiproject.content.api.ContentResource;
030: import org.sakaiproject.entity.api.Entity;
031: import org.sakaiproject.entity.api.EntityManager;
032: import org.sakaiproject.entity.api.EntityProducer;
033: import org.sakaiproject.entity.api.HttpAccess;
034: import org.sakaiproject.entity.api.Reference;
035: import org.sakaiproject.entity.api.ResourceProperties;
036: import org.sakaiproject.util.Validator;
037: import org.w3c.dom.Document;
038: import org.w3c.dom.Element;
039:
040: /**
041: * Created by IntelliJ IDEA.
042: * User: John Ellis
043: * Date: Nov 7, 2005
044: * Time: 1:40:10 PM
045: * To change this template use File | Settings | File Templates.
046: */
047: public abstract class EntityProducerBase implements EntityProducer {
048:
049: private EntityManager entityManager;
050: private HttpAccess httpAccess;
051:
052: public boolean willArchiveMerge() {
053: return false;
054: }
055:
056: public String archive(String siteId, Document doc, Stack stack,
057: String archivePath, List attachments) {
058: return null;
059: }
060:
061: public String merge(String siteId, Element root,
062: String archivePath, String fromSiteId, Map attachmentNames,
063: Map userIdTrans, Set userListAllowImport) {
064: return null;
065: }
066:
067: public boolean parseEntityReference(String reference, Reference ref) {
068: if (reference.startsWith(getContext())) {
069:
070: // removing our label, we expose the wrapped Entity reference
071: String wrappedRef = reference
072: .substring(getLabel().length() + 1);
073:
074: // make a reference for this
075: Reference wrapped = entityManager.newReference(wrappedRef);
076:
077: // use the wrapped id, container and context - our own type (no subtype)
078: ref.set(getLabel(), null, wrapped.getId(), wrapped
079: .getContainer(), wrapped.getContext());
080:
081: return true;
082: }
083: return false;
084: }
085:
086: protected String getContext() {
087: return Entity.SEPARATOR + getLabel() + Entity.SEPARATOR;
088: }
089:
090: public String getEntityDescription(Reference ref) {
091: return ref.getId();
092: }
093:
094: public ResourceProperties getEntityResourceProperties(Reference ref) {
095: ContentEntityWrapper entity = getContentEntityWrapper(ref);
096:
097: return entity.getBase().getProperties();
098: }
099:
100: protected ContentEntityWrapper getContentEntityWrapper(Reference ref) {
101: String wholeRef = ref.getReference();
102: ReferenceParser parser = parseReference(wholeRef);
103: ContentResource base = (ContentResource) entityManager
104: .newReference(parser.getRef()).getEntity();
105: return new ContentEntityWrapper(base, wholeRef);
106: }
107:
108: protected ReferenceParser parseReference(String wholeRef) {
109: return new ReferenceParser(wholeRef, this );
110: }
111:
112: public Entity getEntity(Reference ref) {
113: return getContentEntityWrapper(ref);
114: }
115:
116: public String getEntityUrl(Reference ref) {
117: return ServerConfigurationService.getAccessUrl()
118: + Validator.escapeUrl(ref.getReference());
119: }
120:
121: public Collection getEntityAuthzGroups(Reference ref, String userId) {
122: return null;
123: }
124:
125: public EntityManager getEntityManager() {
126: return entityManager;
127: }
128:
129: public void setEntityManager(EntityManager entityManager) {
130: this .entityManager = entityManager;
131: }
132:
133: public HttpAccess getHttpAccess() {
134: return httpAccess;
135: }
136:
137: public void setHttpAccess(HttpAccess httpAccess) {
138: this .httpAccess = httpAccess;
139: }
140:
141: public void destroy() {
142:
143: }
144:
145: }
|