diff -ruN -x target -x bin legacy/component/src/java/org/sakaiproject/component/legacy/content/BaseContentService.java ../sakai-src_2-1-2/legacy/component/src/java/org/sakaiproject/component/legacy/content/BaseContentService.java --- legacy/component/src/java/org/sakaiproject/component/legacy/content/BaseContentService.java 2006-04-07 19:22:30.000000000 +0100 +++ ../sakai-src_2-1-2/legacy/component/src/java/org/sakaiproject/component/legacy/content/BaseContentService.java 2006-04-28 16:42:30.000000000 +0100 @@ -30,6 +30,7 @@ import org.sakaiproject.api.kernel.session.SessionBindingEvent; import org.sakaiproject.api.kernel.session.SessionBindingListener; import org.sakaiproject.api.kernel.session.cover.SessionManager; +import org.sakaiproject.api.kernel.thread_local.cover.ThreadLocalManager; import org.sakaiproject.api.kernel.tool.cover.ToolManager; import org.sakaiproject.component.legacy.notification.SiteEmailNotificationContent; import org.sakaiproject.exception.*; @@ -96,6 +97,49 @@ /** 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; + +/* + * registers the specified ContentResourceHanlder ch as one special content handler in this + * content service + * @param ch The ContentResourceHandler to be registered + */ + public void registerContentHandler(ContentResourceHandler ch) { + if (specialContentHandler == null) { + specialContentHandler = new ArrayList(); + } + if (ch != null) + specialContentHandler.add(ch); + } + +/* + * deregisters the specified ContentResourceHandler ch from this content service's special + * content handler list + * @param ch the ContentResourceHandler to be deregistered +*/ + public void deRegisterCH(ContentResourceHandler ch) { + if (ch == null) + return; + if(specialContentHandler != null){ + specialContentHandler.remove(ch); + } + } + +/* + * creates a phantom ContentResouce without real content stored in the backend data storage + * with given id and ResourceContnentHandler rch. + * @param id The id of Content Resource being created + * @param rch specific content handler for this new created ContentResource +*/ + 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; @@ -340,6 +384,7 @@ { try { + specialContentHandler = new ArrayList(); m_relativeAccessPoint = REFERENCE_ROOT; // construct a storage helper and read @@ -2263,11 +2308,26 @@ else { resource = m_storage.getResource(id); - + // cache it (hit or miss) m_cache.put(key, resource); } } + + // Process the find request through the ContentResource handler this conent hosting service + // has first + // Xuan Added + if(specialContentHandler == null) + System.out.println("God, it's null"); + for ( Iterator i = specialContentHandler.iterator(); i.hasNext(); ) { + ContentResourceHandler crh = (ContentResourceHandler) i.next(); + resource = crh.verifyContent(id, resource); + if(resource != null){ + break; + } + } + + //:~) Xuan Added End return resource; @@ -4185,12 +4245,19 @@ public void handleAccess(HttpServletRequest req, HttpServletResponse res, Reference ref, Collection copyrightAcceptedRefs) throws PermissionException, IdUnusedException, ServerOverloadException, CopyrightException { + // + // Added by Xuan + ThreadLocalManager.set("contentplugin.request", req); + ThreadLocalManager.set("contentplugin.response", res); + // End Added Xuan + // if the id is null, the request was for just ".../content" String refId = ref.getId(); if (refId == null) refId = ""; // test if the given reference is a resource - if (m_storage.checkResource(refId)) +// if (m_storage.checkResource(refId)) + if(!refId.endsWith(Entity.SEPARATOR)) { handleAccessResource(req, res, ref, copyrightAcceptedRefs); return; @@ -6757,6 +6824,8 @@ /** The file system path, post root, for file system stored body binary. */ protected String m_filePath = null; + + private ResourceContentHandler m_resourceContentHandler = null; /** * Construct. @@ -6842,6 +6911,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. * @@ -7018,8 +7097,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; } @@ -7036,13 +7119,17 @@ { InputStream rv = null; - if (m_body != null) - { - rv = new ByteArrayInputStream(m_body); - } - else - { - rv = m_storage.streamResourceBody(this); + if ( m_resourceContentHandler != null ) { + rv = m_resourceContentHandler.streamResourceBody(); + } else { + if (m_body != null) + { + rv = new ByteArrayInputStream(m_body); + } + else + { + rv = m_storage.streamResourceBody(this); + } } return rv; diff -ruN -x target -x bin legacy/tools/src/java/org/sakaiproject/tool/content/ResourcesAction.java ../sakai-src_2-1-2/legacy/tools/src/java/org/sakaiproject/tool/content/ResourcesAction.java --- legacy/tools/src/java/org/sakaiproject/tool/content/ResourcesAction.java 2006-04-07 19:22:24.000000000 +0100 +++ ../sakai-src_2-1-2/legacy/tools/src/java/org/sakaiproject/tool/content/ResourcesAction.java 2006-04-27 18:33:59.000000000 +0100 @@ -4479,6 +4479,7 @@ catch(RuntimeException e) { logger.error("ResourcesAction.createFiles ***** Unknown Exception ***** " + e.getMessage()); + e.printStackTrace(); alerts.add(rb.getString("failed")); continue outerloop; }