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; 030import java.util.Map; 031 032/** 033 * {@link org.apache.tapestry5.modules.TapestryModule} has gotten too complicated and it is nice to demarkate public 034 * (and stable) from internal (and volatile). 035 */ 036@Marker(Core.class) 037public class InternalModule 038{ 039 /** 040 * Bind all the private/internal services of Tapestry. 041 */ 042 public static void bind(ServiceBinder binder) 043 { 044 binder.bind(PersistentFieldManager.class, PersistentFieldManagerImpl.class); 045 binder.bind(TemplateParser.class, TemplateParserImpl.class); 046 binder.bind(PageResponseRenderer.class, PageResponseRendererImpl.class); 047 binder.bind(PageMarkupRenderer.class, PageMarkupRendererImpl.class); 048 binder.bind(LinkSource.class, LinkSourceImpl.class); 049 binder.bind(LocalizationSetter.class, LocalizationSetterImpl.class); 050 binder.bind(PageElementFactory.class, PageElementFactoryImpl.class); 051 binder.bind(ResourceStreamer.class, ResourceStreamerImpl.class); 052 binder.bind(ClientPersistentFieldStorage.class, ClientPersistentFieldStorageImpl.class); 053 binder.bind(PageRenderQueue.class, PageRenderQueueImpl.class); 054 binder.bind(AjaxPartialResponseRenderer.class, AjaxPartialResponseRendererImpl.class); 055 binder.bind(PageContentTypeAnalyzer.class, PageContentTypeAnalyzerImpl.class); 056 binder.bind(ComponentPageElementResourcesSource.class, ComponentPageElementResourcesSourceImpl.class); 057 binder.bind(RequestSecurityManager.class, RequestSecurityManagerImpl.class); 058 binder.bind(InternalRequestGlobals.class, InternalRequestGlobalsImpl.class); 059 binder.bind(EndOfRequestEventHub.class); 060 binder.bind(ResponseCompressionAnalyzer.class, ResponseCompressionAnalyzerImpl.class); 061 binder.bind(ComponentModelSource.class); 062 binder.bind(JavaScriptStackPathConstructor.class); 063 binder.bind(AjaxFormUpdateController.class); 064 binder.bind(ResourceDigestManager.class, ResourceDigestManagerImpl.class); // Remove in Tapestry 5.5 065 binder.bind(RequestPageCache.class, RequestPageCacheImpl.class); 066 binder.bind(ComponentInstantiatorSource.class); 067 binder.bind(InternalComponentInvalidationEventHub.class); 068 binder.bind(PageSource.class, PageSourceImpl.class); 069 binder.bind(PageLoader.class, PageLoaderImpl.class).preventReloading(); 070 binder.bind(UnknownActivationContextHandler.class, UnknownActivationContextHandlerImpl.class); 071 binder.bind(ReloadHelper.class, ReloadHelperImpl.class); 072 binder.bind(FormControlNameManager.class, FormControlNameManagerImpl.class); 073 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}