You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2012/07/17 10:54:47 UTC
svn commit: r1362411 - in
/sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container:
./ internal/ internal/impl/ internal/services/
Author: cziegeler
Date: Tue Jul 17 08:54:47 2012
New Revision: 1362411
URL: http://svn.apache.org/viewvc?rev=1362411&view=rev
Log:
Code cleanup
Modified:
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/PortletEntityId.java
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/ResourceURLProviderImpl.java
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/impl/SlingPortletConfigImpl.java
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/impl/SlingPortletContextImpl.java
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/services/DefaultPortletInvokerService.java
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/services/DefaultPortletPreferencesService.java
Modified: sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/PortletEntityId.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/PortletEntityId.java?rev=1362411&r1=1362410&r2=1362411&view=diff
==============================================================================
--- sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/PortletEntityId.java (original)
+++ sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/PortletEntityId.java Tue Jul 17 08:54:47 2012
@@ -33,14 +33,14 @@ public class PortletEntityId {
/** The complete key. */
private final String key;
- public PortletEntityId(String appName, String portletName, int prefsSet) {
+ public PortletEntityId(final String appName, final String portletName, final int prefsSet) {
this.appName = appName;
this.portletName = portletName;
this.prefsSet = prefsSet;
this.key = appName + ':' + portletName + '_' + prefsSet;
}
- public PortletEntityId(String key) {
+ public PortletEntityId(final String key) {
final int pos = key.indexOf(':');
if ( pos == -1 ) {
throw new IllegalArgumentException("Key is not a valid portlet identifier: " + key);
@@ -86,7 +86,7 @@ public class PortletEntityId {
/**
* @see java.lang.Object#equals(java.lang.Object)
*/
- public boolean equals(Object obj) {
+ public boolean equals(final Object obj) {
if ( obj instanceof PortletEntityId ) {
return key.equals(((PortletEntityId)obj).getKey());
}
@@ -104,6 +104,6 @@ public class PortletEntityId {
* @see java.lang.Object#toString()
*/
public String toString() {
- return "PortletIdentifier: " + this.key;
+ return "PortletEntityId: " + this.key;
}
}
Modified: sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/ResourceURLProviderImpl.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/ResourceURLProviderImpl.java?rev=1362411&r1=1362410&r2=1362411&view=diff
==============================================================================
--- sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/ResourceURLProviderImpl.java (original)
+++ sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/ResourceURLProviderImpl.java Tue Jul 17 08:54:47 2012
@@ -26,15 +26,15 @@ public class ResourceURLProviderImpl imp
private String stringUrl = "";
private String base = "";
- public ResourceURLProviderImpl(HttpServletRequest req,
- PortletWindow portletWindow) {
+ public ResourceURLProviderImpl(final HttpServletRequest req,
+ final PortletWindow portletWindow) {
}
- public void setAbsoluteURL(String path) {
+ public void setAbsoluteURL(final String path) {
stringUrl = path;
}
- public void setFullPath(String path) {
+ public void setFullPath(final String path) {
stringUrl = base + path;
}
Modified: sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/impl/SlingPortletConfigImpl.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/impl/SlingPortletConfigImpl.java?rev=1362411&r1=1362410&r2=1362411&view=diff
==============================================================================
--- sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/impl/SlingPortletConfigImpl.java (original)
+++ sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/impl/SlingPortletConfigImpl.java Tue Jul 17 08:54:47 2012
@@ -39,15 +39,15 @@ public class SlingPortletConfigImpl
protected ResourceBundleFactory bundles;
- public SlingPortletConfigImpl(PortletContext portletContext,
- PortletDefinition portletDD) {
+ public SlingPortletConfigImpl(final PortletContext portletContext,
+ final PortletDefinition portletDD) {
super(portletContext, portletDD);
}
/**
* @see org.apache.pluto.container.impl.AbstractPortletConfigImpl#getResourceBundle(java.util.Locale)
*/
- public ResourceBundle getResourceBundle(Locale locale) {
+ public ResourceBundle getResourceBundle(final Locale locale) {
if(LOG.isDebugEnabled()) {
LOG.debug("Resource Bundle requested: "+locale);
}
Modified: sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/impl/SlingPortletContextImpl.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/impl/SlingPortletContextImpl.java?rev=1362411&r1=1362410&r2=1362411&view=diff
==============================================================================
--- sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/impl/SlingPortletContextImpl.java (original)
+++ sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/impl/SlingPortletContextImpl.java Tue Jul 17 08:54:47 2012
@@ -16,7 +16,8 @@
*/
package org.apache.sling.portal.container.internal.impl;
-import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
import javax.servlet.ServletContext;
@@ -33,6 +34,8 @@ public class SlingPortletContextImpl
extends PortletContextImpl
implements SlingPortletContext {
+ private static final List<String> EMPTY_OPTIONS = Collections.emptyList();
+
/** The class loader for the portlet. */
private final ClassLoader contextClassLoader;
@@ -41,12 +44,12 @@ public class SlingPortletContextImpl
* @param servletContext the servlet context in which we are contained.
* @param portletApp the portlet application descriptor.
*/
- public SlingPortletContextImpl(ServletContext servletContext,
- PortletApplicationDefinition portletApp,
- ClassLoader contextClassLoader,
- ContainerInfo info,
- RequestDispatcherService rds) {
- super(servletContext, portletApp, info, new ArrayList<String>(), rds);
+ public SlingPortletContextImpl(final ServletContext servletContext,
+ final PortletApplicationDefinition portletApp,
+ final ClassLoader contextClassLoader,
+ final ContainerInfo info,
+ final RequestDispatcherService rds) {
+ super(servletContext, portletApp, info, EMPTY_OPTIONS, rds);
this.contextClassLoader = contextClassLoader;
}
Modified: sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/services/DefaultPortletInvokerService.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/services/DefaultPortletInvokerService.java?rev=1362411&r1=1362410&r2=1362411&view=diff
==============================================================================
--- sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/services/DefaultPortletInvokerService.java (original)
+++ sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/services/DefaultPortletInvokerService.java Tue Jul 17 08:54:47 2012
@@ -72,12 +72,12 @@ public class DefaultPortletInvokerServic
/** Request attribute indicating that the include/forward has been processed. */
private static final String ATTR_PROCESSED = DefaultPortletInvokerService.class.getName() + "/processed";
- private PortletRegistryService registry;
+ private final PortletRegistryService registry;
/**
* Default Constructor.
*/
- public DefaultPortletInvokerService(PortletRegistryService registry) {
+ public DefaultPortletInvokerService(final PortletRegistryService registry) {
this.registry = registry;
}
@@ -151,11 +151,11 @@ public class DefaultPortletInvokerServic
* @throws PortletException if a portlet exception occurs.
* @throws IOException if an error occurs writing to the response.
*/
- protected final void invoke(PortletRequestContext context,
- PortletRequest request,
- PortletResponse response,
- FilterManager filterManager,
- Integer methodID)
+ protected final void invoke(final PortletRequestContext context,
+ final PortletRequest request,
+ final PortletResponse response,
+ final FilterManager filterManager,
+ final Integer methodID)
throws PortletException, IOException, PortletContainerException {
final PortletWindow portletWindow = context.getPortletWindow();
final SlingPortletEntity portletEntity = ((SlingPortletWindow)portletWindow).getPortletEntity();
@@ -195,14 +195,14 @@ public class DefaultPortletInvokerServic
if ( containerRequest.getAttribute(ATTR_PROCESSED) == null ) {
throw new javax.servlet.UnavailableException("Portlet "+ id + " is not reachable. Check if the container servlet is running in the portlet application.");
}
- } catch (javax.servlet.UnavailableException ex) {
+ } catch (final javax.servlet.UnavailableException ex) {
final String msg = "Portlet is unavailable " + id;
if ( ex.isPermanent() ) {
throw new javax.portlet.UnavailableException(msg);
}
throw new javax.portlet.UnavailableException(msg, ex.getUnavailableSeconds());
- } catch (javax.servlet.ServletException ex) {
+ } catch (final javax.servlet.ServletException ex) {
if (ex.getRootCause() != null &&
ex.getRootCause() instanceof PortletException) {
final PortletException pe = (PortletException) ex.getRootCause();
@@ -229,7 +229,7 @@ public class DefaultPortletInvokerServic
} else {
throw new PortletException("Unable to retrieve portlet invoker dispatcher. Check if the container servlet is running in the portlet application.");
}
- } catch (javax.portlet.UnavailableException ua) {
+ } catch (final javax.portlet.UnavailableException ua) {
// handle unavailable exception
this.registry.unloadPortlet(portletEntity, ua.isPermanent(), ua.getUnavailableSeconds());
throw ua;
@@ -241,7 +241,7 @@ public class DefaultPortletInvokerServic
/**
* @see org.apache.sling.portal.container.api.Container#service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
- public void service(HttpServletRequest request, HttpServletResponse response)
+ public void service(final HttpServletRequest request, final HttpServletResponse response)
throws PortletException, IOException {
// Retrieve attributes from the servlet request.
final Integer methodId = (Integer) request.getAttribute(PortletInvokerService.METHOD_ID);
@@ -317,7 +317,7 @@ public class DefaultPortletInvokerServic
private final ServletContext servletContext;
- public RequestWrapper(HttpServletRequest request, final ServletContext sc) {
+ public RequestWrapper(final HttpServletRequest request, final ServletContext sc) {
super(request);
this.servletContext = sc;
}
Modified: sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/services/DefaultPortletPreferencesService.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/services/DefaultPortletPreferencesService.java?rev=1362411&r1=1362410&r2=1362411&view=diff
==============================================================================
--- sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/services/DefaultPortletPreferencesService.java (original)
+++ sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/services/DefaultPortletPreferencesService.java Tue Jul 17 08:54:47 2012
@@ -19,6 +19,7 @@ package org.apache.sling.portal.containe
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
import javax.jcr.Node;
import javax.jcr.Property;
@@ -64,13 +65,13 @@ public class DefaultPortletPreferencesSe
/**
* Cache for default preferences.
*/
- private Map<PortletEntityId, Map<String, PortletPreference>> defaultCache = new HashMap<PortletEntityId, Map<String, PortletPreference>>();
+ private Map<String, Map<String, PortletPreference>> defaultCache = new ConcurrentHashMap<String, Map<String, PortletPreference>>();
/**
* The preferences validator cache: key is the portlet definition, value is
* the portlet preferences validator instance.
*/
- private Map<PortletDefinition, PreferencesValidator> cache = new HashMap<PortletDefinition, PreferencesValidator>();
+ private Map<PortletDefinition, PreferencesValidator> validatorCache = new ConcurrentHashMap<PortletDefinition, PreferencesValidator>();
private static final Map<String,PortletPreference> EMPTY_MAP = Collections.unmodifiableMap(new HashMap<String, PortletPreference>());
@@ -108,9 +109,11 @@ public class DefaultPortletPreferencesSe
PortletRequest request )
throws PortletContainerException {
final Session userSession = PortalUtil.getUserSession(request);
+ final boolean isAnonymous = PortalUtil.isAnonymous(userSession);
final PortletEntityId entityId = ((SlingPortletWindow)portletWindow).getPortletEntity().getPortletEntityId();
- Map<String, PortletPreference> preferences = this.defaultCache.get(entityId);
+ final String key = (isAnonymous ? "anon:" + entityId.getKey() : entityId.getKey());
+ Map<String, PortletPreference> preferences = this.defaultCache.get(key);
if ( preferences == null ) {
final PortletDefinition portlet = portletWindow.getPortletDefinition();
@@ -124,29 +127,28 @@ public class DefaultPortletPreferencesSe
}
preferences.put(pref.getName(), new PortletPreferenceImpl(pref.getName(), values, pref.isReadOnly()));
}
+ // anonymous is not allowed to change preferences!
+ if ( isAnonymous ) {
+ for(PortletPreference p : preferences.values()) {
+ if ( !p.isReadOnly() ) {
+ ((PortletPreferenceImpl)p).setReadOnly(true);
+ }
+ }
+ }
} else {
preferences = EMPTY_MAP;
}
- this.defaultCache.put(entityId, preferences);
- }
- // anonymous is not allowed to change preferences!
- // TODO - cache this as well!
- if ( PortalUtil.isAnonymous(userSession) ) {
- preferences = new HashMap<String, PortletPreference>(preferences);
- for(PortletPreference p : preferences.values()) {
- if ( !p.isReadOnly() ) {
- ((PortletPreferenceImpl)p).setReadOnly(true);
- }
- }
+ this.defaultCache.put(key, preferences);
}
+
return preferences;
}
/**
* @see org.apache.pluto.container.PortletPreferencesService#getStoredPreferences(org.apache.pluto.container.PortletWindow, javax.portlet.PortletRequest)
*/
- public Map<String,PortletPreference> getStoredPreferences(PortletWindow portletWindow,
- PortletRequest request)
+ public Map<String,PortletPreference> getStoredPreferences(final PortletWindow portletWindow,
+ final PortletRequest request)
throws PortletContainerException {
final Session userSession = PortalUtil.getUserSession(request);
// anonymous is not allowed to change preferences!
@@ -160,7 +162,7 @@ public class DefaultPortletPreferencesSe
if ( !userSession.itemExists(path) ) {
return EMPTY_MAP;
}
- } catch (RepositoryException re) {
+ } catch (final RepositoryException re) {
logger.debug("Unable to check preferences path.", re);
return EMPTY_MAP;
}
@@ -197,7 +199,7 @@ public class DefaultPortletPreferencesSe
return preferences;
}
return EMPTY_MAP;
- } catch (RepositoryException re) {
+ } catch (final RepositoryException re) {
logger.debug("Unable to read preferences from path: " + path + ".", re);
return EMPTY_MAP;
}
@@ -206,9 +208,9 @@ public class DefaultPortletPreferencesSe
/**
* @see org.apache.pluto.container.PortletPreferencesService#store(org.apache.pluto.container.PortletWindow, javax.portlet.PortletRequest, java.util.Map)
*/
- public void store(PortletWindow portletWindow,
- PortletRequest request,
- Map<String,PortletPreference> preferences)
+ public void store(final PortletWindow portletWindow,
+ final PortletRequest request,
+ final Map<String,PortletPreference> preferences)
throws PortletContainerException {
final Session userSession = PortalUtil.getUserSession(request);
// anonymous is not allowed to change preferences!
@@ -244,7 +246,7 @@ public class DefaultPortletPreferencesSe
}
// store changes
node.save();
- } catch (RepositoryException re) {
+ } catch (final RepositoryException re) {
throw new PortletContainerException("Unable to store preferences at " + path, re);
}
}
@@ -252,14 +254,14 @@ public class DefaultPortletPreferencesSe
/**
* @see org.apache.pluto.container.PortletPreferencesService#getPreferencesValidator(org.apache.pluto.container.om.portlet.PortletDefinition)
*/
- public PreferencesValidator getPreferencesValidator(PortletDefinition portletDD)
+ public PreferencesValidator getPreferencesValidator(final PortletDefinition portletDD)
throws ValidatorException {
final Preferences portletPreferencesDD = portletDD.getPortletPreferences();
if (portletPreferencesDD != null) {
final String className = portletPreferencesDD.getPreferencesValidator();
if (className != null) {
// Try to retrieve the validator from cache.
- PreferencesValidator validator = cache.get(portletDD);
+ PreferencesValidator validator = validatorCache.get(portletDD);
if (validator != null) {
return validator;
}
@@ -267,21 +269,21 @@ public class DefaultPortletPreferencesSe
if (logger.isDebugEnabled()) {
logger.debug("Creating preferences validator: " + className);
}
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ final ClassLoader loader = Thread.currentThread().getContextClassLoader();
try {
Class<?> clazz = loader.loadClass(className);
validator = (PreferencesValidator) clazz.newInstance();
- cache.put(portletDD, validator);
- } catch (InstantiationException ex) {
+ validatorCache.put(portletDD, validator);
+ } catch (final InstantiationException ex) {
logger.error("Error instantiating validator.", ex);
throw new ValidatorException(ex, null);
- } catch (IllegalAccessException ex) {
+ } catch (final IllegalAccessException ex) {
logger.error("Error instantiating validator.", ex);
throw new ValidatorException(ex, null);
- } catch (ClassNotFoundException ex) {
+ } catch (final ClassNotFoundException ex) {
logger.error("Error instantiating validator.", ex);
throw new ValidatorException(ex, null);
- } catch (ClassCastException ex) {
+ } catch (final ClassCastException ex) {
logger.error("Error casting instance to PreferencesValidator.", ex);
throw new ValidatorException(ex, null);
}