Move Module classes in tapestry-core to the modules package
Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/e764c95b Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/e764c95b Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/e764c95b Branch: refs/heads/master Commit: e764c95bf1c3efbc58f978f953b7f175335fff07 Parents: 83167df Author: Howard M. Lewis Ship <[email protected]> Authored: Sat Apr 20 15:30:20 2013 -0400 Committer: Howard M. Lewis Ship <[email protected]> Committed: Sat Apr 20 15:30:20 2013 -0400 ---------------------------------------------------------------------- .../src/main/resources/log4j.properties | 2 +- .../clojure/tests/ClojureBuilderSpec.groovy | 2 +- .../tapestry5/internal/TapestryAppInitializer.java | 4 +- .../internal/services/InternalModule.java | 125 - .../org/apache/tapestry5/modules/AssetsModule.java | 295 ++ .../tapestry5/modules/CompatibilityModule.java | 35 + .../apache/tapestry5/modules/DashboardModule.java | 37 + .../apache/tapestry5/modules/InternalModule.java | 126 + .../apache/tapestry5/modules/JavaScriptModule.java | 301 ++ .../apache/tapestry5/modules/PageLoadModule.java | 39 + .../apache/tapestry5/modules/TapestryModule.java | 2588 ++++++++++++++ .../apache/tapestry5/services/BeanBlockSource.java | 4 +- .../tapestry5/services/MarkupRendererFilter.java | 4 +- .../services/PartialMarkupRendererFilter.java | 4 +- .../apache/tapestry5/services/TapestryModule.java | 2592 --------------- .../tapestry5/services/assets/AssetsModule.java | 294 -- .../compatibility/CompatibilityModule.java | 33 - .../services/dashboard/DashboardModule.java | 35 - .../services/javascript/JavaScriptModule.java | 300 -- .../services/pageload/PageLoadModule.java | 37 - .../ComponentInstantiatorSourceImplTest.java | 4 +- .../internal/test/InternalBaseTestCase.java | 1 + .../tapestry5/ioc/internal/RegistryImpl.java | 1 + .../services/metrics/MetricCollectorImpl.java | 5 +- .../ioc/specs/ClassNameLocatorImplSpec.groovy | 5 +- .../src/test/resources/log4j.properties | 4 +- .../src/test/resources/log4j.properties | 4 +- 27 files changed, 3444 insertions(+), 3437 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/e764c95b/quickstart/filtered/archetype-resources/src/main/resources/log4j.properties ---------------------------------------------------------------------- diff --git a/quickstart/filtered/archetype-resources/src/main/resources/log4j.properties b/quickstart/filtered/archetype-resources/src/main/resources/log4j.properties index f830807..54d0f18 100644 --- a/quickstart/filtered/archetype-resources/src/main/resources/log4j.properties +++ b/quickstart/filtered/archetype-resources/src/main/resources/log4j.properties @@ -13,7 +13,7 @@ log4j.appender.A1.layout.ConversionPattern=[%p] %c{2} %m%n log4j.category.${package}.services.AppModule.TimingFilter=info # Outputs a list of pages, components and mixins at startup. -log4j.category.org.apache.tapestry5.services.TapestryModule.ComponentClassResolver=info +log4j.category.org.apache.tapestry5.modules.TapestryModule.ComponentClassResolver=info # Outputs startup statistics; elapsed time to setup and initialize the registry, a list of # available services, and a launch banner that includes the Tapestry version number. http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/e764c95b/tapestry-clojure/src/test/groovy/org/apache/tapestry5/clojure/tests/ClojureBuilderSpec.groovy ---------------------------------------------------------------------- diff --git a/tapestry-clojure/src/test/groovy/org/apache/tapestry5/clojure/tests/ClojureBuilderSpec.groovy b/tapestry-clojure/src/test/groovy/org/apache/tapestry5/clojure/tests/ClojureBuilderSpec.groovy index 1563c4b..efee763 100644 --- a/tapestry-clojure/src/test/groovy/org/apache/tapestry5/clojure/tests/ClojureBuilderSpec.groovy +++ b/tapestry-clojure/src/test/groovy/org/apache/tapestry5/clojure/tests/ClojureBuilderSpec.groovy @@ -3,7 +3,7 @@ package org.apache.tapestry5.clojure.tests import org.apache.tapestry5.clojure.ClojureModule import org.apache.tapestry5.ioc.Registry import org.apache.tapestry5.ioc.RegistryBuilder -import org.apache.tapestry5.services.TapestryModule +import org.apache.tapestry5.modules.TapestryModule import spock.lang.AutoCleanup import spock.lang.Shared import spock.lang.Specification http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/e764c95b/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryAppInitializer.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryAppInitializer.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryAppInitializer.java index 730f179..74a63af 100644 --- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryAppInitializer.java +++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryAppInitializer.java @@ -1,4 +1,4 @@ -// Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012 The Apache Software Foundation +// Copyright 2006-2013 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ import org.apache.tapestry5.ioc.def.ContributionDef; import org.apache.tapestry5.ioc.def.ModuleDef; import org.apache.tapestry5.ioc.internal.util.InternalUtils; import org.apache.tapestry5.ioc.services.*; -import org.apache.tapestry5.services.TapestryModule; +import org.apache.tapestry5.modules.TapestryModule; import org.slf4j.Logger; import java.util.Formatter; http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/e764c95b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/InternalModule.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/InternalModule.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/InternalModule.java deleted file mode 100644 index e3911fa..0000000 --- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/InternalModule.java +++ /dev/null @@ -1,125 +0,0 @@ -// Copyright 2008, 2009, 2010, 2011, 2012 The Apache Software Foundation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package org.apache.tapestry5.internal.services; - -import org.apache.tapestry5.internal.pageload.PageLoaderImpl; -import org.apache.tapestry5.internal.services.ajax.AjaxFormUpdateController; -import org.apache.tapestry5.internal.services.javascript.JavaScriptStackPathConstructor; -import org.apache.tapestry5.internal.structure.ComponentPageElementResourcesSource; -import org.apache.tapestry5.internal.structure.ComponentPageElementResourcesSourceImpl; -import org.apache.tapestry5.ioc.MappedConfiguration; -import org.apache.tapestry5.ioc.OrderedConfiguration; -import org.apache.tapestry5.ioc.ServiceBinder; -import org.apache.tapestry5.ioc.annotations.Contribute; -import org.apache.tapestry5.ioc.annotations.Marker; -import org.apache.tapestry5.services.*; -import org.apache.tapestry5.services.transform.ControlledPackageType; - -import javax.servlet.http.Cookie; -import java.util.Map; - -/** - * {@link org.apache.tapestry5.services.TapestryModule} has gotten too complicated and it is nice to demarkate public - * (and stable) from internal (and volatile). - */ -@Marker(Core.class) -public class InternalModule -{ - /** - * Bind all the private/internal services of Tapestry. - */ - public static void bind(ServiceBinder binder) - { - binder.bind(PersistentFieldManager.class, PersistentFieldManagerImpl.class); - binder.bind(TemplateParser.class, TemplateParserImpl.class); - binder.bind(PageResponseRenderer.class, PageResponseRendererImpl.class); - binder.bind(PageMarkupRenderer.class, PageMarkupRendererImpl.class); - binder.bind(LinkSource.class, LinkSourceImpl.class); - binder.bind(LocalizationSetter.class, LocalizationSetterImpl.class); - binder.bind(PageElementFactory.class, PageElementFactoryImpl.class); - binder.bind(ResourceStreamer.class, ResourceStreamerImpl.class); - binder.bind(ClientPersistentFieldStorage.class, ClientPersistentFieldStorageImpl.class); - binder.bind(PageRenderQueue.class, PageRenderQueueImpl.class); - binder.bind(AjaxPartialResponseRenderer.class, AjaxPartialResponseRendererImpl.class); - binder.bind(PageContentTypeAnalyzer.class, PageContentTypeAnalyzerImpl.class); - binder.bind(ComponentPageElementResourcesSource.class, ComponentPageElementResourcesSourceImpl.class); - binder.bind(RequestSecurityManager.class, RequestSecurityManagerImpl.class); - binder.bind(InternalRequestGlobals.class, InternalRequestGlobalsImpl.class); - binder.bind(EndOfRequestEventHub.class); - binder.bind(ResponseCompressionAnalyzer.class, ResponseCompressionAnalyzerImpl.class); - binder.bind(ComponentModelSource.class); - binder.bind(JavaScriptStackPathConstructor.class); - binder.bind(AjaxFormUpdateController.class); - binder.bind(ResourceDigestManager.class, ResourceDigestManagerImpl.class); // Remove in Tapestry 5.5 - binder.bind(RequestPageCache.class, RequestPageCacheImpl.class); - binder.bind(ComponentInstantiatorSource.class); - binder.bind(InternalComponentInvalidationEventHub.class); - binder.bind(PageSource.class, PageSourceImpl.class); - binder.bind(PageLoader.class, PageLoaderImpl.class).preventReloading(); - } - - public static CookieSource buildCookieSource(final RequestGlobals requestGlobals) - { - return new CookieSource() - { - - public Cookie[] getCookies() - { - return requestGlobals.getHTTPServletRequest().getCookies(); - } - }; - } - - public static CookieSink buildCookieSink(final RequestGlobals requestGlobals) - { - return new CookieSink() - { - - public void addCookie(Cookie cookie) - { - requestGlobals.getHTTPServletResponse().addCookie(cookie); - } - }; - } - - /** - * Contributes: - * <dl> - * <dt>LinkDecoration (instance of {@link LinkDecorationListener})</dt> - * <dd>Triggers events for notifications about links</dd> - * <dl> - * - * @since 5.2.0 - */ - public static void contributeLinkSource(OrderedConfiguration<LinkCreationListener2> configuration) - { - configuration.addInstance("LinkDecoration", LinkDecorationListener.class); - } - - /** - * Contributes packages identified by {@link ComponentClassResolver#getControlledPackageMapping()}. - * - * @since 5.3 - */ - @Contribute(ComponentInstantiatorSource.class) - public static void configureControlledPackagesFromComponentClassResolver( - MappedConfiguration<String, ControlledPackageType> configuration, ComponentClassResolver resolver) - { - for (Map.Entry<String, ControlledPackageType> entry : resolver.getControlledPackageMapping().entrySet()) - { - configuration.add(entry.getKey(), entry.getValue()); - } - } -} http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/e764c95b/tapestry-core/src/main/java/org/apache/tapestry5/modules/AssetsModule.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/modules/AssetsModule.java b/tapestry-core/src/main/java/org/apache/tapestry5/modules/AssetsModule.java new file mode 100644 index 0000000..98bc2c4 --- /dev/null +++ b/tapestry-core/src/main/java/org/apache/tapestry5/modules/AssetsModule.java @@ -0,0 +1,295 @@ +// Copyright 2011, 2012, 2013 The Apache Software Foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.apache.tapestry5.modules; + +import org.apache.tapestry5.SymbolConstants; +import org.apache.tapestry5.internal.AssetConstants; +import org.apache.tapestry5.internal.InternalConstants; +import org.apache.tapestry5.internal.services.*; +import org.apache.tapestry5.internal.services.assets.*; +import org.apache.tapestry5.internal.services.messages.ClientLocalizationMessageResource; +import org.apache.tapestry5.ioc.*; +import org.apache.tapestry5.ioc.annotations.*; +import org.apache.tapestry5.ioc.services.FactoryDefaults; +import org.apache.tapestry5.ioc.services.SymbolProvider; +import org.apache.tapestry5.services.*; +import org.apache.tapestry5.services.assets.*; +import org.apache.tapestry5.services.messages.ComponentMessagesSource; + +import java.util.Map; + +/** + * @since 5.3 + */ +@Marker(Core.class) +public class AssetsModule +{ + public static void bind(ServiceBinder binder) + { + binder.bind(AssetFactory.class, ClasspathAssetFactory.class).withSimpleId(); + binder.bind(AssetPathConverter.class, IdentityAssetPathConverter.class); + binder.bind(AssetPathConstructor.class, AssetPathConstructorImpl.class); + binder.bind(ClasspathAssetAliasManager.class, ClasspathAssetAliasManagerImpl.class); + binder.bind(AssetSource.class, AssetSourceImpl.class); + binder.bind(StreamableResourceSource.class, StreamableResourceSourceImpl.class); + binder.bind(CompressionAnalyzer.class, CompressionAnalyzerImpl.class); + binder.bind(ContentTypeAnalyzer.class, ContentTypeAnalyzerImpl.class); + binder.bind(ResourceChangeTracker.class, ResourceChangeTrackerImpl.class); + binder.bind(ResourceMinimizer.class, MasterResourceMinimizer.class); + binder.bind(AssetChecksumGenerator.class, AssetChecksumGeneratorImpl.class); + binder.bind(JavaScriptStackAssembler.class, JavaScriptStackAssemblerImpl.class); + } + + @Contribute(AssetSource.class) + public void configureStandardAssetFactories(MappedConfiguration<String, AssetFactory> configuration, + @ContextProvider + AssetFactory contextAssetFactory, + + @ClasspathProvider + AssetFactory classpathAssetFactory) + { + configuration.add(AssetConstants.CONTEXT, contextAssetFactory); + configuration.add(AssetConstants.CLASSPATH, classpathAssetFactory); + } + + + @Contribute(SymbolProvider.class) + @FactoryDefaults + public static void setupSymbols(MappedConfiguration<String, Object> configuration) + { + // Minification may be enabled in production mode, but unless a minimizer is provided, nothing + // will change. + configuration.add(SymbolConstants.MINIFICATION_ENABLED, SymbolConstants.PRODUCTION_MODE_VALUE); + configuration.add(SymbolConstants.GZIP_COMPRESSION_ENABLED, true); + configuration.add(SymbolConstants.COMBINE_SCRIPTS, SymbolConstants.PRODUCTION_MODE_VALUE); + configuration.add(SymbolConstants.ASSET_URL_FULL_QUALIFIED, false); + + configuration.add(SymbolConstants.ASSET_PATH_PREFIX, "asset"); + configuration.add(SymbolConstants.COMPRESSED_ASSET_PATH_PREFIX, "${tapestry.asset-path-prefix}.gz"); + } + + // The use of decorators is to allow third-parties to get their own extensions + // into the pipeline. + + @Decorate(id = "GZipCompression", serviceInterface = StreamableResourceSource.class) + public StreamableResourceSource enableCompression(StreamableResourceSource delegate, + @Symbol(SymbolConstants.GZIP_COMPRESSION_ENABLED) + boolean gzipEnabled, @Symbol(SymbolConstants.MIN_GZIP_SIZE) + int compressionCutoff, + AssetChecksumGenerator checksumGenerator) + { + return gzipEnabled + ? new SRSCompressingInterceptor(delegate, compressionCutoff, checksumGenerator) + : null; + } + + @Decorate(id = "CacheCompressed", serviceInterface = StreamableResourceSource.class) + @Order("before:GZIpCompression") + public StreamableResourceSource enableCompressedCaching(StreamableResourceSource delegate, + @Symbol(SymbolConstants.GZIP_COMPRESSION_ENABLED) + boolean gzipEnabled, ResourceChangeTracker tracker) + { + return gzipEnabled + ? new SRSCompressedCachingInterceptor(delegate, tracker) + : null; + } + + @Decorate(id = "Cache", serviceInterface = StreamableResourceSource.class) + @Order("after:GZipCompression") + public StreamableResourceSource enableUncompressedCaching(StreamableResourceSource delegate, + ResourceChangeTracker tracker) + { + return new SRSCachingInterceptor(delegate, tracker); + } + + // Goes after cache, to ensure that what we are caching is the minified version. + @Decorate(id = "Minification", serviceInterface = StreamableResourceSource.class) + @Order("after:Cache") + public StreamableResourceSource enableMinification(StreamableResourceSource delegate, ResourceMinimizer minimizer, + @Symbol(SymbolConstants.MINIFICATION_ENABLED) + boolean enabled) + { + return enabled + ? new SRSMinimizingInterceptor(delegate, minimizer) + : null; + } + + // Ordering this after minification means that the URL replacement happens first; + // then the minification, then the uncompressed caching, then compression, then compressed + // cache. + @Decorate(id = "CSSURLRewrite", serviceInterface = StreamableResourceSource.class) + @Order("after:Minification") + public StreamableResourceSource enableCSSURLRewriting(StreamableResourceSource delegate, + OperationTracker tracker, + AssetSource assetSource, + AssetChecksumGenerator checksumGenerator) + { + return new CSSURLRewriter(delegate, tracker, assetSource, checksumGenerator); + } + + /** + * Adds content types: + * <dl> + * <dt>css</dt> + * <dd>text/css</dd> + * <dt>js</dt> + * <dd>text/javascript</dd> + * <dt>jpg, jpeg</dt> + * <dd>image/jpeg</dd> + * <dt>gif</dt> + * <dd>image/gif</dd> + * <dt>png</dt> + * <dd>image/png</dd> + * <dt>svg</dt> + * <dd>image/svg+xml</dd> + * <dt>swf</dt> + * <dd>application/x-shockwave-flash</dd> + * </dl> + */ + @Contribute(ContentTypeAnalyzer.class) + public void setupDefaultContentTypeMappings(MappedConfiguration<String, String> configuration) + { + configuration.add("css", "text/css"); + configuration.add("js", "text/javascript"); + configuration.add("gif", "image/gif"); + configuration.add("jpg", "image/jpeg"); + configuration.add("jpeg", "image/jpeg"); + configuration.add("png", "image/png"); + configuration.add("swf", "application/x-shockwave-flash"); + configuration.add("svg", "image/svg+xml"); + } + + /** + * Disables compression for the following content types: + * <ul> + * <li>image/jpeg</li> + * <li>image/gif</li> + * <li>image/png</li> + * <li>application/x-shockwave-flash</li> + * </ul> + */ + @Contribute(CompressionAnalyzer.class) + public void disableCompressionForImageTypes(MappedConfiguration<String, Boolean> configuration) + { + configuration.add("image/jpeg", false); + configuration.add("image/gif", false); + configuration.add("image/png", false); + configuration.add("application/x-shockwave-flash", false); + } + + @Marker(ContextProvider.class) + public static AssetFactory buildContextAssetFactory(ApplicationGlobals globals, + AssetPathConstructor assetPathConstructor, + ResponseCompressionAnalyzer compressionAnalyzer, + ResourceChangeTracker resourceChangeTracker, + StreamableResourceSource streamableResourceSource) + { + return new ContextAssetFactory(compressionAnalyzer, resourceChangeTracker, streamableResourceSource, assetPathConstructor, globals.getContext()); + } + + @Contribute(ClasspathAssetAliasManager.class) + public static void addApplicationAndTapestryMappings(MappedConfiguration<String, String> configuration, + + @Symbol(InternalConstants.TAPESTRY_APP_PACKAGE_PARAM) + String appPackage) + { + configuration.add("tapestry", "org/apache/tapestry5"); + + configuration.add("app", toPackagePath(appPackage)); + } + + /** + * Contributes an handler for each mapped classpath alias, as well handlers for context assets + * and stack assets (combined {@link org.apache.tapestry5.services.javascript.JavaScriptStack} files). + */ + @Contribute(Dispatcher.class) + @AssetRequestDispatcher + public static void provideBuiltinAssetDispatchers(MappedConfiguration<String, AssetRequestHandler> configuration, + + @ContextProvider + AssetFactory contextAssetFactory, + + @Autobuild + StackAssetRequestHandler stackAssetRequestHandler, + + ClasspathAssetAliasManager classpathAssetAliasManager, + ResourceStreamer streamer, + AssetSource assetSource) + { + Map<String, String> mappings = classpathAssetAliasManager.getMappings(); + + for (String folder : mappings.keySet()) + { + String path = mappings.get(folder); + + configuration.add(folder, new ClasspathAssetRequestHandler(streamer, assetSource, path)); + } + + configuration.add(RequestConstants.CONTEXT_FOLDER, + new ContextAssetRequestHandler(streamer, contextAssetFactory.getRootResource())); + + configuration.add(RequestConstants.STACK_FOLDER, stackAssetRequestHandler); + + } + + @Contribute(ClasspathAssetAliasManager.class) + public static void addMappingsForLibraryVirtualFolders(MappedConfiguration<String, String> configuration, + ComponentClassResolver resolver) + { + // Each library gets a mapping or its folder automatically + + Map<String, String> folderToPackageMapping = resolver.getFolderToPackageMapping(); + + for (String folder : folderToPackageMapping.keySet()) + { + // This is the 5.3 version, which is still supported: + configuration.add(folder, toPackagePath(folderToPackageMapping.get(folder))); + + // This is the 5.4 version; once 5.3 support is dropped, this can be simplified, and the + // "meta/" prefix stripped out. + String folderSuffix = folder.equals("") ? folder : "/" + folder; + + configuration.add("meta" + folderSuffix, "META-INF/assets" + folderSuffix); + } + } + + private static String toPackagePath(String packageName) + { + return packageName.replace('.', '/'); + } + + /** + * Contributes: + * <dl> + * <dt>ClientLocalization</dt> + * <dd>A virtual resource of formatting symbols for decimal numbers</dd> + * <dt>Core</dt> + * <dd>Built in messages used by Tapestry's default validators and components</dd> + * <dt>AppCatalog</dt> + * <dd>The Resource defined by {@link SymbolConstants#APPLICATION_CATALOG}</dd> + * <dt> + * + * @since 5.2.0 + */ + @Contribute(ComponentMessagesSource.class) + public static void setupGlobalMessageCatalog(AssetSource assetSource, + @Symbol(SymbolConstants.APPLICATION_CATALOG) + Resource applicationCatalog, OrderedConfiguration<Resource> configuration) + { + configuration.add("ClientLocalization", new ClientLocalizationMessageResource()); + configuration.add("Core", assetSource.resourceForPath("org/apache/tapestry5/core.properties")); + configuration.add("AppCatalog", applicationCatalog); + } +} http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/e764c95b/tapestry-core/src/main/java/org/apache/tapestry5/modules/CompatibilityModule.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/modules/CompatibilityModule.java b/tapestry-core/src/main/java/org/apache/tapestry5/modules/CompatibilityModule.java new file mode 100644 index 0000000..183ac8b --- /dev/null +++ b/tapestry-core/src/main/java/org/apache/tapestry5/modules/CompatibilityModule.java @@ -0,0 +1,35 @@ +// Copyright 2012-2013 The Apache Software Foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.apache.tapestry5.modules; + +import org.apache.tapestry5.internal.services.compatibility.CompatibilityImpl; +import org.apache.tapestry5.internal.services.compatibility.DeprecationWarningImpl; +import org.apache.tapestry5.ioc.ServiceBinder; +import org.apache.tapestry5.services.compatibility.Compatibility; +import org.apache.tapestry5.services.compatibility.DeprecationWarning; + +/** + * Defines services for managing compatibility across releases. + * + * @since 5.4 + */ +public class CompatibilityModule +{ + public static void bind(ServiceBinder binder) + { + binder.bind(Compatibility.class, CompatibilityImpl.class); + binder.bind(DeprecationWarning.class, DeprecationWarningImpl.class); + } +} http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/e764c95b/tapestry-core/src/main/java/org/apache/tapestry5/modules/DashboardModule.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/modules/DashboardModule.java b/tapestry-core/src/main/java/org/apache/tapestry5/modules/DashboardModule.java new file mode 100644 index 0000000..22abd21 --- /dev/null +++ b/tapestry-core/src/main/java/org/apache/tapestry5/modules/DashboardModule.java @@ -0,0 +1,37 @@ +// Copyright 2013 The Apache Software Foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.apache.tapestry5.modules; + +import org.apache.tapestry5.internal.services.dashboard.DashboardManagerImpl; +import org.apache.tapestry5.ioc.OrderedConfiguration; +import org.apache.tapestry5.ioc.ServiceBinder; +import org.apache.tapestry5.ioc.annotations.Contribute; +import org.apache.tapestry5.services.dashboard.DashboardManager; +import org.apache.tapestry5.services.dashboard.DashboardTab; + +public class DashboardModule +{ + public static void bind(ServiceBinder binder) + { + binder.bind(DashboardManager.class, DashboardManagerImpl.class); + } + + @Contribute(DashboardManager.class) + public static void defaultTabs(OrderedConfiguration<DashboardTab> configuration) + { + configuration.add("Pages", new DashboardTab("Pages", "core/PageCatalog")); + configuration.add("Services", new DashboardTab("Services", "core/ServiceStatus")); + } +} http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/e764c95b/tapestry-core/src/main/java/org/apache/tapestry5/modules/InternalModule.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/modules/InternalModule.java b/tapestry-core/src/main/java/org/apache/tapestry5/modules/InternalModule.java new file mode 100644 index 0000000..b78a4ff --- /dev/null +++ b/tapestry-core/src/main/java/org/apache/tapestry5/modules/InternalModule.java @@ -0,0 +1,126 @@ +// Copyright 2008-2013 The Apache Software Foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.apache.tapestry5.modules; + +import org.apache.tapestry5.internal.pageload.PageLoaderImpl; +import org.apache.tapestry5.internal.services.*; +import org.apache.tapestry5.internal.services.ajax.AjaxFormUpdateController; +import org.apache.tapestry5.internal.services.javascript.JavaScriptStackPathConstructor; +import org.apache.tapestry5.internal.structure.ComponentPageElementResourcesSource; +import org.apache.tapestry5.internal.structure.ComponentPageElementResourcesSourceImpl; +import org.apache.tapestry5.ioc.MappedConfiguration; +import org.apache.tapestry5.ioc.OrderedConfiguration; +import org.apache.tapestry5.ioc.ServiceBinder; +import org.apache.tapestry5.ioc.annotations.Contribute; +import org.apache.tapestry5.ioc.annotations.Marker; +import org.apache.tapestry5.services.*; +import org.apache.tapestry5.services.transform.ControlledPackageType; + +import javax.servlet.http.Cookie; +import java.util.Map; + +/** + * {@link org.apache.tapestry5.modules.TapestryModule} has gotten too complicated and it is nice to demarkate public + * (and stable) from internal (and volatile). + */ +@Marker(Core.class) +public class InternalModule +{ + /** + * Bind all the private/internal services of Tapestry. + */ + public static void bind(ServiceBinder binder) + { + binder.bind(PersistentFieldManager.class, PersistentFieldManagerImpl.class); + binder.bind(TemplateParser.class, TemplateParserImpl.class); + binder.bind(PageResponseRenderer.class, PageResponseRendererImpl.class); + binder.bind(PageMarkupRenderer.class, PageMarkupRendererImpl.class); + binder.bind(LinkSource.class, LinkSourceImpl.class); + binder.bind(LocalizationSetter.class, LocalizationSetterImpl.class); + binder.bind(PageElementFactory.class, PageElementFactoryImpl.class); + binder.bind(ResourceStreamer.class, ResourceStreamerImpl.class); + binder.bind(ClientPersistentFieldStorage.class, ClientPersistentFieldStorageImpl.class); + binder.bind(PageRenderQueue.class, PageRenderQueueImpl.class); + binder.bind(AjaxPartialResponseRenderer.class, AjaxPartialResponseRendererImpl.class); + binder.bind(PageContentTypeAnalyzer.class, PageContentTypeAnalyzerImpl.class); + binder.bind(ComponentPageElementResourcesSource.class, ComponentPageElementResourcesSourceImpl.class); + binder.bind(RequestSecurityManager.class, RequestSecurityManagerImpl.class); + binder.bind(InternalRequestGlobals.class, InternalRequestGlobalsImpl.class); + binder.bind(EndOfRequestEventHub.class); + binder.bind(ResponseCompressionAnalyzer.class, ResponseCompressionAnalyzerImpl.class); + binder.bind(ComponentModelSource.class); + binder.bind(JavaScriptStackPathConstructor.class); + binder.bind(AjaxFormUpdateController.class); + binder.bind(ResourceDigestManager.class, ResourceDigestManagerImpl.class); // Remove in Tapestry 5.5 + binder.bind(RequestPageCache.class, RequestPageCacheImpl.class); + binder.bind(ComponentInstantiatorSource.class); + binder.bind(InternalComponentInvalidationEventHub.class); + binder.bind(PageSource.class, PageSourceImpl.class); + binder.bind(PageLoader.class, PageLoaderImpl.class).preventReloading(); + } + + public static CookieSource buildCookieSource(final RequestGlobals requestGlobals) + { + return new CookieSource() + { + + public Cookie[] getCookies() + { + return requestGlobals.getHTTPServletRequest().getCookies(); + } + }; + } + + public static CookieSink buildCookieSink(final RequestGlobals requestGlobals) + { + return new CookieSink() + { + + public void addCookie(Cookie cookie) + { + requestGlobals.getHTTPServletResponse().addCookie(cookie); + } + }; + } + + /** + * Contributes: + * <dl> + * <dt>LinkDecoration (instance of {@link LinkDecorationListener})</dt> + * <dd>Triggers events for notifications about links</dd> + * <dl> + * + * @since 5.2.0 + */ + public static void contributeLinkSource(OrderedConfiguration<LinkCreationListener2> configuration) + { + configuration.addInstance("LinkDecoration", LinkDecorationListener.class); + } + + /** + * Contributes packages identified by {@link ComponentClassResolver#getControlledPackageMapping()}. + * + * @since 5.3 + */ + @Contribute(ComponentInstantiatorSource.class) + public static void configureControlledPackagesFromComponentClassResolver( + MappedConfiguration<String, ControlledPackageType> configuration, ComponentClassResolver resolver) + { + for (Map.Entry<String, ControlledPackageType> entry : resolver.getControlledPackageMapping().entrySet()) + { + configuration.add(entry.getKey(), entry.getValue()); + } + } +} http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/e764c95b/tapestry-core/src/main/java/org/apache/tapestry5/modules/JavaScriptModule.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/modules/JavaScriptModule.java b/tapestry-core/src/main/java/org/apache/tapestry5/modules/JavaScriptModule.java new file mode 100644 index 0000000..fd92ecf --- /dev/null +++ b/tapestry-core/src/main/java/org/apache/tapestry5/modules/JavaScriptModule.java @@ -0,0 +1,301 @@ +// Copyright 2012, 2013 The Apache Software Foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.apache.tapestry5.modules; + +import org.apache.tapestry5.MarkupWriter; +import org.apache.tapestry5.SymbolConstants; +import org.apache.tapestry5.annotations.Path; +import org.apache.tapestry5.internal.InternalConstants; +import org.apache.tapestry5.internal.services.DocumentLinker; +import org.apache.tapestry5.internal.services.ajax.JavaScriptSupportImpl; +import org.apache.tapestry5.internal.services.assets.ResourceChangeTracker; +import org.apache.tapestry5.internal.services.javascript.*; +import org.apache.tapestry5.internal.util.MessageCatalogResource; +import org.apache.tapestry5.ioc.MappedConfiguration; +import org.apache.tapestry5.ioc.OrderedConfiguration; +import org.apache.tapestry5.ioc.Resource; +import org.apache.tapestry5.ioc.ServiceBinder; +import org.apache.tapestry5.ioc.annotations.Contribute; +import org.apache.tapestry5.ioc.annotations.Symbol; +import org.apache.tapestry5.ioc.services.FactoryDefaults; +import org.apache.tapestry5.ioc.services.SymbolProvider; +import org.apache.tapestry5.ioc.util.IdAllocator; +import org.apache.tapestry5.json.JSONObject; +import org.apache.tapestry5.services.*; +import org.apache.tapestry5.services.assets.AssetRequestHandler; +import org.apache.tapestry5.services.compatibility.Compatibility; +import org.apache.tapestry5.services.compatibility.Trait; +import org.apache.tapestry5.services.javascript.*; +import org.apache.tapestry5.services.messages.ComponentMessagesSource; + +import java.util.Locale; + +/** + * Defines the services related to JavaScript. + * + * @since 5.4 + */ +public class JavaScriptModule +{ + private final Environment environment; + + private final EnvironmentalShadowBuilder environmentalBuilder; + + public JavaScriptModule(Environment environment, EnvironmentalShadowBuilder environmentalBuilder) + { + this.environment = environment; + this.environmentalBuilder = environmentalBuilder; + } + + public static void bind(ServiceBinder binder) + { + binder.bind(ModuleManager.class, ModuleManagerImpl.class); + binder.bind(JavaScriptStackSource.class, JavaScriptStackSourceImpl.class); + binder.bind(JavaScriptStack.class, ExtensibleJavaScriptStack.class).withMarker(Core.class).withId("CoreJavaScriptStack"); + } + + /** + * Contributes the "core" {@link JavaScriptStack}s + * + * @since 5.2.0 + */ + @Contribute(JavaScriptStackSource.class) + public static void provideBuiltinJavaScriptStacks(MappedConfiguration<String, JavaScriptStack> configuration, @Core JavaScriptStack coreStack) + { + configuration.add(InternalConstants.CORE_STACK_NAME, coreStack); + } + + @Contribute(JavaScriptStack.class) + @Core + public static void setupCoreJavaScriptStack(OrderedConfiguration<StackExtension> configuration, Compatibility compatibility, @Symbol(SymbolConstants.JAVASCRIPT_INFRASTRUCTURE_PROVIDER) String provider) + { + final String ROOT = "${tapestry.asset.root}"; + + if (provider.equals("prototype") && compatibility.enabled(Trait.SCRIPTACULOUS)) + { + add(configuration, StackExtensionType.LIBRARY, + "${tapestry.scriptaculous}/scriptaculous.js", + "${tapestry.scriptaculous}/effects.js"); + } + + if (compatibility.enabled(Trait.INITIALIZERS)) + { + add(configuration, StackExtensionType.LIBRARY, + ROOT + "/t53-compatibility.js" + ); + } + + add(configuration, StackExtensionType.STYLESHEET, + "${tapestry.bootstrap-root}/css/bootstrap.css", + + ROOT + "/tapestry.css", + + ROOT + "/exception-frame.css", + + ROOT + "/tapestry-console.css", + + ROOT + "/tree.css"); + } + + private static void add(OrderedConfiguration<StackExtension> configuration, StackExtensionType type, String... paths) + { + for (String path : paths) + { + int slashx = path.lastIndexOf('/'); + String id = path.substring(slashx + 1); + + configuration.add(id, new StackExtension(type, path)); + } + } + + + /** + * Builds a proxy to the current {@link JavaScriptSupport} inside this thread's {@link org.apache.tapestry5.services.Environment}. + * + * @since 5.2.0 + */ + public JavaScriptSupport buildJavaScriptSupport() + { + return environmentalBuilder.build(JavaScriptSupport.class); + } + + @Contribute(Dispatcher.class) + @AssetRequestDispatcher + public static void provideModuleHandler(MappedConfiguration<String, AssetRequestHandler> configuration) + { + configuration.addInstance("module", ModuleAssetRequestHandler.class); + } + + /** + * Adds page render filters, each of which provides an {@link org.apache.tapestry5.annotations.Environmental} + * service. Filters + * often provide {@link org.apache.tapestry5.annotations.Environmental} services needed by + * components as they render. + * <dl> + * <dt>JavascriptSupport</dt> + * <dd>Provides {@link JavaScriptSupport}</dd> + * </dl> + */ + @Contribute(MarkupRenderer.class) + public void exposeJavaScriptSupportForFullPageRenders(OrderedConfiguration<MarkupRendererFilter> configuration, + final JavaScriptStackSource javascriptStackSource, + final JavaScriptStackPathConstructor javascriptStackPathConstructor) + { + + MarkupRendererFilter javaScriptSupport = new MarkupRendererFilter() + { + public void renderMarkup(MarkupWriter writer, MarkupRenderer renderer) + { + DocumentLinker linker = environment.peekRequired(DocumentLinker.class); + + JavaScriptSupportImpl support = new JavaScriptSupportImpl(linker, javascriptStackSource, + javascriptStackPathConstructor); + + environment.push(JavaScriptSupport.class, support); + + renderer.renderMarkup(writer); + + environment.pop(JavaScriptSupport.class); + + support.commit(); + } + }; + + configuration.add("JavaScriptSupport", javaScriptSupport, "after:DocumentLinker"); + } + + /** + * Contributes {@link PartialMarkupRendererFilter}s used when rendering a + * partial Ajax response. + * <dl> + * <dt>JavaScriptSupport + * <dd>Provides {@link JavaScriptSupport}</dd> + * </dl> + */ + @Contribute(PartialMarkupRenderer.class) + public void exposeJavaScriptSupportForPartialPageRender(OrderedConfiguration<PartialMarkupRendererFilter> configuration, + final JavaScriptStackSource javascriptStackSource, + + final JavaScriptStackPathConstructor javascriptStackPathConstructor) + { + PartialMarkupRendererFilter javascriptSupport = new PartialMarkupRendererFilter() + { + public void renderMarkup(MarkupWriter writer, JSONObject reply, PartialMarkupRenderer renderer) + { + String uid = Long.toHexString(System.nanoTime()); + + String namespace = "_" + uid; + + IdAllocator idAllocator = new IdAllocator(namespace); + + DocumentLinker linker = environment.peekRequired(DocumentLinker.class); + + JavaScriptSupportImpl support = new JavaScriptSupportImpl(linker, javascriptStackSource, + javascriptStackPathConstructor, idAllocator, true); + + environment.push(JavaScriptSupport.class, support); + + renderer.renderMarkup(writer, reply); + + environment.pop(JavaScriptSupport.class); + + support.commit(); + } + }; + + configuration.add("JavaScriptSupport", javascriptSupport, "after:DocumentLinker"); + } + + + @Contribute(ModuleManager.class) + public static void setupBaseModules(MappedConfiguration<String, Object> configuration, + @Path("${tapestry.asset.root}/underscore_1_4_4.js") + Resource underscore, + + @Path("${tapestry.asset.root}/jquery-shim.js") + Resource jqueryShim, + + @Path("${tapestry.scriptaculous}/prototype.js") + Resource prototype, + + @Path("${tapestry.asset.root}/jquery-1.9.1.js") + Resource jQuery, + + @Path("${" + SymbolConstants.BOOTSTRAP_ROOT + "}/js/bootstrap.js") + Resource bootstrap) + { + configuration.add("_", new JavaScriptModuleConfiguration(underscore).exports("_")); + // Hacking around https://github.com/jrburke/requirejs/issues/534 + configuration.add("jquery-library", new JavaScriptModuleConfiguration(jQuery)); + configuration.add("jquery", new JavaScriptModuleConfiguration(jqueryShim)); + configuration.add("prototype", new JavaScriptModuleConfiguration(prototype)); + configuration.add("bootstrap", new JavaScriptModuleConfiguration(bootstrap).dependsOn("jquery")); + } + + @Contribute(SymbolProvider.class) + @FactoryDefaults + public static void declareDefaultJavaScriptInfrastructureProvider(MappedConfiguration<String, Object> configuration) + { + configuration.add(SymbolConstants.JAVASCRIPT_INFRASTRUCTURE_PROVIDER, "prototype"); + } + + @Contribute(ModuleManager.class) + public static void setupFoundationFramework(MappedConfiguration<String, Object> configuration, + @Symbol(SymbolConstants.JAVASCRIPT_INFRASTRUCTURE_PROVIDER) + String provider, + @Path("classpath:org/apache/tapestry5/t5-core-dom-prototype.js") + Resource domPrototype, + @Path("classpath:org/apache/tapestry5/t5-core-dom-jquery.js") + Resource domJQuery) + { + if (provider.equals("prototype")) + { + configuration.add("t5/core/dom", new JavaScriptModuleConfiguration(domPrototype)); + } + + if (provider.equals("jquery")) + { + configuration.add("t5/core/dom", new JavaScriptModuleConfiguration(domJQuery)); + } + + // If someone wants to support a different infastructure, they should set the provider symbol to some other value + // and contribute their own version of the t5/core/dom module. + } + + @Contribute(ModuleManager.class) + public static void setupApplicationCatalogModules(MappedConfiguration<String, Object> configuration, + LocalizationSetter localizationSetter, + ComponentMessagesSource messagesSource, + ResourceChangeTracker resourceChangeTracker, + @Symbol(SymbolConstants.COMPACT_JSON) boolean compactJSON) + { + for (Locale locale : localizationSetter.getSupportedLocales()) + { + MessageCatalogResource resource = new MessageCatalogResource(locale, messagesSource, resourceChangeTracker, compactJSON); + + configuration.add("t5/core/messages/" + locale.toString(), new JavaScriptModuleConfiguration(resource)); + } + } + + /** + * Contributes 'ConfigureHTMLElement', which writes the attributes into the HTML tag to describe locale, etc. + */ + @Contribute(MarkupRenderer.class) + public static void renderLocaleAttributeIntoPages(OrderedConfiguration<MarkupRendererFilter> configuration) + { + configuration.addInstance("ConfigureHTMLElement", ConfigureHTMLElementFilter.class); + } + +} http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/e764c95b/tapestry-core/src/main/java/org/apache/tapestry5/modules/PageLoadModule.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/modules/PageLoadModule.java b/tapestry-core/src/main/java/org/apache/tapestry5/modules/PageLoadModule.java new file mode 100644 index 0000000..b0040ae --- /dev/null +++ b/tapestry-core/src/main/java/org/apache/tapestry5/modules/PageLoadModule.java @@ -0,0 +1,39 @@ +// Copyright 2011-2013 The Apache Software Foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.apache.tapestry5.modules; + +import org.apache.tapestry5.internal.pageload.DefaultComponentRequestSelectorAnalyzer; +import org.apache.tapestry5.internal.pageload.DefaultComponentResourceLocator; +import org.apache.tapestry5.internal.services.ComponentTemplateSource; +import org.apache.tapestry5.internal.services.ComponentTemplateSourceImpl; +import org.apache.tapestry5.ioc.ServiceBinder; +import org.apache.tapestry5.ioc.annotations.Marker; +import org.apache.tapestry5.services.Core; +import org.apache.tapestry5.services.pageload.ComponentRequestSelectorAnalyzer; +import org.apache.tapestry5.services.pageload.ComponentResourceLocator; + +/** + * @since 5.3 + */ +@Marker(Core.class) +public class PageLoadModule +{ + public static void bind(ServiceBinder binder) + { + binder.bind(ComponentRequestSelectorAnalyzer.class, DefaultComponentRequestSelectorAnalyzer.class); + binder.bind(ComponentResourceLocator.class, DefaultComponentResourceLocator.class); + binder.bind(ComponentTemplateSource.class, ComponentTemplateSourceImpl.class); + } +}
