incubator-wookie-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scot...@apache.org
Subject svn commit: r1101947 - in /incubator/wookie/trunk: etc/ddl-schema/ features/ src-tests/org/apache/wookie/tests/ src-tests/org/apache/wookie/tests/beans/ src/ src/META-INF/ src/org/apache/wookie/ src/org/apache/wookie/beans/ src/org/apache/wookie/beans/...
Date Wed, 11 May 2011 16:15:45 GMT
Author: scottbw
Date: Wed May 11 16:15:44 2011
New Revision: 1101947

URL: http://svn.apache.org/viewvc?rev=1101947&view=rev
Log:
Implemented XML-based feature loading as described in WOOKIE-210

Added:
    incubator/wookie/trunk/src/org/apache/wookie/feature/Feature.java
    incubator/wookie/trunk/src/org/apache/wookie/feature/Features.java
Removed:
    incubator/wookie/trunk/src-tests/org/apache/wookie/tests/FeatureLoaderTest.java
    incubator/wookie/trunk/src/features.properties
    incubator/wookie/trunk/src/org/apache/wookie/beans/IServerFeature.java
    incubator/wookie/trunk/src/org/apache/wookie/beans/jcr/impl/ServerFeatureImpl.java
    incubator/wookie/trunk/src/org/apache/wookie/beans/jpa/impl/ServerFeatureImpl.java
    incubator/wookie/trunk/src/org/apache/wookie/feature/FeatureLoader.java
Modified:
    incubator/wookie/trunk/etc/ddl-schema/wookie-schema.xml
    incubator/wookie/trunk/features/build.xml
    incubator/wookie/trunk/src-tests/org/apache/wookie/tests/beans/AbstractPersistenceTest.java
    incubator/wookie/trunk/src/META-INF/persistence.xml
    incubator/wookie/trunk/src/org/apache/wookie/WidgetAdminServlet.java
    incubator/wookie/trunk/src/org/apache/wookie/beans/jcr/JCRPersistenceManager.java
    incubator/wookie/trunk/src/org/apache/wookie/beans/jcr/wookie-schema.cnd
    incubator/wookie/trunk/src/org/apache/wookie/beans/jpa/JPAPersistenceManager.java
    incubator/wookie/trunk/src/org/apache/wookie/beans/util/IPersistenceManager.java
    incubator/wookie/trunk/src/org/apache/wookie/server/ContextListener.java
    incubator/wookie/trunk/src/org/apache/wookie/updates/UpdatesController.java
    incubator/wookie/trunk/src/org/apache/wookie/util/html/StartPageProcessor.java

Modified: incubator/wookie/trunk/etc/ddl-schema/wookie-schema.xml
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/etc/ddl-schema/wookie-schema.xml?rev=1101947&r1=1101946&r2=1101947&view=diff
==============================================================================
--- incubator/wookie/trunk/etc/ddl-schema/wookie-schema.xml (original)
+++ incubator/wookie/trunk/etc/ddl-schema/wookie-schema.xml Wed May 11 16:15:44 2011
@@ -297,16 +297,6 @@
     </index>
   </table>
 
-  <table name="ServerFeature">
-    <column name="id" primaryKey="true" required="true" type="INTEGER"/>
-    <column name="jpa_version" type="INTEGER"/>
-    <column name="featureName" required="true" size="255" type="VARCHAR"/>
-    <column name="className" required="true" size="255" type="VARCHAR"/>
-    <index name="IXServerFeature1">
-      <index-column name="featureName"/>
-    </index>
-  </table>
-
   <table name="Token">
     <column name="id" primaryKey="true" required="true" type="INTEGER"/>
     <column name="jpa_version" type="INTEGER"/>

Modified: incubator/wookie/trunk/features/build.xml
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/features/build.xml?rev=1101947&r1=1101946&r2=1101947&view=diff
==============================================================================
--- incubator/wookie/trunk/features/build.xml (original)
+++ incubator/wookie/trunk/features/build.xml Wed May 11 16:15:44 2011
@@ -19,6 +19,7 @@
    <property name="wookie.features.dir" location="."/>
    <property name="project.build.classes.dir" location="${project.build.dir}/classes"
/>
    <property name="feature.shared.dir" value="${servletEngine.webapp.dir}/wookie/shared/feature/${feature.shortname}"/>
  
+   <property name="feature.build.dir" value="${servletEngine.webapp.dir}/wookie/features/${feature.shortname}"/>
 	
    <target name="_clean">
    </target>
@@ -31,24 +32,15 @@
    </target>
    
    <target name="build-feature" depends="_init">
