Source Code Cross Referenced for Message.java in  » Library » Apache-beehive-1.0.2-src » org » apache » beehive » netui » tags » databinding » message » 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 » Library » Apache beehive 1.0.2 src » org.apache.beehive.netui.tags.databinding.message 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         *
017:         * $Header:$
018:         */
019:        package org.apache.beehive.netui.tags.databinding.message;
020:
021:        import org.apache.beehive.netui.tags.AbstractClassicTag;
022:
023:        import javax.servlet.jsp.JspException;
024:        import javax.servlet.jsp.tagext.SimpleTagSupport;
025:        import java.util.ArrayList;
026:        import java.util.List;
027:
028:        /**
029:         * <p>
030:         * This tag provides a message schema, which can be parameterized to construct customizable messages.
031:         * Curly-braces are used to identify argument place holders in the schema:
032:         * <p/>
033:         * For example, the following will format a message and place the result in a {@link javax.servlet.jsp.PageContext}
034:         * attribute named <code>message</code>.
035:         * <pre>
036:         * &lt;%
037:         *    pageContext.setAttribute("msgSkeleton", new String("Hello {0}. {1} {2}, the current date and time are {3}."));
038:         * %>
039:         * &lt;netui-data:message value="${pageScope.msgSkeleton}" resultId="message">
040:         * </pre>
041:         * </p>
042:         * <p>
043:         * The followingn example defines a message schema, while the {@link MessageArg} tags provide the parameters that
044:         * plug values into the schema.  In the following example, the &lt;netui-data:message> tag uses the <code>value</code>
045:         * attribute to bind to the message schema (which was earlier added to the
046:         * {@link javax.servlet.jsp.PageContext javax.servlet.jsp.PageContext} object. The two &lt;netui-data:messageArg>
047:         * tags provide the parameters to plug into the schema.
048:         * <pre>
049:         *    &lt;%
050:         *        pageContext.setAttribute("msgSkeleton", new String("To read about {0}, go to {1}."));
051:         *    %&gt;
052:         *    ...
053:         *    &lt;netui-data:message value="${pageScope.msgSkeleton}" resultId="message"&gt;
054:         *        &lt;netui-data:messageArg value="messaging"/&gt;
055:         *        &lt;netui-data:messageArg value="my web page"/&gt;
056:         *    &lt;/netui-data:message&gt;
057:         *    ...
058:         *    &lt;netui:span value="${pageScope.message}"/&gt;</pre>
059:         * <p/>
060:         * <p>The following message is output to the JSP page:<p>
061:         * <p/>
062:         * <pre>
063:         *     To read about messaging, go to my web page.
064:         * </pre>
065:         * </p>
066:         *
067:         * @jsptagref.tagdescription
068:         * <p>
069:         * This tag provides a message schema, which can be parameterized to construct customizable messages.
070:         * Curly-braces are used to identify argument place holders in the schema:
071:         * <p/>
072:         * <pre>
073:         * &lt;%
074:         *    pageContext.setAttribute("msgSkeleton", new String("Hello {0}. {1} {2}, the current date and time are {3}."));
075:         *    %>
076:         *    &lt;netui-data:message value="${pageScope.msgSkeleton}" resultId="message"></pre>
077:         * @example
078:         * <p>
079:         * The followingn example defines a message schema, while the {@link MessageArg} tags provide the parameters that
080:         * plug values into the schema.  In the following example, the &lt;netui-data:message> tag uses the <code>value</code>
081:         * attribute to bind to the message schema (which was earlier added to the
082:         * {@link javax.servlet.jsp.PageContext javax.servlet.jsp.PageContext} object. The two &lt;netui-data:messageArg>
083:         * tags provide the parameters to plug into the schema.
084:         * <pre>
085:         *    &lt;%
086:         *        pageContext.setAttribute("msgSkeleton", new String("To read about {0}, go to {1}."));
087:         *    %&gt;
088:         *    ...
089:         *    &lt;netui-data:message value="${pageScope.msgSkeleton}" resultId="message"&gt;
090:         *        &lt;netui-data:messageArg value="messaging"/&gt;
091:         *        &lt;netui-data:messageArg value="my web page"/&gt;
092:         *    &lt;/netui-data:message&gt;
093:         *    ...
094:         *    &lt;netui:span value="${pageScope.message}"/&gt;</pre>
095:         * <p/>
096:         * <p>The following message is output to the JSP page:<p>
097:         * <p/>
098:         * <pre>
099:         *     To read about messaging, go to my web page.
100:         * </pre>
101:         * </p>
102:         *
103:         * @deprecated This tag has been deprecated in favor of the i18n tags available in JSTL.
104:         * @netui:tag name="message"
105:         *            deprecated="true"
106:         *            description="Allows you to format messages according to any sequence you want, using one or more values from arguments defined in MessageArg tag(s). The results are available to the page context."
107:         */
108:        public class Message extends AbstractClassicTag {
109:
110:            public static final String MESSAGE_ARG_KEY = "netui_bundleMessageArguments";
111:
112:            private String _resultId = null;
113:            private Object _value = null;
114:            private List _argList = null;
115:
116:            public String getTagName() {
117:                return "Message";
118:            }
119:
120:            /**
121:             * Set the attribute name under which the output formatted message will be available.  The message
122:             * will be stored in the JSP EL implicit object <code>pageScope</code>.  If the value of this attribute
123:             * is <code>foo</code>, the resulting message will be available with <code>${pageScope.foo}</code>.
124:             *
125:             * @jsptagref.attributedescription
126:             * Set the attribute name under which the output formatted message will be available.  The message
127:             * will be stored in the JSP EL implicit object <code>pageScope</code>.  If the value of this attribute
128:             * is <code>foo</code>, the resulting message will be available with <code>${pageScope.foo}</code>.
129:             * @jsptagref.attributesyntaxvalue <i>string_result</i>
130:             * @netui:attribute required="true"
131:             */
132:            public void setResultId(String resultId) {
133:                _resultId = resultId;
134:            }
135:
136:            /**
137:             * <p>
138:             * Set the object to use when formatting a message.  This value should be either a String or be convertable
139:             * to a String via its {@link Object#toString()} method.  In ordet for format the message, this value
140:             * should appear as:
141:             * <pre>
142:             *     Hello, {0}!
143:             * </pre>
144:             * where the <code>{0}</code> can be filled in during formatting via the {@link MessageArg} tag.
145:             * </p>
146:             * @jsptagref.attributedescription
147:             * <p>
148:             * Set the object to use when formatting a message.  This value should be either a String or be convertable
149:             * to a String via its {@link Object#toString()} method.  In ordet for format the message, this value
150:             * should appear as:
151:             * <pre>
152:             *     Hello, {0}!
153:             * </pre>
154:             * where the <code>{0}</code> can be filled in during formatting via the {@link MessageArg} tag.
155:             * </p>
156:             * @jsptagref.attributesyntaxvalue <i>expression_value</i>
157:             * @netui:attribute required="true" rtexprvalue="true"
158:             */
159:            public void setValue(Object value) {
160:                _value = value;
161:            }
162:
163:            public int doStartTag() {
164:                return EVAL_BODY_BUFFERED;
165:            }
166:
167:            public int doEndTag() throws JspException {
168:                Object[] args = (_argList != null ? _argList.toArray() : null);
169:
170:                if (hasErrors()) {
171:                    reportErrors();
172:                    localRelease();
173:                    return EVAL_PAGE;
174:                }
175:
176:                if (_value == null) {
177:                    localRelease();
178:                    return EVAL_PAGE;
179:                }
180:
181:                Object exprVal = null;
182:                try {
183:                    exprVal = java.text.MessageFormat.format(_value.toString(),
184:                            args);
185:                } catch (Exception e) {
186:                    String msg = "Error formatting message \""
187:                            + _value.toString() + "\".  Cause: "
188:                            + e.getLocalizedMessage();
189:                    registerTagError(msg, null);
190:                }
191:
192:                if (hasErrors()) {
193:                    reportErrors();
194:                    localRelease();
195:                    return EVAL_PAGE;
196:                }
197:
198:                Message msgParent = null;
199:                // if nested in a <netui-data:message ... /> tag, add the result of this tag as an argument.
200:                if ((msgParent = (Message) SimpleTagSupport
201:                        .findAncestorWithClass(this , Message.class)) != null) {
202:                    msgParent.addMessageArgument(exprVal);
203:                } else
204:                    pageContext.setAttribute(_resultId, exprVal);
205:
206:                localRelease();
207:                return EVAL_PAGE;
208:            }
209:
210:            public void addMessageArgument(Object messageArgument) {
211:                if (_argList == null)
212:                    _argList = new ArrayList();
213:
214:                _argList.add(messageArgument);
215:            }
216:
217:            protected void localRelease() {
218:                super.localRelease();
219:                _argList = null;
220:                _value = null;
221:                _resultId = null;
222:            }
223:        }
ww___w_.___j__av___a___2__s___.c_om___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.