Source Code Cross Referenced for SubsetIteratorTag.java in  » J2EE » webwork-2.2.6 » com » opensymphony » webwork » views » jsp » iterator » 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 » webwork 2.2.6 » com.opensymphony.webwork.views.jsp.iterator 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2002-2003 by OpenSymphony
003:         * All rights reserved.
004:         */
005:        package com.opensymphony.webwork.views.jsp.iterator;
006:
007:        import com.opensymphony.webwork.util.SubsetIteratorFilter;
008:        import com.opensymphony.webwork.util.SubsetIteratorFilter.Decider;
009:        import com.opensymphony.webwork.views.jsp.WebWorkBodyTagSupport;
010:
011:        import javax.servlet.jsp.JspException;
012:
013:        import org.apache.commons.logging.Log;
014:        import org.apache.commons.logging.LogFactory;
015:
016:        /**
017:         * <!-- START SNIPPET: javadoc -->
018:         * <b>NOTE: JSP-TAG</b>
019:         * 
020:         * <p>A tag that takes an iterator and outputs a subset of it. It delegates to
021:         * {@link com.opensymphony.webwork.util.SubsetIteratorFilter} internally to
022:         * perform the subset functionality.</p>
023:         * <!-- END SNIPPET: javadoc -->
024:         *
025:         * <!-- START SNIPPET: params -->
026:         * <ul>
027:         * 		<li>count (Object) - Indicate the number of entries to be in the resulting subset iterator</li>
028:         * 		<li>source* (Object) - Indicate the source of which the resulting subset iterator is to be derived base on</li>
029:         * 		<li>start (Object) - Indicate the starting index (eg. first entry is 0) of entries in the source to be available as the first entry in the resulting subset iterator</li>
030:         * 		<li>decider (Object) - Extension to plug-in a decider to determine if that particular entry is to be included in the resulting subset iterator</li>
031:         * 		<li>id (String) - Indicate the pageContext attribute id to store the resultant subset iterator in</li>
032:         * </ul>
033:         * <!-- END SNIPPET: params -->
034:         *
035:         *
036:         * <pre>
037:         * <!-- START SNIPPET: action -->
038:         * public class MySubsetTagAction extends ActionSupport {
039:         *      public String execute() throws Exception {
040:         *		   l = new ArrayList();
041:         *		   l.add(new Integer(1));
042:         *		   l.add(new Integer(2));
043:         *		   l.add(new Integer(3));
044:         *		   l.add(new Integer(4));
045:         *		   l.add(new Integer(5));
046:         *		   return "done";
047:         *	    }
048:         *
049:         *
050:         *	    public Integer[] getMyArray() {
051:         *		   return a;
052:         *	    }
053:         *
054:         *	    public List getMyList() {
055:         *		   return l;
056:         *	     }
057:         *
058:         *      public Decider getMyDecider() {
059:         *		return new Decider() {
060:         *			public boolean decide(Object element) throws Exception {
061:         *				int i = ((Integer)element).intValue();
062:         *				return (((i % 2) == 0)?true:false);
063:         *			}
064:         *		};
065:         *		}
066:         *	}
067:         * <!-- END SNIPPET: action -->
068:         * </pre>
069:         *
070:         *
071:         * <pre>
072:         * <!-- START SNIPPET: example1 -->
073:         * &lt;!-- A: List basic --&gt;
074:         *    &lt;ww:subset source="myList"&gt;
075:         *	     &lt;ww:iterator&gt;
076:         *		    &lt;ww:property /&gt;
077:         *	     &lt;/ww:iterator&gt;
078:         *    &lt;/ww:subset&gt;
079:         * <!-- END SNIPPET: example1 -->
080:         * </pre>
081:         *
082:         * <pre>
083:         * <!-- START SNIPPET: example2 -->
084:         * &lt;!-- B: List with count --&gt;
085:         *    &lt;ww:subset source="myList" count="3"&gt;
086:         * 	     &lt;ww:iterator&gt;
087:         * 		     &lt;ww:property /&gt;
088:         * 	     &lt;/ww:iterator&gt;
089:         *     &lt;/ww:subset&gt;
090:         * <!-- END SNIPPET: example2 -->
091:         * </pre>
092:         *
093:         * <pre>
094:         * <!-- START SNIPPET: example3 -->
095:         * &lt;!--  C: List with start -->
096:         *      &lt;ww:subset source="myList" count="13" start="3"&gt;
097:         * 	       &lt;ww:iterator&gt;
098:         * 		     &lt;ww:property /&gt;
099:         * 	       &lt;/ww:iterator&gt;
100:         *      &lt;/ww:subset&gt;
101:         * <!-- END SNIPPET: example3 -->
102:         * </pre>
103:         *
104:         * <pre>
105:         * <!-- START SNIPPET: example4 -->
106:         * &lt;!--  D: List with id --&gt;
107:         *      &lt;ww:subset id="mySubset" source="myList" count="13" start="3" /&gt;
108:         *      &lt;%
109:         * 	        Iterator i = (Iterator) pageContext.getAttribute("mySubset");
110:         *          while(i.hasNext()) {
111:         *      %&gt;
112:         *      &lt;%=i.next() %&gt;
113:         *      &lt;%  } %&gt;
114:         * <!-- END SNIPPET: example4 -->
115:         * </pre>
116:         *
117:         * <pre>
118:         * <!-- START SNIPPET: example5 -->
119:         *  &lt;!--  D: List with Decider --&gt;
120:         *      &lt;ww:subset source="myList" decider="myDecider"&gt;
121:         * 	           &lt;ww:iterator&gt;
122:         *		            &lt;ww:property /&gt;
123:         *	           &lt;/ww:iterator&gt;
124:         *      &lt;/ww:subset&gt;
125:         * <!-- END SNIPPET: example5 -->
126:         * </pre>
127:         *
128:         *
129:         * @author Rickard �berg (rickard@dreambean.com)
130:         * @author tm_jee ( tm_jee(at)yahoo.co.uk )
131:         * @ww.tag name="subset" tld-body-content="JSP"
132:         * description="Takes an iterator and outputs a subset of it"
133:         */
134:        public class SubsetIteratorTag extends WebWorkBodyTagSupport {
135:
136:            private static final long serialVersionUID = -6252696081713080102L;
137:
138:            private static final Log _log = LogFactory
139:                    .getLog(SubsetIteratorTag.class);
140:
141:            String countAttr;
142:            String sourceAttr;
143:            String startAttr;
144:            String deciderAttr;
145:
146:            SubsetIteratorFilter subsetIteratorFilter = null;
147:
148:            /**
149:             * @ww.tagattribute required="false" type="Integer"
150:             * description="Indicate the number of entries to be in the resulting subset iterator"
151:             */
152:            public void setCount(String count) {
153:                countAttr = count;
154:            }
155:
156:            /**
157:             * @ww.tagattribute required="false"
158:             * description="Indicate the source of which the resulting subset iterator is to be derived base on"
159:             */
160:            public void setSource(String source) {
161:                sourceAttr = source;
162:            }
163:
164:            /**
165:             * @ww.tagattribute required="false" type="Integer"
166:             * description="Indicate the starting index (eg. first entry is 0) of entries in the source to be available as the first entry in the resulting subset iterator"
167:             */
168:            public void setStart(String start) {
169:                startAttr = start;
170:            }
171:
172:            /**
173:             * @ww.tagattribute required="false" type="com.opensymphony.webwork.util.SubsetIteratorFilter.Decider"
174:             * description="Extension to plug-in a decider to determine if that particular entry is to be included in the resulting subset iterator"
175:             */
176:            public void setDecider(String decider) {
177:                deciderAttr = decider;
178:            }
179:
180:            public int doStartTag() throws JspException {
181:
182:                // source
183:                Object source = null;
184:                if (sourceAttr == null && sourceAttr.length() <= 0) {
185:                    source = findValue("top");
186:                } else {
187:                    source = findValue(sourceAttr);
188:                }
189:
190:                // count
191:                int count = -1;
192:                if (countAttr != null && countAttr.length() > 0) {
193:                    Object countObj = findValue(countAttr);
194:                    if (countObj instanceof  Integer) {
195:                        count = ((Integer) countObj).intValue();
196:                    } else if (countObj instanceof  Float) {
197:                        count = ((Float) countObj).intValue();
198:                    } else if (countObj instanceof  Long) {
199:                        count = ((Long) countObj).intValue();
200:                    } else if (countObj instanceof  Double) {
201:                        count = ((Long) countObj).intValue();
202:                    } else if (countObj instanceof  String) {
203:                        try {
204:                            count = Integer.parseInt((String) countObj);
205:                        } catch (NumberFormatException e) {
206:                            _log.warn("unable to convert count attribute ["
207:                                    + countObj
208:                                    + "] to number, ignore count attribute", e);
209:                        }
210:                    }
211:                }
212:
213:                // start
214:                int start = 0;
215:                if (startAttr != null && startAttr.length() > 0) {
216:                    Object startObj = findValue(startAttr);
217:                    if (startObj instanceof  Integer) {
218:                        start = ((Integer) startObj).intValue();
219:                    } else if (startObj instanceof  Float) {
220:                        start = ((Float) startObj).intValue();
221:                    } else if (startObj instanceof  Long) {
222:                        start = ((Long) startObj).intValue();
223:                    } else if (startObj instanceof  Double) {
224:                        start = ((Long) startObj).intValue();
225:                    } else if (startObj instanceof  String) {
226:                        try {
227:                            start = Integer.parseInt((String) startObj);
228:                        } catch (NumberFormatException e) {
229:                            _log.warn("unable to convert count attribute ["
230:                                    + startObj
231:                                    + "] to number, ignore count attribute", e);
232:                        }
233:                    }
234:                }
235:
236:                // decider
237:                Decider decider = null;
238:                if (deciderAttr != null && deciderAttr.length() > 0) {
239:                    Object deciderObj = findValue(deciderAttr);
240:                    if (!(deciderObj instanceof  Decider)) {
241:                        throw new JspException("decider found from stack ["
242:                                + deciderObj + "] does not implement "
243:                                + Decider.class);
244:                    }
245:                    decider = (Decider) deciderObj;
246:                }
247:
248:                subsetIteratorFilter = new SubsetIteratorFilter();
249:                subsetIteratorFilter.setCount(count);
250:                subsetIteratorFilter.setDecider(decider);
251:                subsetIteratorFilter.setSource(source);
252:                subsetIteratorFilter.setStart(start);
253:                subsetIteratorFilter.execute();
254:
255:                getStack().push(subsetIteratorFilter);
256:                if (getId() != null) {
257:                    pageContext.setAttribute(getId(), subsetIteratorFilter);
258:                }
259:
260:                return EVAL_BODY_INCLUDE;
261:            }
262:
263:            public int doEndTag() throws JspException {
264:
265:                getStack().pop();
266:
267:                subsetIteratorFilter = null;
268:
269:                return EVAL_PAGE;
270:            }
271:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.