portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r333039 - in /portals/jetspeed-2/trunk: components/portal/src/java/org/apache/jetspeed/util/descriptor/ components/portlet-factory/src/java/org/apache/jetspeed/factory/ components/registry/src/java/org/apache/jetspeed/om/portlet/impl/ compo...
Date Sun, 13 Nov 2005 16:01:29 GMT
Author: ate
Date: Sun Nov 13 08:01:06 2005
New Revision: 333039

URL: http://svn.apache.org/viewcvs?rev=333039&view=rev
Log:
PreferencesValidator implementation added.
With these changes committed, I'd like to (informally) announce that J2 now passes the Portlet
TCK!

Added:
    portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/om/common/preference/PreferencesValidatorFactory.java
  (with props)
Modified:
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/util/descriptor/PortletPreferenceRuleSet.java
    portals/jetspeed-2/trunk/components/portlet-factory/src/java/org/apache/jetspeed/factory/JetspeedPortletFactory.java
    portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/om/portlet/impl/PortletDefinitionImpl.java
    portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/om/preference/impl/FragmentPortletPreferenceSet.java
    portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/om/preference/impl/PrefsPreferenceSetImpl.java
    portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/factory/PortletFactory.java
    portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/om/common/preference/PreferenceSetComposite.java

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/util/descriptor/PortletPreferenceRuleSet.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/util/descriptor/PortletPreferenceRuleSet.java?rev=333039&r1=333038&r2=333039&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/util/descriptor/PortletPreferenceRuleSet.java
(original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/util/descriptor/PortletPreferenceRuleSet.java
Sun Nov 13 08:01:06 2005
@@ -36,6 +36,7 @@
      */
     public void addRuleInstances( Digester digester )
     {
+       digester.addBeanPropertySetter("portlet-app/portlet/portlet-preferences/preferences-validator",
"preferenceValidatorClassname");
        digester.addRule("portlet-app/portlet/portlet-preferences/preference", new PortletPreferenceRule());
        digester.addBeanPropertySetter("portlet-app/portlet/portlet-preferences/preference/name",
"name");
        digester.addCallMethod("portlet-app/portlet/portlet-preferences/preference/value",
"addValue", 0);

Modified: portals/jetspeed-2/trunk/components/portlet-factory/src/java/org/apache/jetspeed/factory/JetspeedPortletFactory.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portlet-factory/src/java/org/apache/jetspeed/factory/JetspeedPortletFactory.java?rev=333039&r1=333038&r2=333039&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portlet-factory/src/java/org/apache/jetspeed/factory/JetspeedPortletFactory.java
(original)
+++ portals/jetspeed-2/trunk/components/portlet-factory/src/java/org/apache/jetspeed/factory/JetspeedPortletFactory.java
Sun Nov 13 08:01:06 2005
@@ -22,6 +22,7 @@
 import javax.portlet.PortletConfig;
 import javax.portlet.PortletContext;
 import javax.portlet.PortletException;
+import javax.portlet.PreferencesValidator;
 import javax.portlet.UnavailableException;
 import javax.servlet.ServletContext;
 
@@ -29,6 +30,7 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.jetspeed.container.PortalAccessor;
 import org.apache.jetspeed.om.common.portlet.PortletApplication;
+import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
 import org.apache.pluto.om.portlet.PortletDefinition;
 
 /**
@@ -46,6 +48,8 @@
 {
 
     private HashMap portletCache;
+    private HashMap validatorCache;
+    
     private static final Log log = LogFactory.getLog(JetspeedPortletFactory.class);
     private final HashMap classLoaderMap;
 
@@ -55,6 +59,7 @@
     public JetspeedPortletFactory()
     {
         this.portletCache = new HashMap();
+        this.validatorCache = new HashMap();
         classLoaderMap = new HashMap();
     }
 
@@ -82,7 +87,8 @@
                     while (portletDefinitions.hasNext())
                     {
                         PortletDefinition pd = (PortletDefinition) portletDefinitions.next();
-                        Portlet portlet = (Portlet) portletCache.remove(pd.getId().toString());
+                        String pdId = pd.getId().toString();
+                        Portlet portlet = (Portlet) portletCache.remove(pdId);
                         if (portlet != null)
                         {
                             try
@@ -95,11 +101,65 @@
                                 Thread.currentThread().setContextClassLoader(currentContextClassLoader);
                             }
                         }
+                        validatorCache.remove(pdId);
                     }
                 }
             }
         }
     }
+    
+    public PreferencesValidator getPreferencesValidator(PortletDefinition pd)
+    {
+        PreferencesValidator validator = null;
+        try
+        {
+            String pdId = pd.getId().toString();
+            
+            synchronized (validatorCache)
+            {
+                validator = (PreferencesValidator)validatorCache.get(pdId);
+                if ( validator == null )
+                {
+                    String className = ((PortletDefinitionComposite)pd).getPreferenceValidatorClassname();
+                    if ( className != null )
+                    {
+                        PortletApplication pa = (PortletApplication)pd.getPortletApplicationDefinition();
+                        ClassLoader paCl = (ClassLoader)classLoaderMap.get(pa.getId().toString());
+                        if ( paCl == null )
+                        {
+                            throw new UnavailableException("Portlet Application "+pa.getName()+"
not available");
+                        }
+                        
+                        ClassLoader currentContextClassLoader = Thread.currentThread().getContextClassLoader();
+                        try
+                        {
+                            Class clazz = paCl.loadClass(className);
+                            try
+                            {
+                                Thread.currentThread().setContextClassLoader(paCl);
+                                validator = (PreferencesValidator)clazz.newInstance();
+                                validatorCache.put(pdId, validator);
+                            }
+                            finally
+                            {
+                                Thread.currentThread().setContextClassLoader(currentContextClassLoader);
+                            }
+                        }
+                        catch (Exception e)
+                        {
+                            String msg = "Cannot create PreferencesValidator instance "+className+"
for Portlet "+pd.getName();
+                            log.error(msg,e);
+                        }
+                    }
+                }
+            }
+        }
+        catch (Exception e)
+        {
+            log.error(e);
+        }
+        return validator;
+    }
 
     /**
      * Gets a portlet by either creating it or returning a handle to it from the portlet
'cache'
@@ -111,14 +171,14 @@
     public PortletInstance getPortletInstance( ServletContext servletContext, PortletDefinition
pd ) throws PortletException
     {
         PortletInstance portlet = null;
-        String portletName = pd.getId().toString();
+        String pdId = pd.getId().toString();
         PortletApplication pa = (PortletApplication)pd.getPortletApplicationDefinition();
 
         try
         {                        
           synchronized (portletCache)
           {
-            portlet = (PortletInstance)portletCache.get(portletName);
+            portlet = (PortletInstance)portletCache.get(pdId);
             if (null != portlet)
             {
                 return portlet;
@@ -175,7 +235,7 @@
                 log.error("Failed to initialize Portlet "+pd.getClassName()+" for Portlet
Application "+pa.getName(), e1);
                 throw e1;
             }            
-            portletCache.put(portletName, portlet);
+            portletCache.put(pdId, portlet);
           }
         }
         catch (PortletException pe)

Modified: portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/om/portlet/impl/PortletDefinitionImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/om/portlet/impl/PortletDefinitionImpl.java?rev=333039&r1=333038&r2=333039&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/om/portlet/impl/PortletDefinitionImpl.java
(original)
+++ portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/om/portlet/impl/PortletDefinitionImpl.java
Sun Nov 13 08:01:06 2005
@@ -27,6 +27,8 @@
 import java.util.prefs.BackingStoreException;
 import java.util.prefs.Preferences;
 
+import javax.portlet.PreferencesValidator;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.jetspeed.components.portletregistry.PortletRegistry;
@@ -41,6 +43,7 @@
 import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
 import org.apache.jetspeed.om.common.preference.PreferenceComposite;
 import org.apache.jetspeed.om.common.preference.PreferenceSetComposite;
+import org.apache.jetspeed.om.common.preference.PreferencesValidatorFactory;
 import org.apache.jetspeed.om.impl.DescriptionImpl;
 import org.apache.jetspeed.om.impl.DescriptionSetImpl;
 import org.apache.jetspeed.om.impl.DisplayNameSetImpl;
@@ -83,7 +86,7 @@
  * @version $Id$
  *  
  */
-public class PortletDefinitionImpl implements PortletDefinitionComposite, Serializable, Support
+public class PortletDefinitionImpl implements PortletDefinitionComposite, PreferencesValidatorFactory,
Serializable, Support
 {
     private static final Log log = LogFactory.getLog(PortletDefinitionImpl.class);
     
@@ -228,7 +231,7 @@
                 }
                 
                 Preferences prefNode = PrefsPreference.createPrefenceNode(this);
-                preferenceSet = new PrefsPreferenceSetImpl(prefNode);
+                preferenceSet = new PrefsPreferenceSetImpl(prefNode, this);
             }
         }
         catch (BackingStoreException e)