-		<!-- compile classes -->
-		<javac 
-			source="${java.source.version}" 
-			target="${java.target.version}" 
- 		    destdir="${project.build.classes.dir}" 
-			debug="${compile.debug}" 
-			>
-			<src path="${wookie.root.dir}/${wookie.features.dir}/${feature.shortname}/src" />
-		</javac>
-    	<!-- copy to classes dir -->
     </target>
 	
     <target name="deploy-feature">
       <echo>Deploying feature: ${feature.shortname}</echo>
       <!-- copy shared resources -->
-      <mkdir dir="${user.dir}/${feature.shared.dir}"/>
-      <copy todir="${user.dir}/${feature.shared.dir}">
-        <fileset dir="${user.dir}/${wookie.features.dir}/${feature.shortname}/shared/"/>
+      <mkdir dir="${user.dir}/${feature.build.dir}"/>
+      <copy todir="${user.dir}/${feature.build.dir}">
+          <fileset dir="${user.dir}/${wookie.features.dir}/${feature.shortname}"/>
       </copy>
+      	
     </target>
 </project>

Modified: incubator/wookie/trunk/src-tests/org/apache/wookie/tests/beans/AbstractPersistenceTest.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src-tests/org/apache/wookie/tests/beans/AbstractPersistenceTest.java?rev=1101947&r1=1101946&r2=1101947&view=diff
==============================================================================
--- incubator/wookie/trunk/src-tests/org/apache/wookie/tests/beans/AbstractPersistenceTest.java
(original)
+++ incubator/wookie/trunk/src-tests/org/apache/wookie/tests/beans/AbstractPersistenceTest.java
Wed May 11 16:15:44 2011
@@ -25,7 +25,6 @@ import org.apache.wookie.beans.IAccessRe
 import org.apache.wookie.beans.IApiKey;
 import org.apache.wookie.beans.IParticipant;
 import org.apache.wookie.beans.IPreference;
-import org.apache.wookie.beans.IServerFeature;
 import org.apache.wookie.beans.IWidget;
 import org.apache.wookie.beans.IWidgetDefault;
 import org.apache.wookie.beans.IWidgetInstance;
@@ -169,12 +168,6 @@ public abstract class AbstractPersistenc
         participant.setParticipantThumbnailUrl("");
         persistenceManager.save(participant);
 
-        // create server feature
-        IServerFeature serverFeature = persistenceManager.newInstance(IServerFeature.class);
-        serverFeature.setFeatureName("test-feature-name");
-        serverFeature.setClassName("test.feature.class.name");
-        persistenceManager.save(serverFeature);
-
         // create access request
         IAccessRequest accessRequest = persistenceManager.newInstance(IAccessRequest.class);
         accessRequest.setOrigin("localhost");
@@ -215,14 +208,6 @@ public abstract class AbstractPersistenc
         assertNotNull(participant);
         assertEquals(participants[0], participant);
         
-        // test custom server feature query methods
-        String [] serverFeatureNames = persistenceManager.findServerFeatureNames();
-        assertNotNull(serverFeatureNames);
-        assertEquals(1, serverFeatureNames.length);
-        String serverFeatureName = serverFeatureNames[0];
-        serverFeature = persistenceManager.findServerFeatureByName(serverFeatureName);
-        assertNotNull(serverFeature);
-        assertEquals("test-feature-name", serverFeature.getFeatureName());
         
         IAccessRequest [] accessRequests = persistenceManager.findAll(IAccessRequest.class);
         assertNotNull(accessRequests);
@@ -231,7 +216,6 @@ public abstract class AbstractPersistenc
         // delete test objects
         persistenceManager.delete(widgetInstance0);
         persistenceManager.delete(participant);
-        persistenceManager.delete(serverFeature);
         persistenceManager.delete(accessRequests);
         
         // commit and close persistence manager transaction
@@ -249,9 +233,6 @@ public abstract class AbstractPersistenc
         participants = persistenceManager.findAll(IParticipant.class);
         assertNotNull(participants);
         assertEquals(0, participants.length);
-        IServerFeature [] serverFeatures = persistenceManager.findAll(IServerFeature.class);
-        assertNotNull(serverFeatures);
-        assertEquals(0, serverFeatures.length);
         
         // rollback and close persistence manager transaction
         persistenceManager.rollback();

Modified: incubator/wookie/trunk/src/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/META-INF/persistence.xml?rev=1101947&r1=1101946&r2=1101947&view=diff
==============================================================================
--- incubator/wookie/trunk/src/META-INF/persistence.xml (original)
+++ incubator/wookie/trunk/src/META-INF/persistence.xml Wed May 11 16:15:44 2011
@@ -31,7 +31,6 @@
         <class>org.apache.wookie.beans.jpa.impl.ParticipantImpl</class>     
  
         <class>org.apache.wookie.beans.jpa.impl.PreferenceDefaultImpl</class>
         <class>org.apache.wookie.beans.jpa.impl.PreferenceImpl</class>
