    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.modules;
    014
    015import org.apache.tapestry5.internal.pageload.PageLoaderImpl;
    016import org.apache.tapestry5.internal.services.*;
    017import org.apache.tapestry5.internal.services.ajax.AjaxFormUpdateController;
    018import org.apache.tapestry5.internal.services.javascript.JavaScriptStackPathConstructor;
    019import org.apache.tapestry5.internal.structure.ComponentPageElementResourcesSource;
    020import org.apache.tapestry5.internal.structure.ComponentPageElementResourcesSourceImpl;
    021import org.apache.tapestry5.ioc.MappedConfiguration;
    022import org.apache.tapestry5.ioc.OrderedConfiguration;
    023import org.apache.tapestry5.ioc.ServiceBinder;
    024import org.apache.tapestry5.ioc.annotations.Contribute;
    025import org.apache.tapestry5.ioc.annotations.Marker;
    026import org.apache.tapestry5.services.*;
    027import org.apache.tapestry5.services.transform.ControlledPackageType;
    028
    029import javax.servlet.http.Cookie;
    030
    031import java.util.Map;
    032
    033/**
    034 * {@link org.apache.tapestry5.modules.TapestryModule} has gotten too complicated and it is nice to demarkate public
    035 * (and stable) from internal (and volatile).
    036 */
    037@Marker(Core.class)
    038public class InternalModule
    039{
    040    /**
    041     * Bind all the private/internal services of Tapestry.
    042     */
    043    public static void bind(ServiceBinder binder)
    044    {
    045        binder.bind(PersistentFieldManager.class, PersistentFieldManagerImpl.class);
    046        binder.bind(TemplateParser.class, TemplateParserImpl.class);
    047        binder.bind(PageResponseRenderer.class, PageResponseRendererImpl.class);
    048        binder.bind(PageMarkupRenderer.class, PageMarkupRendererImpl.class);
    049        binder.bind(LinkSource.class, LinkSourceImpl.class);
    050        binder.bind(LocalizationSetter.class, LocalizationSetterImpl.class);
    051        binder.bind(PageElementFactory.class, PageElementFactoryImpl.class);
    052        binder.bind(ResourceStreamer.class, ResourceStreamerImpl.class);
    053        binder.bind(ClientPersistentFieldStorage.class, ClientPersistentFieldStorageImpl.class);
    054        binder.bind(PageRenderQueue.class, PageRenderQueueImpl.class);
    055        binder.bind(AjaxPartialResponseRenderer.class, AjaxPartialResponseRendererImpl.class);
    056        binder.bind(PageContentTypeAnalyzer.class, PageContentTypeAnalyzerImpl.class);
    057        binder.bind(ComponentPageElementResourcesSource.class, ComponentPageElementResourcesSourceImpl.class);
    058        binder.bind(RequestSecurityManager.class, RequestSecurityManagerImpl.class);
    059        binder.bind(InternalRequestGlobals.class, InternalRequestGlobalsImpl.class);
    060        binder.bind(EndOfRequestEventHub.class);
    061        binder.bind(ResponseCompressionAnalyzer.class, ResponseCompressionAnalyzerImpl.class);
    062        binder.bind(ComponentModelSource.class);
    063        binder.bind(JavaScriptStackPathConstructor.class);
    064        binder.bind(AjaxFormUpdateController.class);
    065        binder.bind(ResourceDigestManager.class, ResourceDigestManagerImpl.class);  // Remove in Tapestry 5.5
    066        binder.bind(RequestPageCache.class, RequestPageCacheImpl.class);
    067        binder.bind(ComponentInstantiatorSource.class);
    068        binder.bind(InternalComponentInvalidationEventHub.class);
    069        binder.bind(PageSource.class, PageSourceImpl.class);
    070        binder.bind(PageLoader.class, PageLoaderImpl.class).preventReloading();
    071        binder.bind(UnknownActivationContextHandler.class, UnknownActivationContextHandlerImpl.class);
    072        binder.bind(ReloadHelper.class, ReloadHelperImpl.class);
    073        binder.bind(FormControlNameManager.class, FormControlNameManagerImpl.class);
    074
    075    }
    076
    077    public static CookieSource buildCookieSource(final RequestGlobals requestGlobals)
    078    {
    079        return new CookieSource()
    080        {
    081
    082            public Cookie[] getCookies()
    083            {
    084                return requestGlobals.getHTTPServletRequest().getCookies();
    085            }
    086        };
    087    }
    088
    089    public static CookieSink buildCookieSink(final RequestGlobals requestGlobals)
    090    {
    091        return new CookieSink()
    092        {
    093
    094            public void addCookie(Cookie cookie)
    095            {
    096                requestGlobals.getHTTPServletResponse().addCookie(cookie);
    097            }
    098        };
    099    }
    100
    101    /**
    102     * Contributes:
    103     * <dl>
    104     * <dt>LinkDecoration (instance of {@link LinkDecorationListener})</dt>
    105     * <dd>Triggers events for notifications about links</dd>
    106     * <dl>
    107     *
    108     * @since 5.2.0
    109     */
    110    public static void contributeLinkSource(OrderedConfiguration<LinkCreationListener2> configuration)
    111    {
    112        configuration.addInstance("LinkDecoration", LinkDecorationListener.class);
    113    }
    114
    115    /**
    116     * Contributes packages identified by {@link ComponentClassResolver#getControlledPackageMapping()}.
    117     *
    118     * @since 5.3
    119     */
    120    @Contribute(ComponentInstantiatorSource.class)
    121    public static void configureControlledPackagesFromComponentClassResolver(
    122            MappedConfiguration<String, ControlledPackageType> configuration, ComponentClassResolver resolver)
    123    {
    124        for (Map.Entry<String, ControlledPackageType> entry : resolver.getControlledPackageMapping().entrySet())
    125        {
    126            configuration.add(entry.getKey(), entry.getValue());
    127        }
    128    }
    129}