KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > xml > xmlc > html > parsers > HTMLParserBase


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  * $Id: HTMLParserBase.java,v 1.2 2005/01/26 08:29:24 jkjome Exp $
22  */

23
24 package org.enhydra.xml.xmlc.html.parsers;
25
26 import org.enhydra.xml.io.ErrorReporter;
27 import org.enhydra.xml.xmlc.XMLCException;
28 import org.enhydra.xml.xmlc.dom.XMLCDocument;
29 import org.enhydra.xml.xmlc.metadata.MetaData;
30 import org.enhydra.xml.xmlc.metadata.Parser;
31 import org.enhydra.xml.xmlc.metadata.ParserType;
32 import org.enhydra.xml.xmlc.parsers.XMLCParser;
33
34 /**
35  * Abstract class used to constructor XMLCParser objects for HTML.
36  * Methods in this class are the only ones that do DOM implementation-
37  * specific operations.
38  */

39 abstract public class HTMLParserBase implements XMLCParser {
40     /**
41      * Table of HTML 4.0 elements that have a content model including #PCDATA.
42      */

43     private static final String JavaDoc[] PCDATA_ELEMENTS = {
44         // From strict DTD
45
"A", "ABBR", "ACRONYM", "ADDRESS", "B", "BDO", "BIG", "BUTTON",
46         "CAPTION", "CITE", "CODE", "DD", "DEL", "DFN", "DIV", "DT", "EM",
47         "FIELDSET", "H1", "H2", "H3", "H4", "H5", "H6", "I", "INS", "KBD",
48         "LABEL", "LEGEND", "LI", "OBJECT", "OPTION", "P", "PRE", "Q", "SAMP",
49         "SCRIPT", "SMALL", "SPAN", "STRONG", "STYLE", "SUB", "SUP", "TD",
50         "TEXTAREA", "TH", "TITLE", "TT", "VAR",
51
52         // Added by transitional and frameset DTDs
53
"APPLET", "BLOCKQUOTE", "BODY", "CENTER", "FONT", "FORM", "IFRAME",
54         "NOSCRIPT", "S", "STRIKE", "U",
55
56         // Added by transitional DTD
57
"NOFRAMES"
58     };
59
60     /**
61      * Common validation of configuration.
62      */

63     protected void validateConf(ParserType parserType,
64                                 MetaData metaData) throws XMLCException {
65         Parser parser = metaData.getParser();
66
67         Boolean JavaDoc validate = parser.getValidate();
68         if ((validate != null) && (!validate.booleanValue())) {
69             throw new XMLCException(parserType.getName() + " parser can't disable document validation");
70         }
71         
72         if (parser.getXCatalogURLs().length != 0) {
73             throw new XMLCException("XCatalog not support for HTML");
74         }
75     }
76
77     /**
78      * Generate error exception for parse errors.
79      */

80     protected void handleParseErrors(ErrorReporter reporter) throws XMLCException {
81         throw new XMLCException("" + reporter.getErrorCnt()
82                                 + " parse "
83                                 + ((reporter.getErrorCnt() > 1) ? "errors" : "error")
84                                 + " in HTML file");
85     }
86
87     /**
88      * Add elements that have #PCDATA as part of its content model
89      * to the XMLCDocument description.
90      */

91     protected void addPCDataContentElements(XMLCDocument xmlcDocument) {
92         for (int idx = 0; idx < PCDATA_ELEMENTS.length; idx++) {
93             xmlcDocument.addPCDataContentElement(PCDATA_ELEMENTS[idx]);
94         }
95     }
96 }
97
Popular Tags