-        <class>org.apache.wookie.beans.jpa.impl.ServerFeatureImpl</class>
         <class>org.apache.wookie.beans.jpa.impl.SharedDataImpl</class>
         <class>org.apache.wookie.beans.jpa.impl.StartFileImpl</class>
         <class>org.apache.wookie.beans.jpa.impl.TokenImpl</class>

Modified: incubator/wookie/trunk/src/org/apache/wookie/WidgetAdminServlet.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/WidgetAdminServlet.java?rev=1101947&r1=1101946&r2=1101947&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/WidgetAdminServlet.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/WidgetAdminServlet.java Wed May 11 16:15:44
2011
@@ -39,6 +39,7 @@ import org.apache.wookie.controller.Widg
 import org.apache.wookie.exceptions.InvalidParametersException;
 import org.apache.wookie.exceptions.ResourceDuplicationException;
 import org.apache.wookie.exceptions.ResourceNotFoundException;
+import org.apache.wookie.feature.Features;
 import org.apache.wookie.helpers.WidgetFactory;
 import org.apache.wookie.helpers.WidgetKeyManager;
 import org.apache.wookie.manager.IWidgetAdminManager;
@@ -485,7 +486,7 @@ public class WidgetAdminServlet extends 
 				fac.setLocales(locales);
 				fac.setLocalPath(getServletContext().getContextPath()+properties.getString("widget.widgetfolder"));
 				fac.setOutputDirectory(WIDGETFOLDER);
-				fac.setFeatures(persistenceManager.findServerFeatureNames());
+				fac.setFeatures(Features.getFeatureNames());
 				fac.setStartPageProcessor(new StartPageProcessor());
 				W3CWidget widgetModel = fac.parse(zipFile);
 				WidgetJavascriptSyntaxAnalyzer jsa = new WidgetJavascriptSyntaxAnalyzer(fac.getUnzippedWidgetDirectory());
			

Modified: incubator/wookie/trunk/src/org/apache/wookie/beans/jcr/JCRPersistenceManager.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/beans/jcr/JCRPersistenceManager.java?rev=1101947&r1=1101946&r2=1101947&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/beans/jcr/JCRPersistenceManager.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/beans/jcr/JCRPersistenceManager.java Wed
May 11 16:15:44 2011
@@ -61,7 +61,6 @@ import org.apache.wookie.beans.IParam;
 import org.apache.wookie.beans.IParticipant;
 import org.apache.wookie.beans.IPreference;
 import org.apache.wookie.beans.IPreferenceDefault;
-import org.apache.wookie.beans.IServerFeature;
 import org.apache.wookie.beans.ISharedData;
 import org.apache.wookie.beans.IStartFile;
 import org.apache.wookie.beans.IToken;
@@ -82,7 +81,6 @@ import org.apache.wookie.beans.jcr.impl.
 import org.apache.wookie.beans.jcr.impl.ParticipantImpl;
 import org.apache.wookie.beans.jcr.impl.PreferenceDefaultImpl;
 import org.apache.wookie.beans.jcr.impl.PreferenceImpl;
-import org.apache.wookie.beans.jcr.impl.ServerFeatureImpl;
 import org.apache.wookie.beans.jcr.impl.SharedDataImpl;
 import org.apache.wookie.beans.jcr.impl.StartFileImpl;
 import org.apache.wookie.beans.jcr.impl.TokenImpl;
@@ -132,7 +130,6 @@ public class JCRPersistenceManager imple
         INTERFACE_TO_CLASS_MAP.put(IParticipant.class, ParticipantImpl.class);
         INTERFACE_TO_CLASS_MAP.put(IPreference.class, PreferenceImpl.class);
         INTERFACE_TO_CLASS_MAP.put(IPreferenceDefault.class, PreferenceDefaultImpl.class);
-        INTERFACE_TO_CLASS_MAP.put(IServerFeature.class, ServerFeatureImpl.class);
         INTERFACE_TO_CLASS_MAP.put(ISharedData.class, SharedDataImpl.class);
         INTERFACE_TO_CLASS_MAP.put(IStartFile.class, StartFileImpl.class);
         INTERFACE_TO_CLASS_MAP.put(IToken.class, TokenImpl.class);
@@ -147,7 +144,6 @@ public class JCRPersistenceManager imple
         BEAN_INTERFACE_TO_CLASS_MAP.put(IAccessRequest.class, AccessRequestImpl.class);
         BEAN_INTERFACE_TO_CLASS_MAP.put(IApiKey.class, ApiKeyImpl.class);
         BEAN_INTERFACE_TO_CLASS_MAP.put(IParticipant.class, ParticipantImpl.class);
