You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Guido Casper <gc...@s-und-n.de> on 2008/01/21 13:24:22 UTC

Portal: ApplicationCopletAdapter and persistent links

Hi all,

I am trying to implement persistent links within an application coplet 
of the portal. By default the internal links of external applications 
are dynamically converted to "?cocoon-portal-event=xx" parameters at 
runtime. So a particular page of an external application is not easily 
bookmarkable or to be incorporated in search results, etc. So to have a 
search crawler be able to index these pages, these links have to be 
globally valid, identifyable and have to survive Tomcat restarts. In 
short, they have to be persistent.

I found it would be easiest to base the implementation on the 
PageLabelEventConverter.

As a test I tried to manually create a CopletLinkEvent within the start 
Method (initialize() wouldn't work because this code accesses the 
ProfileManager) to simulate recreating these Links from a persistent store:

public void start() {
     String label = this.labelManager.setCurrentLabel();
     try {
         PortalService portalService = 
(PortalService)this.manager.lookup(PortalService.ROLE);
         PortalComponentManager componentManager = 
portalService.getComponentManager();
         ProfileManager profileManager = 
componentManager.getProfileManager();
         if (this.eventList.size() == 0) {
             CopletInstanceData cid = 
profileManager.getCopletInstanceData( "Google-1" );
             if (cid != null) {
                 cid.setAttribute("cookie", null);
                 cid.setAttribute("documentbase", "http://www.google.de/");
                 Event persistentEevent = new CopletLinkEvent(cid, 
"/intl/de/about.html");
                 this.eventList.add(persistentEevent);
             }
         }
     } catch (ServiceException se) {
         this.getLogger().error("Error getting " + PortalService.ROLE + 
": ", se);
     }
}

The event gets correctly endoded into the pages. Even decoding seems to 
work correctly, however clicking this link simply reloads the current page.

Any idea what might go wrong is much appreciated. The complete Code of 
PageLabelPersistentEventConverter is below.

Thanks
Guido

-- 
Freundliche Grüße / With kind regards
Guido Casper

S&N AG
Klingenderstr. 5
D 33100 Paderborn

voice  +49 5251/1581-87
fax    +49 5251/1581-71
eMail  gcasper@s-und-n.de
Web    http://www.s-und-n.de

Vorstand
Klaus Beverungen
Josef Tillmann

Vorsitzender des Aufsichtsrates
Heinz-Dieter Wendorff

Handelsregister
Amtsgericht Paderborn HRB 3270


-------------------------------------------

package org.apache.cocoon.portal.event.impl;

import java.util.List;
import java.util.ArrayList;

import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.cocoon.portal.PortalComponentManager;
import org.apache.cocoon.portal.PortalService;
import org.apache.cocoon.portal.profile.ProfileManager;
import org.apache.cocoon.portal.coplet.CopletBaseData;
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.event.Event;
import org.apache.cocoon.portal.event.EventConverter;
import org.apache.cocoon.portal.impl.PageLabelManager;

public class PageLabelPersistentEventConverter extends AbstractLogEnabled
     implements EventConverter, Serviceable, ThreadSafe {

     protected PageLabelManager labelManager;

     protected ServiceManager manager;

     protected List eventList = new ArrayList();

     public void service(ServiceManager manager) throws ServiceException {
         this.manager = manager;
         this.labelManager = 
(PageLabelManager)manager.lookup(PageLabelManager.ROLE);
     }

     public String encode(Event event) {
         int index = this.eventList.indexOf(event);
         if ( index == -1 ) {
             this.eventList.add(event);
           index = this.eventList.size() - 1;
         }
         return String.valueOf(index);
     }

     public Event decode(String value) {

         if ( null != this.eventList ) {
             int index = new Integer(value).intValue();
             if (index < this.eventList.size()) {
                 this.getLogger().info("decoded");
                 Event event = (Event)this.eventList.get(index);
                 return event;
             }
         }
         return null;
     }

     public void start() {
         String label = this.labelManager.setCurrentLabel();
         try {
             PortalService portalService = 
(PortalService)this.manager.lookup(PortalService.ROLE);
             PortalComponentManager componentManager = 
portalService.getComponentManager();
             ProfileManager profileManager = 
componentManager.getProfileManager();
             if (this.eventList.size() == 0) {
                 CopletInstanceData cid = 
profileManager.getCopletInstanceData( "Google-1" );
                 if (cid != null) {
                     System.out.println("CopletInstanceData found");
                     cid.setAttribute("cookie", null);
                     cid.setAttribute("documentbase", 
"http://www.google.de/");
                     Event persistentEevent = new CopletLinkEvent(cid, 
"/intl/de/about.html");
                     eventList.add(persistentEevent);
                 }

             }
         } catch (ServiceException se) {
             this.getLogger().error("Error getting " + 
PortalService.ROLE + ": ", se);
         }

     }

     public void finish() {
         // nothing to do
     }

     public boolean isMarshallEvents() {
         return this.labelManager.isMarshallEvents();
     }
}

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Portal: ApplicationCopletAdapter and persistent links

