diff -ruN official/legacy/component/src/java/org/sakaiproject/component/legacy/content/BaseContentService.java xuan/legacy/component/src/java/org/sakaiproject/component/legacy/content/BaseContentService.java --- official/legacy/component/src/java/org/sakaiproject/component/legacy/content/BaseContentService.java 2006-02-09 00:02:03.000000000 +0000 +++ xuan/legacy/component/src/java/org/sakaiproject/component/legacy/content/BaseContentService.java 2006-04-11 18:01:56.718541448 +0100 @@ -78,9 +78,11 @@ import org.sakaiproject.service.legacy.authzGroup.cover.AuthzGroupService; import org.sakaiproject.service.legacy.content.ContentCollection; import org.sakaiproject.service.legacy.content.ContentCollectionEdit; +import org.sakaiproject.service.legacy.content.ContentResourceHandler; import org.sakaiproject.service.legacy.content.ContentHostingService; import org.sakaiproject.service.legacy.content.ContentResource; import org.sakaiproject.service.legacy.content.ContentResourceEdit; +import org.sakaiproject.service.legacy.content.ResourceContentHandler; import org.sakaiproject.service.legacy.content.cover.ContentTypeImageService; import org.sakaiproject.service.legacy.entity.Edit; import org.sakaiproject.service.legacy.entity.Entity; @@ -132,6 +134,26 @@ /** Maximum number of characters in a valid resource-id */ protected static final int MAXIMUM_RESOURCE_ID_LENGTH = 255; + /* Added member by Xuan*/ + protected List specialContentHandler = null; + + public void registerContentHandler(ContentResourceHandler ch) { + if (specialContentHandler == null) { + specialContentHandler = new ArrayList(); + } + if (ch != null) + specialContentHandler.add(ch); + } + + public ContentResourceEdit newContentResource(String id, ResourceContentHandler rch) { + ContentResourceEdit cre = new BaseResourceEdit(id); + cre.setContentHandler(rch); + return cre; + } + + /* END - Added member by Xuan */ + + /** The initial portion of a relative access point URL. */ protected String m_relativeAccessPoint = null; @@ -308,6 +330,9 @@ { try { + specialContentHandler = new ArrayList(); +// new ContentPackageResourceWrapper(this).init(); + m_relativeAccessPoint = REFERENCE_ROOT; // construct a storage helper and read @@ -2163,7 +2188,19 @@ if ((!m_caching) || (m_cache == null) || (m_cache.disabled())) { // TODO: current service caching + resource = m_storage.getResource(id); + + // Process the find request through the ContentResource handler this conent hosting service + // has first + // Xuan Added + for ( Iterator i = specialContentHandler.iterator(); i.hasNext(); ) { + ContentResourceHandler crh = (ContentResourceHandler) i.next(); + resource = crh.verifyContent(id, resource); + if(resource != null){ + break; + } + }//:~) Xuan Added End } else @@ -2182,6 +2219,14 @@ else { resource = m_storage.getResource(id); + + for ( Iterator i = specialContentHandler.iterator(); i.hasNext(); ) { + ContentResourceHandler crh = (ContentResourceHandler) i.next(); + resource = crh.verifyContent(id, resource); + if(resource != null){ + break; + } + } // cache it (hit or miss) m_cache.put(key, resource); @@ -3753,6 +3798,14 @@ public void handleAccess(HttpServletRequest req, HttpServletResponse res, Reference ref, Collection copyrightAcceptedRefs) throws PermissionException, IdUnusedException, ServerOverloadException, CopyrightException { + // preprocess the request by the content resource handler + // Added by Xuan + for(Iterator it = specialContentHandler.iterator(); it.hasNext(); ){ + ContentResourceHandler crh = (ContentResourceHandler) it.next(); + crh.checkRequest(req, res); + } + // End Added Xuan + // we only access resources, not collections if (ref.getId().endsWith(Entity.SEPARATOR)) throw new IdUnusedException(ref.getReference()); @@ -3785,7 +3838,7 @@ // for url content type, encode a redirect to the body URL if (contentType.equalsIgnoreCase(ResourceProperties.TYPE_URL)) - { + { byte[] content = resource.getContent(); if ((content == null) || (content.length == 0)) { @@ -6370,7 +6423,7 @@ /********************************************************************************************************************************************************************************************************************************************************** * ContentResource implementation *********************************************************************************************************************************************************************************************************************************************************/ - + public class BaseResourceEdit implements ContentResourceEdit, SessionBindingListener { /** The resource id. */ @@ -6403,6 +6456,8 @@ /** The file system path, post root, for file system stored body binary. */ protected String m_filePath = null; + private ResourceContentHandler m_resourceContentHandler = null; + /** * Construct. * @@ -6487,6 +6542,16 @@ } // set + public ResourceContentHandler getContentHandler() { + return m_resourceContentHandler; + } + + public void setContentHandler(ResourceContentHandler resourceContentHandler) { + m_resourceContentHandler = resourceContentHandler; + if(m_resourceContentHandler != null) + m_body = m_resourceContentHandler.getResourceBody(); + } + /** * Construct from information in XML in a DOM element. * @@ -6632,8 +6697,12 @@ if ((rv == null) && (m_contentLength > 0)) { - // TODO: we do not store the body with the object, so as not to cache the body bytes -ggolden - rv = m_storage.getResourceBody(this); + if (m_resourceContentHandler != null ) { + rv = m_resourceContentHandler .getResourceBody(); + } else { + // TODO: we do not store the body with the object, so as not to cache the body bytes -ggolden + rv = m_storage.getResourceBody(this); + } // m_body = rv; } @@ -6649,14 +6718,19 @@ public InputStream streamContent() throws ServerOverloadException { InputStream rv = null; + + if ( m_resourceContentHandler != null ) { + rv = m_resourceContentHandler.streamResourceBody(); + } else { - if (m_body != null) - { - rv = new ByteArrayInputStream(m_body); - } - else - { - rv = m_storage.streamResourceBody(this); + if (m_body != null) + { + rv = new ByteArrayInputStream(m_body); + } + else + { + rv = m_storage.streamResourceBody(this); + } } return rv; @@ -6877,7 +6951,7 @@ /********************************************************************************************************************************************************************************************************************************************************** * Storage implementation *********************************************************************************************************************************************************************************************************************************************************/ - + protected interface Storage { /** diff -ruN official/legacy-service/service/src/java/org/sakaiproject/service/legacy/content/ContentHostingService.java xuan/legacy-service/service/src/java/org/sakaiproject/service/legacy/content/ContentHostingService.java --- official/legacy-service/service/src/java/org/sakaiproject/service/legacy/content/ContentHostingService.java 2006-02-09 00:01:49.000000000 +0000 +++ xuan/legacy-service/service/src/java/org/sakaiproject/service/legacy/content/ContentHostingService.java 2006-03-30 16:43:53.000000000 +0100 @@ -1174,4 +1174,13 @@ * @return The default dropbox collection display name for the site. */ public String getDropboxDisplayName(String siteId); + + + // Xuan Added Method + // Registers a ContentHandler in this content service + + public void registerContentHandler(ContentResourceHandler ch); + public ContentResourceEdit newContentResource(String id, ResourceContentHandler rch); + // End. Xuan added + } diff -ruN official/legacy-service/service/src/java/org/sakaiproject/service/legacy/content/ContentResourceEdit.java xuan/legacy-service/service/src/java/org/sakaiproject/service/legacy/content/ContentResourceEdit.java --- official/legacy-service/service/src/java/org/sakaiproject/service/legacy/content/ContentResourceEdit.java 2006-02-09 00:01:49.000000000 +0000 +++ xuan/legacy-service/service/src/java/org/sakaiproject/service/legacy/content/ContentResourceEdit.java 2006-03-30 16:31:56.000000000 +0100 @@ -55,6 +55,12 @@ * @param content An array containing the bytes of the resource's content. */ public void setContent(byte[] content); + + + // Xuan added method + public void setContentHandler(ResourceContentHandler handler); + // End Xuan Added + } // ContentResourceEdit diff -ruN official/legacy-service/service/src/java/org/sakaiproject/service/legacy/content/ContentResourceHandler.java xuan/legacy-service/service/src/java/org/sakaiproject/service/legacy/content/ContentResourceHandler.java --- official/legacy-service/service/src/java/org/sakaiproject/service/legacy/content/ContentResourceHandler.java 1970-01-01 01:00:00.000000000 +0100 +++ xuan/legacy-service/service/src/java/org/sakaiproject/service/legacy/content/ContentResourceHandler.java 2006-04-11 18:11:21.374700664 +0100 @@ -0,0 +1,59 @@ +package org.sakaiproject.service.legacy.content; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.sakaiproject.service.legacy.entity.Entity; + + + +public interface ContentResourceHandler { + + public static final String CONTENT_REFERENCE_ROOT = Entity.SEPARATOR + "content"; + public static final String IMS_CP_MIMETYPE = "ims/cp"; + + public static final String IMS_CP_FLAG = ".ims"; + + public static final String IMS_CP_DEFAULTMANIFEST = "/imsmanifest.xml"; + + /* + * Handles the resource returned by ContenHostingService, if resource is NOT null. Otherwise + * processes the id and returns appropriate resource for this ContentResourceHandler. + * @param id + * @param resource The default resource returned by ContentHostingService for id, may be + * NULL + * @return The resource corresponding for id or NULL when resource doesn't exit or isn't + * supported by this Handler + * */ + public ContentResource verifyContent(String id, ContentResource resource); + + /* + * Before verify the ContentResource, the HttpServletRequest and HttpServletResponse for this + * resource can be processed here. For instance, the parameters encoded in the request URL. + * @param request The HttpServletRequest for this request + * @param response The HttpServletResponse for this request + */ + public void checkRequest( HttpServletRequest request, HttpServletResponse response); + + /* + * Init method for this ContentResourceHandler. Generally, the handler registers itself with the + * ContentHostingService. + */ + public void init(); + + /* + * destroy method for this ContentResourceHanlder. + */ + public void destroy(); + + /* + * Getter method for the ContentHostingService + */ + public ContentHostingService getService(); + + /* + * Setter method for the ContentHostingService. The handler holds a reference to + * the ContentHostingService in Sakai + */ + public void setService(ContentHostingService service); +} diff -ruN official/legacy-service/service/src/java/org/sakaiproject/service/legacy/content/ResourceContentHandler.java xuan/legacy-service/service/src/java/org/sakaiproject/service/legacy/content/ResourceContentHandler.java --- official/legacy-service/service/src/java/org/sakaiproject/service/legacy/content/ResourceContentHandler.java 1970-01-01 01:00:00.000000000 +0100 +++ xuan/legacy-service/service/src/java/org/sakaiproject/service/legacy/content/ResourceContentHandler.java 2006-03-30 16:28:48.000000000 +0100 @@ -0,0 +1,10 @@ +package org.sakaiproject.service.legacy.content; + +import java.io.InputStream; + +public interface ResourceContentHandler { + + public byte[] getResourceBody(); + + public InputStream streamResourceBody(); +}