Source Code Cross Referenced for DownloadRule.java in  » Web-Crawler » JoBo » net » matuschek » http » 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 Crawler » JoBo » net.matuschek.http 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.matuschek.http;
002:
003:        /*********************************************
004:         Copyright (c) 2001 by Daniel Matuschek
005:         *********************************************/
006:
007:        /**
008:         * This class implements a rule what documents should be
009:         * downloaded based on file size and mime type
010:         * 
011:         * @author Daniel Matuschek
012:         * @version $Id: DownloadRule.java,v 1.4 2003/02/25 13:21:03 oliver_schmidt Exp $
013:         */
014:        public class DownloadRule {
015:
016:            private final static int MINDEFAULT = 0;
017:            private final static int MAXDEFAULT = Integer.MAX_VALUE;
018:
019:            /** basic mime type **/
020:            private String mimeBaseType = null;
021:            private String mimeSubType = null;
022:            private int minSize = MINDEFAULT;
023:            private int maxSize = MAXDEFAULT;
024:
025:            /** allow or deny download ? **/
026:            private boolean allow;
027:
028:            /** allow or deny processing ? **/
029:            private boolean processAllowed = true;
030:
031:            /**
032:               empty constructor that does nothing
033:             **/
034:            public DownloadRule() {
035:            }
036:
037:            /**
038:               Get the value of minSize.
039:               @return Value of minSize.
040:             **/
041:            public int getMinSize() {
042:                return minSize;
043:            }
044:
045:            /**
046:               Set the value of minSize.
047:               @param v  Value to assign to minSize.
048:             **/
049:            public void setMinSize(int minSize) {
050:                if (minSize >= MINDEFAULT) {
051:                    this .minSize = minSize;
052:                }
053:            }
054:
055:            /**
056:               Get the value of maxSize.
057:               @return Value of maxSize.
058:             **/
059:            public int getMaxSize() {
060:                return maxSize;
061:            }
062:
063:            /**
064:               Set the value of maxSize.
065:               @param v  Value to assign to maxSize.
066:             **/
067:            public void setMaxSize(int maxSize) {
068:                if (maxSize >= MINDEFAULT) {
069:                    this .maxSize = maxSize;
070:                }
071:            }
072:
073:            /**
074:               Get the value of allow.
075:               @return Value of allow.
076:             **/
077:            public boolean getAllow() {
078:                return allow;
079:            }
080:
081:            /**
082:               Set the value of allow.
083:               @param v  Value to assign to allow.
084:             **/
085:            public void setAllow(boolean allow) {
086:                this .allow = allow;
087:            }
088:
089:            /** 
090:             * Gets the value of processAllowed
091:             * @return true, if this rule allows indexing, false if it denies
092:             *  something
093:             */
094:            public boolean getProcessAllowed() {
095:                return processAllowed && allow;
096:            }
097:
098:            /** 
099:             * Sets the value of processAllowed
100:             * @param processAllowed true, if this rule allows indexing, false if it denies
101:             * something
102:             */
103:            public void setProcessAllowed(boolean processAllowed) {
104:                this .processAllowed = processAllowed;
105:            }
106:
107:            /**
108:               Get the value of mimeBaseType.
109:               @return Value of mimeBaseType.
110:             **/
111:            public String getMimeBaseType() {
112:                return mimeBaseType;
113:            }
114:
115:            /**
116:               Set the value of mimeBaseType.
117:               @param v  Value to assign to mimeBaseType.
118:             **/
119:            public void setMimeBaseType(String mimeBaseType) {
120:                this .mimeBaseType = mimeBaseType;
121:            }
122:
123:            /**
124:               Get the value of mimeSubType.
125:               @return Value of mimeSubType.
126:             **/
127:            public String getMimeSubType() {
128:                return mimeSubType;
129:            }
130:
131:            /**
132:               Set the value of mimeSubType.
133:               @param v  Value to assign to mimeSubType.
134:             **/
135:            public void setMimeSubType(String mimeSubType) {
136:                this .mimeSubType = mimeSubType;
137:            }
138:
139:            /**
140:               Get the value of mimeType.
141:               @return Value of mimeType.
142:             **/
143:            public String getMimeType() {
144:                return mimeBaseType + "/" + mimeSubType;
145:            }
146:
147:            /**
148:               Set the value of mimeType.
149:               @param v  Value to assign to mimeType.
150:             **/
151:            public void setMimeType(String mimeType)
152:                    throws IllegalArgumentException {
153:                int pos = mimeType.indexOf("/");
154:                if (pos < 0) {
155:                    throw new IllegalArgumentException(
156:                            "mime type must be in the format "
157:                                    + " basetype/subtype");
158:                }
159:
160:                this .mimeBaseType = mimeType.substring(0, pos);
161:                this .mimeSubType = mimeType.substring(pos + 1);
162:            }
163:
164:            public boolean matches(String mimeBaseType, String mimeSubType,
165:                    int size) {
166:                if (simpleStringMatch(mimeBaseType, this .mimeBaseType)
167:                        && simpleStringMatch(mimeSubType, this .mimeSubType)) {
168:                    if (size >= 0) {
169:                        if ((size >= this .minSize) && (size <= this .maxSize)) {
170:                            return true;
171:                        }
172:                    } else {
173:                        // if sizes are default (0, MAXINT), this rule belongs
174:                        // to ALL documents of this type (it matches), otherwise it depends
175:                        // on size and doesn't match !
176:                        if ((this .minSize == MINDEFAULT)
177:                                && (this .maxSize == MAXDEFAULT)) {
178:                            return true;
179:                        } else {
180:                            return false;
181:                        }
182:                    }
183:                }
184:                return false;
185:            }
186:
187:            /**
188:               matches the given string to the rule string
189:               @param value a string to test
190:               @param rule rule used (can be a value or "* that will
191:               match anything
192:               @return true is value is equal to rule or rule is "*"
193:             **/
194:            protected boolean simpleStringMatch(String value, String rule) {
195:                if (rule.equals("*")) {
196:                    return true;
197:                }
198:                if (value.equalsIgnoreCase(rule)) {
199:                    return true;
200:                }
201:                return false;
202:            }
203:
204:            /**
205:               Convert rule to a String
206:               @return a String representation of this rule. Format may change
207:               without notice (only useful for debugging or logging)
208:             **/
209:            public String toString() {
210:                String s = null;
211:                if (allow) {
212:                    s = "allow";
213:                } else {
214:                    s = "deny";
215:                }
216:                return mimeBaseType + "/" + mimeSubType + " >" + minSize + " <"
217:                        + maxSize + " " + s;
218:            }
219:
220:        } // DownloadRule
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.