portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From raph...@apache.org
Subject cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/om/profile BasePSMLDocument.java PSMLDocument.java BaseProfile.java Profile.java
Date Mon, 04 Jun 2001 17:43:16 GMT
raphael     01/06/04 10:43:16

  Modified:    src/java/org/apache/jetspeed/om/profile BaseProfile.java
                        Profile.java
  Added:       src/java/org/apache/jetspeed/om/profile
                        BasePSMLDocument.java PSMLDocument.java
  Log:
  add a PSML Document to the Profile object model (they may be
  merged in a future evolution)
  
  remove the RunData parameter from some methods as it's not needed
  anymore
  
  Revision  Changes    Path
  1.5       +35 -17    jakarta-jetspeed/src/java/org/apache/jetspeed/om/profile/BaseProfile.java
  
  Index: BaseProfile.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/om/profile/BaseProfile.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- BaseProfile.java	2001/03/07 06:44:40	1.4
  +++ BaseProfile.java	2001/06/04 17:43:11	1.5
  @@ -58,27 +58,27 @@
   import org.apache.turbine.services.BaseInitable;
   
   import org.apache.jetspeed.portal.PortletSet;
  -import org.apache.jetspeed.portal.factory.PortletSetFactory;
  +import org.apache.jetspeed.services.PortalToolkit;
  +import org.apache.jetspeed.services.PsmlManager;
   
  -
  -
   /**
   Provides base functionality within a Registry.
   
   @author <a href="mailto:david@bluesunrise.com">David Sean Taylor</a>
  -@version $Id: BaseProfile.java,v 1.4 2001/03/07 06:44:40 taylor Exp $
  +@version $Id: BaseProfile.java,v 1.5 2001/06/04 17:43:11 raphael Exp $
   */
   
  -public class BaseProfile extends BaseInitable implements Profile {
  +public class BaseProfile extends BaseInitable implements Profile
  +{
   
       private String url;
   
       private String page = null;
       private String group = null;
       private String role = null;
  +    private PSMLDocument doc = null;
  +    private PortletSet set = null;
   
  -    PortletSetFactory factory = null;
  -
       public BaseProfile()
       {}
   
  @@ -92,7 +92,8 @@
           return this.url;
       }
   
  -    public void init() {
  +    public void init()
  +    {
           setInit(true);
       }
   
  @@ -106,24 +107,37 @@
   
          @return The root portlet set for this profile.
        */
  -    public PortletSet getRootSet(RunData rundata)
  +    public PortletSet getRootSet()
       {
  -        return this.getFactory().getPortletSet( rundata );
  +        synchronized (this)
  +        {
  +            if (this.set == null)
  +            {
  +                this.set = PortalToolkit.getSet( getDocument().getPortlets() );
  +            }
  +        }
  +        
  +        return this.set;
       }
   
       /**
  -       Gets the PortletSetFactory for this profile
  +       Gets the root set of portlets for this profile object.
   
  -       @return The portlet set factory for this profile.
  +       @return The root portlet set for this profile.
        */
  -    public PortletSetFactory getFactory()
  +    public PSMLDocument getDocument()
       {
  -        if (null == factory)
  -            factory = PortletSetFactory.getInstance( url );
  -        return factory;
  +        synchronized (this)
  +        {
  +            if (this.doc == null)
  +            {
  +                this.doc = PsmlManager.getDocument(getURL());
  +            }
  +        }
  +        
  +        return this.doc;
       }
   
  -
       /**
          stores the resource by merging and rewriting the psml file
   
  @@ -131,6 +145,10 @@
       */
       public void store() throws ProfileException
       {
  +        if (doc!=null)
  +        {
  +            PsmlManager.saveDocument(doc);
  +        }
       }
   
       public void setGroup( String group )
  
  
  
  1.5       +7 -7      jakarta-jetspeed/src/java/org/apache/jetspeed/om/profile/Profile.java
  
  Index: Profile.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/om/profile/Profile.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Profile.java	2001/03/07 06:44:41	1.4
  +++ Profile.java	2001/06/04 17:43:13	1.5
  @@ -56,7 +56,6 @@
   
   import org.apache.turbine.services.Initable;
   import org.apache.jetspeed.portal.PortletSet;
  -import org.apache.jetspeed.portal.factory.PortletSetFactory;
   import java.util.Enumeration;
   import org.apache.turbine.util.RunData;
   
  @@ -64,23 +63,24 @@
   Represents a profile, the interface to a PSML resource.
   
   @author <a href="mailto:david@bluesunrise.com">David Sean Taylor</a>
  -@version $Id: Profile.java,v 1.4 2001/03/07 06:44:41 taylor Exp $
  +@version $Id: Profile.java,v 1.5 2001/06/04 17:43:13 raphael Exp $
   */
   
  -public interface Profile extends Initable {
  +public interface Profile extends Initable
  +{
       /**
          Gets the root set of portlets for this profile object.
   
          @return The root portlet set for this profile.
        */
  -    public PortletSet getRootSet(RunData rundata);
  +    public PortletSet getRootSet();
   
       /**
  -       Gets the PortletSetFactory for this profile
  +       Gets the psml document attached to this profile
   
  -       @return The portlet set factory for this profile.
  +       @return The PSML document for this profile.
        */
  -    public PortletSetFactory getFactory();
  +    public PSMLDocument getDocument();
   
       /**
          Gets the URL for this profile, a fully qualified local path and resource name
  
  
  
  1.1                  jakarta-jetspeed/src/java/org/apache/jetspeed/om/profile/BasePSMLDocument.java
  
  Index: BasePSMLDocument.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2001 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" 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.om.profile;
  
  import org.apache.jetspeed.xml.api.portletmarkup.Portlets;
  import org.apache.jetspeed.xml.api.portletmarkup.Entry;
  import java.util.Enumeration;
  
  /**
   * This class represents a loaded PSML document in memory, providing
   * all facilities for finding and updating specific parts of the 
   * document.
   *
   * @author <a href="mailto:raphael@apache.org">RaphaŽl Luta</a>
   * @version $Id: BasePSMLDocument.java,v 1.1 2001/06/04 17:43:11 raphael Exp $
   */
  public class BasePSMLDocument implements PSMLDocument
  {
      /**
       * The name of this PSML document, will be typically the URL of the file
       * for file-based implementations
       */
      private String name = null;
  
      /**
       * The PortletSet descriptions that make up this document
       */
      private Portlets portlets = null;
  
      /**
       * Construct a new empty PSMLDocument
       */
      public BasePSMLDocument()
      {
          // empty constructor
      }
  
      /**
       * Construct a new named PSMLDocument associated with the specified
       * PSML portlet set description
       *
       * @param name the name of this document
       * @param portlets the PSML memory structure
       */
      public BasePSMLDocument( String name, Portlets portlets )
      {
          this.portlets = portlets;
      }
  
      /**
       * Return the name of this document
       */
      public final String getName()
      {
          return this.name;
      }
          
      /**
       * Sets a new name for this document
       * 
       * @param name the new document name
       */
      public final void setName(String name)
      {
          this.name = name;
      }
  
      /**
       * Return ths portlet set PSML description of this document
       *
       * @return a PSML object model hierarchy, or null if none is 
       * defined for this document
       */
      public final Portlets getPortlets()
      {
          return this.portlets;
      }
  
      /**
       * Sets a new PSML object model for this document
       * 
       * @param portlets the PSML object model
       */
      public final void setPortlets(Portlets portlets)
      {
          this.portlets = portlets;
      }
  
      /** Returns the first entry in the current PSML resource corresponding 
       *  to the given portlet name
       * 
       *  @param name the portlet name to seek
       *  @return the found entry description or null
       */
      public Entry getEntry(String name)
      {
          return getEntry(this.portlets, name);
      }
  
      /** Returns the first portlets element in the current PSML resource corresponding 
       *  to the given name
       * 
       *  @param name the portlets name to seek
       *  @return the found portlets description or null
       */
      public Portlets getPortlets(String name)
      {        
          Portlets p = getPortlets(this.portlets, name);
          
          if (p == null)
          {
              //maybe name is a position...
              try
              {
                  p = getPortlets(Integer.parseInt(name));
              }
              catch (NumberFormatException e)
              {
                  // this will happen if name is not parseable, ignore
              }
          }
          
          return p;
      }
  
      /** Returns the first portlets element in the current PSML resource 
       *  found at the specified position. The position is computed using
       *  a left-most tree traversal algorithm of the existing portlets (thus
       *  not counting other entry objects)
       * 
       *  @param position the sought position
       *  @return the found portlets object or null if we did not find such an
       *  object
       */
      public Portlets getPortlets(int position)
      {
          return getPortlets(this.portlets, position, 0);
      }
  
      /** Returns the first entry in the specified PSML resource corresponding 
       *  to the given portlet name
       * 
       *  @param portlets the PSML description to look into
       *  @param name the portlet name to seek
       *  @return the found entry description or null
       */
      public static Entry getEntry(Portlets portlets, String name)
      {
          Entry entry = null;
  
          for (Enumeration e1 = portlets.enumerateEntry (); e1.hasMoreElements (); )
          {
              entry = (Entry) e1.nextElement ();
              if (entry.getParent().equals (name))
                   return (entry);
          }
  
          entry = null;
  
          for (Enumeration e2 = portlets.enumeratePortlets (); e2.hasMoreElements (); )
          {
              Portlets p = (Portlets) e2.nextElement ();
  
              entry = getEntry(p, name);
  
              if (entry != null)
                   break;
          }
  
          return (entry);
      }
  
      /** Returns the first portlets element in the specified PSML resource corresponding

       *  to the given name
       * 
       *  @param portlets the PSML description to look into
       *  @param name the portlets name to seek
       *  @return the found portlets description or null
       */
      public static Portlets getPortlets(Portlets portlets, String name)
      {
          Portlets entry = portlets;
          
          if (entry.getName().equals(name))
          {
              return entry;
          }
  
          entry = null;
          
          for (Enumeration e2 = portlets.enumeratePortlets (); e2.hasMoreElements (); )
          {
              Portlets p = (Portlets) e2.nextElement ();
  
              entry = getPortlets(p, name);
  
              if (entry != null) break;
          }
  
          return (entry);
      }
  
      /** Returns the first portlets element in the specified PSML resource 
       *  in the given position
       * 
       *  @param portlets the PSML description to look into
       *  @param position the position to look for
       *  @param count the numbering for the portlets passed as parameter
       *  @return the found portlets description or null
       */
      public static Portlets getPortlets(Portlets portlets, int position, int count)
      {
          // sanity check, we never look after the sought position
          if (position < count)
          {
              return null;
          }
          
          // the base portlets is the one we're looking for...
          if (position == count)
          {
              return portlets;
          }
  
          // we need to recurse in the children
          Portlets result = null;
          
          for (Enumeration e2 = portlets.enumeratePortlets (); e2.hasMoreElements (); )
          {
              Portlets p = (Portlets) e2.nextElement ();
              count++;
              result = getPortlets(p, position, count);
  
              if (result != null) break;
          }
  
          return result;
      }
  
  }
  
  
  
  
  1.1                  jakarta-jetspeed/src/java/org/apache/jetspeed/om/profile/PSMLDocument.java
  
  Index: PSMLDocument.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2001 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" 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.om.profile;
  
  import org.apache.jetspeed.xml.api.portletmarkup.Portlets;
  import org.apache.jetspeed.xml.api.portletmarkup.Entry;
  
  /**
   * This interface represents a loaded PSML document in memory, providing
   * all facilities for finding and updating specific parts of the 
   * document.
   *
   * @author <a href="mailto:raphael@apache.org">RaphaŽl Luta</a>
   * @version $Id: PSMLDocument.java,v 1.1 2001/06/04 17:43:13 raphael Exp $
   */
  public interface PSMLDocument
  {
      /**
       * Return the name of this document
       */
      public String getName();
          
      /**
       * Sets a new name for this document
       * 
       * @param name the new document name
       */
      public void setName(String name);
  
      /**
       * Return ths portlet set PSML description of this document
       *
       * @return a PSML object model hierarchy, or null if none is 
       * defined for this document
       */
      public Portlets getPortlets();
  
      /**
       * Sets a new PSML object model for this document
       * 
       * @param portlets the PSML object model
       */
      public void setPortlets(Portlets portlets);
  
      /** Returns the first entry in the current PSML resource corresponding 
       *  to the given portlet name
       * 
       *  @param name the portlet name to seek
       *  @return the found entry description or null
       */
      public Entry getEntry(String name);
  
      /** Returns the first portlets element in the current PSML resource corresponding 
       *  to the given name
       * 
       *  @param name the portlets name to seek
       *  @return the found portlets description or null
       */
      public Portlets getPortlets(String name);
  
      /** Returns the first portlets element in the current PSML resource 
       *  found at the specified position. The position is computed using
       *  a left-most tree traversal algorithm of the existing portlets (thus
       *  not counting other entry objects)
       * 
       *  @param position the sought position
       *  @return the found portlets object or null if we did not find such an
       *  object
       */
      public Portlets getPortlets(int position);
  
  }
  
  
  
  

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


Mime
View raw message