public void initImageLoader(HTMLDocument document) { try { document.setBase(new URL(ImageLoaderCache.IMAGE_URL_PREFIX)); } catch (MalformedURLException e) { log.error(e.getMessage()); } setContextResource(navigator.getCurrentResource()); document.getDocumentProperties().put("imageCache", this); }
public void setPage(final URL page) throws IOException { if (page == null) { throw new IOException(Messages.getString("swing.03", "Page")); // $NON-NLS-1$ //$NON-NLS-2$ } String url = page.toString(); String baseUrl = getBaseURL(url); Document oldDoc = getDocument(); if (baseUrl != null && oldDoc != null && baseUrl.equals(oldDoc.getProperty(Document.StreamDescriptionProperty))) { scrollToReference(page.getRef()); return; } InputStream stream = getStream(page); if (stream == null) { return; } Document newDoc = editorKit.createDefaultDocument(); // Perhaps, it is reasonable only for HTMLDocument... if (newDoc instanceof HTMLDocument) { newDoc.putProperty(Document.StreamDescriptionProperty, baseUrl); newDoc.putProperty(StringConstants.IGNORE_CHARSET_DIRECTIVE, new Boolean(false)); try { ((HTMLDocument) newDoc).setBase(new URL(baseUrl)); } catch (IOException e) { } } // TODO Asynch loading doesn't work with completely. // Also page property change event is written incorrectly now // (at the asynchrounous loading), because loading may not be // completed. // int asynchronousLoadPriority = getAsynchronousLoadPriority(newDoc); int asynchronousLoadPriority = -1; if (asynchronousLoadPriority >= 0) { setDocument(newDoc); AsynchLoad newThread = new AsynchLoad(asynchronousLoadPriority, stream, page); newThread.start(); if (newThread.successfulLoading) { changePage(page); } } else { try { documentLoading(stream, newDoc, page); stream.close(); setDocument(newDoc); changePage(page); } catch (IOException e) { } } }