Source Code Cross Referenced for TransformTag.java in  » J2EE » spring-framework-2.0.6 » org » springframework » web » servlet » tags » 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.tags 
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.servlet.tags;
018:
019:        import java.beans.PropertyEditor;
020:        import java.io.IOException;
021:
022:        import javax.servlet.jsp.JspException;
023:        import javax.servlet.jsp.tagext.TagSupport;
024:
025:        import org.springframework.web.util.ExpressionEvaluationUtils;
026:        import org.springframework.web.util.HtmlUtils;
027:        import org.springframework.web.util.TagUtils;
028:
029:        /**
030:         * Tag for transforming reference data values from form controllers and
031:         * other objects inside a <code>spring:bind</code> tag.
032:         *
033:         * <p>The BindTag has a PropertyEditor that it uses to transform properties of
034:         * a bean to a String, useable in HTML forms. This tag uses that PropertyEditor
035:         * to transform objects passed into this tag.
036:         *
037:         * @author Alef Arendsen
038:         * @author Juergen Hoeller
039:         * @since 20.09.2003
040:         * @see BindTag
041:         */
042:        public class TransformTag extends HtmlEscapingAwareTag {
043:
044:            /** the value to transform using the appropriate property editor */
045:            private Object value;
046:
047:            /** the variable to put the result in */
048:            private String var;
049:
050:            /** the scope of the variable the result will be put in */
051:            private String scope = TagUtils.SCOPE_PAGE;
052:
053:            /**
054:             * Set the value to transform, using the appropriate PropertyEditor
055:             * from the enclosing BindTag.
056:             * <p>The value can either be a plain value to transform (a hard-coded String
057:             * value in a JSP or a JSP expression), or a JSP EL expression to be evaluated
058:             * (transforming the result of the expression).
059:             * <p>Like all of Spring's JSP tags, this tag is capable of parsing EL expressions
060:             * itself, on any JSP version. Note, however, that EL expressions in a JSP 2.0 page
061:             * will be evaluated by the JSP container, with the result getting passed in here.
062:             * For this reason, the type of this property is Object (accepting any result
063:             * object from a pre-evaluated expression) rather than String.
064:             */
065:            public void setValue(Object value) {
066:                this .value = value;
067:            }
068:
069:            /**
070:             * Set PageContext attribute name under which to expose
071:             * a variable that contains the result of the transformation.
072:             * @see #setScope
073:             * @see javax.servlet.jsp.PageContext#setAttribute
074:             */
075:            public void setVar(String var) {
076:                this .var = var;
077:            }
078:
079:            /**
080:             * Set the scope to export the variable to.
081:             * Default is SCOPE_PAGE ("page").
082:             * @see #setVar
083:             * @see org.springframework.web.util.TagUtils#SCOPE_PAGE
084:             * @see javax.servlet.jsp.PageContext#setAttribute
085:             */
086:            public void setScope(String scope) {
087:                this .scope = scope;
088:            }
089:
090:            protected final int doStartTagInternal() throws JspException {
091:                Object resolvedValue = this .value;
092:                if (this .value instanceof  String) {
093:                    String strValue = (String) this .value;
094:                    resolvedValue = ExpressionEvaluationUtils.evaluate("value",
095:                            strValue, pageContext);
096:                }
097:                if (resolvedValue != null) {
098:                    // Find the BindTag, if applicable.
099:                    BindTag tag = (BindTag) TagSupport.findAncestorWithClass(
100:                            this , BindTag.class);
101:                    if (tag == null) {
102:                        // The tag can only be used within a BindTag.
103:                        throw new JspException(
104:                                "TransformTag can only be used within BindTag");
105:                    }
106:                    // OK, get the property editor.
107:                    PropertyEditor editor = tag.getEditor();
108:                    String result = null;
109:                    if (editor != null) {
110:                        // If an editor was found, edit the value.
111:                        editor.setValue(resolvedValue);
112:                        result = editor.getAsText();
113:                    } else {
114:                        // Else, just do a toString.
115:                        result = resolvedValue.toString();
116:                    }
117:                    result = isHtmlEscape() ? HtmlUtils.htmlEscape(result)
118:                            : result;
119:                    String resolvedVar = ExpressionEvaluationUtils
120:                            .evaluateString("var", this .var, pageContext);
121:                    if (resolvedVar != null) {
122:                        String resolvedScope = ExpressionEvaluationUtils
123:                                .evaluateString("scope", this .scope,
124:                                        pageContext);
125:                        pageContext.setAttribute(resolvedVar, result, TagUtils
126:                                .getScope(resolvedScope));
127:                    } else {
128:                        try {
129:                            // Else, just print it out.
130:                            pageContext.getOut().print(result);
131:                        } catch (IOException ex) {
132:                            throw new JspException(ex);
133:                        }
134:                    }
135:                }
136:                return SKIP_BODY;
137:            }
138:
139:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.