-        BEAN_INTERFACE_TO_CLASS_MAP.put(IServerFeature.class, ServerFeatureImpl.class);
         BEAN_INTERFACE_TO_CLASS_MAP.put(IWhitelist.class, WhitelistImpl.class);
         BEAN_INTERFACE_TO_CLASS_MAP.put(IWidget.class, WidgetImpl.class);
         BEAN_INTERFACE_TO_CLASS_MAP.put(IWidgetDefault.class, WidgetDefaultImpl.class);
@@ -882,68 +878,6 @@ public class JCRPersistenceManager imple
     }
 
     /* (non-Javadoc)
-     * @see org.apache.wookie.beans.util.IPersistenceManager#findServerFeatureByName(java.lang.String)
-     */
-    public IServerFeature findServerFeatureByName(String name)
-    {
-        // validate object content manager transaction
-        if (ocm == null)
-        {
-            throw new IllegalStateException("Transaction not initiated or already closed");
-        }
-
-        // get server feature by name
-        if (name != null)
-        {
-            try
-            {
-                IServerFeature [] serverFeature = findByValue(IServerFeature.class, "featureName",
name);
-                if (serverFeature.length == 1)
-                {
-                    return serverFeature[0];
-                }
-            }
-            catch (Exception e)
-            {
-                logger.error("Unexpected exception: "+e, e);
-            }
-        }
-        return null;
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.wookie.beans.util.IPersistenceManager#findServerFeatureNames()
-     */
-    public String[] findServerFeatureNames()
-    {
-        // validate object content manager transaction
-        if (ocm == null)
-        {
-            throw new IllegalStateException("Transaction not initiated or already closed");
-        }
-
-        // get server feature names
-        try
-        {
-            IServerFeature [] serverFeatures = findAll(IServerFeature.class);
-            if (serverFeatures.length > 0)
-            {
-                String [] names = new String[serverFeatures.length];
-                for (int i = 0; (i < serverFeatures.length); i++)
-                {
-                    names[i] = serverFeatures[i].getFeatureName();
-                }
-                return names;
-            }
-        }
-        catch (Exception e)
-        {
-            logger.error("Unexpected exception: "+e, e);
-        }
-        return new String[0];
-    }
-
-    /* (non-Javadoc)
      * @see org.apache.wookie.beans.util.IPersistenceManager#findWidgetByGuid(java.lang.String)
      */
     public IWidget findWidgetByGuid(String guid)

Modified: incubator/wookie/trunk/src/org/apache/wookie/beans/jcr/wookie-schema.cnd
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/beans/jcr/wookie-schema.cnd?rev=1101947&r1=1101946&r2=1101947&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/beans/jcr/wookie-schema.cnd (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/beans/jcr/wookie-schema.cnd Wed May 11 16:15:44
2011
@@ -154,9 +154,5 @@
 - wookie:value (string) mandatory
 - wookie:email (string) mandatory
 
-[wookie:serverFeature] > nt:base
-- wookie:featureName (string) mandatory
-- wookie:className (string) mandatory
-
 [wookie:widgetService] > nt:base
 - wookie:serviceName (string) mandatory

Modified: incubator/wookie/trunk/src/org/apache/wookie/beans/jpa/JPAPersistenceManager.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/beans/jpa/JPAPersistenceManager.java?rev=1101947&r1=1101946&r2=1101947&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/beans/jpa/JPAPersistenceManager.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/beans/jpa/JPAPersistenceManager.java Wed
May 11 16:15:44 2011
@@ -58,7 +58,6 @@ import org.apache.wookie.beans.IParam;
 import org.apache.wookie.beans.IParticipant;
 import org.apache.wookie.beans.IPreference;
 import org.apache.wookie.beans.IPreferenceDefault;
-import org.apache.wookie.beans.IServerFeature;
 import org.apache.wookie.beans.ISharedData;
 import org.apache.wookie.beans.IStartFile;
 import org.apache.wookie.beans.IToken;
@@ -79,7 +78,6 @@ import org.apache.wookie.beans.jpa.impl.
 import org.apache.wookie.beans.jpa.impl.ParticipantImpl;
 import org.apache.wookie.beans.jpa.impl.PreferenceDefaultImpl;
 import org.apache.wookie.beans.jpa.impl.PreferenceImpl;
-import org.apache.wookie.beans.jpa.impl.ServerFeatureImpl;
 import org.apache.wookie.beans.jpa.impl.SharedDataImpl;
 import org.apache.wookie.beans.jpa.impl.StartFileImpl;
 import org.apache.wookie.beans.jpa.impl.TokenImpl;
@@ -127,7 +125,6 @@ public class JPAPersistenceManager imple
         INTERFACE_TO_CLASS_MAP.put(IParticipant.class, ParticipantImpl.class);
         INTERFACE_TO_CLASS_MAP.put(IPreference.class, PreferenceImpl.class);
         INTERFACE_TO_CLASS_MAP.put(IPreferenceDefault.class, PreferenceDefaultImpl.class);
-        INTERFACE_TO_CLASS_MAP.put(IServerFeature.class, ServerFeatureImpl.class);
         INTERFACE_TO_CLASS_MAP.put(ISharedData.class, SharedDataImpl.class);
         INTERFACE_TO_CLASS_MAP.put(IStartFile.class, StartFileImpl.class);
         INTERFACE_TO_CLASS_MAP.put(IToken.class, TokenImpl.class);
@@ -143,7 +140,6 @@ public class JPAPersistenceManager imple
         BEAN_INTERFACE_TO_CLASS_MAP.put(IApiKey.class, ApiKeyImpl.class);
         BEAN_INTERFACE_TO_CLASS_MAP.put(IParticipant.class, ParticipantImpl.class);
         BEAN_INTERFACE_TO_CLASS_MAP.put(IPreference.class, PreferenceImpl.class);
-        BEAN_INTERFACE_TO_CLASS_MAP.put(IServerFeature.class, ServerFeatureImpl.class);
         BEAN_INTERFACE_TO_CLASS_MAP.put(ISharedData.class, SharedDataImpl.class);
         BEAN_INTERFACE_TO_CLASS_MAP.put(IWhitelist.class, WhitelistImpl.class);
         BEAN_INTERFACE_TO_CLASS_MAP.put(IWidget.class, WidgetImpl.class);
@@ -154,7 +150,6 @@ public class JPAPersistenceManager imple
         BEAN_INTERFACE_TO_ID_FIELD_TYPE_MAP.put(IAccessRequest.class, Integer.class);
         BEAN_INTERFACE_TO_ID_FIELD_TYPE_MAP.put(IApiKey.class, Integer.class);
         BEAN_INTERFACE_TO_ID_FIELD_TYPE_MAP.put(IParticipant.class, Integer.class);
-        BEAN_INTERFACE_TO_ID_FIELD_TYPE_MAP.put(IServerFeature.class, Integer.class);
         BEAN_INTERFACE_TO_ID_FIELD_TYPE_MAP.put(IWhitelist.class, Integer.class);
         BEAN_INTERFACE_TO_ID_FIELD_TYPE_MAP.put(IWidget.class, Integer.class);
         BEAN_INTERFACE_TO_ID_FIELD_TYPE_MAP.put(IWidgetDefault.class, String.class);
@@ -736,66 +731,6 @@ public class JPAPersistenceManager imple
     }
 
     /* (non-Javadoc)
-     * @see org.apache.wookie.beans.util.IPersistenceManager#findServerFeatureByName(java.lang.String)
-     */
-    public IServerFeature findServerFeatureByName(String name)
-    {
-        // validate entity manager transaction
-        if (entityManager == null)
-        {
-            throw new IllegalStateException("Transaction not initiated or already closed");
-        }        
-
-        // get server feature by name using custom query
-        if (name != null)
-        {
-            try
-            {
-                Query query = entityManager.createNamedQuery("SERVER_FEATURE");
-                query.setParameter("featureName", name);
-                return (IServerFeature)query.getSingleResult();
-            }
-            catch (NoResultException nre)
-            {
-            }
-            catch (Exception e)
-            {
-                logger.error("Unexpected exception: "+e, e);
-            }
-        }
-        return null;
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.wookie.beans.util.IPersistenceManager#findServerFeatureNames()
-     */
-    @SuppressWarnings("unchecked")
-    public String[] findServerFeatureNames()
-    {
-        // validate entity manager transaction
-        if (entityManager == null)
-        {
-            throw new IllegalStateException("Transaction not initiated or already closed");
-        }        
-
-        // get server feature names using custom query
-        try
-        {
-            Query query = entityManager.createNamedQuery("SERVER_FEATURE_NAMES");
-            List<String> namesList = query.getResultList();
-            if ((namesList != null) && !namesList.isEmpty())
-            {
-                return namesList.toArray(new String[namesList.size()]);
-            }
-        }
-        catch (Exception e)
-        {
-            logger.error("Unexpected exception: "+e, e);
-        }
-        return new String[0];
-    }
-
-    /* (non-Javadoc)
      * @see org.apache.wookie.beans.util.IPersistenceManager#findWidgetByGuid(java.lang.String)
      */
     public IWidget findWidgetByGuid(String guid)

Modified: incubator/wookie/trunk/src/org/apache/wookie/beans/util/IPersistenceManager.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/beans/util/IPersistenceManager.java?rev=1101947&r1=1101946&r2=1101947&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/beans/util/IPersistenceManager.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/beans/util/IPersistenceManager.java Wed May
11 16:15:44 2011
@@ -19,7 +19,6 @@ import java.util.Map;
 import org.apache.wookie.beans.IAccessRequest;
 import org.apache.wookie.beans.IBean;
 import org.apache.wookie.beans.IParticipant;
-import org.apache.wookie.beans.IServerFeature;
 import org.apache.wookie.beans.IWidget;
 import org.apache.wookie.beans.IWidgetInstance;
 
@@ -213,14 +212,6 @@ public interface IPersistenceManager
      * @return retrieved IParticipant bean instance or null if not found
      */
     IParticipant findParticipantViewer(IWidgetInstance widgetInstance);
-
-    /**
-     * Custom name IServerFeature query.
-     * 
-     * @param name name query value
-     * @return retrieved IServerFeature bean instance or null if not found
-     */
-    IServerFeature findServerFeatureByName(String name);
     
     /**
      * Custom name IAccessRequest query.
@@ -229,11 +220,5 @@ public interface IPersistenceManager
      * @return retrieved matching IAccessRequest beans array or empty array if none found
      */
     IAccessRequest [] findApplicableAccessRequests(IWidget widget);
-    
-    /**
-     * Custom IServerFeature names query.
-     * 
-     * @return retrieved IServerFeature beans names array or empty array if none found
-     */
-    String [] findServerFeatureNames();
+ 
 }

Added: incubator/wookie/trunk/src/org/apache/wookie/feature/Feature.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/feature/Feature.java?rev=1101947&view=auto
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/feature/Feature.java (added)
+++ incubator/wookie/trunk/src/org/apache/wookie/feature/Feature.java Wed May 11 16:15:44
2011
@@ -0,0 +1,56 @@
+/*
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ */
+
+package org.apache.wookie.feature;
+
+/**
+ * Default IFeature implementation
+ */
+public class Feature implements IFeature {
+  
+  private String name;
+  private String[] scripts;
+  private String[] stylesheets;
+  
+  public Feature(String name, String[] scripts, String[] stylesheets){
+    this.name = name;
+    this.scripts = scripts;
+    this.stylesheets = stylesheets;
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.wookie.feature.IFeature#getName()
+   */
+  public String getName() {
+    return name;
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.wookie.feature.IFeature#scripts()
+   */
+  public String[] scripts() {
+    return scripts;
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.wookie.feature.IFeature#stylesheets()
+   */
+  public String[] stylesheets() {
+    return stylesheets;
+  }
+
+}

Added: incubator/wookie/trunk/src/org/apache/wookie/feature/Features.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/feature/Features.java?rev=1101947&view=auto
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/feature/Features.java (added)
+++ incubator/wookie/trunk/src/org/apache/wookie/feature/Features.java Wed May 11 16:15:44
2011
@@ -0,0 +1,153 @@
+/*
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ */
+
+package org.apache.wookie.feature;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.ServletContext;
+import org.apache.log4j.Logger;
+import org.apache.wookie.feature.wave.WaveAPIImpl;
+import org.apache.wookie.w3c.util.IRIValidator;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.input.SAXBuilder;
+
+/**
+ * Installs and manages Features. 
+ * 
+ * Features are loaded from the DEFAULT_FEATURE_FOLDER, looking for files named feature.xml.
+ * 
+ * Feature.xml files consist of a <feature> element with child <name> <script>
and <stylesheet> elements.
+ * 
+ * The <name> element contains the Feature name IRI; the <script> and <stylesheet>
elements should contain a src attribute
+ * with the filename of the resource relative to the feature folder (e.g. "myfile.js")
+ */
+public class Features {
+  
+  /*
+   * The current features installed
+   */
+  private static ArrayList<IFeature> features;
+
+  static Logger _logger = Logger.getLogger(Features.class.getName());
+
+  /*
+   * The default folder name for features 
+   */
+  public static final File DEFAULT_FEATURE_FOLDER = new File("features");
+  
+  /**
+   * Get the currently installed features
+   * @return a List of IFeature objects
+   */
+  public static List<IFeature> getFeatures(){
+    return features;
+  }
+  
+  /**
+   * Get an array of names of installed features
+   * @return an array of names as Strings
+   */
+  public static String[] getFeatureNames(){
+    ArrayList<String> featureNames = new ArrayList<String>();
+    for (IFeature feature: features){
+      featureNames.add(feature.getName());
+    }
+    return featureNames.toArray(new String[featureNames.size()]);
+  }
+  
+  /**
+   * Explicitly load any "special" features
+   */
+  public static void loadDefaultFeatures(){
+    features.add(new WaveAPIImpl());
+  }
+
+  /**
+   * Loads features from the default feature folder in the current servlet context
+   * @param context the current servlet context
+   */
+  public static void loadFeatures(ServletContext context){
+    
+    // Clear any existing installed features
+    features = new ArrayList<IFeature>();
+    
+    // Load defaults
+    loadDefaultFeatures();
+    
+    // Iterate over child folders of the /features folder
+    for (File folder: DEFAULT_FEATURE_FOLDER.listFiles()){
+
+      // If the folder contains a feature.xml file, parse it and create a Feature object
+      if (folder.isDirectory()){
+        File featureXml = new File(folder.getPath()+"/feature.xml");
+        if (featureXml.exists() && featureXml.canRead()){
+          try {
+            // Create a base path for resources using the current servlet context and default
feature folder 
+            String basePath = context.getContextPath() + "/" + DEFAULT_FEATURE_FOLDER + "/"
+ folder.getName();
+            // Load the feature and add it to the features collection
+            IFeature feature = loadFeature(featureXml, basePath);
+            features.add(feature);
+            _logger.info("Installed feature:"+feature.getName());   
+          } catch (Exception e) {
+            _logger.error("Error installing feature:"+e.getMessage());
+          }
+        }
+      }
+    }
+  }
+
+  /**
+   * Load a feature.xml file
+   * @param featureFile the feature.xml file to load
+   * @param basePath the base path (e.g. /wookie/features) to prepend to any resources
+   * @return an IFeature implementation
+   * @throws Exception
+   */
+  private static IFeature loadFeature(File featureFile, String basePath) throws Exception{
+    // Parse the XML
+    Document doc;
+    doc = new SAXBuilder().build(featureFile);
+
+    String name = doc.getRootElement().getChild("name").getText();
+    @SuppressWarnings("unchecked")
+    List<Element> scriptElements = doc.getRootElement().getChildren("script");
+    @SuppressWarnings("unchecked")
+    List<Element> stylesheetElements = doc.getRootElement().getChildren("stylesheet");
+
+    // Is the feature name a valid IRI?
+    if (!IRIValidator.isValidIRI(name)){
+      throw new Exception("Invalid feature: name is not a valid IRI");            
+    }
+    // Construct arrays for scripts and stylesheet URLs
+    String[] scripts = new String[doc.getRootElement().getChildren("script").size()];
+    for (int i=0;i<scriptElements.size();i++){
+      scripts[i] = basePath + "/" + scriptElements.get(i).getAttributeValue("src");
+    }
+    String[] stylesheets = new String[doc.getRootElement().getChildren("stylesheet").size()];
+    for (int i=0;i<stylesheetElements.size();i++){
+      stylesheets[i] =  basePath + "/" + stylesheetElements.get(i).getAttributeValue("src");
+    }
+    // Create a Feature object and return it
+    IFeature feature = new Feature(name, scripts, stylesheets);
+    return feature;
+  }
+
+}

Modified: incubator/wookie/trunk/src/org/apache/wookie/server/ContextListener.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/server/ContextListener.java?rev=1101947&r1=1101946&r2=1101947&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/server/ContextListener.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/server/ContextListener.java Wed May 11 16:15:44
2011
@@ -32,7 +32,7 @@ import org.apache.wookie.Messages;
 import org.apache.wookie.ajaxmodel.IWidgetRuntimeHelper;
 import org.apache.wookie.beans.util.IPersistenceManager;
 import org.apache.wookie.beans.util.PersistenceManagerFactory;
-import org.apache.wookie.feature.FeatureLoader;
+import org.apache.wookie.feature.Features;
 import org.apache.wookie.helpers.FlashMessage;
 import org.apache.wookie.helpers.WidgetFactory;
 import org.apache.wookie.util.WgtWatcher;
@@ -135,18 +135,7 @@ public class ContextListener implements 
 			/*
 			 * Load installed features
 			 */
-			PropertiesConfiguration featuresConfiguration;
-			File localFeaturesPropsFile = new File(System.getProperty("user.dir") + File.separator
+ "local.features.properties");
-			if (localFeaturesPropsFile.exists()) {
-				featuresConfiguration = new PropertiesConfiguration(localFeaturesPropsFile);
-				_logger.info("Loading local features file: " + localOpenSocialPropsFile.toString());
-			} else {
-				featuresConfiguration = new PropertiesConfiguration("features.properties");
-				featuresConfiguration.setFile(localFeaturesPropsFile);
-				featuresConfiguration.save();
-				_logger.info("Loading default features, configure your local server using: " + localFeaturesPropsFile.toString());
-			}
-			FeatureLoader.loadFeatures(featuresConfiguration);
+			Features.loadFeatures(context);
 			
 			/*
 			 * Run diagnostics
@@ -200,7 +189,7 @@ public class ContextListener implements 
 	 						fac.setLocales(locales);
 	 						fac.setLocalPath(contextPath+localWidgetFolderPath);
 	 						fac.setOutputDirectory(WIDGETFOLDER);
-	 						fac.setFeatures(persistenceManager.findServerFeatureNames());
+	 						fac.setFeatures(Features.getFeatureNames());
 	 						fac.setStartPageProcessor(new StartPageProcessor());
 	 						W3CWidget model = fac.parse(upload);
 	 						WidgetJavascriptSyntaxAnalyzer jsa = new WidgetJavascriptSyntaxAnalyzer(fac.getUnzippedWidgetDirectory());

Modified: incubator/wookie/trunk/src/org/apache/wookie/updates/UpdatesController.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/updates/UpdatesController.java?rev=1101947&r1=1101946&r2=1101947&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/updates/UpdatesController.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/updates/UpdatesController.java Wed May 11
16:15:44 2011
@@ -23,7 +23,6 @@ import javax.servlet.http.HttpServletRes
 
 import org.apache.commons.configuration.Configuration;
 import org.apache.log4j.Logger;
-import org.apache.wookie.beans.IServerFeature;
 import org.apache.wookie.beans.IWidget;
 import org.apache.wookie.beans.util.IPersistenceManager;
 import org.apache.wookie.beans.util.PersistenceManagerFactory;
@@ -32,6 +31,7 @@ import org.apache.wookie.exceptions.Inva
 import org.apache.wookie.exceptions.ResourceDuplicationException;
 import org.apache.wookie.exceptions.ResourceNotFoundException;
 import org.apache.wookie.exceptions.UnauthorizedAccessException;
+import org.apache.wookie.feature.Features;
 import org.apache.wookie.helpers.FlashMessage;
 import org.apache.wookie.helpers.WidgetFactory;
 import org.apache.wookie.util.html.StartPageProcessor;
@@ -194,13 +194,7 @@ public class UpdatesController extends C
 			_logger.error(e);
 		}
 		// Configure the widget factory with the installed feature set
-		IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
-		IServerFeature[] features = persistenceManager.findAll(IServerFeature.class);
-		String[] featureNames = new String[features.length];
-		for (int i=0;i<features.length;i++){
-			featureNames[i] = features[i].getFeatureName();
-		}
-		factory.setFeatures(featureNames);
+		factory.setFeatures(Features.getFeatureNames());
 		factory.setStartPageProcessor(new StartPageProcessor());
 		return factory;
 	}

Modified: incubator/wookie/trunk/src/org/apache/wookie/util/html/StartPageProcessor.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/util/html/StartPageProcessor.java?rev=1101947&r1=1101946&r2=1101947&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/util/html/StartPageProcessor.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/util/html/StartPageProcessor.java Wed May
11 16:15:44 2011
@@ -17,9 +17,9 @@ import java.io.File;
 import java.io.FileReader;
 import java.io.FileWriter;
 
-import org.apache.wookie.beans.IServerFeature;
 import org.apache.wookie.beans.util.IPersistenceManager;
 import org.apache.wookie.beans.util.PersistenceManagerFactory;
+import org.apache.wookie.feature.Features;
 import org.apache.wookie.feature.IFeature;
 import org.apache.wookie.w3c.IContentEntity;
 import org.apache.wookie.w3c.IFeatureEntity;
@@ -77,11 +77,13 @@ public class StartPageProcessor implemen
 	 */
 	private void addFeatures(IHtmlProcessor engine,W3CWidget model) throws Exception{
 		for (IFeatureEntity feature: model.getFeatures()){
-		    IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
-			IServerFeature sf = persistenceManager.findServerFeatureByName(feature.getName());
-			IFeature theFeature = getFeatureInstanceForName(sf.getClassName());
-			addScripts(engine, theFeature);
-			addStylesheets(engine, theFeature);
+			for (IFeature theFeature: Features.getFeatures()){
+			  if (theFeature.getName().equals(feature.getName())){
+		      addScripts(engine, theFeature);
+		      addStylesheets(engine, theFeature);			    
+			  }
+			}
+			
 		}
 	}
 	



Mime
View raw message