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