Posted by Guido Casper <gc...@s-und-n.de>.
Yes, page labels work fine. I use page labels as they already identify 
the portal state through urls and I only have to "attach" the 
CopletLinkEvent when persisting links/urls - so I thought.

Thanks
Guido

Ralph Goers schrieb:
> Have you configured your application to actually use page labels? By 
> default they are disabled.
> 
> Guido Casper wrote:
>> Hi all,
>>
>> I am trying to implement persistent links within an application coplet 
>> of the portal. By default the internal links of external applications 
>> are dynamically converted to "?cocoon-portal-event=xx" parameters at 
>> runtime. So a particular page of an external application is not easily 
>> bookmarkable or to be incorporated in search results, etc. So to have 
>> a search crawler be able to index these pages, these links have to be 
>> globally valid, identifyable and have to survive Tomcat restarts. In 
>> short, they have to be persistent.
>>
>> I found it would be easiest to base the implementation on the 
>> PageLabelEventConverter.
>>
>> As a test I tried to manually create a CopletLinkEvent within the 
>> start Method (initialize() wouldn't work because this code accesses 
>> the ProfileManager) to simulate recreating these Links from a 
>> persistent store:
>>
>> public void start() {
>>     String label = this.labelManager.setCurrentLabel();
>>     try {
>>         PortalService portalService = 
>> (PortalService)this.manager.lookup(PortalService.ROLE);
>>         PortalComponentManager componentManager = 
>> portalService.getComponentManager();
>>         ProfileManager profileManager = 
>> componentManager.getProfileManager();
>>         if (this.eventList.size() == 0) {
>>             CopletInstanceData cid = 
>> profileManager.getCopletInstanceData( "Google-1" );
>>             if (cid != null) {
>>                 cid.setAttribute("cookie", null);
>>                 cid.setAttribute("documentbase", 
>> "http://www.google.de/");
>>                 Event persistentEevent = new CopletLinkEvent(cid, 
>> "/intl/de/about.html");
>>                 this.eventList.add(persistentEevent);
>>             }
>>         }
>>     } catch (ServiceException se) {
>>         this.getLogger().error("Error getting " + PortalService.ROLE + 
>> ": ", se);
>>     }
>> }
>>
>> The event gets correctly endoded into the pages. Even decoding seems 
>> to work correctly, however clicking this link simply reloads the 
>> current page.
>>
>> Any idea what might go wrong is much appreciated. The complete Code of 
>> PageLabelPersistentEventConverter is below.
>>
>> Thanks
>> Guido
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 
> 

-- 
Freundliche Grüße / With kind regards
Guido Casper

S&N AG
Klingenderstr. 5
D 33100 Paderborn

voice  +49 5251/1581-87
fax    +49 5251/1581-71
eMail  gcasper@s-und-n.de
Web    http://www.s-und-n.de

Vorstand
Klaus Beverungen
Josef Tillmann

Vorsitzender des Aufsichtsrates
Heinz-Dieter Wendorff

Handelsregister
Amtsgericht Paderborn HRB 3270

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Portal: ApplicationCopletAdapter and persistent links

Posted by Ralph Goers <Ra...@dslextreme.com>.
Have you configured your application to actually use page labels? By 
default they are disabled.

Guido Casper wrote:
> Hi all,
>
> I am trying to implement persistent links within an application coplet 
> of the portal. By default the internal links of external applications 
> are dynamically converted to "?cocoon-portal-event=xx" parameters at 
> runtime. So a particular page of an external application is not easily 
> bookmarkable or to be incorporated in search results, etc. So to have 
> a search crawler be able to index these pages, these links have to be 
> globally valid, identifyable and have to survive Tomcat restarts. In 
> short, they have to be persistent.
>
> I found it would be easiest to base the implementation on the 
> PageLabelEventConverter.
>
> As a test I tried to manually create a CopletLinkEvent within the 
> start Method (initialize() wouldn't work because this code accesses 
> the ProfileManager) to simulate recreating these Links from a 
> persistent store:
>
> public void start() {
>     String label = this.labelManager.setCurrentLabel();
>     try {
>         PortalService portalService = 
> (PortalService)this.manager.lookup(PortalService.ROLE);
>         PortalComponentManager componentManager = 
> portalService.getComponentManager();
>         ProfileManager profileManager = 
> componentManager.getProfileManager();
>         if (this.eventList.size() == 0) {
>             CopletInstanceData cid = 
> profileManager.getCopletInstanceData( "Google-1" );
>             if (cid != null) {
>                 cid.setAttribute("cookie", null);
>                 cid.setAttribute("documentbase", 
> "http://www.google.de/");
>                 Event persistentEevent = new CopletLinkEvent(cid, 
> "/intl/de/about.html");
>                 this.eventList.add(persistentEevent);
>             }
>         }
>     } catch (ServiceException se) {
>         this.getLogger().error("Error getting " + PortalService.ROLE + 
> ": ", se);
>     }
> }
>
> The event gets correctly endoded into the pages. Even decoding seems 
> to work correctly, however clicking this link simply reloads the 
> current page.
>
> Any idea what might go wrong is much appreciated. The complete Code of 
> PageLabelPersistentEventConverter is below.
>
> Thanks
> Guido
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org