Skip to content

Commit

Permalink
Merge pull request UbuntuEvangelist#461 from buckett/LSNBLDR-485
Browse files Browse the repository at this point in the history
LSNBLDR-485 Have content served through lessons wrapped.
  • Loading branch information
clhedrick committed Apr 29, 2015
2 parents ddec3e8 + 6c09c7f commit 89d297e
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -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 <code>null</code>.
* @return A new content resource wrapped up or if the original resource if no filters apply.
*/
ContentResource wrap(ContentResource resource);

}
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,7 @@
<entry key="oracle" ><ref bean="org.sakaiproject.content.impl.ContentServiceSqlOracle" /></entry>
</map>
</property>
<property name="outputFilters">
<list>
<ref bean="org.sakaiproject.content.impl.HtmlPageFilter"/>
</list>
</property>
<property name="contentFilterService" ref="org.sakaiproject.content.api.ContentFilterService"/>
</bean>

<bean id="org.sakaiproject.content.impl.CollectionAccessFormatter"
Expand Down Expand Up @@ -115,6 +111,15 @@
-->
</bean>

<bean id="org.sakaiproject.content.api.ContentFilterService"
class="org.sakaiproject.content.impl.ContentFilterServiceImpl">
<property name="outputFilters">
<list>
<ref bean="org.sakaiproject.content.impl.HtmlPageFilter"/>
</list>
</property>
</bean>

<bean id="org.sakaiproject.content.api.ContentResourceFilter.base"
class="org.sakaiproject.content.impl.BaseExtensionResourceFilter">
<property name="viewAll"> <value>true</value> </property>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ContentFilter> m_outputFilters = Collections.emptyList();

/**********************************************************************************************************************************************************************************************************************************************************
* Constructors, Dependencies and their setter methods
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -841,12 +842,7 @@ public void setConvertToContextQueryForCollectionSize(boolean convertToContextQu
this.convertToContextQueryForCollectionSize = convertToContextQueryForCollectionSize;
}

public void setOutputFilters(List<ContentFilter> outputFilters)
{
this.m_outputFilters = outputFilters;
}


/**********************************************************************************************************************************************************************************************************************************************************
* Init and Destroy
*********************************************************************************************************************************************************************************************************************************************************/
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ContentFilter> m_outputFilters = Collections.emptyList();

public void setOutputFilters(List<ContentFilter> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ simplePageBean.peerEvalAllowSelfGrade
<property name="contentHostingService"><ref bean="org.sakaiproject.content.api.ContentHostingService"/></property>
<property name="eventTrackingService"><ref bean="org.sakaiproject.event.api.EventTrackingService"/></property>
<property name="sessionManager"><ref bean="org.sakaiproject.tool.api.SessionManager"/></property>
<property name="contentFilterService"><ref bean="org.sakaiproject.content.api.ContentFilterService"/></property>

<property name="messageLocator" ref="messageLocator"/>
<property name="toolManager" ref="org.sakaiproject.tool.api.ActiveToolManager" />
Expand Down

0 comments on commit 89d297e

Please sign in to comment.