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