raphael     2003/08/08 15:05:55

  Modified:    portal/src/java/org/apache/jetspeed/om/page Fragment.java
                        Page.java
               portal/src/java/org/apache/jetspeed/om/page/psml
                        Defaults.java FragmentImpl.java PageImpl.java
                        PropertyImpl.java
               portal/src/test/org/apache/jetspeed/om/page
                        TestPageObjectModel.java
               portal/src/webapp/WEB-INF/conf jetspeed.properties
               portal/src/webapp/WEB-INF/conf/test jetspeed.properties
  Added:       portal/src/java/org/apache/jetspeed/services/page
                        PageManager.java PageManagerService.java
               portal/src/java/org/apache/jetspeed/services/page/impl
                        CastorXmlPageManagerService.java
               portal/src/test/org/apache/jetspeed/services/page
                        TestPageXmlPersistence.java
               portal/src/webapp/WEB-INF/conf page-mapping.xml
               portal/src/webapp/WEB-INF/pages p001.psml
  Log:
  - Update Page OM to fix Property maniuplation issue
  - Add Castor XML implementation of PageManager service
  
  Revision  Changes    Path
  1.2       +32 -13    
jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/om/page/Fragment.java
  
  Index: Fragment.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/om/page/Fragment.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Fragment.java     3 Aug 2003 14:18:51 -0000       1.1
  +++ Fragment.java     8 Aug 2003 22:05:55 -0000       1.2
  @@ -54,9 +54,7 @@
   
   package org.apache.jetspeed.om.page;
   
  -import java.util.Map;
   import java.util.List;
  -import java.util.Set;
   
   /**
    * <p>A <code>Fragment</code> is the basic element handled by the aggregation
  @@ -233,22 +231,43 @@
       public List getFragments();
   
       /**
  -     * Returns all properties describing this fragment. Only the
  -     * implementation of the "classname" knows how to handle the
  -     * properties
  +     * Returns all layout names for which properties have
  +     * been defined.
        *
  -     * @return a collection containing Property objects
  +     * @return a list of layout names Strings
        */
  -    public Set getLayoutProperties();
  +    public List getLayoutProperties();
   
       /**
  -     * Returns all properties describing this fragment. Only the
  -     * implementation of the "classname" knows how to handle the
  -     * properties
  +     * Returns a list of all properties defined
  +     * for the layoutName specified. You can update the properties
  +     * but not add or remove them
        *
  -     * @return a collection containing Property objects
  +     * @return an immutable List of Property objects
        */
  -    public Map getProperties(String layoutName);
  +    public List getProperties(String layoutName);
  +
  +    /**
  +     * Adds a new property to this fragment
  +     *
  +     * @param p the new Property to add
  +     */
  +    public void addProperty(Property p);
  +
  +    /**
  +     * Removes a new property from this fragment
  +     *
  +     * @param p the Property to remove
  +     */
  +    public void removeProperty(Property p);
  +
  +    /**
  +     * Clear all the properties for a specific layout,
  +     * if layoutName is null, clear all properties.
  +     *
  +     * @param layoutName the layout for which to remove the properties
  +     */
  +    public void clearProperties(String layoutName);
   
       /**
        * Test if this fragment is actually a reference to an external fragment.
  
  
  
  1.2       +1 -18     
jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/om/page/Page.java
  
  Index: Page.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/om/page/Page.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Page.java 3 Aug 2003 14:18:51 -0000       1.1
  +++ Page.java 8 Aug 2003 22:05:55 -0000       1.2
  @@ -79,23 +79,6 @@
       public void setId(String id);
   
       /**
  -     * Return the name of this page. This name is a convenient handler
  -     * for the page that can be used to locate a page.
  -     * It's possible for several pages to have the same name.
  -     *
  -     * @return the name of this page
  -     */
  -    public String getName();
  -
  -    /**
  -     * Sets a new name for this page. It must not be null and must not contain
  -     * any space or slash character.
  -     *
  -     * @param name the new document name
  -     */
  -    public void setName(String name);
  -
  -    /**
        * Returns the Page title in the default Locale
        *
        * @return the page title
  
  
  
  1.2       +3 -3      
jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/om/page/psml/Defaults.java
  
  Index: Defaults.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/om/page/psml/Defaults.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Defaults.java     3 Aug 2003 14:18:52 -0000       1.1
  +++ Defaults.java     8 Aug 2003 22:05:55 -0000       1.2
  @@ -91,12 +91,12 @@
           decoratorMap.put(type,decorator);
       }
   
  -    public String getFragmentDecorator()
  +    public String getLayoutDecorator()
       {
           return getDecorator("layout");
       }
   
  -    public void setFragmentDecorator(String decorator)
  +    public void setLayoutDecorator(String decorator)
       {
           setDecorator("layout",decorator);
       }
  
  
  
  1.2       +70 -66    
jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/om/page/psml/FragmentImpl.java
  
  Index: FragmentImpl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/om/page/psml/FragmentImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FragmentImpl.java 3 Aug 2003 14:18:52 -0000       1.1
  +++ FragmentImpl.java 8 Aug 2003 22:05:55 -0000       1.2
  @@ -54,11 +54,8 @@
   
   package org.apache.jetspeed.om.page.psml;
   
  -import java.util.Map;
  -import java.util.List;
  -import java.util.Set;
  -import java.util.Hashtable;
   import java.util.ArrayList;
  +import java.util.List;
   import java.util.Vector;
   import java.util.Iterator;
   
  @@ -79,11 +76,9 @@
   
       private String skin = null;
   
  -    private Map properties = new Hashtable();
  -
  -    private List fragments = new ArrayList();
  +    private List fragments = new Vector();
   
  -    private transient List psmlProperties = new Vector();
  +    private List properties = new Vector();
   
       public FragmentImpl()
       {}
  @@ -138,85 +133,94 @@
           return this.fragments;
       }
   
  -    public Set getLayoutProperties()
  +    public List getLayoutProperties()
       {
  -        return this.properties.keySet();
  -    }
  +        List layouts = new ArrayList();
  +        Iterator i = this.properties.iterator();
   
  -    public Map getProperties(String layoutName)
  -    {
  -        return (Map)this.properties.get(layoutName);
  +        while(i.hasNext())
  +        {
  +            Property p = (Property)i.next();
  +            if (!layouts.contains(p.getLayout()))
  +            {
  +                layouts.add(p.getLayout());
  +            }
  +        }
  +
  +        return layouts;
       }
   
  -    public List getProperties()
  +    public List getProperties(String layoutName)
       {
  -        synchronized (properties)
  -        {
  -            this.psmlProperties.clear();
  +        List props = new ArrayList();
  +        Iterator i = this.properties.iterator();
   
  -            Iterator i = this.properties.keySet().iterator();
  +        if (layoutName == null)
  +        {
  +            layoutName = "";
  +        }
   
  -            while(i.hasNext())
  +        while(i.hasNext())
  +        {
  +            Property p = (Property)i.next();
  +            if (layoutName.equals(p.getLayout()))
               {
  -                String layout = (String)i.next();
  -                Map lprop = (Map)this.properties.get(layout);
  -
  -                Iterator i2 = lprop.keySet().iterator();
  -
  -                while(i2.hasNext())
  -                {
  -                    String name = (String)i.next();
  -                    String value = (String)lprop.get(name);
  -
  -                    Property property = new PropertyImpl();
  -                    property.setLayout(layout);
  -                    property.setName(name);
  -                    property.setValue(value);
  -
  -                    this.psmlProperties.add(property);
  -                }
  +                props.add(p);
               }
           }
   
  -        return this.psmlProperties;
  +        return props;
       }
   
  -    public void setProperties(List psmlProperties)
  +    public void addProperty(Property p)
       {
  -        synchronized (properties)
  -        {
  -            this.psmlProperties = psmlProperties;
  +        this.properties.add(p);
  +    }
   
  -            Iterator i = this.psmlProperties.iterator();
  +    public void removeProperty(Property p)
  +    {
  +        Iterator i = this.properties.iterator();
  +
  +        while(i.hasNext())
  +        {
  +            Property p2 = (Property)i.next();
   
  -            while(i.hasNext())
  +            if (p2.equals(p))
               {
  -                Property prop = (Property)i.next();
  +                i.remove();
  +            }
  +        }
  +    }
  +
  +    public void clearProperties(String layoutName)
  +    {
  +        if (layoutName == null)
  +        {
  +            this.properties.clear();
  +            return;
  +        }
   
  -                String name = prop.getName();
  -                String value = prop.getValue();
  +        Iterator i = this.properties.iterator();
   
  -                if ((name == null)||(value == null))
  -                {
  -                    continue;
  -                }
  -
  -                String layout = prop.getLayout();
  -                if (layout == null)
  -                {
  -                    layout = "";
  -                }
  -
  -                Map lprop = (Map)this.properties.get(layout);
  -                if (lprop == null)
  -                {
  -                    lprop = new Hashtable();
  -                    this.properties.put(layout,lprop);
  -                }
  +        while(i.hasNext())
  +        {
  +            Property p = (Property)i.next();
   
  -                lprop.put(name,value);
  +            if (layoutName.equals(p.getLayout()))
  +            {
  +                i.remove();
               }
           }
  +    }
  +
  +    public Vector getProperties()
  +    {
  +        return (Vector)this.properties;
  +    }
  +
  +    public void setProperties(Vector props)
  +    {
  +        this.properties=props;
       }
   
       public void setFragments(List fragements)
  
  
  
  1.2       +9 -2      
jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/om/page/psml/PageImpl.java
  
  Index: PageImpl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/om/page/psml/PageImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PageImpl.java     3 Aug 2003 14:18:52 -0000       1.1
  +++ PageImpl.java     8 Aug 2003 22:05:55 -0000       1.2
  @@ -122,7 +122,14 @@
                   stack.push(i.next());
               }
   
  -            f = (Fragment)stack.pop();
  +            if (stack.size()>0)
  +            {
  +                f = (Fragment)stack.pop();
  +            }
  +            else
  +            {
  +                f = null;
  +            }
           }
   
           return f;
  
  
  
  1.2       +43 -1     
jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/om/page/psml/PropertyImpl.java
  
  Index: PropertyImpl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/om/page/psml/PropertyImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PropertyImpl.java 3 Aug 2003 14:18:52 -0000       1.1
  +++ PropertyImpl.java 8 Aug 2003 22:05:55 -0000       1.2
  @@ -105,6 +105,48 @@
           this.value = value;
       }
   
  +
  +    public boolean equals(Object object)
  +    {
  +        boolean isEqual = true;
  +
  +        if (object instanceof Property)
  +        {
  +            if (this.name!=null)
  +            {
  +                isEqual&=this.name.equals(((Property)object).getName());
  +            }
  +            else
  +            {
  +                isEqual&=((Property)object).getName()==null;
  +            }
  +
  +            if (this.value!=null)
  +            {
  +                isEqual&=this.value.equals(((Property)object).getValue());
  +            }
  +            else
  +            {
  +                isEqual&=((Property)object).getValue()==null;
  +            }
  +
  +            if (this.layout!=null)
  +            {
  +                isEqual&=this.layout.equals(((Property)object).getLayout());
  +            }
  +            else
  +            {
  +                isEqual&=((Property)object).getLayout()==null;
  +            }
  +        }
  +        else
  +        {
  +            isEqual = false;
  +        }
  +
  +        return isEqual;
  +    }
  +
       public Object clone()
           throws java.lang.CloneNotSupportedException
       {
  
  
  
  1.1                  
jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/services/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 [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache" or
   *    "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.services.page;
  
  import java.util.Iterator;
  import java.util.List;
  import org.apache.jetspeed.om.page.Page;
  import org.apache.jetspeed.om.page.Fragment;
  import org.apache.jetspeed.om.page.Property;
  import org.apache.jetspeed.exception.JetspeedException;
  import org.apache.jetspeed.util.ServiceUtil;
  
  /**
   * Convenience static wrapper around <code>PageManagerService</code>
   *
   * @version $Id: PageManager.java,v 1.1 2003/08/08 22:05:55 raphael Exp $
   */
  public class PageManager
  {
      private static final PageManagerService getService()
      {
          return (PageManagerService) ServiceUtil.getServiceByName(
              PageManagerService.SERVICE_NAME);
      }
  
      /**
       * @see org.apache.jetspeed.services.page.PageManagerService#newPage()
       */
      public static Page newPage()
      {
          return getService().newPage();
      }
  
      /**
       * @see org.apache.jetspeed.services.page.PageManagerService#newFragment()
       */
      public static Fragment newFragment()
      {
          return getService().newFragment();
      }
  
      /**
       * @see org.apache.jetspeed.services.page.PageManagerService#newProperty()
       */
      public static Property newProperty()
      {
          return getService().newProperty();
      }
  
      /**
       * @see 
org.apache.jetspeed.services.page.PageManagerService#getPage(java.lang.String)
       */
      public static Page getPage(String id)
      {
          return getService().getPage(id);
      }
  
      /**
       * @see org.apache.jetspeed.services.page.PageManagerService#listPages()
       */
      public static List listPages()
      {
          return getService().listPages();
      }
  
      /**
       * @see 
org.apache.jetspeed.services.page.PageManagerService#registerPage(org.apache.jetspeed.om.page.Page)
       */
      public static void registerPage(Page page) throws JetspeedException
      {
          getService().registerPage(page);
      }
  
      /**
       * @see 
org.apache.jetspeed.services.page.PageManagerService#updatePage(org.apache.jetspeed.om.page.Page)
       */
      public static void updatePage(Page page) throws JetspeedException
      {
          getService().updatePage(page);
      }
  
      /**
       * @see 
org.apache.jetspeed.services.page.PageManagerService#removePage(org.apache.jetspeed.om.page.Page)
       */
      public static void removePage(Page page)
      {
          getService().removePage(page);
      }
  
  }
  
  
  
  
  1.1                  
jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/services/page/PageManagerService.java
  
  Index: PageManagerService.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 [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache" or
   *    "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.services.page;
  
  import java.util.Iterator;
  import java.util.List;
  import org.apache.jetspeed.om.page.Page;
  import org.apache.jetspeed.om.page.Fragment;
  import org.apache.jetspeed.om.page.Property;
  import org.apache.jetspeed.exception.JetspeedException;
  import org.apache.fulcrum.Service;
  
  /**
   * This service is responsible for loading and saving Pages into
   * the selected persistent store.
   *
   * @version $Id: PageManagerService.java,v 1.1 2003/08/08 22:05:55 raphael Exp $
   */
  public interface PageManagerService extends Service
  {
      /** 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 locator
       *
       * @param locator The locator descriptor of the document to be retrieved.
       */
      public Page getPage(String id);
  
      /** 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;
  
      /** Remove a document.
       *
       * @param locator The description of the profile to be removed.
       */
      public void removePage(Page page);
  
  }
  
  
  
  
  1.1                  
jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/services/page/impl/CastorXmlPageManagerService.java
  
  Index: CastorXmlPageManagerService.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 [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache" or
   *    "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.services.page.impl;
  
  //standard java stuff
  import java.io.File;
  import java.io.FilenameFilter;
  import java.io.Reader;
  import java.io.FileReader;
  import java.io.Writer;
  import java.io.FileWriter;
  import java.io.IOException;
  import java.util.Iterator;
  import java.util.List;
  import java.util.ArrayList;
  
  //castor support
  import org.exolab.castor.xml.MarshalException;
  import org.exolab.castor.xml.Unmarshaller;
  import org.exolab.castor.xml.Marshaller;
  import org.exolab.castor.xml.ValidationException;
  import org.exolab.castor.mapping.Mapping;
  import org.exolab.castor.mapping.MappingException;
  import org.xml.sax.InputSource;
  
  // serialization support
  import org.apache.xml.serialize.Serializer;
  import org.apache.xml.serialize.XMLSerializer;
  import org.apache.xml.serialize.OutputFormat;
  
  import org.apache.fulcrum.BaseService;
  import org.apache.fulcrum.InitializationException;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  import org.apache.jetspeed.om.page.Page;
  import org.apache.jetspeed.om.page.Fragment;
  import org.apache.jetspeed.om.page.Property;
  import org.apache.jetspeed.om.page.psml.PageImpl;
  import org.apache.jetspeed.om.page.psml.FragmentImpl;
  import org.apache.jetspeed.om.page.psml.PropertyImpl;
  
  import org.apache.jetspeed.Jetspeed;
  import org.apache.jetspeed.exception.JetspeedException;
  import org.apache.jetspeed.cache.file.FileCache;
  import org.apache.jetspeed.cache.file.FileCacheEventListener;
  import org.apache.jetspeed.cache.file.FileCacheEntry;
  import org.apache.jetspeed.services.idgenerator.JetspeedIdGenerator;
  import org.apache.jetspeed.services.page.PageManagerService;
  
  /**
   * This service is responsible for loading and saving PSML pages
   * serialized to disk
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Rapha�l Luta</a>
   * @version $Id: CastorXmlPageManagerService.java,v 1.1 2003/08/08 22:05:55 raphael 
Exp $
   */
  public class CastorXmlPageManagerService extends BaseService
                                           implements FileCacheEventListener,
                                                      PageManagerService
  {
      // 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;
  
      /** 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;
  
      private final static Log log = 
LogFactory.getLog(CastorXmlPageManagerService.class);
  
      /**
       * This is the early initialization method called by the
       * Turbine <code>Service</code> framework
       */
      public void init() throws InitializationException
      {
          if (isInitialized())
          {
              return;
          }
  
          // get the PSML Root Directory
          this.root = getConfiguration().getString( CONFIG_ROOT, DEFAULT_ROOT );
          this.rootDir = new File(root);
  
          //If the rootDir does not exist, treat it as context relative
          if ( !rootDir.exists() )
          {
              try
              {
                  this.rootDir = new File(Jetspeed.getRealPath(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)
              {
              }
          }
  
          // get default extension
          this.ext = getConfiguration().getString( CONFIG_EXT, DEFAULT_EXT );
  
          // create the serializer output format
          this.format = new OutputFormat();
          format.setIndenting(true);
          format.setIndent(4);
  
          // psml castor mapping file
          mapFile = getConfiguration().getString("mapping",DEFAULT_MAPPING);
          mapFile = Jetspeed.getRealPath( mapFile );
          loadMapping();
  
          this.scanRate = getConfiguration().getLong(CONFIG_SCAN_RATE, this.scanRate);
          this.cacheSize= getConfiguration().getInt(CONFIG_CACHE_SIZE, this.cacheSize);
  
          pages = new FileCache(this.scanRate, this.cacheSize);
          pages.addListener(this);
          pages.startFileScanner();
  
          //Mark that we are done
          setInit(true);
      }
  
      /**
       * This is the shutdown method called by the
       * Turbine <code>Service</code> framework
       */
      public void shutdown()
      {
          pages.stopFileScanner();
      }
  
      /**
       * @see org.apache.jetspeed.services.page.PageManagerService#newPage()
       */
      public Page newPage()
      {
          PageImpl p = new PageImpl();
          p.setId(JetspeedIdGenerator.getNextPeid());
          FragmentImpl f = new FragmentImpl();
          f.setId(JetspeedIdGenerator.getNextPeid());
          f.setType(Fragment.LAYOUT);
          p.setRootFragment(f);
  
          return p;
      }
  
      /**
       * @see org.apache.jetspeed.services.page.PageManagerService#newFragment()
       */
      public Fragment newFragment()
      {
          FragmentImpl f = new FragmentImpl();
          f.setId(JetspeedIdGenerator.getNextPeid());
          f.setType(Fragment.LAYOUT);
  
          return f;
      }
  
      /**
       * @see org.apache.jetspeed.services.page.PageManagerService#newProperty()
       */
      public Property newProperty()
      {
          return new PropertyImpl();
      }
  
      /**
       * @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(CastorXmlPageManagerService.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
      {
          // snaity checks
          if (page == null)
          {
              log.warn("Recieved null page to register");
              return;
          }
  
          String id = page.getId();
  
          if (id == null)
          {
              page.setId(JetspeedIdGenerator.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()
          throws InitializationException
      {
          // 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);
                      throw new InitializationException("Error in mapping",e);
                  }
              }
              else
              {
                  throw new InitializationException("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.2       +4 -6      
jakarta-jetspeed-2/portal/src/test/org/apache/jetspeed/om/page/TestPageObjectModel.java
  
  Index: TestPageObjectModel.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/portal/src/test/org/apache/jetspeed/om/page/TestPageObjectModel.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestPageObjectModel.java  3 Aug 2003 14:18:52 -0000       1.1
  +++ TestPageObjectModel.java  8 Aug 2003 22:05:55 -0000       1.2
  @@ -115,7 +115,6 @@
       {
           PageImpl page = new PageImpl();
           page.setId("MyPageID");
  -        page.setName("Test");
   
           Fragment frag = new FragmentImpl();
           frag.setId("Frag1");
  @@ -132,7 +131,6 @@
   
           Page page = buildBasePage();
           assertTrue(page.getId().equals("MyPageID"));
  -        assertTrue(page.getName().equals("Test"));
           Fragment root = page.getRootFragment();
           assertNotNull(root);
           assertTrue(root.getId().equals("Frag1"));
  @@ -140,7 +138,7 @@
           assertNull(root.getTitle());
       }
   
  -    public void tesFragmentManipulation() throws Exception
  +    public void testFragmentManipulation() throws Exception
       {
           System.out.println("Testing Fragments manipulation");
   
  @@ -204,10 +202,10 @@
           frag2.setType(Fragment.PORTLET);
           frag2.setName("P4");
   
  -        frag3 = page.getFragmentById("Portlet3");
  +        frag3 = page.getFragmentById("F3");
           assertNotNull(frag3);
           f.getFragments().remove(frag3);
  -        frag3 = page.getFragmentById("Portlet3");
  +        frag3 = page.getFragmentById("F3");
           assertNull(frag3);
           f.getFragments().add(frag2);
           assertTrue(f.getFragments().size()==1);
  
  
  
  1.1                  
jakarta-jetspeed-2/portal/src/test/org/apache/jetspeed/services/page/TestPageXmlPersistence.java
  
  Index: TestPageXmlPersistence.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 [EMAIL PROTECTED]
   *
   * 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.services.page;
  
  // Java imports
  import java.util.List;
  import java.util.Map;
  import java.util.Iterator;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  
  import org.apache.jetspeed.om.page.Page;
  import org.apache.jetspeed.om.page.Fragment;
  import org.apache.jetspeed.om.page.Property;
  import org.apache.jetspeed.test.JetspeedTest;
  import org.apache.jetspeed.util.ServiceUtil;
  /**
   * TestPageXmlPersistence
   *
   * @author <a href="[EMAIL PROTECTED]">Rapha�l Luta</a>
   * @version $Id: TestPageXmlPersistence.java,v 1.1 2003/08/08 22:05:55 raphael Exp $
   */
  public class TestPageXmlPersistence extends JetspeedTest
  {
      private PageManagerService service = null;
      private String test_id = "test002";
  
      /**
       * Defines the testcase name for JUnit.
       *
       * @param name the testcase's name.
       */
      public TestPageXmlPersistence( 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[] { 
TestPageXmlPersistence.class.getName() } );
      }
  
      public void setup()
      {
          System.out.println("Setup: Testing Xml Persistence of Pages");
      }
  
      /**
       * 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( TestPageXmlPersistence.class );
      }
  
  
      protected PageManagerService getService()
      {
          if (service == null)
          {
              service = (PageManagerService) 
ServiceUtil.getServiceByName("XML"+PageManagerService.SERVICE_NAME);
          }
          return service;
      }
  
      public void testService()
      {
          assertNotNull(getService());
      }
  
      public void testNewPage()
      {
          PageManagerService pms = getService();
          Page testpage = pms.newPage();
          assertNotNull(testpage);
          assertNotNull(testpage.getId());
          assertNotNull(testpage.getRootFragment());
          assertNotNull(testpage.getRootFragment().getId());
      }
  
      public void testNewFragment()
      {
  
          PageManagerService pms = getService();
          Fragment f = pms.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()
      {
          PageManagerService pms = getService();
          Page testpage = pms.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
      {
          PageManagerService pms = getService();
          Page page = pms.newPage();
          System.out.println("Retrieved test_id in register " + this.test_id);
          page.setId(this.test_id);
          page.setDefaultSkin("myskin");
          page.setTitle("Registered Page");
  
          Fragment root = page.getRootFragment();
          root.setName("TestLayout");
          Fragment f = pms.newFragment();
          f.setType(Fragment.PORTLET);
          f.setName("TestPortlet");
          Property p = pms.newProperty();
          p.setLayout("TestLayout");
          p.setName("row");
          p.setValue("0");
          f.addProperty(p);
          p = pms.newProperty();
          p.setLayout("TestLayout");
          p.setName("column");
          p.setValue("0");
          f.addProperty(p);
          root.getFragments().add(f);
  
          try
          {
              pms.registerPage(page);
          }
          catch (Exception e)
          {
              String errmsg = "Exception in page registratio: " + e.toString();
              e.printStackTrace();
              System.err.println(errmsg);
              assertNotNull(errmsg, null);
          }
  
          page = pms.getPage(this.test_id);
          assertNotNull(page);
          assertTrue(page.getId().equals(this.test_id));
          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
      {
          PageManagerService pms = getService();
          Page page = pms.getPage(this.test_id);
          page.setTitle("Updated Title");
  
          try
          {
              pms.updatePage(page);
          }
          catch (Exception e)
          {
              String errmsg = "Exception in page update: " + e.toString();
              e.printStackTrace();
              System.err.println(errmsg);
              assertNotNull(errmsg, null);
          }
  
          page = pms.getPage(this.test_id);
          assertTrue(page.getTitle().equals("Updated Title"));
      }
  
      public void testListPages() throws Exception
      {
          PageManagerService pms = getService();
          List pages = pms.listPages();
          assertTrue(pages.size()==2);
          assertTrue(pages.contains(this.test_id));
          assertTrue(pages.contains("test001"));
      }
  
      public void testRemovePage() throws Exception
      {
          PageManagerService pms = getService();
          Page page = pms.getPage(this.test_id);
  
          try
          {
              pms.removePage(page);
          }
          catch (Exception e)
          {
              String errmsg = "Exception in page remove: " + e.toString();
              e.printStackTrace();
              System.err.println(errmsg);
              assertNotNull(errmsg, null);
          }
  
          page = pms.getPage(this.test_id);
          assertNull(page);
      }
  }
  
  
  
  1.3       +14 -1     
jakarta-jetspeed-2/portal/src/webapp/WEB-INF/conf/jetspeed.properties
  
  Index: jetspeed.properties
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/portal/src/webapp/WEB-INF/conf/jetspeed.properties,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- jetspeed.properties       1 Aug 2003 20:15:13 -0000       1.2
  +++ jetspeed.properties       8 Aug 2003 22:05:55 -0000       1.3
  @@ -242,3 +242,16 @@
   #  E N T I T Y   S E R V I C E
   #---------------------------------------------------------------------------
   
services.PortletEntityService.classname=org.apache.jetspeed.services.entity.PortletEntityServiceImpl
  +
  +# -------------------------------------------------------------------
  +# 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
  +
  
  
  
  1.1                  
jakarta-jetspeed-2/portal/src/webapp/WEB-INF/conf/page-mapping.xml
  
  Index: page-mapping.xml
  ===================================================================
  <?xml version="1.0"?>
  <mapping>
    <class name="org.apache.jetspeed.om.page.psml.PageImpl">
      <map-to xml="page"/>
  
      <field name="id" type="java.lang.String">
        <bind-xml name="id" node="attribute"/>
      </field>
  
      <field name="acl" type="java.lang.String">
        <bind-xml name="acl" node="attribute"/>
      </field>
  
      <field name="title" type="java.lang.String">
        <bind-xml name="title"/>
      </field>
  
      <field name="defaults"
             type="org.apache.jetspeed.om.page.psml.Defaults">
        <bind-xml name="defaults"/>
      </field>
  
      <field name="rootFragment"
             type="org.apache.jetspeed.om.page.psml.FragmentImpl">
        <bind-xml name="fragment"/>
      </field>             
    </class>
  
    <class name="org.apache.jetspeed.om.page.psml.FragmentImpl">
      <map-to xml="fragment"/>
  
      <field name="id" type="java.lang.String">
        <bind-xml name="id" node="attribute"/>
      </field>
  
      <field name="acl" type="java.lang.String">
        <bind-xml name="acl" node="attribute"/>
      </field>
  
      <field name="type" type="java.lang.String">
        <bind-xml name="type" node="attribute"/>
      </field>
  
      <field name="name" type="java.lang.String">
        <bind-xml name="name" node="attribute"/>
      </field>
  
      <field name="skin" type="java.lang.String">
        <bind-xml name="skin" node="attribute"/>
      </field>
  
      <field name="state" type="java.lang.String">
        <bind-xml name="state" node="attribute"/>
      </field>
  
      <field name="decorator" type="java.lang.String">
        <bind-xml name="decorator" node="attribute"/>
      </field>
  
      <field name="title" type="java.lang.String">
        <bind-xml name="title"/>
      </field>
  
      <field name="fragments"
             type="org.apache.jetspeed.om.page.psml.FragmentImpl" 
             collection="vector">
        <bind-xml name="fragment"/>
      </field>
  
      <field name="properties"
             type="org.apache.jetspeed.om.page.psml.PropertyImpl" collection="vector">
        <bind-xml name="property"/>
      </field>
    </class>
  
    <class name="org.apache.jetspeed.om.page.psml.Defaults">
      <map-to xml="defaults"/>
  
      <field name="skin" type="java.lang.String">
        <bind-xml name="skin" node="attribute"/>
      </field>
  
      <field name="layoutDecorator" type="java.lang.String">
        <bind-xml name="layout-decorator" node="attribute"/>
      </field>
      
      <field name="portletDecorator" type="java.lang.String">
        <bind-xml name="portlet-decorator" node="attribute"/>
      </field>
   </class>
  
    <class name="org.apache.jetspeed.om.page.psml.PropertyImpl">
      <map-to xml="property"/>
  
      <field name="name" type="java.lang.String">
        <bind-xml name="name" node="attribute"/>
      </field>
  
      <field name="value" type="java.lang.String">
        <bind-xml name="value" node="attribute"/>
      </field>
  
      <field name="layout" type="java.lang.String">
        <bind-xml name="layout" node="attribute"/>
      </field>
   </class>
  
  </mapping>
  
  
  1.3       +15 -1     
jakarta-jetspeed-2/portal/src/webapp/WEB-INF/conf/test/jetspeed.properties
  
  Index: jetspeed.properties
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/portal/src/webapp/WEB-INF/conf/test/jetspeed.properties,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- jetspeed.properties       1 Aug 2003 20:15:53 -0000       1.2
  +++ jetspeed.properties       8 Aug 2003 22:05:55 -0000       1.3
  @@ -25,3 +25,17 @@
   
services.PersistenceService.classname=org.apache.jetspeed.services.persistence.JetspeedPersistenceService
   
   
  +# -------------------------------------------------------------------
  +# Page Manager (Castor based)            
  +# -------------------------------------------------------------------
  
+services.XMLPageManager.classname=org.apache.jetspeed.services.page.impl.CastorXmlPageManagerService
  +services.XMLPageManager.root=./test/testdata/pages
  +services.XMLPageManager.ext=.psml
  +services.XMLPageManager.mapping=/WEB-INF/conf/page-mapping.xml
  +# scan rate in seconds (every 2 minutes)
  +services.XMLPageManager.scanRate=120
  +# cache size - number of PSML pages to cache
  +services.XMLPageManager.cacheSize=100
  +
  +services.PageManager.root=./test/testdata/pages
  +services.PageManager.mapping=/WEB-INF/conf/page-mapping.xml
  \ No newline at end of file
  
  
  
  1.1                  jakarta-jetspeed-2/portal/src/webapp/WEB-INF/pages/p001.psml
  
  Index: p001.psml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <page id="p001">
    <defaults
       skin="light-blue"
       layout-decorator="clear"
       portlet-decorator="box-titled"
    />
    <title>My First PSML Page</title>
    <fragment id="f001" type="layout" name="TwoColumns">
      <fragment id="pe001" type="portlet" name="HelloPortlet">
        <property layout="TwoColumns" name="row" value="0" />
        <property layout="TwoColumns" name="column" value="0" />      
      </fragment>
      <fragment id="pe002" type="portlet" name="JMXPortlet">
        <property layout="TwoColumns" name="row" value="0" />
        <property layout="TwoColumns" name="column" value="1" />      
      </fragment>
      <fragment id="pe003" type="portlet" name="CustomerList">
        <property layout="TwoColumns" name="row" value="1" />
        <property layout="TwoColumns" name="column" value="0" />      
      </fragment>
      <fragment id="pe004" type="portlet" name="CustomerInfo">
        <property layout="TwoColumns" name="row" value="1" />
        <property layout="TwoColumns" name="column" value="1" />      
      </fragment>
    </fragment>
  </page>
  
  
  

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

Reply via email to