Source Code Cross Referenced for OutSupport.java in  » EJB-Server-GlassFish » appserv-jstl » org » apache » taglibs » standard » tag » common » core » 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 » EJB Server GlassFish » appserv jstl » org.apache.taglibs.standard.tag.common.core 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         * 
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         * 
006:         * Portions Copyright Apache Software Foundation.
007:         * 
008:         * The contents of this file are subject to the terms of either the GNU
009:         * General Public License Version 2 only ("GPL") or the Common Development
010:         * and Distribution License("CDDL") (collectively, the "License").  You
011:         * may not use this file except in compliance with the License. You can obtain
012:         * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
013:         * or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
014:         * language governing permissions and limitations under the License.
015:         * 
016:         * When distributing the software, include this License Header Notice in each
017:         * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
018:         * Sun designates this particular file as subject to the "Classpath" exception
019:         * as provided by Sun in the GPL Version 2 section of the License file that
020:         * accompanied this code.  If applicable, add the following below the License
021:         * Header, with the fields enclosed by brackets [] replaced by your own
022:         * identifying information: "Portions Copyrighted [year]
023:         * [name of copyright owner]"
024:         * 
025:         * Contributor(s):
026:         * 
027:         * If you wish your version of this file to be governed by only the CDDL or
028:         * only the GPL Version 2, indicate your decision by adding "[Contributor]
029:         * elects to include this software in this distribution under the [CDDL or GPL
030:         * Version 2] license."  If you don't indicate a single choice of license, a
031:         * recipient has the option to distribute your version of this file under
032:         * either the CDDL, the GPL Version 2 or to extend the choice of license to
033:         * its licensees as provided above.  However, if you add GPL Version 2 code
034:         * and therefore, elected the GPL Version 2 license, then the option applies
035:         * only if the new code is made subject to such option by the copyright
036:         * holder.
037:         */
038:
039:        package org.apache.taglibs.standard.tag.common.core;
040:
041:        import java.io.IOException;
042:        import java.io.Reader;
043:
044:        import javax.servlet.jsp.JspException;
045:        import javax.servlet.jsp.JspWriter;
046:        import javax.servlet.jsp.PageContext;
047:        import javax.servlet.jsp.tagext.BodyTagSupport;
048:
049:        /**
050:         * <p>Support for handlers of the &lt;out&gt; tag, which simply evalutes and
051:         * prints the result of the expression it's passed.  If the result is
052:         * null, we print the value of the 'default' attribute's expression or
053:         * our body (which two are mutually exclusive, although this constraint
054:         * is enforced outside this handler, in our TagLibraryValidator).</p>
055:         *
056:         * @author Shawn Bayern
057:         */
058:        public class OutSupport extends BodyTagSupport {
059:
060:            /*
061:             * (One almost wishes XML and JSP could support "anonymous tags,"
062:             * given the amount of trouble we had naming this one!)  :-)  - sb
063:             */
064:
065:            //*********************************************************************
066:            // Internal state
067:            protected Object value; // tag attribute
068:            protected String def; // tag attribute
069:            protected boolean escapeXml; // tag attribute
070:            private boolean needBody; // non-space body needed?
071:
072:            //*********************************************************************
073:            // Construction and initialization
074:
075:            /**
076:             * Constructs a new handler.  As with TagSupport, subclasses should
077:             * not provide other constructors and are expected to call the
078:             * superclass constructor.
079:             */
080:            public OutSupport() {
081:                super ();
082:                init();
083:            }
084:
085:            // resets local state
086:            private void init() {
087:                value = def = null;
088:                escapeXml = true;
089:                needBody = false;
090:            }
091:
092:            // Releases any resources we may have (or inherit)
093:            public void release() {
094:                super .release();
095:                init();
096:            }
097:
098:            //*********************************************************************
099:            // Tag logic
100:
101:            // evaluates 'value' and determines if the body should be evaluted
102:            public int doStartTag() throws JspException {
103:
104:                needBody = false; // reset state related to 'default'
105:                this .bodyContent = null; // clean-up body (just in case container is pooling tag handlers)
106:
107:                try {
108:                    // print value if available; otherwise, try 'default'
109:                    if (value != null) {
110:                        out(pageContext, escapeXml, value);
111:                        return SKIP_BODY;
112:                    } else {
113:                        // if we don't have a 'default' attribute, just go to the body
114:                        if (def == null) {
115:                            needBody = true;
116:                            return EVAL_BODY_BUFFERED;
117:                        }
118:
119:                        // if we do have 'default', print it
120:                        if (def != null) {
121:                            // good 'default'
122:                            out(pageContext, escapeXml, def);
123:                        }
124:                        return SKIP_BODY;
125:                    }
126:                } catch (IOException ex) {
127:                    throw new JspException(ex.toString(), ex);
128:                }
129:            }
130:
131:            // prints the body if necessary; reports errors
132:            public int doEndTag() throws JspException {
133:                try {
134:                    if (!needBody)
135:                        return EVAL_PAGE; // nothing more to do
136:
137:                    // trim and print out the body
138:                    if (bodyContent != null && bodyContent.getString() != null)
139:                        out(pageContext, escapeXml, bodyContent.getString()
140:                                .trim());
141:                    return EVAL_PAGE;
142:                } catch (IOException ex) {
143:                    throw new JspException(ex.toString(), ex);
144:                }
145:            }
146:
147:            //*********************************************************************
148:            // Public utility methods
149:
150:            /**
151:             * Outputs <tt>text</tt> to <tt>pageContext</tt>'s current JspWriter.
152:             * If <tt>escapeXml</tt> is true, performs the following substring
153:             * replacements (to facilitate output to XML/HTML pages):
154:             *
155:             *    & -> &amp;
156:             *    < -> &lt;
157:             *    > -> &gt;
158:             *    " -> &#034;
159:             *    ' -> &#039;
160:             *
161:             * See also Util.escapeXml().
162:             */
163:            public static void out(PageContext pageContext, boolean escapeXml,
164:                    Object obj) throws IOException {
165:                JspWriter w = pageContext.getOut();
166:                if (!escapeXml) {
167:                    // write chars as is
168:                    if (obj instanceof  Reader) {
169:                        Reader reader = (Reader) obj;
170:                        char[] buf = new char[4096];
171:                        int count;
172:                        while ((count = reader.read(buf, 0, 4096)) != -1) {
173:                            w.write(buf, 0, count);
174:                        }
175:                    } else {
176:                        w.write(obj.toString());
177:                    }
178:                } else {
179:                    // escape XML chars
180:                    if (obj instanceof  Reader) {
181:                        Reader reader = (Reader) obj;
182:                        char[] buf = new char[4096];
183:                        int count;
184:                        while ((count = reader.read(buf, 0, 4096)) != -1) {
185:                            writeEscapedXml(buf, count, w);
186:                        }
187:                    } else {
188:                        String text = obj.toString();
189:                        writeEscapedXml(text.toCharArray(), text.length(), w);
190:                    }
191:                }
192:            }
193:
194:            /**
195:             *
196:             *  Optimized to create no extra objects and write directly
197:             *  to the JspWriter using blocks of escaped and unescaped characters
198:             *
199:             */
200:            private static void writeEscapedXml(char[] buffer, int length,
201:                    JspWriter w) throws IOException {
202:                int start = 0;
203:
204:                for (int i = 0; i < length; i++) {
205:                    char c = buffer[i];
206:                    if (c <= Util.HIGHEST_SPECIAL) {
207:                        char[] escaped = Util.specialCharactersRepresentation[c];
208:                        if (escaped != null) {
209:                            // add unescaped portion
210:                            if (start < i) {
211:                                w.write(buffer, start, i - start);
212:                            }
213:                            // add escaped xml
214:                            w.write(escaped);
215:                            start = i + 1;
216:                        }
217:                    }
218:                }
219:                // add rest of unescaped portion
220:                if (start < length) {
221:                    w.write(buffer, start, length - start);
222:                }
223:            }
224:        }
ww___w_.___j_a__v___a_2_s.___c_o_m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.