All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.struts2.config.DefaultBeanSelectionProvider Maven / Gradle / Ivy

There is a newer version: 6.4.0
Show newest version
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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.struts2.config;

import com.opensymphony.xwork2.ActionProxyFactory;
import com.opensymphony.xwork2.LocaleProviderFactory;
import com.opensymphony.xwork2.LocalizedTextProvider;
import com.opensymphony.xwork2.TextProviderFactory;
import com.opensymphony.xwork2.factory.UnknownHandlerFactory;
import com.opensymphony.xwork2.security.AcceptedPatternsChecker;
import com.opensymphony.xwork2.security.ExcludedPatternsChecker;
import com.opensymphony.xwork2.FileManager;
import com.opensymphony.xwork2.FileManagerFactory;
import com.opensymphony.xwork2.ObjectFactory;
import com.opensymphony.xwork2.TextProvider;
import com.opensymphony.xwork2.UnknownHandlerManager;
import com.opensymphony.xwork2.XWorkConstants;
import com.opensymphony.xwork2.conversion.ConversionAnnotationProcessor;
import com.opensymphony.xwork2.conversion.ConversionFileProcessor;
import com.opensymphony.xwork2.conversion.ConversionPropertiesProcessor;
import com.opensymphony.xwork2.conversion.ObjectTypeDeterminer;
import com.opensymphony.xwork2.conversion.TypeConverterCreator;
import com.opensymphony.xwork2.conversion.TypeConverterHolder;
import com.opensymphony.xwork2.conversion.impl.ArrayConverter;
import com.opensymphony.xwork2.conversion.impl.CollectionConverter;
import com.opensymphony.xwork2.conversion.impl.DateConverter;
import com.opensymphony.xwork2.conversion.impl.NumberConverter;
import com.opensymphony.xwork2.conversion.impl.StringConverter;
import com.opensymphony.xwork2.conversion.impl.XWorkConverter;
import com.opensymphony.xwork2.factory.ActionFactory;
import com.opensymphony.xwork2.factory.ConverterFactory;
import com.opensymphony.xwork2.factory.InterceptorFactory;
import com.opensymphony.xwork2.factory.ResultFactory;
import com.opensymphony.xwork2.factory.ValidatorFactory;
import com.opensymphony.xwork2.inject.ContainerBuilder;
import com.opensymphony.xwork2.inject.Scope;
import com.opensymphony.xwork2.util.PatternMatcher;
import com.opensymphony.xwork2.util.TextParser;
import com.opensymphony.xwork2.util.ValueStackFactory;
import com.opensymphony.xwork2.util.location.LocatableProperties;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import com.opensymphony.xwork2.util.reflection.ReflectionContextFactory;
import com.opensymphony.xwork2.util.reflection.ReflectionProvider;
import com.opensymphony.xwork2.validator.ActionValidatorManager;
import org.apache.struts2.StrutsConstants;
import org.apache.struts2.components.UrlRenderer;
import org.apache.struts2.dispatcher.DispatcherErrorHandler;
import org.apache.struts2.dispatcher.StaticContentLoader;
import org.apache.struts2.dispatcher.mapper.ActionMapper;
import org.apache.struts2.dispatcher.multipart.MultiPartRequest;
import org.apache.struts2.util.ContentTypeMatcher;
import org.apache.struts2.views.freemarker.FreemarkerManager;
import org.apache.struts2.views.util.UrlHelper;
import org.apache.struts2.views.velocity.VelocityManager;

