org.fit.net.DataURLHandler Java Examples

The following examples show how to use org.fit.net.DataURLHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SwingBrowser.java    From SwingBox with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void displayURL(String urlstring)
{
    try {
        if (!urlstring.startsWith("http:") &&
                !urlstring.startsWith("https:") &&
                !urlstring.startsWith("ftp:") &&
                !urlstring.startsWith("file:") &&
                !urlstring.startsWith("data:"))
                    urlstring = "http://" + urlstring;
            
        URL url = DataURLHandler.createURL(null, urlstring);
        urlText.setText(url.toString());

        while (historyPos < history.size())
            history.remove(history.size() - 1);
        history.add(url);
        historyPos++;

        displayURLSwingBox(url);
    } catch (Exception e) {
        System.err.println("*** Error: "+e.getMessage());
        e.printStackTrace();
    }
}
 
Example #2
Source File: CSSParserFactory.java    From jStyleParser with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Parses the source using the given infrastructure and returns the resulting style sheet.
 * The imports are handled recursively.
 */
protected StyleSheet parseAndImport(Object source, NetworkProcessor network, String encoding, SourceType type,
                                    StyleSheet sheet, Preparator preparator, URL base, List<MediaQuery> media)
        throws CSSException, IOException {
    CSSParser parser = createParser(source, network, encoding, type, base);
    CSSParserExtractor extractor = parse(parser, type, preparator, media);

    for (int i = 0; i < extractor.getImportPaths().size(); i++) {
        String path = extractor.getImportPaths().get(i);
        List<MediaQuery> imedia = extractor.getImportMedia().get(i);

        if (((imedia == null || imedia.isEmpty()) && CSSFactory.getAutoImportMedia().matchesEmpty()) //no media query specified
                || CSSFactory.getAutoImportMedia().matchesOneOf(imedia)) //or some media query matches to the autoload media spec
        {
            URL url = DataURLHandler.createURL(base, path);
            try {
                parseAndImport(url, network, encoding, SourceType.URL, sheet, preparator, url, imedia);
            } catch (IOException e) {
                log.warn("Couldn't read imported style sheet: {}", e.getMessage());
            }
        } else
            log.trace("Skipping import {} (media not matching)", path);
    }

    return addRulesToStyleSheet(extractor.getRules(), sheet);
}
 
Example #3
Source File: GraphicsVisualContext.java    From CSSBox with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected String registerExternalFont(TermURI urlstring, String format)
        throws MalformedURLException, IOException
{
    String nameFound = null;
    if (format == null || FontDecoder.supportedFormats.contains(format))
    {
        URL url = DataURLHandler.createURL(urlstring.getBase(), urlstring.getValue());
        String regName = FontDecoder.findRegisteredFont(url);
        if (regName == null)
        {
            DocumentSource imgsrc = getViewport().getConfig().createDocumentSource(url);
            Font newFont;
            try {
                newFont = FontDecoder.decodeFont(imgsrc, format);
            } catch (FontFormatException e) {
                throw new IOException(e);
            }
            if (GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(newFont))
                log.debug("Registered font: {}", newFont.getFontName());
            else
                log.debug("Failed to register font: {} (not fatal, probably already existing)", newFont.getFontName());
            regName = newFont.getFontName();
            FontDecoder.registerFont(url, regName);
        }
        nameFound = regName;
    }
    return nameFound;
}
 
Example #4
Source File: DefaultDocumentSource.java    From CSSBox with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Creates a data source based on the URL string. The data: urls are automatically
 * recognized and  processed.
 * @param urlstring The URL string
 * @throws IOException
 */
public DefaultDocumentSource(String urlstring) throws IOException
{
    super(null, urlstring);
    URL url = DataURLHandler.createURL(null, urlstring);
    con = createConnection(url);
    is = null;
}
 
Example #5
Source File: DefaultDocumentSource.java    From CSSBox with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Creates a data source based on the URL string. The data: urls are automatically
 * recognized and  processed.
 * @param base The base URL to be used for the relative URLs in the urlstring
 * @param urlstring The URL string
 * @throws IOException
 */
public DefaultDocumentSource(URL base, String urlstring) throws IOException
{
    super(base, urlstring);
    URL url = DataURLHandler.createURL(base, urlstring);
    con = createConnection(url);
    is = null;
}
 
Example #6
Source File: CSSFactory.java    From jStyleParser with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected void processNode(StyleSheet result, Node current,	Object source) 
{
	// base uri
	URL base = ((SourceData) source).base;
	// allowed media
	MediaSpec media = ((SourceData) source).media;
	// network processor
	NetworkProcessor network = ((SourceData) source).network;
	Element elem = (Element) current;

	try {
		// embedded style-sheet
		if (isEmbeddedStyleSheet(elem, media)) {
			result = pf.append(extractElementText(elem), network, null,
					SourceType.EMBEDDED, result, base);
			log.debug("Matched embedded CSS style");
		}
		// linked style-sheet
		else if (isLinkedStyleSheet(elem, media)) {
		    URL uri = DataURLHandler.createURL(base, matcher.getAttribute(elem, "href"));
			result = pf.append(uri, network, encoding, SourceType.URL,
					result, uri);
			log.debug("Matched linked CSS style");
		}
		// in-line style and default style
		else {
  				    if (elem.getAttribute("style") != null && elem.getAttribute("style").length() > 0) {
      					result = pf.append(
      							elem.getAttribute("style"), network,
      							null, SourceType.INLINE,
      							elem, true, result, base);
      					log.debug("Matched inline CSS style");
  				    }
                      if (elem.getAttribute("XDefaultStyle") != null && elem.getAttribute("XDefaultStyle").length() > 0) {
                          result = pf.append(
                                  elem.getAttribute("XDefaultStyle"), network,
                                  null, SourceType.INLINE,
                                  elem, false, result, base);
                          log.debug("Matched default CSS style");
                      }
		}
	} catch (CSSException ce) {
		log.error("THROWN:", ce);
	} catch (IOException ioe) {
		log.error("THROWN:", ioe);
	}

}
 
Example #7
Source File: ReplacedImage.java    From CSSBox with GNU Lesser General Public License v3.0 3 votes vote down vote up
/**
 * Creates a new instance of ReplacedImage. 
 * 
 * @param owner
 *            the owning Box.
 * @param ctx
 *            the visual context applied during rendering.
 * @param baseurl
 *            the base url used for loading images from.
 * @param src
 *            the source URL
 * 
 * @see ElementBox
 * @see VisualContext
 * @see URL
 */
public ReplacedImage(ElementBox owner, VisualContext ctx, URL baseurl, String src)
{
    super(owner);
    this.ctx = ctx;
    base = baseurl;
    try
    {
        url = DataURLHandler.createURL(base, src);
    } catch (MalformedURLException e) {
        url = null;
        log.error("URL: " + e.getMessage());
    }
}