Source Code Cross Referenced for DefaultRequestToViewNameTranslator.java in  » J2EE » spring-framework-2.0.6 » org » springframework » web » servlet » view » 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.0.6 » org.springframework.web.servlet.view 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2002-2006 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.servlet.view;
018:
019:        import javax.servlet.http.HttpServletRequest;
020:
021:        import org.springframework.util.StringUtils;
022:        import org.springframework.util.Assert;
023:        import org.springframework.web.servlet.RequestToViewNameTranslator;
024:        import org.springframework.web.util.UrlPathHelper;
025:
026:        /**
027:         * Simply transforms the URI of the incoming request into the view name.
028:         * 
029:         * <p>Can be explicitly defined as the "viewNameTranslator" bean in a
030:         * {@link org.springframework.web.servlet.DispatcherServlet} context; else,
031:         * a plain default instance will be used.
032:         *
033:         * <p>The default transformation simply strips the leading slash and file
034:         * extension of the URI and returns the result as the view name with the
035:         * configured {@link #setPrefix(String) "prefix"} and and
036:         * {@link #setSuffix(String) "suffix"} added as appropriate.
037:         *
038:         * <p>The stripping of the leading slash and file extension can be disabled
039:         * using the {@link #setStripLeadingSlash(boolean) "stripLeadingSlash"} and
040:         * {@link #setStripExtension(boolean) "stripExtension"} properties,
041:         * respectively.
042:         * 
043:         * <p>Find below some examples of request to view name translation.
044:         * 
045:         * <pre class="code"> http://localhost:8080/gamecast/display.html -> display
046:         * http://localhost:8080/gamecast/displayShoppingCart.html -> displayShoppingCart
047:         * http://localhost:8080/gamecast/admin/index.html -> admin/index
048:         * </pre>
049:         *
050:         * @author Rob Harrop
051:         * @since 2.0
052:         * @see org.springframework.web.servlet.RequestToViewNameTranslator
053:         * @see org.springframework.web.servlet.ViewResolver
054:         */
055:        public class DefaultRequestToViewNameTranslator implements 
056:                RequestToViewNameTranslator {
057:
058:            private static final String SLASH = "/";
059:
060:            private String prefix = "";
061:
062:            private String suffix = "";
063:
064:            private String separator = SLASH;
065:
066:            private boolean stripLeadingSlash = true;
067:
068:            private boolean stripExtension = true;
069:
070:            private UrlPathHelper urlPathHelper = new UrlPathHelper();
071:
072:            /**
073:             * Set the prefix to prepend to generated view names.
074:             * @param prefix the prefix to prepend to generated view names
075:             */
076:            public void setPrefix(String prefix) {
077:                this .prefix = (prefix == null ? "" : prefix);
078:            }
079:
080:            /**
081:             * Set the suffix to append to generated view names.
082:             * @param suffix the suffix to append to generated view names
083:             */
084:            public void setSuffix(String suffix) {
085:                this .suffix = (suffix == null ? "" : suffix);
086:            }
087:
088:            /**
089:             * Set the value that will replace '<code>/</code>' as the separator
090:             * in the view name. The default behavior simply leaves '<code>/</code>'
091:             * as the separator.
092:             * @param separator the desired separator value
093:             */
094:            public void setSeparator(String separator) {
095:                this .separator = separator;
096:            }
097:
098:            /**
099:             * Set whether or not leading slashes should be stripped from the URI when
100:             * generating the view name. Default is "true".
101:             * @param stripLeadingSlash <code>true</code> if leading slashes are to be stripped
102:             */
103:            public void setStripLeadingSlash(boolean stripLeadingSlash) {
104:                this .stripLeadingSlash = stripLeadingSlash;
105:            }
106:
107:            /**
108:             * Set whether or not file extensions should be stripped from the URI when
109:             * generating the view name. Default is "true".
110:             * @param stripExtension <code>true</code> if file extensions should be stripped
111:             */
112:            public void setStripExtension(boolean stripExtension) {
113:                this .stripExtension = stripExtension;
114:            }
115:
116:            /**
117:             * Set if URL lookup should always use the full path within the current servlet
118:             * context. Else, the path within the current servlet mapping is used
119:             * if applicable (i.e. in the case of a ".../*" servlet mapping in web.xml).
120:             * Default is "false".
121:             * @param alwaysUseFullPath <code>true</code> if URL lookup should always use the full path
122:             * @see org.springframework.web.util.UrlPathHelper#setAlwaysUseFullPath
123:             */
124:            public void setAlwaysUseFullPath(boolean alwaysUseFullPath) {
125:                this .urlPathHelper.setAlwaysUseFullPath(alwaysUseFullPath);
126:            }
127:
128:            /**
129:             * Set if the context path and request URI should be URL-decoded.
130:             * Both are returned <i>undecoded</i> by the Servlet API,
131:             * in contrast to the servlet path.
132:             * <p>Uses either the request encoding or the default encoding according
133:             * to the Servlet spec (ISO-8859-1).
134:             * <p>Note: Setting this to "true" requires JDK 1.4 if the encoding differs
135:             * from the VM's platform default encoding, as JDK 1.3's URLDecoder class
136:             * does not offer a way to specify the encoding.
137:             * @param urlDecode <code>true</code> if the context path and request URI should be URL-decoded
138:             * @see org.springframework.web.util.UrlPathHelper#setUrlDecode
139:             */
140:            public void setUrlDecode(boolean urlDecode) {
141:                this .urlPathHelper.setUrlDecode(urlDecode);
142:            }
143:
144:            /**
145:             * Set the {@link org.springframework.web.util.UrlPathHelper} to use for
146:             * the resolution of lookup paths.
147:             * <p>Use this to override the default UrlPathHelper with a custom subclass,
148:             * or to share common UrlPathHelper settings across multiple web components.
149:             * @param urlPathHelper the desired helper
150:             * @throws IllegalArgumentException if the supplied UrlPathHelper is <code>null</code>
151:             */
152:            public void setUrlPathHelper(UrlPathHelper urlPathHelper) {
153:                Assert.notNull(urlPathHelper);
154:                this .urlPathHelper = urlPathHelper;
155:            }
156:
157:            /**
158:             * Translates the request URI of the incoming {@link HttpServletRequest} to the
159:             * view name based on the configured parameters.
160:             * @see org.springframework.web.util.UrlPathHelper#getLookupPathForRequest
161:             * @see #transformPath
162:             */
163:            public final String getViewName(HttpServletRequest request) {
164:                String lookupPath = this .urlPathHelper
165:                        .getLookupPathForRequest(request);
166:                return this .prefix + transformPath(lookupPath) + this .suffix;
167:            }
168:
169:            /**
170:             * Transform the request URI (in the context of the webapp) stripping
171:             * slashes and extensions, and replacing the separator as required.
172:             * @param lookupPath the lookup path for the current request,
173:             * as determined by the UrlPathHelper
174:             * @return the transformed path, with slashes and extensions stripped
175:             * if desired
176:             */
177:            protected String transformPath(String lookupPath) {
178:                String path = lookupPath;
179:                if (this .stripLeadingSlash && path.startsWith(SLASH)) {
180:                    path = path.substring(1);
181:                }
182:                if (this.stripExtension) {
183:                    path = StringUtils.stripFilenameExtension(path);
184:                }
185:                if (!SLASH.equals(this.separator)) {
186:                    path = StringUtils.replace(path, SLASH, this.separator);
187:                }
188:                return path;
189:            }
190:
191:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.