001: /*
002: * $Id: HtmlParser.java 2366 2006-09-14 23:10:58Z xlv $
003: * $Name$
004: *
005: * Copyright 2001, 2002 by Bruno Lowagie.
006: *
007: * The contents of this file are subject to the Mozilla Public License Version 1.1
008: * (the "License"); you may not use this file except in compliance with the License.
009: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
010: *
011: * Software distributed under the License is distributed on an "AS IS" basis,
012: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
013: * for the specific language governing rights and limitations under the License.
014: *
015: * The Original Code is 'iText, a free JAVA-PDF library'.
016: *
017: * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
018: * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
019: * All Rights Reserved.
020: * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
021: * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
022: *
023: * Contributor(s): all the names of the contributors are added in the source code
024: * where applicable.
025: *
026: * Alternatively, the contents of this file may be used under the terms of the
027: * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
028: * provisions of LGPL are applicable instead of those above. If you wish to
029: * allow use of your version of this file only under the terms of the LGPL
030: * License and not to allow others to use your version of this file under
031: * the MPL, indicate your decision by deleting the provisions above and
032: * replace them with the notice and other provisions required by the LGPL.
033: * If you do not delete the provisions above, a recipient may use your version
034: * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
035: *
036: * This library is free software; you can redistribute it and/or modify it
037: * under the terms of the MPL as stated above or under the terms of the GNU
038: * Library General Public License as published by the Free Software Foundation;
039: * either version 2 of the License, or any later version.
040: *
041: * This library is distributed in the hope that it will be useful, but WITHOUT
042: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
043: * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
044: * details.
045: *
046: * If you didn't download this code from the following link, you should check if
047: * you aren't using an obsolete version:
048: * http://www.lowagie.com/iText/
049: */
050:
051: package com.lowagie.text.html;
052:
053: import java.io.IOException;
054: import java.io.InputStream;
055: import java.io.Reader;
056:
057: import org.xml.sax.InputSource;
058: import org.xml.sax.SAXException;
059:
060: import com.lowagie.text.DocListener;
061: import com.lowagie.text.ExceptionConverter;
062: import com.lowagie.text.xml.XmlParser;
063:
064: /**
065: * This class can be used to parse some HTML files.
066: */
067:
068: public class HtmlParser extends XmlParser {
069:
070: /**
071: * Constructs an HtmlParser.
072: */
073:
074: public HtmlParser() {
075: super ();
076: }
077:
078: /**
079: * Parses a given file.
080: * @param document the document the parser will write to
081: * @param is the InputSource with the content
082: */
083:
084: public void go(DocListener document, InputSource is) {
085: try {
086: parser.parse(is, new SAXmyHtmlHandler(document));
087: } catch (SAXException se) {
088: throw new ExceptionConverter(se);
089: } catch (IOException ioe) {
090: throw new ExceptionConverter(ioe);
091: }
092: }
093:
094: /**
095: * Parses a given file that validates with the iText DTD and writes the content to a document.
096: * @param document the document the parser will write to
097: * @param is the InputSource with the content
098: */
099:
100: public static void parse(DocListener document, InputSource is) {
101: HtmlParser p = new HtmlParser();
102: p.go(document, is);
103: }
104:
105: /**
106: * Parses a given file.
107: * @param document the document the parser will write to
108: * @param file the file with the content
109: */
110:
111: public void go(DocListener document, String file) {
112: try {
113: parser.parse(file, new SAXmyHtmlHandler(document));
114: } catch (SAXException se) {
115: throw new ExceptionConverter(se);
116: } catch (IOException ioe) {
117: throw new ExceptionConverter(ioe);
118: }
119: }
120:
121: /**
122: * Parses a given file that validates with the iText DTD and writes the content to a document.
123: * @param document the document the parser will write to
124: * @param file the file with the content
125: */
126:
127: public static void parse(DocListener document, String file) {
128: HtmlParser p = new HtmlParser();
129: p.go(document, file);
130: }
131:
132: /**
133: * Parses a given file.
134: * @param document the document the parser will write to
135: * @param is the InputStream with the content
136: */
137:
138: public void go(DocListener document, InputStream is) {
139: try {
140: parser.parse(new InputSource(is), new SAXmyHtmlHandler(
141: document));
142: } catch (SAXException se) {
143: throw new ExceptionConverter(se);
144: } catch (IOException ioe) {
145: throw new ExceptionConverter(ioe);
146: }
147: }
148:
149: /**
150: * Parses a given file that validates with the iText DTD and writes the content to a document.
151: * @param document the document the parser will write to
152: * @param is the InputStream with the content
153: */
154:
155: public static void parse(DocListener document, InputStream is) {
156: HtmlParser p = new HtmlParser();
157: p.go(document, new InputSource(is));
158: }
159:
160: /**
161: * Parses a given file.
162: * @param document the document the parser will write to
163: * @param is the Reader with the content
164: */
165:
166: public void go(DocListener document, Reader is) {
167: try {
168: parser.parse(new InputSource(is), new SAXmyHtmlHandler(
169: document));
170: } catch (SAXException se) {
171: throw new ExceptionConverter(se);
172: } catch (IOException ioe) {
173: throw new ExceptionConverter(ioe);
174: }
175: }
176:
177: /**
178: * Parses a given file that validates with the iText DTD and writes the content to a document.
179: * @param document the document the parser will write to
180: * @param is the Reader with the content
181: */
182:
183: public static void parse(DocListener document, Reader is) {
184: HtmlParser p = new HtmlParser();
185: p.go(document, new InputSource(is));
186: }
187: }
|