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/java/org/apache/cocoon/portal/coplet/adapter/impl URICopletAdapter.java AbstractCopletAdapter.java
Date Wed, 03 Mar 2004 14:35:49 GMT
cziegeler    2004/03/03 06:35:49

  Modified:    .        status.xml
               src/blocks/portal/java/org/apache/cocoon/portal/coplet/adapter/impl
                        URICopletAdapter.java AbstractCopletAdapter.java
  Log:
       Pass notification object to coplet error pipelines so it can react on it.
  
  Revision  Changes    Path
  1.255     +4 -1      cocoon-2.1/status.xml
  
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/status.xml,v
  retrieving revision 1.254
  retrieving revision 1.255
  diff -u -r1.254 -r1.255
  --- status.xml	3 Mar 2004 09:26:24 -0000	1.254
  +++ status.xml	3 Mar 2004 14:35:49 -0000	1.255
  @@ -196,6 +196,9 @@
     <changes>
   
    <release version="@version@" date="@date@">
  +   <action dev="CZ" type="update">
  +     Pass notification object to coplet error pipelines so it can react on it.
  +   </action>
      <action dev="AG" type="update" fixes-bug="24457" due-to-email="ouzo@wlkp.org" due-to="Leszek
Gawron">
        Updated xalan to 2.6.0
      </action>
  
  
  
  1.13      +55 -7     cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/coplet/adapter/impl/URICopletAdapter.java
  
  Index: URICopletAdapter.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/coplet/adapter/impl/URICopletAdapter.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- URICopletAdapter.java	9 Feb 2004 12:14:20 -0000	1.12
  +++ URICopletAdapter.java	3 Mar 2004 14:35:49 -0000	1.13
  @@ -54,13 +54,21 @@
   import java.util.ArrayList;
   import java.util.HashMap;
   import java.util.List;
  +import java.util.Map;
   
   import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.activity.Initializable;
  +import org.apache.avalon.framework.context.Context;
  +import org.apache.avalon.framework.context.ContextException;
  +import org.apache.avalon.framework.context.Contextualizable;
   import org.apache.avalon.framework.service.ServiceException;
   import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.cocoon.ProcessingException;
  +import org.apache.cocoon.components.ContextHelper;
  +import org.apache.cocoon.components.notification.Notifying;
  +import org.apache.cocoon.components.notification.NotifyingBuilder;
   import org.apache.cocoon.components.source.SourceUtil;
  +import org.apache.cocoon.environment.ObjectModelHelper;
   import org.apache.cocoon.portal.Constants;
   import org.apache.cocoon.portal.PortalService;
   import org.apache.cocoon.portal.coplet.CopletInstanceData;
  @@ -84,11 +92,21 @@
    */
   public class URICopletAdapter 
       extends AbstractCopletAdapter
  -    implements Disposable, Subscriber, Initializable {
  +    implements Disposable, Subscriber, Initializable, Contextualizable {
   	
       /** The source resolver */
       protected SourceResolver resolver;
       
  +    /** The application context */
  +    protected Context context;
  +    
  +    /* (non-Javadoc)
  +     * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
  +     */
  +    public void contextualize(Context context) throws ContextException {
  +        this.context = context;
  +    }
  +    
       /* (non-Javadoc)
        * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
        */
  @@ -225,20 +243,50 @@
   
       /**
        * Render the error content for a coplet
  -     * @param coplet
  -     * @param handler
  +     * @param coplet  The coplet instance data
  +     * @param handler The content handler
  +     * @param error   The exception that occured
        * @return True if the error content has been rendered, otherwise false
        * @throws SAXException
        */
  -    protected boolean renderErrorContent(CopletInstanceData coplet, ContentHandler handler)
  +    protected boolean renderErrorContent(CopletInstanceData coplet, 
  +                                         ContentHandler     handler,
  +                                         Exception          error)
       throws SAXException {
           final String uri = (String) this.getConfiguration(coplet, "error-uri");
           if ( uri != null ) {
               // TODO - if an error occured for this coplet, remember this
               //         and use directly the error-uri from now on
  -            // We need for this the ability to dynamically add aspects to
  -            // objects!
  +
  +            if ( uri.startsWith("cocoon:") && error != null) {
  +                // Create a Notifying
  +                NotifyingBuilder notifyingBuilder = null;
  +                Notifying currentNotifying = null;
  +                try {
  +                    notifyingBuilder= (NotifyingBuilder)this.manager.lookup(NotifyingBuilder.ROLE);
  +                    currentNotifying = notifyingBuilder.build(this, error);
  +                } catch (Exception ignore) {
  +                } finally {
  +                    this.manager.release(notifyingBuilder);
  +                }
  +
  +                final Map objectModel = ContextHelper.getObjectModel(this.context);
  +                // Add it to the object model
  +                if ( currentNotifying != null ) {
  +                    objectModel.put(org.apache.cocoon.Constants.NOTIFYING_OBJECT, currentNotifying);
                   
  +                    objectModel.put(ObjectModelHelper.THROWABLE_OBJECT, error);
  +                }
  +            
  +                try {
  +                    this.streamContent( coplet, uri, handler);
  +                } finally {
  +                    objectModel.remove(org.apache.cocoon.Constants.NOTIFYING_OBJECT);
  +                    objectModel.remove(ObjectModelHelper.THROWABLE_OBJECT);
  +                }
  +            }
  +            
               this.streamContent( coplet, uri, handler);
  +                        
               return true;
           }
           return false;
  
  
  
  1.9       +10 -5     cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/coplet/adapter/impl/AbstractCopletAdapter.java
  
  Index: AbstractCopletAdapter.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/coplet/adapter/impl/AbstractCopletAdapter.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- AbstractCopletAdapter.java	1 Mar 2004 20:34:28 -0000	1.8
  +++ AbstractCopletAdapter.java	3 Mar 2004 14:35:49 -0000	1.9
  @@ -121,6 +121,7 @@
           if ( bool != null && bool.booleanValue() ) {
               boolean read = false;
               SaxBuffer buffer = new SaxBuffer();
  +            Exception error = null;
               try {
                   
                   if ( timeout != null ) {
  @@ -140,13 +141,14 @@
                       read = true;
                   }
               } catch (Exception exception ) {
  +                error = exception;
                   this.getLogger().warn("Unable to get content of coplet: " + coplet.getId(),
exception);
               }
               
               if ( read ) {
                   buffer.toSAX( contentHandler );
               } else {
  -                if ( !this.renderErrorContent(coplet, contentHandler)) {
  +                if ( !this.renderErrorContent(coplet, contentHandler, error)) {
                       // FIXME - get correct error message
                       contentHandler.startDocument();
                       XMLUtils.startElement( contentHandler, "p");
  @@ -196,12 +198,15 @@
       
       /**
        * Render the error content for a coplet
  -     * @param coplet
  -     * @param handler
  +     * @param coplet  The coplet instance data
  +     * @param handler The content handler
  +     * @param error   The exception that occured
        * @return True if the error content has been rendered, otherwise false
        * @throws SAXException
        */
  -    protected boolean renderErrorContent(CopletInstanceData coplet, ContentHandler handler)
  +    protected boolean renderErrorContent(CopletInstanceData coplet, 
  +                                         ContentHandler     handler,
  +                                         Exception          error)
       throws SAXException {
           return false;
       }
  
  
  

Mime
View raw message