View Javadoc

1   /*
2    *  Java HTML Tidy - JTidy
3    *  HTML parser and pretty printer
4    *
5    *  Copyright (c) 1998-2000 World Wide Web Consortium (Massachusetts
6    *  Institute of Technology, Institut National de Recherche en
7    *  Informatique et en Automatique, Keio University). All Rights
8    *  Reserved.
9    *
10   *  Contributing Author(s):
11   *
12   *     Dave Raggett <dsr@w3.org>
13   *     Andy Quick <ac.quick@sympatico.ca> (translation to Java)
14   *     Gary L Peskin <garyp@firstech.com> (Java development)
15   *     Sami Lempinen <sami@lempinen.net> (release management)
16   *     Fabrizio Giustina <fgiust at users.sourceforge.net>
17   *     Vlad Skarzhevskyy <vlads at users.sourceforge.net> (JTidy servlet  development)
18   *
19   *  The contributing author(s) would like to thank all those who
20   *  helped with testing, bug fixes, and patience.  This wouldn't
21   *  have been possible without all of you.
22   *
23   *  COPYRIGHT NOTICE:
24   *
25   *  This software and documentation is provided "as is," and
26   *  the copyright holders and contributing author(s) make no
27   *  representations or warranties, express or implied, including
28   *  but not limited to, warranties of merchantability or fitness
29   *  for any particular purpose or that the use of the software or
30   *  documentation will not infringe any third party patents,
31   *  copyrights, trademarks or other rights.
32   *
33   *  The copyright holders and contributing author(s) will not be
34   *  liable for any direct, indirect, special or consequential damages
35   *  arising out of any use of the software or documentation, even if
36   *  advised of the possibility of such damage.
37   *
38   *  Permission is hereby granted to use, copy, modify, and distribute
39   *  this source code, or portions hereof, documentation and executables,
40   *  for any purpose, without fee, subject to the following restrictions:
41   *
42   *  1. The origin of this source code must not be misrepresented.
43   *  2. Altered versions must be plainly marked as such and must
44   *     not be misrepresented as being the original source.
45   *  3. This Copyright notice may not be removed or altered from any
46   *     source or altered source distribution.
47   *
48   *  The copyright holders and contributing author(s) specifically
49   *  permit, without fee, and encourage the use of this source code
50   *  as a component for supporting the Hypertext Markup Language in
51   *  commercial products. If you use this source code in a product,
52   *  acknowledgment is not required but would be appreciated.
53   *
54   */
55  package org.w3c.tidy.servlet.data;
56  /*
57   * Created on 18.09.2004
58   */
59  import org.w3c.tidy.TidyMessage;
60  import org.w3c.tidy.TidyMessageListener;
61  import org.w3c.tidy.servlet.ResponseRecord;
62  
63  import java.util.List;
64  import java.util.Vector;
65  
66  
67  /***
68   * Data to store Validation results and error.
69   * @todo Create the API interface for adding additional attributes like JSP name, action
70   *
71   * @author Vlad Skarzhevskyy <a href="mailto:skarzhevskyy@gmail.com">skarzhevskyy@gmail.com</a>
72   * @version $Revision: 1.2 $ ($Author: vlads $)
73   */
74  public class DefaultResponseRecord implements TidyMessageListener, ResponseRecord
75  {
76  
77      private Object requestID;
78  
79      private int parseErrors;
80  
81      private int parseWarnings;
82  
83      private String html;
84  
85      private String htmlResult;
86  
87      private String report;
88  
89      private List messages;
90  
91      private long parsTime;
92  
93      private long when;
94  
95      public DefaultResponseRecord()
96      {
97          messages = new Vector();
98          when = System.currentTimeMillis();
99      }
100 
101     public void messageReceived(TidyMessage message)
102     {
103         if (message.getLevel().equals(TidyMessage.Level.ERROR))
104         {
105             parseErrors++;
106         }
107         else if (message.getLevel().equals(TidyMessage.Level.WARNING))
108         {
109             parseWarnings++;
110         }
111         messages.add(message);
112     }
113 
114     /***
115      * @return Returns the requestID.
116      */
117     public Object getRequestID()
118     {
119         return requestID;
120     }
121 
122     /***
123      * @param requestID The requestID to set.
124      */
125     public void setRequestID(Object requestID)
126     {
127         this.requestID = requestID;
128     }
129 
130     /***
131      * @return Returns the html.
132      */
133     public String getHtmlInput()
134     {
135         return html;
136     }
137 
138     /***
139      * @param html The html to set.
140      */
141     public void setHtmlInput(String html)
142     {
143         this.html = html;
144     }
145 
146     /***
147      * @return Returns the parseErrors.
148      */
149     public int getParseErrors()
150     {
151         return parseErrors;
152     }
153 
154     /***
155      * @param parseErrors The parseErrors to set.
156      */
157     public void setParseErrors(int parseErrors)
158     {
159         this.parseErrors = parseErrors;
160     }
161 
162     /***
163      * @return Returns the parseWarnings.
164      */
165     public int getParseWarnings()
166     {
167         return parseWarnings;
168     }
169 
170     /***
171      * @param parseWarnings The parseWarnings to set.
172      */
173     public void setParseWarnings(int parseWarnings)
174     {
175         this.parseWarnings = parseWarnings;
176     }
177 
178     /***
179      * @return Returns the report.
180      */
181     public String getReport()
182     {
183         return report;
184     }
185 
186     /***
187      * @param report The report to set.
188      */
189     public void setReport(String report)
190     {
191         this.report = report;
192     }
193 
194     /***
195      * @return Returns the messages.
196      */
197     public List getMessages()
198     {
199         return messages;
200     }
201 
202     /***
203      * @return Returns the parsTime.
204      */
205     public long getParsTime()
206     {
207         return parsTime;
208     }
209 
210     /***
211      * @param parsTime The parsTime to set.
212      */
213     public void setParsTime(long parsTime)
214     {
215         this.parsTime = parsTime;
216     }
217 
218     /***
219      * @return Returns the when.
220      */
221     public long getWhen()
222     {
223         return when;
224     }
225 
226     /***
227      * @return Returns the htmlResult.
228      */
229     public String getHtmlOutput()
230     {
231         return htmlResult;
232     }
233 
234     /***
235      * @param html The htmlResult to set.
236      */
237     public void setHtmlOutput(String html)
238     {
239         this.htmlResult = html;
240     }
241 
242     /***
243      * @return Returns the part of ImageName shown as icon or null to use default implementation
244      */
245     public String getImageName()
246     {
247         String imageName = "unknown";
248         if (getParseErrors() != 0)
249         {
250             imageName = "error";
251         }
252         else if (getParseWarnings() != 0)
253         {
254             imageName = "warning";
255         }
256         else
257         {
258             imageName = "ok";
259         }
260         return imageName;
261     }
262 }