diff --git a/kernel/api/src/main/java/org/sakaiproject/content/api/ContentFilterService.java b/kernel/api/src/main/java/org/sakaiproject/content/api/ContentFilterService.java new file mode 100644 index 000000000000..60c505fc8aad --- /dev/null +++ b/kernel/api/src/main/java/org/sakaiproject/content/api/ContentFilterService.java @@ -0,0 +1,18 @@ +package org.sakaiproject.content.api; + +/** + * This is a service that holds all the ContentFilters and allows streams to be filtered. + * It's exposed as a service so that tools serving up thier own content can do it in the + * same way as the kernel. + * @see ContentFilter + */ +public interface ContentFilterService { + + /** + * This applies all the filters defined to the supplied content resource. + * @param resource The content resource to wrap cannot be null. + * @return A new content resource wrapped up or if the original resource if no filters apply. + */ + ContentResource wrap(ContentResource resource); + +} diff --git a/kernel/kernel-component/src/main/webapp/WEB-INF/content-components.xml b/kernel/kernel-component/src/main/webapp/WEB-INF/content-components.xml index e793fcc2bad9..e54191d9557d 100644 --- a/kernel/kernel-component/src/main/webapp/WEB-INF/content-components.xml +++ b/kernel/kernel-component/src/main/webapp/WEB-INF/content-components.xml @@ -71,11 +71,7 @@ - - - - - + + + + + + + + + true diff --git a/kernel/kernel-impl/src/main/java/org/sakaiproject/content/impl/BaseContentService.java b/kernel/kernel-impl/src/main/java/org/sakaiproject/content/impl/BaseContentService.java index 95cff0d86be0..9d2ae383ba2f 100644 --- a/kernel/kernel-impl/src/main/java/org/sakaiproject/content/impl/BaseContentService.java +++ b/kernel/kernel-impl/src/main/java/org/sakaiproject/content/impl/BaseContentService.java @@ -83,19 +83,7 @@ import org.sakaiproject.authz.api.SecurityService; import org.sakaiproject.component.api.ServerConfigurationService; import org.sakaiproject.conditions.api.ConditionService; -import org.sakaiproject.content.api.ContentCollection; -import org.sakaiproject.content.api.ContentCollectionEdit; -import org.sakaiproject.content.api.ContentEntity; -import org.sakaiproject.content.api.ContentFilter; -import org.sakaiproject.content.api.ContentHostingHandler; -import org.sakaiproject.content.api.ContentHostingService; -import org.sakaiproject.content.api.ContentResource; -import org.sakaiproject.content.api.ContentResourceEdit; -import org.sakaiproject.content.api.ContentTypeImageService; -import org.sakaiproject.content.api.GroupAwareEdit; -import org.sakaiproject.content.api.GroupAwareEntity; -import org.sakaiproject.content.api.ResourceType; -import org.sakaiproject.content.api.ResourceTypeRegistry; +import org.sakaiproject.content.api.*; import org.sakaiproject.content.api.GroupAwareEntity.AccessMode; import org.sakaiproject.content.api.providers.SiteContentAdvisor; import org.sakaiproject.content.api.providers.SiteContentAdvisorProvider; @@ -279,8 +267,6 @@ public abstract class BaseContentService implements ContentHostingService, Cache /** Optional set of folders just within the m_bodyPath to distribute files among. */ protected String[] m_bodyVolumes = null; - - protected List m_outputFilters = Collections.emptyList(); /********************************************************************************************************************************************************************************************************************************************************** * Constructors, Dependencies and their setter methods @@ -486,6 +472,21 @@ public void setCollectionAccessFormatter(CollectionAccessFormatter service) m_collectionAccessFormatter = service; } + /** Dependency: ContentFilterService */ + protected ContentFilterService m_contentFilterService; + + /** + * Dependency: ContentFilterService. + * + * @param service + * The ContentFilterService. + */ + public void setContentFilterService(ContentFilterService service) + { + m_contentFilterService = service; + } + + /** * Set the site quota. * @@ -841,12 +842,7 @@ public void setConvertToContextQueryForCollectionSize(boolean convertToContextQu this.convertToContextQueryForCollectionSize = convertToContextQueryForCollectionSize; } - public void setOutputFilters(List outputFilters) - { - this.m_outputFilters = outputFilters; - } - /********************************************************************************************************************************************************************************************************************************************************** * Init and Destroy *********************************************************************************************************************************************************************************************************************************************************/ @@ -6859,11 +6855,8 @@ protected void handleAccessResource(HttpServletRequest req, HttpServletResponse } // Wrap up the resource if we need to. - for (ContentFilter filter: m_outputFilters) - { - resource = filter.wrap(resource); - } - + resource = m_contentFilterService.wrap(resource); + // Set some headers to tell browsers to revalidate and check for updated files res.addHeader("Cache-Control", "must-revalidate, private"); res.addHeader("Expires", "-1"); diff --git a/kernel/kernel-impl/src/main/java/org/sakaiproject/content/impl/ContentFilterServiceImpl.java b/kernel/kernel-impl/src/main/java/org/sakaiproject/content/impl/ContentFilterServiceImpl.java new file mode 100644 index 000000000000..63031d8fc722 --- /dev/null +++ b/kernel/kernel-impl/src/main/java/org/sakaiproject/content/impl/ContentFilterServiceImpl.java @@ -0,0 +1,31 @@ +package org.sakaiproject.content.impl; + +import org.sakaiproject.content.api.ContentFilter; +import org.sakaiproject.content.api.ContentFilterService; +import org.sakaiproject.content.api.ContentResource; + +import java.util.Collections; +import java.util.List; + +/** + * A simple implementation of the output filtering. + */ +public class ContentFilterServiceImpl implements ContentFilterService { + + protected List m_outputFilters = Collections.emptyList(); + + public void setOutputFilters(List outputFilters) + { + this.m_outputFilters = outputFilters; + } + + @Override + public ContentResource wrap(ContentResource resource) { + // Wrap up the resource if we need to. + for (ContentFilter filter: m_outputFilters) + { + resource = filter.wrap(resource); + } + return resource; + } +} diff --git a/lessonbuilder/tool/src/java/org/sakaiproject/lessonbuildertool/service/LessonBuilderAccessService.java b/lessonbuilder/tool/src/java/org/sakaiproject/lessonbuildertool/service/LessonBuilderAccessService.java index d883f199f512..3cf8f5ac7ef8 100644 --- a/lessonbuilder/tool/src/java/org/sakaiproject/lessonbuildertool/service/LessonBuilderAccessService.java +++ b/lessonbuilder/tool/src/java/org/sakaiproject/lessonbuildertool/service/LessonBuilderAccessService.java @@ -54,6 +54,7 @@ import javax.crypto.spec.SecretKeySpec; import javax.xml.bind.DatatypeConverter; +import org.sakaiproject.content.api.ContentFilterService; import org.sakaiproject.memory.api.SimpleConfiguration; import org.sakaiproject.time.api.Time; import org.sakaiproject.time.cover.TimeService; @@ -189,6 +190,12 @@ public void setQuizEntity(Object e) { LessonEntity assignmentEntity = null; + ContentFilterService contentFilterService; + + public void setContentFilterService(ContentFilterService s) { + contentFilterService = s; + } + public void setAssignmentEntity(Object e) { assignmentEntity = (LessonEntity) e; } @@ -600,6 +607,9 @@ public void handleAccess(HttpServletRequest req, HttpServletResponse res, Refere throw new EntityCopyrightException(resource.getReference()); } try { + // Wrap it in any filtering needed. + resource = contentFilterService.wrap(resource); + // following cast is redundant is current kernels, but is needed for Sakai 2.6.1 long len = (long)resource.getContentLength(); String contentType = resource.getContentType(); diff --git a/lessonbuilder/tool/src/webapp/WEB-INF/applicationContext.xml b/lessonbuilder/tool/src/webapp/WEB-INF/applicationContext.xml index 7a3c091b95cb..cfcb53df7ebf 100644 --- a/lessonbuilder/tool/src/webapp/WEB-INF/applicationContext.xml +++ b/lessonbuilder/tool/src/webapp/WEB-INF/applicationContext.xml @@ -265,6 +265,7 @@ simplePageBean.peerEvalAllowSelfGrade +