Hi; i have found where this link is changed; it's in the java class 
PageLabelLinkService.java.. i have modified it (i attach my new version... but 
i'm not sure that it works very well i must test it); the problem, now is that 
i can't take the request parameter called sid in the request..... this thing 
will make me become crazy....
Can anybody help me?
Thanks.

---------- Initial Header -----------

>From      : "Ralph Goers" [EMAIL PROTECTED]
To          : users@cocoon.apache.org
Cc          :
Date      : Tue, 28 Jun 2005 11:24:41 -0700
Subject : Re: Cocoon portal







> This wouldn't be happening in the LinkService, at least directly.  The
> pipeline that is creating the page with the bad link in it most likely
> has one or more transformers.
>
> What bothers me is that the link you are seeing
>
> <A 
> href="http://localhost:8080/pmm/portal/portal?cocoon-portal-event=15&amp;pageLabel=mare";
>  
> xmlns:coplet="http=://apache.org/cocoon/portal/coplet/1.0">Utilizza il 
> servizio</A>
>
> looks very little like the link in your template
>
> <a href='/portal?pageLabel=dispatcher&amp;sid=3DS077'>Utilizza il servizio</a>
>
> The only think they have in common is the text for the link.  My guess is 
> that somehow there is something in your pipeline doing this. For example, I 
> believe the LinkTransformer could be doing this.  It would call the 
> LinkService, which would always add the pageLabel for the current page, not 
> the page you specified.
>
> Ralph
>
> 
>
> Angelo Immediata wrote:
>
> >Yes you are right.. but i'm not able to understand where this href tag is 
> >changed.
> >Do you know where this tag is changed?
> >What method is responsable of this change in DefaultLinkService o 
> >PageLabelLinkService java classes?
> >Thanks again
> >
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 



____________________________________________________________
Navighi a 4 MEGA e i primi 3 mesi sono GRATIS. 
Scegli Libero Adsl Flat senza limiti su http://www.libero.it
/*
 * Copyright 1999-2002,2004 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.cocoon.portal.impl;

import java.io.UnsupportedEncodingException;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;

import org.apache.cocoon.portal.event.Event;
import org.apache.cocoon.portal.event.impl.ChangeAspectDataEvent;
import org.apache.cocoon.portal.layout.CompositeLayout;
import org.apache.cocoon.portal.layout.Item;
import org.apache.cocoon.portal.layout.NamedItem;
import org.apache.cocoon.util.NetUtils;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.cocoon.environment.*;
import org.apache.avalon.framework.component.ComponentException;
import java.util.Vector;
import java.util.StringTokenizer;
import org.apache.cocoon.components.CocoonComponentManager;
import java.util.Map;
import java.util.HashMap;
import java.util.Enumeration;

/**
 * The PageLabelLinkService generates links for named items defined in the layout portal.xml.
 * Links for other entities are passed to the DefaultLinkService to be resolved.
 *
 * @author Ralph Goers
 *
 * @version CVS $Id:$
 */
public class PageLabelLinkService extends DefaultLinkService {

    protected String apectName;

    /** The label manager */
    protected PageLabelManager labelManager;

    /* (non-Javadoc)
    * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
    */
    public void service(ServiceManager manager) throws ServiceException {
        super.service(manager);
        this.labelManager = (PageLabelManager)this.manager.lookup(PageLabelManager.ROLE);
    }

    /**
     * Get the uri for the coplet containing event
     *
     * @param event The event to find
     * @return A URI
     */
    public String getLinkURI(Event event) {
        return getLinkURI(event, null);
    }

    /**
     * Get the uri for the coplet containing event
     *
     * @param event The event to find
     * @param secure true if a secure protocol is required, false otherwise.
     * @return A URI
     */
    public String getLinkURI(Event event, Boolean secure) {
        if (event == null) {
            return this.getRefreshLinkURI();
        }
        if (this.labelManager == null) {
            return super.getLinkURI(event);
        }

        String requestParameterName = this.labelManager.getRequestParameterName();

        if (event instanceof ChangeAspectDataEvent &&
            ((ChangeAspectDataEvent) event).getTarget() instanceof CompositeLayout) {

            ChangeAspectDataEvent e = (ChangeAspectDataEvent)event;
            CompositeLayout layout = (CompositeLayout)e.getTarget();
            int i = ((Integer)e.getData()).intValue();

            Item item = layout.getItem(i);
            if (item instanceof NamedItem) {
                StringBuffer key = new StringBuffer("");
                getKey(item, key);

                if (this.labelManager.getPageLabelEvents(key.toString()) != null) {
                    final Info info = this.getInfo();
                    boolean hasParams = info.hasParameters;
                    final StringBuffer buffer = new StringBuffer(info.getBase(secure));
                    if (hasParams) {
                        buffer.append('&');
                    }
                    else {
                        buffer.append('?');
                    }
                    try {
                        String encodedKey = NetUtils.encode(key.toString(), "utf-8");
                        buffer.append(requestParameterName).append('=').append(encodedKey);
                    } catch (UnsupportedEncodingException uee) {
                        // ignore this as utf-8 is always supported
                    }
                    return buffer.toString();
                }
            }
        }

        String label = this.labelManager.getCurrentLabel();
        /**
         * Start Angelo modification.
         * @todo CHECK THIS CORRECTION.
         */
        String linkPageLabel = null;
        if( (label != null) && (event instanceof org.apache.cocoon.portal.event.impl.CopletJXPathEvent) ){
            //take the eventValue.
            String eventValue = (String) (((org.apache.cocoon.portal.event.impl.
                                            CopletJXPathEvent) (event)).
                                          getValue());
            try{
                linkPageLabel = getPageLabelValue(eventValue);
            }catch( Exception e ){

                if( (e instanceof IllegalArgumentException)&&(((IllegalArgumentException)(e)).getMessage().equalsIgnoreCase( "No pageLabel present" )) ){

                    linkPageLabel = label;
                }
            }
            if (!linkPageLabel.equalsIgnoreCase(label)) {

                return getLink(super.getLinkURI(event, secure), requestParameterName, linkPageLabel);
            }
        }
        return getLink(super.getLinkURI(event, secure), requestParameterName, label);
    }

    private String getPageLabelValue( String aString ){

        if( aString.indexOf( "pageLabel=" ) == -1 ){

            throw new IllegalArgumentException( "No pageLabel present" );
        }
        //Get the pageLabel value.
        StringBuffer result = new StringBuffer( aString );
        int finalDeleteIndex = result.indexOf( "pageLabel=" )+"pageLabel=".length();
        result = result.delete( 0, finalDeleteIndex );
        return result.toString();
    }

    /**
     * Get the uri for this coplet containing the additional events.
     *
     * @param events The events that will be processed by the generated uri.
     * @return A URI
     */
    public String getLinkURI(List events) {
        return getLinkURI(events, null);
    }

    /**
     * Get the uri for this coplet containing the additional events.
     *
     * @param events The events that will be processed by the generated uri.
     * @return A URI
     */
    public String getLinkURI(List events, Boolean secure) {
        if (events == null || events.size() == 0) {
            return this.getRefreshLinkURI();
        }
        if (this.labelManager == null) {
            return super.getLinkURI(events);
        }

        String requestParameterName = this.labelManager.getRequestParameterName();
        final Info info = this.getInfo();
        final StringBuffer buffer = new StringBuffer(info.getBase(secure));
        boolean hasParams = info.hasParameters;
        Iterator iter = events.iterator();
        StringBuffer value = new StringBuffer("");

        while (iter.hasNext())
        {
            Event event = (Event)iter.next();

            if (event instanceof ChangeAspectDataEvent &&
                ((ChangeAspectDataEvent) event).getTarget() instanceof CompositeLayout) {

                ChangeAspectDataEvent e = (ChangeAspectDataEvent) event;
                CompositeLayout layout = (CompositeLayout) e.getTarget();
                int i = ((Integer) e.getData()).intValue();

                Item item = layout.getItem(i);
                if (value.length() > 0) {
                    value.append('.');
                }
                if (item instanceof NamedItem) {
                    value.append(((NamedItem)item).getName());
                }
                else {
                    value.append(Integer.toString(i));
                }
            }
            else {
                String label = this.labelManager.getCurrentLabel();

                return getLink(super.getLinkURI(events, secure), requestParameterName, label);
            }
        }

        if (value.length() > 0 && this.labelManager.getPageLabelEvents(value.toString()) != null) {
            if (hasParams) {
                buffer.append('&');
            }
            else {
                buffer.append('?');
            }
            try {
                buffer.append(requestParameterName).append('=')
                      .append(NetUtils.encode(value.toString(), "utf-8"));
            } catch (UnsupportedEncodingException uee) {
                // ignore this as utf-8 is always supported
            }

            return buffer.toString();
        }

        String label = this.labelManager.getCurrentLabel();

        return getLink(super.getLinkURI(events), requestParameterName, label);
    }

    /* (non-Javadoc)
    * @see org.apache.avalon.framework.activity.Disposable#dispose()
    */
    public void dispose() {
        if (this.manager != null) {
            if (this.labelManager != null) {
                this.manager.release(this.labelManager);
                this.labelManager = null;
            }
        }
        super.dispose();
    }

    /*
     * Generates the page label.
     * @param item An Item.
     * @param key The StringBuffer in which to create the page label.
     */
    private void getKey(Item item, StringBuffer key) {
        CompositeLayout parentLayout = item.getParent();
        Item parentItem = parentLayout.getParent();

        if (parentItem != null) {
            getKey(parentItem, key);
        }

        if (key.length() > 0) {
            key.append('.');
        }
        if (item instanceof NamedItem) {
            key.append(((NamedItem) item).getName());
        }
        else {
            key.append(parentLayout.getItems().indexOf(item));
        }
    }

    /*
     * Append the page label to the link.
     * @param link The link to add the label to.
     * @param parmName The request parameter name.
     * @param label The page label.
     * @return The modified link.
     */
    private String getLink(String link, String parmName, String label)
    {
        if (label == null) {
            return link;
        }
        StringBuffer uri = new StringBuffer(link);
        if (link.indexOf('?') >= 0) {
            uri.append('&');
        } else {
            uri.append('?');
        }
        try {

            List labelContents = toList( label );

            String encodedLabel = NetUtils.encode((String)(labelContents.get(0)), "utf-8");
            if( labelContents.size() > 1 ){

                List ugList = (List)labelContents.get(1);
                uri.append(parmName).append('=').append(encodedLabel).append( '&' ).append((String)(ugList.get(0))).append( '=' ).append((String)(ugList.get(1)));
            }else{

                uri.append(parmName).append('=').append(encodedLabel);
            }
        } catch (UnsupportedEncodingException uee) {
            // ignore this as utf-8 is always supported
        }
        return uri.toString();
    }

    private Map fromRequest(){

        Map result = Collections.synchronizedMap( new HashMap() );

        CocoonComponentManager man = null;
        Request req = null;
        try {
            man = (CocoonComponentManager)this.manager.lookup(CocoonComponentManager.ROLE);
            req = org.apache.cocoon.environment.ObjectModelHelper.getRequest(man.getCurrentEnvironment().getObjectModel());
            String paramName = null;
            Enumeration enumer = req.getParameterNames();
            while( enumer.hasMoreElements() ){

                paramName = (String)(enumer.nextElement());
                result.put( paramName, req.getParameter( paramName ) );
            }
        } catch (Exception ex) {
        }finally{

            this.manager.release(man);
        }
        return result;
    }
    /**
     * From the label value i have a List in which i have the first element that is the pageLabel value.
     * @param label String
     * @return List
     */
    private List toList( String label ){

        List result = new Vector();
        if( label.indexOf("&") == -1 ){

            result.add( label );
            return result;
        }
        StringTokenizer st = new StringTokenizer( label, "&" );
        List ugList    = new Vector();
        StringTokenizer st1 = null;
        String stToken = null;
        while( st.hasMoreTokens() ){

            stToken = st.nextToken();
            if(stToken.indexOf( "=" ) > -1 ){

                st1 = new StringTokenizer( stToken, "=" );
                while( st1.hasMoreTokens() ){

                    ugList.add( st1.nextToken() );
                }
                result.add( ugList );
                break;
            }
            result.add( stToken );
        }
        return result;
    }
}

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to