Source Code Cross Referenced for Option.java in  » Ajax » Laszlo-4.0.10 » org » openlaszlo » server » 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 » Ajax » Laszlo 4.0.10 » org.openlaszlo.server 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /******************************************************************************
002:         * Option.java
003:         * ****************************************************************************/package org.openlaszlo.server;
004:
005:        import java.io.*;
006:        import java.util.*;
007:
008:        import org.apache.log4j.Logger;
009:        import org.jdom.*;
010:        import org.apache.regexp.RE;
011:        import org.apache.regexp.RESyntaxException;
012:
013:        /**
014:         * An Option contains a set of deny and allow patterns.
015:         * 
016:         * @author Eric Bloch
017:         * @version 1.0 
018:         */
019:        public class Option implements  Serializable {
020:
021:            private static Logger mLogger = Logger.getLogger(Option.class);
022:
023:            // No need to sync; access is read only after construction. These lists hold
024:            // regexp objects.
025:            private ArrayList allowList = null;
026:            private ArrayList deniesList = null;
027:
028:            // These lists hold the pattern for the regexp objects.
029:            private ArrayList allowSerializableList = null;
030:            private ArrayList deniesSerializableList = null;
031:
032:            void init() {
033:                if (allowList == null)
034:                    allowList = new ArrayList();
035:                if (deniesList == null)
036:                    deniesList = new ArrayList();
037:                if (allowSerializableList == null)
038:                    allowSerializableList = new ArrayList();
039:                if (deniesSerializableList == null)
040:                    deniesSerializableList = new ArrayList();
041:            }
042:
043:            Option() {
044:                init();
045:            }
046:
047:            /**
048:             * Constructs a new option
049:             * @param elt
050:             */
051:            Option(Element el) {
052:                this ();
053:                addElement(el);
054:            }
055:
056:            /**
057:             * Add new patterns to option
058:             */
059:            public void addElement(Element el) {
060:                List list = el.getChildren();
061:                ListIterator iter = list.listIterator();
062:
063:                Element a = el.getChild("allow", el.getNamespace());
064:                if (a != null)
065:                    addPatterns(allowList, allowSerializableList, a);
066:                Element d = el.getChild("deny", el.getNamespace());
067:                if (d != null)
068:                    addPatterns(deniesList, deniesSerializableList, d);
069:            }
070:
071:            /**
072:             * @param l list to add REs to
073:             * @param element that has pattern element children
074:             */
075:            private void addPatterns(ArrayList list,
076:                    ArrayList serializableList, Element elt) {
077:                ListIterator iter = elt.getChildren("pattern",
078:                        elt.getNamespace()).listIterator();
079:
080:                while (iter.hasNext()) {
081:                    String p = ((Element) iter.next()).getTextNormalize();
082:                    mLogger.debug(elt.getName() + ": " + p);
083:                    try {
084:                        RE re = new RE(p);
085:                        list.add(re);
086:                        serializableList.add(p);
087:                    } catch (RESyntaxException e) {
088:                        mLogger.error(
089:                        /* (non-Javadoc)
090:                         * @i18n.test
091:                         * @org-mes="ignoring bad regexp syntax: " + p[0]
092:                         */
093:                        org.openlaszlo.i18n.LaszloMessages.getMessage(
094:                                Option.class.getName(), "051019-99",
095:                                new Object[] { p }));
096:                        continue;
097:                    }
098:                }
099:            }
100:
101:            /**
102:             * @param val value to check against
103:             * @param allow if true, an undefined option means that it is allowed, else
104:             * it is denied.
105:             * @return true if this option allows the given value
106:             */
107:            boolean allows(String val, boolean allow) {
108:
109:                mLogger.debug(
110:                /* (non-Javadoc)
111:                 * @i18n.test
112:                 * @org-mes="checking: " + p[0]
113:                 */
114:                org.openlaszlo.i18n.LaszloMessages.getMessage(Option.class
115:                        .getName(), "051019-120", new Object[] { val }));
116:
117:                // If we don't specify what's allowed, allow all.
118:                if (!allowList.isEmpty()) {
119:                    allow = false;
120:                    ListIterator iter = allowList.listIterator();
121:                    while (iter.hasNext()) {
122:                        RE re = (RE) iter.next();
123:                        if (re.match(val)) {
124:                            allow = true;
125:                            break;
126:                        }
127:                    }
128:                }
129:
130:                if (allow) {
131:                    ListIterator iter = deniesList.listIterator();
132:                    int i = 0;
133:                    while (iter.hasNext()) {
134:                        RE re = (RE) iter.next();
135:                        if (re.match(val)) {
136:                            allow = false;
137:                            break;
138:                        }
139:                    }
140:                }
141:                return allow;
142:            }
143:
144:            /**
145:             * Handle object serialization.
146:             */
147:            private void writeObject(ObjectOutputStream out) throws IOException {
148:
149:                ListIterator iter;
150:
151:                // write out allow
152:                out.writeInt(allowSerializableList.size());
153:                iter = allowSerializableList.listIterator();
154:                while (iter.hasNext()) {
155:                    out.writeObject(iter.next());
156:                }
157:
158:                // write out denies
159:                out.writeInt(deniesSerializableList.size());
160:                iter = deniesSerializableList.listIterator();
161:                while (iter.hasNext()) {
162:                    out.writeObject(iter.next());
163:                }
164:            }
165:
166:            /**
167:             * Handle object deserialization.
168:             */
169:            private void readObject(ObjectInputStream in) throws IOException,
170:                    ClassNotFoundException {
171:                int size, i;
172:
173:                init();
174:
175:                size = in.readInt();
176:                for (i = 0; i < size; i++) {
177:                    String p = (String) in.readObject();
178:                    try {
179:                        allowList.add(new RE(p));
180:                        allowSerializableList.add(p);
181:                    } catch (RESyntaxException e) {
182:                        mLogger.error(
183:                        /* (non-Javadoc)
184:                         * @i18n.test
185:                         * @org-mes="ignoring bad regexp syntax: " + p[0]
186:                         */
187:                        org.openlaszlo.i18n.LaszloMessages.getMessage(
188:                                Option.class.getName(), "051019-99",
189:                                new Object[] { p }));
190:                        continue;
191:                    }
192:                }
193:
194:                size = in.readInt();
195:                for (i = 0; i < size; i++) {
196:                    String p = (String) in.readObject();
197:                    try {
198:                        deniesList.add(new RE(p));
199:                        deniesSerializableList.add(p);
200:                    } catch (RESyntaxException e) {
201:                        mLogger.error(
202:                        /* (non-Javadoc)
203:                         * @i18n.test
204:                         * @org-mes="ignoring bad regexp syntax: " + p[0]
205:                         */
206:                        org.openlaszlo.i18n.LaszloMessages.getMessage(
207:                                Option.class.getName(), "051019-99",
208:                                new Object[] { p }));
209:                        continue;
210:                    }
211:                }
212:            }
213:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.