You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by ta...@apache.org on 2004/02/11 05:35:12 UTC

cvs commit: jakarta-jetspeed-2/cps/test/rewriter test-001-output.html

taylor      2004/02/10 20:35:12

  Modified:    cps      maven.xml project.xml
               cps/test/rewriter test-001-output.html
  Added:       cps/src/java/org/apache/jetspeed/cps/template
                        TemplateLocatorComponent.java
                        TemplateLocatorComponentImpl.java
               cps/src/test/org/apache/jetspeed/cps TestPico.java
  Log:
  Pico Container test - im stuck here trying to figure out how to pass in a Configuration....
  
  Revision  Changes    Path
  1.5       +1 -1      jakarta-jetspeed-2/cps/maven.xml
  
  Index: maven.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/cps/maven.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- maven.xml	3 Feb 2004 21:57:35 -0000	1.4
  +++ maven.xml	11 Feb 2004 04:35:11 -0000	1.5
  @@ -4,7 +4,7 @@
            xmlns:reactor="reactor">
   
     <!-- Target of maven test:single test -->
  -  <property name='testcase' value='org.apache.jetspeed.cps.discovery.TestCPSDiscovery'/>  
  +  <property name='testcase' value='org.apache.jetspeed.cps.TestPico'/>  
     
      <goal name="deployJar">
     	<attainGoal name="jar:install"/>
  
  
  
  1.7       +7 -1      jakarta-jetspeed-2/cps/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/cps/project.xml,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- project.xml	4 Feb 2004 21:40:25 -0000	1.6
  +++ project.xml	11 Feb 2004 04:35:11 -0000	1.7
  @@ -91,7 +91,13 @@
           <war.bundle.jar>false</war.bundle.jar>
         </properties>
       </dependency>
  -
  +    <dependency>
  +      <id>picocontainer</id>
  +      <version>1.0-beta-4</version>
  +      <properties>
  +        <war.bundle.jar>true</war.bundle.jar>
  +      </properties>
  +    </dependency>
     </dependencies>
     <build>
       <sourceDirectory>src/java</sourceDirectory>
  
  
  
  1.1                  jakarta-jetspeed-2/cps/src/java/org/apache/jetspeed/cps/template/TemplateLocatorComponent.java
  
  Index: TemplateLocatorComponent.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.cps.template;
  
  import java.util.Iterator;
  
  /**
   * TemplateLocatorComponent
   *
   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
   * @version $Id: TemplateLocatorComponent.java,v 1.1 2004/02/11 04:35:11 taylor Exp $
   */
  public interface TemplateLocatorComponent
  {
      /** The name of this service */
      String SERVICE_NAME = "template";
          
      /**
       * Locate an template using Jetspeed template location algorithm
       *
       * @param locator The template locator
       * @return The template found, or null if not found.
       * @throws TemplateLocatorException
       */
      Template locateTemplate(TemplateLocator locator)
          throws TemplateLocatorException;
  
      /**
       * Factory to create template locators of the given type.
       * Known supported locator types, but not limited to: 
       *      <code>portlet</code>
       *      <code>email</code>
       * 
       * @param The type of locator to create
       * @return a general template locator of the given type
       * @throws TemplateLocatorException if factory exception or if not valid locator type
       */
      TemplateLocator createLocator(String type)
          throws TemplateLocatorException;
  
      /**
       * Creates a locator from a string of format (where brackets are optional]:
       *
       *   template/<templateType>/[media-type/<mediaType>]/[language/<language>]/[country/<country>]]/name/<templateName
       * 
       * @param string the string representation of a template locator 
       * @throws TemplateLocatorException
       */        
      TemplateLocator createFromString(String string)
          throws TemplateLocatorException;
          
      /** 
       * Query for a collection of templates given template locator criteria.
       *
       * @param locator The template locator criteria.
       * @return The result list of {@link Template} objects matching the locator criteria.
       */
      public Iterator query(TemplateLocator locator);
      
  }
  
  
  
  1.1                  jakarta-jetspeed-2/cps/src/java/org/apache/jetspeed/cps/template/TemplateLocatorComponentImpl.java
  
  Index: TemplateLocatorComponentImpl.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.cps.template;
  
  import java.util.Iterator;
  import java.io.File;
  import java.util.Iterator;
  import java.util.Map;
  import java.util.HashMap;
  import java.util.StringTokenizer;
  
  import org.apache.commons.configuration.Configuration;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  /**
   * TemplateLocatorComponentImpl
   *
   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
   * @version $Id: TemplateLocatorComponentImpl.java,v 1.1 2004/02/11 04:35:11 taylor Exp $
   */
  public class TemplateLocatorComponentImpl implements TemplateLocatorComponent
  {
      private final static Log log = LogFactory.getLog(TemplateLocatorServiceImpl.class);
      private final static String MSG_MISSING_PARAMETER =
          "TemplateLocatorService initialization failed. Missing parameter: ";
      private static final String PATH_SEPARATOR = "/";
  
      /** the template root directories, all application root relative */
      private String[] templateRoots;
      private final static String TEMPLATE_ROOTS = "roots";
  
      /** use the name cache when looking up a template */
      private boolean useNameCache = true;
      
      /** template name cache used to speed up searches for templates */
      private Map templateMap = null;
      
      /** the TemplateLocator class is factory created */     
      private static String locatorClassName = null;
      private static Class  locatorClass = null;
      private final static String TEMPLATE_LOCATOR_CLASS = "locator.class";
      
      /** the default locator type */
      private String defaultLocatorType = "portlet";
      private final static String DEFAULT_LOCATOR_TYPE = "locator.default.type";
  
      /** the default template name */    
      private String defaultTemplateName = "default.vm";
      private final static String DEFAULT_TEMPLATE_NAME = "default.template.name";
  
      /** the default template name */    
      private String defaultExtension = "vm";
      private final static String DEFAULT_EXTENSION = "default.extension";
      
          
      /* (non-Javadoc)
       * @see org.apache.jetspeed.cps.template.TemplateLocatorService#locateTemplate(org.apache.jetspeed.cps.template.TemplateLocator)
       */
      public Template locateTemplate(TemplateLocator locator)
      {
          for (int ix = 0; ix < templateRoots.length; ix++)
          {        
              Template template = locateTemplate(locator, templateRoots[ix]);
              if (null == template)
              {
                  // Try to locate it directly on file system, perhaps it was recently added
                  useNameCache = false;
                  template = locateTemplate(locator, templateRoots[ix]);
                  if (null != template)
                  {
                      // add it to the map
                      templateMap.put(template.getAbsolutePath(), null);
                  }
                  useNameCache = true;   
              }
              if (template != null)
              {
                  return template;
              }
          }
          return null;        
      }
   
      /**
       * General template location algorithm. Starts with the most specific resource,
       * including mediatype + nls specification, and fallsback to least specific.
       *
       * @param locator The template locator 
       * @param root The root directory to search
       *
       * @return Template the exact path to the template, or null if not found.
       */
      private Template locateTemplate(TemplateLocator locator, String root)
      {
          String templateName = locator.getName();       
          String path = locator.toPath();
          
          int last = path.lastIndexOf(PATH_SEPARATOR);
          if (last > -1)
          {
              // drop off the name
              path = path.substring(0, last);
          }
          else
          {
              path = null;
          }                
                  
          String basePath = root; 
          String realPath = null;
          String workingPath = null;
          
          do // fallback
          {
              workingPath = path + PATH_SEPARATOR + templateName;
              // TODO: realPath = CommonPortletServices.getInstance().getRealPath(root + workingPath);
  
              // the current template exists, return the corresponding path
              if (templateExists(realPath))
              {
                  if (log.isDebugEnabled())
                  {
                      log.debug(
                              "TemplateLocator: template exists: "
                                  + realPath
                                  + " returning "
                                  + workingPath);
                  }
                  return createTemplateFromPath(path, templateName, realPath, root + workingPath);
              }
              // else strip path of one of its components and loop
              int pt = path.lastIndexOf(PATH_SEPARATOR);
              if (pt > -1)
              {
                  path = path.substring(0, pt);
              }
              else
              {
                  path = null;
              }
          }
          while (path != null);
  
          return null;
      }
  
      /**
       * Checks for the existence of a template resource given a key.
       * The key are absolute paths to the templates, and are cached
       * in a template cache for performance.
       *
       * @param key The absolute path to the template resource.
       *
       * @return True when the template is found, otherwise false.
       */
      public boolean templateExists(String templateKey)
      {
          if (null == templateKey)
          {
              return false;
          }
          if (useNameCache == true)
          {
              return templateMap.containsKey(templateKey);
          }
          return (new File(templateKey).exists());
      }
      
     
      /* (non-Javadoc)
       * @see org.apache.jetspeed.cps.template.TemplateLocatorService#createFromString(java.lang.String)
       */
      public TemplateLocator createFromString(String path)
          throws TemplateLocatorException
      {
          TemplateLocator locator = createLocator(this.defaultLocatorType);
          StringTokenizer tok = new StringTokenizer(path, "/");
          while (tok.hasMoreTokens())
          {
              String name = (String)tok.nextToken();
              if (name.equals(TemplateLocator.PARAM_TYPE) && tok.hasMoreTokens())
              {
                  locator.setType( tok.nextToken() );
              }
              else if (name.equals(TemplateLocator.PARAM_MEDIA_TYPE) && tok.hasMoreTokens())
              {
                  locator.setMediaType(tok.nextToken());
              }
              else if (name.equals(TemplateLocator.PARAM_LANGUAGE) && tok.hasMoreTokens())
              {
                  locator.setLanguage(tok.nextToken());
              }
              else if (name.equals(TemplateLocator.PARAM_COUNTRY) && tok.hasMoreTokens())
              {
                  locator.setCountry(tok.nextToken());
              }
          
              else if (name.equals(TemplateLocator.PARAM_NAME) && tok.hasMoreTokens())
              {
                  locator.setName(tok.nextToken());
              }
          }    
          return locator;    
      }
  
      /**
       * Given a path, name and realPath creates a new template object
       * 
       * @param path the relative path to the template
       * @param name the template name
       * @param realPath the real path on the file system
       * @return newly created Template
       */
      private Template createTemplateFromPath(String path, String name, String realPath, String relativePath)
      {    
          TemplateImpl template = new TemplateImpl();
          template.setAbsolutePath(realPath);
          if(relativePath.indexOf("/") != 0)
          {
              relativePath = "/"+relativePath;
          }
          template.setAppRelativePath(relativePath);
          template.setName(name);            
          StringTokenizer tok = new StringTokenizer(path, "/");
          int count = 0;
          while (tok.hasMoreTokens())
          {
              String token = (String)tok.nextToken();
              switch (count)
              {
                  case 0:
                      template.setType(token);
                      break;
                  case 1:
                      template.setMediaType(token);
                      break;
                  case 2:
                      template.setLanguage(token);
                      break;
                  case 3:                    
                      template.setCountry(token);
                      break;                                    
              }
              count++;
          }    
          return template;                                                    
      }
      
      /* (non-Javadoc)
       * @see org.apache.jetspeed.cps.template.TemplateLocatorService#createLocator(String type)
       */
      public TemplateLocator createLocator(String type)
          throws TemplateLocatorException
      {
          TemplateLocator locator = null;
          
          if (null == locatorClass)
          {
              try
              {                
                  // TODO: locatorClassName = getConfiguration().getString(TEMPLATE_LOCATOR_CLASS);
                  locatorClass = Class.forName(locatorClassName);
              }
              catch(Exception e)
              {
                  throw new TemplateLocatorException(
                      "TemplateLocator Factory: Failed to create a Class object for TemplateLocator implementation: ", e);
              }
          }
      
          try
          {
              locator = (TemplateLocator)locatorClass.newInstance();
              locator.setType(type);
          }
          catch(Exception e)
          {
              throw new TemplateLocatorException("Failed instantiate a Template Locator implementation object: ", e);
          }
          return locator;    
      }
          
      public TemplateLocatorComponentImpl()
      {  
          System.out.println("--- DEFAULT constructing template locator impl");      
      }
  
      public TemplateLocatorComponentImpl(Configuration configuration)
      {  
          System.out.println("--- CONFIGURATION constructing template locator impl");
          this.configuration = configuration;      
      }
      
      
      Configuration configuration = null;
      
      public Configuration getConfiguration()
      {
          return configuration;
      }
      
      /* (non-Javadoc)
       * @see org.apache.fulcrum.Service#init()
       *
      public void init() throws CPSInitializationException
      {
          if (isInitialized())
          {
              return;
          }
          
          this.defaultLocatorType = getConfiguration().getString(DEFAULT_LOCATOR_TYPE, defaultLocatorType);
          this.defaultTemplateName = getConfiguration().getString(DEFAULT_TEMPLATE_NAME, defaultTemplateName);        
          this.defaultExtension = getConfiguration().getString(DEFAULT_EXTENSION, defaultExtension);        
  
          this.templateRoots = getConfiguration().getStringArray(TEMPLATE_ROOTS);
  
          if ((this.templateRoots == null) || (this.templateRoots.length == 0))
          {
              throw new CPSInitializationException(MSG_MISSING_PARAMETER + TEMPLATE_ROOTS);
          }
  
          this.templateMap = new HashMap();
  
          for (int ix = 0; ix < this.templateRoots.length; ix++)
          {
              String templateRoot = this.templateRoots[ix];
  
              if (!templateRoot.endsWith(PATH_SEPARATOR))
              {
                  templateRoot = templateRoot + PATH_SEPARATOR;
              }
  
              if (log.isDebugEnabled())
              {
                  log.debug("TemplateLocator: Adding templateRoot:" + templateRoot);
              }
  
              // traverse starting from the root template directory and add resources
              String templateRootPath = CommonPortletServices.getInstance().getRealPath(templateRoot);
              if (null != templateRootPath)
              {
                  loadNameCache(templateRootPath, "");
              }
          }
          
          setInit(true);
      }
    */
    
      /* (non-Javadoc)
       * @see org.apache.jetspeed.cps.template.TemplateLocatorService#query(org.apache.jetspeed.cps.template.TemplateLocator)
       */
      public Iterator query(TemplateLocator locator)
      {
          return null; // TODO: implement this
      }
  
      /**
       * Loads the template name cache map to accelerate template searches.
       *
       * @param path The template
       * @param name just the name of the resource
       */
      private void loadNameCache(String path, String name)
      {
          File file = new File(path);
          if (file.isFile())
          {
              // add it to the map
              templateMap.put(path, null);
          }
          else
          {
              if (file.isDirectory())
              {
                  if (!path.endsWith(File.separator))
                  {
                      path += File.separator;
                  }
  
                  String list[] = file.list();
  
                  // Process all files recursivly
                  for (int ix = 0; list != null && ix < list.length; ix++)
                  {
                      loadNameCache(path + list[ix], list[ix]);
                  }
              }
          }
      }
  }
  
  
  
  1.1                  jakarta-jetspeed-2/cps/src/test/org/apache/jetspeed/cps/TestPico.java
  
  Index: TestPico.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.cps;
  
  import java.io.File;
  import java.util.Iterator;
  
  import org.apache.commons.configuration.Configuration;
  import org.apache.commons.configuration.PropertiesConfiguration;
  import org.apache.jetspeed.cps.template.Template;
  import org.apache.jetspeed.cps.template.TemplateLocator;
  import org.apache.jetspeed.cps.template.TemplateLocatorComponent;
  import org.apache.jetspeed.cps.template.TemplateLocatorComponentImpl;
  import org.picocontainer.ComponentAdapter;
  import org.picocontainer.MutablePicoContainer;
  import org.picocontainer.defaults.DefaultPicoContainer;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  /**
   * TestPico
   *
   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
   * @version $Id: TestPico.java,v 1.1 2004/02/11 04:35:11 taylor Exp $
   */
  public class TestPico extends TestCase
  {
      /**
        * Defines the testcase name for JUnit.
        *
        * @param name the testcase's name.
        */
      public TestPico( 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[] { TestPico.class.getName() } );
      }
  
      public void setup() 
      {
          System.out.println("Setup: Testing Email");
      }
  
      public static Test suite()
      {
          // All methods starting with "test" will be executed in the test suite.
          return new TestSuite( TestPico.class );
      }
      
      public void testContainer()
            throws Exception
      {
          Configuration configuration = getConfiguration();
          
          MutablePicoContainer pico = new DefaultPicoContainer();
          // ConstructorComponentAdaptorFactory cca = new ConstructorComponentAdaptorFactory();
              
          pico.registerComponentImplementation(TemplateLocatorComponent.class, TemplateLocatorComponentImpl.class);    
          // pico.addParameterToComponent(TemplateLocatorComponent.class, Configuration.class, configuration);    
          pico.start();
          
          TemplateLocatorComponent locator1 = (TemplateLocatorComponent)pico.getComponentInstance(TemplateLocatorComponent.class);
          assertNotNull("locator 1 is null", locator1);
          System.out.println("locator 1 = " + locator1);
          
          TemplateLocatorComponent locator2 = (TemplateLocatorComponent)pico.getComponentInstance(TemplateLocatorComponent.class);
          assertNotNull("locator 1 is null", locator2);
          System.out.println("locator 2 = " + locator2);
          // simpleTest(locator2);
          
          ComponentAdapter adapter = null;
          Iterator adapters = pico.getComponentAdapters().iterator();
          while (adapters.hasNext())
          {
              adapter = (ComponentAdapter)adapters.next();
              System.out.println("adapter = " + adapter);                
          }
          
          pico.stop();
          
      }
      
      public void simpleTest(TemplateLocatorComponent service)
      throws Exception        
      {
          TemplateLocator locator = service.createLocator("email");
          locator.setName("test.vm");
          /*
          Template template = service.locateTemplate(locator);
          assertNotNull("template is null", template);
          System.out.println("template1 = " + template);
          assertTrue("template1 result", "type/email/name/test.vm".endsWith(template.toString()));
          */        
      }
      
      public Configuration getConfiguration()
      throws Exception
      {
          String propertiesFilename = getPropertiesFile();
          String applicationRoot = getApplicationRoot();
          Configuration configuration = (Configuration) 
              new PropertiesConfiguration(propertiesFilename);
              
          configuration.setProperty(CPSConstants.APPLICATION_ROOT_KEY, applicationRoot);
          return configuration;
      }
      
      /**
       * Override to set your own properties file
       *
       */
      public String getPropertiesFile()
      {
          return getApplicationRoot() + "/WEB-INF/conf/cps.properties";
      }
  
      
      /**
       * Override to set your own application root
       * If the default directory does not exist, then look in
       * the cps directory.  If the directory exist in the cps directory,
       * then return this directory.  Yes this is a hack, but it works.
       */
      public String getApplicationRoot()
      {
          String applicationRoot = "test";
          File testPath = new File(applicationRoot);
          if (!testPath.exists())
          {
              testPath = new File( "cps" + File.separator + applicationRoot);
              if (testPath.exists())
              {
                  applicationRoot = testPath.getAbsolutePath();
              }
          }
          return applicationRoot;
      }
      
  }
  
  
  
  1.17      +3 -3      jakarta-jetspeed-2/cps/test/rewriter/test-001-output.html
  
  Index: test-001-output.html
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/cps/test/rewriter/test-001-output.html,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- test-001-output.html	5 Feb 2004 02:59:20 -0000	1.16
  +++ test-001-output.html	11 Feb 2004 04:35:11 -0000	1.17
  @@ -1,8 +1,8 @@
   <p>
   This is a test</p>
  -<a target="_BLANK" href="http://www.bluesunrise.com/suffix" name="1">keep this</a>
  - <a target="_BLANK" href="http://www.rewriter.com/stuff/junk/stuffedjunk.html/suffix" name="2">junk</a>
  - <a target="_BLANK" href="http://www.rewriter.com/stuff/junk/stuffedjunk.html/suffix" name="3">junk2</a>
  +<a href="http://www.bluesunrise.com/suffix" target="_BLANK" name="1">keep this</a>
  + <a href="http://www.rewriter.com/stuff/junk/stuffedjunk.html/suffix" target="_BLANK" name="2">junk</a>
  + <a href="http://www.rewriter.com/stuff/junk/stuffedjunk.html/suffix" target="_BLANK" name="3">junk2</a>
    <a href="javascript:whatever()" name="4">script</a>
    <a href="mailto:david@bluesunrise.com" name="5">script</a>
    <a href="#INTERNAL" name="6">internal</a>
  
  
  

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