Source Code Cross Referenced for HtmlParserMessage.java in  » Testing » webtest » com » canoo » webtest » steps » 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 » Testing » webtest » com.canoo.webtest.steps 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // Copyright © 2002-2005 Canoo Engineering AG, Switzerland.
002:        package com.canoo.webtest.steps;
003:
004:        import com.gargoylesoftware.htmlunit.html.HTMLParserListener;
005:
006:        import java.net.URL;
007:        import java.util.ArrayList;
008:        import java.util.List;
009:
010:        /**
011:         * Represents a message generated by an html parser.
012:         * @author Marc Guillemot
013:         */
014:        public class HtmlParserMessage implements  Comparable {
015:            /**
016:             * Safe enum to represent the type of a message.
017:             */
018:            public static final class Type implements  Comparable {
019:                public static final String ERROR_NAME = "error";
020:                public static final String WARNING_NAME = "warning";
021:                public static final Type ERROR = new Type(ERROR_NAME);
022:                public static final Type WARNING = new Type(WARNING_NAME);
023:                private String fName;
024:
025:                /**
026:                 * Private constructor to prohibit external instantiations
027:                 * @param str
028:                 */
029:                private Type(final String str) {
030:                    fName = str;
031:                }
032:
033:                /**
034:                 * Compares with following rule: error > warning
035:                 * (no need to override equals(): in this case it is equivalent to ==)
036:                 *
037:                 * @throws ClassCastException if the argument is not a {@link HtmlParserMessage.Type}
038:                 */
039:                public int compareTo(final Object o) {
040:                    final Type other = (Type) o;
041:                    if (getName().equals(other.getName()))
042:                        return 0;
043:                    else
044:                        return isError() ? 1 : -1;
045:                }
046:
047:                /**
048:                 * Gets the name of the type
049:                 */
050:                public String getName() {
051:                    return fName;
052:                }
053:
054:                public boolean isError() {
055:                    return ERROR_NAME.equals(getName());
056:                }
057:
058:                public boolean isWarning() {
059:                    return WARNING_NAME.equals(getName());
060:                }
061:
062:                /**
063:                 * Gets the name.
064:                 */
065:                public String toString() {
066:                    return getName();
067:                }
068:            }
069:
070:            /**
071:             * Listener collecting the messages from parser.
072:             */
073:            public static class MessageCollector implements  HTMLParserListener {
074:                private List fMessages = new ArrayList();
075:
076:                public void error(final String message, final URL url,
077:                        final int line, final int column, final String key) {
078:                    fMessages.add(new HtmlParserMessage(Type.ERROR, url,
079:                            message, line, column));
080:                }
081:
082:                public void warning(final String message, final URL url,
083:                        final int line, final int column, final String key) {
084:                    fMessages.add(new HtmlParserMessage(Type.WARNING, url,
085:                            message, line, column));
086:                }
087:
088:                /**
089:                 * Gets all messages received since last call to this method.
090:                 * @return a list of {@link HtmlParserMessage}
091:                 */
092:                public List popAll() {
093:                    final List l = fMessages;
094:                    fMessages = new ArrayList();
095:                    return l;
096:                }
097:            }
098:
099:            private int fColumn;
100:            private int fLine;
101:            private String fMessage;
102:            private Type fType;
103:            private URL fUrl;
104:            private volatile int fHash;
105:
106:            public HtmlParserMessage(final Type type, final URL url,
107:                    final String strMessage, final int iLine, final int iColumn) {
108:                fType = type;
109:                fUrl = url;
110:                fMessage = strMessage;
111:                fLine = iLine;
112:                fColumn = iColumn;
113:            }
114:
115:            /**
116:             * Compare to an other HtmlParserMessage according to (url, line, col, type, msg)
117:             * @see java.lang.Comparable#compareTo(java.lang.Object)
118:             */
119:            public int compareTo(final Object o) {
120:                final HtmlParserMessage other = (HtmlParserMessage) o;
121:
122:                // first compare urls
123:                int iRep = getURL().toString().compareTo(
124:                        other.getURL().toString());
125:                if (iRep != 0)
126:                    return iRep;
127:
128:                // then line in file
129:                iRep = getLine() - other.getLine();
130:                if (iRep != 0)
131:                    return iRep;
132:
133:                // then column in line
134:                iRep = getColumn() - other.getColumn();
135:                if (iRep != 0)
136:                    return iRep;
137:
138:                // error or warning
139:                iRep = getType().compareTo(other.getType());
140:                if (iRep != 0)
141:                    return iRep;
142:
143:                // and at least the message
144:                return getMessage().compareTo(other.getMessage());
145:            }
146:
147:            public int hashCode() {
148:                if (fHash == 0)
149:                    fHash = calculateHash();
150:                return fHash;
151:            }
152:
153:            private int calculateHash() {
154:                // aggregate of primes multiplied by hashes of components
155:                final int h1 = 3 * new Integer(fColumn).hashCode();
156:                final int h2 = 5 * new Integer(fLine).hashCode();
157:                final int h3 = 7 * fMessage.hashCode();
158:                final int h4 = 11 * fType.hashCode();
159:                final int h5 = 13 * fUrl.hashCode();
160:                return h1 + h2 + h3 + h4 + h5;
161:            }
162:
163:            /**
164:             * Test for equality with an other HtmlParserMessage according to (url, line, col, type, msg)
165:             * @see java.lang.Object#equals(java.lang.Object)
166:             */
167:            public boolean equals(final Object o) {
168:                return compareTo(o) == 0;
169:            }
170:
171:            /**
172:             * Gets the column in the source file for which the message has been generated
173:             */
174:            public int getColumn() {
175:                return fColumn;
176:            }
177:
178:            /**
179:             * Gets the line in the source file for which the message has been generated
180:             */
181:            public int getLine() {
182:                return fLine;
183:            }
184:
185:            /**
186:             * Gets the description of the message
187:             */
188:            public String getMessage() {
189:                return fMessage;
190:            }
191:
192:            /**
193:             * Gets the type of the message determining its severity
194:             */
195:            public Type getType() {
196:                return fType;
197:            }
198:
199:            /**
200:             * Gets the url of the file which parsing caused this message.
201:             */
202:            public URL getURL() {
203:                return fUrl;
204:            }
205:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.