    001    // Copyright 2010 The Apache Software Foundation
    002    //
    003    // Licensed under the Apache License, Version 2.0 (the "License");
    004    // you may not use this file except in compliance with the License.
    005    // You may obtain a copy of the License at
    006    //
    007    // http://www.apache.org/licenses/LICENSE-2.0
    008    //
    009    // Unless required by applicable law or agreed to in writing, software
    010    // distributed under the License is distributed on an "AS IS" BASIS,
    011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    012    // See the License for the specific language governing permissions and
    013    // limitations under the License.
    014
    015    package org.apache.tapestry5.services.linktransform;
    016
    017    import org.apache.tapestry5.Link;
    018    import org.apache.tapestry5.internal.services.ComponentEventDispatcher;
    019    import org.apache.tapestry5.ioc.annotations.UsesOrderedConfiguration;
    020    import org.apache.tapestry5.services.ComponentEventRequestParameters;
    021    import org.apache.tapestry5.services.LocalizationSetter;
    022    import org.apache.tapestry5.services.Request;
    023
    024    /**
    025     * Allows for selective replacement of the default {@link Link} used to represent a component event request.
    026     * This is a service, but also the contribution to the service, as a chain of command.
    027     * <p>
    028     * This transformer follows the same pattern as {@link PageRenderLinkTransformer}.
    029     *
    030     * @since 5.2.0
    031     */
    032    @UsesOrderedConfiguration(ComponentEventLinkTransformer.class)
    033    public interface ComponentEventLinkTransformer
    034    {
    035        /**
    036         * Allows the default Link created for the component event request to be replaced.
    037         *
    038         * @param defaultLink
    039         *            the default Link generated for a component event request
    040         * @param parameters
    041         *            used to create the default Link
    042         * @return a replacement Link, or null
    043         */
    044        Link transformComponentEventLink(Link defaultLink, ComponentEventRequestParameters parameters);
    045
    046        /**
    047         * Attempts to decode the page render request, to perform the opposite action for
    048         * {@link #transformComponentEventLink(Link, ComponentEventRequestParameters)}. The transformer
    049         * is also responsible for identifying the locale in the request (as part of the path, or as a
    050         * query parameter or cookie) and setting the locale for the request.
    051         * <p>
    052         * This method will be invoked from the {@link ComponentEventDispatcher} and a non-null value returned from this
    053         * method will prevent the default
    054         * {@link org.apache.tapestry5.services.ComponentEventLinkEncoder#decodeComponentEventRequest(Request)} method
    055         * from being invoked.
    056         *
    057         * @return decoded parameters, or null to proceed normally
    058         * @see LocalizationSetter#setLocaleFromLocaleName(String)
    059         */
    060        ComponentEventRequestParameters decodeComponentEventRequest(Request request);
    061    }