Attached is a patch that implements the capability handling for J2.

Clients, MimeType, MediaType and Capability information are now stored in the 
database and accessed through OJB. The xreg files used in J1 to store the 
information are no longer used.

Documentation about the supported types and the database schema can be found 
in ./docs/CapabilityHandlingJ2.pdf 

Roger
Index: maven.xml
===================================================================
RCS file: /home/cvspublic/jakarta-jetspeed-2/maven.xml,v
retrieving revision 1.11
diff -u -r1.11 maven.xml
--- maven.xml   4 Dec 2003 18:38:44 -0000       1.11
+++ maven.xml   19 Dec 2003 02:00:44 -0000
@@ -92,6 +92,14 @@
                ignoreFailures="false"/>
                
           <attainGoal name="copy.shared.deps" />
+          
+          <maven:reactor
+               basedir="${basedir}"
+               includes="portal/project.xml"
+               goals="deploy"
+               banner="Deploys the jetspeed war"
+               postProcessing="false"
+               ignoreFailures="false"/>
   </goal>
   
   <goal name="copy.shared.deps"> 

Index: portal/src/java/org/apache/jetspeed/capability/CapabilityMap.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/capability/CapabilityMap.java,v
retrieving revision 1.2
diff -u -r1.2 CapabilityMap.java
--- portal/src/java/org/apache/jetspeed/capability/CapabilityMap.java   5 Dec 2003 
21:09:21 -0000       1.2
+++ portal/src/java/org/apache/jetspeed/capability/CapabilityMap.java   19 Dec 2003 
02:00:53 -0000
@@ -67,51 +67,32 @@
 public interface CapabilityMap
 {

-    /** Handle HTML Table */
-    public static final int HTML_TABLE = 0;
-
-    /** Handle inline image display */
-    public static final int HTML_IMAGE = 1;
-
-    /** Handle form handling */
-    public static final int HTML_FORM = 2;
-
-    /** Handle frames */
-    public static final int HTML_FRAME = 3;
-
-    /** Handle client-side applet */
-    public static final int HTML_JAVA = 17;
-    public static final int HTML_JAVA1_0 = 4;
-    public static final int HTML_JAVA1_1 = 5;
-    public static final int HTML_JAVA1_2 = 6;
-
-    /** Handle client-side javascript */
-    public static final int HTML_JSCRIPT = 18;
-    public static final int HTML_JSCRIPT1_0 = 7;
-    public static final int HTML_JSCRIPT1_1 = 8;
-    public static final int HTML_JSCRIPT1_2 = 9;
-
-    /** Handle activex controls */
-    public static final int HTML_ACTIVEX = 10;
-
-    /** Handle CSS1 */
-    public static final int HTML_CSS1 = 11;
-
-    /** Handle CSS2 */
-    public static final int HTML_CSS2 = 12;
-
-    /** Handle CSSP */
-    public static final int HTML_CSSP = 13;
-
-    /** Handle XML */
-    public static final int HTML_XML = 14;
-
-    /** Handle XSL */
-    public static final int HTML_XSL = 15;
-
-    /** Handle DOM */
-    public static final int HTML_DOM = 16;
-
+       /**
+               Sets the client for the CapabilityMap
+       */
+       public void setClient(Client client);
+
+       /**
+               Returns the Client for the CapabilityMap
+       */
+       public Client getClient();
+
+       /**
+               Add capability to the CapabilityMap
+       */
+       public void addCapability(Capability capability);
+
+       /**
+               Add Mimetype to the MimetypeMap
+       */
+       public void addMimetype(MimeType  mimetype);
+
+       /**
+               Add MediaType to the MediaTypeMap
+       */
+       public void addMediaType(MediaTypeEntry  mediatype);
+
+
     /**
     Returns the preferred MIME type for the current user-agent
     */
@@ -120,7 +101,7 @@
     /**
     Returns the preferred media type for the current user-agent
     */
-    public String getPreferredMediaType();
+    public MediaTypeEntry getPreferredMediaType();

     /**
      * Returns an ordered list of supported media-types, from most preferred
@@ -132,6 +113,12 @@
     Returns the user-agent string
     */
     public String getAgent();
+
+    /**
+     *
+     * set userAgent
+     */
+    public void setAgent(String userAgent);

     /**
     Checks to see if the current agent has the specified capability
Index: portal/src/java/org/apache/jetspeed/capability/CapabilityService.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/capability/CapabilityService.java,v
retrieving revision 1.1
diff -u -r1.1 CapabilityService.java
--- portal/src/java/org/apache/jetspeed/capability/CapabilityService.java       5 Dec 
2003 21:09:21 -0000       1.1
+++ portal/src/java/org/apache/jetspeed/capability/CapabilityService.java       19 Dec 
2003 02:00:58 -0000
@@ -54,6 +54,7 @@
 package org.apache.jetspeed.capability;

 import java.util.Iterator;
+import java.util.Collection;

 import org.apache.jetspeed.cps.CommonService;

@@ -69,8 +70,9 @@
     public String SERVICE_NAME = "capability";

     /**
-     * @param userAgent
-     * @return
+     * @param userAgent Agent from the request
+     * @return CapabilityMap populated with Capabilities, Mimetypes and Mediatype
+     * that match the userAgent
      */
     CapabilityMap getCapabilityMap(String userAgent);

@@ -78,4 +80,26 @@
      * @return
      */
     Iterator getClients();
+
+    /**
+     *
+     * @param userAgent
+     * @return Client that matches agent or null if no match is found
+     *
+     */
+    Client findClient(String userAgent);
+
+       /**
+        *
+        * @param Mimetype
+        *
+        * @return Collection of Mediatypes that matches the mimetypes
+        */
+       Collection  getMediaTypesForMimeTypes(Iterator mimetypes);
+
+       /**
+        * Clears CapabilityMap cache
+        *
+        */
+       public void DeleteCapabilityMapCache();
 }
Index: portal/src/java/org/apache/jetspeed/capability/Client.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/capability/Client.java,v
retrieving revision 1.1
diff -u -r1.1 Client.java
--- portal/src/java/org/apache/jetspeed/capability/Client.java  5 Dec 2003 21:09:21 
-0000       1.1
+++ portal/src/java/org/apache/jetspeed/capability/Client.java  19 Dec 2003 02:00:58 
-0000
@@ -53,7 +53,7 @@
  */
 package org.apache.jetspeed.capability;

-import java.util.Vector;
+import java.util.Collection;

 /**
  * <P>
@@ -149,13 +149,13 @@
      * @return the MimeTypeMap
      * @see MimeTypeMap
      */
-    public Vector getMimetypes();
+    public Collection getMimetypes();

     /**
      * Set MimeTypes
      * @param mimetypes
      */
-    public void setMimetypes(Vector mimetypes);
+    public void setMimetypes(Collection mimetypes);

     String getName();
     void setName(String name);
@@ -168,7 +168,7 @@
      * @return the CapabilityMap
      * @see CapabilityMap
      */
-    public Vector getCapabilities();
-    public void setCapabilities(Vector capabilities);
+    public Collection getCapabilities();
+    public void setCapabilities(Collection capabilities);

 }
Index: portal/src/java/org/apache/jetspeed/capability/MediaTypeEntry.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/capability/MediaTypeEntry.java,v
retrieving revision 1.1
diff -u -r1.1 MediaTypeEntry.java
--- portal/src/java/org/apache/jetspeed/capability/MediaTypeEntry.java  5 Dec 2003 
21:09:21 -0000       1.1
+++ portal/src/java/org/apache/jetspeed/capability/MediaTypeEntry.java  19 Dec 2003 
02:00:58 -0000
@@ -54,6 +54,7 @@
 package org.apache.jetspeed.capability;

 import java.util.Vector;
+import java.util.Collection;


 /**
@@ -110,13 +111,13 @@
    * @return the MimeTypeMap
    * @see MimeTypeMap
    */
-  public Vector getMimetypes();
+  public Collection getMimetypes();

   /**
    * Set mime types
    * @param mimetypes
    */
-  public void setMimetypes(Vector mimetypes);
+  public void setMimetypes(Collection mimetypes);

   /**
    *    removes the MimeType to the MimeType map
@@ -130,6 +131,28 @@
    * @param name
    */
   public void addMimetype(String name);
+
+  /**
+   * Set name ob MediaTypeEntry
+   */
+  public void setName(String name);
+
+  /**
+   * Get name ob MediaTypeEntry
+   */
+
+  public String getName();
+
+  public String getTitle();
+
+
+       public void setTitle(String title);
+
+       public String getDescription();
+
+
+       public void setDescription(String desc);
+


 }
Index: portal/src/java/org/apache/jetspeed/capability/impl/CapabilityMapImpl.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/capability/impl/CapabilityMapImpl.java,v
retrieving revision 1.1
diff -u -r1.1 CapabilityMapImpl.java
--- portal/src/java/org/apache/jetspeed/capability/impl/CapabilityMapImpl.java  5 Dec 
2003 21:09:21 -0000       1.1
+++ portal/src/java/org/apache/jetspeed/capability/impl/CapabilityMapImpl.java  19 Dec 
2003 02:00:59 -0000
@@ -55,10 +55,13 @@

 import org.apache.jetspeed.capability.CapabilityMap;
 import org.apache.jetspeed.capability.Client;
+import org.apache.jetspeed.capability.Capability;
+import org.apache.jetspeed.capability.MediaTypeEntry;

-import java.util.Hashtable;
-import java.util.Enumeration;
+
+import java.util.HashMap;
 import java.util.Iterator;
+import java.util.Map;

 import org.apache.jetspeed.capability.MimeType;

@@ -72,28 +75,84 @@
 {
     // Members
     private String      useragent;        // User agent for request
-    private Hashtable    mimeTypeMap;    // supported Mimetypes for Agent
-    private Hashtable    capabiltyMap;    // supported Capabilities for Agent
-    private Hashtable    mediaTypeMap;    // supported MediaTypes for Agent
-    private Client    client;            // client for Agent
+    private Map                mimeTypeMap = new HashMap();    // supported Mimetypes 
for Agent
+    private Map                capabilityMap = new HashMap();    // supported 
Capabilities for Agent
+    private Map                mediaTypeMap = new HashMap();    // supported 
MediaTypes for Agent
+    private Client     client;            // client for Agent
+
+
+       /**
+               Sets the client for the CapabilityMap
+       */
+       public void setClient(Client client)
+       {
+               this.client = client;
+       }
+
+       /**
+               Returns the Client for the CapabilityMap
+       */
+       public Client getClient()
+       {
+               return this.client;
+       }
+
+       /**
+               Add capability to the CapabilityMap
+       */
+       public void addCapability(Capability capability)
+       {
+                       this.capabilityMap.put(capability.getName(), capability);
+       }
+
+       /**
+               Add Mimetype to the MimetypeMap
+       */
+       public void addMimetype(MimeType  mimetype)
+       {
+               this.mimeTypeMap.put(mimetype.getName(), mimetype);
+       }
+
+       /**
+               Add MediaType to the MediaTypeMap
+       */
+       public void addMediaType(MediaTypeEntry  mediatype)
+       {
+               this.mediaTypeMap.put(mediatype.getName(), mediatype);
+       }

-
     /**
     Returns the preferred MIME type for the current user-agent
     */
     public MimeType getPreferredType()
     {
         // Return first entry
-        Enumeration e = this.mimeTypeMap.elements();
-        return (MimeType)e.nextElement();
+        Iterator e = this.mimeTypeMap.values().iterator();
+        if (e.hasNext())
+        {
+               return (MimeType)e.next();
+        }
+        else
+        {
+               return null;
+        }
     }

     /**
     Returns the preferred media type for the current user-agent
     */
-    public String getPreferredMediaType()
+    public MediaTypeEntry getPreferredMediaType()
     {
-        return null;
+               // Return first entry
+               Iterator e = this.mediaTypeMap.values().iterator();
+               if (e.hasNext())
+               {
+                       return (MediaTypeEntry)e.next();
+               }
+               else
+               {
+                       return null;
+               }
     }

     /**
@@ -102,7 +161,7 @@
      */
     public Iterator listMediaTypes()
     {
-        return null;
+        return mediaTypeMap.values().iterator();
     }

     /**
@@ -112,12 +171,28 @@
     {
         return this.useragent;
     }
+
+       /**
+        * set userAgent
+        */
+       public void setAgent(String userAgent)
+       {
+               this.useragent = userAgent;
+       }

     /**
     Checks to see if the current agent has the specified capability
     */
     public boolean hasCapability(int capability)
-    {
+    {
+       Iterator capabilities = capabilityMap.values().iterator();
+       while (capabilities.hasNext() )
+       {
+               if (((Capability)capabilities.next()).getCapabilityId() == capability)
+               {
+                       return true;
+               }
+       }
         return false;
     }

@@ -126,7 +201,15 @@
     */
     public boolean hasCapability(String capability)
     {
-        return false;
+               Iterator capabilities = capabilityMap.values().iterator();
+               while (capabilities.hasNext() )
+               {
+                       if (((Capability)capabilities.next()).getName() == capability)
+                       {
+                               return true;
+                       }
+               }
+               return false;
     }

     /**
@@ -142,7 +225,15 @@
     */
     public boolean supportsMimeType(MimeType mimeType)
     {
-        return false;
+               Iterator mimetypes = mimeTypeMap.values().iterator();
+               while (mimetypes.hasNext() )
+               {
+                       if (((MimeType)mimetypes.next()).getName() == 
mimeType.getName())
+                       {
+                               return true;
+                       }
+               }
+               return false;
     }

     /**
@@ -156,7 +247,15 @@
      */
     public boolean supportsMediaType(String media)
     {
-        return false;
+               Iterator mediatypes = mediaTypeMap.values().iterator();
+               while (mediatypes.hasNext() )
+               {
+                       if (((MediaTypeEntry)mediatypes.next()).getName() == media)
+                       {
+                               return true;
+                       }
+               }
+               return false;
     }

     /**
Index: portal/src/java/org/apache/jetspeed/capability/impl/CapabilityServiceImpl.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/capability/impl/CapabilityServiceImpl.java,v
retrieving revision 1.1
diff -u -r1.1 CapabilityServiceImpl.java
--- portal/src/java/org/apache/jetspeed/capability/impl/CapabilityServiceImpl.java     
 5 Dec 2003 21:09:21 -0000       1.1
+++ portal/src/java/org/apache/jetspeed/capability/impl/CapabilityServiceImpl.java     
 19 Dec 2003 02:01:00 -0000
@@ -55,10 +55,16 @@

 import java.util.Collection;
 import java.util.Iterator;
+import java.util.Hashtable;
+

 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.jetspeed.capability.CapabilityMap;
+import org.apache.jetspeed.capability.Capability;
+import org.apache.jetspeed.capability.MimeType;
+import org.apache.jetspeed.capability.MediaTypeEntry;
+import org.apache.jetspeed.capability.impl.CapabilityMapImpl;
 import org.apache.jetspeed.capability.CapabilityService;
 import org.apache.jetspeed.capability.Client;
 import org.apache.jetspeed.cps.BaseCommonService;
@@ -66,12 +72,14 @@
 import org.apache.jetspeed.cps.CommonPortletServices;
 import org.apache.jetspeed.persistence.PersistencePlugin;
 import org.apache.jetspeed.persistence.PersistenceService;
-import org.apache.regexp.RE;
+
+import org.apache.jetspeed.persistence.LookupCriteria;

 /**
  * CapabilityServiceImpl
  *
  * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Roger Ruttimann</a>
  * @version $Id: CapabilityServiceImpl.java,v 1.1 2003/12/05 21:09:21 taylor Exp $
  */
 public class CapabilityServiceImpl extends BaseCommonService implements 
CapabilityService
@@ -87,10 +95,16 @@
     public static final String DEFAULT_AGENT = "Mozilla/4.0";

     public static final String AGENT_XML = "agentxml/1.0";
+
+    // Cache for the capability maps
+    Hashtable capabilityMapCache = null;

     private Collection clients = null;

     private Class clientClass;
+       private Class capabilityClass;
+       private Class mimetypeClass;
+       private Class mediatypeClass;

     /**
      *
@@ -109,22 +123,15 @@
             String pluginName = 
getConfiguration().getString("persistence.plugin.name", "jetspeed");

             plugin = ps.getPersistencePlugin(pluginName);
-
-            String className = getConfiguration().getString("client.impl", null);
-
-            if (null == className)
-            {
-                throw new CPSInitializationException("Factory class properties not 
found in configuration.");
-            }
-
-            try
-            {
-                clientClass = createClass(className);
-            }
-            catch (ClassNotFoundException e)
-            {
-                throw new CPSInitializationException("Could not preload client 
implementation class.", e);
-            }
+
+            // Create classes
+                       clientClass = createClass("client.impl");
+                       capabilityClass= createClass("capability.impl");
+                       mimetypeClass= createClass("mimetype.impl");
+                       mediatypeClass= createClass("mediatype.impl");
+
+                       capabilityMapCache = new Hashtable();
+

             setInit(true);
         }
@@ -135,49 +142,116 @@
      * @return
      * @throws ClassNotFoundException
      */
-    private Class createClass(String className) throws ClassNotFoundException
+    private Class createClass(String classDescriptor) throws  
CPSInitializationException
     {
-        return Class.forName(className);
+               String className = getConfiguration().getString(classDescriptor, null);
+
+               if (null == className)
+               {
+                       throw new CPSInitializationException("Factory class properties 
not found in configuration.");
+               }
+
+               try
+               {
+                       return clientClass = Class.forName(className);
+               }
+               catch (ClassNotFoundException e)
+               {
+                       throw new CPSInitializationException("Could not preload client 
implementation class.", e);
+               }
     }
+

-    /* (non-Javadoc)
+    /**
+     * @param userAgent Agent from the request
      * @see 
org.apache.jetspeed.services.capability.CapabilityService#getCapabilityMap(java.lang.String)
      */
     public CapabilityMap getCapabilityMap(String userAgent)
     {
         CapabilityMap map = null;
+        boolean bClientFound = false;

         if (userAgent == null)
         {
             userAgent = DEFAULT_AGENT;
         }
-
-        Client entry = findClient(userAgent);
-
-        if (entry == null)
-        {
-            if (userAgent.equals(DEFAULT_AGENT))
-            {
-                log.error("CapabilityMap: Default agent not found in Client Registry 
!");
-            }
-            else
-            {
-                if (log.isDebugEnabled())
-                {
-                    log.debug("CapabilityMap: useragent " + userAgent + "unknown, 
falling back to default");
-                }
-                // LEFT OFF HERE: map = getDefaultCapabilityMap();
-            }
-        }
-        else
-        {
-            // LEFT OFF HERE: map = new BaseCapabilityMap(userAgent, entry);
-        }
-
-        if (log.isDebugEnabled())
-        {
-            log.debug("CapabilityMap: User-agent: " + userAgent + " mapped to " + 
map);
-        }
+
+        // Check the cache if we have already a capability map for
+        // the given Agent
+               map = (CapabilityMap)capabilityMapCache.get(userAgent);
+
+               if ( map != null )
+               {
+                       // Entry found
+                       return map;
+               }
+
+
+               while (!bClientFound)
+               {
+               Client entry = findClient(userAgent);
+
+               if (entry == null)
+               {
+                   if (userAgent.equals(DEFAULT_AGENT))
+                   {
+                       log.error("CapabilityMap: Default agent not found in Client 
Registry !");
+
+                       // Stop searching -- event the default userAgent can't be found
+                                       bClientFound = true;
+                   }
+                   else
+                   {
+                       // Retry with the default Agent
+                       if (log.isDebugEnabled())
+                       {
+                           log.debug("CapabilityMap: useragent " + userAgent + 
"unknown, falling back to default");
+                       }
+
+                                       // Use default Client
+                       userAgent = DEFAULT_AGENT;
+                   }
+               }
+               else
+               {
+                       // Found Client entry start populating the capability map.
+                       map = new CapabilityMapImpl();
+
+                       // Add client to CapabilityMap
+                   map.setClient(entry);
+
+                   // Add capabilities
+                               Iterator capabilities =  
entry.getCapabilities().iterator();
+                               while (capabilities.hasNext())
+                               {
+                                       
map.addCapability((Capability)capabilities.next());
+                               }
+
+
+                               Collection mediatypes = 
getMediaTypesForMimeTypes(entry.getMimetypes().iterator());
+
+
+                               // Add Mimetypes to map
+                               Iterator mimetypes        =  
entry.getMimetypes().iterator();
+                               while (mimetypes.hasNext())
+                               {
+                                       map.addMimetype((MimeType)mimetypes.next());
+                               }
+
+
+                               Iterator media = mediatypes.iterator();
+                               while (media.hasNext())
+                               {
+                                       map.addMediaType((MediaTypeEntry)media.next());
+                               }
+
+                               // Add map to cache
+                               capabilityMapCache.put(userAgent, map);
+
+                               return map;
+               }
+
+               }

         return map;
     }
@@ -206,15 +280,17 @@
             {
                 try
                 {
-                    RE r = new RE(client.getUserAgentPattern());
-                    r.setMatchFlags(RE.MATCH_CASEINDEPENDENT);
-
-                    if (r.match(userAgent))
+                       // Java 1.4 has regular expressions build in
+                       String exp = client.getUserAgentPattern();
+                    //RE r = new RE(client.getUserAgentPattern());
+                    //r.setMatchFlags(RE.MATCH_CASEINDEPENDENT);
+                                       //if (r.match(userAgent))
+                    if (userAgent.matches(exp))
                     {

                         if (log.isDebugEnabled())
                         {
-                            log.debug("ClientRegistry: " + userAgent + " matches " + 
client.getUserAgentPattern());
+                            log.debug("Client: " + userAgent + " matches " + 
client.getUserAgentPattern());
                         }

                         return client;
@@ -223,14 +299,14 @@
                     {
                         if (log.isDebugEnabled())
                         {
-                            log.debug("ClientRegistry: " + userAgent + " does not 
match " + client.getUserAgentPattern());
+                            log.debug("Client: " + userAgent + " does not match " + 
client.getUserAgentPattern());
                         }
                     }
                 }
-                catch (org.apache.regexp.RESyntaxException e)
+                catch (java.util.regex.PatternSyntaxException e)
                 {
                     String message =
-                        "ClientRegistryService: UserAgentPattern not valid : "
+                        "CapabilityServiceImpl: UserAgentPattern not valid : "
                             + client.getUserAgentPattern()
                             + " : "
                             + e.getMessage();
@@ -254,4 +330,40 @@

         return this.clients.iterator();
     }
+
+    /**
+     *
+     * @param
+     *
+     * @return Collection of MediaTypeEntries
+     */
+    public Collection  getMediaTypesForMimeTypes(Iterator mimetypes)
+    {
+               //Find the MediaType by matching the Mimetype
+               LookupCriteria criteria = plugin.newLookupCriteria();
+
+               // Add Mimetypes to map and create query
+               while (mimetypes.hasNext())
+               {
+                       MimeType mt = (MimeType)mimetypes.next();
+
+                       // Add mimetype to query
+                       // Note: mimetypes is a member of MediaTypeEntryImp
+                       criteria.addEqualTo("mimetypes.name",mt.getName() );
+               }
+
+               return plugin.getCollectionByQuery(mediatypeClass, 
plugin.generateQuery(mediatypeClass, criteria));
+
+       }
+
+       /**
+        * Clears CapabilityMap cache
+        *
+        */
+       public void DeleteCapabilityMapCache()
+       {
+               capabilityMapCache.clear();
+               clients = null;
+       }
+
 }
Index: portal/src/java/org/apache/jetspeed/capability/impl/CapabilityValveImpl.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/capability/impl/CapabilityValveImpl.java,v
retrieving revision 1.2
diff -u -r1.2 CapabilityValveImpl.java
--- portal/src/java/org/apache/jetspeed/capability/impl/CapabilityValveImpl.java       
 17 Dec 2003 20:46:33 -0000      1.2
+++ portal/src/java/org/apache/jetspeed/capability/impl/CapabilityValveImpl.java       
 19 Dec 2003 02:01:00 -0000
@@ -60,7 +60,11 @@
 import org.apache.jetspeed.pipeline.valve.CapabilityValve;
 import org.apache.jetspeed.pipeline.valve.ValveContext;
 import org.apache.jetspeed.request.RequestContext;
-
+import org.apache.jetspeed.capability.CapabilityService;
+import org.apache.jetspeed.capability.CapabilityMap;
+import org.apache.jetspeed.capability.MediaTypeEntry;
+import org.apache.jetspeed.capability.MimeType;
+import org.apache.jetspeed.cps.CommonPortletServices;

 /**
  * Invokes the capability mapper in the request pipeline
@@ -80,6 +84,11 @@
     {

     }
+
+       protected CapabilityService getService()
+       {
+               return (CapabilityService) 
CommonPortletServices.getPortalService(CapabilityService.SERVICE_NAME);
+       }

     public void invoke(RequestContext request, ValveContext context)
         throws PipelineException
@@ -90,16 +99,53 @@
         {
             // TODO: support request based selection of media type instead of using 
User-Agent header
             //       mediaType = 
request.getRequest().getQueryString(Profiler.PARAM_MEDIA_TYPE);
-      /*
-            String agent = request.getRequest().getHeader("User-Agent");
+
+            String agent = request.getRequest().getHeader("User-Agent");
+
+            // Connect to CapabilityService
+                       CapabilityService service = getService();
+
+                       // Get capability map
+                       CapabilityMap cm = service.getCapabilityMap(agent);
+
+                       if ( cm == null)
+                       {
+                               log.debug("Couldn't create capability map for agent: " 
+ agent);
+                       }
+                       else
+                       {
+                               log.debug("Created Capability map for agent: " + 
agent);
+                       }
+
+                       MediaTypeEntry mediaType = cm.getPreferredMediaType();
+                       MimeType mimeType = cm.getPreferredType();
+
+                       String encoding = request.getRequest().getCharacterEncoding();
+
+
+                       if (encoding == null)
+                       {
+                               if (mediaType != null && mediaType.getCharacterSet() 
!= null)
+                               {
+                                       encoding = mediaType.getCharacterSet();
+                               }
+                       }
+
+                       if (log.isDebugEnabled())
+                       {
+                               log.debug("MediaType: " + mediaType.getName());
+                               log.debug("Encoding: "  + encoding);
+                               log.debug("Mimetype: "  + mimeType.getName());
+                       }
+                 /*
             CapabilityMap cm = CapabilityMapFactory.getCapabilityMap(agent);

             String mediaType = cm.getPreferredMediaType();

             String mimeType = cm.getPreferredType().getCode();
-      */
+
             String encoding = request.getRequest().getCharacterEncoding();
-    /*
+
             if (encoding == null)
             {
                 Configuration configuration = 
Jetspeed.getContext().getConfiguration();
@@ -124,14 +170,14 @@
             request.setCharacterEncoding(encoding);

             // Put the CapabilityMap into the request
-            // request.setCapabilityMap(cm);
+            request.setCapabilityMap(cm);

             // Put the Media Type into the request
-            request.setMediaType("HTML");
+            request.setMediaType(mediaType.getName());

             // Put the Mime Type into the request
-            request.setMimeType("text/html");
-            request.getResponse().setContentType("text/html");
+            request.setMimeType(mimeType.getName());
+            request.getResponse().setContentType(mimeType.getName());

         }
         catch (Exception e)
Index: portal/src/java/org/apache/jetspeed/capability/impl/ClientImpl.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/capability/impl/ClientImpl.java,v
retrieving revision 1.1
diff -u -r1.1 ClientImpl.java
--- portal/src/java/org/apache/jetspeed/capability/impl/ClientImpl.java 5 Dec 2003 
21:09:21 -0000       1.1
+++ portal/src/java/org/apache/jetspeed/capability/impl/ClientImpl.java 19 Dec 2003 
02:01:00 -0000
@@ -55,7 +55,7 @@
 package org.apache.jetspeed.capability.impl;

 import org.apache.jetspeed.capability.Client;
-import java.util.Vector;
+import java.util.Collection;

 /**
  * Simple implementation of the ClientRegistry interface.
@@ -73,8 +73,8 @@
     private String model = "";
     private String version = "";
     private String name;
-    private Vector mimetypes;
-    private Vector capabilities;
+    private Collection mimetypes;
+    private Collection capabilities;

     private int clientId;

@@ -210,22 +210,22 @@
     }


-    public Vector getMimetypes()
+    public Collection getMimetypes()
     {
         return mimetypes;
     }

-    public void setMimetypes(Vector mimetypes)
+    public void setMimetypes(Collection mimetypes)
     {
         this.mimetypes = mimetypes;
     }

-    public Vector getCapabilities()
+    public Collection getCapabilities()
     {
         return capabilities;
     }

-    public void setCapabilities(Vector capabilities)
+    public void setCapabilities(Collection capabilities)
     {
         this.capabilities = capabilities;
     }
Index: portal/src/java/org/apache/jetspeed/capability/impl/MediaTypeEntryImpl.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/capability/impl/MediaTypeEntryImpl.java,v
retrieving revision 1.1
diff -u -r1.1 MediaTypeEntryImpl.java
--- portal/src/java/org/apache/jetspeed/capability/impl/MediaTypeEntryImpl.java 5 Dec 
2003 21:09:21 -0000       1.1
+++ portal/src/java/org/apache/jetspeed/capability/impl/MediaTypeEntryImpl.java 19 Dec 
2003 02:01:00 -0000
@@ -55,6 +55,7 @@

 import org.apache.jetspeed.capability.MediaTypeEntry;
 import java.util.Vector;
+import java.util.Collection;

 /**
  * Default bean like implementation of MediaTypeEntry interface
@@ -68,8 +69,12 @@
 {
     protected String characterSet;
     private Vector capabilities;
-    private Vector mimetypes;
+    private Collection mimetypes;
     private int mediatypeId;
+    private String title;
+    private String description;
+
+    private String name;       // MediaTypeEntry name

     public MediaTypeEntryImpl()
     {}
@@ -101,7 +106,7 @@

         if (mimetypes.isEmpty()!= true)
         {
-            if ( !mimetypes.contains(obj.getMimetypes().firstElement()) )
+            if ( !mimetypes.contains(obj.getMimetypes().iterator().next()) )
             {
                 return false;
             }
@@ -161,12 +166,12 @@
         this.capabilities = capabilities;
     }

-    public Vector getMimetypes()
+    public Collection getMimetypes()
     {
         return this.mimetypes;
     }

-    public void setMimetypes(Vector mimetypes)
+    public void setMimetypes(Collection mimetypes)
     {
         this.mimetypes = mimetypes;
     }
@@ -201,5 +206,42 @@
     {
         return this.mediatypeId;
     }
-
+
+       /**
+         * Set name ob MediaTypeEntry
+         */
+        public void setName(String name)
+        {
+               this.name = name;
+        }
+
+        /**
+         * Get name ob MediaTypeEntry
+         */
+
+        public String getName()
+        {
+               return this.name;
+        }
+
+        public String getTitle()
+        {
+               return this.title;
+        }
+
+        public void setTitle(String title)
+        {
+               this.title = title;
+        }
+
+        public String getDescription()
+        {
+               return this.description;
+        }
+
+
+       public void setDescription(String desc)
+       {
+               this.description = desc;
+       }
 }
Index: portal/src/test/org/apache/jetspeed/capability/TestCapability.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-jetspeed-2/portal/src/test/org/apache/jetspeed/capability/TestCapability.java,v
retrieving revision 1.1
diff -u -r1.1 TestCapability.java
--- portal/src/test/org/apache/jetspeed/capability/TestCapability.java  5 Dec 2003 
21:09:22 -0000       1.1
+++ portal/src/test/org/apache/jetspeed/capability/TestCapability.java  19 Dec 2003 
02:01:04 -0000
@@ -55,6 +55,8 @@
 package org.apache.jetspeed.capability;

 import java.util.Iterator;
+import java.util.Collection;
+

 import junit.framework.Test;
 import junit.framework.TestSuite;
@@ -129,13 +131,29 @@
         CapabilityService service = getService();
         assertNotNull("capability service is null", service);

-        Iterator clients = service.getClients();
-        assertNotNull("getClients is null", clients);
-        while (clients.hasNext())
-        {
-            Client client = (Client)clients.next();
-            System.out.println("Client = " + client.getName());
-        }
+        // Find specific client -- testing pattern matching
+               String userAgent;
+               System.out.println("Test pattern matching...")  ;
+
+               userAgent = "Mozilla/4.0";
+               System.out.println("Find pattern: " + userAgent)  ;
+
+               CapabilityMap cm = service.getCapabilityMap(userAgent);
+               assertNotNull("getCapabilityMap is null", cm);
+
+               MediaTypeEntry mediaType = cm.getPreferredMediaType();
+               assertNotNull("MediaType is null", mediaType);
+
+               MimeType mimeTypeObj =    cm.getPreferredType();
+               assertNotNull("MimeType is null", mimeTypeObj);
+               String mimeType = mimeTypeObj.getName();
+
+               String encoding = mediaType.getCharacterSet();
+
+               System.out.println("MediaType = " + mediaType.getName());
+               System.out.println("Mimetype = " + mimeType);
+               System.out.println("Encoding = " + encoding);
+
     }

 }
Index: portal/src/webapp/WEB-INF/conf/jetspeed.properties
===================================================================
RCS file: 
/home/cvspublic/jakarta-jetspeed-2/portal/src/webapp/WEB-INF/conf/jetspeed.properties,v
retrieving revision 1.14
diff -u -r1.14 jetspeed.properties
--- portal/src/webapp/WEB-INF/conf/jetspeed.properties  8 Dec 2003 18:28:07 -0000      
 1.14
+++ portal/src/webapp/WEB-INF/conf/jetspeed.properties  19 Dec 2003 02:01:06 -0000
@@ -141,6 +141,9 @@
 services.capability.classname = 
org.apache.jetspeed.capability.impl.CapabilityServiceImpl
 services.capability.earlyInit = true
 services.capability.client.impl = org.apache.jetspeed.capability.impl.ClientImpl
+services.capability.mimetype.impl = org.apache.jetspeed.capability.impl.MimeTypeImpl
+services.capability.capability.impl = 
org.apache.jetspeed.capability.impl.CapabilityImpl
+services.capability.mediatype.impl = 
org.apache.jetspeed.capability.impl.MediaTypeEntryImpl

 # -------------------------------------------------------------------
 #  P S M L  M A N A G E R
Index: portal/src/webapp/WEB-INF/conf/ojb/repository_jetspeed.xml
===================================================================
RCS file: 
/home/cvspublic/jakarta-jetspeed-2/portal/src/webapp/WEB-INF/conf/ojb/repository_jetspeed.xml,v
retrieving revision 1.13
diff -u -r1.13 repository_jetspeed.xml
--- portal/src/webapp/WEB-INF/conf/ojb/repository_jetspeed.xml  5 Dec 2003 21:09:22 
-0000       1.13
+++ portal/src/webapp/WEB-INF/conf/ojb/repository_jetspeed.xml  19 Dec 2003 02:01:08 
-0000
@@ -909,9 +909,9 @@
           name="capabilities"
           element-class-ref="org.apache.jetspeed.capability.impl.CapabilityImpl"

-          indirection-table="MEDIATYPE_TO_CAPABILITY"
+          indirection-table="CLIENT_TO_CAPABILITY"
        >
-          <fk-pointing-to-this-class column="MEDIATYPE_ID"/>
+          <fk-pointing-to-this-class column="CLIENT_ID"/>
           <fk-pointing-to-element-class column="CAPABILITY_ID"/>
        </collection-descriptor>

@@ -919,9 +919,9 @@
           name="mimetypes"
           element-class-ref="org.apache.jetspeed.capability.impl.MimeTypeImpl"

-          indirection-table="MEDIATYPE_TO_MIMETYPE"
+          indirection-table="CLIENT_TO_MIMETYPE"
        >
-          <fk-pointing-to-this-class column="MEDIATYPE_ID"/>
+          <fk-pointing-to-this-class column="CLIENT_ID"/>
           <fk-pointing-to-element-class column="MIMETYPE_ID"/>
        </collection-descriptor>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to