use of org.apache.pluto.container.om.portlet.PortletDefinition in project uPortal by Jasig.
the class PortletCacheControlServiceImplTest method testDetermineCacheScopePortletDefinitionPrivate.
@Test
public void testDetermineCacheScopePortletDefinitionPrivate() {
MockHttpServletRequest httpRequest = new MockHttpServletRequest();
MockPortletWindowId portletWindowId = new MockPortletWindowId("123");
MockPortletDefinitionId portletDefinitionId = new MockPortletDefinitionId(789);
PortletDefinition portletDefinition = mock(PortletDefinition.class);
when(portletDefinition.getCacheScope()).thenReturn("private");
when(portletWindowRegistry.getPortletWindow(httpRequest, portletWindowId)).thenReturn(portletWindow);
when(portletWindow.getPortletWindowId()).thenReturn(portletWindowId);
when(portletWindow.getPortletEntity()).thenReturn(portletEntity);
when(portletWindow.getWindowState()).thenReturn(WindowState.NORMAL);
when(portletWindow.getPortletMode()).thenReturn(PortletMode.VIEW);
when(portletEntity.getPortletDefinitionId()).thenReturn(portletDefinitionId);
when(portletDefinitionRegistry.getParentPortletDescriptor(portletDefinitionId)).thenReturn(portletDefinition);
when(urlSyntaxProvider.getPortalRequestInfo(httpRequest)).thenReturn(portalRequestInfo);
cacheControlService.setPortletWindowRegistry(portletWindowRegistry);
cacheControlService.setPortletDefinitionRegistry(portletDefinitionRegistry);
final CacheState<CachedPortletData<PortletRenderResult>, PortletRenderResult> cacheState = cacheControlService.getPortletRenderState(httpRequest, portletWindowId);
final CacheControl cacheControl = cacheState.getCacheControl();
assertFalse(cacheControl.isPublicScope());
}
use of org.apache.pluto.container.om.portlet.PortletDefinition in project uPortal by Jasig.
the class GuestPortletEntityPreferencesImpl method loadBasePortletPreferences.
@Override
protected void loadBasePortletPreferences(IPortletEntity portletEntity, Map<String, IPortletPreference> basePortletPreferences) {
final IPortletDefinition portletDefinition = portletEntity.getPortletDefinition();
//Add descriptor prefs to base Map
final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
final PortletDefinition portletDescriptor = this.portletDefinitionRegistry.getParentPortletDescriptor(portletDefinitionId);
final Preferences descriptorPreferences = portletDescriptor.getPortletPreferences();
for (final Preference preference : descriptorPreferences.getPortletPreferences()) {
final IPortletPreference preferenceWrapper = new PortletPreferenceImpl(preference);
basePortletPreferences.put(preferenceWrapper.getName(), preferenceWrapper);
}
//Add definition prefs to base Map
final List<IPortletPreference> definitionPreferences = portletDefinition.getPortletPreferences();
for (final IPortletPreference preference : definitionPreferences) {
basePortletPreferences.put(preference.getName(), preference);
}
//Add entity prefs to base Map
final List<IPortletPreference> entityPreferences = portletEntity.getPortletPreferences();
for (final IPortletPreference preference : entityPreferences) {
basePortletPreferences.put(preference.getName(), preference);
}
}
use of org.apache.pluto.container.om.portlet.PortletDefinition in project uPortal by Jasig.
the class PortletDefinitionPreferencesImpl method loadBasePortletPreferences.
@Override
protected void loadBasePortletPreferences(IPortletDefinition portletDefinition, Map<String, IPortletPreference> basePortletPreferences) {
//Add descriptor prefs to base Map
final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
final PortletDefinition portletDescriptor = this.portletDefinitionRegistry.getParentPortletDescriptor(portletDefinitionId);
final Preferences descriptorPreferences = portletDescriptor.getPortletPreferences();
for (final Preference preference : descriptorPreferences.getPortletPreferences()) {
final IPortletPreference preferenceWrapper = new PortletPreferenceImpl(preference);
basePortletPreferences.put(preferenceWrapper.getName(), preferenceWrapper);
}
}
use of org.apache.pluto.container.om.portlet.PortletDefinition in project uPortal by Jasig.
the class PortletEntityPreferencesImpl method loadBasePortletPreferences.
@Override
protected void loadBasePortletPreferences(IPortletEntity portletEntity, Map<String, IPortletPreference> basePortletPreferences) {
final IPortletDefinition portletDefinition = portletEntity.getPortletDefinition();
//Add descriptor prefs to base Map
final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
final PortletDefinition portletDescriptor = this.portletDefinitionRegistry.getParentPortletDescriptor(portletDefinitionId);
final Preferences descriptorPreferences = portletDescriptor.getPortletPreferences();
for (final Preference preference : descriptorPreferences.getPortletPreferences()) {
final IPortletPreference preferenceWrapper = new PortletPreferenceImpl(preference);
basePortletPreferences.put(preferenceWrapper.getName(), preferenceWrapper);
}
//Add definition prefs to base Map
final List<IPortletPreference> definitionPreferences = portletDefinition.getPortletPreferences();
for (final IPortletPreference preference : definitionPreferences) {
basePortletPreferences.put(preference.getName(), preference);
}
}
use of org.apache.pluto.container.om.portlet.PortletDefinition in project uPortal by Jasig.
the class PortletCacheControlServiceImpl method getPortletState.
private <D extends CachedPortletResultHolder<T>, T extends Serializable> CacheState<D, T> getPortletState(HttpServletRequest request, IPortletWindow portletWindow, PublicPortletCacheKey publicCacheKey, Ehcache publicOutputCache, Ehcache privateOutputCache, boolean useHttpHeaders) {
//See if there is any cached data for the portlet header request
final CacheState<D, T> cacheState = this.<D, T>getPortletCacheState(request, portletWindow, publicCacheKey, publicOutputCache, privateOutputCache);
String etagHeader = null;
final D cachedPortletData = cacheState.getCachedPortletData();
if (cachedPortletData != null) {
if (useHttpHeaders) {
//Browser headers being used, check ETag and Last Modified
etagHeader = request.getHeader(IF_NONE_MATCH);
if (etagHeader != null && etagHeader.equals(cachedPortletData.getEtag())) {
//ETag is valid, mark the browser data as matching
cacheState.setBrowserDataMatches(true);
} else {
long ifModifiedSince = request.getDateHeader(IF_MODIFIED_SINCE);
if (ifModifiedSince >= 0 && cachedPortletData.getTimeStored() <= ifModifiedSince) {
//Cached content hasn't been modified since header date, mark the browser data as matching
cacheState.setBrowserDataMatches(true);
}
}
}
final long expirationTime = cachedPortletData.getExpirationTime();
if (expirationTime == -1 || expirationTime > System.currentTimeMillis()) {
//Cached data exists, see if it can be used with no additional work
//Cached data is not expired, check if browser data should be used
cacheState.setUseCachedData(true);
//Copy browser-data-matching flag to the user-browser-data flag
cacheState.setUseBrowserData(cacheState.isBrowserDataMatches());
//No browser side data to be used, return the cached data for replay
return cacheState;
}
}
//Build CacheControl structure
final CacheControl cacheControl = cacheState.getCacheControl();
//Get the portlet descriptor
final IPortletEntity entity = portletWindow.getPortletEntity();
final IPortletDefinitionId definitionId = entity.getPortletDefinitionId();
final PortletDefinition portletDescriptor = this.portletDefinitionRegistry.getParentPortletDescriptor(definitionId);
//Set the default scope
final String cacheScopeValue = portletDescriptor.getCacheScope();
if (MimeResponse.PUBLIC_SCOPE.equalsIgnoreCase(cacheScopeValue)) {
cacheControl.setPublicScope(true);
}
//Set the default expiration time
cacheControl.setExpirationTime(portletDescriptor.getExpirationCache());
// Use the request etag if it exists (implies useHttpHeaders==true)
if (etagHeader != null) {
cacheControl.setETag(etagHeader);
cacheState.setBrowserSetEtag(true);
} else // No browser-set etag, use the cached etag value if there is cached data
if (cachedPortletData != null) {
logger.debug("setting cacheControl.eTag from cached data to {}", cachedPortletData.getEtag());
cacheControl.setETag(cachedPortletData.getEtag());
}
return cacheState;
}
Aggregations