portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject cvs commit: jakarta-jetspeed-2/portal/src/webapp/WEB-INF/db/hsql Registry.script
Date Mon, 22 Dec 2003 02:18:23 GMT
taylor      2003/12/21 18:18:23

  Modified:    portal   maven.xml
               portal/src/java/org/apache/jetspeed/capability
                        Capability.java CapabilityMap.java
                        CapabilityService.java Client.java
               portal/src/java/org/apache/jetspeed/capability/impl
                        CapabilityMapImpl.java CapabilityServiceImpl.java
                        CapabilityValveImpl.java ClientImpl.java
                        MimeTypeImpl.java
               portal/src/test/org/apache/jetspeed/capability
                        TestCapability.java
               portal/src/webapp/WEB-INF/conf jetspeed.properties
               portal/src/webapp/WEB-INF/conf/ojb repository_jetspeed.xml
               portal/src/webapp/WEB-INF/db/hsql Registry.script
  Added:       portal/src/java/org/apache/jetspeed/capability
                        MediaType.java
               portal/src/java/org/apache/jetspeed/capability/impl
                        MediaTypeImpl.java
  Removed:     portal/src/java/org/apache/jetspeed/capability
                        MediaTypeEntry.java
               portal/src/java/org/apache/jetspeed/capability/impl
                        MediaTypeEntryImpl.java
  Log:
  First working implementation of Capability for J2
  Capability valve enabled to call Capability service.
  
  Revision  Changes    Path
  1.20      +1 -1      jakarta-jetspeed-2/portal/maven.xml
  
  Index: maven.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/maven.xml,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- maven.xml	17 Dec 2003 20:46:33 -0000	1.19
  +++ maven.xml	22 Dec 2003 02:18:22 -0000	1.20
  @@ -4,7 +4,7 @@
            xmlns:reactor="reactor">
   
     <!-- Target of maven test:single test -->
  -<property name='testcase' value='org.apache.jetspeed.profiler.TestProfiler'/>        
  +<property name='testcase' value='org.apache.jetspeed.capability.TestCapability'/>        
    
   <!--
     <goal name="jaxb:portlet"
  
  
  
  1.2       +4 -5      jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/capability/Capability.java
  
  Index: Capability.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/capability/Capability.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Capability.java	5 Dec 2003 21:09:21 -0000	1.1
  +++ Capability.java	22 Dec 2003 02:18:22 -0000	1.2
  @@ -52,7 +52,6 @@
    * <http://www.apache.org/>.
    */
   
  -
   package org.apache.jetspeed.capability;
   
   /**
  @@ -69,21 +68,21 @@
        * @param id
        */
       public void setCapabilityId(int id);
  -    
  +
       /**
        * Get CapabilityId
        * 
        * @return capabilityId
        */
       public int getCapabilityId();
  -    
  +
       /**
        * Set Capability name
        * 
        * @param name
        */
       public void setName(String name);
  -    
  +
       /**
        * Get CapabilityId
        * 
  
  
  
  1.3       +63 -64    jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/capability/CapabilityMap.java
  
  Index: CapabilityMap.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/capability/CapabilityMap.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CapabilityMap.java	5 Dec 2003 21:09:21 -0000	1.2
  +++ CapabilityMap.java	22 Dec 2003 02:18:22 -0000	1.3
  @@ -55,7 +55,6 @@
   
   import java.util.Iterator;
   
  -
   /**
    * This interface provides lookup features on the capabilities supported
    * by a client user agent.
  @@ -67,60 +66,50 @@
   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;
  +    /**
  +     * Sets the client for the CapabilityMap
  +     * 
  +     * @param client The client associated with this map
  +     */
  +    public void setClient(Client client);
   
  -    /** Handle CSSP */
  -    public static final int HTML_CSSP = 13;
  +    /**
  +     *  Returns the Client for the CapabilityMap
  +     * 
  +     * @return The client associated with this map
  +     */
  +    public Client getClient();
   
  -    /** Handle XML */
  -    public static final int HTML_XML = 14;
  +    /**
  +     * Add capability to the CapabilityMap
  +     * 
  +     * @param capability
  +     */
  +    public void addCapability(Capability capability);
   
  -    /** Handle XSL */
  -    public static final int HTML_XSL = 15;
  +    /**
  +     * Add Mimetype to the MimetypeMap
  +     * 
  +     * @param mimetype
  +     */
  +    public void addMimetype(MimeType mimetype);
   
  -    /** Handle DOM */
  -    public static final int HTML_DOM = 16;
  +    /**
  +     * Add MediaType to the MediaTypeMap
  +     * 
  +     * @param Mediatype to add
  +     */
  +    public void addMediaType(MediaType mediatype);
   
       /**
  -    Returns the preferred MIME type for the current user-agent
  -    */
  +     * @return Returns the preferred MIME type for the current user-agent
  +     */
       public MimeType getPreferredType();
   
       /**
  -    Returns the preferred media type for the current user-agent
  -    */
  -    public String getPreferredMediaType();
  +     * @return Returns the preferred media type for the current user-agent
  +     */
  +    public MediaType getPreferredMediaType();
   
       /**
        * Returns an ordered list of supported media-types, from most preferred
  @@ -129,29 +118,40 @@
       public Iterator listMediaTypes();
   
       /**
  -    Returns the user-agent string
  -    */
  +     * @return Returns the user-agent string
  +     */
       public String getAgent();
   
       /**
  -    Checks to see if the current agent has the specified capability
  -    */
  -    public boolean hasCapability( int cap );
  +     * @parm userAgent Agent from the request
  +     * 
  +     * Set the userAgent in the capabilityMap
  +     */
  +    public void setAgent(String userAgent);
   
       /**
  -    Checks to see if the current agent has the specified capability
  -    */
  -    public boolean hasCapability( String capability );
  +     * @param CApabilityID
  +     * @return Returns true if the current agent has the specified capabilityID
  +     */
  +    public boolean hasCapability(int cap);
   
       /**
  -    Get the mime types that this CapabilityMap supports.
  -    */
  +     * @param Capability
  +     * @return returns true if the current agent has the specified capability
  +     */
  +    public boolean hasCapability(String capability);
  +
  +    /**
  +     * Get the mime types that this CapabilityMap supports.
  +     * @return Array of Mimetypes
  +     */
       public MimeType[] getMimeTypes();
   
       /**
  -    Return true if this CapabilityMap supports the given MimeType
  -    */
  -    public boolean supportsMimeType( MimeType mimeType );
  +     * @param  MimeType
  +     * @return Return true if this CapabilityMap supports the given MimeType
  +     */
  +    public boolean supportsMimeType(MimeType mimeType);
   
       /**
        * Return true if this CapabilityMap supports the given media type
  @@ -162,12 +162,11 @@
        * @return true is the capabilities of this agent at least match those
        * required by the media type
        */
  -    public boolean supportsMediaType( String media );
  +    public boolean supportsMediaType(String media);
   
       /**
  -    Create a map -> string representation
  -    */
  +     * @return Create a map -> string representation
  +     */
       public String toString();
   
   }
  -
  
  
  
  1.2       +41 -6     jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/capability/CapabilityService.java
  
  Index: CapabilityService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/capability/CapabilityService.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CapabilityService.java	5 Dec 2003 21:09:21 -0000	1.1
  +++ CapabilityService.java	22 Dec 2003 02:18:22 -0000	1.2
  @@ -54,6 +54,7 @@
   package org.apache.jetspeed.capability;
   
   import java.util.Iterator;
  +import java.util.Collection;
   
   import org.apache.jetspeed.cps.CommonService;
   
  @@ -67,15 +68,49 @@
   {
       /** The name of this service */
       public String SERVICE_NAME = "capability";
  -    
  +
       /**
  -     * @param userAgent
  -     * @return
  +     * Creates a Capability Map with Capabilities, Mimetypes and mediaTypes for the given UserAgentPattern
  +     * @param userAgent Agent from the request
  +     * @return CapabilityMap populated with Capabilities, Mimetypes and Mediatype
  +     * that match the userAgent
        */
       CapabilityMap getCapabilityMap(String userAgent);
  -    
  +
       /**
  -     * @return
  +     * Obtain an iterator of all existing clients.
  +     * @return Returns an iterator for all existing Clients
        */
       Iterator getClients();
  +
  +    /**
  +     * Finds a client for a given userAgentPattern
  +     * @param userAgent
  +     * @return Client that matches agent or null if no match is found
  +     *
  +     */
  +    Client findClient(String userAgent);
  +
  +    /**
  +     * Returns a collection of MediaTypes that matches the MimeTypes defined in the mimetype parameter
  +     * @param Mimetype
  +     *
  +     * @return Collection of Mediatypes that matches the mimetypes
  +     */
  +    Collection getMediaTypesForMimeTypes(Iterator mimetypes);
  +
  +    /**
  +     * Clears CapabilityMap cache
  +     * TODO: Roger, why is this on the public interface. It seems to be impl specific 
  +     */
  +    void deleteCapabilityMapCache();
  +    
  +    /**
  +     * Given a media type string, look up the corresponding media type object.
  +     * 
  +     * @param mediaType The string representation of a media type.
  +     * @return The found media type object or if not found, null.
  +     */
  +    MediaType getMediaType(String mediaType);
  +            
   }
  
  
  
  1.2       +22 -18    jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/capability/Client.java
  
  Index: Client.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/capability/Client.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Client.java	5 Dec 2003 21:09:21 -0000	1.1
  +++ Client.java	22 Dec 2003 02:18:22 -0000	1.2
  @@ -53,7 +53,7 @@
    */
   package org.apache.jetspeed.capability;
   
  -import java.util.Vector;
  +import java.util.Collection;
   
   /**
    * <P>
  @@ -66,21 +66,20 @@
    * @author <a href="raphael@apache.org">RaphaŽl Luta</a>
    * @author <a href="mailto:roger.ruttimann@earthlink.net">Roger Ruttimann</a>
    */
  -public interface Client 
  +public interface Client
   {
       /**
  -    * Set Client ID -- Assigns the Client ID
  -    * @param id
  -    */
  +     * Set Client ID -- Assigns the Client ID
  +     * @param id
  +     */
       public void setClientId(int id);
  - 
  -    
  -       /**
  -    * Get Client ID
  -    * @return Client ID
  -    */
  +
  +    /**
  +     * Get Client ID
  +     * @return Client ID
  +     */
       public int getClientId();
  -       
  +
       /**
        * Returns the pattern parameter of this client. The pattern is used
        * to match a client to the user agent used to access the portal. If
  @@ -149,17 +148,17 @@
        * @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);
  -    
  +
       /**
        * Returns all supported capablities as <CODE>CapabilityMap</CODE>.
        * The <CODE>CapabilityMap</CODE> contains all capabilities in arbitrary
  @@ -168,7 +167,12 @@
        * @return the CapabilityMap
        * @see CapabilityMap
        */
  -    public Vector getCapabilities();
  -    public void setCapabilities(Vector capabilities);
  +    public Collection getCapabilities();
  +
  +    /**
  +     * Assigns a list of capabilities
  +     * @param capabilities
  +      */
  +    public void setCapabilities(Collection capabilities);
   
   }
  
  
  
  1.1                  jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/capability/MediaType.java
  
  Index: MediaType.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Jetspeed" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Jetspeed", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.jetspeed.capability;
  
  import java.util.Vector;
  import java.util.Collection;
  
  /**
   * This entry describes all the properties that should be present in
   * a RegistryEntry describing a MediaType
   *
   * FIXME: we should add some additionnal attrbutes for separating 2 versions
   * of the same mime type
   *
   * @author <a href="mailto:raphael@apache.org">RaphaŽl Luta</a>
   * @version $Id: MediaType.java,v 1.1 2003/12/22 02:18:22 taylor Exp $
   */
  public interface MediaType
  {
      /**
       * Set MediaType ID -- Assigns ID
       * @param id
       */
      public void setMediatypeId(int id);
  
      /**
       * Get MediaType ID -- Return ID
       * @return MediaTypeID
       */
      public int getMediatypeId();
  
      /** @return the character set associated with this MediaType */
      public String getCharacterSet();
  
      /** Sets the character set associated with this MediaType */
      public void setCharacterSet(String charSet);
  
      /**
       * Returns all supported capablities as <CODE>CapabilityMap</CODE>.
       * The <CODE>CapabilityMap</CODE> contains all capabilities in arbitrary
       * order.
       *
       * @return a vector of capabilities
       */
      public Vector getCapabilities();
  
      /**
       * Set the capabilities
       * @param vector of capabilities
       */
      public void setCapabilities(Vector capabilities);
  
      /**
      * Returns all supported mimetypes as <CODE>MimeTypeMap</CODE>.
      * The <CODE>MimeTypeMap</CODE> contains all mimetypes in decreasing
      * order of importance.
      *
      * @return the MimeTypeMap
      * @see MimeTypeMap
      */
      public Collection getMimetypes();
  
      /**
       * Set mime types
       * @param mimetypes
       */
      public void setMimetypes(Collection mimetypes);
  
      /**
       * Removes the MimeType to the MimeType map 
       * @param name of MimeType to remove
       */
  
      public void removeMimetype(String name);
  
      /**
       * Add MimeType to the MimeType map 
       * @param name
       */
      public void addMimetype(String name);
  
      /**
       * Set Name of MediaType
       * @param name Name of MediaType
       */
      public void setName(String name);
  
      /**
       * Get Name of MediaType
       * @return Name of MediaType
       */
      public String getName();
  
      /**
       * Get Title of MediaType
       * @return Title of MediaType
       */
      public String getTitle();
  
      /**
       * Set MediaType title
       * @param title
       */
      public void setTitle(String title);
  
      /**
       * Get MediaType description
       * @return Returns description of MediaType
       */
      public String getDescription();
  
      /**
       * Set description of MediaType
       * @param desc Description string
       */
      public void setDescription(String desc);
  }
  
  
  
  1.2       +119 -24   jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/capability/impl/CapabilityMapImpl.java
  
  Index: CapabilityMapImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/capability/impl/CapabilityMapImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CapabilityMapImpl.java	5 Dec 2003 21:09:21 -0000	1.1
  +++ CapabilityMapImpl.java	22 Dec 2003 02:18:22 -0000	1.2
  @@ -55,15 +55,17 @@
   
   import org.apache.jetspeed.capability.CapabilityMap;
   import org.apache.jetspeed.capability.Client;
  +import org.apache.jetspeed.capability.Capability;
  +import org.apache.jetspeed.capability.MediaType;
   
  -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;
   
   /**
  - * IMplementation for capabilityMap interface
  + * Implementation for capabilityMap interface
    *
    * @author <a href="mailto:roger.ruttimann@earthlink.net">Roger Ruttimann</a>
    * @version $Id$
  @@ -71,29 +73,81 @@
   class CapabilityMapImpl implements CapabilityMap
   {
       // 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 String useragent; // User agent for request
  +    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(MediaType 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; // TODO: NEVER return null
  +        }
       }
   
       /**
       Returns the preferred media type for the current user-agent
       */
  -    public String getPreferredMediaType()
  +    public MediaType getPreferredMediaType()
       {
  -        return null;
  +        // Return first entry
  +        Iterator e = this.mediaTypeMap.values().iterator();
  +        if (e.hasNext())
  +        {
  +            return (MediaType) e.next();
  +        } 
  +        return null; // TODO: NEVER RETURN NULL
       }
   
       /**
  @@ -102,7 +156,7 @@
        */
       public Iterator listMediaTypes()
       {
  -        return null;        
  +        return mediaTypeMap.values().iterator();
       }
   
       /**
  @@ -114,18 +168,43 @@
       }
   
       /**
  -    Checks to see if the current agent has the specified capability
  -    */
  +     * 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;
       }
   
       /**
  -    Checks to see if the current agent has the specified capability
  -    */
  +     *  Checks to see if the current agent has the specified capability
  +     */
       public boolean hasCapability(String capability)
       {
  +        Iterator capabilities = capabilityMap.values().iterator();
  +        while (capabilities.hasNext())
  +        {
  +            if (((Capability) capabilities.next()).getName() == capability)
  +            {
  +                return true;
  +            }
  +        }
           return false;
       }
   
  @@ -134,7 +213,7 @@
       */
       public MimeType[] getMimeTypes()
       {
  -        return null;        
  +        return null;
       }
   
       /**
  @@ -142,6 +221,14 @@
       */
       public boolean supportsMimeType(MimeType mimeType)
       {
  +        Iterator mimetypes = mimeTypeMap.values().iterator();
  +        while (mimetypes.hasNext())
  +        {
  +            if (((MimeType) mimetypes.next()).getName() == mimeType.getName())
  +            {
  +                return true;
  +            }
  +        }
           return false;
       }
   
  @@ -156,14 +243,22 @@
        */
       public boolean supportsMediaType(String media)
       {
  +        Iterator mediatypes = mediaTypeMap.values().iterator();
  +        while (mediatypes.hasNext())
  +        {
  +            if (((MediaType) mediatypes.next()).getName() == media)
  +            {
  +                return true;
  +            }
  +        }
           return false;
       }
   
       /**
  -    Create a map -> string representation
  -    */
  +     * Create a map -> string representation
  +     */
       public String toString()
  -    {    
  +    {
           return "";
       }
   
  
  
  
  1.2       +207 -57   jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/capability/impl/CapabilityServiceImpl.java
  
  Index: CapabilityServiceImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/capability/impl/CapabilityServiceImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CapabilityServiceImpl.java	5 Dec 2003 21:09:21 -0000	1.1
  +++ CapabilityServiceImpl.java	22 Dec 2003 02:18:22 -0000	1.2
  @@ -55,10 +55,15 @@
   
   import java.util.Collection;
   import java.util.Iterator;
  +import java.util.Hashtable;
  +import java.util.Vector;
   
   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.MediaType;
   import org.apache.jetspeed.capability.CapabilityService;
   import org.apache.jetspeed.capability.Client;
   import org.apache.jetspeed.cps.BaseCommonService;
  @@ -66,15 +71,19 @@
   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:taylor@apache.org">David Sean Taylor</a>
  + * @author <a href="mailto:roger.ruttimann@earthlink.net">Roger Ruttimann</a>
    * @version $Id$
    */
  -public class CapabilityServiceImpl extends BaseCommonService implements CapabilityService
  +public class CapabilityServiceImpl
  +    extends BaseCommonService
  +    implements CapabilityService
   {
       private PersistencePlugin plugin;
   
  @@ -82,49 +91,52 @@
   
       private String originalAlias;
   
  -    private static final Log log = LogFactory.getLog(CapabilityServiceImpl.class);
  +    private static final Log log =
  +        LogFactory.getLog(CapabilityServiceImpl.class);
   
       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;
   
       /**
  -     *  
        * <p>
        * init
        * </p>
  -     * 
  -     * @see org.apache.fulcrum.Service#init()
  +     * Initialize CapabilityService
  +     * @see org.apache.jetspeed.services.capability.CapabilityService#init()
        * @throws CPSInitializationException
        */
       public void init() throws CPSInitializationException
       {
           if (!isInitialized())
           {
  -            PersistenceService ps = (PersistenceService) CommonPortletServices.getPortalService(PersistenceService.SERVICE_NAME);
  -            String pluginName = getConfiguration().getString("persistence.plugin.name", "jetspeed");
  +            PersistenceService ps =
  +                (PersistenceService) CommonPortletServices.getPortalService(
  +                    PersistenceService.SERVICE_NAME);
  +            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.");
  -            }
  +            // Create classes
  +            clientClass = createClass("client.impl");
  +            capabilityClass = createClass("capability.impl");
  +            mimeTypeClass = createClass("mimetype.impl");
  +            mediaTypeClass = createClass("mediatype.impl");
   
  -            try
  -            {
  -                clientClass = createClass(className);
  -            }
  -            catch (ClassNotFoundException e)
  -            {
  -                throw new CPSInitializationException("Could not preload client implementation class.", e);
  -            }
  +            capabilityMapCache = new Hashtable();
   
               setInit(true);
           }
  @@ -135,48 +147,115 @@
        * @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);
  +        // Check the cache if we have already a capability map for
  +        // the given Agent
  +        map = (CapabilityMap) capabilityMapCache.get(userAgent);
   
  -        if (entry == null)
  +        if (map != null)
           {
  -            if (userAgent.equals(DEFAULT_AGENT))
  +            // Entry found
  +            return map;
  +        }
  +
  +        while (!bClientFound)
  +        {
  +            Client entry = findClient(userAgent);
  +
  +            if (entry == null)
               {
  -                log.error("CapabilityMap: Default agent not found in Client Registry !");
  -            }
  -            else
  +                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
               {
  -                if (log.isDebugEnabled())
  +                // 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())
                   {
  -                    log.debug("CapabilityMap: useragent " + userAgent + "unknown, falling back to default");
  +                    map.addMimetype((MimeType) mimetypes.next());
                   }
  -                // LEFT OFF HERE: map = getDefaultCapabilityMap();
  +
  +                Iterator media = mediatypes.iterator();
  +                while (media.hasNext())
  +                {
  +                    map.addMediaType((MediaType) media.next());
  +                }
  +
  +                // Add map to cache
  +                capabilityMapCache.put(userAgent, map);
  +
  +                return map;
               }
  -        }
  -        else
  -        {
  -            // LEFT OFF HERE: map = new BaseCapabilityMap(userAgent, entry);
  -        }
   
  -        if (log.isDebugEnabled())
  -        {
  -            log.debug("CapabilityMap: User-agent: " + userAgent + " mapped to " + map);
           }
   
           return map;
  @@ -188,7 +267,9 @@
        * @param useragent     the useragent to match
        * @return the found client or null if the user-agent does not match any
        *  defined client
  +     * @see org.apache.jetspeed.capability.CapabilityService#findClient(java.lang.String)
        */
  +
       public Client findClient(String userAgent)
       {
           Client clientEntry = null;
  @@ -196,7 +277,9 @@
   
           if (log.isDebugEnabled())
           {
  -            log.debug("ClientRegistry: Looking for client with useragent :" + userAgent);
  +            log.debug(
  +                "ClientRegistry: Looking for client with useragent :"
  +                    + userAgent);
           }
   
           while (clients.hasNext())
  @@ -206,31 +289,39 @@
               {
                   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;
  -                    }
  -                    else
  +                    } else
                       {
                           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();
  @@ -242,8 +333,8 @@
           return clientEntry;
       }
   
  -    /**
  -     * @return
  +    /* 
  +     * @see org.apache.jetspeed.capability.CapabilityService#getClients()
        */
       public Iterator getClients()
       {
  @@ -253,5 +344,64 @@
           }
   
           return this.clients.iterator();
  +    }
  +
  +    /* 
  +     * @see org.apache.jetspeed.capability.CapabilityService#getMediaTypesForMimeTypes(java.util.Iterator)
  +     */
  +    public Collection getMediaTypesForMimeTypes(Iterator mimetypes)
  +    {
  +        //Find the MediaType by matching the Mimetype
  +        LookupCriteria criteria = plugin.newLookupCriteria();
  +
  +        Vector temp = new Vector();
  +        // 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 MediaTypeImpl
  +            // criteria.addEqualTo("mimetypes.name", mt.getName());
  +            //stuff.add(new Integer(mt.getMimetypeId()));
  +            temp.add(mt.getName());
  +        }
  +        criteria.addIn("mimetypes.name", temp);
  +
  +        Collection co = plugin.getCollectionByQuery(
  +            mediaTypeClass,
  +            plugin.generateQuery(mediaTypeClass, criteria));
  +            
  +        if (co.isEmpty())
  +        {            
  +            System.out.println("collection is empty");
  +            MediaType mt = getMediaType("html");
  +            Vector v = new Vector();
  +            v.add(mt);
  +            return v;
  +        }
  +        System.out.println("collection is NOT empty");
  +                
  +        return co;                   
  +    }
  +
  +    /* 
  +     * @see org.apache.jetspeed.capability.CapabilityService#deleteCapabilityMapCache()
  +     */
  +    public void deleteCapabilityMapCache()
  +    {
  +        capabilityMapCache.clear();
  +        clients = null;
  +    }
  +
  +    /* (non-Javadoc)
  +     * @see org.apache.jetspeed.capability.CapabilityService#getMediaType(java.lang.String)
  +     */
  +    public MediaType getMediaType(String mediaType)
  +    {
  +        LookupCriteria criteria = plugin.newLookupCriteria();
  +        criteria.addEqualTo("name", mediaType);
  +        Object query = plugin.generateQuery(mediaTypeClass, criteria);        
  +        return (MediaType) plugin.getObjectByQuery(mediaTypeClass, query);
       }
   }
  
  
  
  1.3       +50 -33    jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/capability/impl/CapabilityValveImpl.java
  
  Index: CapabilityValveImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/capability/impl/CapabilityValveImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CapabilityValveImpl.java	17 Dec 2003 20:46:33 -0000	1.2
  +++ CapabilityValveImpl.java	22 Dec 2003 02:18:22 -0000	1.3
  @@ -59,8 +59,13 @@
   import org.apache.jetspeed.pipeline.PipelineException;
   import org.apache.jetspeed.pipeline.valve.CapabilityValve;
   import org.apache.jetspeed.pipeline.valve.ValveContext;
  +import org.apache.jetspeed.profiler.rules.ProfilingRule;
   import org.apache.jetspeed.request.RequestContext;
  -
  +import org.apache.jetspeed.capability.CapabilityService;
  +import org.apache.jetspeed.capability.CapabilityMap;
  +import org.apache.jetspeed.capability.MediaType;
  +import org.apache.jetspeed.capability.MimeType;
  +import org.apache.jetspeed.cps.CommonPortletServices;
   
   /**
    * Invokes the capability mapper in the request pipeline
  @@ -80,6 +85,11 @@
       {
   
       }
  +    
  +    protected CapabilityService getService()
  +    {
  +        return (CapabilityService) CommonPortletServices.getPortalService(CapabilityService.SERVICE_NAME);
  +    }
   
       public void invoke(RequestContext request, ValveContext context)
           throws PipelineException
  @@ -88,50 +98,57 @@
   
           try
           {
  -            // 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");                              
  -            CapabilityMap cm = CapabilityMapFactory.getCapabilityMap(agent);
  -                    
  -            String mediaType = cm.getPreferredMediaType();
  -                    
  -            String mimeType = cm.getPreferredType().getCode();
  -      */      
  +            String requestMediaType = request.getRequestParameter(ProfilingRule.STANDARD_MEDIATYPE);
  +            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);
  +            }
  +            
  +            MediaType mediaType = cm.getPreferredMediaType();                          
  +            MimeType mimeType = cm.getPreferredType();  
  +            
               String encoding = request.getRequest().getCharacterEncoding();
  -    /*            
  +            
  +            
               if (encoding == null)
  -            {           
  -                Configuration configuration = Jetspeed.getContext().getConfiguration();
  -                encoding = configuration.getString(CapabilityMapFactory.CONTENT_ENCODING_KEY, 
  -                                                   CapabilityMapFactory.DEFAULT_CONTENT_ENCODING_KEY);
  -                if (mimeType != null)
  +            {
  +                if (mediaType != null && mediaType.getCharacterSet() != null)
                   {
  -                
  -                    MediaTypeEntry media = (MediaTypeEntry) JetspeedRegistry.getEntry(
  -                            RegistryService.MEDIA_TYPE,
  -                            mimeType);
  -                    if (media != null && media.getCharacterSet() != null)
  -                    {
  -                        encoding = media.getCharacterSet();
  -                    }
  -
  -                }                                                      
  +                    encoding = mediaType.getCharacterSet();
  +                }
  +            }
  +            
  +            if (log.isDebugEnabled())
  +            {
  +                log.debug("MediaType: " + mediaType.getName());
  +                log.debug("Encoding: "  + encoding);
  +                log.debug("Mimetype: "  + mimeType.getName());
               }
  -        */    
                                                                               
               // Put the encoding in the request
               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)
  
  
  
  1.2       +8 -8      jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/capability/impl/ClientImpl.java
  
  Index: ClientImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/capability/impl/ClientImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ClientImpl.java	5 Dec 2003 21:09:21 -0000	1.1
  +++ ClientImpl.java	22 Dec 2003 02:18:22 -0000	1.2
  @@ -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;
       }
  
  
  
  1.2       +2 -3      jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/capability/impl/MimeTypeImpl.java
  
  Index: MimeTypeImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/capability/impl/MimeTypeImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MimeTypeImpl.java	5 Dec 2003 21:09:21 -0000	1.1
  +++ MimeTypeImpl.java	22 Dec 2003 02:18:22 -0000	1.2
  @@ -56,7 +56,6 @@
   
   import org.apache.jetspeed.capability.MimeType;
   
  -
   /**
    * Mimetype implementation class.
    *
  @@ -74,7 +73,7 @@
        */
       public void setMimetypeId(int id)
       {
  -      this.mimeTypeId = id;
  +        this.mimeTypeId = id;
       }
   
       /* (non-Javadoc)
  
  
  
  1.1                  jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/capability/impl/MediaTypeImpl.java
  
  Index: MediaTypeImpl.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Jetspeed" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Jetspeed", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.jetspeed.capability.impl;
  
  import org.apache.jetspeed.capability.MediaType;
  import java.util.Vector;
  import java.util.Collection;
  
  /**
   * Default bean like implementation of MediaTypeEntry interface
   * suitable for serializing with Castor
   *
   * @author <a href="mailto:raphael@apache.org">RaphaŽl Luta</a>
   * @version $Id: MediaTypeImpl.java,v 1.1 2003/12/22 02:18:22 taylor Exp $
   */
  public class MediaTypeImpl 
      implements MediaType
  {
      protected String characterSet;
      private Vector capabilities;
      private Collection mimetypes;
      private int mediatypeId;
      private String title;
      private String description;
      
      private String name;    // MediaTypeEntry name
  
      public MediaTypeImpl()
      {}
  
      public MediaTypeImpl(long id,
                                String name,
                                int _hidden,
                                String mimeType,
                                String title,
                                String description,
                                String image,
                                 String role)
      {
           this.mimetypes.add(mimeType);
      }
  
      /**
       * Implements the equals operation so that 2 elements are equal if
       * all their member values are equal.
       */
      public boolean equals(Object object)
      {
          if (object==null)
          {
              return false;
          }
  
          MediaTypeImpl obj = (MediaTypeImpl)object;
  
          if (mimetypes.isEmpty()!= true)
          {
              if ( !mimetypes.contains(obj.getMimetypes().iterator().next()) )
              {
                  return false;
              }
          }
          else
          {
              if (obj.getMimetypes().isEmpty() == false)
              {
                  return false;
              }
          }
  
          if (characterSet!=null)
          {
              if (!characterSet.equals(obj.characterSet))
              {
                  return false;
              }
          }
          else
          {
              if (obj.characterSet!=null)
              {
                  return false;
              }
          }
  
          if (!capabilities.equals(obj.capabilities))
          {
              return false;
          }
  
          return super.equals(object);
      }
      
   
      /** @return the character set associated with this MediaType */
      public String getCharacterSet()
      {
          return this.characterSet;
      }
  
      /** Sets the character set associated with this MediaType */
      public void setCharacterSet( String charSet)
      {
          this.characterSet = charSet;
      }
  
      
      public Vector getCapabilities()
      {
          return this.capabilities;
      }
  
      public void setCapabilities(Vector capabilities)
      {
          this.capabilities = capabilities;
      }
      
      public Collection getMimetypes()
      {
          return this.mimetypes;
      }
      
      public void setMimetypes(Collection mimetypes)
      {
          this.mimetypes = mimetypes;
      }
      
      public void addMimetype(String name)
      {
          if (!mimetypes.contains(name))
          {
              mimetypes.add(name);
          }
      }
  
      public void removeMimetype(String name)
      {
          mimetypes.remove(name);
      }
      
      /**
       * Set MediaType ID -- Assigns ID
       * @param id
       */
      public void setMediatypeId(int id)
      {
          this.mediatypeId = id;
      }
  
      /**
       * Get MediaType ID -- Return ID
       * @return MediaTypeID
       */
      public int getMediatypeId()
      {
          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;
      }
  }
  
  
  
  1.2       +24 -9     jakarta-jetspeed-2/portal/src/test/org/apache/jetspeed/capability/TestCapability.java
  
  Index: TestCapability.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/test/org/apache/jetspeed/capability/TestCapability.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestCapability.java	5 Dec 2003 21:09:22 -0000	1.1
  +++ TestCapability.java	22 Dec 2003 02:18:23 -0000	1.2
  @@ -54,7 +54,6 @@
    
   package org.apache.jetspeed.capability;
   
  -import java.util.Iterator;
   
   import junit.framework.Test;
   import junit.framework.TestSuite;
  @@ -129,13 +128,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);
  +        
  +        MediaType 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);
  +                
       }
   
   }
  
  
  
  1.15      +4 -1      jakarta-jetspeed-2/portal/src/webapp/WEB-INF/conf/jetspeed.properties
  
  Index: jetspeed.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/webapp/WEB-INF/conf/jetspeed.properties,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- jetspeed.properties	8 Dec 2003 18:28:07 -0000	1.14
  +++ jetspeed.properties	22 Dec 2003 02:18:23 -0000	1.15
  @@ -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.MediaTypeImpl
   
   # -------------------------------------------------------------------
   #  P S M L  M A N A G E R
  
  
  
  1.14      +7 -7      jakarta-jetspeed-2/portal/src/webapp/WEB-INF/conf/ojb/repository_jetspeed.xml
  
  Index: repository_jetspeed.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/webapp/WEB-INF/conf/ojb/repository_jetspeed.xml,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- repository_jetspeed.xml	5 Dec 2003 21:09:22 -0000	1.13
  +++ repository_jetspeed.xml	22 Dec 2003 02:18:23 -0000	1.14
  @@ -802,7 +802,7 @@
      - M E D I A T Y P E
     -->
       <class-descriptor
  -   	  class="org.apache.jetspeed.capability.impl.MediaTypeEntryImpl"
  +   	  class="org.apache.jetspeed.capability.impl.MediaTypeImpl"
      	  table="MEDIA_TYPE"
      >
         
  @@ -842,9 +842,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>
          
  @@ -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>
         
  
  
  
  1.15      +1 -1      jakarta-jetspeed-2/portal/src/webapp/WEB-INF/db/hsql/Registry.script
  
  Index: Registry.script
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/webapp/WEB-INF/db/hsql/Registry.script,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- Registry.script	17 Dec 2003 20:46:34 -0000	1.14
  +++ Registry.script	22 Dec 2003 02:18:23 -0000	1.15
  @@ -275,5 +275,5 @@
   INSERT INTO RULE_CRITERION VALUES('6','j1',5,'country','country',NULL,1)
   INSERT INTO RULE_CRITERION VALUES('7','role-fallback',0,'request.session','desktop','default-desktop',0)
   INSERT INTO RULE_CRITERION VALUES('8','role-fallback',1,'request.session','page','default-page',0)
  -INSERT INTO RULE_CRITERION VALUES('9','role-fallback',2,'role','role',NULL,0)
  +INSERT INTO RULE_CRITERION VALUES('9','role-fallback',2,'role','role',NULL,2)
   INSERT INTO PRINCIPAL_RULE_ASSOC VALUES('anon','j1')
  
  
  

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


Mime
View raw message