Source Code Cross Referenced for ServletContextPropertyPlaceholderConfigurer.java in  » J2EE » spring-framework-2.5 » org » springframework » web » context » support » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » spring framework 2.5 » org.springframework.web.context.support 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2002-2005 the original author or authors.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.springframework.web.context.support;
018:
019:        import java.util.Properties;
020:
021:        import javax.servlet.ServletContext;
022:
023:        import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
024:        import org.springframework.web.context.ServletContextAware;
025:
026:        /**
027:         * Subclass of PropertyPlaceholderConfigurer that resolves placeholders as
028:         * ServletContext init parameters (that is, <code>web.xml</code> context-param
029:         * entries).
030:         *
031:         * <p>Can be combined with "locations" and/or "properties" values in addition
032:         * to web.xml context-params. Alternatively, can be defined without local
033:         * properties, to resolve all placeholders as <code>web.xml</code> context-params
034:         * (or JVM system properties).
035:         *
036:         * <p>If a placeholder could not be resolved against the provided local
037:         * properties within the application, this configurer will fall back to
038:         * ServletContext parameters. Can also be configured to let ServletContext
039:         * init parameters override local properties (contextOverride=true).
040:         *
041:         * <p>Optionally supports searching for ServletContext <i>attributes</i>: If turned
042:         * on, an otherwise unresolvable placeholder will matched against the corresponding
043:         * ServletContext attribute, using its stringified value if found. This can be
044:         * used to feed dynamic values into Spring's placeholder resolution.
045:         *
046:         * <p>If not running within a WebApplicationContext (or any other context that
047:         * is able to satisfy the ServletContextAware callback), this class will behave
048:         * like the default PropertyPlaceholderConfigurer. This allows for keeping
049:         * ServletContextPropertyPlaceholderConfigurer definitions in test suites.
050:         *
051:         * @author Juergen Hoeller
052:         * @since 1.1.4
053:         * @see #setLocations
054:         * @see #setProperties
055:         * @see #setSystemPropertiesModeName
056:         * @see #setContextOverride
057:         * @see #setSearchContextAttributes
058:         * @see javax.servlet.ServletContext#getInitParameter(String)
059:         * @see javax.servlet.ServletContext#getAttribute(String)
060:         */
061:        public class ServletContextPropertyPlaceholderConfigurer extends
062:                PropertyPlaceholderConfigurer implements  ServletContextAware {
063:
064:            private boolean contextOverride = false;
065:
066:            private boolean searchContextAttributes = false;
067:
068:            private ServletContext servletContext;
069:
070:            /**
071:             * Set whether ServletContext init parameters (and optionally also ServletContext
072:             * attributes) should override local properties within the application.
073:             * Default is "false": ServletContext settings serve as fallback.
074:             * <p>Note that system properties will still override ServletContext settings,
075:             * if the system properties mode is set to "SYSTEM_PROPERTIES_MODE_OVERRIDE".
076:             * @see #setSearchContextAttributes
077:             * @see #setSystemPropertiesModeName
078:             * @see #SYSTEM_PROPERTIES_MODE_OVERRIDE
079:             */
080:            public void setContextOverride(boolean contextOverride) {
081:                this .contextOverride = contextOverride;
082:            }
083:
084:            /**
085:             * Set whether to search for matching a ServletContext attribute before
086:             * checking a ServletContext init parameter. Default is "false": only
087:             * checking init parameters.
088:             * <p>If turned on, the configurer will look for a ServletContext attribute with
089:             * the same name as the placeholder, and use its stringified value if found.
090:             * Exposure of such ServletContext attributes can be used to dynamically override
091:             * init parameters defined in <code>web.xml</code>, for example in a custom
092:             * context listener.
093:             * @see javax.servlet.ServletContext#getInitParameter(String)
094:             * @see javax.servlet.ServletContext#getAttribute(String)
095:             */
096:            public void setSearchContextAttributes(
097:                    boolean searchContextAttributes) {
098:                this .searchContextAttributes = searchContextAttributes;
099:            }
100:
101:            /**
102:             * Set the ServletContext to resolve placeholders against.
103:             * Will be auto-populated when running in a WebApplicationContext.
104:             * <p>If not set, this configurer will simply not resolve placeholders
105:             * against the ServletContext: It will effectively behave like a plain
106:             * PropertyPlaceholderConfigurer in such a scenario.
107:             */
108:            public void setServletContext(ServletContext servletContext) {
109:                this .servletContext = servletContext;
110:            }
111:
112:            protected String resolvePlaceholder(String placeholder,
113:                    Properties props) {
114:                String value = null;
115:                if (this .contextOverride && this .servletContext != null) {
116:                    value = resolvePlaceholder(placeholder,
117:                            this .servletContext, this .searchContextAttributes);
118:                }
119:                if (value == null) {
120:                    value = super .resolvePlaceholder(placeholder, props);
121:                }
122:                if (value == null && this .servletContext != null) {
123:                    value = resolvePlaceholder(placeholder,
124:                            this .servletContext, this .searchContextAttributes);
125:                }
126:                return value;
127:            }
128:
129:            /**
130:             * Resolves the given placeholder using the init parameters
131:             * and optionally also the attributes of the given ServletContext.
132:             * <p>Default implementation checks ServletContext attributes before
133:             * init parameters. Can be overridden to customize this behavior,
134:             * potentially also applying specific naming patterns for parameters
135:             * and/or attributes (instead of using the exact placeholder name).
136:             * @param placeholder the placeholder to resolve
137:             * @param servletContext the ServletContext to check
138:             * @param searchContextAttributes whether to search for a matching
139:             * ServletContext attribute
140:             * @return the resolved value, of null if none
141:             * @see javax.servlet.ServletContext#getInitParameter(String)
142:             * @see javax.servlet.ServletContext#getAttribute(String)
143:             */
144:            protected String resolvePlaceholder(String placeholder,
145:                    ServletContext servletContext,
146:                    boolean searchContextAttributes) {
147:
148:                String value = null;
149:                if (searchContextAttributes) {
150:                    Object attrValue = servletContext.getAttribute(placeholder);
151:                    if (attrValue != null) {
152:                        value = attrValue.toString();
153:                    }
154:                }
155:                if (value == null) {
156:                    value = servletContext.getInitParameter(placeholder);
157:                }
158:                return value;
159:            }
160:
161:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.