cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject cvs commit: cocoon-2.1/src/blocks/portal/samples sitemap.xmap
Date Tue, 27 May 2003 11:54:18 GMT
cziegeler    2003/05/27 04:54:18

  Modified:    src/blocks/portal/java/org/apache/cocoon/portal/transformation
                        CopletTransformer.java EventLinkTransformer.java
                        AbstractCopletTransformer.java
               src/blocks/portal/java/org/apache/cocoon/portal/profile/impl
                        MapSourceAdapter.java
               src/blocks/portal/java/org/apache/cocoon/portal/components/modules/input
                        CopletModule.java
               src/blocks/portal/conf portal.xconf
               src/blocks/portal/samples sitemap.xmap
  Added:       src/blocks/portal/java/org/apache/cocoon/portal/profile/impl
                        StaticProfileManager.java
                        AuthenticationProfileManager.java
  Removed:     src/blocks/portal/java/org/apache/cocoon/portal/profile/impl
                        SimpleProfileManager.java
  Log:
  Refactoring profile manager
  Fixing jdk 1.3 issue
  Getting demo working again
  
  Revision  Changes    Path
  1.3       +14 -1     cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/transformation/CopletTransformer.java
  
  Index: CopletTransformer.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/transformation/CopletTransformer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CopletTransformer.java	26 May 2003 12:49:13 -0000	1.2
  +++ CopletTransformer.java	27 May 2003 11:54:17 -0000	1.3
  @@ -60,6 +60,19 @@
   
   /**
    * Includes coplet instance data by using JXPath expressions.
  + * The transformer searches for tags <coplet:coplet xmlns:coplet="http://apache.org/cocoon/portal/coplet/1.0">.
  + * They must have an attribute "select" that contains a valid JXPath expression applying to the coplet instance data.<br><br>
  + *
  + * Example:<br><br>
  + * 
  + * <pre>&lt;maxpageable xmlns:coplet="http://apache.org/cocoon/portal/coplet/1.0"&gt;
  + * 	&lt;coplet:coplet select="copletData.maxpageable"/&gt;
  + * &lt;/maxpageable&gt;<br></pre>
  + * 
  + * The transformer will insert the boolean value specifying whether the coplet is 
  + * maxpageable or not.<br> 
  + * Please see also the documentation of superclass AbstractCopletTransformer for how
  + * the coplet instance data are acquired.
    *
    * @author <a href="mailto:bluetkemeier@s-und-n.de">Björn Lütkemeier</a>
    * @version CVS $Id$
  
  
  
  1.4       +19 -2     cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/transformation/EventLinkTransformer.java
  
  Index: EventLinkTransformer.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/transformation/EventLinkTransformer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- EventLinkTransformer.java	26 May 2003 13:18:20 -0000	1.3
  +++ EventLinkTransformer.java	27 May 2003 11:54:17 -0000	1.4
  @@ -64,8 +64,25 @@
   /**
    * This transformer searches for event descriptions in the XML. 
    * For each one an event is created and the event link is inserted into the XML 
  - * instead of the description.
  + * instead of the description.<br><br>
    *  
  + * Example:<br><br>
  + * 
  + * <pre>&lt;root xmlns:event="http://apache.org/cocoon/portal/eventlink/1.0"&gt;
  + * 	&lt;event:event attribute="href"&gt;
  + * 		&lt;a href="http://eventlinkexample"/&gt;
  + * 	&lt;/event:event&gt;
  + * 	&lt;event:event element="uri"&gt;
  + * 		&lt;link>&lt;uri&gt;http://eventlinkexample&lt;/uri&gt;&lt;/link&gt;
  + * 	&lt;/event:event&gt;
  + * &lt;/root&gt;<br></pre>
  + *
  + * The transformer will create two CopletLinkEvents and insert corresponding links 
  + * to them to the XML instead of "http://eventlinkexample". If such a link is pressed 
  + * the corresponding CopletLinkEvent is sent to the Subscribers to be handled.<br>
  + * Please see also the documentation of superclass AbstractCopletTransformer for how
  + * the coplet instance data are acquired.
  + *   
    * @author <a href="mailto:bluetkemeier@s-und-n.de">Björn Lütkemeier</a>
    * 
    * @version CVS $Id$
  
  
  
  1.2       +13 -2     cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/transformation/AbstractCopletTransformer.java
  
  Index: AbstractCopletTransformer.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/transformation/AbstractCopletTransformer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractCopletTransformer.java	26 May 2003 12:49:13 -0000	1.1
  +++ AbstractCopletTransformer.java	27 May 2003 11:54:17 -0000	1.2
  @@ -63,7 +63,18 @@
   import org.xml.sax.SAXException;
   
   /**
  - * Abstract transformer implementation
  + * Abstract transformer implementation that provides a method getCopletInstanceData().
  + * There are two possibilities how the transformer obtains the information required for 
  + * getting the coplet instance data:<br><br>
  + * 1) If it is used within a coplet pipeline and this pipeline is called using the "cocoon:" protocol,
  + * all required information are passed automatically.<br>
  + * 2) Otherwise the portal name and the coplet id must be passed to the transformer 
  + * as paremeters in the following way:
  + *
  + * <pre>&lt;map:transform type="coplet"&gt;
  + * 	&lt;map:parameter name="portalName" type="exampleportal"/&gt;
  + * 	&lt;map:parameter name="copletId" type="examplecoplet"/&gt;
  + * &lt;/map:transform&gt;</pre>
    *
    * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
    * @version CVS $Id$
  
  
  
  1.5       +68 -131   cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/MapSourceAdapter.java
  
  Index: MapSourceAdapter.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/MapSourceAdapter.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- MapSourceAdapter.java	27 May 2003 07:38:33 -0000	1.4
  +++ MapSourceAdapter.java	27 May 2003 11:54:18 -0000	1.5
  @@ -59,7 +59,6 @@
   import org.apache.avalon.framework.component.ComponentException;
   import org.apache.avalon.framework.component.ComponentManager;
   import org.apache.avalon.framework.component.Composable;
  -import org.apache.avalon.framework.configuration.Configurable;
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.ConfigurationException;
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
  @@ -71,12 +70,12 @@
   import org.apache.excalibur.source.ModifiableSource;
   import org.apache.excalibur.source.Source;
   import org.apache.excalibur.source.SourceResolver;
  +import org.apache.excalibur.source.SourceUtil;
   import org.apache.excalibur.source.SourceValidity;
   import org.apache.excalibur.xml.sax.SAXParser;
   import org.w3c.dom.Element;
   
   /**
  - *
    * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
    * @author <a href="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
    * @author <a href="mailto:bluetkemeier@s-und-n.de">Björn Lütkemeier</a>
  @@ -85,56 +84,69 @@
    */
   public class MapSourceAdapter
       extends AbstractLogEnabled
  -    implements Component, Composable, Configurable, ProfileLS, ThreadSafe {
  +    implements Component, Composable, ProfileLS, ThreadSafe {
   
       public static final String ROLE = MapSourceAdapter.class.getName();
  -    private ComponentManager manager;
  +    /** The component manager */
  +    protected ComponentManager manager;
   
  +
  +    protected String getURI(Map mapKey, Map map, String postFix) 
  +    throws Exception{
  +        Object type = map.get("type");
  +        String profile = (String)map.get("profile");
  +        Configuration config = ((Configuration)mapKey.get("config")).getChild("profiles");
  +        String uri = null;
  +        try {
  +            if (type == null) {
  +                uri = config.getChild(profile+"-"+postFix).getAttribute("uri");
  +            } else if (type.equals("global")) {
  +                uri = config.getChild(profile+"-global-"+postFix).getAttribute("uri");
  +            } else if (type.equals("role")) {
  +                uri = config.getChild(profile+"-role-"+postFix).getAttribute("uri");
  +            } else if (type.equals("user")) {
  +                uri = config.getChild(profile+"-user-"+postFix).getAttribute("uri");
  +            }
  +        } catch (Exception e) {
  +            throw new ConfigurationException("Error reading URI from configuration.", e);
  +        }
  +        return uri;
  +    }
  +    
  +    protected StringBuffer getCompleteURI(String baseURI, Map keyMap, Map map) {
  +        StringBuffer buffer = new StringBuffer(baseURI);
  +
  +        if (baseURI.indexOf("?") == -1) {
  +            buffer.append("?portal=");
  +        } else {
  +            buffer.append("&portal=");
  +        }
  +        buffer.append(map.get("portalname"));
  +
  +        if ( keyMap.containsKey("role")) {
  +            buffer.append("&role=");
  +            buffer.append(keyMap.get("role"));
  +        }
  +        
  +        if ( keyMap.containsKey("user")) {
  +            buffer.append("&user=");
  +            buffer.append(keyMap.get("user"));
  +        }
  +        return buffer;
  +    }
  +    
       /* (non-Javadoc)
        * @see org.apache.cocoon.portal.profile.ProfileLS#loadProfile(java.lang.Object)
        */
       public Object loadProfile(Object key, Map map) throws Exception {
  -		Map mapKey = (Map) key;
  -		StringBuffer buffer = new StringBuffer();
  -
  -		String profile = (String)map.get("profile");
  -
  -		Configuration config = ((Configuration)mapKey.get("config")).getChild("profiles");
  -		Object type = map.get("type");
  -		String uri = null, configKey = null;
  -		try {
  -			if (type == null) {
  -				configKey = profile+"-load";
  -				uri = config.getChild(configKey).getAttribute("uri");
  -			} else if (type.equals("global")) {
  -				configKey = profile+"-global-load";
  -				uri = config.getChild(configKey).getAttribute("uri");
  -			} else if (type.equals("role")) {
  -				configKey = profile+"-role-load";
  -				uri = config.getChild(configKey).getAttribute("uri");
  -			} else if (type.equals("user")) {
  -				configKey = profile+"-user-load";
  -				uri = config.getChild(configKey).getAttribute("uri");
  -			}
  -		} catch (Exception e) {
  -			throw new ConfigurationException("Error reading URI from configuration "+configKey, e);
  -		}
  -		buffer.append(uri);
  -
  -		if (uri.indexOf("?") == -1) {
  -			buffer.append("?portal=");
  -		} else {
  -			buffer.append("&portal=");
  -		}
  -		buffer.append(map.get("portalname"));
  -
  -		buffer.append("&role=");
  -		buffer.append(mapKey.get("role"));
  +		final Map keyMap = (Map) key;
           
  -		buffer.append("&user=");
  -		buffer.append(mapKey.get("user"));
  +        final String uri = this.getURI( keyMap, map , "load");
  +        final String profile = (String)map.get("profile");
   
  -		String sourceURI = buffer.toString();
  +		final StringBuffer buffer = this.getCompleteURI(uri, keyMap, map );
  +
  +		final String sourceURI = buffer.toString();
   		Source source = null;
   		CastorSourceConverter converter = null;
           SourceResolver resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
  @@ -155,32 +167,11 @@
        * @see org.apache.cocoon.portal.profile.ProfileLS#saveProfile(java.lang.Object, java.lang.Object)
        */
       public void saveProfile(Object key, Map map, Object profile) throws Exception {
  -		Map mapKey = (Map) key;
  -
  -		String profileName = (String)map.get("profile");
  -
  -		Configuration config = ((Configuration)mapKey.get("config")).getChild("profiles");
  -		Object type = map.get("type");
  -		String uri = null;
  -        String configKey = null;
  -		try {
  -			if (type == null) {
  -				configKey = profileName+"-save";
  -				uri = config.getChild(configKey).getAttribute("uri");
  -			} else if (type.equals("global")) {
  -				configKey = profileName+"-global-save";
  -				uri = config.getChild(configKey).getAttribute("uri");
  -			} else if (type.equals("role")) {
  -				configKey = profileName+"-role-save";
  -				uri = config.getChild(configKey).getAttribute("uri");
  -			} else if (type.equals("user")) {
  -				configKey = profileName+"-user-save";
  -				uri = config.getChild(configKey).getAttribute("uri");
  -			}
  -		} catch (Exception e) {
  -			throw new ConfigurationException("Error reading URI from configuration "+configKey, e);
  -		}
  +        final Map keyMap = (Map) key;
           
  +        final String uri = this.getURI( keyMap, map , "save");
  +        final String profileName = (String)map.get("profile");
  +
           // first test: modifiable source?
           SourceResolver resolver = null;
           CastorSourceConverter converter = null;
  @@ -203,21 +194,7 @@
               resolver = null;
           }
           
  -        StringBuffer buffer = new StringBuffer();
  -		buffer.append(uri);
  -
  -		if (uri.indexOf("?") == -1) {
  -			buffer.append("?portal=");
  -		} else {
  -			buffer.append("&portal=");
  -		}
  -		buffer.append(map.get("portalname"));
  -
  -		buffer.append("&role=");
  -		buffer.append(mapKey.get("role"));
  -        
  -		buffer.append("&user=");
  -		buffer.append(mapKey.get("user"));
  +        final StringBuffer buffer = this.getCompleteURI(uri, keyMap, map );
   
   		SAXParser parser = null;
   		try {
  @@ -229,7 +206,7 @@
               converter.storeObject(writer, profileName, profile);
   
               buffer.append("&content=");
  -            buffer.append(writer.toString());
  +            buffer.append(SourceUtil.encode(writer.toString()));
   
               source = resolver.resolveURI(buffer.toString());
   
  @@ -254,47 +231,15 @@
   		SourceResolver resolver = null;
   		Source source = null;
   		try {
  -			Map mapKey = (Map) key;
  -			StringBuffer buffer = new StringBuffer();
  +            final Map keyMap = (Map) key;
  +        
  +            final String uri = this.getURI( keyMap, map, "load" );
  +            final String profile = (String)map.get("profile");
   
  -			String profile = (String)map.get("profile");
  +            final StringBuffer buffer = this.getCompleteURI(uri, keyMap, map );
   
  -			Configuration config = ((Configuration)mapKey.get("config")).getChild("profiles");
  -			Object type = map.get("type");
  -			String uri = null, configKey = null;
  -			try {
  -				if (type == null) {
  -					configKey = profile+"-load";
  -					uri = config.getChild(configKey).getAttribute("uri");
  -				} else if (type.equals("global")) {
  -					configKey = profile+"-global-load";
  -					uri = config.getChild(configKey).getAttribute("uri");
  -				} else if (type.equals("role")) {
  -					configKey = profile+"-role-load";
  -					uri = config.getChild(configKey).getAttribute("uri");
  -				} else if (type.equals("user")) {
  -					configKey = profile+"-user-load";
  -					uri = config.getChild(configKey).getAttribute("uri");
  -				}
  -			} catch (Exception e) {
  -				throw new ConfigurationException("Error reading URI from configuration "+configKey, e);
  -			}
  -			buffer.append(uri);
  -
  -			if (uri.indexOf("?") == -1) {
  -				buffer.append("?portal=");
  -			} else {
  -				buffer.append("&portal=");
  -			}
  -			buffer.append(map.get("portalname"));
  +            final String sourceURI = buffer.toString();
   
  -			buffer.append("&role=");
  -			buffer.append(mapKey.get("role"));
  -        
  -			buffer.append("&user=");
  -			buffer.append(mapKey.get("user"));
  -
  -			String sourceURI = buffer.toString();
   			resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
   			source = resolver.resolveURI(sourceURI);
   			return source.getValidity();
  @@ -306,14 +251,6 @@
   				resolver.release(source);
   			manager.release(resolver);
   		}
  -    }
  -
  -    /* (non-Javadoc)
  -     * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
  -     */
  -    public void configure(Configuration config) throws ConfigurationException {
  -        // TODO Auto-generated method stub
  -
       }
   
       /* (non-Javadoc)
  
  
  
  1.1                  cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/StaticProfileManager.java
  
  Index: StaticProfileManager.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, 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 Cocoon" and  "Apache Software Foundation" 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", 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 (INCLU-
   DING, 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 and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.portal.profile.impl;
  
  import java.io.PrintWriter;
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Map;
  
  import org.apache.avalon.framework.CascadingRuntimeException;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  import org.apache.avalon.framework.thread.ThreadSafe;
  import org.apache.cocoon.portal.PortalService;
  import org.apache.cocoon.portal.coplet.CopletBaseData;
  import org.apache.cocoon.portal.coplet.CopletData;
  import org.apache.cocoon.portal.coplet.CopletInstanceData;
  import org.apache.cocoon.portal.layout.AbstractLayout;
  import org.apache.cocoon.portal.layout.CompositeLayout;
  import org.apache.cocoon.portal.layout.Item;
  import org.apache.cocoon.portal.layout.Layout;
  import org.apache.cocoon.portal.layout.impl.CopletLayout;
  import org.apache.cocoon.portal.profile.ProfileManager;
  import org.apache.excalibur.source.SourceValidity;
  import org.exolab.castor.mapping.Mapping;
  import org.exolab.castor.xml.Marshaller;
  
  /**
   *
   * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
   * @author <a href="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
   * 
   * @version CVS $Id: StaticProfileManager.java,v 1.1 2003/05/27 11:54:18 cziegeler Exp $
   */
  public class StaticProfileManager 
      extends AbstractLogEnabled 
      implements Composable, ProfileManager, ThreadSafe {
  
      protected ComponentManager componentManager;
  
      private Mapping layoutMapping;
  
      private Map layoutStati = new HashMap(100);
      
      /**
       * @see org.apache.avalon.framework.component.Composable#compose(ComponentManager)
       */
      public void compose(ComponentManager componentManager) throws ComponentException {
          this.componentManager = componentManager;
      }
  
      /**
       * @see org.apache.cocoon.portal.profile.ProfileManager#getPortalLayout(Object)
       */
      public Layout getPortalLayout(String key) {
          PortalService service = null;
          MapSourceAdapter adapter = null;
          try {
              service = (PortalService) this.componentManager.lookup(PortalService.ROLE);
              
              if ( null == key ) {
                  Layout l = (Layout) service.getTemporaryAttribute("DEFAULT_LAYOUT");
                  if ( null != l) {
                      return l;
                  }
              }
  
              Object[] objects = (Object[]) service.getAttribute(StaticProfileManager.class.getName() + "/Layout");
  
              Map map = new HashMap();
              map.put("profile", "layout");
              map.put("portalname", service.getPortalName());
  
              int valid = SourceValidity.INVALID;
              SourceValidity sourceValidity = null;
              if (objects != null) {
                  sourceValidity = (SourceValidity) objects[1];
                  valid = sourceValidity.isValid();
                  if (valid == SourceValidity.VALID)
                      return (Layout) objects[0];
              }
              adapter = (MapSourceAdapter) this.componentManager.lookup(MapSourceAdapter.ROLE);
              Map param = new HashMap();
              param.put("portalname", service.getPortalName());
              SourceValidity newValidity = adapter.getValidity(param, map);
              if (valid == SourceValidity.UNKNWON) {
                  if (sourceValidity.isValid(newValidity) == SourceValidity.VALID)
                      return (Layout) objects[0];
              }
              Layout layout = (Layout) adapter.loadProfile(param, map);
              if (newValidity != null) {
                  objects = new Object[] { layout, newValidity };
                  service.setAttribute(StaticProfileManager.class.getName() + "/Layout", objects);
              }
              // resolve parents
              resolveParents(layout, null);
              return layout;
          } catch (Exception ce) {
              // TODO
              throw new CascadingRuntimeException("Arg", ce);
          } finally {
              this.componentManager.release(service);
              this.componentManager.release(adapter);
          }
      }
  
      public CopletInstanceData getCopletInstanceData(String copletID) {
          PortalService service = null;
          String key = null;
          try {
              service = (PortalService) this.componentManager.lookup(PortalService.ROLE);
              key = service.getPortalName() + ":" + copletID;
  
              Map coplets = (Map) service.getAttribute(StaticProfileManager.class.getName() + "/Coplets");
              if (null == coplets) {
                  coplets = new HashMap();
                  service.setAttribute(StaticProfileManager.class.getName() + "/Coplets", coplets);
              }
  
              CopletInstanceData cid = (CopletInstanceData) coplets.get(key);
              if (null == cid) {
                  CopletBaseData base = new CopletBaseData();
                  base.setId("URICoplet");
                  base.setCopletAdapterName("uri");
                  cid = new CopletInstanceData();
                  CopletData cd = new CopletData();
                  cd.setName(copletID);
                  cid.setCopletData(cd);
                  cid.setId(copletID); // TODO generate unique copletID
                  cid.getCopletData().setCopletBaseData(base);
                  cid.getCopletData().setAttribute("uri", copletID);
                  cid.getCopletData().setTitle(copletID);
                  coplets.put(key, cid);
  
                  Marshaller marshaller;
                  try {
                      marshaller = new Marshaller(new PrintWriter(System.out));
                      marshaller.setSuppressXSIType(true);
                      marshaller.setMapping(layoutMapping);
                      marshaller.marshal(cid);
                  } catch (Exception e) {
                      //e.printStackTrace();
                  }
              }
              return cid;
          } catch (ComponentException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
              throw new CascadingRuntimeException("CE", e);
          } finally {
              this.componentManager.release(service);
          }
      }
  
      public List getCopletInstanceData(CopletData data) {
          List coplets = new ArrayList();
          PortalService service = null;
          String attribute = null;
          try {
              service = (PortalService) this.componentManager.lookup(PortalService.ROLE);
  
              Map allCoplets = (Map) service.getAttribute(StaticProfileManager.class.getName() + "/Coplets");
              if (null != allCoplets) {
  
                  Iterator iter = allCoplets.values().iterator();
                  while ( iter.hasNext() ) {
                      CopletInstanceData current = (CopletInstanceData)iter.next();
                      if ( current.getCopletData().equals(data) ) {
                          coplets.add( current );
                      }
                  }
              }
              return coplets;
          } catch (ComponentException e) {
              throw new CascadingRuntimeException("Unable to lookup portal service.", e);
          } finally {
              this.componentManager.release(service);
          }
      }
  
      public void setDefaultLayout(Layout object) {
          PortalService service = null;
          try {
              service = (PortalService) this.componentManager.lookup(PortalService.ROLE);
              service.setTemporaryAttribute("DEFAULT_LAYOUT", object);
          } catch (ComponentException e) {
              throw new CascadingRuntimeException("Unable to lookup service manager.", e);
          } finally {
              this.componentManager.release(service);
          }
      }
  
      private void resolveParents(final Layout layout, final Item item) {
          String id = layout.getId();
          if ( id == null ) {
              id = Integer.toString(layout.hashCode());
              ((AbstractLayout)layout).setId(id);
          }
          if (layout instanceof CompositeLayout) {
  
              final CompositeLayout compositeLayout = (CompositeLayout) layout;
  
              for (int j = 0; j < compositeLayout.getSize(); j++) {
                  final Item layoutItem = (Item) compositeLayout.getItem(j);
                  layoutItem.setParent(compositeLayout);
                  this.resolveParents(layoutItem.getLayout(), layoutItem);
              }
          }
          if (layout instanceof CopletLayout) {
              final CopletLayout cl = (CopletLayout)layout;
              final CopletInstanceData cid = this.getCopletInstanceData(cl.getId());
              cl.setCopletInstanceData(cid);
          }
          layout.setParent(item);
      }
  
      public void register(CopletInstanceData coplet) {
      }
      
      public void unregister(CopletInstanceData coplet) {
      }
  
      public void register(Layout layout) {
      }
      
      public void unregister(Layout layout) {
      }
  
      public void saveUserProfiles() {
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/AuthenticationProfileManager.java
  
  Index: AuthenticationProfileManager.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, 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 Cocoon" and  "Apache Software Foundation" 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", 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 (INCLU-
   DING, 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 and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.portal.profile.impl;
  
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Map;
  
  import org.apache.avalon.framework.CascadingRuntimeException;
  import org.apache.avalon.framework.CascadingThrowable;
  import org.apache.avalon.framework.component.Component;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  import org.apache.avalon.framework.thread.ThreadSafe;
  import org.apache.cocoon.ProcessingException;
  import org.apache.cocoon.portal.PortalService;
  import org.apache.cocoon.portal.coplet.CopletData;
  import org.apache.cocoon.portal.coplet.CopletFactory;
  import org.apache.cocoon.portal.coplet.CopletInstanceData;
  import org.apache.cocoon.portal.layout.CompositeLayout;
  import org.apache.cocoon.portal.layout.Item;
  import org.apache.cocoon.portal.layout.Layout;
  import org.apache.cocoon.portal.layout.LayoutFactory;
  import org.apache.cocoon.portal.profile.ProfileManager;
  import org.apache.cocoon.portal.util.DeltaApplicableReferencesAdjustable;
  import org.apache.cocoon.webapps.authentication.AuthenticationManager;
  import org.apache.cocoon.webapps.authentication.user.RequestState;
  import org.apache.cocoon.webapps.authentication.user.UserHandler;
  import org.apache.excalibur.source.SourceNotFoundException;
  import org.apache.excalibur.source.SourceValidity;
  import org.exolab.castor.mapping.Mapping;
  import org.xml.sax.SAXException;
  
  /**
   * The profile manager using the authentication framework
   * 
   * FIXME - create abstract base class
   * 
   * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
   * @author <a href="mailto:bluetkemeier@s-und-n.de">Björn Lütkemeier</a>
   * 
   * @version CVS $Id: AuthenticationProfileManager.java,v 1.1 2003/05/27 11:54:18 cziegeler Exp $
   */
  public class AuthenticationProfileManager 
      extends AbstractLogEnabled 
      implements Composable, ProfileManager, ThreadSafe {
  
      protected ComponentManager manager;
  
      private Mapping layoutMapping;
  
      private Map layoutStati = new HashMap(100);
      
      private Map attributes = new HashMap();
      
      private ReadWriteLock lock = new ReadWriteLock();
      
      /**
       * @see org.apache.avalon.framework.component.Composable#compose(ComponentManager)
       */
      public void compose(ComponentManager componentManager) throws ComponentException {
          this.manager = componentManager;
      }
  
      public RequestState getRequestState() {
          AuthenticationManager authManager = null;
          try {
              authManager = (AuthenticationManager)this.manager.lookup(AuthenticationManager.ROLE);
              return authManager.getState();    
          } catch (ComponentException ce) {
              // ignore this here
              return null;
          } finally {
              this.manager.release( (Component)authManager );
          }
      }
      
      /**
       * @see org.apache.cocoon.portal.profile.ProfileManager#getPortalLayout(Object)
       */
      public Layout getPortalLayout(String key) {
          PortalService service = null;
          LayoutFactory factory = null;
          CopletFactory copletFactory = null;
          
          try {
              service = (PortalService) this.manager.lookup(PortalService.ROLE);
              factory = (LayoutFactory) this.manager.lookup(LayoutFactory.ROLE);
              copletFactory = (CopletFactory) this.manager.lookup(CopletFactory.ROLE);
              
              if ( null == key ) {
                  Layout l = (Layout) service.getTemporaryAttribute("DEFAULT_LAYOUT");
                  if ( null != l) {
                      return l;
                  }
              }
              
              String portalPrefix = AuthenticationProfileManager.class.getName()+"/"+service.getPortalName();
              Layout layout = null;
  
              if ( key != null ) {
                  // now search for a layout
                  Map layoutMap = (Map)service.getAttribute("layout-map");
                  if ( layoutMap == null ) {
                      layout = (Layout)service.getAttribute(portalPrefix+"/Layout");
                      if (layout != null) {
                          layoutMap = new HashMap();
                          this.cacheLayouts(layoutMap, layout);
                          service.setAttribute("layout-map", layoutMap);
                      }
                  }
                  if ( layoutMap != null) {
                      layout = (Layout) layoutMap.get( key );
                      if ( layout != null) {
                          return layout;
                      }
                  }
              }
              
  
  			layout = (Layout)service.getAttribute(portalPrefix+"/Layout");
  			if (layout == null) {
  				this.lock.readLock();
  				try {
  					HashMap map = new HashMap();
  					map.put("portalname", service.getPortalName());
  					
  					// TODO Change to KeyManager usage
  					RequestState state = this.getRequestState();
  					UserHandler handler = state.getHandler();
  					HashMap keyMap = new HashMap();
  					keyMap.put("user", handler.getUserId());
  					keyMap.put("role", handler.getContext().getContextInfo().get("role"));
  					keyMap.put("config", state.getApplicationConfiguration().getConfiguration("portal"));
  					
  					// load coplet base data
  					map.put("profile", "copletbasedata");
  					map.put("objectmap", null);
  					Object[] result = this.getProfile(keyMap, map, portalPrefix+"/CopletBaseData", null);
  					CopletBaseDataManager copletBaseDataManager = (CopletBaseDataManager)result[0];
  					
  					// load coplet data
  					map.put("profile", "copletdata");
  					map.put("objectmap", copletBaseDataManager.getCopletBaseData());
  					CopletDataManager copletDataManager = (CopletDataManager)this.getDeltaProfile(keyMap, map, portalPrefix+"/CopletData", service, copletFactory, ((Boolean)result[1]).booleanValue());
  					
  					// load coplet instance data
  					map.put("profile", "copletinstancedata");
  					map.put("objectmap", copletDataManager.getCopletData());
  					CopletInstanceDataManager copletInstanceDataManager = (CopletInstanceDataManager)this.getOrCreateProfile(keyMap, map, portalPrefix+"/CopletInstanceData", service, copletFactory);
  					
  					// load layout
  					map.put("profile", "layout");
  					map.put("objectmap", copletInstanceDataManager.getCopletInstanceData());
  					layout = (Layout)this.getOrCreateProfile(keyMap, map, portalPrefix+"/Layout", service, factory);
  				} finally {
  					this.lock.releaseLocks();
  				}
  			}
  			
              return layout;
          } catch (Exception ce) {
              // TODO
              throw new CascadingRuntimeException("Arg", ce);
          } finally {
              this.manager.release(service);
              this.manager.release((Component)factory);
              this.manager.release((Component)copletFactory);
          }
      }
      
      /**
       * @param layoutMap
       * @param layout
       */
      private void cacheLayouts(Map layoutMap, Layout layout) {
          if ( layout != null ) {
              layoutMap.put( layout.getId(), layout );
              if ( layout instanceof CompositeLayout ) {
                  CompositeLayout cl = (CompositeLayout)layout;
                  Iterator i = cl.getItems().iterator();
                  while ( i.hasNext() ) {
                      Item current = (Item)i.next();
                      this.cacheLayouts( layoutMap, current.getLayout() );
                  }
              }
          }
          
      }
  
      public void saveUserProfiles() {
  		MapSourceAdapter adapter = null;
  		PortalService service = null;
  		try {
  			adapter = (MapSourceAdapter) this.manager.lookup(MapSourceAdapter.ROLE);
  			service = (PortalService) this.manager.lookup(PortalService.ROLE);
              
  			String portalPrefix = AuthenticationProfileManager.class.getName()+"/"+service.getPortalName();
  
  			HashMap map = new HashMap();
  			map.put("portalname", service.getPortalName());
  			map.put("type", "user");
  				
  			// TODO Change to KeyManager usage
              RequestState state = this.getRequestState();
  			UserHandler handler = state.getHandler();
  			HashMap key = new HashMap();
  			key.put("user", handler.getUserId());
  			key.put("role", handler.getContext().getContextInfo().get("role"));
  			key.put("config", state.getApplicationConfiguration().getConfiguration("portal"));
  	
  			// save coplet instance data
  			map.put("profile", "copletinstancedata");
  			Object profile = ((Object[])service.getAttribute(portalPrefix+"/CopletInstanceData"))[0];
  			adapter.saveProfile(key, map, profile);
  
  			// save coplet instance data
  			map.put("profile", "layout");
  			profile = ((Object[])service.getAttribute(portalPrefix+"/Layout"))[0];
  			adapter.saveProfile(key, map, profile);
  		} catch (Exception e) {
  			// TODO
  			throw new CascadingRuntimeException("Arg", e);
  		} finally {
  			this.manager.release(adapter);
  			this.manager.release(service);
  		}
      }
      
  	/**
  	 * Gets a profile.
  	 * @return result[0] is the profile, result[1] is a Boolean, 
  	 * which signals whether the profile has been loaded or reused.
  	 */
  	private Object[] getProfile(Object key, Map map, String location, Object factory)
  	throws Exception {
  		return this.getProfile(key, map, location, factory, false);
  	}
  
  	/**
  	 * Gets a profile and applies possible user and role deltas to it.
  	 */
  	private Object getDeltaProfile(Object key, Map map, String location, PortalService service, Object factory, boolean forcedLoad) 
  	throws Exception {
  		DeltaApplicableReferencesAdjustable result;
  		Object object;
      	
  		// TODO Change to KeyManager usage
  		Map keyMap = (Map)key;
  
  		// load global profile
  		map.put("type", "global");
  		Object global = this.getProfile(key, map, location, factory, forcedLoad)[0];
  		result = (DeltaApplicableReferencesAdjustable)this.loadProfile(key, map, factory);
  	
  		// load role delta
  		map.put("type", "role");
  		try {
  			object = this.getProfile(key, map, location+"-role-"+keyMap.get("role"), factory, forcedLoad)[0];
  			if (object != null)
  				result.applyDelta(object); 		
  		} catch (Exception e) {
  			if (!isSourceNotFoundException(e))
  				throw e;
  		}
  
  		// load user delta
  		map.put("type", "user");
  		try {
  			object = this.loadProfile(key, map, factory);
  			if (object != null)
  				result.applyDelta(object);
  		} catch (Exception e) {
  			if (!isSourceNotFoundException(e))
  				throw e;
  		}
  		
  		if (result == null)
  			throw new SourceNotFoundException("Global "+keyMap.get("profile")+" does not exist.");
  		
  		// change references to objects where no delta has been applied
  		result.adjustReferences(global);
  		
  		service.setAttribute(location, result);
  		
  		return result;
  	}
  
  	/**
  	 * Gets a user profile and creates it by copying the role or the global profile.
  	 */
  	private Object getOrCreateProfile(Object key, Map map, String location, PortalService service, Object factory) 
  	throws Exception {
  		Object result;
      	
  		// TODO Change to KeyManager usage
  		Map keyMap = (Map)key;
  
  		// load user profile
  		map.put("type", "user");
  		try {
  			result = this.loadProfile(key, map, factory);
  		} catch (Exception e1) {
  			if (!isSourceNotFoundException(e1))
  				throw e1;
  
  			// load role profile
  			map.put("type", "role");
  			try {
  				result = this.loadProfile(key, map, factory);
  			} catch (Exception e2) {
  				if (!isSourceNotFoundException(e2))
  					throw e2;
  
  				// load global profile
  				map.put("type", "global");
  				result = this.loadProfile(key, map, factory);
  			}
  			
  			// save profile as user profile
  			MapSourceAdapter adapter = null;
  			try {
  				adapter = (MapSourceAdapter) this.manager.lookup(MapSourceAdapter.ROLE);
  				map.put("type", "user");
  				
                  adapter.saveProfile(key, map, result);
  			} finally {
  				this.manager.release(adapter);
  			}
  		}
  		
  		service.setAttribute(location, result);
  
  		return result;
  	}
  
  	/**
  	 * Gets a profile.
  	 * @return result[0] is the profile, result[1] is a Boolean, 
  	 * which signals whether the profile has been loaded or reused.
  	 */
  	private Object[] getProfile(Object key, Map map, String location, Object factory, boolean forcedLoad) 
  	throws Exception {
  		MapSourceAdapter adapter = null;
  		try {
  			adapter = (MapSourceAdapter)this.manager.lookup(MapSourceAdapter.ROLE);
  
  			Object result = this.checkValidity(key, map, location, forcedLoad, adapter);
  			if (!(result instanceof SourceValidity))
  				return new Object[]{result, Boolean.FALSE};
  			SourceValidity newValidity = (SourceValidity)result; 
  
  			this.lock.releaseReadLock();
  			this.lock.writeLock();
  			
  			// check validity again in case of another thread has already loaded
  			result = this.checkValidity(key, map, location, forcedLoad, adapter);
  			if (!(result instanceof SourceValidity))
  				return new Object[]{result, Boolean.FALSE};
  			newValidity = (SourceValidity)result; 
  
  			Object object = adapter.loadProfile(key, map);
  			this.prepareObject(object, factory);
  			if (newValidity != null) {
  				this.attributes.put(location, new Object[] {object, newValidity});
  			}
  
  			return new Object[]{object, Boolean.TRUE};
  		} finally {
  			this.manager.release(adapter);
  		}
  	}
  	
  	/**
  	 * If the profile is valid itself is returned, otherwise a newly created SourceValidity object is returned.
  	 */
  	private Object checkValidity(Object key, Map map, String location, boolean forcedLoad, MapSourceAdapter adapter) {
  		Object[] objects = (Object[])this.attributes.get(location);
  
  		SourceValidity sourceValidity = null;
  		int valid = SourceValidity.INVALID;
  		if (objects != null) {
  			sourceValidity = (SourceValidity) objects[1];
  			valid = sourceValidity.isValid();
  			if (!forcedLoad && valid == SourceValidity.VALID)
  				return objects[0];
  		}
  
  		SourceValidity newValidity = adapter.getValidity(key, map);
  		if (!forcedLoad && valid == SourceValidity.UNKNWON) {
  			if (sourceValidity.isValid(newValidity) == SourceValidity.VALID)
  				return objects[0];
  		}
  		
  		return newValidity;
  	}
  
  	/**
  	 * Loads a profile.
  	 */
  	private Object loadProfile(Object key, Map map, Object factory)
  	throws Exception {
  		MapSourceAdapter adapter = null;
  		try {
  			adapter = (MapSourceAdapter) this.manager.lookup(MapSourceAdapter.ROLE);
  
  			Object object = adapter.loadProfile(key, map);
  			this.prepareObject(object, factory);
  
  			return object;
  		} finally {
  			this.manager.release(adapter);
  		}
  	}
  
  	private boolean isSourceNotFoundException(Throwable t) {
  		while (t != null) {
  			if (t instanceof SourceNotFoundException) {
                  return true;
  			}
              if (t instanceof CascadingThrowable) {
                  t = ((CascadingThrowable)t).getCause();
              } else if ( t instanceof SAXException ) {
                  t = ((SAXException)t).getCause();
              } else {
                  t = null;
              }
  		}
  		return false;
  	}
  	
  	/**
  	 * Prepares the object by using the specified factory.
  	 */
  	private void prepareObject(Object object, Object factory)
  	throws ProcessingException {
  		if (factory != null && object != null) {
  			if (object instanceof Layout) {
  				((LayoutFactory)factory).prepareLayout((Layout)object);
  			} else if (object instanceof CopletDataManager) {
  				CopletFactory copletFactory = (CopletFactory)factory;
  				Iterator iterator = ((CopletDataManager)object).getCopletData().values().iterator();
  				while (iterator.hasNext()) {
  					CopletData cd = (CopletData)iterator.next();
  					copletFactory.prepare(cd);
  				}
  			} else if (object instanceof CopletInstanceDataManager) {
  				CopletFactory copletFactory = (CopletFactory)factory;
  				Iterator iterator = ((CopletInstanceDataManager)object).getCopletInstanceData().values().iterator();
  				while (iterator.hasNext()) {
  					CopletInstanceData cid = (CopletInstanceData)iterator.next();
  					copletFactory.prepare(cid);
  				}
  			}
  		}
  	}
  	
      public CopletInstanceData getCopletInstanceData(String copletID) {
          PortalService service = null;
          String attribute = null;
          try {
              service = (PortalService) this.manager.lookup(PortalService.ROLE);
  
  			attribute = AuthenticationProfileManager.class.getName()+"/"+service.getPortalName()+"/CopletInstanceData";
  			CopletInstanceDataManager copletInstanceDataManager = (CopletInstanceDataManager)service.getAttribute(attribute);
  
              return copletInstanceDataManager.getCopletInstanceData(copletID);
          } catch (ComponentException e) {
              throw new CascadingRuntimeException("Unable to lookup portal service.", e);
          } finally {
              this.manager.release(service);
          }
      }
  
      public List getCopletInstanceData(CopletData data) {
          List coplets = new ArrayList();
          PortalService service = null;
          String attribute = null;
          try {
              service = (PortalService) this.manager.lookup(PortalService.ROLE);
  
              attribute = AuthenticationProfileManager.class.getName()+"/"+service.getPortalName()+"/CopletInstanceData";
              CopletInstanceDataManager copletInstanceDataManager = (CopletInstanceDataManager)service.getAttribute(attribute);
  
              Iterator iter = copletInstanceDataManager.getCopletInstanceData().values().iterator();
              while ( iter.hasNext() ) {
                  CopletInstanceData current = (CopletInstanceData)iter.next();
                  if ( current.getCopletData().equals(data) ) {
                      coplets.add( current );
                  }
              }
              return coplets;
          } catch (ComponentException e) {
              throw new CascadingRuntimeException("Unable to lookup portal service.", e);
          } finally {
              this.manager.release(service);
          }
      }
  
      public void register(CopletInstanceData coplet) {
          PortalService service = null;
          String attribute = null;
          try {
              service = (PortalService) this.manager.lookup(PortalService.ROLE);
  
              attribute = AuthenticationProfileManager.class.getName()+"/"+service.getPortalName()+"/CopletInstanceData";
              CopletInstanceDataManager copletInstanceDataManager = (CopletInstanceDataManager)service.getAttribute(attribute);
              
              copletInstanceDataManager.putCopletInstanceData( coplet );
              
          } catch (ComponentException e) {
              throw new CascadingRuntimeException("Unable to lookup portal service.", e);
          } finally {
              this.manager.release(service);
          }
      }
      
      public void unregister(CopletInstanceData coplet) {
          PortalService service = null;
          String attribute = null;
          try {
              service = (PortalService) this.manager.lookup(PortalService.ROLE);
  
              attribute = AuthenticationProfileManager.class.getName()+"/"+service.getPortalName()+"/CopletInstanceData";
              CopletInstanceDataManager copletInstanceDataManager = (CopletInstanceDataManager)service.getAttribute(attribute);
              
              copletInstanceDataManager.getCopletInstanceData().remove(coplet.getId());
              
          } catch (ComponentException e) {
              throw new CascadingRuntimeException("Unable to lookup portal service.", e);
          } finally {
              this.manager.release(service);
          }
      }
  
      public void register(Layout layout) {
          PortalService service = null;
          try {
              service = (PortalService) this.manager.lookup(PortalService.ROLE);
              String portalPrefix = AuthenticationProfileManager.class.getName()+"/"+service.getPortalName();
  
              Map layoutMap = (Map)service.getAttribute("layout-map");
              if ( layoutMap == null ) {
                  layout = (Layout)service.getAttribute(portalPrefix+"/Layout");
                  if (layout != null) {
                      layoutMap = new HashMap();
                      this.cacheLayouts(layoutMap, layout);
                      service.setAttribute("layout-map", layoutMap);
                  }
              }
              
              if ( layoutMap != null) {
                  layoutMap.put(layout.getId(), layout);
              }
              
          } catch (ComponentException e) {
              throw new CascadingRuntimeException("Unable to lookup portal service.", e);
          } finally {
              this.manager.release(service);
          }
      }
      
      public void unregister(Layout layout) {
          PortalService service = null;
          try {
              service = (PortalService) this.manager.lookup(PortalService.ROLE);
              String portalPrefix = AuthenticationProfileManager.class.getName()+"/"+service.getPortalName();
  
              Map layoutMap = (Map)service.getAttribute("layout-map");
              
              if ( layoutMap != null) {
                  layoutMap.remove(layout.getId());
              }
              
          } catch (ComponentException e) {
              throw new CascadingRuntimeException("Unable to lookup portal service.", e);
          } finally {
              this.manager.release(service);
          }
      }
  
      public void setDefaultLayout(Layout object) {
          PortalService service = null;
          try {
              service = (PortalService) this.manager.lookup(PortalService.ROLE);
              service.setTemporaryAttribute("DEFAULT_LAYOUT", object);
          } catch (ComponentException e) {
              throw new CascadingRuntimeException("Unable to lookup service manager.", e);
          } finally {
              this.manager.release(service);
          }
      }
      
      class ReadWriteLock {
      	private Thread activeWriter = null;
      	private HashSet activeReaders = new HashSet();
      	private int waitingWriters = 0;
      	
      	public void readLock() 
      	throws InterruptedException {
      		synchronized (ReadWriteLock.this) {
  				while (this.activeWriter != null || this.waitingWriters != 0) {
  					ReadWriteLock.this.wait();
  				}
  				this.activeReaders.add(Thread.currentThread());
      		}
      	}
      	
      	public void writeLock()
      	throws InterruptedException {
      		synchronized (ReadWriteLock.this) {
  				Thread current = Thread.currentThread();
  
  				if (this.activeWriter != current) {
  					this.waitingWriters++;
  					while (this.activeWriter != null || this.activeReaders.size() != 0) {
  						ReadWriteLock.this.wait();
  					}
  					this.waitingWriters--;
  					this.activeWriter = current;
  				}
      		}
      	}
      	
  		public void releaseReadLock() {
  			synchronized (ReadWriteLock.this) {
  				Thread current = Thread.currentThread();
  
  				this.activeReaders.remove(current);
  				if (this.activeReaders.size() == 0 && this.waitingWriters > 0) {
  					ReadWriteLock.this.notifyAll();
  				}
  			}
  		}
  
      	public void releaseLocks() {
  			synchronized (ReadWriteLock.this) {
  				Thread current = Thread.currentThread();
  				boolean notify = false;
  				
  	    		if (this.activeWriter == current) {
  	    			this.activeWriter = null;
  	    			notify = true;
  	    		} 
  
  				this.activeReaders.remove(current);
  				if (this.activeReaders.size() == 0 && this.waitingWriters > 0) {
  					notify = true;
  				}
  
  				if (notify) {
  					ReadWriteLock.this.notifyAll();
  				}
  			}
         	}
      }
  }
  
  
  1.2       +25 -2     cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/components/modules/input/CopletModule.java
  
  Index: CopletModule.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/components/modules/input/CopletModule.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CopletModule.java	8 May 2003 11:54:01 -0000	1.1
  +++ CopletModule.java	27 May 2003 11:54:18 -0000	1.2
  @@ -68,7 +68,30 @@
   import org.apache.commons.jxpath.JXPathContext;
   
   /**
  - * Makes accessible coplet instance data by using JXPath expressions.
  + * Makes accessible coplet instance data by using JXPath expressions.<br><br>
  + *
  + * Example:<br><br>
  + * 
  + * <pre>&lt;map:action type="foo"&gt;
  + * 	&lt;map:parameter name="maxpageable" value="{coplet:copletData.maxpageable}"/&gt;
  + * &lt;/map:action&gt;<br></pre>
  + * 
  + * The module will insert the boolean value specifying whether the coplet is 
  + * maxpageable or not as value of attribute "value" in &lt;map:parameter&gt;. 
  + * There are two possibilities how the module obtains the information required for 
  + * getting the coplet instance data:<br><br>
  + * 1) If it is used within a coplet pipeline and this pipeline is called using the "cocoon:" protocol,
  + * all required information are passed automatically.<br>
  + * 2) Otherwise the portal name and the coplet id must be passed in the object model 
  + * which can be done by using the ObjectModelAction:
  + *
  + * <pre>&lt;map:action type="objectModel"&gt;
  + *	&lt;map:parameter name="portalName" value="exampleportal"/&gt;
  + *	&lt;map:parameter name="copletId" value="examplecoplet"/&gt;
  + *	&lt;map:action type="foo"&gt;
  + *		&lt;map:parameter name="maxpageable" value="{coplet:copletData.maxpageable}"/&gt;
  + *	&lt;/map:action&gt;
  + * &lt;/map:action&gt;</pre>
    *
    * @author <a href="mailto:bluetkemeier@s-und-n.de">Björn Lütkemeier</a>
    * @version CVS $Id$
  
  
  
  1.12      +1 -1      cocoon-2.1/src/blocks/portal/conf/portal.xconf
  
  Index: portal.xconf
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/portal/conf/portal.xconf,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- portal.xconf	27 May 2003 09:39:06 -0000	1.11
  +++ portal.xconf	27 May 2003 11:54:18 -0000	1.12
  @@ -19,7 +19,7 @@
       </event-aspects>
    </component>
   
  - <component class="org.apache.cocoon.portal.profile.impl.SimpleProfileManager" logger="portal" role="org.apache.cocoon.portal.profile.ProfileManager">
  + <component class="org.apache.cocoon.portal.profile.impl.AuthenticationProfileManager" logger="portal" role="org.apache.cocoon.portal.profile.ProfileManager">
    </component>
   
    <component class="org.apache.cocoon.portal.impl.PortalManagerImpl" logger="portal" role="org.apache.cocoon.portal.PortalManager"/>
  
  
  
  1.7       +2 -2      cocoon-2.1/src/blocks/portal/samples/sitemap.xmap
  
  Index: sitemap.xmap
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/portal/samples/sitemap.xmap,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- sitemap.xmap	27 May 2003 11:10:20 -0000	1.6
  +++ sitemap.xmap	27 May 2003 11:54:18 -0000	1.7
  @@ -98,12 +98,12 @@
             <map:generate type="portal" label="content">
           	<map:parameter name="portal-name" value="portal" />
             </map:generate>
  -<!--
  +
             <map:transform type="cinclude"/> 
   
             <map:transform src="{global:skin}styles/header.xsl"/>
             <map:transform src="{global:skin}styles/portal_layout.xsl"/>
  --->
  +
   <!--
             <map:transform type="htmlroot" />
   -->
  
  
  

Mime
View raw message