Source Code Cross Referenced for MatchTag.java in  » Web-Framework » struts-1.3.8 » org » apache » struts » taglib » logic » 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 » Web Framework » struts 1.3.8 » org.apache.struts.taglib.logic 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: MatchTag.java 471754 2006-11-06 14:55:09Z husted $
003:         *
004:         * Licensed to the Apache Software Foundation (ASF) under one
005:         * or more contributor license agreements.  See the NOTICE file
006:         * distributed with this work for additional information
007:         * regarding copyright ownership.  The ASF licenses this file
008:         * to you under the Apache License, Version 2.0 (the
009:         * "License"); you may not use this file except in compliance
010:         * with the License.  You may obtain a copy of the License at
011:         *
012:         *  http://www.apache.org/licenses/LICENSE-2.0
013:         *
014:         * Unless required by applicable law or agreed to in writing,
015:         * software distributed under the License is distributed on an
016:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017:         * KIND, either express or implied.  See the License for the
018:         * specific language governing permissions and limitations
019:         * under the License.
020:         */
021:        package org.apache.struts.taglib.logic;
022:
023:        import org.apache.struts.taglib.TagUtils;
024:
025:        import javax.servlet.http.Cookie;
026:        import javax.servlet.http.HttpServletRequest;
027:        import javax.servlet.jsp.JspException;
028:
029:        /**
030:         * Evalute the nested body content of this tag if the specified value is a
031:         * substring of the specified variable.
032:         *
033:         * @version $Rev: 471754 $ $Date: 2004-10-16 12:38:42 -0400 (Sat, 16 Oct 2004)
034:         *          $
035:         */
036:        public class MatchTag extends ConditionalTagBase {
037:            // ------------------------------------------------------------- Properties
038:
039:            /**
040:             * The location where the match must exist (<code>start</code> or
041:             * <code>end</code>), or <code>null</code> for anywhere.
042:             */
043:            protected String location = null;
044:
045:            /**
046:             * The value to which the variable specified by other attributes of this
047:             * tag will be matched.
048:             */
049:            protected String value = null;
050:
051:            public String getLocation() {
052:                return (this .location);
053:            }
054:
055:            public void setLocation(String location) {
056:                this .location = location;
057:            }
058:
059:            public String getValue() {
060:                return (this .value);
061:            }
062:
063:            public void setValue(String value) {
064:                this .value = value;
065:            }
066:
067:            // --------------------------------------------------------- Public Methods
068:
069:            /**
070:             * Release all allocated resources.
071:             */
072:            public void release() {
073:                super .release();
074:                location = null;
075:                value = null;
076:            }
077:
078:            // ------------------------------------------------------ Protected Methods
079:
080:            /**
081:             * Evaluate the condition that is being tested by this particular tag, and
082:             * return <code>true</code> if the nested body content of this tag should
083:             * be evaluated, or <code>false</code> if it should be skipped. This
084:             * method must be implemented by concrete subclasses.
085:             *
086:             * @throws JspException if a JSP exception occurs
087:             */
088:            protected boolean condition() throws JspException {
089:                return (condition(true));
090:            }
091:
092:            /**
093:             * Evaluate the condition that is being tested by this particular tag, and
094:             * return <code>true</code> if the nested body content of this tag should
095:             * be evaluated, or <code>false</code> if it should be skipped. This
096:             * method must be implemented by concrete subclasses.
097:             *
098:             * @param desired Desired value for a true result
099:             * @throws JspException if a JSP exception occurs
100:             */
101:            protected boolean condition(boolean desired) throws JspException {
102:                // Acquire the specified variable
103:                String variable = null;
104:
105:                if (cookie != null) {
106:                    Cookie[] cookies = ((HttpServletRequest) pageContext
107:                            .getRequest()).getCookies();
108:
109:                    if (cookies == null) {
110:                        cookies = new Cookie[0];
111:                    }
112:
113:                    for (int i = 0; i < cookies.length; i++) {
114:                        if (cookie.equals(cookies[i].getName())) {
115:                            variable = cookies[i].getValue();
116:
117:                            break;
118:                        }
119:                    }
120:                } else if (header != null) {
121:                    variable = ((HttpServletRequest) pageContext.getRequest())
122:                            .getHeader(header);
123:                } else if (name != null) {
124:                    Object value = TagUtils.getInstance().lookup(pageContext,
125:                            name, property, scope);
126:
127:                    if (value != null) {
128:                        variable = value.toString();
129:                    }
130:                } else if (parameter != null) {
131:                    variable = pageContext.getRequest().getParameter(parameter);
132:                } else {
133:                    JspException e = new JspException(messages
134:                            .getMessage("logic.selector"));
135:
136:                    TagUtils.getInstance().saveException(pageContext, e);
137:                    throw e;
138:                }
139:
140:                if (variable == null) {
141:                    JspException e = new JspException(messages.getMessage(
142:                            "logic.variable", value));
143:
144:                    TagUtils.getInstance().saveException(pageContext, e);
145:                    throw e;
146:                }
147:
148:                // Perform the comparison requested by the location attribute
149:                boolean matched = false;
150:
151:                if (location == null) {
152:                    matched = (variable.indexOf(value) >= 0);
153:                } else if (location.equals("start")) {
154:                    matched = variable.startsWith(value);
155:                } else if (location.equals("end")) {
156:                    matched = variable.endsWith(value);
157:                } else {
158:                    JspException e = new JspException(messages.getMessage(
159:                            "logic.location", location));
160:
161:                    TagUtils.getInstance().saveException(pageContext, e);
162:                    throw e;
163:                }
164:
165:                // Return the final result
166:                return (matched == desired);
167:            }
168:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.