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


001:        package net.matuschek.html;
002:
003:        /*********************************************
004:         Copyright (c) 2001 by Daniel Matuschek
005:         *********************************************/
006:
007:        import java.net.*;
008:        import java.util.*;
009:
010:        /**
011:         * This class implements a stores settings for web forms.
012:         * It is used by the WebRobot to fill form field with
013:         * predefined values.
014:         *
015:         * <b>FormHandler is not thread safe</b>. That means you can't 
016:         * use the same formHandler in different tasks with different addValue() calls,
017:         * because there is only one internal array to store those values.
018:         * 
019:         * @author Daniel Matuschek 
020:         * @version $Id $
021:         */
022:        public class FormHandler {
023:
024:            /**
025:             * initializes a new FormHandler without any settings
026:             */
027:            public FormHandler() {
028:                defaults = new Vector<FormField>();
029:                clearValues();
030:            }
031:
032:            /**
033:             * add a new default value for this form handler
034:             */
035:            public void addDefault(String fieldname, String value) {
036:                FormField ff = new FormField();
037:                ff.setFieldname(fieldname);
038:                ff.setValue(value);
039:                defaults.add(ff);
040:            }
041:
042:            /**
043:             * add a new value for this form handler
044:             */
045:            public void addValue(String fieldname, String value) {
046:                FormField ff = new FormField();
047:                ff.setFieldname(fieldname);
048:                ff.setValue(value);
049:                values.add(ff);
050:            }
051:
052:            /**
053:             * if we have added values before, this function removed all 
054:             * values (e.g. to retrieve a new document with a different
055:             * set of values)
056:             */
057:            public void clearValues() {
058:                values = new Vector<FormField>();
059:            }
060:
061:            public String getUrl() {
062:                //return url.toString(); 
063:                return url;
064:            }
065:
066:            public void setUrl(String u) throws MalformedURLException {
067:                //this.url=new URL(u); 
068:                this .url = u;
069:            }
070:
071:            /**
072:             * construct an encoded string of all attributes and their values
073:             * to process this form
074:             */
075:            public String getParamString() {
076:                StringBuffer sb = new StringBuffer();
077:
078:                // first, use the defaults
079:                for (int i = 0; i < defaults.size(); i++) {
080:                    FormField ff = (FormField) defaults.elementAt(i);
081:                    // default overidden by another value ?
082:                    if (!hasValue(ff.getFieldname())) {
083:                        sb.append(ff.toEncodedString());
084:                        sb.append('&');
085:                    }
086:                }
087:
088:                // now add the values
089:                for (int i = 0; i < values.size(); i++) {
090:                    FormField ff = (FormField) values.elementAt(i);
091:                    sb.append(ff.toEncodedString());
092:                    sb.append('&');
093:                }
094:
095:                // remove the last "&"
096:                sb.deleteCharAt(sb.length() - 1);
097:
098:                return sb.toString();
099:            }
100:
101:            /**
102:             * look, if we have a value for this attribute or if
103:             * we should use the default
104:             */
105:            protected boolean hasValue(String attrib) {
106:                for (int i = 0; i < values.size(); i++) {
107:                    FormField ff = (FormField) values.elementAt(i);
108:                    if (ff.getFieldname().equals(attrib)) {
109:                        return true;
110:                    }
111:                }
112:                return false;
113:            }
114:
115:            public int getMethod() {
116:                return method;
117:            }
118:
119:            public void setMethod(int method) {
120:                this .method = method;
121:            }
122:
123:            /**
124:             * Get the value of defaults.
125:             * @return Value of defaults.
126:             */
127:            public Vector getDefaults() {
128:                return defaults;
129:            }
130:
131:            /**
132:             * Set the value of defaults.
133:             * @param v  Value to assign to defaults.
134:             */
135:            public void setDefaults(Vector<FormField> v) {
136:                this .defaults = v;
137:            }
138:
139:            /**
140:             * Get the value of values.
141:             * @return Value of values.
142:             */
143:            public Vector getValues() {
144:                return values;
145:            }
146:
147:            /**
148:             * Set the value of values.
149:             * @param v  Value to assign to values.
150:             */
151:            public void setValues(Vector<FormField> v) {
152:                this .values = v;
153:            }
154:
155:            /**
156:             * GET or POST ?
157:             */
158:            private int method;
159:
160:            /**
161:             *@link aggregation
162:             *     @associates <{FormField}>*/
163:            private Vector<FormField> defaults;
164:
165:            // since not allways a full url is given, this solution is better.
166:            // a set URL with "/search" would throw a MalformatException
167:            private String url;
168:            //private URL url;
169:
170:            /**
171:             *@link aggregation
172:             *     @associates <{FormField}>*/
173:            private Vector<FormField> values;
174:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.