001// Copyright 2009, 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
015package org.apache.tapestry5.services;
016
017import org.apache.tapestry5.Link;
018import org.apache.tapestry5.services.linktransform.ComponentEventLinkTransformer;
019import org.apache.tapestry5.services.linktransform.PageRenderLinkTransformer;
020
021/**
022 * Responsible for creating {@link org.apache.tapestry5.Link}s for page render requests and for component event
023 * requests, and for parsing incoming paths to identify requests that are component event or page render requests. This
024 * centralizes some logic that was scattered about in Tapestry 5.0.
025 * 
026 * @since 5.1.0.1
027 */
028public interface ComponentEventLinkEncoder
029{
030    /**
031     * Creates a Link that encapsulates a page render request, including activation context <em>and {@link
032     * org.apache.tapestry5.services.PersistentLocale} (if set)</em>.
033     * Passes the resulting Link through the {@link PageRenderLinkTransformer} chain of command, returning
034     * the result.
035     * 
036     * @param parameters
037     *            defining page to render and context
038     * @return link for the page render
039     */
040    Link createPageRenderLink(PageRenderRequestParameters parameters);
041
042    /**
043     * Creates a link that encapsulates a component event request, including <em>{@link
044     * org.apache.tapestry5.services.PersistentLocale} (if set)</em>.
045     * <p>
046     * Forms:
047     * <ul>
048     * <li>/context/pagename:eventname -- event on the page, no action context</li>
049     * <li>/context/pagename:eventname/foo/bar -- event on the page with action context "foo", "bar"</li>
050     * <li>/context/pagename.foo.bar -- event on component foo.bar within the page, default event, no action context</li>
051     * <li>/context/pagename.foo.bar/baz.gnu -- event on component foo.bar within the page, default event, with action
052     * context "baz", "gnu"</li>
053     * <li>/context/pagename.bar.baz:eventname/foo/gnu -- event on component bar.baz within the page with action context
054     * "foo" , "gnu"</li>
055     * </ul>
056     * <p/>
057     * The persistent locale may be placed in between the context name and the page name, i.e., "/context/fr/SomePage".
058     * <p/>
059     * In many cases the context name is blank, so the path begins with a "/" and then the locale name or page name.
060     * <p/>
061     * The page name portion may itself consist of a series of folder names, i.e., "admin/user/create". The context
062     * portion isn't the concern of this code, since {@link org.apache.tapestry5.services.Request#getPath()} will
063     * already have stripped that off. We can act as if the context is always "/" (the path always starts with a slash).
064     * <p/>
065     * Passes the resulting Link through the {@link ComponentEventLinkTransformer} chain of command, returning the
066     * result.
067     * 
068     * @param parameters
069     *            defining page, component, activation context and other details
070     * @param forForm
071     *            true if the event link will trigger a form submission
072     * @return link for the component event
073     */
074    Link createComponentEventLink(ComponentEventRequestParameters parameters, boolean forForm);
075
076    /**
077     * Checks the request, primarily the {@linkplain org.apache.tapestry5.services.Request#getPath() path}, to determine
078     * the if the request is a component event request. As a side-effect (necessary for historical reasons), responsible
079     * for setting the locale for the thread, including the {@link org.apache.tapestry5.services.PersistentLocale} ...
080     * but only if the locale is a component event.
081     * 
082     * @param request
083     *            incoming request
084     * @return component event request details, if a component event request
085     */
086    ComponentEventRequestParameters decodeComponentEventRequest(Request request);
087
088    /**
089     * Checks the request, primarily the {@linkplain org.apache.tapestry5.services.Request#getPath() path}, to determine
090     * the if the request is a page render request. As a side-effect (necessary for historical reasons), responsible for
091     * setting the locale for the thread, including the {@link org.apache.tapestry5.services.PersistentLocale} ... but
092     * only if the request is a page render.
093     * 
094     * @param request
095     *            incoming request
096     * @return page render request details, if a page render request
097     */
098    PageRenderRequestParameters decodePageRenderRequest(Request request);
099}