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/21 10:01:31 UTC

cvs commit: jakarta-jetspeed-2/portal/test/assembly TestCastorXmlPageManager.groovy TestDatabasePageManager.groovy

taylor      2004/02/21 01:01:30

  Modified:    portal   maven.xml
               portal/src/webapp/WEB-INF/assembly jetspeed.groovy
               portal/src/webapp/WEB-INF/conf jetspeed.properties
  Added:       portal/src/java/org/apache/jetspeed/page PageManager.java
                        PageNotRemovedException.java
                        PageNotUpdatedException.java
               portal/src/java/org/apache/jetspeed/page/impl
                        AbstractPageManager.java CastorXmlPageManager.java
                        DatabasePageManager.java
               portal/src/test/org/apache/jetspeed
                        PortalComponentAssemblyTestCase.java
               portal/src/test/org/apache/jetspeed/page
                        TestCastorXmlPageManager.java
                        TestDatabasePageManager.java
               portal/test/assembly TestCastorXmlPageManager.groovy
                        TestDatabasePageManager.groovy
  Removed:     portal/src/java/org/apache/jetspeed/services/page
                        PageManager.java PageManagerService.java
                        PageNotRemovedException.java
                        PageNotUpdatedException.java
               portal/src/java/org/apache/jetspeed/services/page/impl
                        AbstractPageManagerService.java
                        CastorXmlPageManagerService.java
                        DatabasePageManagerService.java
               portal/src/test/org/apache/jetspeed/services/page
                        TestPageDBPersistence.java
                        TestPageXmlPersistence.java
  Log:
  conversion of page service to component
  
  Revision  Changes    Path
  1.40      +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.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- maven.xml	20 Feb 2004 04:26:51 -0000	1.39
  +++ maven.xml	21 Feb 2004 09:01:30 -0000	1.40
  @@ -4,7 +4,7 @@
            xmlns:reactor="reactor">
   
     <!-- Target of maven test:single test -->
  -<property name='testcase' value='org.apache.jetspeed.tools.pamanager.TestPortletDescriptor'/>
  +<property name='testcase' value='org.apache.jetspeed.page.TestDatabasePageManager'/>
   
     <!-- ================================================================ -->
     <!-- Set System properties for junit                                  -->
  
  
  
  1.1                  jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/page/PageManager.java
  
  Index: PageManager.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.page;
  
  import java.util.List;
  
  import org.apache.jetspeed.exception.JetspeedException;
  import org.apache.jetspeed.om.page.Fragment;
  import org.apache.jetspeed.om.page.Page;
  import org.apache.jetspeed.om.page.Property;
  import org.apache.jetspeed.profiler.ProfileLocator;
  
  /**
   * This service is responsible for loading and saving Pages into
   * the selected persistent store.
   *
   * @version $Id: PageManager.java,v 1.1 2004/02/21 09:01:30 taylor Exp $
   */
  public interface PageManager 
  {
      /** The name of the service */
      public String SERVICE_NAME = "PageManager";
  
      /**
       * Creates a new empty Page instance
       *
       * @return a newly created Page object
       */
      public Page newPage();
  
      /**
       * Creates a new empty Fragment instance
       *
       * @return a newly created Fragment object
       */
      public Fragment newFragment();
  
      /**
       * Creates a new empty Property instance
       *
       * @return a newly created Property object
       */
      public Property newProperty();
  
      /**
       * Returns a PSML document for the given key
       *
       * @param locator The locator descriptor of the document to be retrieved.
       */
      public Page getPage(String id);
  
      /**
       * Returns a PSML document for the given locator
       *
       * @param locator The locator descriptor of the document to be retrieved.
       */
      public Page getPage(ProfileLocator locator);
  
      /** Query for a collection of profiles given a profile locator criteria.
       *
       * @param locator The profile locator criteria.
       *
       * @return A collection of profiles that match the criteria specified in the locator.
       */
      public List listPages();
  
      /** Store the PSML document on disk, using its locator
       *
       * @param profile the profile locator description.
       * @return true if the operation succeeded
       */
      public void registerPage(Page page) throws JetspeedException;
  
      /** Update a page in persistent storage
       *
       * @param locator The description of the profile to be removed.
       */
      public void updatePage(Page page) throws JetspeedException, PageNotUpdatedException;
  
      /** Remove a document.
       *
       * @param locator The description of the profile to be removed.
       */
      public void removePage(Page page)  throws PageNotRemovedException;
  
  }
  
  
  
  
  1.1                  jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/page/PageNotRemovedException.java
  
  Index: PageNotRemovedException.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.page;
  
  import org.apache.jetspeed.exception.JetspeedException;
  
  /**
   * <p>
   * PageNotRemovedException
   * </p>
   * 
   * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
   * @version $Id: PageNotRemovedException.java,v 1.1 2004/02/21 09:01:30 taylor Exp $
   *
   */
  public class PageNotRemovedException extends JetspeedException
  {
  
      /**
       * 
       */
      public PageNotRemovedException()
      {
          super();
          // TODO Auto-generated constructor stub
      }
  
      /**
       * @param message
       */
      public PageNotRemovedException(String message)
      {
          super(message);
          // TODO Auto-generated constructor stub
      }
  
      /**
       * @param nested
       */
      public PageNotRemovedException(Throwable nested)
      {
          super(nested);
          // TODO Auto-generated constructor stub
      }
  
      /**
       * @param msg
       * @param nested
       */
      public PageNotRemovedException(String msg, Throwable nested)
      {
          super(msg, nested);
          // TODO Auto-generated constructor stub
      }
  
  }
  
  
  
  1.1                  jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/page/PageNotUpdatedException.java
  
  Index: PageNotUpdatedException.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.page;
  
  import org.apache.jetspeed.exception.JetspeedException;
  
  /**
   * <p>
   * PageNotUpdatedException
   * </p>
   * 
   * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
   * @version $Id: PageNotUpdatedException.java,v 1.1 2004/02/21 09:01:30 taylor Exp $
   *
   */
  public class PageNotUpdatedException extends JetspeedException
  {
  
      /**
       * 
       */
      public PageNotUpdatedException()
      {
          super();
          // TODO Auto-generated constructor stub
      }
  
      /**
       * @param message
       */
      public PageNotUpdatedException(String message)
      {
          super(message);
          // TODO Auto-generated constructor stub
      }
  
      /**
       * @param nested
       */
      public PageNotUpdatedException(Throwable nested)
      {
          super(nested);
          // TODO Auto-generated constructor stub
      }
  
      /**
       * @param msg
       * @param nested
       */
      public PageNotUpdatedException(String msg, Throwable nested)
      {
          super(msg, nested);
          // TODO Auto-generated constructor stub
      }
  
  }
  
  
  
  1.1                  jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/page/impl/AbstractPageManager.java
  
  Index: AbstractPageManager.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.page.impl;
  
  import java.util.List;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.jetspeed.Jetspeed;
  import org.apache.jetspeed.idgenerator.IdGenerator;
  import org.apache.jetspeed.om.page.Fragment;
  import org.apache.jetspeed.om.page.Page;
  import org.apache.jetspeed.om.page.Property;
  import org.apache.jetspeed.om.page.psml.FragmentImpl;
  import org.apache.jetspeed.om.page.psml.PageImpl;
  import org.apache.jetspeed.om.page.psml.PropertyImpl;
  import org.apache.jetspeed.page.PageManager;
  import org.picocontainer.Startable;
  
  /**
   * AbstractPageManagerService
   *
   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
   * @version $Id: AbstractPageManager.java,v 1.1 2004/02/21 09:01:30 taylor Exp $
   */
  public abstract class AbstractPageManager 
      implements PageManager, Startable    
  {
      private final static Log log = LogFactory.getLog(AbstractPageManager.class);
      
      protected Class fragmentClass = FragmentImpl.class;
      protected Class pageClass = PageImpl.class;
      protected Class propertyClass = PropertyImpl.class;
      protected IdGenerator generator = null;
  
      public AbstractPageManager(IdGenerator generator)
      {    
          this.generator = generator;
      }
      
      public AbstractPageManager(IdGenerator generator, List modelClasses)
      {
          this.generator = (IdGenerator)Jetspeed.getComponentManager().getComponent("IdGenerator");        
          if (modelClasses.size() > 0)
          {
              this.fragmentClass = (Class)modelClasses.get(0);
              if (modelClasses.size() > 1)
              {
                  this.pageClass  = (Class)modelClasses.get(1);
                  if (modelClasses.size() > 2)
                  {
                      this.propertyClass  = (Class)modelClasses.get(2);
                  }                
              }
          }                                 
      }
      
      public void start()
      {
      }
      
      public void stop()
      {
      }
      
      /* (non-Javadoc)
       * @see org.apache.jetspeed.services.page.PageManagerService#newPage()
       */
      public Page newPage()
      {
          Page page = null;
          try
          {
              // factory create the page
              page = (Page)createObject(this.pageClass);            
              page.setId(generator.getNextPeid());
              
              // create the default fragment
              Fragment fragment = (Fragment)createObject(this.fragmentClass);
              fragment.setId(generator.getNextPeid());
              fragment.setType(Fragment.LAYOUT);
              page.setRootFragment(fragment);            
          }
          catch (ClassCastException e)
          {
              String message = "Failed to create page object for " + this.pageClass;
              log.error(message, e);
          }
          return page;        
      }
      
      /* (non-Javadoc)
       * @see org.apache.jetspeed.services.page.PageManagerService#newFragment()
       */
      public Fragment newFragment()
      {
          Fragment fragment = null;
          try
          {
              fragment = (Fragment)createObject(this.fragmentClass);
              fragment.setId(generator.getNextPeid());
              fragment.setType(Fragment.LAYOUT);
              
          }
          catch (ClassCastException e)
          {
              String message = "Failed to create page object for " + this.pageClass;
              log.error(message, e);
              // throw new JetspeedException(message, e);
          }
          return fragment;        
      }
      
      /* (non-Javadoc)
       * @see org.apache.jetspeed.services.page.PageManagerService#newProperty()
       */
      public Property newProperty()
      {
          Property property = null;
          try
          {
              property = (Property)createObject(this.propertyClass);
              
          }
          catch (ClassCastException e)
          {
              String message = "Failed to create fragment-property object for " + this.propertyClass;
              log.error(message, e);
              // throw new JetspeedException(message, e);
          }
          return property;        
      }
  
      public Object createObject(Class classe)
      {
          Object object = null;
          try
          {
              object = classe.newInstance();
          }
          catch (Exception e)
          {
              log.error("Factory failed to create object: " + classe.getName(), e);            
          }
          
          return object;        
      }
      
  }
  
  
  
  1.1                  jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/page/impl/CastorXmlPageManager.java
  
  Index: CastorXmlPageManager.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.page.impl;
  
  //standard java stuff
  import java.io.File;
  import java.io.FileReader;
  import java.io.FileWriter;
  import java.io.FilenameFilter;
  import java.io.IOException;
  import java.util.ArrayList;
  import java.util.List;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.jetspeed.Jetspeed;
  import org.apache.jetspeed.cache.file.FileCache;
  import org.apache.jetspeed.cache.file.FileCacheEntry;
  import org.apache.jetspeed.cache.file.FileCacheEventListener;
  import org.apache.jetspeed.exception.JetspeedException;
  import org.apache.jetspeed.idgenerator.IdGenerator;
  import org.apache.jetspeed.om.page.Page;
  import org.apache.jetspeed.page.PageManager;
  import org.apache.jetspeed.profiler.ProfileLocator;
  import org.apache.xml.serialize.OutputFormat;
  import org.apache.xml.serialize.Serializer;
  import org.apache.xml.serialize.XMLSerializer;
  import org.exolab.castor.mapping.Mapping;
  import org.exolab.castor.mapping.MappingException;
  import org.exolab.castor.xml.MarshalException;
  import org.exolab.castor.xml.Marshaller;
  import org.exolab.castor.xml.Unmarshaller;
  import org.exolab.castor.xml.ValidationException;
  import org.picocontainer.Startable;
  import org.xml.sax.InputSource;
  
  /**
   * This service is responsible for loading and saving PSML pages
   * serialized to disk
   *
   * @author <a href="mailto:raphael@apache.org">Rapha�l Luta</a>
   * @version $Id: CastorXmlPageManager.java,v 1.1 2004/02/21 09:01:30 taylor Exp $
   */
  public class CastorXmlPageManager extends AbstractPageManager implements FileCacheEventListener, PageManager, Startable
  {
      private final static Log log = LogFactory.getLog(CastorXmlPageManager.class);
      
      // configuration keys
      protected final static String CONFIG_ROOT = "root";
      protected final static String CONFIG_EXT = "ext";
      protected final static String CONFIG_SCAN_RATE = "scanRate";
      protected final static String CONFIG_CACHE_SIZE = "cacheSize";
  
      // default configuration values
      public final static String DEFAULT_ROOT = "/WEB-INF/pages";
      public final static String DEFAULT_EXT = ".psml";
  
      // the root psml resource directory
      protected String root;
      // base store directory
      protected File rootDir = null;
      // file extension
      protected String ext = DEFAULT_EXT;
  
      /** The pages loaded by this manager */
      protected FileCache pages = null;
  
      /** the output format for pretty printing when saving registries */
      protected OutputFormat format = null;
  
      /** the base refresh rate for pages */
      protected long scanRate = 1000 * 60; // every minute
  
      /** the default cache size */
      protected int cacheSize = 100;
  
      // castor mapping
      public static final String DEFAULT_MAPPING = "page-mapping.xml";
      protected String mapFile = null;
  
      /** the Castor mapping file name */
      protected Mapping mapping = null;
  
      public CastorXmlPageManager(IdGenerator generator, String mapFile, String root)
      {    
          super(generator);
          this.mapFile = mapFile;
          this.rootDir = new File(root);        
      }
      
      public CastorXmlPageManager(IdGenerator generator, String mapFile, String root, List modelClasses)
      {
          super(generator, modelClasses);
          this.mapFile = mapFile;
          this.rootDir = new File(root);        
      }
  
      public CastorXmlPageManager(IdGenerator generator, 
                                         String mapFile,
                                         String root,                                        
                                         List modelClasses,
                                         String extension, 
                                         long scanRate, 
                                         int cacheSize)
                                         
      {
          super(generator, modelClasses);
          this.mapFile = mapFile;        
          this.rootDir = new File(root);
          this.ext = extension;
          this.scanRate = scanRate;
          this.cacheSize = cacheSize;
      }
  
  
  
      public void start()
      {
          super.start();
          
  
          //If the rootDir does not exist, treat it as context relative
          if (!rootDir.exists())
          {
              try
              {
                  this.rootDir = new File(Jetspeed.getRealPath(DEFAULT_ROOT));
              }
              catch (Exception e)
              {
                  // this.rootDir = new File("./webapp" + this.rootDir.toString());
              }
          }
          //If it is still missing, try to create it
          if (!rootDir.exists())
          {
              try
              {
                  rootDir.mkdirs();
              }
              catch (Exception e)
              {
              }
          }
  
          // create the serializer output format
          this.format = new OutputFormat();
          format.setIndenting(true);
          format.setIndent(4);
  
          // psml castor mapping file
          loadMapping();
  
          pages = new FileCache(this.scanRate, this.cacheSize);
          pages.addListener(this);
          pages.startFileScanner();
  
      }
  
      public void stop()
      {
          pages.stopFileScanner();
      }
  
      /* (non-Javadoc)
       * @see org.apache.jetspeed.services.page.PageManagerService#getPage(org.apache.jetspeed.profiler.ProfileLocator)
       */
      public Page getPage(ProfileLocator locator)
      {
          return getPage(locator.getValue("page"));
      }
      
      /**
       * @see org.apache.jetspeed.services.page.PageManagerService#getPage(java.lang.String)
       */
      public Page getPage(String id)
      {
          if (id == null)
          {
              String message = "PageManager: Must specify an id";
              log.error(message);
              throw new IllegalArgumentException(message);
          }
  
          if (log.isDebugEnabled())
          {
              log.debug("Asked for PageID=" + id);
          }
  
          Page page = null;
  
          page = (Page) pages.getDocument(id);
  
          if (page == null)
          {
              File f = new File(this.rootDir, id + this.ext);
              if (!f.exists())
              {
                  return null;
              }
  
              FileReader reader = null;
  
              try
              {
                  reader = new FileReader(f);
                  Unmarshaller unmarshaller = new Unmarshaller(this.mapping);
                  page = (Page) unmarshaller.unmarshal(reader);
              }
              catch (IOException e)
              {
                  log.error("Could not load the file " + f.getAbsolutePath(), e);
                  page = null;
              }
              catch (MarshalException e)
              {
                  log.error("Could not unmarshal the file " + f.getAbsolutePath(), e);
                  page = null;
              }
              catch (MappingException e)
              {
                  log.error("Could not unmarshal the file " + f.getAbsolutePath(), e);
                  page = null;
              }
              catch (ValidationException e)
              {
                  log.error("Document " + f.getAbsolutePath() + " is not valid", e);
                  page = null;
              }
              finally
              {
                  try
                  {
                      reader.close();
                  }
                  catch (IOException e)
                  {
                  }
              }
  
              synchronized (pages)
              {
                  // store the document in the hash and reference it to the watcher
                  try
                  {
                      pages.put(id, page);
                  }
                  catch (java.io.IOException e)
                  {
                      log.error("Error putting document: " + e);
                  }
              }
          }
  
          return page;
      }
  
      /**
       * @see org.apache.jetspeed.services.page.PageManagerService#listPages()
       */
      public List listPages()
      {
          ArrayList results = new ArrayList();
          File[] files = this.rootDir.listFiles(new FilenameFilter()
          {
              public boolean accept(File dir, String file)
              {
                  return file.endsWith(CastorXmlPageManager.this.ext);
              }
          });
  
          for (int i = 0; i < files.length; i++)
          {
              String id = files[i].getName().substring(0, files[i].getName().length() - this.ext.length());
              results.add(id);
          }
  
          return results;
      }
  
      /**
       * @see org.apache.jetspeed.services.page.PageManagerService#registerPage(org.apache.jetspeed.om.page.Page)
       */
      public void registerPage(Page page) throws JetspeedException
      {
          // sanity checks
          if (page == null)
          {
              log.warn("Recieved null page to register");
              return;
          }
  
          String id = page.getId();
  
          if (id == null)
          {
              page.setId(generator.getNextPeid());
              id = page.getId();
              log.warn("Page with no Id, created new Id : " + id);
          }
  
          // marshal page to disk
          File f = new File(this.rootDir, id + this.ext);
          FileWriter writer = null;
  
          try
          {
              writer = new FileWriter(f);
              Serializer serializer = new XMLSerializer(writer, this.format);
              Marshaller marshaller = new Marshaller(serializer.asDocumentHandler());
              marshaller.setMapping(this.mapping);
              marshaller.marshal(page);
          }
          catch (MarshalException e)
          {
              log.error("Could not marshal the file " + f.getAbsolutePath(), e);
              throw new JetspeedException(e);
          }
          catch (MappingException e)
          {
              log.error("Could not marshal the file " + f.getAbsolutePath(), e);
              throw new JetspeedException(e);
          }
          catch (ValidationException e)
          {
              log.error("Document " + f.getAbsolutePath() + " is not valid", e);
              throw new JetspeedException(e);
          }
          catch (IOException e)
          {
              log.error("Could not save the file " + f.getAbsolutePath(), e);
              throw new JetspeedException(e);
          }
          catch (Exception e)
          {
              log.error("Error while saving  " + f.getAbsolutePath(), e);
              throw new JetspeedException(e);
          }
          finally
          {
              try
              {
                  writer.close();
              }
              catch (IOException e)
              {
              }
          }
  
          // update it in cache
          synchronized (pages)
          {
              try
              {
                  pages.put(id, page);
              }
              catch (IOException e)
              {
                  log.error("Error storing document: " + e);
              }
          }
      }
  
      /**
       * @see org.apache.jetspeed.services.page.PageManagerService#updatePage(org.apache.jetspeed.om.page.Page)
       */
      public void updatePage(Page page) throws JetspeedException
      {
          registerPage(page);
      }
  
      /**
       * @see org.apache.jetspeed.services.page.PageManagerService#removePage(org.apache.jetspeed.om.page.Page)
       */
      public void removePage(Page page)
      {
          String id = page.getId();
  
          if (id == null)
          {
              log.warn("Unable to remove page with null Id from disk");
              return;
          }
  
          File file = new File(this.rootDir, id + this.ext);
  
          synchronized (pages)
          {
              pages.remove(id);
          }
  
          file.delete();
  
      }
  
      protected void loadMapping() 
      {
          // test the mapping file and create the mapping object
  
          if (mapFile != null)
          {
              File map = new File(mapFile);
              if (log.isDebugEnabled())
              {
                  log.debug("Loading psml mapping file " + mapFile);
              }
              if (map.exists() && map.isFile() && map.canRead())
              {
                  try
                  {
                      mapping = new Mapping();
                      InputSource is = new InputSource(new FileReader(map));
                      is.setSystemId(mapFile);
                      mapping.loadMapping(is);
                  }
                  catch (Exception e)
                  {
                      log.error("Error in psml mapping creation", e);
                  }
              }
              else
              {
                  log.error("PSML Mapping not found or not a file or unreadable: " + mapFile);
              }
          }
      }
  
      /**
       * Refresh event, called when the entry is being refreshed from file system.
       *
       * @param entry the entry being refreshed.
       */
      public void refresh(FileCacheEntry entry)
      {
          log.debug("Entry is refreshing: " + entry.getFile().getName());
      }
  
      /**
       * Evict event, called when the entry is being evicted out of the cache
       *
       * @param entry the entry being refreshed.
       */
      public void evict(FileCacheEntry entry)
      {
          log.debug("Entry is evicting: " + entry.getFile().getName());
      }
  }
  
  
  1.1                  jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/page/impl/DatabasePageManager.java
  
  Index: DatabasePageManager.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.page.impl;
  
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.jetspeed.cps.CommonPortletServices;
  import org.apache.jetspeed.exception.JetspeedException;
  import org.apache.jetspeed.idgenerator.IdGenerator;
  import org.apache.jetspeed.om.page.Page;
  import org.apache.jetspeed.page.PageManager;
  import org.apache.jetspeed.persistence.LookupCriteria;
  import org.apache.jetspeed.persistence.PersistencePlugin;
  import org.apache.jetspeed.persistence.PersistenceService;
  import org.apache.jetspeed.persistence.store.PersistenceStore;
  import org.apache.jetspeed.profiler.ProfileLocator;
  import org.apache.jetspeed.page.PageNotRemovedException;
  import org.apache.jetspeed.page.PageNotUpdatedException;
  import org.picocontainer.Startable;
  
  /**
   * DatabasePageManagerService
   *
   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
   * @version $Id: DatabasePageManager.java,v 1.1 2004/02/21 09:01:30 taylor Exp $
   */
  public class DatabasePageManager extends AbstractPageManager implements PageManager, Startable
  {
      protected final static Log log = LogFactory.getLog(DatabasePageManager.class);
  
      private PersistencePlugin plugin;
  
      private PersistencePlugin originalPlugin;
  
      private String originalAlias;
  
      // TODO: this should eventually use a system cach like JCS
      private Map pageCache = new HashMap();
  
  
      public DatabasePageManager(PersistenceStore store, IdGenerator generator)
      {
          super(generator);
      }
  
      public void start()
      {
          //PersistenceService ps = (PersistenceService) CommonPortletServices.getPortalService(PersistenceService.SERVICE_NAME);
          // TODO: use new stuff String pluginName = getConfiguration().getString("persistence.plugin.name", "jetspeed");
          // String pluginName = "jetspeed";
  
          // plugin = ps.getPersistencePlugin(pluginName);
  
      }
      
      /* (non-Javadoc)
       * @see org.apache.jetspeed.services.page.PageManagerService#getPage(org.apache.jetspeed.profiler.ProfileLocator)
       */
      public Page getPage(ProfileLocator locator)
      {
          return getPage(locator.getValue("page"));
      }    
  
      /* (non-Javadoc)
       * @see org.apache.jetspeed.services.page.PageManagerService#getPage(java.lang.String)
       */
      public Page getPage(String id)
      {
          if (pageCache.containsKey(id))
          {
              return (Page) pageCache.get(id);
          }
          else
          {
              LookupCriteria c = plugin.newLookupCriteria();
              c.addEqualTo("id", id);
              Object q = plugin.generateQuery(pageClass, c);
              Page page = (Page) plugin.getObjectByQuery(pageClass, q);
  
              pageCache.put(id, page);
              return page;
          }
      }
  
      /* (non-Javadoc)
       * @see org.apache.jetspeed.services.page.PageManagerService#listPages()
       */
      public List listPages()
      {
          // TODO Auto-generated method stub
          return null;
      }
  
      /* (non-Javadoc)
       * @see org.apache.jetspeed.services.page.PageManagerService#registerPage(org.apache.jetspeed.om.page.Page)
       */
      public void registerPage(Page page) throws JetspeedException
      {
          // sanity checks
          if (page == null)
          {
              log.warn("Recieved null page to register");
              return;
          }
  
          String id = page.getId();
  
          if (id == null)
          {
              page.setId(generator.getNextPeid());
              id = page.getId();
              log.warn("Page with no Id, created new Id : " + id);
          }
  
      }
  
      /* (non-Javadoc)
       * @see org.apache.jetspeed.services.page.PageManagerService#updatePage(org.apache.jetspeed.om.page.Page)
       */
      public void updatePage(Page page) throws JetspeedException, PageNotUpdatedException
      {
          try
          {
              plugin.prepareForUpdate(page);
          }
          catch (Exception e)
          {
              String msg = "Unable to update Page.";
              log.error(msg, e);
              throw new PageNotUpdatedException(msg, e);
          }
      }
  
      /* (non-Javadoc)
       * @see org.apache.jetspeed.services.page.PageManagerService#removePage(org.apache.jetspeed.om.page.Page)
       */
      public void removePage(Page page) throws PageNotRemovedException
      {
          if (pageCache.containsKey(page.getId()))
          {
              pageCache.remove(pageCache.get(page.getId()));
          }
          try
          {
              plugin.prepareForDelete(page);
          }
          catch (Exception e)
          {
              String msg = "Unable to remove Page.";
              log.error(msg, e);
              throw new PageNotRemovedException(msg, e);
          }
      }
  
  }
  
  
  
  1.1                  jakarta-jetspeed-2/portal/src/test/org/apache/jetspeed/PortalComponentAssemblyTestCase.java
  
  Index: PortalComponentAssemblyTestCase.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;
  
  import org.apache.jetspeed.components.ComponentAssemblyTestCase;
  
  /**
   * PortalComponentAssemblyTestCase
   *
   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
   * @version $Id: PortalComponentAssemblyTestCase.java,v 1.1 2004/02/21 09:01:30 taylor Exp $
   */
  public class PortalComponentAssemblyTestCase extends ComponentAssemblyTestCase
  {
      public PortalComponentAssemblyTestCase(String name)
      {
          super(name);
      }
      
      /* (non-Javadoc)
       * @see org.apache.jetspeed.components.ComponentAssemblyTestCase#getBaseProject()
       */
      public String getBaseProject()
      {
          return "portal";
      }
  }
  
  
  
  1.1                  jakarta-jetspeed-2/portal/src/test/org/apache/jetspeed/page/TestCastorXmlPageManager.java
  
  Index: TestCastorXmlPageManager.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.page;
  
  // Java imports
  import java.util.List;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  
  import org.apache.jetspeed.PortalComponentAssemblyTestCase;
  import org.apache.jetspeed.om.page.Fragment;
  import org.apache.jetspeed.om.page.Page;
  import org.apache.jetspeed.om.page.Property;
  
  /**
   * TestPageXmlPersistence
   *
   * @author <a href="raphael@apache.org">Rapha�l Luta</a>
   * @version $Id: TestCastorXmlPageManager.java,v 1.1 2004/02/21 09:01:30 taylor Exp $
   */
  public class TestCastorXmlPageManager extends PortalComponentAssemblyTestCase
  {
      private String testId = "test002";
  
      /**
       * Defines the testcase name for JUnit.
       *
       * @param name the testcase's name.
       */
      public TestCastorXmlPageManager(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[] { TestCastorXmlPageManager.class.getName()});
      }
  
      /**
       * Creates the test suite.
       *
       * @return a test suite (<code>TestSuite</code>) that includes all methods
       *         starting with "test"
       */
      public static Test suite()
      {
          // All methods starting with "test" will be executed in the test suite.
          return new TestSuite(TestCastorXmlPageManager.class);
      }
  
      public void testNewPage()
      {
          PageManager pm = (PageManager)componentManager.getComponent("CastorXmlPageManager");
          assertNotNull("castor xml manager is null", pm);            
          Page testpage = pm.newPage();
          assertNotNull(testpage);
          assertNotNull(testpage.getId());
          assertNotNull(testpage.getRootFragment());
          assertNotNull(testpage.getRootFragment().getId());
      }
  
      public void testNewFragment()
      {
          PageManager pm = (PageManager)componentManager.getComponent("CastorXmlPageManager");
          assertNotNull("castor xml manager is null", pm);            
          Fragment f = pm.newFragment();
          assertNotNull(f);
          assertNotNull(f.getId());
          assertTrue(f.getType().equals(Fragment.LAYOUT));
      }
  
      public void testNewProperty()
      {
          // TODO: Fix Property manipulation API, too clumsy right now
      }
  
      public void testGetPage()
      {
          PageManager pm = (PageManager)componentManager.getComponent("CastorXmlPageManager");
          assertNotNull("castor xml manager is null", pm);            
          Page testpage = pm.getPage("test001");
          assertNotNull(testpage);
          assertTrue(testpage.getId().equals("test001"));
          assertTrue(testpage.getTitle().equals("Test Page"));
          assertTrue(testpage.getAcl().equals("owner-only"));
          assertTrue(testpage.getDefaultSkin().equals("test-skin"));
          assertTrue(testpage.getDefaultDecorator(Fragment.LAYOUT).equals("test-layout"));
          assertTrue(testpage.getDefaultDecorator(Fragment.PORTLET).equals("test-portlet"));
  
          Fragment root = testpage.getRootFragment();
          assertNotNull(root);
          assertTrue(root.getId().equals("f001"));
          assertTrue(root.getName().equals("TwoColumns"));
          assertTrue(root.getType().equals(Fragment.LAYOUT));
          assertNull(root.getDecorator());
  
          List children = root.getFragments();
          assertNotNull(children);
          assertTrue(children.size() == 3);
  
          Fragment f = (Fragment) children.get(0);
          assertTrue(f.getId().equals("pe001"));
          assertTrue(f.getName().equals("HelloPortlet"));
          assertTrue(f.getType().equals(Fragment.PORTLET));
  
          List properties = f.getProperties(root.getName());
          assertNotNull(properties);
          assertTrue(properties.size() == 2);
          assertTrue(((Property) properties.get(0)).getName().equals("row"));
          assertTrue(((Property) properties.get(0)).getValue().equals("0"));
          assertTrue(((Property) properties.get(1)).getName().equals("column"));
          assertTrue(((Property) properties.get(1)).getValue().equals("0"));
  
          f = (Fragment) children.get(1);
          assertTrue(f.getId().equals("pe002"));
          assertTrue(f.getName().equals("JMXPortlet"));
          assertTrue(f.getType().equals(Fragment.PORTLET));
  
          properties = f.getProperties(root.getName());
          assertNotNull(properties);
          assertTrue(properties.size() == 2);
          assertTrue(((Property) properties.get(0)).getName().equals("row"));
          assertTrue(((Property) properties.get(0)).getValue().equals("0"));
          assertTrue(((Property) properties.get(1)).getName().equals("column"));
          assertTrue(((Property) properties.get(1)).getValue().equals("1"));
  
          f = testpage.getFragmentById("f002");
          assertNotNull(f);
          assertTrue(f.getId().equals("f002"));
          assertTrue(f.getName().equals("Card"));
          assertTrue(f.getType().equals(Fragment.LAYOUT));
          assertTrue(f.getDecorator().equals("Tab"));
          assertNotNull(f.getFragments());
          assertTrue(f.getFragments().size() == 2);
      }
  
      public void testRegisterPage() throws Exception
      {
          PageManager pm = (PageManager)componentManager.getComponent("CastorXmlPageManager");
          assertNotNull("castor xml manager is null", pm);            
          Page page = pm.newPage();
          System.out.println("Retrieved test_id in register " + this.testId);
          page.setId(this.testId);
          page.setDefaultSkin("myskin");
          page.setTitle("Registered Page");
  
          Fragment root = page.getRootFragment();
          root.setName("TestLayout");
          Fragment f = pm.newFragment();
          f.setType(Fragment.PORTLET);
          f.setName("TestPortlet");
          Property p = pm.newProperty();
          p.setLayout("TestLayout");
          p.setName("row");
          p.setValue("0");
          f.addProperty(p);
          p = pm.newProperty();
          p.setLayout("TestLayout");
          p.setName("column");
          p.setValue("0");
          f.addProperty(p);
          root.getFragments().add(f);
  
          try
          {
              pm.registerPage(page);
          }
          catch (Exception e)
          {
              String errmsg = "Exception in page registratio: " + e.toString();
              e.printStackTrace();
              System.err.println(errmsg);
              assertNotNull(errmsg, null);
          }
  
          page = pm.getPage(this.testId);
          assertNotNull(page);
          assertTrue(page.getId().equals(this.testId));
          assertTrue(page.getTitle().equals("Registered Page"));
          assertNotNull(page.getRootFragment());
          assertTrue(page.getRootFragment().getName().equals("TestLayout"));
          assertTrue(page.getRootFragment().getFragments().size() == 1);
  
          f = (Fragment) page.getRootFragment().getFragments().get(0);
          assertNotNull(f.getProperties("TestLayout"));
          assertTrue(((Property) f.getProperties("TestLayout").get(0)).getValue().equals("0"));
      }
  
      public void testUpdatePage() throws Exception
      {
          PageManager pm = (PageManager)componentManager.getComponent("CastorXmlPageManager");
          assertNotNull("castor xml manager is null", pm);            
          Page page = pm.getPage(this.testId);
          page.setTitle("Updated Title");
  
          try
          {
              pm.updatePage(page);
          }
          catch (Exception e)
          {
              String errmsg = "Exception in page update: " + e.toString();
              e.printStackTrace();
              System.err.println(errmsg);
              assertNotNull(errmsg, null);
          }
  
          page = pm.getPage(this.testId);
          assertTrue(page.getTitle().equals("Updated Title"));
      }
  
      public void testListPages() throws Exception
      {
          PageManager pm = (PageManager)componentManager.getComponent("CastorXmlPageManager");
          assertNotNull("castor xml manager is null", pm);            
          List pages = pm.listPages();
          assertTrue(pages.size() == 3);
          assertTrue(pages.contains(this.testId));
          assertTrue(pages.contains("test001"));
      }
  
      public void testRemovePage() throws Exception
      {
          PageManager pm = (PageManager)componentManager.getComponent("CastorXmlPageManager");
          assertNotNull("castor xml manager is null", pm);            
          Page page = pm.getPage(this.testId);
  
          try
          {
              pm.removePage(page);
          }
          catch (Exception e)
          {
              String errmsg = "Exception in page remove: " + e.toString();
              e.printStackTrace();
              System.err.println(errmsg);
              assertNotNull(errmsg, null);
          }
  
          page = pm.getPage(this.testId);
          assertNull(page);
      }
  }
  
  
  
  1.1                  jakarta-jetspeed-2/portal/src/test/org/apache/jetspeed/page/TestDatabasePageManager.java
  
  Index: TestDatabasePageManager.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.page;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  
  import org.apache.jetspeed.PortalComponentAssemblyTestCase;
  import org.apache.jetspeed.om.page.Fragment;
  import org.apache.jetspeed.om.page.Page;
  
  /**
   * TestPageService
   *
   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
   * @version $Id: TestDatabasePageManager.java,v 1.1 2004/02/21 09:01:30 taylor Exp $
   */
  public class TestDatabasePageManager extends PortalComponentAssemblyTestCase
  {
      private PageManager service = null;
      
      /**
       * Defines the testcase name for JUnit.
       *
       * @param name the testcase's name.
       */
      public TestDatabasePageManager(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[] { TestDatabasePageManager.class.getName()});
      }
  
      public void setup()
      {
          System.out.println("Setup: Testing Page Service");
      }
  
      /**
       * Creates the test suite.
       *
       * @return a test suite (<code>TestSuite</code>) that includes all methods
       *         starting with "test"
       */
      public static Test suite()
      {
          // All methods starting with "test" will be executed in the test suite.
          return new TestSuite(TestDatabasePageManager.class);
      }
      
      
      public void testBuildBasePage()
      {
          PageManager pm = (PageManager)componentManager.getComponent("DatabasePageManager");
          assertNotNull("page manager is null", pm);            
          
          Page page = pm.newPage();
          page.setTitle("TEST");
  
          Fragment frag = pm.newFragment();
          frag.setId("Frag1");
          frag.setType(Fragment.LAYOUT);
  
          page.setRootFragment(frag);
      }
      
  }
  
  
  
  1.3       +9 -0      jakarta-jetspeed-2/portal/src/webapp/WEB-INF/assembly/jetspeed.groovy
  
  Index: jetspeed.groovy
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/webapp/WEB-INF/assembly/jetspeed.groovy,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- jetspeed.groovy	21 Feb 2004 07:24:50 -0000	1.2
  +++ jetspeed.groovy	21 Feb 2004 09:01:30 -0000	1.3
  @@ -23,4 +23,13 @@
   peidSuffix = ""
   container.registerComponentInstance("IdGenerator", new JetspeedIdGenerator(counterStart, peidPrefix, peidSuffix))
   
  +//
  +// Page Manager
  +//
  +root = applicationRoot + "/WEB-INF/pages"
  +mapping = applicationRoot + "/WEB-INF/conf/page-mapping.xml"
  +// TODO: modelclasses, extension, scanrate, cachesize
  +container.registerComponentInstance("CastorXmlPageManager", 
  +                                     new CastorXmlPageManager(idgenerator, mapping, root))
  +
   return container
  
  
  
  1.35      +1 -31     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.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- jetspeed.properties	21 Feb 2004 07:24:50 -0000	1.34
  +++ jetspeed.properties	21 Feb 2004 09:01:30 -0000	1.35
  @@ -249,25 +249,6 @@
   #---------------------------------------------------------------------------
   services.PortletEntityService.classname=org.apache.jetspeed.entity.PortletEntityServiceImpl
   services.PortletEntityService.entity.impl = org.apache.jetspeed.om.entity.impl.PortletEntityImpl
  -
  -# -------------------------------------------------------------------
  -# Page Manager 
  -# -------------------------------------------------------------------
  -services.PageManager.fragment.impl = org.apache.jetspeed.om.page.psml.FragmentImpl
  -services.PageManager.page.impl = org.apache.jetspeed.om.page.psml.PageImpl
  -services.PageManager.property.impl = org.apache.jetspeed.om.page.psml.PropertyImpl
  -
  -# -------------------------------------------------------------------
  -# Page Manager (Castor based)            
  -# -------------------------------------------------------------------
  -services.PageManager.classname=org.apache.jetspeed.services.page.impl.CastorXmlPageManagerService
  -services.PageManager.root=/WEB-INF/pages
  -services.PageManager.ext=.psml
  -services.PageManager.mapping=/WEB-INF/conf/page-mapping.xml
  -scan rate in seconds (every 2 minutes)
  -services.PageManager.scanRate=120
  -cache size - number of PSML pages to cache
  -services.PageManager.cacheSize=100
    
   #---------------------------------------------------------------------------------
   # Run Auto-Deployment set up
  @@ -283,11 +264,6 @@
   services.autodeployment.earlyInit = true
   
   
  -# -------------------------------------------------------------------
  -# Page Manager (Database)            
  -# -------------------------------------------------------------------
  -# services.PageManager.classname = org.apache.jetspeed.services.page.impl.DatabasePageManagerService
  -
   #--------------------------------------------------------------------
   # P R E F E R E N C E S  P R O P E R T Y  S E R V I C E
   #--------------------------------------------------------------------
  @@ -298,12 +274,6 @@
   #--------------------------------------------------------------------
   preferences.factory=org.apache.jetspeed.spi.services.prefs.impl.PreferencesFactoryImpl
   
  -# -------------------------------------------------------------------
  -# Page Registry (Castor based)            
  -# -------------------------------------------------------------------
  -# services.PageRegistry.classname=org.apache.jetspeed.services.page.impl.CastorXmlPageRegistryService
  -# services.PageRegistry.file=/WEB-INF/pages/pages.xreg
  -# services.PageRegistry.mapping=/WEB-INF/conf/pageregistry-mapping.xml
   
   #--------------------------------------------------------------------
   # S E C U R I T Y  S E R V I C E
  
  
  
  1.1                  jakarta-jetspeed-2/portal/test/assembly/TestCastorXmlPageManager.groovy
  
  Index: TestCastorXmlPageManager.groovy
  ===================================================================
  import org.picocontainer.defaults.DefaultPicoContainer
  import org.apache.jetspeed.idgenerator.JetspeedIdGenerator
  import org.apache.jetspeed.page.impl.CastorXmlPageManager
  import org.apache.jetspeed.components.ComponentAssemblyTestCase
  
  // create the root container
  container = new DefaultPicoContainer()
  
  applicationRoot = ComponentAssemblyTestCase.getApplicationRoot("portal", "test")
  
  //
  // ID Generator
  //
  idgenerator = new JetspeedIdGenerator()
  container.registerComponentInstance("IdGenerator", idgenerator)
  
  //
  // Page Manager
  //
  println("app root = " + applicationRoot)
  root = applicationRoot + "/testdata/pages"
  mapping = applicationRoot + "/../src/webapp/WEB-INF/conf/page-mapping.xml"
  container.registerComponentInstance("CastorXmlPageManager", 
                                       new CastorXmlPageManager(idgenerator, mapping, root))
  
  return container
  
  
  
  1.1                  jakarta-jetspeed-2/portal/test/assembly/TestDatabasePageManager.groovy
  
  Index: TestDatabasePageManager.groovy
  ===================================================================
  import org.picocontainer.defaults.DefaultPicoContainer
  import org.apache.jetspeed.idgenerator.JetspeedIdGenerator
  import org.apache.jetspeed.page.impl.DatabasePageManager
  import org.apache.jetspeed.components.ComponentAssemblyTestCase
  
  // create the root container
  container = new DefaultPicoContainer()
  
  applicationRoot = ComponentAssemblyTestCase.getApplicationRoot("portal", "test")
  
  //
  // ID Generator
  //
  idgenerator = new JetspeedIdGenerator()
  container.registerComponentInstance("IdGenerator", idgenerator)
  
  
  //
  // Persistence Store Service
  //
  // TODO: get persistence store service
  
  //
  // Page Manager
  //
  container.registerComponentInstance("DatabasePageManager", 
                                       new DatabasePageManager(null, idgenerator))
  
  return container
  
  
  

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