Move UploadModule into a 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/ed79f2e4 Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/ed79f2e4 Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/ed79f2e4 Branch: refs/heads/master Commit: ed79f2e48f17f013d011837401f1cb2f0cb7f11c Parents: be8884d Author: Howard M. Lewis Ship <[email protected]> Authored: Mon Apr 22 17:10:46 2013 -0700 Committer: Howard M. Lewis Ship <[email protected]> Committed: Mon Apr 22 17:10:46 2013 -0700 ---------------------------------------------------------------------- tapestry-upload/build.gradle | 2 +- .../tapestry5/upload/modules/UploadModule.java | 122 +++++++++++++++ .../tapestry5/upload/services/UploadModule.java | 121 -------------- .../org/example/upload/services/AppModule.java | 4 +- 4 files changed, 125 insertions(+), 124 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/ed79f2e4/tapestry-upload/build.gradle ---------------------------------------------------------------------- diff --git a/tapestry-upload/build.gradle b/tapestry-upload/build.gradle index d34da2f..b149b46 100644 --- a/tapestry-upload/build.gradle +++ b/tapestry-upload/build.gradle @@ -11,6 +11,6 @@ dependencies { jar { manifest { - attributes 'Tapestry-Module-Classes': 'org.apache.tapestry5.upload.services.UploadModule' + attributes 'Tapestry-Module-Classes': 'org.apache.tapestry5.upload.modules.UploadModule' } } http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/ed79f2e4/tapestry-upload/src/main/java/org/apache/tapestry5/upload/modules/UploadModule.java ---------------------------------------------------------------------- diff --git a/tapestry-upload/src/main/java/org/apache/tapestry5/upload/modules/UploadModule.java b/tapestry-upload/src/main/java/org/apache/tapestry5/upload/modules/UploadModule.java new file mode 100755 index 0000000..c9de59a --- /dev/null +++ b/tapestry-upload/src/main/java/org/apache/tapestry5/upload/modules/UploadModule.java @@ -0,0 +1,122 @@ +// Copyright 2007-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.upload.modules; + +import org.apache.commons.fileupload.FileItemFactory; +import org.apache.commons.fileupload.disk.DiskFileItemFactory; +import org.apache.commons.io.FileCleaner; +import org.apache.tapestry5.internal.InternalConstants; +import org.apache.tapestry5.ioc.Configuration; +import org.apache.tapestry5.ioc.MappedConfiguration; +import org.apache.tapestry5.ioc.OrderedConfiguration; +import org.apache.tapestry5.ioc.ScopeConstants; +import org.apache.tapestry5.ioc.annotations.Autobuild; +import org.apache.tapestry5.ioc.annotations.Scope; +import org.apache.tapestry5.ioc.annotations.Symbol; +import org.apache.tapestry5.ioc.services.PerthreadManager; +import org.apache.tapestry5.ioc.services.RegistryShutdownHub; +import org.apache.tapestry5.services.ComponentEventRequestFilter; +import org.apache.tapestry5.services.HttpServletRequestFilter; +import org.apache.tapestry5.services.LibraryMapping; +import org.apache.tapestry5.upload.internal.services.MultipartDecoderImpl; +import org.apache.tapestry5.upload.internal.services.MultipartServletRequestFilter; +import org.apache.tapestry5.upload.internal.services.UploadExceptionFilter; +import org.apache.tapestry5.upload.services.MultipartDecoder; +import org.apache.tapestry5.upload.services.UploadSymbols; + +import java.io.File; +import java.util.concurrent.atomic.AtomicBoolean; + +public class UploadModule +{ + private static final String NO_LIMIT = "-1"; + + private static final AtomicBoolean needToAddShutdownListener = new AtomicBoolean(true); + + public static void contributeComponentClassResolver(Configuration<LibraryMapping> configuration) + { + // Add the component to the "core" library. + + configuration.add(new LibraryMapping(InternalConstants.CORE_LIBRARY, "org.apache.tapestry5.upload")); + } + + @Scope(ScopeConstants.PERTHREAD) + public static MultipartDecoder buildMultipartDecoder(PerthreadManager perthreadManager, + + RegistryShutdownHub shutdownHub, + + @Autobuild + MultipartDecoderImpl multipartDecoder) + { + // This is proabably overkill since the FileCleaner should catch temporary files, but lets + // be safe. + perthreadManager.addThreadCleanupListener(multipartDecoder); + + if (needToAddShutdownListener.getAndSet(false)) + { + shutdownHub.addRegistryShutdownListener(new Runnable() + { + public void run() + { + FileCleaner.exitWhenFinished(); + } + }); + } + + return multipartDecoder; + } + + /** + * Contributes a filter, "MultipartFilter" after "IgnoredPaths". + */ + public static void contributeHttpServletRequestHandler( + OrderedConfiguration<HttpServletRequestFilter> configuration, MultipartDecoder multipartDecoder) + { + configuration.add("MultipartFilter", new MultipartServletRequestFilter(multipartDecoder), "after:IgnoredPaths"); + } + + /** + * Adds UploadException to the pipeline, between Secure and Ajax (both provided by TapestryModule). UploadException + * is responsible for triggering the {@linkplain org.apache.tapestry5.upload.services.UploadEvents#UPLOAD_EXCEPTION + * upload exception event}. + */ + public static void contributeComponentEventRequestHandler( + OrderedConfiguration<ComponentEventRequestFilter> configuration) + { + configuration.addInstance("UploadException", UploadExceptionFilter.class, "after:Secure", "before:Ajax"); + } + + /** + * The default FileItemFactory used by the MultipartDecoder is + * {@link org.apache.commons.fileupload.disk.DiskFileItemFactory}. + */ + public static FileItemFactory buildDefaultFileItemFactory(@Symbol(UploadSymbols.REPOSITORY_THRESHOLD) + int repositoryThreshold, + + @Symbol(UploadSymbols.REPOSITORY_LOCATION) + String repositoryLocation) + { + return new DiskFileItemFactory(repositoryThreshold, new File(repositoryLocation)); + } + + public static void contributeFactoryDefaults(MappedConfiguration<String, String> configuration) + { + configuration.add(UploadSymbols.REPOSITORY_THRESHOLD, Integer + .toString(DiskFileItemFactory.DEFAULT_SIZE_THRESHOLD)); + configuration.add(UploadSymbols.REPOSITORY_LOCATION, System.getProperty("java.io.tmpdir")); + configuration.add(UploadSymbols.REQUESTSIZE_MAX, NO_LIMIT); + configuration.add(UploadSymbols.FILESIZE_MAX, NO_LIMIT); + } +} http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/ed79f2e4/tapestry-upload/src/main/java/org/apache/tapestry5/upload/services/UploadModule.java ---------------------------------------------------------------------- diff --git a/tapestry-upload/src/main/java/org/apache/tapestry5/upload/services/UploadModule.java b/tapestry-upload/src/main/java/org/apache/tapestry5/upload/services/UploadModule.java deleted file mode 100755 index 9a40b05..0000000 --- a/tapestry-upload/src/main/java/org/apache/tapestry5/upload/services/UploadModule.java +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright 2007, 2008, 2009, 2011 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.upload.services; - -import org.apache.commons.fileupload.FileItemFactory; -import org.apache.commons.fileupload.disk.DiskFileItemFactory; -import org.apache.commons.io.FileCleaner; -import org.apache.tapestry5.internal.InternalConstants; -import org.apache.tapestry5.ioc.Configuration; -import org.apache.tapestry5.ioc.MappedConfiguration; -import org.apache.tapestry5.ioc.OrderedConfiguration; -import org.apache.tapestry5.ioc.ScopeConstants; -import org.apache.tapestry5.ioc.annotations.Autobuild; -import org.apache.tapestry5.ioc.annotations.Scope; -import org.apache.tapestry5.ioc.annotations.Symbol; -import org.apache.tapestry5.ioc.services.PerthreadManager; -import org.apache.tapestry5.ioc.services.RegistryShutdownHub; -import org.apache.tapestry5.ioc.services.RegistryShutdownListener; -import org.apache.tapestry5.services.ComponentEventRequestFilter; -import org.apache.tapestry5.services.HttpServletRequestFilter; -import org.apache.tapestry5.services.LibraryMapping; -import org.apache.tapestry5.upload.internal.services.MultipartDecoderImpl; -import org.apache.tapestry5.upload.internal.services.MultipartServletRequestFilter; -import org.apache.tapestry5.upload.internal.services.UploadExceptionFilter; - -import java.io.File; -import java.util.concurrent.atomic.AtomicBoolean; - -public class UploadModule -{ - private static final String NO_LIMIT = "-1"; - - private static final AtomicBoolean needToAddShutdownListener = new AtomicBoolean(true); - - public static void contributeComponentClassResolver(Configuration<LibraryMapping> configuration) - { - // Add the component to the "core" library. - - configuration.add(new LibraryMapping(InternalConstants.CORE_LIBRARY, "org.apache.tapestry5.upload")); - } - - @Scope(ScopeConstants.PERTHREAD) - public static MultipartDecoder buildMultipartDecoder(PerthreadManager perthreadManager, - - RegistryShutdownHub shutdownHub, - - @Autobuild - MultipartDecoderImpl multipartDecoder) - { - // This is proabably overkill since the FileCleaner should catch temporary files, but lets - // be safe. - perthreadManager.addThreadCleanupListener(multipartDecoder); - - if (needToAddShutdownListener.getAndSet(false)) - { - shutdownHub.addRegistryShutdownListener(new Runnable() - { - public void run() - { - FileCleaner.exitWhenFinished(); - } - }); - } - - return multipartDecoder; - } - - /** - * Contributes a filter, "MultipartFilter" after "IgnoredPaths". - */ - public static void contributeHttpServletRequestHandler( - OrderedConfiguration<HttpServletRequestFilter> configuration, MultipartDecoder multipartDecoder) - { - configuration.add("MultipartFilter", new MultipartServletRequestFilter(multipartDecoder), "after:IgnoredPaths"); - } - - /** - * Adds UploadException to the pipeline, between Secure and Ajax (both provided by TapestryModule). UploadException - * is responsible for triggering the {@linkplain org.apache.tapestry5.upload.services.UploadEvents#UPLOAD_EXCEPTION - * upload exception event}. - */ - public static void contributeComponentEventRequestHandler( - OrderedConfiguration<ComponentEventRequestFilter> configuration) - { - configuration.addInstance("UploadException", UploadExceptionFilter.class, "after:Secure", "before:Ajax"); - } - - /** - * The default FileItemFactory used by the MultipartDecoder is - * {@link org.apache.commons.fileupload.disk.DiskFileItemFactory}. - */ - public static FileItemFactory buildDefaultFileItemFactory(@Symbol(UploadSymbols.REPOSITORY_THRESHOLD) - int repositoryThreshold, - - @Symbol(UploadSymbols.REPOSITORY_LOCATION) - String repositoryLocation) - { - return new DiskFileItemFactory(repositoryThreshold, new File(repositoryLocation)); - } - - public static void contributeFactoryDefaults(MappedConfiguration<String, String> configuration) - { - configuration.add(UploadSymbols.REPOSITORY_THRESHOLD, Integer - .toString(DiskFileItemFactory.DEFAULT_SIZE_THRESHOLD)); - configuration.add(UploadSymbols.REPOSITORY_LOCATION, System.getProperty("java.io.tmpdir")); - configuration.add(UploadSymbols.REQUESTSIZE_MAX, NO_LIMIT); - configuration.add(UploadSymbols.FILESIZE_MAX, NO_LIMIT); - } -} http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/ed79f2e4/tapestry-upload/src/test/java/org/example/upload/services/AppModule.java ---------------------------------------------------------------------- diff --git a/tapestry-upload/src/test/java/org/example/upload/services/AppModule.java b/tapestry-upload/src/test/java/org/example/upload/services/AppModule.java index 6a3e9cc..d376800 100755 --- a/tapestry-upload/src/test/java/org/example/upload/services/AppModule.java +++ b/tapestry-upload/src/test/java/org/example/upload/services/AppModule.java @@ -1,4 +1,4 @@ -// Copyright 2007, 2008 The Apache Software Foundation +// Copyright 2007-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. @@ -17,7 +17,7 @@ package org.example.upload.services; import org.apache.tapestry5.SymbolConstants; import org.apache.tapestry5.ioc.MappedConfiguration; import org.apache.tapestry5.ioc.annotations.SubModule; -import org.apache.tapestry5.upload.services.UploadModule; +import org.apache.tapestry5.upload.modules.UploadModule; import org.apache.tapestry5.upload.services.UploadSymbols; /**
