portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wea...@apache.org
Subject cvs commit: jakarta-jetspeed-2/components/capability/src/java/META-INF ojb_repository.xml
Date Fri, 28 May 2004 18:49:15 GMT
weaver      2004/05/28 11:49:15

  Added:       components/capability/src/test/org/apache/jetspeed/capabilities
                        TestCapability.java
               components/capability/src/test repository_database.xml
                        repository.dtd OJB.properties log4j.properties
                        repository.xml repository_internal.xml
               components/capability project.xml maven.xml
                        project.properties repository_database.xml
               components/capability/src/java/org/apache/jetspeed/capabilities/impl
                        MimeTypeImpl.java ClientImpl.java
                        JetspeedCapabilities.java CapabilityMapImpl.java
                        MediaTypeImpl.java CapabilityImpl.java
               components/capability/src/java/META-INF ojb_repository.xml
  Log:
  see: JS2-50: <http://issues.apache.org/jira/browse/JS2-50>
  
  Revision  Changes    Path
  1.1                  jakarta-jetspeed-2/components/capability/src/test/org/apache/jetspeed/capabilities/TestCapability.java
  
  Index: TestCapability.java
  ===================================================================
  /*
   * Copyright 2000-2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.jetspeed.capabilities;
  
  import java.util.Iterator;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  
  import org.apache.jetspeed.capabilities.impl.JetspeedCapabilities;
  import org.apache.jetspeed.components.persistence.store.util.PersistenceSupportedTestCase;
  
  /**
   * Test Capability Service
   *
   * @author <a href="roger.ruttimann@earthlink.net">Roger Ruttimann</a>
   * @version $Id: TestCapability.java,v 1.1 2004/05/28 18:49:14 weaver Exp $
   */
  public class TestCapability extends PersistenceSupportedTestCase
  {
      private Capabilities capabilities = null;
      
      /**
       * Defines the testcase name for JUnit.
       *
       * @param name the testcase's name.
       */
      public TestCapability(String name)
      {
          super(name);
      }
  
      
      /**
       * Start the tests.
       *
       * @param args the arguments. Not used
       */
      public static void main(String args[])
      {
          junit.awtui.TestRunner.main(
              new String[] { TestCapability.class.getName()});
      }
  
      protected void setUp() throws Exception
      {
          super.setUp();               
  
          capabilities = new JetspeedCapabilities(persistenceStore);        
      }
      
      public static Test suite()
      {
          // All methods starting with "test" will be executed in the test suite.
          return new TestSuite(TestCapability.class);
      }
  
      /**
       * Tests categories
       * @throws Exception
       */
      public void testCapability() throws Exception
      {
          assertNotNull("capabilities component is null", capabilities);
  
          // Find specific client -- testing pattern matching
          String userAgent;
          System.out.println("Testing all supported Clients...");
  
          userAgent = "Opera/7.0";
          System.out.println("Find pattern: " + userAgent);
          CapabilityMap cm = capabilities.getCapabilityMap(userAgent);
          assertNotNull("getCapabilityMap is null", cm);
          capabilityMapReport(cm);
  
          userAgent = "Mozilla/4.0";
          System.out.println("Find pattern: " + userAgent);
          cm = capabilities.getCapabilityMap(userAgent);
          assertNotNull("getCapabilityMap is null", cm);
          capabilityMapReport(cm);
  
          userAgent = "MSIE 5.0";
          System.out.println("Find pattern: " + userAgent);
          cm = capabilities.getCapabilityMap(userAgent);
          assertNotNull("getCapabilityMap is null", cm);
          capabilityMapReport(cm);
  
          userAgent = "Mozilla/5.0";
          System.out.println("Find pattern: " + userAgent);
          cm = capabilities.getCapabilityMap(userAgent);
          assertNotNull("getCapabilityMap is null", cm);
          capabilityMapReport(cm);
  
          userAgent = "Lynx";
          System.out.println("Find pattern: " + userAgent);
          cm = capabilities.getCapabilityMap(userAgent);
          assertNotNull("getCapabilityMap is null", cm);
          capabilityMapReport(cm);
  
          userAgent = "Nokia";
          System.out.println("Find pattern: " + userAgent);
          cm = capabilities.getCapabilityMap(userAgent);
          assertNotNull("getCapabilityMap is null", cm);
          capabilityMapReport(cm);
  
      }
  
      private void capabilityMapReport(CapabilityMap cm)
      {
          MediaType mediaType = cm.getPreferredMediaType();
          assertNotNull("Preferred MediaType is null", mediaType);
  
          MimeType mimeTypeObj = cm.getPreferredType();
          assertNotNull("Preferred MimeType is null", mimeTypeObj);
          String mimeType = mimeTypeObj.getName();
  
          String encoding = mediaType.getCharacterSet();
  
          System.out.println("Preferred MediaType = " + mediaType.getName());
          System.out.println("Preferred Mimetype = " + mimeType);
          System.out.println("Encoding = " + encoding);
          System.out.println("Supported MediaTypes");
          Iterator cmIterator = cm.listMediaTypes();
  
          while (cmIterator.hasNext())
          {
              System.out.println(((MediaType) cmIterator.next()).getName());
          }
  
          System.out.println("Supported MimeTypes");
          Iterator mtIterator = cm.getMimeTypes();
  
          while (mtIterator.hasNext())
          {
              System.out.println(((MimeType) mtIterator.next()).getName());
          }
      }
  
  }
  
  
  
  1.2       +50 -0     jakarta-jetspeed-2/components/capability/src/test/repository_database.xml
  
  
  
  
  1.2       +949 -0    jakarta-jetspeed-2/components/capability/src/test/repository.dtd
  
  
  
  
  1.2       +455 -0    jakarta-jetspeed-2/components/capability/src/test/OJB.properties
  
  
  
  
  1.1                  jakarta-jetspeed-2/components/capability/src/test/log4j.properties
  
  Index: log4j.properties
  ===================================================================
  # Copyright 2004 The Apache Software Foundation
  #
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  # 
  #     http://www.apache.org/licenses/LICENSE-2.0
  # 
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  
  # ------------------------------------------------------------------------
  #
  # Logging Configuration
  #
  # $Id: log4j.properties,v 1.1 2004/05/28 18:49:14 weaver Exp $
  #
  # ------------------------------------------------------------------------
  
  #
  # If we don't know the logging facility, put it into the jetspeed.log
  # 
  #
  log4j.rootLogger = INFO, console
  
  #
  # Jetspeed goes into Jetspeed Log
  #
  log4j.category.org.apache.jetspeed = DEBUG, console
  log4j.additivity.org.apache.jetspeed = false
  
  #
  # Velocity Logfile
  #
  log4j.category.velocity = INFO, console
  log4j.additivity.velocity = false
  
  #
  # OJB Logfile
  #
  log4j.category.org.apache.ojb= INFO, console
  log4j.additivity.org.apache.ojb= false
  
  
  
  
  #
  # Console
  #
  log4j.appender.console=org.apache.log4j.ConsoleAppender
  log4j.appender.console.layout=org.apache.log4j.PatternLayout
  
  # Pattern to output the caller's file name and line number.
  log4j.appender.console.layout.ConversionPattern=%5p: %m%n
  
  
  
  1.2       +37 -0     jakarta-jetspeed-2/components/capability/src/test/repository.xml
  
  
  
  
  1.2       +363 -0    jakarta-jetspeed-2/components/capability/src/test/repository_internal.xml
  
  
  
  
  1.2       +177 -0    jakarta-jetspeed-2/components/capability/project.xml
  
  
  
  
  1.2       +46 -0     jakarta-jetspeed-2/components/capability/maven.xml
  
  
  
  
  1.2       +55 -0     jakarta-jetspeed-2/components/capability/project.properties
  
  
  
  
  1.1                  jakarta-jetspeed-2/components/capability/repository_database.xml
  
  Index: repository_database.xml
  ===================================================================
  <!--
  Copyright 2004 The Apache Software Foundation
  
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
  
      http://www.apache.org/licenses/LICENSE-2.0
  
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  -->
  <!--
  Define here all used connections.
  One defined connection should be defined as the default one,
  by set default-connection="true" - this could be done at runtime too.
  
  It is possible to set user/password at
  runtime or let login different users at runtime using the same
  database. Use different PBKey with same jcdAlias name but
  different user/password.
  
  Ditto it is possible to add jdbc-connection-descriptor at runtime
  using the MetadataManager.
  -->
  
  
      <jdbc-connection-descriptor
          jcd-alias="jetspeed"
          platform="Hsqldb"
          default-connection="true"
          jdbc-level="2.0"
           jndi-datasource-name="java:comp/env/jdbc/jetspeed"
          batch-mode="false"
       >
  
          <connection-pool
              maxActive="21"
              validationQuery="" />
  
          <sequence-manager className="org.apache.ojb.broker.util.sequence.SequenceManagerHighLowImpl">
              <attribute attribute-name="grabSize" attribute-value="20"/>
              <attribute attribute-name="autoNaming" attribute-value="true"/>
              <attribute attribute-name="globalSequenceId" attribute-value="false"/>
              <attribute attribute-name="globalSequenceStart" attribute-value="10000"/>
          </sequence-manager>
     </jdbc-connection-descriptor>
  
  
  
  1.1                  jakarta-jetspeed-2/components/capability/src/java/org/apache/jetspeed/capabilities/impl/MimeTypeImpl.java
  
  Index: MimeTypeImpl.java
  ===================================================================
  /*
   * Copyright 2000-2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.jetspeed.capabilities.impl;
  
  import org.apache.jetspeed.capabilities.MimeType;
  
  /**
   * Mimetype implementation class.
   *
   * @author <a href="mailto:roger.ruttimann@earthlink.net">Roger Ruttimann</a>
   * @version $Id: MimeTypeImpl.java,v 1.1 2004/05/28 18:49:15 weaver Exp $
   */
  
  public class MimeTypeImpl implements MimeType
  {
      private int mimeTypeId;
      private String name;
  
      /* (non-Javadoc)
       * @see org.apache.jetspeed.om.registry.MimeType#setMimetypeId(int)
       */
      public void setMimetypeId(int id)
      {
          this.mimeTypeId = id;
      }
  
      /* (non-Javadoc)
       * @see org.apache.jetspeed.om.registry.MimeType#getMimetypeId()
       */
      public int getMimetypeId()
      {
          return this.mimeTypeId;
      }
  
      /* (non-Javadoc)
       * @see org.apache.jetspeed.om.registry.MimeType#setName(java.lang.String)
       */
      public void setName(String name)
      {
          this.name = name;
      }
  
      /* (non-Javadoc)
       * @see org.apache.jetspeed.om.registry.MimeType#getName()
       */
      public String getName()
      {
          return this.name;
      }
  
  }
  
  
  
  1.1                  jakarta-jetspeed-2/components/capability/src/java/org/apache/jetspeed/capabilities/impl/ClientImpl.java
  
  Index: ClientImpl.java
  ===================================================================
  /*
   * Copyright 2000-2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.jetspeed.capabilities.impl;
  
  import org.apache.jetspeed.capabilities.Client;
  
  import java.util.ArrayList;
  import java.util.Collection;
  
  /**
   * Simple implementation of the ClientRegistry interface.
   *
   * @author <a href="shesmer@raleigh.ibm.com">Stephan Hesmer</a>
   * @author <a href="mailto:raphael@apache.org">RaphaŽl Luta</a>
   * @author <a href="mailto:roger.ruttimann@earthlink.net">Roger Ruttimann</a>
   * @version $Id: ClientImpl.java,v 1.1 2004/05/28 18:49:15 weaver Exp $
   */
  public class ClientImpl implements Client, java.io.Serializable
  {
      private String userAgentPattern = "";
      private String manufacturer = "";
      private String model = "";
      private String version = "";
      private String name;
      private Collection mimetypes;
      private Collection capabilities;
      private int preferredMimeTypeId;
  
      private int clientId;
  
      public ClientImpl()
      {
      }
  
      /**
       * 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;
          }
  
          ClientImpl obj = (ClientImpl) object;
  
          if (userAgentPattern != null)
          {
              if (!userAgentPattern.equals(obj.userAgentPattern))
              {
                  return false;
              }
          } else
          {
              if (obj.userAgentPattern != null)
              {
                  return false;
              }
          }
  
          if (manufacturer != null)
          {
              if (!manufacturer.equals(obj.manufacturer))
              {
                  return false;
              }
          } else
          {
              if (obj.manufacturer != null)
              {
                  return false;
              }
          }
  
          if (model != null)
          {
              if (!model.equals(obj.model))
              {
                  return false;
              }
          } else
          {
              if (obj.model != null)
              {
                  return false;
              }
          }
  
          if (version != null)
          {
              if (!version.equals(obj.version))
              {
                  return false;
              }
          } else
          {
              if (obj.version != null)
              {
                  return false;
              }
          }
  
          if (!mimetypes.contains(obj.mimetypes))
          {
              return false;
          }
  
          if (!capabilities.contains(obj.capabilities))
          {
              return false;
          }
  
          return super.equals(object);
      }
  
      public String getUserAgentPattern()
      {
          return userAgentPattern;
      }
  
      public void setUserAgentPattern(String userAgentPattern)
      {
          this.userAgentPattern = userAgentPattern;
      }
  
      public String getManufacturer()
      {
          return manufacturer;
      }
  
      public void setManufacturer(String name)
      {
          manufacturer = name;
      }
  
      public String getModel()
      {
          return model;
      }
  
      public void setModel(String name)
      {
          model = name;
      }
  
      public String getVersion()
      {
          return version;
      }
  
      public void setVersion(String name)
      {
          version = name;
      }
  
      public Collection getMimetypes()
      {
          if(this.mimetypes == null)
          {
              this.mimetypes = new ArrayList();
          }
          return mimetypes;
      }
  
      public void setMimetypes(Collection mimetypes)
      {
          this.mimetypes = mimetypes;
      }
  
      public Collection getCapabilities()
      {
          if(capabilities == null)
          {
              capabilities = new ArrayList();
          }
          return capabilities;
      }
  
      public void setCapabilities(Collection capabilities)
      {
          this.capabilities = capabilities;
      }
  
      /**
       * Set Client ID -- Assigns the Client ID
       * @param id
       */
      public void setClientId(int id)
      {
          this.clientId = id;
      }
  
      /**
       * Get Client ID
       * @return Client ID
       */
      public int getClientId()
      {
          return this.clientId;
      }
      /**
       * @return
       */
      public String getName()
      {
          return name;
      }
  
      /**
       * @param string
       */
      public void setName(String string)
      {
          name = string;
      }
  
      /**
       * @return Preferred MimeType ID for Client
       */
      public int getPreferredMimeTypeId()
      {
          return this.preferredMimeTypeId;
      }
  
      /**
       * Set preferred Mimetype ID for Client
       * @param mimeTypeId MimeTypeId
       */
      public void setPreferredMimeTypeId(int mimeTypeId)
      {
          this.preferredMimeTypeId = mimeTypeId;
      }
  
  }
  
  
  
  1.1                  jakarta-jetspeed-2/components/capability/src/java/org/apache/jetspeed/capabilities/impl/JetspeedCapabilities.java
  
  Index: JetspeedCapabilities.java
  ===================================================================
  /*
   * Copyright 2000-2001,2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.jetspeed.capabilities.impl;
  
  import java.util.Collection;
  import java.util.Hashtable;
  import java.util.Iterator;
  import java.util.Properties;
  import java.util.Vector;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.jetspeed.capabilities.Capabilities;
  import org.apache.jetspeed.capabilities.Capability;
  import org.apache.jetspeed.capabilities.CapabilityMap;
  import org.apache.jetspeed.capabilities.Client;
  import org.apache.jetspeed.capabilities.MediaType;
  import org.apache.jetspeed.capabilities.MimeType;
  import org.apache.jetspeed.components.persistence.store.Filter;
  import org.apache.jetspeed.components.persistence.store.PersistenceStore;
  
  /**
   * Jetspeed Capabilities
   *
   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
   * @author <a href="mailto:roger.ruttimann@earthlink.net">Roger Ruttimann</a>
   * @version $Id: JetspeedCapabilities.java,v 1.1 2004/05/28 18:49:15 weaver Exp $
   */
  public class JetspeedCapabilities implements Capabilities 
  {
      private String originalAlias;
  
      private static final Log log =
          LogFactory.getLog(JetspeedCapabilities.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 = new Hashtable();
  
      private Collection clients = null;
  
      private Class clientClass = ClientImpl.class;
      private Class capabilityClass = CapabilityImpl.class;
      private Class mimeTypeClass = MimeTypeImpl.class;
      private Class mediaTypeClass = MediaTypeImpl.class;
      private PersistenceStore persistenceStore;
  
      public JetspeedCapabilities(PersistenceStore persistenceStore)
      {
           this.persistenceStore = persistenceStore;
      }
      
      /**
       * Create a JetspeedProfiler with properties. Expected properties are:
       * 
       * 	   defaultRule   = the default profiling rule
       *     anonymousUser = the name of the anonymous user
       *     persistenceStoreName = The name of the persistence persistenceStore component
to connect to  
       *     services.profiler.locator.impl = the pluggable Profile Locator impl
       *     services.profiler.principalRule.impl = the pluggable Principal Rule impl
       *     services.profiler.profilingRule.impl = the pluggable Profiling Rule impl
       *      
       * @param persistenceStore  The persistence persistenceStore 
       * @param properties  Properties for this component described above
       */
      public JetspeedCapabilities(PersistenceStore persistenceStore, Properties properties)
  	{
          this(persistenceStore);
          initModelClasses(properties);
      }
      
      private void initModelClasses(Properties properties)
  	{
          String modelName = "";
          try
          {
  	        if ((modelName = properties.getProperty("client.impl")) != null)
  	        {
  	            clientClass = Class.forName(modelName);
  	        }
  	        if ((modelName = properties.getProperty("capability.impl")) != null)
  	        {
  	            capabilityClass = Class.forName(modelName);
  	        }
  	        if ((modelName = properties.getProperty("mimetype.impl")) != null)
  	        {
  	            mimeTypeClass = Class.forName(modelName);
  	        }
  	        if ((modelName = properties.getProperty("mediatype.impl")) != null)
  	        {
  	            mediaTypeClass = Class.forName(modelName);
  	        }	        	        
  	        
          }
          catch (ClassNotFoundException e)
          {
              log.error("Model class not found: " + modelName);
          }
      }
      
  
      /**
       * @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;
          }
  
          // 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((MediaType) media.next());
                  }
  
                  //Set preferred Mimetype
                  MediaType mtEntry =
                      getMediaTypeForMimeType(map.getPreferredType().getName());
  
                  map.setPreferredMediaType(mtEntry);
  
                  // Add map to cache
                  capabilityMapCache.put(userAgent, map);
  
                  return map;
              }
  
          }
  
          return map;
      }
  
      /**
       * Returns the client which matches the given useragent string.
       *
       * @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.capabilities.CapabilityService#findClient(java.lang.String)
       */
  
      public Client findClient(String userAgent)
      {
          Client clientEntry = null;
          Iterator clients = getClients();
  
          if (log.isDebugEnabled())
          {
              log.debug(
                  "ClientRegistry: Looking for client with useragent :"
                      + userAgent);
          }
  
          while (clients.hasNext())
          {
              Client client = (Client) clients.next();
              if (client.getUserAgentPattern() != null)
              {
                  try
                  {
                      // 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(
                                  "Client: "
                                      + userAgent
                                      + " matches "
                                      + client.getUserAgentPattern());
                          }
  
                          return client;
                      } else
                      {
                          if (log.isDebugEnabled())
                          {
                              log.debug(
                                  "Client: "
                                      + userAgent
                                      + " does not match "
                                      + client.getUserAgentPattern());
                          }
                      }
                  } catch (java.util.regex.PatternSyntaxException e)
                  {
                      String message =
                          "CapabilityServiceImpl: UserAgentPattern not valid : "
                              + client.getUserAgentPattern()
                              + " : "
                              + e.getMessage();
                      log.error(message, e);
                  }
              }
          }
  
          return clientEntry;
      }
  
      /* 
       * @see org.apache.jetspeed.capabilities.CapabilityService#getClients()
       */
      public Iterator getClients()
      {
          if (null == clients)
          {
                  
              this.clients = persistenceStore.getExtent(ClientImpl.class);
          }
  
          return this.clients.iterator();
      }
  
      /* 
       * @see org.apache.jetspeed.capabilities.CapabilityService#getMediaTypesForMimeTypes(java.util.Iterator)
       */
      public Collection getMediaTypesForMimeTypes(Iterator mimetypes)
      {
          //Find the MediaType by matching the Mimetype
          
          Filter filter = persistenceStore.newFilter();        
  
          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());
          }
          
          Collection co = null;
          if (temp.size() > 0)
          {
              filter.addIn("mimetypes.name", temp);
              Object query = persistenceStore.newQuery(mediaTypeClass, filter);
              co = persistenceStore.getCollectionByQuery(query);
          }
  
          if (co == null || co.isEmpty())
          {
              MediaType mt = getMediaType("html");
              Vector v = new Vector();
              v.add(mt);
              return v;
          }
          return co;
      }
  
      /* 
       * @see org.apache.jetspeed.capabilities.CapabilityService#deleteCapabilityMapCache()
       */
      public void deleteCapabilityMapCache()
      {
          capabilityMapCache.clear();
          clients = null;
      }
  
      /* (non-Javadoc)
       * @see org.apache.jetspeed.capabilities.CapabilityService#getMediaType(java.lang.String)
       */
      public MediaType getMediaType(String mediaType)
      {
          
          Filter filter = persistenceStore.newFilter();        
          filter.addEqualTo("name", mediaType);
          Object query = persistenceStore.newQuery(mediaTypeClass, filter);
          return (MediaType) persistenceStore.getObjectByQuery(query);
      }
  
      /**
       * getMediaTypeForMimeType
       * @param mimeType to use for lookup
       * @return MediaTypeEntry that matches the lookup in the MEDIATYPE_TO_MIMETYPE table
       */
      public MediaType getMediaTypeForMimeType(String mimeTypeName)
      {               
          //Find the MediaType by matching the Mimetype
          
          
          Filter filter = persistenceStore.newFilter();        
          filter.addEqualTo("mimetypes.name", mimeTypeName);
          Object query = persistenceStore.newQuery(mediaTypeClass, filter);        
          Collection mediaTypeCollection = persistenceStore.getCollectionByQuery(query); 
              
          Iterator mtIterator = mediaTypeCollection.iterator();
          if (mtIterator.hasNext())
          {
              return (MediaType) mtIterator.next();
          } else
          {
              return null;
          }
      }
      
  }
  
  
  
  1.1                  jakarta-jetspeed-2/components/capability/src/java/org/apache/jetspeed/capabilities/impl/CapabilityMapImpl.java
  
  Index: CapabilityMapImpl.java
  ===================================================================
  /*
   * Copyright 2000-2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.jetspeed.capabilities.impl;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.jetspeed.capabilities.CapabilityMap;
  import org.apache.jetspeed.capabilities.Client;
  import org.apache.jetspeed.capabilities.Capability;
  import org.apache.jetspeed.capabilities.MediaType;
  
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Map;
  
  import org.apache.jetspeed.capabilities.MimeType;
  
  /**
   * Implementation for capabilityMap interface
   *
   * @author <a href="mailto:roger.ruttimann@earthlink.net">Roger Ruttimann</a>
   * @version $Id: CapabilityMapImpl.java,v 1.1 2004/05/28 18:49:15 weaver Exp $
   */
  class CapabilityMapImpl implements CapabilityMap
  {
      private static final Log log =
          LogFactory.getLog(JetspeedCapabilities.class);
      
      // Members
      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
      private MediaType preferredMediaType; // Preferred MediaType for client.
  
      /**
          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 the value that matches the preferredMimeType defined in the Client
          int prefMimeTypeId = this.client.getPreferredMimeTypeId();
  
          MimeType mt = null;        
          Iterator e = this.mimeTypeMap.values().iterator();
          while (e.hasNext())
          {            
              mt = (MimeType) e.next();
              
              if (mt.getMimetypeId() == prefMimeTypeId)
                  return mt;
          }
          log.error("Could not find preferred Mime Type for " + prefMimeTypeId);        
  
          // Should never reach this point. A preferred value needs to be set
          return null; // TODO: NEVER RETURN NULL
      }
  
      /**
            * Sets the preferred MediaType for this CapabilityMap
            * @param MediaTypeEntry 
          */
      public void setPreferredMediaType(MediaType type)
      {
          this.preferredMediaType = type;
      }
  
      /**
      Returns the preferred media type for the current user-agent
      */
      public MediaType getPreferredMediaType()
      {
          return this.preferredMediaType;
      }
  
      /**
       * Returns an ordered list of supported media-types, from most preferred
       * to least preferred
       */
      public Iterator listMediaTypes()
      {
          return mediaTypeMap.values().iterator();
      }
  
      /**
      Returns the user-agent string
      */
      public String getAgent()
      {
          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;
      }
  
      /**
       *  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;
      }
  
      /**
      Get the mime types that this CapabilityMap supports.
      */
      public Iterator getMimeTypes()
      {
          return mimeTypeMap.values().iterator();
      }
  
      /**
      Return true if this CapabilityMap supports the given MimeType
      */
      public boolean supportsMimeType(MimeType mimeType)
      {
          Iterator mimetypes = mimeTypeMap.values().iterator();
          while (mimetypes.hasNext())
          {
              if (((MimeType) mimetypes.next()).getName() == mimeType.getName())
              {
                  return true;
              }
          }
          return false;
      }
  
      /**
       * Return true if this CapabilityMap supports the given media type
       *
       * @param media the name of a media type registered in the
       * MediaType regsitry
       *
       * @return true is the capabilities of this agent at least match those
       * required by the media type
       */
      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
       */
      public String toString()
      {
          return "";
      }
  
  }
  
  
  
  1.1                  jakarta-jetspeed-2/components/capability/src/java/org/apache/jetspeed/capabilities/impl/MediaTypeImpl.java
  
  Index: MediaTypeImpl.java
  ===================================================================
  /*
   * Copyright 2000-2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.jetspeed.capabilities.impl;
  
  import org.apache.jetspeed.capabilities.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 2004/05/28 18:49:15 weaver 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.1                  jakarta-jetspeed-2/components/capability/src/java/org/apache/jetspeed/capabilities/impl/CapabilityImpl.java
  
  Index: CapabilityImpl.java
  ===================================================================
  /*
   * Copyright 2000-2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.jetspeed.capabilities.impl;
  
  import org.apache.jetspeed.capabilities.Capability;
  
  /**
   * Capability implementation class.
   *
   * @author <a href="mailto:roger.ruttimann@earthlink.net">Roger Ruttimann</a>
   * @version $Id: CapabilityImpl.java,v 1.1 2004/05/28 18:49:15 weaver Exp $
   */
  
  public class CapabilityImpl implements Capability
  {
      private int capabilityId;
      private String name;
  
      /* (non-Javadoc)
       * @see org.apache.jetspeed.om.registry.Capability#setCapabilityId(int)
       */
      public void setCapabilityId(int id)
      {
          this.capabilityId = id;
      }
  
      /* (non-Javadoc)
       * @see org.apache.jetspeed.om.registry.Capability#getCapabilityId()
       */
      public int getCapabilityId()
      {
          return this.capabilityId;
      }
  
      /* (non-Javadoc)
       * @see org.apache.jetspeed.om.registry.Capability#setName(java.lang.String)
       */
      public void setName(String name)
      {
          this.name = name;
      }
  
      /* (non-Javadoc)
       * @see org.apache.jetspeed.om.registry.Capability#getName()
       */
      public String getName()
      {
          return this.name;
      }
  
  }
  
  
  
  1.2       +204 -0    jakarta-jetspeed-2/components/capability/src/java/META-INF/ojb_repository.xml
  
  
  
  

---------------------------------------------------------------------
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