/** * Check if the passed CSS file can be parsed without error * * @param aFile * The file to be parsed. May not be <code>null</code>. * @param aFallbackCharset * The charset to be used for reading the CSS file in case neither a * <code>@charset</code> rule nor a BOM is present. May not be * <code>null</code>. * @param eVersion * The CSS version to be used for scanning. May not be * <code>null</code>. * @return <code>true</code> if the file can be parsed without error, * <code>false</code> if not */ public static boolean isValidCSS (@Nonnull final File aFile, @Nonnull final Charset aFallbackCharset, @Nonnull final ECSSVersion eVersion) { return isValidCSS (new FileSystemResource (aFile), aFallbackCharset, eVersion); }
/** * Check if the passed String can be resembled to valid CSS content. This is * accomplished by fully parsing the CSS file each time the method is called. * This is similar to calling * {@link #readFromString(String, Charset, ECSSVersion)} and checking for a * non-<code>null</code> result. * * @param sCSS * The CSS string to scan. May not be <code>null</code>. * @param eVersion * The CSS version to use. May not be <code>null</code>. * @return <code>true</code> if the CSS is valid according to the version, * <code>false</code> if not */ public static boolean isValidCSS (@Nonnull final String sCSS, @Nonnull final ECSSVersion eVersion) { ValueEnforcer.notNull (sCSS, "CSS"); return isValidCSS (new NonBlockingStringReader (sCSS), eVersion); }
/** * Check if the passed CSS resource can be parsed without error * * @param aRes * The resource to be parsed. May not be <code>null</code>. * @param aFallbackCharset * The charset to be used for reading the CSS file in case neither a * <code>@charset</code> rule nor a BOM is present. May not be * <code>null</code>. * @param eVersion * The CSS version to be used for scanning. May not be * <code>null</code>. * @return <code>true</code> if the file can be parsed without error, * <code>false</code> if not */ public static boolean isValidCSS (@Nonnull final IReadableResource aRes, @Nonnull final Charset aFallbackCharset, @Nonnull final ECSSVersion eVersion) { ValueEnforcer.notNull (aRes, "Resource"); ValueEnforcer.notNull (aFallbackCharset, "FallbackCharset"); ValueEnforcer.notNull (eVersion, "Version"); final Reader aReader = aRes.getReader (aFallbackCharset); if (aReader == null) { LOGGER.warn ("Failed to open CSS reader " + aRes); return false; } return isValidCSS (aReader, eVersion); }
/** * Check if the passed input stream can be resembled to valid CSS content. * This is accomplished by fully parsing the CSS file each time the method is * called. This is similar to calling * {@link #readFromStream(IHasInputStream,Charset, ECSSVersion)} and checking * for a non-<code>null</code> result. * * @param aIS * The input stream to use. Is automatically closed. May not be * <code>null</code>. * @param aFallbackCharset * The charset to be used in case neither a <code>@charset</code> rule * nor a BOM is present. May not be <code>null</code>. * @param eVersion * The CSS version to use. May not be <code>null</code>. * @return <code>true</code> if the CSS is valid according to the version, * <code>false</code> if not */ public static boolean isValidCSS (@Nonnull @WillClose final InputStream aIS, @Nonnull final Charset aFallbackCharset, @Nonnull final ECSSVersion eVersion) { ValueEnforcer.notNull (aIS, "InputStream"); ValueEnforcer.notNull (aFallbackCharset, "FallbackCharset"); return isValidCSS (StreamHelper.createReader (aIS, aFallbackCharset), eVersion); }