use of org.loboevolution.html.io.WritableLineReader in project LoboEvolution by LoboEvolution.
the class LoboWebDriver method loadHtml.
/**
* <p>loadHtml.</p>
*
* @param in a {@link java.io.InputStream} object.
* @return a {@link org.loboevolution.html.dom.domimpl.HTMLDocumentImpl} object.
*/
protected static HTMLDocumentImpl loadHtml(InputStream in) {
HTMLDocumentImpl doc = null;
try {
WritableLineReader wis = new WritableLineReader(new InputStreamReader(in, StandardCharsets.UTF_8));
final UserAgentContext ucontext = new UserAgentContext(true);
HtmlPanel panel = new HtmlPanel();
panel.setPreferredSize(new Dimension(800, 400));
final HtmlRendererContext rendererContext = new HtmlRendererContext(panel, ucontext);
rendererContext.setTest(true);
ucontext.setUserAgentEnabled(true);
doc = new HTMLDocumentImpl(ucontext, rendererContext, wis, "http://www.example.com/xhtml/htmlsample.html");
doc.load();
} catch (Exception e) {
e.printStackTrace();
}
return doc;
}
use of org.loboevolution.html.io.WritableLineReader in project LoboEvolution by LoboEvolution.
the class LoboWebDriver method loadHtml.
/**
* <p>loadHtml.</p>
*
* @param html a {@link java.lang.String} object.
* @return a {@link org.loboevolution.html.dom.domimpl.HTMLDocumentImpl} object.
*/
protected HTMLDocumentImpl loadHtml(String html) {
HTMLDocumentImpl doc = null;
try {
WritableLineReader wis = new WritableLineReader(new StringReader(html));
final UserAgentContext ucontext = new UserAgentContext(true);
HtmlPanel panel = new HtmlPanel();
panel.setPreferredSize(new Dimension(800, 400));
final HtmlRendererContext rendererContext = new HtmlRendererContext(panel, ucontext);
rendererContext.setTest(true);
ucontext.setUserAgentEnabled(true);
doc = new HTMLDocumentImpl(ucontext, rendererContext, wis, "http://www.example.com/xhtml/htmlsample.html");
doc.load();
} catch (Exception e) {
e.printStackTrace();
}
return doc;
}
use of org.loboevolution.html.io.WritableLineReader in project LoboEvolution by LoboEvolution.
the class HTMLDocumentImpl method load.
/**
* <p>load.</p>
*
* @param closeReader a boolean.
* @throws java.io.IOException if any.
* @throws org.xml.sax.SAXException if any.
* @throws java.io.UnsupportedEncodingException if any.
*/
public void load(boolean closeReader) throws IOException, SAXException, UnsupportedEncodingException {
WritableLineReader reader;
synchronized (this) {
removeAllChildrenImpl();
setTitle(null);
setBaseURI(null);
setDefaultTarget(null);
this.styleSheets.clear();
this.styleSheetAggregator = null;
reader = this.reader;
}
if (reader != null) {
try {
final ErrorHandler errorHandler = new LocalErrorHandler();
final HtmlParser parser = new HtmlParser(getUcontext(), document, errorHandler, true);
parser.parse(reader);
} finally {
if (closeReader) {
try {
reader.close();
} catch (final Exception err) {
logger.log(Level.WARNING, "load(): Unable to close stream", err);
}
synchronized (this) {
this.reader = null;
}
}
}
}
}
use of org.loboevolution.html.io.WritableLineReader in project LoboEvolution by LoboEvolution.
the class DocumentBuilderImpl method createDocument.
/**
* Creates a document without parsing the input provided, so the document object
* can be used for incremental rendering.
*
* @param is The input source, which may be an instance of
* {@link org.loboevolution.html.parser.InputSourceImpl}. The input
* source must provide either an input stream or a reader.
* @see HTMLDocumentImpl#load()
* @return a {@link org.loboevolution.html.node.Document} object.
* @throws org.xml.sax.SAXException if any.
* @throws java.io.IOException if any.
*/
public Document createDocument(InputSource is) throws SAXException, IOException {
final String encoding = is.getEncoding();
String charset = encoding;
if (charset == null) {
charset = "US-ASCII";
}
final String uri = is.getSystemId();
if (uri == null) {
logger.warning("parse(): InputSource has no SystemId (URI); document item URLs will not be resolvable.");
}
WritableLineReader wis;
final Reader reader = is.getCharacterStream();
if (reader != null) {
wis = new WritableLineReader(reader);
} else {
InputStream in = is.getByteStream();
if (in != null) {
wis = new WritableLineReader(new InputStreamReader(in, charset));
} else if (uri != null) {
final URLConnection connection = new URL(uri).openConnection();
in = connection.getInputStream();
if (encoding == null) {
charset = Urls.getCharset(connection);
}
wis = new WritableLineReader(new InputStreamReader(in, charset));
} else {
throw new IllegalArgumentException("The InputSource must have either a reader, an input stream or a URI.");
}
}
return new HTMLDocumentImpl(this.bcontext, this.rcontext, wis, uri);
}
Aggregations