@@ -932,5 +935,14 @@
     public static void setPortletFactory(PortletFactory portletFactory)
     {
         PortletDefinitionImpl.portletFactory = portletFactory;
+    }
+
+    public PreferencesValidator getPreferencesValidator()
+    {
+        if ( portletFactory != null )
+        {
+            return portletFactory.getPreferencesValidator(this);
+        }
+        return null;
     }
 }

Modified: portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/om/preference/impl/FragmentPortletPreferenceSet.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/om/preference/impl/FragmentPortletPreferenceSet.java?rev=333039&r1=333038&r2=333039&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/om/preference/impl/FragmentPortletPreferenceSet.java
(original)
+++ portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/om/preference/impl/FragmentPortletPreferenceSet.java
Sun Nov 13 08:01:06 2005
@@ -108,11 +108,6 @@
         return pref;
     }
 
-    public void setPreferenceValidator(PreferencesValidator validator)
-    {
-        preferenceSet.setPreferenceValidator(validator);
-    }
-
     public int size()
     {
         return prefs.size();

Modified: portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/om/preference/impl/PrefsPreferenceSetImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/om/preference/impl/PrefsPreferenceSetImpl.java?rev=333039&r1=333038&r2=333039&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/om/preference/impl/PrefsPreferenceSetImpl.java
(original)
+++ portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/om/preference/impl/PrefsPreferenceSetImpl.java
Sun Nov 13 08:01:06 2005
@@ -27,6 +27,7 @@
 import javax.portlet.PreferencesValidator;
 
 import org.apache.jetspeed.om.common.preference.PreferenceSetComposite;
+import org.apache.jetspeed.om.common.preference.PreferencesValidatorFactory;
 import org.apache.pluto.om.common.Preference;
 
 /**
@@ -36,10 +37,9 @@
  */
 public class PrefsPreferenceSetImpl implements PreferenceSetComposite
 {
-
     protected Preferences prefsRootNode;
-    protected PreferencesValidator validator;
     protected PreferenceSetComposite defaults;
+    protected PreferencesValidatorFactory validatorFactory;
 
     /**
      * @param portletEntity
@@ -55,6 +55,21 @@
 
     }
     
+    /**
+     * @param portletEntity
+     *                  PortletEntity for which to build the PreferenceSet for.
+     * @param validatorFactory
+     *                  Factory for providing access to a PreferencesValidator instance 
              
+     * @throws BackingStoreException
+     *                   if an error is encountered while accessing the Preferences
+     *                   backing store.
+     */
+    public PrefsPreferenceSetImpl( Preferences prefsRootNode, PreferencesValidatorFactory
validatorFactory ) throws BackingStoreException
+    {
+        this(prefsRootNode);
+        this.validatorFactory = validatorFactory;
+    }
+
     public PrefsPreferenceSetImpl( Preferences prefsRootNode,  PreferenceSetComposite defaults)
throws BackingStoreException
     {
         this(prefsRootNode);        
@@ -95,20 +110,6 @@
 
     /**
      * <p>
-     * setPreferenceValidator
-     * </p>
-     * 
-     * @see org.apache.jetspeed.om.common.preference.PreferenceSetComposite#setPreferenceValidator(javax.portlet.PreferencesValidator)
-     * @param validator
-     */
-    public void setPreferenceValidator( PreferencesValidator validator )
-    {
-        this.validator = validator;
-
-    }
-
-    /**
-     * <p>
      * get
      * </p>
      * 
@@ -156,7 +157,11 @@
      */
     public PreferencesValidator getPreferencesValidator()
     {
-        return validator;
+        if ( validatorFactory != null )
+        {
+            return validatorFactory.getPreferencesValidator();
+        }
+        return null;
     }
 
     /**

Modified: portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/factory/PortletFactory.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/factory/PortletFactory.java?rev=333039&r1=333038&r2=333039&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/factory/PortletFactory.java
(original)
+++ portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/factory/PortletFactory.java
Sun Nov 13 08:01:06 2005
@@ -16,6 +16,7 @@
 package org.apache.jetspeed.factory;
 
 import javax.portlet.PortletException;
+import javax.portlet.PreferencesValidator;
 import javax.servlet.ServletContext;
 
 import org.apache.jetspeed.om.common.portlet.PortletApplication;
@@ -40,4 +41,5 @@
     boolean isPortletApplicationRegistered(PortletApplication pa);
     ClassLoader getPortletApplicationClassLoader(PortletApplication pa);
     PortletInstance getPortletInstance( ServletContext servletContext, PortletDefinition
pd ) throws PortletException;
+    PreferencesValidator getPreferencesValidator(PortletDefinition pd );
 }

Modified: portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/om/common/preference/PreferenceSetComposite.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/om/common/preference/PreferenceSetComposite.java?rev=333039&r1=333038&r2=333039&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/om/common/preference/PreferenceSetComposite.java
(original)
+++ portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/om/common/preference/PreferenceSetComposite.java
Sun Nov 13 08:01:06 2005
@@ -17,8 +17,6 @@
 
 import java.util.Set;
 
-import javax.portlet.PreferencesValidator;
-
 import org.apache.pluto.om.common.PreferenceSet;
 import org.apache.pluto.om.common.PreferenceSetCtrl;
 
@@ -36,7 +34,4 @@
     Set getNames();
 
     int size();
-
-    void setPreferenceValidator(PreferencesValidator validator);
-
 }

Added: portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/om/common/preference/PreferencesValidatorFactory.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/om/common/preference/PreferencesValidatorFactory.java?rev=333039&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/om/common/preference/PreferencesValidatorFactory.java
(added)
+++ portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/om/common/preference/PreferencesValidatorFactory.java
Sun Nov 13 08:01:06 2005
@@ -0,0 +1,10 @@
+package org.apache.jetspeed.om.common.preference;
+
+import java.io.Serializable;
+
+import javax.portlet.PreferencesValidator;
+
+public interface PreferencesValidatorFactory extends Serializable
+{
+    PreferencesValidator getPreferencesValidator();
+}

Propchange: portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/om/common/preference/PreferencesValidatorFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message