/**
 * Selects the implementations of key framework extension points, using the loaded
 * property constants.  The implementations are selected from the container builder
 * using the name defined in its associated property.  The default implementation name will
 * always be "struts".
 *
 * 

* The following is a list of the allowed extension points: * * *

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
TypePropertyScopeDescription
com.opensymphony.xwork2.ObjectFactorystruts.objectFactorysingletonCreates actions, results, and interceptors
com.opensymphony.xwork2.factory.ActionFactorystruts.objectFactory.actionFactorysingletonDedicated factory used to create Actions, you can implement/extend existing one instead of defining new ObjectFactory
com.opensymphony.xwork2.factory.ResultFactorystruts.objectFactory.resultFactorysingletonDedicated factory used to create Results, you can implement/extend existing one instead of defining new ObjectFactory
com.opensymphony.xwork2.factory.InterceptorFactorystruts.objectFactory.interceptorFactorysingletonDedicated factory used to create Interceptors, you can implement/extend existing one instead of defining new ObjectFactory
com.opensymphony.xwork2.factory.ConverterFactorystruts.objectFactory.converterFactorysingletonDedicated factory used to create TypeConverters, you can implement/extend existing one instead of defining new ObjectFactory
com.opensymphony.xwork2.factory.ValidatorFactorystruts.objectFactory.validatorFactorysingletonDedicated factory used to create Validators, you can implement/extend existing one instead of defining new ObjectFactory
com.opensymphony.xwork2.ActionProxyFactorystruts.actionProxyFactorysingletonCreates the ActionProxy
com.opensymphony.xwork2.util.ObjectTypeDeterminerstruts.objectTypeDeterminersingletonDetermines what the key and element class of a Map or Collection should be
org.apache.struts2.dispatcher.mapper.ActionMapperstruts.mapper.classsingletonDetermines the ActionMapping from a request and a URI from an ActionMapping
org.apache.struts2.dispatcher.multipart.MultiPartRequeststruts.multipart.parserper requestParses a multipart request (file upload)
org.apache.struts2.views.freemarker.FreemarkerManagerstruts.freemarker.manager.classnamesingletonLoads and processes Freemarker templates
org.apache.struts2.views.velocity.VelocityManagerstruts.velocity.manager.classnamesingletonLoads and processes Velocity templates
com.opensymphony.xwork2.validator.ActionValidatorManagerstruts.actionValidatorManagersingletonMain interface for validation managers (regular and annotation based). Handles both the loading of * configuration and the actual validation (since 2.1)
com.opensymphony.xwork2.util.ValueStackFactorystruts.valueStackFactorysingletonCreates value stacks (since 2.1)
com.opensymphony.xwork2.reflection.ReflectionProviderstruts.reflectionProvidersingletonProvides reflection services, key place to plug in a custom expression language (since 2.1)
com.opensymphony.xwork2.reflection.ReflectionContextFactorystruts.reflectionContextFactorysingletonCreates reflection context maps used for reflection and expression language operations (since 2.1)
com.opensymphony.xwork2.config.PackageProviderN/AsingletonAll beans registered as PackageProvider implementations will be automatically included in configuration building (since 2.1)
com.opensymphony.xwork2.util.PatternMatcherstruts.patternMatchersingletonMatches patterns, such as action names, generally used in configuration (since 2.1)
org.apache.struts2.views.dispatcher.DefaultStaticContentLoaderstruts.staticContentLoadersingletonLoads static resources (since 2.1)
com.opensymphony.xwork2.conversion.impl.XWorkConverterstruts.xworkConvertersingletonHandles conversion logic and allows to load custom converters per class or per action
com.opensymphony.xwork2.TextProviderstruts.xworkTextProviderdefaultAllows provide custom TextProvider for whole application
com.opensymphony.xwork2.LocaleProviderstruts.localeProvidersingletonDEPRECATED! Allows provide custom TextProvider for whole application - instead this endpoint use struts.localeProviderFactory
com.opensymphony.xwork2.LocaleProviderFactorystruts.localeProviderFactorysingletonAllows provide custom LocaleProvider for whole application
org.apache.struts2.components.UrlRendererstruts.urlRenderersingletonAllows provide custom implementation of environment specific URL rendering/creating class
com.opensymphony.xwork2.UnknownHandlerManagerstruts.unknownHandlerManagersingletonImplementation of this interface allows handle logic of unknown Actions, Methods or Results
org.apache.struts2.views.util.UrlHelperstruts.view.urlHelpersingletonHelper class used with URLRenderer to provide exact logic for building URLs
com.opensymphony.xwork2.FileManagerFactorystruts.fileManagerFactorysingletonUsed to create {@link FileManager} instance to access files on the File System as also to monitor if reload is needed, * can be implemented / overwritten to meet specific an application server needs *
com.opensymphony.xwork2.conversion.impl.CollectionConverterstruts.converter.collectionsingletonConverter used to convert any object to Collection and back
com.opensymphony.xwork2.conversion.impl.ArrayConverterstruts.converter.arraysingletonConverter used to convert any object to Array and back
com.opensymphony.xwork2.conversion.impl.DateConverterstruts.converter.datesingletonConverter used to convert any object to Date and back
com.opensymphony.xwork2.conversion.impl.NumberConverterstruts.converter.numbersingletonConverter used to convert any object to Number and back
com.opensymphony.xwork2.conversion.impl.StringConverterstruts.converter.stringsingletonConverter used to convert any object to String and back
com.opensymphony.xwork2.conversion.ConversionPropertiesProcessorstruts.conversion.properties.processorsingletonProcess Properties to create converters
com.opensymphony.xwork2.conversion.ConversionPropertiesProcessorstruts.converter.file.processorsingletonProcess <class>-conversion.properties file create converters</class>
com.opensymphony.xwork2.conversion.ConversionAnnotationProcessorstruts.converter.annotation.processorsingletonProcess TypeConversion annotation to create converters
com.opensymphony.xwork2.conversion.TypeConverterCreatorstruts.converter.creatorsingletonCreates user converters
com.opensymphony.xwork2.conversion.TypeConverterHolderstruts.converter.holdersingletonHolds user converters' instances
com.opensymphony.xwork2.util.TextParserstruts.expression.parsersingletonUsed to parse expressions like ${foo.bar} or %{bar.foo} but it is up tp the TextParser's * implementation what kind of opening char to use (#, $, %, etc)
com.opensymphony.xwork2.ExcludedPatternsCheckerstruts.excludedPatterns.checkerrequestUsed across different interceptors to check if given string matches one of the excluded patterns
com.opensymphony.xwork2.AcceptedPatternsCheckerstruts.acceptedPatterns.checkerrequestUsed across different interceptors to check if given string matches one of the accepted patterns
org.apache.struts2.util.ContentTypeMatcherstruts.contentTypeMatchersingletonMatches content type of uploaded files (since 2.3.22)
com.opensymphony.xwork2.LocalizedTextProviderstruts.localizedTextProvidersingletonProvides access to resource bundles used to localise messages (since 2.5.11)
* * * *

* Implementations are selected using the value of its associated property. That property is * used to determine the implementation by: *

* *
    *
  1. Trying to find an existing bean by that name in the container
  2. *
  3. Trying to find a class by that name, then creating a new bean factory for it
  4. *
  5. Creating a new delegation bean factory that delegates to the configured ObjectFactory at runtime
  6. *
* *

* Finally, this class overrides certain properties if dev mode is enabled: *

* *
    *
  • struts.i18n.reload = true
  • *
  • struts.configuration.xml.reload = true
  • *
*/ public class DefaultBeanSelectionProvider extends AbstractBeanSelectionProvider { private static final Logger LOG = LogManager.getLogger(DefaultBeanSelectionProvider.class); public void register(ContainerBuilder builder, LocatableProperties props) { alias(ObjectFactory.class, StrutsConstants.STRUTS_OBJECTFACTORY, builder, props); alias(ActionFactory.class, StrutsConstants.STRUTS_OBJECTFACTORY_ACTIONFACTORY, builder, props); alias(ResultFactory.class, StrutsConstants.STRUTS_OBJECTFACTORY_RESULTFACTORY, builder, props); alias(ConverterFactory.class, StrutsConstants.STRUTS_OBJECTFACTORY_CONVERTERFACTORY, builder, props); alias(InterceptorFactory.class, StrutsConstants.STRUTS_OBJECTFACTORY_INTERCEPTORFACTORY, builder, props); alias(ValidatorFactory.class, StrutsConstants.STRUTS_OBJECTFACTORY_VALIDATORFACTORY, builder, props); alias(UnknownHandlerFactory.class, StrutsConstants.STRUTS_OBJECTFACTORY_UNKNOWNHANDLERFACTORY, builder, props); alias(FileManagerFactory.class, StrutsConstants.STRUTS_FILE_MANAGER_FACTORY, builder, props, Scope.SINGLETON); alias(XWorkConverter.class, StrutsConstants.STRUTS_XWORKCONVERTER, builder, props); alias(CollectionConverter.class, StrutsConstants.STRUTS_CONVERTER_COLLECTION, builder, props); alias(ArrayConverter.class, StrutsConstants.STRUTS_CONVERTER_ARRAY, builder, props); alias(DateConverter.class, StrutsConstants.STRUTS_CONVERTER_DATE, builder, props); alias(NumberConverter.class, StrutsConstants.STRUTS_CONVERTER_NUMBER, builder, props); alias(StringConverter.class, StrutsConstants.STRUTS_CONVERTER_STRING, builder, props); alias(ConversionPropertiesProcessor.class, StrutsConstants.STRUTS_CONVERTER_PROPERTIES_PROCESSOR, builder, props); alias(ConversionFileProcessor.class, StrutsConstants.STRUTS_CONVERTER_FILE_PROCESSOR, builder, props); alias(ConversionAnnotationProcessor.class, StrutsConstants.STRUTS_CONVERTER_ANNOTATION_PROCESSOR, builder, props); alias(TypeConverterCreator.class, StrutsConstants.STRUTS_CONVERTER_CREATOR, builder, props); alias(TypeConverterHolder.class, StrutsConstants.STRUTS_CONVERTER_HOLDER, builder, props); alias(TextProvider.class, StrutsConstants.STRUTS_XWORKTEXTPROVIDER, builder, props, Scope.PROTOTYPE); alias(TextProvider.class, StrutsConstants.STRUTS_TEXT_PROVIDER, builder, props, Scope.PROTOTYPE); alias(TextProviderFactory.class, StrutsConstants.STRUTS_TEXT_PROVIDER_FACTORY, builder, props, Scope.PROTOTYPE); alias(LocaleProviderFactory.class, StrutsConstants.STRUTS_LOCALE_PROVIDER_FACTORY, builder, props); alias(LocalizedTextProvider.class, StrutsConstants.STRUTS_LOCALIZED_TEXT_PROVIDER, builder, props); alias(ActionProxyFactory.class, StrutsConstants.STRUTS_ACTIONPROXYFACTORY, builder, props); alias(ObjectTypeDeterminer.class, StrutsConstants.STRUTS_OBJECTTYPEDETERMINER, builder, props); alias(ActionMapper.class, StrutsConstants.STRUTS_MAPPER_CLASS, builder, props); alias(MultiPartRequest.class, StrutsConstants.STRUTS_MULTIPART_PARSER, builder, props, Scope.PROTOTYPE); alias(FreemarkerManager.class, StrutsConstants.STRUTS_FREEMARKER_MANAGER_CLASSNAME, builder, props); alias(VelocityManager.class, StrutsConstants.STRUTS_VELOCITY_MANAGER_CLASSNAME, builder, props); alias(UrlRenderer.class, StrutsConstants.STRUTS_URL_RENDERER, builder, props); alias(ActionValidatorManager.class, StrutsConstants.STRUTS_ACTIONVALIDATORMANAGER, builder, props); alias(ValueStackFactory.class, StrutsConstants.STRUTS_VALUESTACKFACTORY, builder, props); alias(ReflectionProvider.class, StrutsConstants.STRUTS_REFLECTIONPROVIDER, builder, props); alias(ReflectionContextFactory.class, StrutsConstants.STRUTS_REFLECTIONCONTEXTFACTORY, builder, props); alias(PatternMatcher.class, StrutsConstants.STRUTS_PATTERNMATCHER, builder, props); alias(ContentTypeMatcher.class, StrutsConstants.STRUTS_CONTENT_TYPE_MATCHER, builder, props); alias(StaticContentLoader.class, StrutsConstants.STRUTS_STATIC_CONTENT_LOADER, builder, props); alias(UnknownHandlerManager.class, StrutsConstants.STRUTS_UNKNOWN_HANDLER_MANAGER, builder, props); alias(UrlHelper.class, StrutsConstants.STRUTS_URL_HELPER, builder, props); alias(TextParser.class, StrutsConstants.STRUTS_EXPRESSION_PARSER, builder, props); alias(DispatcherErrorHandler.class, StrutsConstants.STRUTS_DISPATCHER_ERROR_HANDLER, builder, props); /** Checker is used mostly in interceptors, so there be one instance of checker per interceptor with Scope.PROTOTYPE **/ alias(ExcludedPatternsChecker.class, StrutsConstants.STRUTS_EXCLUDED_PATTERNS_CHECKER, builder, props, Scope.PROTOTYPE); alias(AcceptedPatternsChecker.class, StrutsConstants.STRUTS_ACCEPTED_PATTERNS_CHECKER, builder, props, Scope.PROTOTYPE); switchDevMode(props); // Convert Struts properties into XWork properties convertIfExist(props, StrutsConstants.STRUTS_LOG_MISSING_PROPERTIES, XWorkConstants.LOG_MISSING_PROPERTIES); convertIfExist(props, StrutsConstants.STRUTS_ENABLE_OGNL_EXPRESSION_CACHE, XWorkConstants.ENABLE_OGNL_EXPRESSION_CACHE); convertIfExist(props, StrutsConstants.STRUTS_ENABLE_OGNL_EVAL_EXPRESSION, XWorkConstants.ENABLE_OGNL_EVAL_EXPRESSION); convertIfExist(props, StrutsConstants.STRUTS_ALLOW_STATIC_METHOD_ACCESS, XWorkConstants.ALLOW_STATIC_METHOD_ACCESS); convertIfExist(props, StrutsConstants.STRUTS_CONFIGURATION_XML_RELOAD, XWorkConstants.RELOAD_XML_CONFIGURATION); convertIfExist(props, StrutsConstants.STRUTS_EXCLUDED_CLASSES, XWorkConstants.OGNL_EXCLUDED_CLASSES); convertIfExist(props, StrutsConstants.STRUTS_EXCLUDED_PACKAGE_NAME_PATTERNS, XWorkConstants.OGNL_EXCLUDED_PACKAGE_NAME_PATTERNS); convertIfExist(props, StrutsConstants.STRUTS_EXCLUDED_PACKAGE_NAMES, XWorkConstants.OGNL_EXCLUDED_PACKAGE_NAMES); convertIfExist(props, StrutsConstants.STRUTS_ADDITIONAL_EXCLUDED_PATTERNS, XWorkConstants.ADDITIONAL_EXCLUDED_PATTERNS); convertIfExist(props, StrutsConstants.STRUTS_ADDITIONAL_ACCEPTED_PATTERNS, XWorkConstants.ADDITIONAL_ACCEPTED_PATTERNS); convertIfExist(props, StrutsConstants.STRUTS_OVERRIDE_EXCLUDED_PATTERNS, XWorkConstants.OVERRIDE_EXCLUDED_PATTERNS); convertIfExist(props, StrutsConstants.STRUTS_OVERRIDE_ACCEPTED_PATTERNS, XWorkConstants.OVERRIDE_ACCEPTED_PATTERNS); } /** * Enables/disables devMode and related settings if they aren't explicit set in struts.xml/struts.properties * * @param props configured properties */ private void switchDevMode(LocatableProperties props) { if ("true".equalsIgnoreCase(props.getProperty(StrutsConstants.STRUTS_DEVMODE))) { if (props.getProperty(StrutsConstants.STRUTS_I18N_RELOAD) == null) { props.setProperty(StrutsConstants.STRUTS_I18N_RELOAD, "true"); } if (props.getProperty(StrutsConstants.STRUTS_CONFIGURATION_XML_RELOAD) == null) { props.setProperty(StrutsConstants.STRUTS_CONFIGURATION_XML_RELOAD, "true"); } if (props.getProperty(StrutsConstants.STRUTS_FREEMARKER_TEMPLATES_CACHE_UPDATE_DELAY) == null) { props.setProperty(StrutsConstants.STRUTS_FREEMARKER_TEMPLATES_CACHE_UPDATE_DELAY, "0"); } // Convert struts properties into ones that xwork expects props.setProperty(XWorkConstants.DEV_MODE, "true"); } else { props.setProperty(XWorkConstants.DEV_MODE, "false"); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy