/** * Parses text into StyleSheet * * @param css * Text with CSS declarations * @return Parsed StyleSheet * @throws IOException * When exception during read occurs * @throws CSSException * When exception during parse occurs */ public static final StyleSheet parse(String css) throws IOException, CSSException { return CSSParserFactory.parse(css, null, SourceType.EMBEDDED, null); }
parse(parser, type);
/** * Parses URL into StyleSheet * * @param url * URL of file to be parsed * @param encoding * Encoding of file * @return Parsed StyleSheet * @throws CSSException * When exception during parse occurs * @throws IOException * When file not found */ public static final StyleSheet parse(URL url, String encoding) throws CSSException, IOException { return CSSParserFactory.parse((Object) url, encoding, SourceType.URL, url); }
/** * Parses source of given type. Uses no element. * * @param source * Source, interpretation depends on {@code type} * @param type * Type of source provided * @param base * The base URL * @return Created StyleSheet * @throws IOException * When problem with input stream occurs * @throws CSSException * When unrecoverable exception during parsing occurs * @throws IllegalArgumentException * When type of source is INLINE */ public StyleSheet parse(Object source, NetworkProcessor network, String encoding, SourceType type, URL base) throws IOException, CSSException { if (type == SourceType.INLINE) throw new IllegalArgumentException( "Missing element for INLINE input"); return parse(source, network, encoding, type, null, false, base); }
/** * Parses source of given type. Uses no element. * * @param source * Source, interpretation depends on {@code type} * @param type * Type of source provided * @param base * The base URL * @return Created StyleSheet * @throws IOException * When problem with input stream occurs * @throws CSSException * When unrecoverable exception during parsing occurs * @throws IllegalArgumentException * When type of source is INLINE */ public static StyleSheet parse(Object source, String encoding, SourceType type, URL base) throws IOException, CSSException { if (type == SourceType.INLINE) throw new IllegalArgumentException( "Missing element for INLINE input"); return parse(source, encoding, type, null, false, base); }
/** * Parses URL into StyleSheet * * @param url * URL of file to be parsed * @param network * Network processor used for handling the URL connections * @param encoding * Encoding of file * @return Parsed StyleSheet * @throws CSSException * When exception during parse occurs * @throws IOException * When file not found */ public static final StyleSheet parse(URL url, NetworkProcessor network, String encoding) throws CSSException, IOException { return getCSSParserFactory().parse((Object) url, network, encoding, SourceType.URL, url); }
/** * Parses text into a StyleSheet * * @param css * Text with CSS declarations * @param base * The URL to be used as a base for loading external resources. Base URL may * be {@code null} if there are no external resources in the CSS string * referenced by relative URLs. * @param network * Network processor for retrieving the URL resources * @return Parsed StyleSheet * @throws IOException * When exception during read occurs * @throws CSSException * When exception during parse occurs */ public static final StyleSheet parseString(String css, URL base, NetworkProcessor network) throws IOException, CSSException { URL baseurl = base; if (baseurl == null) baseurl = new URL("file:///base/url/is/not/specified"); //prevent errors if there are still some relative URLs used return getCSSParserFactory().parse(css, network, null, SourceType.EMBEDDED, baseurl); }
/** * Parses text into StyleSheet * * @param css * Text with CSS declarations * @return Parsed StyleSheet * @throws IOException * When exception during read occurs * @throws CSSException * When exception during parse occurs * @deprecated * This function does not specify the base URL. {@link #parseString(String, URL)} * should be used instead. */ @Deprecated public static final StyleSheet parse(String css) throws IOException, CSSException { URL base = new URL("file:///base/url/is/not/specified"); //Cannot determine the base URI in this method but we need some base URI for relative URLs return getCSSParserFactory().parse(css, new DefaultNetworkProcessor(), null, SourceType.EMBEDDED, base); }
public void analyse(Collection<URI> sheetURIs, Collection<String> embeddedCSS, URI embedContainerURI, NetworkProcessor network) throws IOException, URISyntaxException, CSSException { if (!SupportedCSS.isSupportedMedia(Medium)) { throw new IllegalStateException("medium '" + Medium + "' is not supported"); } List<URI> alluris = new ArrayList<URI>(); List<String> csscode = new ArrayList<String>(embeddedCSS); for (int k = 0; k < embeddedCSS.size(); ++k) alluris.add(embedContainerURI); for (URI uri : sheetURIs) { if (uri != null) { alluris.add(uri); csscode.add(IOUtils.toString(uri.toURL().openStream(), "UTF-8")); } } List<StyleSheet> styleSheets = new ArrayList<StyleSheet>(); for (int k = 0; k < csscode.size(); ++k) { String basePath = alluris.get(k).resolve(".").toString(); String withAbsURL = makeURLabsolute(csscode.get(k), basePath); styleSheets.add(parserFactory.parse(withAbsURL, network, null, SourceType.EMBEDDED, new URL("http://base"))); /* * we cannot use CSSFactory.parse(withAbsURL) because it tries to * convert the null base URL into a String */ } mAnalyzer = new Analyzer(styleSheets); }
/** * Parses URL into StyleSheet * * @param url * URL of file to be parsed * @param encoding * Encoding of file * @return Parsed StyleSheet * @throws CSSException * When exception during parse occurs * @throws IOException * When file not found */ public static final StyleSheet parse(URL url, String encoding) throws CSSException, IOException { return getCSSParserFactory().parse((Object) url, new DefaultNetworkProcessor(), encoding, SourceType.URL, url); }