All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cat.inspiracio.html.HTMLDocumentBuilder Maven / Gradle / Ivy

/*
Copyright 2015 Alexander Bunkenburg 

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cat.inspiracio.html;

import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.io.StringReader;

import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

/** Defines the API to obtain HTML5 Document instances from an HTML5
 * document. Using this class, an application programmer can obtain a
 * {@link HTMLDocument} from HTML5.
 * */
public class HTMLDocumentBuilder extends HTMLBuilder{

	public HTMLDocumentBuilder(){
		super();
	}

	// business methods -------------------------

    /** Creates an HTMLDocument object with the minimal tree made
     * of the following elements: 
     * html , 
     * head ,
     * title , and 
     * body .
     * 
     * @return  A new HTMLDocument object.
     */
	public HTMLDocument newDocument(){
		return (HTMLDocument)htb.newDocument();
	}
	
	/** In this subclass, returns a complete Document, even if the source is just a fragment. */
	@Override public HTMLDocument parse(String s) throws SAXException, IOException{
		return parse(new InputSource(new StringReader(s)));
	}

	/** In this subclass, returns a complete Document, even if the source is just a fragment. */
	@Override public HTMLDocument parse(InputStream in) throws SAXException, IOException{
		return parse(new InputSource(in));
	}

	/** In this subclass, returns a complete Document, even if the source is just a fragment. */
	@Override public HTMLDocument parse(Reader in) throws SAXException, IOException{
		return parse(new InputSource(in));
	}

	/** In this subclass, returns a complete Document, even if the source is just a fragment. */
	@Override public HTMLDocument parse(InputSource source) throws SAXException, IOException{
		//This is the only parse() method that really does something, the others just
		//adapt parameters.
		HTMLDocument d=(HTMLDocument)htb.parse(source);
		return clean(d);
	}
	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy