    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.PageRenderDispatcher;
    019    import org.apache.tapestry5.ioc.annotations.UsesOrderedConfiguration;
    020    import org.apache.tapestry5.services.ComponentEventLinkEncoder;
    021    import org.apache.tapestry5.services.LocalizationSetter;
    022    import org.apache.tapestry5.services.PageRenderRequestParameters;
    023    import org.apache.tapestry5.services.Request;
    024
    025    /**
    026     * Allows the default {@link Link} for a page render request to be replaced.
    027     * This is a service, but also the contribution to the service, as a chain of command.
    028     * <p>
    029     * A contributed implementation of this interface is expected to identify which requests it wants to transform. The
    030     * {@link #transformPageRenderLink(Link, PageRenderRequestParameters)} method can return a {@link Link} that is allowed
    031     * to differ from Tapestry normal default. Later, when that request is triggered,
    032     * {@link #decodePageRenderRequest(Request)} is required to reverse the operation, identifying the original parameters
    033     * so that request handling can continue.
    034     *
    035     * @since 5.2.0
    036     */
    037    @UsesOrderedConfiguration(PageRenderLinkTransformer.class)
    038    public interface PageRenderLinkTransformer
    039    {
    040        /**
    041         * Transforms a page render link.
    042         *
    043         * @param defaultLink
    044         *            default Link for this request
    045         * @param parameters
    046         *            that define the request
    047         * @return replacement Link, or null
    048         */
    049        Link transformPageRenderLink(Link defaultLink, PageRenderRequestParameters parameters);
    050
    051        /**
    052         * Attempts to decode the page render request, to perform the opposite action for
    053         * {@link #transformPageRenderLink(Link, PageRenderRequestParameters)}. The transformer
    054         * is also responsible for identifying the locale in the request (as part of the path, or as a
    055         * query parameter or cookie) and setting the locale for the request.
    056         * <p>
    057         * This method will be invoked from the {@link PageRenderDispatcher} and a non-null value returned from this method
    058         * will prevent the default {@link ComponentEventLinkEncoder#decodePageRenderRequest(Request)} method from being
    059         * invoked.
    060         *
    061         * @return decoded parameters, or null to proceed normally
    062         * @see LocalizationSetter#setLocaleFromLocaleName(String)
    063         */
    064        PageRenderRequestParameters decodePageRenderRequest(Request request);
    065    }