Source Code Cross Referenced for Report.java in  » HTML-Parser » JTidy » org » w3c » tidy » 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 » HTML Parser » JTidy » org.w3c.tidy 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         *  Java HTML Tidy - JTidy
0003:         *  HTML parser and pretty printer
0004:         *
0005:         *  Copyright (c) 1998-2000 World Wide Web Consortium (Massachusetts
0006:         *  Institute of Technology, Institut National de Recherche en
0007:         *  Informatique et en Automatique, Keio University). All Rights
0008:         *  Reserved.
0009:         *
0010:         *  Contributing Author(s):
0011:         *
0012:         *     Dave Raggett <dsr@w3.org>
0013:         *     Andy Quick <ac.quick@sympatico.ca> (translation to Java)
0014:         *     Gary L Peskin <garyp@firstech.com> (Java development)
0015:         *     Sami Lempinen <sami@lempinen.net> (release management)
0016:         *     Fabrizio Giustina <fgiust at users.sourceforge.net>
0017:         *
0018:         *  The contributing author(s) would like to thank all those who
0019:         *  helped with testing, bug fixes, and patience.  This wouldn't
0020:         *  have been possible without all of you.
0021:         *
0022:         *  COPYRIGHT NOTICE:
0023:         * 
0024:         *  This software and documentation is provided "as is," and
0025:         *  the copyright holders and contributing author(s) make no
0026:         *  representations or warranties, express or implied, including
0027:         *  but not limited to, warranties of merchantability or fitness
0028:         *  for any particular purpose or that the use of the software or
0029:         *  documentation will not infringe any third party patents,
0030:         *  copyrights, trademarks or other rights. 
0031:         *
0032:         *  The copyright holders and contributing author(s) will not be
0033:         *  liable for any direct, indirect, special or consequential damages
0034:         *  arising out of any use of the software or documentation, even if
0035:         *  advised of the possibility of such damage.
0036:         *
0037:         *  Permission is hereby granted to use, copy, modify, and distribute
0038:         *  this source code, or portions hereof, documentation and executables,
0039:         *  for any purpose, without fee, subject to the following restrictions:
0040:         *
0041:         *  1. The origin of this source code must not be misrepresented.
0042:         *  2. Altered versions must be plainly marked as such and must
0043:         *     not be misrepresented as being the original source.
0044:         *  3. This Copyright notice may not be removed or altered from any
0045:         *     source or altered source distribution.
0046:         * 
0047:         *  The copyright holders and contributing author(s) specifically
0048:         *  permit, without fee, and encourage the use of this source code
0049:         *  as a component for supporting the Hypertext Markup Language in
0050:         *  commercial products. If you use this source code in a product,
0051:         *  acknowledgment is not required but would be appreciated.
0052:         *
0053:         */
0054:        package org.w3c.tidy;
0055:
0056:        import java.io.PrintWriter;
0057:        import java.text.MessageFormat;
0058:        import java.text.SimpleDateFormat;
0059:        import java.util.Date;
0060:        import java.util.MissingResourceException;
0061:        import java.util.ResourceBundle;
0062:
0063:        import org.w3c.tidy.TidyMessage.Level;
0064:
0065:        /**
0066:         * Error/informational message reporter. You should only need to edit the file TidyMessages.properties to localize HTML
0067:         * tidy.
0068:         * @author Dave Raggett <a href="mailto:dsr@w3.org">dsr@w3.org </a>
0069:         * @author Andy Quick <a href="mailto:ac.quick@sympatico.ca">ac.quick@sympatico.ca </a> (translation to Java)
0070:         * @author Fabrizio Giustina
0071:         * @version $Revision: 1.49 $ ($Author: fgiust $)
0072:         */
0073:        public final class Report {
0074:
0075:            /**
0076:             * used to point to Web Accessibility Guidelines.
0077:             */
0078:            public static final String ACCESS_URL = "http://www.w3.org/WAI/GL";
0079:
0080:            /**
0081:             * Release date.
0082:             */
0083:            public static final Date RELEASE_DATE = new Date(1096227718000L);
0084:
0085:            /**
0086:             * Release date String.
0087:             */
0088:            public static final String RELEASE_DATE_STRING = new SimpleDateFormat(
0089:                    "dd MMM yyyy").format(RELEASE_DATE);
0090:
0091:            /**
0092:             * invalid entity: missing semicolon.
0093:             */
0094:            public static final short MISSING_SEMICOLON = 1;
0095:
0096:            /**
0097:             * invalid entity: missing semicolon.
0098:             */
0099:            public static final short MISSING_SEMICOLON_NCR = 2;
0100:
0101:            /**
0102:             * invalid entity: unknown entity.
0103:             */
0104:            public static final short UNKNOWN_ENTITY = 3;
0105:
0106:            /**
0107:             * invalid entity: unescaped ampersand.
0108:             */
0109:            public static final short UNESCAPED_AMPERSAND = 4;
0110:
0111:            /**
0112:             * invalid entity: apos undefined in current definition.
0113:             */
0114:            public static final short APOS_UNDEFINED = 5;
0115:
0116:            /**
0117:             * missing an end tag.
0118:             */
0119:            public static final short MISSING_ENDTAG_FOR = 6;
0120:
0121:            /**
0122:             * missing end tag before.
0123:             */
0124:            public static final short MISSING_ENDTAG_BEFORE = 7;
0125:
0126:            /**
0127:             * discarding unexpected element.
0128:             */
0129:            public static final short DISCARDING_UNEXPECTED = 8;
0130:
0131:            /**
0132:             * nested emphasis.
0133:             */
0134:            public static final short NESTED_EMPHASIS = 9;
0135:
0136:            /**
0137:             * non matching end tag.
0138:             */
0139:            public static final short NON_MATCHING_ENDTAG = 10;
0140:
0141:            /**
0142:             * tag not allowed in.
0143:             */
0144:            public static final short TAG_NOT_ALLOWED_IN = 11;
0145:
0146:            /**
0147:             * missing start tag.
0148:             */
0149:            public static final short MISSING_STARTTAG = 12;
0150:
0151:            /**
0152:             * unexpected end tag.
0153:             */
0154:            public static final short UNEXPECTED_ENDTAG = 13;
0155:
0156:            /**
0157:             * unsing br in place of.
0158:             */
0159:            public static final short USING_BR_INPLACE_OF = 14;
0160:
0161:            /**
0162:             * inserting tag.
0163:             */
0164:            public static final short INSERTING_TAG = 15;
0165:
0166:            /**
0167:             * suspected missing quote.
0168:             */
0169:            public static final short SUSPECTED_MISSING_QUOTE = 16;
0170:
0171:            /**
0172:             * missing title element.
0173:             */
0174:            public static final short MISSING_TITLE_ELEMENT = 17;
0175:
0176:            /**
0177:             * duplicate frameset.
0178:             */
0179:            public static final short DUPLICATE_FRAMESET = 18;
0180:
0181:            /**
0182:             * elments can be nested.
0183:             */
0184:            public static final short CANT_BE_NESTED = 19;
0185:
0186:            /**
0187:             * obsolete element.
0188:             */
0189:            public static final short OBSOLETE_ELEMENT = 20;
0190:
0191:            /**
0192:             * proprietary element.
0193:             */
0194:            public static final short PROPRIETARY_ELEMENT = 21;
0195:
0196:            /**
0197:             * unknown element.
0198:             */
0199:            public static final short UNKNOWN_ELEMENT = 22;
0200:
0201:            /**
0202:             * trim empty element.
0203:             */
0204:            public static final short TRIM_EMPTY_ELEMENT = 23;
0205:
0206:            /**
0207:             * coerce to end tag.
0208:             */
0209:            public static final short COERCE_TO_ENDTAG = 24;
0210:
0211:            /**
0212:             * illegal nesting.
0213:             */
0214:            public static final short ILLEGAL_NESTING = 25;
0215:
0216:            /**
0217:             * noframes content.
0218:             */
0219:            public static final short NOFRAMES_CONTENT = 26;
0220:
0221:            /**
0222:             * content after body.
0223:             */
0224:            public static final short CONTENT_AFTER_BODY = 27;
0225:
0226:            /**
0227:             * inconsistent version.
0228:             */
0229:            public static final short INCONSISTENT_VERSION = 28;
0230:
0231:            /**
0232:             * malformed comment.
0233:             */
0234:            public static final short MALFORMED_COMMENT = 29;
0235:
0236:            /**
0237:             * bad coment chars.
0238:             */
0239:            public static final short BAD_COMMENT_CHARS = 30;
0240:
0241:            /**
0242:             * bad xml comment.
0243:             */
0244:            public static final short BAD_XML_COMMENT = 31;
0245:
0246:            /**
0247:             * bad cdata comment.
0248:             */
0249:            public static final short BAD_CDATA_CONTENT = 32;
0250:
0251:            /**
0252:             * inconsistent namespace.
0253:             */
0254:            public static final short INCONSISTENT_NAMESPACE = 33;
0255:
0256:            /**
0257:             * doctype after tags.
0258:             */
0259:            public static final short DOCTYPE_AFTER_TAGS = 34;
0260:
0261:            /**
0262:             * malformed doctype.
0263:             */
0264:            public static final short MALFORMED_DOCTYPE = 35;
0265:
0266:            /**
0267:             * unexpected end of file.
0268:             */
0269:            public static final short UNEXPECTED_END_OF_FILE = 36;
0270:
0271:            /**
0272:             * doctype not upper case.
0273:             */
0274:            public static final short DTYPE_NOT_UPPER_CASE = 37;
0275:
0276:            /**
0277:             * too many element.
0278:             */
0279:            public static final short TOO_MANY_ELEMENTS = 38;
0280:
0281:            /**
0282:             * unescaped element.
0283:             */
0284:            public static final short UNESCAPED_ELEMENT = 39;
0285:
0286:            /**
0287:             * nested quotation.
0288:             */
0289:            public static final short NESTED_QUOTATION = 40;
0290:
0291:            /**
0292:             * element not empty.
0293:             */
0294:            public static final short ELEMENT_NOT_EMPTY = 41;
0295:
0296:            /**
0297:             * encoding IO conflict.
0298:             */
0299:            public static final short ENCODING_IO_CONFLICT = 42;
0300:
0301:            /**
0302:             * mixed content in block.
0303:             */
0304:            public static final short MIXED_CONTENT_IN_BLOCK = 43;
0305:
0306:            /**
0307:             * missing doctype.
0308:             */
0309:            public static final short MISSING_DOCTYPE = 44;
0310:
0311:            /**
0312:             * space preceding xml declaration.
0313:             */
0314:            public static final short SPACE_PRECEDING_XMLDECL = 45;
0315:
0316:            /**
0317:             * too many elements in.
0318:             */
0319:            public static final short TOO_MANY_ELEMENTS_IN = 46;
0320:
0321:            /**
0322:             * unexpected endag in.
0323:             */
0324:            public static final short UNEXPECTED_ENDTAG_IN = 47;
0325:
0326:            /**
0327:             * replacing element.
0328:             */
0329:            public static final short REPLACING_ELEMENT = 83;
0330:
0331:            /**
0332:             * replacing unexcaped element.
0333:             */
0334:            public static final short REPLACING_UNEX_ELEMENT = 84;
0335:
0336:            /**
0337:             * coerce to endtag.
0338:             */
0339:            public static final short COERCE_TO_ENDTAG_WARN = 85;
0340:
0341:            /**
0342:             * attribute: unknown attribute.
0343:             */
0344:            public static final short UNKNOWN_ATTRIBUTE = 48;
0345:
0346:            /**
0347:             * attribute: missing attribute.
0348:             */
0349:            public static final short MISSING_ATTRIBUTE = 49;
0350:
0351:            /**
0352:             * attribute: missing attribute value.
0353:             */
0354:            public static final short MISSING_ATTR_VALUE = 50;
0355:
0356:            /**
0357:             * attribute: bad attribute value.
0358:             */
0359:            public static final short BAD_ATTRIBUTE_VALUE = 51;
0360:
0361:            /**
0362:             * attribute: unexpected gt.
0363:             */
0364:            public static final short UNEXPECTED_GT = 52;
0365:
0366:            /**
0367:             * attribute: proprietary attribute.
0368:             */
0369:            public static final short PROPRIETARY_ATTRIBUTE = 53;
0370:
0371:            /**
0372:             * attribute: proprietary attribute value.
0373:             */
0374:            public static final short PROPRIETARY_ATTR_VALUE = 54;
0375:
0376:            /**
0377:             * attribute: repeated attribute.
0378:             */
0379:            public static final short REPEATED_ATTRIBUTE = 55;
0380:
0381:            /**
0382:             * attribute: missing image map.
0383:             */
0384:            public static final short MISSING_IMAGEMAP = 56;
0385:
0386:            /**
0387:             * attribute: xml attribute value.
0388:             */
0389:            public static final short XML_ATTRIBUTE_VALUE = 57;
0390:
0391:            /**
0392:             * attribute: missing quotemark.
0393:             */
0394:            public static final short MISSING_QUOTEMARK = 58;
0395:
0396:            /**
0397:             * attribute: unexpected quotemark.
0398:             */
0399:            public static final short UNEXPECTED_QUOTEMARK = 59;
0400:
0401:            /**
0402:             * attribute: id and name mismatch.
0403:             */
0404:            public static final short ID_NAME_MISMATCH = 60;
0405:
0406:            /**
0407:             * attribute: backslash in URI.
0408:             */
0409:            public static final short BACKSLASH_IN_URI = 61;
0410:
0411:            /**
0412:             * attribute: fixed backslash.
0413:             */
0414:            public static final short FIXED_BACKSLASH = 62;
0415:
0416:            /**
0417:             * attribute: illegal URI reference.
0418:             */
0419:            public static final short ILLEGAL_URI_REFERENCE = 63;
0420:
0421:            /**
0422:             * attribute: escaped illegal URI.
0423:             */
0424:            public static final short ESCAPED_ILLEGAL_URI = 64;
0425:
0426:            /**
0427:             * attribute: newline in URI.
0428:             */
0429:            public static final short NEWLINE_IN_URI = 65;
0430:
0431:            /**
0432:             * attribute: anchor not unique.
0433:             */
0434:            public static final short ANCHOR_NOT_UNIQUE = 66;
0435:
0436:            /**
0437:             * attribute: entity in id.
0438:             */
0439:            public static final short ENTITY_IN_ID = 67;
0440:
0441:            /**
0442:             * attribute: joining attribute.
0443:             */
0444:            public static final short JOINING_ATTRIBUTE = 68;
0445:
0446:            /**
0447:             * attribute: expected equalsign.
0448:             */
0449:            public static final short UNEXPECTED_EQUALSIGN = 69;
0450:
0451:            /**
0452:             * attribute: attribute value not lower case.
0453:             */
0454:            public static final short ATTR_VALUE_NOT_LCASE = 70;
0455:
0456:            /**
0457:             * attribute: id sintax.
0458:             */
0459:            public static final short XML_ID_SYNTAX = 71;
0460:
0461:            /**
0462:             * attribute: invalid attribute.
0463:             */
0464:            public static final short INVALID_ATTRIBUTE = 72;
0465:
0466:            /**
0467:             * attribute: bad attribute value replaced.
0468:             */
0469:            public static final short BAD_ATTRIBUTE_VALUE_REPLACED = 73;
0470:
0471:            /**
0472:             * attribute: invalid xml id.
0473:             */
0474:            public static final short INVALID_XML_ID = 74;
0475:
0476:            /**
0477:             * attribute: unexpected end of file.
0478:             */
0479:            public static final short UNEXPECTED_END_OF_FILE_ATTR = 75;
0480:
0481:            /**
0482:             * character encoding: vendor specific chars.
0483:             */
0484:            public static final short VENDOR_SPECIFIC_CHARS = 76;
0485:
0486:            /**
0487:             * character encoding: invalid sgml chars.
0488:             */
0489:            public static final short INVALID_SGML_CHARS = 77;
0490:
0491:            /**
0492:             * character encoding: invalid utf8.
0493:             */
0494:            public static final short INVALID_UTF8 = 78;
0495:
0496:            /**
0497:             * character encoding: invalid utf16.
0498:             */
0499:            public static final short INVALID_UTF16 = 79;
0500:
0501:            /**
0502:             * character encoding: encoding mismatch.
0503:             */
0504:            public static final short ENCODING_MISMATCH = 80;
0505:
0506:            /**
0507:             * character encoding: nvalid URI.
0508:             */
0509:            public static final short INVALID_URI = 81;
0510:
0511:            /**
0512:             * character encoding: invalid NCR.
0513:             */
0514:            public static final short INVALID_NCR = 82;
0515:
0516:            /**
0517:             * Constant used for reporting of given doctype.
0518:             */
0519:            public static final short DOCTYPE_GIVEN_SUMMARY = 110;
0520:
0521:            /**
0522:             * Constant used for reporting of version summary.
0523:             */
0524:            public static final short REPORT_VERSION_SUMMARY = 111;
0525:
0526:            /**
0527:             * Constant used for reporting of bad access summary.
0528:             */
0529:            public static final short BADACCESS_SUMMARY = 112;
0530:
0531:            /**
0532:             * Constant used for reporting of bad form summary.
0533:             */
0534:            public static final short BADFORM_SUMMARY = 113;
0535:
0536:            /**
0537:             * accessibility flaw: missing image map.
0538:             */
0539:            public static final short MISSING_IMAGE_ALT = 1;
0540:
0541:            /**
0542:             * accessibility flaw: missing link alt.
0543:             */
0544:            public static final short MISSING_LINK_ALT = 2;
0545:
0546:            /**
0547:             * accessibility flaw: missing summary.
0548:             */
0549:            public static final short MISSING_SUMMARY = 4;
0550:
0551:            /**
0552:             * accessibility flaw: missing image map.
0553:             */
0554:            public static final short MISSING_IMAGE_MAP = 8;
0555:
0556:            /**
0557:             * accessibility flaw: using frames.
0558:             */
0559:            public static final short USING_FRAMES = 16;
0560:
0561:            /**
0562:             * accessibility flaw: using noframes.
0563:             */
0564:            public static final short USING_NOFRAMES = 32;
0565:
0566:            /**
0567:             * presentation flaw: using spacer.
0568:             */
0569:            public static final short USING_SPACER = 1;
0570:
0571:            /**
0572:             * presentation flaw: using layer.
0573:             */
0574:            public static final short USING_LAYER = 2;
0575:
0576:            /**
0577:             * presentation flaw: using nobr.
0578:             */
0579:            public static final short USING_NOBR = 4;
0580:
0581:            /**
0582:             * presentation flaw: using font.
0583:             */
0584:            public static final short USING_FONT = 8;
0585:
0586:            /**
0587:             * presentation flaw: using body.
0588:             */
0589:            public static final short USING_BODY = 16;
0590:
0591:            /**
0592:             * character encoding error: windows chars.
0593:             */
0594:            public static final short WINDOWS_CHARS = 1;
0595:
0596:            /**
0597:             * character encoding error: non ascii.
0598:             */
0599:            public static final short NON_ASCII = 2;
0600:
0601:            /**
0602:             * character encoding error: found utf16.
0603:             */
0604:            public static final short FOUND_UTF16 = 4;
0605:
0606:            /**
0607:             * char has been replaced.
0608:             */
0609:            public static final short REPLACED_CHAR = 0;
0610:
0611:            /**
0612:             * char has been discarder.
0613:             */
0614:            public static final short DISCARDED_CHAR = 1;
0615:
0616:            /**
0617:             * Resource bundle with messages.
0618:             */
0619:            private static ResourceBundle res;
0620:
0621:            /**
0622:             * Printed in GNU Emacs messages.
0623:             */
0624:            private String currentFile;
0625:
0626:            /**
0627:             * message listener for error reporting.
0628:             */
0629:            private TidyMessageListener listener;
0630:
0631:            static {
0632:                try {
0633:                    res = ResourceBundle.getBundle("org/w3c/tidy/TidyMessages");
0634:                } catch (MissingResourceException e) {
0635:                    throw new Error(e.toString());
0636:                }
0637:            }
0638:
0639:            /**
0640:             * Instantiated only in Tidy() constructor.
0641:             */
0642:            protected Report() {
0643:                super ();
0644:            }
0645:
0646:            /**
0647:             * Generates a complete message for the warning/error. The message is composed by:
0648:             * <ul>
0649:             * <li>position in file</li>
0650:             * <li>prefix for the error level (warning: | error:)</li>
0651:             * <li>message read from ResourceBundle</li>
0652:             * <li>optional parameters added to message using MessageFormat</li>
0653:             * </ul>
0654:             * @param errorCode tidy error code
0655:             * @param lexer Lexer
0656:             * @param message key for the ResourceBundle
0657:             * @param params optional parameters added with MessageFormat
0658:             * @param level message level. One of <code>TidyMessage.LEVEL_ERROR</code>,
0659:             * <code>TidyMessage.LEVEL_WARNING</code>,<code>TidyMessage.LEVEL_INFO</code>
0660:             * @return formatted message
0661:             * @throws MissingResourceException if <code>message</code> key is not available in jtidy resource bundle.
0662:             * @see TidyMessage
0663:             */
0664:            protected String getMessage(int errorCode, Lexer lexer,
0665:                    String message, Object[] params, Level level)
0666:                    throws MissingResourceException {
0667:                String resource;
0668:                resource = res.getString(message);
0669:
0670:                String position;
0671:
0672:                if (lexer != null && level != Level.SUMMARY) {
0673:                    position = getPosition(lexer);
0674:                } else {
0675:                    position = "";
0676:                }
0677:
0678:                String prefix;
0679:
0680:                if (level == Level.ERROR) {
0681:                    prefix = res.getString("error");
0682:                } else if (level == Level.WARNING) {
0683:                    prefix = res.getString("warning");
0684:                } else {
0685:                    prefix = "";
0686:                }
0687:
0688:                String messageString;
0689:
0690:                if (params != null) {
0691:                    messageString = MessageFormat.format(resource, params);
0692:                } else {
0693:                    messageString = resource;
0694:                }
0695:
0696:                if (listener != null) {
0697:                    TidyMessage msg = new TidyMessage(errorCode,
0698:                            (lexer != null) ? lexer.lines : 0,
0699:                            (lexer != null) ? lexer.columns : 0, level,
0700:                            messageString);
0701:                    listener.messageReceived(msg);
0702:                }
0703:
0704:                return position + prefix + messageString;
0705:            }
0706:
0707:            /**
0708:             * Prints a message to lexer.errout after calling getMessage().
0709:             * @param errorCode tidy error code
0710:             * @param lexer Lexer
0711:             * @param message key for the ResourceBundle
0712:             * @param params optional parameters added with MessageFormat
0713:             * @param level message level. One of <code>TidyMessage.LEVEL_ERROR</code>,
0714:             * <code>TidyMessage.LEVEL_WARNING</code>,<code>TidyMessage.LEVEL_INFO</code>
0715:             * @see TidyMessage
0716:             */
0717:            private void printMessage(int errorCode, Lexer lexer,
0718:                    String message, Object[] params, Level level) {
0719:                String resource;
0720:                try {
0721:                    resource = getMessage(errorCode, lexer, message, params,
0722:                            level);
0723:                } catch (MissingResourceException e) {
0724:                    lexer.errout.println(e.toString());
0725:                    return;
0726:                }
0727:
0728:                lexer.errout.println(resource);
0729:            }
0730:
0731:            /**
0732:             * Prints a message to errout after calling getMessage(). Used when lexer is not yet defined.
0733:             * @param errout PrintWriter
0734:             * @param message key for the ResourceBundle
0735:             * @param params optional parameters added with MessageFormat
0736:             * @param level message level. One of <code>TidyMessage.LEVEL_ERROR</code>,
0737:             * <code>TidyMessage.LEVEL_WARNING</code>,<code>TidyMessage.LEVEL_INFO</code>
0738:             * @see TidyMessage
0739:             */
0740:            private void printMessage(PrintWriter errout, String message,
0741:                    Object[] params, Level level) {
0742:                String resource;
0743:                try {
0744:                    resource = getMessage(-1, null, message, params, level);
0745:                } catch (MissingResourceException e) {
0746:                    errout.println(e.toString());
0747:                    return;
0748:                }
0749:                errout.println(resource);
0750:            }
0751:
0752:            /**
0753:             * print version information.
0754:             * @param p printWriter
0755:             */
0756:            public void showVersion(PrintWriter p) {
0757:                printMessage(p, "version_summary",
0758:                        new Object[] { RELEASE_DATE }, Level.SUMMARY);
0759:            }
0760:
0761:            /**
0762:             * Returns a formatted tag name handling start and ent tags, nulls, doctypes, and text.
0763:             * @param tag Node
0764:             * @return formatted tag name
0765:             */
0766:            private String getTagName(Node tag) {
0767:                if (tag != null) {
0768:                    if (tag.type == Node.START_TAG) {
0769:                        return "<" + tag.element + ">";
0770:                    } else if (tag.type == Node.END_TAG) {
0771:                        return "</" + tag.element + ">";
0772:                    } else if (tag.type == Node.DOCTYPE_TAG) {
0773:                        return "<!DOCTYPE>";
0774:                    } else if (tag.type == Node.TEXT_NODE) {
0775:                        return "plain text";
0776:                    } else {
0777:                        return tag.element;
0778:                    }
0779:                }
0780:                return "";
0781:            }
0782:
0783:            /**
0784:             * Prints an "unknown option" error message. Lexer is not defined when this is called.
0785:             * @param option unknown option name
0786:             */
0787:            public void unknownOption(String option) {
0788:                try {
0789:                    System.err.println(MessageFormat.format(res
0790:                            .getString("unknown_option"),
0791:                            new Object[] { option }));
0792:                } catch (MissingResourceException e) {
0793:                    System.err.println(e.toString());
0794:                }
0795:            }
0796:
0797:            /**
0798:             * Prints a "bad argument" error message. Lexer is not defined when this is called.
0799:             * @param key argument name
0800:             * @param value bad argument value
0801:             */
0802:            public void badArgument(String key, String value) {
0803:                try {
0804:                    System.err.println(MessageFormat.format(res
0805:                            .getString("bad_argument"), new Object[] { value,
0806:                            key }));
0807:                } catch (MissingResourceException e) {
0808:                    System.err.println(e.toString());
0809:                }
0810:            }
0811:
0812:            /**
0813:             * Returns a formatted String describing the current position in file.
0814:             * @param lexer Lexer
0815:             * @return String position ("line:column")
0816:             */
0817:            private String getPosition(Lexer lexer) {
0818:                try {
0819:                    // Change formatting to be parsable by GNU Emacs
0820:                    if (lexer.configuration.emacs) {
0821:                        return MessageFormat.format(res
0822:                                .getString("emacs_format"), new Object[] {
0823:                                this .currentFile, new Integer(lexer.lines),
0824:                                new Integer(lexer.columns) })
0825:                                + " ";
0826:                    }
0827:                    // traditional format
0828:                    return MessageFormat.format(res.getString("line_column"),
0829:                            new Object[] { new Integer(lexer.lines),
0830:                                    new Integer(lexer.columns) });
0831:
0832:                } catch (MissingResourceException e) {
0833:                    lexer.errout.println(e.toString());
0834:                }
0835:                return "";
0836:            }
0837:
0838:            /**
0839:             * Prints encoding error messages.
0840:             * @param lexer Lexer
0841:             * @param code error code
0842:             * @param c invalid char
0843:             */
0844:            public void encodingError(Lexer lexer, int code, int c) {
0845:                lexer.warnings++;
0846:
0847:                if (lexer.errors > lexer.configuration.showErrors) // keep quiet after <showErrors> errors
0848:                {
0849:                    return;
0850:                }
0851:
0852:                if (lexer.configuration.showWarnings) {
0853:                    String buf = Integer.toHexString(c);
0854:
0855:                    // An encoding mismatch is currently treated as a non-fatal error
0856:                    if ((code & ~DISCARDED_CHAR) == ENCODING_MISMATCH) {
0857:                        // actual encoding passed in "c"
0858:                        lexer.badChars |= ENCODING_MISMATCH;
0859:                        printMessage(code, lexer, "encoding_mismatch",
0860:                                new Object[] {
0861:                                        lexer.configuration
0862:                                                .getInCharEncodingName(),
0863:                                        ParsePropertyImpl.CHAR_ENCODING
0864:                                                .getFriendlyName(null,
0865:                                                        new Integer(c),
0866:                                                        lexer.configuration) },
0867:                                Level.WARNING);
0868:                    } else if ((code & ~DISCARDED_CHAR) == VENDOR_SPECIFIC_CHARS) {
0869:                        lexer.badChars |= VENDOR_SPECIFIC_CHARS;
0870:                        printMessage(code, lexer, "invalid_char", new Object[] {
0871:                                new Integer(code & DISCARDED_CHAR), buf },
0872:                                Level.WARNING);
0873:                    } else if ((code & ~DISCARDED_CHAR) == INVALID_SGML_CHARS) {
0874:                        lexer.badChars |= INVALID_SGML_CHARS;
0875:                        printMessage(code, lexer, "invalid_char", new Object[] {
0876:                                new Integer(code & DISCARDED_CHAR), buf },
0877:                                Level.WARNING);
0878:                    } else if ((code & ~DISCARDED_CHAR) == INVALID_UTF8) {
0879:                        lexer.badChars |= INVALID_UTF8;
0880:                        printMessage(code, lexer, "invalid_utf8", new Object[] {
0881:                                new Integer(code & DISCARDED_CHAR), buf },
0882:                                Level.WARNING);
0883:                    }
0884:
0885:                    else if ((code & ~DISCARDED_CHAR) == INVALID_UTF16) {
0886:                        lexer.badChars |= INVALID_UTF16;
0887:                        printMessage(
0888:                                code,
0889:                                lexer,
0890:                                "invalid_utf16",
0891:                                new Object[] {
0892:                                        new Integer(code & DISCARDED_CHAR), buf },
0893:                                Level.WARNING);
0894:
0895:                    }
0896:
0897:                    else if ((code & ~DISCARDED_CHAR) == INVALID_NCR) {
0898:                        lexer.badChars |= INVALID_NCR;
0899:                        printMessage(code, lexer, "invalid_ncr", new Object[] {
0900:                                new Integer(code & DISCARDED_CHAR), buf },
0901:                                Level.WARNING);
0902:                    }
0903:
0904:                }
0905:            }
0906:
0907:            /**
0908:             * Prints entity error messages.
0909:             * @param lexer Lexer
0910:             * @param code error code
0911:             * @param entity invalid entity String
0912:             * @param c invalid char
0913:             */
0914:            public void entityError(Lexer lexer, short code, String entity,
0915:                    int c) {
0916:                lexer.warnings++;
0917:
0918:                if (lexer.errors > lexer.configuration.showErrors) // keep quiet after <showErrors> errors
0919:                {
0920:                    return;
0921:                }
0922:
0923:                if (lexer.configuration.showWarnings) {
0924:                    switch (code) {
0925:                    case MISSING_SEMICOLON:
0926:                        printMessage(code, lexer, "missing_semicolon",
0927:                                new Object[] { entity }, Level.WARNING);
0928:                        break;
0929:                    case MISSING_SEMICOLON_NCR:
0930:                        printMessage(code, lexer, "missing_semicolon_ncr",
0931:                                new Object[] { entity }, Level.WARNING);
0932:                        break;
0933:                    case UNKNOWN_ENTITY:
0934:                        printMessage(code, lexer, "unknown_entity",
0935:                                new Object[] { entity }, Level.WARNING);
0936:                        break;
0937:                    case UNESCAPED_AMPERSAND:
0938:                        printMessage(code, lexer, "unescaped_ampersand", null,
0939:                                Level.WARNING);
0940:                        break;
0941:                    case APOS_UNDEFINED:
0942:                        printMessage(code, lexer, "apos_undefined", null,
0943:                                Level.WARNING);
0944:                        break;
0945:                    default:
0946:                        // should not reach here
0947:                        break;
0948:                    }
0949:                }
0950:            }
0951:
0952:            /**
0953:             * Prints error messages for attributes.
0954:             * @param lexer Lexer
0955:             * @param node current tag
0956:             * @param attribute attribute
0957:             * @param code error code
0958:             */
0959:            public void attrError(Lexer lexer, Node node, AttVal attribute,
0960:                    short code) {
0961:                if (code == UNEXPECTED_GT) {
0962:                    lexer.errors++;
0963:                } else {
0964:                    lexer.warnings++;
0965:                }
0966:
0967:                if (lexer.errors > lexer.configuration.showErrors) // keep quiet after <showErrors> errors
0968:                {
0969:                    return;
0970:                }
0971:
0972:                if (code == UNEXPECTED_GT) // error
0973:                {
0974:                    printMessage(code, lexer, "unexpected_gt",
0975:                            new Object[] { getTagName(node) }, Level.ERROR);
0976:                }
0977:
0978:                if (!lexer.configuration.showWarnings) // warnings
0979:                {
0980:                    return;
0981:                }
0982:
0983:                switch (code) {
0984:                case UNKNOWN_ATTRIBUTE:
0985:                    printMessage(code, lexer, "unknown_attribute",
0986:                            new Object[] { attribute.attribute }, Level.WARNING);
0987:                    break;
0988:
0989:                case MISSING_ATTRIBUTE:
0990:                    printMessage(code, lexer, "missing_attribute",
0991:                            new Object[] { getTagName(node),
0992:                                    attribute.attribute }, Level.WARNING);
0993:                    break;
0994:
0995:                case MISSING_ATTR_VALUE:
0996:                    printMessage(code, lexer, "missing_attr_value",
0997:                            new Object[] { getTagName(node),
0998:                                    attribute.attribute }, Level.WARNING);
0999:                    break;
1000:
1001:                case MISSING_IMAGEMAP:
1002:                    printMessage(code, lexer, "missing_imagemap",
1003:                            new Object[] { getTagName(node) }, Level.WARNING);
1004:                    lexer.badAccess |= MISSING_IMAGE_MAP;
1005:                    break;
1006:
1007:                case BAD_ATTRIBUTE_VALUE:
1008:                    printMessage(code, lexer, "bad_attribute_value",
1009:                            new Object[] { getTagName(node),
1010:                                    attribute.attribute, attribute.value },
1011:                            Level.WARNING);
1012:                    break;
1013:
1014:                case XML_ID_SYNTAX:
1015:                    printMessage(code, lexer, "xml_id_sintax", new Object[] {
1016:                            getTagName(node), attribute.attribute },
1017:                            Level.WARNING);
1018:                    break;
1019:
1020:                case XML_ATTRIBUTE_VALUE:
1021:                    printMessage(code, lexer, "xml_attribute_value",
1022:                            new Object[] { getTagName(node),
1023:                                    attribute.attribute }, Level.WARNING);
1024:                    break;
1025:
1026:                case UNEXPECTED_QUOTEMARK:
1027:                    printMessage(code, lexer, "unexpected_quotemark",
1028:                            new Object[] { getTagName(node) }, Level.WARNING);
1029:                    break;
1030:
1031:                case MISSING_QUOTEMARK:
1032:                    printMessage(code, lexer, "missing_quotemark",
1033:                            new Object[] { getTagName(node) }, Level.WARNING);
1034:                    break;
1035:
1036:                case REPEATED_ATTRIBUTE:
1037:                    printMessage(code, lexer, "repeated_attribute",
1038:                            new Object[] { getTagName(node), attribute.value,
1039:                                    attribute.attribute }, Level.WARNING);
1040:                    break;
1041:
1042:                case PROPRIETARY_ATTR_VALUE:
1043:                    printMessage(code, lexer, "proprietary_attr_value",
1044:                            new Object[] { getTagName(node), attribute.value },
1045:                            Level.WARNING);
1046:                    break;
1047:
1048:                case PROPRIETARY_ATTRIBUTE:
1049:                    printMessage(code, lexer, "proprietary_attribute",
1050:                            new Object[] { getTagName(node),
1051:                                    attribute.attribute }, Level.WARNING);
1052:                    break;
1053:
1054:                case UNEXPECTED_END_OF_FILE:
1055:                    // on end of file adjust reported position to end of input
1056:                    lexer.lines = lexer.in.getCurline();
1057:                    lexer.columns = lexer.in.getCurcol();
1058:                    printMessage(code, lexer, "unexpected_end_of_file",
1059:                            new Object[] { getTagName(node) }, Level.WARNING);
1060:                    break;
1061:
1062:                case ID_NAME_MISMATCH:
1063:                    printMessage(code, lexer, "id_name_mismatch",
1064:                            new Object[] { getTagName(node) }, Level.WARNING);
1065:                    break;
1066:
1067:                case BACKSLASH_IN_URI:
1068:                    printMessage(code, lexer, "backslash_in_uri",
1069:                            new Object[] { getTagName(node) }, Level.WARNING);
1070:                    break;
1071:
1072:                case FIXED_BACKSLASH:
1073:                    printMessage(code, lexer, "fixed_backslash",
1074:                            new Object[] { getTagName(node) }, Level.WARNING);
1075:                    break;
1076:
1077:                case ILLEGAL_URI_REFERENCE:
1078:                    printMessage(code, lexer, "illegal_uri_reference",
1079:                            new Object[] { getTagName(node) }, Level.WARNING);
1080:                    break;
1081:
1082:                case ESCAPED_ILLEGAL_URI:
1083:                    printMessage(code, lexer, "escaped_illegal_uri",
1084:                            new Object[] { getTagName(node) }, Level.WARNING);
1085:                    break;
1086:
1087:                case NEWLINE_IN_URI:
1088:                    printMessage(code, lexer, "newline_in_uri",
1089:                            new Object[] { getTagName(node) }, Level.WARNING);
1090:                    break;
1091:
1092:                case ANCHOR_NOT_UNIQUE:
1093:                    printMessage(code, lexer, "anchor_not_unique",
1094:                            new Object[] { getTagName(node), attribute.value },
1095:                            Level.WARNING);
1096:                    break;
1097:
1098:                case ENTITY_IN_ID:
1099:                    printMessage(code, lexer, "entity_in_id", null,
1100:                            Level.WARNING);
1101:                    break;
1102:
1103:                case JOINING_ATTRIBUTE:
1104:                    printMessage(code, lexer, "joining_attribute",
1105:                            new Object[] { getTagName(node),
1106:                                    attribute.attribute }, Level.WARNING);
1107:                    break;
1108:
1109:                case UNEXPECTED_EQUALSIGN:
1110:                    printMessage(code, lexer, "expected_equalsign",
1111:                            new Object[] { getTagName(node) }, Level.WARNING);
1112:                    break;
1113:
1114:                case ATTR_VALUE_NOT_LCASE:
1115:                    printMessage(code, lexer, "attr_value_not_lcase",
1116:                            new Object[] { getTagName(node), attribute.value,
1117:                                    attribute.attribute }, Level.WARNING);
1118:                    break;
1119:
1120:                default:
1121:                    break;
1122:                }
1123:            }
1124:
1125:            /**
1126:             * Prints warnings.
1127:             * @param lexer Lexer
1128:             * @param element parent/missing tag
1129:             * @param node current tag
1130:             * @param code error code
1131:             */
1132:            public void warning(Lexer lexer, Node element, Node node, short code) {
1133:
1134:                TagTable tt = lexer.configuration.tt;
1135:                if (!((code == DISCARDING_UNEXPECTED) && lexer.badForm != 0)) // lexer->errors++; already done in BadForm()
1136:                {
1137:                    lexer.warnings++;
1138:                }
1139:
1140:                // keep quiet after <showErrors> errors
1141:                if (lexer.errors > lexer.configuration.showErrors) {
1142:                    return;
1143:                }
1144:
1145:                if (lexer.configuration.showWarnings) {
1146:                    switch (code) {
1147:                    case MISSING_ENDTAG_FOR:
1148:                        printMessage(code, lexer, "missing_endtag_for",
1149:                                new Object[] { element.element }, Level.WARNING);
1150:                        break;
1151:
1152:                    case MISSING_ENDTAG_BEFORE:
1153:                        printMessage(code, lexer, "missing_endtag_before",
1154:                                new Object[] { element.element,
1155:                                        getTagName(node) }, Level.WARNING);
1156:                        break;
1157:
1158:                    case DISCARDING_UNEXPECTED:
1159:                        if (lexer.badForm == 0) {
1160:                            // the case for when this is an error not a warning, is handled later
1161:                            printMessage(code, lexer, "discarding_unexpected",
1162:                                    new Object[] { getTagName(node) },
1163:                                    Level.WARNING);
1164:                        }
1165:                        break;
1166:
1167:                    case NESTED_EMPHASIS:
1168:                        printMessage(code, lexer, "nested_emphasis",
1169:                                new Object[] { getTagName(node) }, Level.INFO);
1170:                        break;
1171:
1172:                    case COERCE_TO_ENDTAG:
1173:                        printMessage(code, lexer, "coerce_to_endtag",
1174:                                new Object[] { element.element }, Level.INFO);
1175:                        break;
1176:
1177:                    case NON_MATCHING_ENDTAG:
1178:                        printMessage(code, lexer, "non_matching_endtag",
1179:                                new Object[] { getTagName(node),
1180:                                        element.element }, Level.WARNING);
1181:                        break;
1182:
1183:                    case TAG_NOT_ALLOWED_IN:
1184:                        printMessage(code, lexer, "tag_not_allowed_in",
1185:                                new Object[] { getTagName(node),
1186:                                        element.element }, Level.WARNING);
1187:                        break;
1188:
1189:                    case DOCTYPE_AFTER_TAGS:
1190:                        printMessage(code, lexer, "doctype_after_tags", null,
1191:                                Level.WARNING);
1192:                        break;
1193:
1194:                    case MISSING_STARTTAG:
1195:                        printMessage(code, lexer, "missing_starttag",
1196:                                new Object[] { node.element }, Level.WARNING);
1197:                        break;
1198:
1199:                    case UNEXPECTED_ENDTAG:
1200:                        if (element != null) {
1201:                            printMessage(code, lexer, "unexpected_endtag_in",
1202:                                    new Object[] { node.element,
1203:                                            element.element }, Level.WARNING);
1204:                        } else {
1205:                            printMessage(code, lexer, "unexpected_endtag",
1206:                                    new Object[] { node.element },
1207:                                    Level.WARNING);
1208:                        }
1209:                        break;
1210:
1211:                    case TOO_MANY_ELEMENTS:
1212:                        if (element != null) {
1213:                            printMessage(code, lexer, "too_many_elements_in",
1214:                                    new Object[] { node.element,
1215:                                            element.element }, Level.WARNING);
1216:                        } else {
1217:                            printMessage(code, lexer, "too_many_elements",
1218:                                    new Object[] { node.element },
1219:                                    Level.WARNING);
1220:                        }
1221:                        break;
1222:
1223:                    case USING_BR_INPLACE_OF:
1224:                        printMessage(code, lexer, "using_br_inplace_of",
1225:                                new Object[] { getTagName(node) },
1226:                                Level.WARNING);
1227:                        break;
1228:
1229:                    case INSERTING_TAG:
1230:                        printMessage(code, lexer, "inserting_tag",
1231:                                new Object[] { node.element }, Level.WARNING);
1232:                        break;
1233:
1234:                    case CANT_BE_NESTED:
1235:                        printMessage(code, lexer, "cant_be_nested",
1236:                                new Object[] { getTagName(node) },
1237:                                Level.WARNING);
1238:                        break;
1239:
1240:                    case PROPRIETARY_ELEMENT:
1241:                        printMessage(code, lexer, "proprietary_element",
1242:                                new Object[] { getTagName(node) },
1243:                                Level.WARNING);
1244:
1245:                        if (node.tag == tt.tagLayer) {
1246:                            lexer.badLayout |= USING_LAYER;
1247:                        } else if (node.tag == tt.tagSpacer) {
1248:                            lexer.badLayout |= USING_SPACER;
1249:                        } else if (node.tag == tt.tagNobr) {
1250:                            lexer.badLayout |= USING_NOBR;
1251:                        }
1252:                        break;
1253:
1254:                    case OBSOLETE_ELEMENT:
1255:                        if (element.tag != null
1256:                                && (element.tag.model & Dict.CM_OBSOLETE) != 0) {
1257:                            printMessage(code, lexer, "obsolete_element",
1258:                                    new Object[] { getTagName(element),
1259:                                            getTagName(node) }, Level.WARNING);
1260:                        } else {
1261:                            printMessage(code, lexer, "replacing_element",
1262:                                    new Object[] { getTagName(element),
1263:                                            getTagName(node) }, Level.WARNING);
1264:                        }
1265:                        break;
1266:
1267:                    case UNESCAPED_ELEMENT:
1268:                        printMessage(code, lexer, "unescaped_element",
1269:                                new Object[] { getTagName(element) },
1270:                                Level.WARNING);
1271:                        break;
1272:
1273:                    case TRIM_EMPTY_ELEMENT:
1274:                        printMessage(code, lexer, "trim_empty_element",
1275:                                new Object[] { getTagName(element) },
1276:                                Level.WARNING);
1277:                        break;
1278:
1279:                    case MISSING_TITLE_ELEMENT:
1280:                        printMessage(code, lexer, "missing_title_element",
1281:                                null, Level.WARNING);
1282:                        break;
1283:
1284:                    case ILLEGAL_NESTING:
1285:                        printMessage(code, lexer, "illegal_nesting",
1286:                                new Object[] { getTagName(element) },
1287:                                Level.WARNING);
1288:                        break;
1289:
1290:                    case NOFRAMES_CONTENT:
1291:                        printMessage(code, lexer, "noframes_content",
1292:                                new Object[] { getTagName(node) },
1293:                                Level.WARNING);
1294:                        break;
1295:
1296:                    case INCONSISTENT_VERSION:
1297:                        printMessage(code, lexer, "inconsistent_version", null,
1298:                                Level.WARNING);
1299:                        break;
1300:
1301:                    case MALFORMED_DOCTYPE:
1302:                        printMessage(code, lexer, "malformed_doctype", null,
1303:                                Level.WARNING);
1304:                        break;
1305:
1306:                    case CONTENT_AFTER_BODY:
1307:                        printMessage(code, lexer, "content_after_body", null,
1308:                                Level.WARNING);
1309:                        break;
1310:
1311:                    case MALFORMED_COMMENT:
1312:                        printMessage(code, lexer, "malformed_comment", null,
1313:                                Level.WARNING);
1314:                        break;
1315:
1316:                    case BAD_COMMENT_CHARS:
1317:                        printMessage(code, lexer, "bad_comment_chars", null,
1318:                                Level.WARNING);
1319:                        break;
1320:
1321:                    case BAD_XML_COMMENT:
1322:                        printMessage(code, lexer, "bad_xml_comment", null,
1323:                                Level.WARNING);
1324:                        break;
1325:
1326:                    case BAD_CDATA_CONTENT:
1327:                        printMessage(code, lexer, "bad_cdata_content", null,
1328:                                Level.WARNING);
1329:                        break;
1330:
1331:                    case INCONSISTENT_NAMESPACE:
1332:                        printMessage(code, lexer, "inconsistent_namespace",
1333:                                null, Level.WARNING);
1334:                        break;
1335:
1336:                    case DTYPE_NOT_UPPER_CASE:
1337:                        printMessage(code, lexer, "dtype_not_upper_case", null,
1338:                                Level.WARNING);
1339:                        break;
1340:
1341:                    case UNEXPECTED_END_OF_FILE:
1342:                        // on end of file adjust reported position to end of input
1343:                        lexer.lines = lexer.in.getCurline();
1344:                        lexer.columns = lexer.in.getCurcol();
1345:                        printMessage(code, lexer, "unexpected_end_of_file",
1346:                                new Object[] { getTagName(element) },
1347:                                Level.WARNING);
1348:                        break;
1349:
1350:                    case NESTED_QUOTATION:
1351:                        printMessage(code, lexer, "nested_quotation", null,
1352:                                Level.WARNING);
1353:                        break;
1354:
1355:                    case ELEMENT_NOT_EMPTY:
1356:                        printMessage(code, lexer, "element_not_empty",
1357:                                new Object[] { getTagName(element) },
1358:                                Level.WARNING);
1359:                        break;
1360:
1361:                    case MISSING_DOCTYPE:
1362:                        printMessage(code, lexer, "missing_doctype", null,
1363:                                Level.WARNING);
1364:                        break;
1365:
1366:                    default:
1367:                        break;
1368:                    }
1369:                }
1370:
1371:                if ((code == DISCARDING_UNEXPECTED) && lexer.badForm != 0) {
1372:                    // the case for when this is a warning not an error, is handled earlier
1373:                    printMessage(code, lexer, "discarding_unexpected",
1374:                            new Object[] { getTagName(node) }, Level.ERROR);
1375:                }
1376:
1377:            }
1378:
1379:            /**
1380:             * Prints errors.
1381:             * @param lexer Lexer
1382:             * @param element parent/missing tag
1383:             * @param node current tag
1384:             * @param code error code
1385:             */
1386:            public void error(Lexer lexer, Node element, Node node, short code) {
1387:                lexer.errors++;
1388:
1389:                // keep quiet after <showErrors> errors
1390:                if (lexer.errors > lexer.configuration.showErrors) {
1391:                    return;
1392:                }
1393:
1394:                if (code == SUSPECTED_MISSING_QUOTE) {
1395:                    printMessage(code, lexer, "suspected_missing_quote", null,
1396:                            Level.ERROR);
1397:                } else if (code == DUPLICATE_FRAMESET) {
1398:                    printMessage(code, lexer, "duplicate_frameset", null,
1399:                            Level.ERROR);
1400:                } else if (code == UNKNOWN_ELEMENT) {
1401:                    printMessage(code, lexer, "unknown_element",
1402:                            new Object[] { getTagName(node) }, Level.ERROR);
1403:                } else if (code == UNEXPECTED_ENDTAG) {
1404:                    if (element != null) {
1405:                        printMessage(code, lexer, "unexpected_endtag_in",
1406:                                new Object[] { node.element, element.element },
1407:                                Level.ERROR);
1408:                    } else {
1409:                        printMessage(code, lexer, "unexpected_endtag",
1410:                                new Object[] { node.element }, Level.ERROR);
1411:                    }
1412:                }
1413:            }
1414:
1415:            /**
1416:             * Prints error summary.
1417:             * @param lexer Lexer
1418:             */
1419:            public void errorSummary(Lexer lexer) {
1420:                // adjust badAccess to that its null if frames are ok
1421:                if ((lexer.badAccess & (USING_FRAMES | USING_NOFRAMES)) != 0) {
1422:                    if (!(((lexer.badAccess & USING_FRAMES) != 0) && ((lexer.badAccess & USING_NOFRAMES) == 0))) {
1423:                        lexer.badAccess &= ~(USING_FRAMES | USING_NOFRAMES);
1424:                    }
1425:                }
1426:                if (lexer.badChars != 0) {
1427:                    if ((lexer.badChars & VENDOR_SPECIFIC_CHARS) != 0) {
1428:                        int encodingChoiche = 0;
1429:
1430:                        if ("Cp1252".equals(lexer.configuration
1431:                                .getInCharEncodingName())) {
1432:                            encodingChoiche = 1;
1433:                        } else if ("MacRoman".equals(lexer.configuration
1434:                                .getInCharEncodingName())) {
1435:                            encodingChoiche = 2;
1436:                        }
1437:
1438:                        printMessage(VENDOR_SPECIFIC_CHARS, lexer,
1439:                                "vendor_specific_chars_summary",
1440:                                new Object[] { new Integer(encodingChoiche) },
1441:                                Level.SUMMARY);
1442:                    }
1443:
1444:                    if ((lexer.badChars & INVALID_SGML_CHARS) != 0
1445:                            || (lexer.badChars & INVALID_NCR) != 0) {
1446:                        int encodingChoiche = 0;
1447:
1448:                        if ("Cp1252".equals(lexer.configuration
1449:                                .getInCharEncodingName())) {
1450:                            encodingChoiche = 1;
1451:                        } else if ("MacRoman".equals(lexer.configuration
1452:                                .getInCharEncodingName())) {
1453:                            encodingChoiche = 2;
1454:                        }
1455:
1456:                        printMessage(INVALID_SGML_CHARS, lexer,
1457:                                "invalid_sgml_chars_summary",
1458:                                new Object[] { new Integer(encodingChoiche) },
1459:                                Level.SUMMARY);
1460:                    }
1461:
1462:                    if ((lexer.badChars & INVALID_UTF8) != 0) {
1463:                        printMessage(INVALID_UTF8, lexer,
1464:                                "invalid_utf8_summary", null, Level.SUMMARY);
1465:                    }
1466:
1467:                    if ((lexer.badChars & INVALID_UTF16) != 0) {
1468:                        printMessage(INVALID_UTF16, lexer,
1469:                                "invalid_utf16_summary", null, Level.SUMMARY);
1470:                    }
1471:
1472:                    if ((lexer.badChars & INVALID_URI) != 0) {
1473:                        printMessage(INVALID_URI, lexer, "invaliduri_summary",
1474:                                null, Level.SUMMARY);
1475:                    }
1476:                }
1477:
1478:                if (lexer.badForm != 0) {
1479:                    printMessage(BADFORM_SUMMARY, lexer, "badform_summary",
1480:                            null, Level.SUMMARY);
1481:                }
1482:
1483:                if (lexer.badAccess != 0) {
1484:                    if ((lexer.badAccess & MISSING_SUMMARY) != 0) {
1485:                        printMessage(MISSING_SUMMARY, lexer,
1486:                                "badaccess_missing_summary", null,
1487:                                Level.SUMMARY);
1488:                    }
1489:
1490:                    if ((lexer.badAccess & MISSING_IMAGE_ALT) != 0) {
1491:                        printMessage(MISSING_IMAGE_ALT, lexer,
1492:                                "badaccess_missing_image_alt", null,
1493:                                Level.SUMMARY);
1494:                    }
1495:
1496:                    if ((lexer.badAccess & MISSING_IMAGE_MAP) != 0) {
1497:                        printMessage(MISSING_IMAGE_MAP, lexer,
1498:                                "badaccess_missing_image_map", null,
1499:                                Level.SUMMARY);
1500:                    }
1501:
1502:                    if ((lexer.badAccess & MISSING_LINK_ALT) != 0) {
1503:                        printMessage(MISSING_LINK_ALT, lexer,
1504:                                "badaccess_missing_link_alt", null,
1505:                                Level.SUMMARY);
1506:                    }
1507:
1508:                    if (((lexer.badAccess & USING_FRAMES) != 0)
1509:                            && ((lexer.badAccess & USING_NOFRAMES) == 0)) {
1510:                        printMessage(USING_FRAMES, lexer, "badaccess_frames",
1511:                                null, Level.SUMMARY);
1512:                    }
1513:
1514:                    printMessage(BADACCESS_SUMMARY, lexer, "badaccess_summary",
1515:                            new Object[] { ACCESS_URL }, Level.SUMMARY);
1516:                }
1517:
1518:                if (lexer.badLayout != 0) {
1519:                    if ((lexer.badLayout & USING_LAYER) != 0) {
1520:                        printMessage(USING_LAYER, lexer,
1521:                                "badlayout_using_layer", null, Level.SUMMARY);
1522:                    }
1523:
1524:                    if ((lexer.badLayout & USING_SPACER) != 0) {
1525:                        printMessage(USING_SPACER, lexer,
1526:                                "badlayout_using_spacer", null, Level.SUMMARY);
1527:                    }
1528:
1529:                    if ((lexer.badLayout & USING_FONT) != 0) {
1530:                        printMessage(USING_FONT, lexer, "badlayout_using_font",
1531:                                null, Level.SUMMARY);
1532:                    }
1533:
1534:                    if ((lexer.badLayout & USING_NOBR) != 0) {
1535:                        printMessage(USING_NOBR, lexer, "badlayout_using_nobr",
1536:                                null, Level.SUMMARY);
1537:                    }
1538:
1539:                    if ((lexer.badLayout & USING_BODY) != 0) {
1540:                        printMessage(USING_BODY, lexer, "badlayout_using_body",
1541:                                null, Level.SUMMARY);
1542:                    }
1543:                }
1544:            }
1545:
1546:            /**
1547:             * Prints the "unknown option" message.
1548:             * @param errout PrintWriter
1549:             * @param c invalid option char
1550:             */
1551:            public void unknownOption(PrintWriter errout, char c) {
1552:                printMessage(errout, "unrecognized_option",
1553:                        new Object[] { new String(new char[] { c }) },
1554:                        Level.ERROR);
1555:            }
1556:
1557:            /**
1558:             * Prints the "unknown file" message.
1559:             * @param errout PrintWriter
1560:             * @param file invalid file name
1561:             */
1562:            public void unknownFile(PrintWriter errout, String file) {
1563:                printMessage(errout, "unknown_file", new Object[] { "Tidy",
1564:                        file }, Level.ERROR);
1565:            }
1566:
1567:            /**
1568:             * Prints the "needs author intervention" message.
1569:             * @param errout PrintWriter
1570:             */
1571:            public void needsAuthorIntervention(PrintWriter errout) {
1572:                printMessage(errout, "needs_author_intervention", null,
1573:                        Level.SUMMARY);
1574:            }
1575:
1576:            /**
1577:             * Prints the "missing body" message.
1578:             * @param errout PrintWriter
1579:             */
1580:            public void missingBody(PrintWriter errout) {
1581:                printMessage(errout, "missing_body", null, Level.ERROR);
1582:            }
1583:
1584:            /**
1585:             * Prints the number of generated slides.
1586:             * @param errout PrintWriter
1587:             * @param count slides count
1588:             */
1589:            public void reportNumberOfSlides(PrintWriter errout, int count) {
1590:                printMessage(errout, "slides_found",
1591:                        new Object[] { new Integer(count) }, Level.SUMMARY);
1592:            }
1593:
1594:            /**
1595:             * Prints tidy general info.
1596:             * @param errout PrintWriter
1597:             */
1598:            public void generalInfo(PrintWriter errout) {
1599:                printMessage(errout, "general_info", null, Level.SUMMARY);
1600:            }
1601:
1602:            /**
1603:             * Prints tidy hello message.
1604:             * @param errout PrintWriter
1605:             */
1606:            public void helloMessage(PrintWriter errout) {
1607:                printMessage(errout, "hello_message", new Object[] {
1608:                        Report.RELEASE_DATE, this .currentFile }, Level.SUMMARY);
1609:            }
1610:
1611:            /**
1612:             * Sets the current file name.
1613:             * @param filename current file.
1614:             */
1615:            public void setFilename(String filename) {
1616:                this .currentFile = filename; // for use with Gnu Emacs
1617:            }
1618:
1619:            /**
1620:             * Prints information for html version in input file.
1621:             * @param errout PrintWriter
1622:             * @param lexer Lexer
1623:             * @param filename file name
1624:             * @param doctype doctype Node
1625:             */
1626:            public void reportVersion(PrintWriter errout, Lexer lexer,
1627:                    String filename, Node doctype) {
1628:                int i, c;
1629:                int state = 0;
1630:                String vers = lexer.htmlVersionName();
1631:                int[] cc = new int[1];
1632:
1633:                // adjust reported position to first line
1634:                lexer.lines = 1;
1635:                lexer.columns = 1;
1636:
1637:                if (doctype != null) {
1638:
1639:                    StringBuffer doctypeBuffer = new StringBuffer();
1640:                    for (i = doctype.start; i < doctype.end; ++i) {
1641:                        c = doctype.textarray[i];
1642:
1643:                        // look for UTF-8 multibyte character
1644:                        if (c < 0) {
1645:                            i += PPrint.getUTF8(doctype.textarray, i, cc);
1646:                            c = cc[0];
1647:                        }
1648:
1649:                        if (c == '"') {
1650:                            ++state;
1651:                        } else if (state == 1) {
1652:                            doctypeBuffer.append((char) c);
1653:                        }
1654:                    }
1655:
1656:                    printMessage(DOCTYPE_GIVEN_SUMMARY, lexer, "doctype_given",
1657:                            new Object[] { filename, doctypeBuffer },
1658:                            Level.SUMMARY);
1659:                }
1660:
1661:                printMessage(REPORT_VERSION_SUMMARY, lexer, "report_version",
1662:                        new Object[] { filename,
1663:                                (vers != null ? vers : "HTML proprietary") },
1664:                        Level.SUMMARY);
1665:            }
1666:
1667:            /**
1668:             * Prints the number of error/warnings found.
1669:             * @param errout PrintWriter
1670:             * @param lexer Lexer
1671:             */
1672:            public void reportNumWarnings(PrintWriter errout, Lexer lexer) {
1673:                if (lexer.warnings > 0 || lexer.errors > 0) {
1674:                    printMessage(errout, "num_warnings", new Object[] {
1675:                            new Integer(lexer.warnings),
1676:                            new Integer(lexer.errors) }, Level.SUMMARY);
1677:                } else {
1678:                    printMessage(errout, "no_warnings", null, Level.SUMMARY);
1679:                }
1680:            }
1681:
1682:            /**
1683:             * Prints tidy help.
1684:             * @param out PrintWriter
1685:             */
1686:            public void helpText(PrintWriter out) {
1687:                printMessage(out, "help_text", new Object[] { "Tidy",
1688:                        RELEASE_DATE }, Level.SUMMARY);
1689:            }
1690:
1691:            /**
1692:             * Prints the "bad tree" message.
1693:             * @param errout PrintWriter
1694:             */
1695:            public void badTree(PrintWriter errout) {
1696:                printMessage(errout, "bad_tree", null, Level.ERROR);
1697:            }
1698:
1699:            /**
1700:             * Adds a message listener.
1701:             * @param listener TidyMessageListener
1702:             */
1703:            public void addMessageListener(TidyMessageListener listener) {
1704:                this.listener = listener;
1705:            }
1706:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.