Source Code Cross Referenced for HTTPSelector.java in  » Web-Server » JicarillaHTTP » org » jicarilla » webserver » plumbing » 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 Server » JicarillaHTTP » org.jicarilla.webserver.plumbing 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* ====================================================================
002:        The Jicarilla Software License
003:
004:        Copyright (c) 2003 Leo Simons.
005:        All rights reserved.
006:
007:        Permission is hereby granted, free of charge, to any person obtaining
008:        a copy of this software and associated documentation files (the
009:        "Software"), to deal in the Software without restriction, including
010:        without limitation the rights to use, copy, modify, merge, publish,
011:        distribute, sublicense, and/or sell copies of the Software, and to
012:        permit persons to whom the Software is furnished to do so, subject to
013:        the following conditions:
014:
015:        The above copyright notice and this permission notice shall be
016:        included in all copies or substantial portions of the Software.
017:
018:        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
019:        EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
020:        MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
021:        IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
022:        CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
023:        TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
024:        SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
025:        ==================================================================== */
026:        package org.jicarilla.webserver.plumbing;
027:
028:        import org.jicarilla.http.HTTPField;
029:        import org.jicarilla.http.HTTPMessage;
030:        import org.jicarilla.lang.RegexpSelector;
031:        import org.jicarilla.lang.Selector;
032:
033:        import java.net.InetAddress;
034:        import java.util.ArrayList;
035:        import java.util.Iterator;
036:        import java.util.List;
037:        import java.util.regex.Pattern;
038:
039:        /**
040:         * 
041:         *
042:         * @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
043:         * @version $Id: HTTPSelector.java,v 1.1 2004/03/31 12:11:00 lsimons Exp $
044:         */
045:        public class HTTPSelector implements  Selector {
046:            protected List m_methodSelectors = new ArrayList();
047:            protected List m_uriSelectors = new ArrayList();
048:            protected List m_versionSelectors = new ArrayList();
049:            protected List m_headerSelectors = new ArrayList();
050:            protected List m_bodySelectors = new ArrayList();
051:
052:            public final static boolean POLICY_AND = true;
053:            public final static boolean POLICY_OR = false;
054:
055:            protected boolean m_methodSelectorPolicy = POLICY_OR;
056:            protected boolean m_uriSelectorPolicy = POLICY_OR;
057:            protected boolean m_versionSelectorPolicy = POLICY_OR;
058:            protected boolean m_headerSelectorPolicy = POLICY_AND;
059:            protected boolean m_bodySelectorPolicy = POLICY_AND;
060:            protected boolean m_globalPolicy = POLICY_AND;
061:
062:            public boolean select(final Object object) {
063:                if (!(object instanceof  HTTPEvent))
064:                    return false;
065:
066:                final HTTPEvent event = (HTTPEvent) object;
067:                final HTTPMessage request = event.getHTTPRequest();
068:
069:                if (m_globalPolicy == POLICY_AND)
070:                    return selectStartLine(request) && selectHeaders(request)
071:                            && selectBody(request);
072:                else
073:                    // POLICY_OR
074:                    return selectStartLine(request) || selectHeaders(request)
075:                            || selectBody(request);
076:            }
077:
078:            public void addURLPattern(final Pattern pattern) {
079:                final Selector s = new RegexpSelector(pattern);
080:                m_uriSelectors.add(s);
081:            }
082:
083:            public void addVirtualHost(final InetAddress host) {
084:                final String hostname = host.getHostName();
085:                final Pattern pattern = Pattern.compile("Host:[ \\t]*"
086:                        + hostname, Pattern.CASE_INSENSITIVE);
087:                final Selector s = new RegexpSelector(pattern);
088:                m_uriSelectors.add(s);
089:            }
090:
091:            protected boolean selectStartLine(final HTTPMessage request) {
092:                if (m_globalPolicy == POLICY_AND)
093:                    return selectMethod(request) && selectURI(request)
094:                            && selectVersion(request);
095:                else
096:                    // POLICY_OR
097:                    return selectMethod(request) || selectURI(request)
098:                            || selectVersion(request);
099:            }
100:
101:            protected boolean selectMethod(final HTTPMessage request) {
102:                if (m_methodSelectors.size() == 0)
103:                    return true;
104:
105:                final String method = request.getField1String();
106:                return select(method, m_methodSelectors, m_methodSelectorPolicy);
107:            }
108:
109:            protected boolean selectURI(final HTTPMessage request) {
110:                if (m_uriSelectors.size() == 0)
111:                    return true;
112:
113:                final String uri = request.getField2String();
114:                return select(uri, m_uriSelectors, m_uriSelectorPolicy);
115:            }
116:
117:            protected boolean selectVersion(final HTTPMessage request) {
118:                if (m_versionSelectors.size() == 0)
119:                    return true;
120:
121:                final String version = request.getField3String();
122:                return select(version, m_methodSelectors,
123:                        m_methodSelectorPolicy);
124:            }
125:
126:            protected boolean selectHeaders(final HTTPMessage request) {
127:                if (m_versionSelectors.size() == 0)
128:                    return true;
129:
130:                final List headers = request.getHeaders();
131:                final Iterator it = headers.iterator();
132:                if (m_headerSelectorPolicy == POLICY_AND) {
133:                    while (it.hasNext()) {
134:                        final HTTPField header = (HTTPField) it.next();
135:                        final String headerString = header.toExternalForm();
136:                        if (!selectHeader(headerString, m_headerSelectors,
137:                                m_headerSelectorPolicy))
138:                            return false;
139:                    }
140:                    return true;
141:                } else {
142:                    while (it.hasNext()) {
143:                        final HTTPField header = (HTTPField) it.next();
144:                        final String headerString = header.toExternalForm();
145:                        if (selectHeader(headerString, m_headerSelectors,
146:                                m_headerSelectorPolicy))
147:                            return true;
148:                    }
149:                    return true;
150:                }
151:            }
152:
153:            protected boolean selectBody(final HTTPMessage request) {
154:                if (m_bodySelectors.size() == 0)
155:                    return true;
156:
157:                return select(request.getBodyAsString(), m_bodySelectors,
158:                        m_bodySelectorPolicy);
159:            }
160:
161:            protected boolean select(final String field, final List selectors,
162:                    final boolean policy) {
163:                final Iterator it = selectors.iterator();
164:                if (policy == POLICY_AND) {
165:                    while (it.hasNext()) {
166:                        final Selector selector = (Selector) it.next();
167:                        if (!selector.select(field))
168:                            return false;
169:                    }
170:                    return true;
171:                } else {
172:                    // POLICY_OR
173:                    while (it.hasNext()) {
174:                        final Selector selector = (Selector) it.next();
175:                        if (selector.select(field))
176:                            return true;
177:                    }
178:                    return false;
179:                }
180:            }
181:
182:            protected boolean selectHeader(final String header,
183:                    final List selectors, final boolean policy) {
184:                final Iterator it = selectors.iterator();
185:                while (it.hasNext()) {
186:                    final Selector selector = (Selector) it.next();
187:                    if (selector.select(header))
188:                        return true;
189:                }
190:                return false;
191:            }
192:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.