KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > xml > xmlc > html > parsers > swing > SwingHTMLParser


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: SwingHTMLParser.java,v 1.2 2005/01/26 08:29:24 jkjome Exp $
22  */

23
24 package org.enhydra.xml.xmlc.html.parsers.swing;
25
26 import java.io.IOException JavaDoc;
27 import java.io.Reader JavaDoc;
28
29 import org.enhydra.xml.io.ErrorReporter;
30 import org.enhydra.xml.xmlc.XMLCException;
31 import org.enhydra.xml.xmlc.dom.XMLCDocument;
32 import org.enhydra.xml.xmlc.dom.XMLCDomFactory;
33 import org.enhydra.xml.xmlc.html.parsers.HTMLDocBuilder;
34 import org.enhydra.xml.xmlc.html.parsers.HTMLParserBase;
35 import org.enhydra.xml.xmlc.metadata.MetaData;
36 import org.enhydra.xml.xmlc.metadata.ParserType;
37 import org.enhydra.xml.xmlc.misc.LineNumberMap;
38 import org.enhydra.xml.xmlc.misc.LineNumberMapReader;
39 import org.enhydra.xml.xmlc.parsers.ParseTracer;
40 import org.enhydra.xml.xmlc.parsers.XMLCParser;
41 import org.xml.sax.InputSource JavaDoc;
42
43
44 // FIXME: should we check that no propritary tags are supplied???
45

46
47 /**
48  * XMLCParser object for HTML and HTML framesets using the Swing HTML parser.
49  */

50 public class SwingHTMLParser extends HTMLParserBase implements XMLCParser {
51     /**
52      * @see XMLCParser#parse
53      */

54     public XMLCDocument parse(InputSource JavaDoc input,
55                               LineNumberMap lineNumberMap,
56                               XMLCDomFactory domFactory,
57                               MetaData metaData,
58                               ErrorReporter errorReporter,
59                               ParseTracer tracer)
60         throws IOException JavaDoc, XMLCException {
61         HTMLDocBuilder docBuilder = new HTMLDocBuilder(domFactory,
62                                                        input);
63         validateConf(ParserType.SWING, metaData);
64
65         // We need a LineNumberMap, even with a single file, since swing
66
// reports things in character offsets.
67
Reader JavaDoc reader = null;
68         if (lineNumberMap == null) {
69             LineNumberMapReader mapReader = new LineNumberMapReader(input);
70             reader = mapReader;
71             lineNumberMap = mapReader.getLineNumberMap();
72         } else {
73             reader = input.getCharacterStream();
74         }
75
76         SwingParser parser = new SwingParser();
77         parser.parse(docBuilder, errorReporter, tracer, reader, lineNumberMap);
78         if (errorReporter.getErrorCnt() != 0) {
79             handleParseErrors(errorReporter);
80         }
81         
82         addPCDataContentElements(docBuilder.getXMLCDocument());
83         return docBuilder.getXMLCDocument();
84     }
85 }
86
Popular Tags