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