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/transformation NewEventLinkTransformer.java CopletTransformer.java EventLinkTransformer.java HTMLEventLinkTransformer.java AbstractCopletTransformer.java
Date Tue, 16 Mar 2004 09:16:59 GMT
cziegeler    2004/03/16 01:16:59

  Modified:    src/blocks/portal/java/org/apache/cocoon/portal/transformation
                        NewEventLinkTransformer.java CopletTransformer.java
                        EventLinkTransformer.java
                        HTMLEventLinkTransformer.java
                        AbstractCopletTransformer.java
  Log:
  Hopefully fixing bug 27672 now
  
  Revision  Changes    Path
  1.7       +28 -39    cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/transformation/NewEventLinkTransformer.java
  
  Index: NewEventLinkTransformer.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/transformation/NewEventLinkTransformer.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- NewEventLinkTransformer.java	5 Mar 2004 13:02:16 -0000	1.6
  +++ NewEventLinkTransformer.java	16 Mar 2004 09:16:59 -0000	1.7
  @@ -17,8 +17,6 @@
   
   import java.util.Stack;
   
  -import org.apache.avalon.framework.service.ServiceException;
  -import org.apache.cocoon.portal.PortalService;
   import org.apache.cocoon.portal.coplet.CopletInstanceData;
   import org.apache.cocoon.portal.event.impl.CopletLinkEvent;
   import org.xml.sax.Attributes;
  @@ -172,46 +170,37 @@
           // if attribute found that contains a link
           if (link != null) {
               CopletInstanceData cid = this.getCopletInstanceData();
  -            PortalService portalService = null;
  -            try {
  -                portalService = (PortalService) this.manager.lookup(PortalService.ROLE);
  -                // create event link
  -                CopletLinkEvent event = new CopletLinkEvent(cid, link);
  -                String eventLink = portalService.getComponentManager().getLinkService().getLinkURI(event);
  -
  -                //form elements need hidden inputs to change request parameters
  -                if (formSpecialTreatment) {
  -                    int begin =
  -                        eventLink.indexOf("cocoon-portal-action=")
  -                            + "cocoon-portal-action=".length();
  -                    int end = eventLink.indexOf('&', begin);
  -                    if (end == -1) {
  -                        end = eventLink.length();
  -                    }
  -
  -                    portalAction = eventLink.substring(begin, end);
  -
  -                    begin =
  -                        eventLink.indexOf("cocoon-portal-event=")
  -                            + "cocoon-portal-event=".length();
  -                    end = eventLink.indexOf('&', begin);
  -                    if (end == -1) {
  -                        end = eventLink.length();
  -                    }
  -                    portalEvent = eventLink.substring(begin, end);
  +            // create event link
  +            CopletLinkEvent event = new CopletLinkEvent(cid, link);
  +            String eventLink = this.getPortalService().getComponentManager().getLinkService().getLinkURI(event);
  +
  +            //form elements need hidden inputs to change request parameters
  +            if (formSpecialTreatment) {
  +                int begin =
  +                    eventLink.indexOf("cocoon-portal-action=")
  +                        + "cocoon-portal-action=".length();
  +                int end = eventLink.indexOf('&', begin);
  +                if (end == -1) {
  +                    end = eventLink.length();
  +                }
  +
  +                portalAction = eventLink.substring(begin, end);
   
  -                    eventLink =
  -                        eventLink.substring(0, eventLink.indexOf('?'));
  +                begin =
  +                    eventLink.indexOf("cocoon-portal-event=")
  +                        + "cocoon-portal-event=".length();
  +                end = eventLink.indexOf('&', begin);
  +                if (end == -1) {
  +                    end = eventLink.length();
                   }
  +                portalEvent = eventLink.substring(begin, end);
   
  -                // insert event link
  -                newAttributes.setValue(index, eventLink);
  -            }
  -            catch (ServiceException e) {
  -                throw new SAXException(e);
  -            } finally {
  -                this.manager.release(portalService);
  +                eventLink =
  +                    eventLink.substring(0, eventLink.indexOf('?'));
               }
  +
  +            // insert event link
  +            newAttributes.setValue(index, eventLink);
           }
   
           elementStack.push(elementName);
  
  
  
  1.17      +52 -69    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.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- CopletTransformer.java	5 Mar 2004 13:02:16 -0000	1.16
  +++ CopletTransformer.java	16 Mar 2004 09:16:59 -0000	1.17
  @@ -19,10 +19,8 @@
   import java.util.ArrayList;
   import java.util.List;
   
  -import org.apache.avalon.framework.service.ServiceException;
   import org.apache.cocoon.ProcessingException;
   import org.apache.cocoon.portal.LinkService;
  -import org.apache.cocoon.portal.PortalService;
   import org.apache.cocoon.portal.coplet.CopletInstanceData;
   import org.apache.cocoon.portal.event.impl.ChangeCopletInstanceAspectDataEvent;
   import org.apache.cocoon.portal.event.impl.CopletJXPathEvent;
  @@ -133,64 +131,56 @@
               }
                   
           } else if (name.equals(LINK_ELEM)) {
  -            PortalService portalService = null;
  -            try {
  -                portalService = (PortalService)this.manager.lookup(PortalService.ROLE);
  -
  -                final LinkService linkService = portalService.getComponentManager().getLinkService();
  -                final String format = attr.getValue("format");
  -                AttributesImpl newAttrs = new AttributesImpl();
  -                newAttrs.setAttributes(attr);
  -                newAttrs.removeAttribute("format");
  -
  -                if ( attr.getValue("href") != null ) {
  -                    final CopletInstanceData cid = this.getCopletInstanceData();
  -                    ChangeCopletInstanceAspectDataEvent event = new ChangeCopletInstanceAspectDataEvent(cid,
null, null);
  -                    
  -                    String value = linkService.getLinkURI(event);
  -                    if (value.indexOf('?') == -1) {
  -                        value = value + '?' + attr.getValue("href");
  -                    } else {
  -                        value = value + '&' + attr.getValue("href");
  +
  +            final LinkService linkService = this.getPortalService().getComponentManager().getLinkService();
  +            final String format = attr.getValue("format");
  +            AttributesImpl newAttrs = new AttributesImpl();
  +            newAttrs.setAttributes(attr);
  +            newAttrs.removeAttribute("format");
  +
  +            if ( attr.getValue("href") != null ) {
  +                final CopletInstanceData cid = this.getCopletInstanceData();
  +                ChangeCopletInstanceAspectDataEvent event = new ChangeCopletInstanceAspectDataEvent(cid,
null, null);
  +                
  +                String value = linkService.getLinkURI(event);
  +                if (value.indexOf('?') == -1) {
  +                    value = value + '?' + attr.getValue("href");
  +                } else {
  +                    value = value + '&' + attr.getValue("href");
  +                }
  +                newAttrs.removeAttribute("href");
  +                this.output(value, format, newAttrs );
  +            } else {
  +                final String path = attr.getValue("path");
  +                final String value = attr.getValue("value");
  +                
  +                newAttrs.removeAttribute("path");
  +                newAttrs.removeAttribute("value");
  +                
  +                JXPathEvent event = null;
  +                if ( attr.getValue("layout") != null ) {
  +                    newAttrs.removeAttribute("layout");
  +                    final String layoutId = attr.getValue("layout");
  +                    Object layout = this.getPortalService().getComponentManager().getProfileManager().getPortalLayout(null,
layoutId);
  +                    if ( layout != null ) {
  +                        event = new JXPathEvent(layout, path, value);
                       }
  -                    newAttrs.removeAttribute("href");
  -                    this.output(value, format, newAttrs );
                   } else {
  -                    final String path = attr.getValue("path");
  -                    final String value = attr.getValue("value");
  -                    
  -                    newAttrs.removeAttribute("path");
  -                    newAttrs.removeAttribute("value");
  -                    
  -                    JXPathEvent event = null;
  -                    if ( attr.getValue("layout") != null ) {
  -                        newAttrs.removeAttribute("layout");
  -                        final String layoutId = attr.getValue("layout");
  -                        Object layout = portalService.getComponentManager().getProfileManager().getPortalLayout(null,
layoutId);
  -                        if ( layout != null ) {
  -                            event = new JXPathEvent(layout, path, value);
  -                        }
  -                    } else {
  -                        String copletId = attr.getValue("coplet");
  -                        newAttrs.removeAttribute("coplet");
  -                        final CopletInstanceData cid = this.getCopletInstanceData(copletId);
  -                        if ( cid != null ) {
  -                            event = new CopletJXPathEvent(cid, path, value);
  -                        }
  +                    String copletId = attr.getValue("coplet");
  +                    newAttrs.removeAttribute("coplet");
  +                    final CopletInstanceData cid = this.getCopletInstanceData(copletId);
  +                    if ( cid != null ) {
  +                        event = new CopletJXPathEvent(cid, path, value);
                       }
  -                    if ( this.insideLinks ) {
  -                        if ( event != null ) {
  -                            this.collectedEvents.add(event);
  -                        }
  -                    } else {
  -                        final String href = linkService.getLinkURI(event);
  -                        this.output(href, format, newAttrs );
  +                }
  +                if ( this.insideLinks ) {
  +                    if ( event != null ) {
  +                        this.collectedEvents.add(event);
                       }
  +                } else {
  +                    final String href = linkService.getLinkURI(event);
  +                    this.output(href, format, newAttrs );
                   }
  -            } catch (ServiceException e) {
  -                throw new SAXException("Error getting portal service.", e);
  -            } finally {
  -                this.manager.release( portalService );
               }
           } else if (name.equals(LINKS_ELEM) ) {
               this.insideLinks = true;
  @@ -221,19 +211,12 @@
           } else if ( name.equals(LINKS_ELEM) ) {
               this.insideLinks = false;
               final String format = (String)this.stack.pop();
  -            PortalService portalService = null;
  -            try {
  -                portalService = (PortalService)this.manager.lookup(PortalService.ROLE);
  -                final LinkService linkService = portalService.getComponentManager().getLinkService();
  -                
  -                final String href = linkService.getLinkURI(this.collectedEvents);
  -                final AttributesImpl newAttrs = new AttributesImpl();
  -                this.output(href, format, newAttrs );
  -            } catch (ServiceException e) {
  -                throw new SAXException("Error getting portal service.", e);
  -            } finally {
  -                this.manager.release( portalService );
  -            }
  +            final LinkService linkService = this.getPortalService().getComponentManager().getLinkService();
  +            
  +            final String href = linkService.getLinkURI(this.collectedEvents);
  +            final AttributesImpl newAttrs = new AttributesImpl();
  +            this.output(href, format, newAttrs );
  +
               this.collectedEvents.clear();
               if ( this.content != null ) {
                   this.content.toSAX(this.contentHandler);
  
  
  
  1.8       +13 -28    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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- EventLinkTransformer.java	5 Mar 2004 13:02:16 -0000	1.7
  +++ EventLinkTransformer.java	16 Mar 2004 09:16:59 -0000	1.8
  @@ -17,7 +17,6 @@
   
   import java.util.Stack;
   
  -import org.apache.avalon.framework.service.ServiceException;
   import org.apache.cocoon.portal.LinkService;
   import org.apache.cocoon.portal.coplet.CopletInstanceData;
   import org.apache.cocoon.portal.event.impl.CopletLinkEvent;
  @@ -169,21 +168,14 @@
                       // if attribute found that contains a link
                       if (link != null) {
                           CopletInstanceData cid = this.getCopletInstanceData();        
              
  -                        LinkService linkService = null;
  -                        try {
  -                            linkService = (LinkService)this.manager.lookup(LinkService.ROLE);
  +                        LinkService linkService = this.getPortalService().getComponentManager().getLinkService();
           
  -                            // create event link
  -                            CopletLinkEvent event = new CopletLinkEvent(cid, link);
  -                            String eventLink = linkService.getLinkURI(event);
  -        
  -                            // insert event link
  -                            attr.setValue(index, eventLink);
  -                        } catch (ServiceException e) {
  -                            throw new SAXException(e);
  -                        } finally {
  -                            this.manager.release(linkService);
  -                        }
  +                        // create event link
  +                        CopletLinkEvent event = new CopletLinkEvent(cid, link);
  +                        String eventLink = linkService.getLinkURI(event);
  +    
  +                        // insert event link
  +                        attr.setValue(index, eventLink);
                       }
                   }
                   
  @@ -195,18 +187,11 @@
                       String link = this.endTextRecording();
   
                       CopletInstanceData cid = this.getCopletInstanceData();            
          
  -                    LinkService linkService = null;
  -                    try {
  -                        linkService = (LinkService)this.manager.lookup(LinkService.ROLE);
  -        
  -                        // create event link
  -                        CopletLinkEvent event = new CopletLinkEvent(cid, link);
  -                        eventLink = linkService.getLinkURI(event);
  -                    } catch (ServiceException e) {
  -                        throw new SAXException(e);
  -                    } finally {
  -                        this.manager.release(linkService);
  -                    }
  +                    LinkService linkService = this.getPortalService().getComponentManager().getLinkService();
  +
  +                    // create event link
  +                    CopletLinkEvent event = new CopletLinkEvent(cid, link);
  +                    eventLink = linkService.getLinkURI(event);
                   } else {
                       fragment = this.endRecording();
                   }
  
  
  
  1.4       +2 -4      cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/transformation/HTMLEventLinkTransformer.java
  
  Index: HTMLEventLinkTransformer.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/transformation/HTMLEventLinkTransformer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- HTMLEventLinkTransformer.java	11 Mar 2004 09:44:02 -0000	1.3
  +++ HTMLEventLinkTransformer.java	16 Mar 2004 09:16:59 -0000	1.4
  @@ -19,7 +19,6 @@
   import java.util.Map;
   
   import org.apache.avalon.framework.parameters.Parameters;
  -import org.apache.avalon.framework.service.Serviceable;
   import org.apache.cocoon.ProcessingException;
   import org.apache.cocoon.environment.SourceResolver;
   import org.apache.cocoon.portal.coplet.CopletInstanceData;
  @@ -38,8 +37,7 @@
    * @version CVS $Id$
    */
   public class HTMLEventLinkTransformer 
  -extends AbstractCopletTransformer 
  -implements Serviceable {
  +extends AbstractCopletTransformer {
       
       /** The temporary attribute used to store the uri */
       protected String attributeName;
  
  
  
  1.9       +63 -36    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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- AbstractCopletTransformer.java	5 Mar 2004 13:02:16 -0000	1.8
  +++ AbstractCopletTransformer.java	16 Mar 2004 09:16:59 -0000	1.9
  @@ -56,6 +56,9 @@
        */
       public static final String PORTAL_NAME_PARAM = "portalName";
   
  +    /** The portal service */
  +    private PortalService _portalService;
  +    
       /**
        * Try to get the coplet instance data belonging to the current request
        * @return The coplet instance data
  @@ -70,6 +73,39 @@
           return cid;
       }
       
  +    
  +    /**
  +     * Get the portal service
  +     */
  +    protected PortalService getPortalService()
  +    throws SAXException {
  +        if ( this._portalService == null ) {
  +            try {
  +                this._portalService = (PortalService)this.manager.lookup(PortalService.ROLE);
  +                
  +                if ( this._portalService.getPortalName() == null ) {
  +                    // set portal name
  +                    String portalName = this.parameters.getParameter(PORTAL_NAME_PARAM,

  +                                                                    (String)this.objectModel.get(Constants.PORTAL_NAME_KEY));
  +                    if ( portalName == null ) {
  +                        final Map context = (Map)this.objectModel.get(ObjectModelHelper.PARENT_CONTEXT);
  +                        if ( context != null ) {
  +                            portalName = (String) context.get(Constants.PORTAL_NAME_KEY);
  +                        }
  +                    }
  +                    if ( portalName == null ) {
  +                        throw new SAXException("portalName must be passed as parameter
or in the object model.");
  +                    }
  +                    this._portalService.setPortalName(portalName);
  +                }
  +            } catch (ServiceException se) {
  +                throw new SAXException("Unable to get portal service.", se);
  +            }
  +        }
  +        return this._portalService;
  +    }
  +    
  +    
       /**
        * Try to get the coplet instance data with the given id
        * @param copletId  The id of the coplet instance or null if this transformer
  @@ -79,47 +115,38 @@
        */
       protected CopletInstanceData getCopletInstanceData(String copletId) 
       throws SAXException {
  -        PortalService portalService = null;
  -        try {
  -
  -            portalService = (PortalService)this.manager.lookup(PortalService.ROLE);
  -
  -            final Map context = (Map)objectModel.get(ObjectModelHelper.PARENT_CONTEXT);
  -            
  -            if ( portalService.getPortalName() == null && context == null) {
  -                // set portal name
  +        final Map context = (Map)objectModel.get(ObjectModelHelper.PARENT_CONTEXT);
  +        
  +        if ( copletId == null ) {
  +            // determine coplet id
  +            if (context != null) {
  +                copletId = (String)context.get(Constants.COPLET_ID_KEY);
  +            } else {
                   try {
  -                    portalService.setPortalName(this.parameters.getParameter(PORTAL_NAME_PARAM));
  +                    copletId = this.parameters.getParameter(COPLET_ID_PARAM);
  +                        
                   } catch (ParameterException e) {
  -                    throw new SAXException("portalName must be passed as parameter or in
the object model within the parent context.");
  -                }
  -            }
  -            
  -            if ( copletId == null ) {
  -                // determine coplet id
  -                if (context != null) {
  -                    copletId = (String)context.get(Constants.COPLET_ID_KEY);
  -                } else {
  -                    try {
  -                        copletId = this.parameters.getParameter(COPLET_ID_PARAM);
  -                            
  -                    } catch (ParameterException e) {
  -                        throw new SAXException("copletId must be passed as parameter or
in the object model within the parent context.");
  -                    }
  +                    throw new SAXException("copletId must be passed as parameter or in
the object model within the parent context.");
                   }
               }
  -            if (copletId == null) {
  -                throw new SAXException("copletId must be passed as parameter or in the
object model within the parent context.");
  -            }
  +        }
  +        if (copletId == null) {
  +            throw new SAXException("copletId must be passed as parameter or in the object
model within the parent context.");
  +        }
   
  +        CopletInstanceData object = this.getPortalService().getComponentManager().getProfileManager().getCopletInstanceData(
copletId );
  +            
  +        return object;
  +    }
   
  -            CopletInstanceData object = portalService.getComponentManager().getProfileManager().getCopletInstanceData(
copletId );
  -                
  -            return object;
  -        } catch (ServiceException e) {
  -            throw new SAXException("Error getting portal service.", e);
  -        } finally {
  -            this.manager.release( portalService );
  +    /* (non-Javadoc)
  +     * @see org.apache.avalon.excalibur.pool.Recyclable#recycle()
  +     */
  +    public void recycle() {
  +        if ( this._portalService != null ) {
  +            this.manager.release( this._portalService );
  +            this._portalService = null;            
           }
  +        super.recycle();
       }
   }
  
  
  

Mime
View raw message