com.helger.commons.io.file.IFileFilter Java Examples
The following examples show how to use
com.helger.commons.io.file.IFileFilter.
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: CSSWriterFuncTest.java From ph-css with Apache License 2.0 | 6 votes |
@Test public void testRead30Write21 () throws IOException { for (final File aFile : new FileSystemRecursiveIterator (new File ("src/test/resources/testfiles/css30/good/artificial")).withFilter (IFileFilter.filenameEndsWith (".css"))) { final String sKey = aFile.getAbsolutePath (); try { // read and interpret CSS 3.0 final CascadingStyleSheet aCSS = CSSReader.readFromFile (aFile, StandardCharsets.UTF_8, ECSSVersion.CSS30); assertNotNull (sKey, aCSS); // write to CSS 2.1 final NonBlockingStringWriter aSW = new NonBlockingStringWriter (); new CSSWriter (ECSSVersion.CSS21).writeCSS (aCSS, aSW); // This should throw an error fail (sKey + " should have thrown an exception but got: " + aSW.getAsString ()); } catch (final IllegalStateException ex) {} } }
Example #2
Source File: AbstractFuncTestCSSReader.java From ph-css with Apache License 2.0 | 6 votes |
protected final void testReadBad (@Nonnull final String sBaseDir) { final File aBaseDir = new File (sBaseDir); if (!aBaseDir.exists ()) throw new IllegalArgumentException ("BaseDir " + sBaseDir + " does not exist!"); for (final File aFile : new FileSystemRecursiveIterator (aBaseDir).withFilter (IFileFilter.filenameEndsWith (".css"))) { final String sKey = aFile.getAbsolutePath (); if (m_bDebug) m_aLogger.info (sKey); // Handle each error as a fatal error! final CascadingStyleSheet aCSS = CSSReader.readFromFile (aFile, m_aReaderSettings); assertNull (sKey, aCSS); } }
Example #3
Source File: CSSVisitor30FuncTest.java From ph-css with Apache License 2.0 | 6 votes |
@Test public void testVisitContent30 () { for (final File aFile : new FileSystemRecursiveIterator (new File ("src/test/resources/testfiles/css30/good")).withFilter (IFileFilter.filenameEndsWith (".css"))) { final String sKey = aFile.getAbsolutePath (); if (true) LOGGER.info (sKey); final CascadingStyleSheet aCSS = CSSReader.readFromFile (aFile, new CSSReaderSettings ().setFallbackCharset (StandardCharsets.UTF_8) .setCSSVersion (ECSSVersion.CSS30) .setCustomErrorHandler (new LoggingCSSParseErrorHandler ()) .setBrowserCompliantMode (true)); assertNotNull (sKey, aCSS); CSSVisitor.visitCSSUrl (aCSS, new MockUrlVisitor (sKey)); } }
Example #4
Source File: CSSWriterFuncTest.java From ph-css with Apache License 2.0 | 5 votes |
@Test public void testScanTestResourcesHandler21 () { for (final File aFile : new FileSystemRecursiveIterator (new File ("src/test/resources/testfiles/css21/good/artificial")).withFilter (IFileFilter.filenameEndsWith (".css"))) { _testMe (aFile, ECSSVersion.CSS30); } }
Example #5
Source File: CSSWriterFuncTest.java From ph-css with Apache License 2.0 | 5 votes |
@Test public void testScanTestResourcesHandler30 () { for (final File aFile : new FileSystemRecursiveIterator (new File ("src/test/resources/testfiles/css30/good/artificial")).withFilter (IFileFilter.filenameEndsWith (".css"))) { _testMe (aFile, ECSSVersion.CSS30); } }
Example #6
Source File: AbstractFuncTestCSSReader.java From ph-css with Apache License 2.0 | 5 votes |
protected final void testReadBadButRecoverable (@Nonnull final String sBaseDir) { final File aBaseDir = new File (sBaseDir); if (!aBaseDir.exists ()) throw new IllegalArgumentException ("BaseDir " + sBaseDir + " does not exist!"); for (final File aFile : new FileSystemRecursiveIterator (aBaseDir).withFilter (IFileFilter.filenameEndsWith (".css"))) { final String sKey = aFile.getAbsolutePath (); if (m_bDebug) m_aLogger.info (sKey); // Handle each error as a fatal error! final CollectingCSSParseErrorHandler aErrorHdl = new CollectingCSSParseErrorHandler (); m_aReaderSettings.setCustomErrorHandler (aErrorHdl.and (new LoggingCSSParseErrorHandler ())); final CascadingStyleSheet aCSS = CSSReader.readFromFile (aFile, m_aReaderSettings); assertNotNull (sKey, aCSS); assertTrue (sKey, aErrorHdl.hasParseErrors ()); assertTrue (sKey, aErrorHdl.getParseErrorCount () > 0); if (m_bDebug) m_aLogger.info (aErrorHdl.getAllParseErrors ().toString ()); // Write optimized version and re-read it final String sCSS = new CSSWriter (m_aWriterSettings.setOptimizedOutput (true)).getCSSAsString (aCSS); assertNotNull (sKey, sCSS); if (m_bDebug) m_aLogger.info (sCSS); final CascadingStyleSheet aCSSReRead = CSSReader.readFromStringReader (sCSS, m_aReaderSettings); assertNotNull ("Failed to parse:\n" + sCSS, aCSSReRead); assertEquals (sKey, aCSS, aCSSReRead); } }
Example #7
Source File: MainReadAllCSSOnDisc.java From ph-css with Apache License 2.0 | 5 votes |
@SuppressFBWarnings ("DMI_HARDCODED_ABSOLUTE_FILENAME") public static void main (final String [] args) { int nFilesOK = 0; int nFilesError = 0; final ICommonsOrderedMap <File, ParseException> aErrors = new CommonsLinkedHashMap<> (); final Wrapper <File> aCurrentFile = new Wrapper<> (); final ICSSParseExceptionCallback aHdl = ex -> aErrors.put (aCurrentFile.get (), ex); for (final File aFile : new FileSystemRecursiveIterator (new File ("/")).withFilter (IFileFilter.filenameEndsWith (".css"))) { if (false) LOGGER.info (aFile.getAbsolutePath ()); aCurrentFile.set (aFile); final CascadingStyleSheet aCSS = CSSReader.readFromFile (aFile, StandardCharsets.UTF_8, ECSSVersion.CSS30, aHdl); if (aCSS == null) { nFilesError++; LOGGER.warn (" " + aFile.getAbsolutePath () + " failed!"); } else nFilesOK++; } LOGGER.info ("Done"); for (final Map.Entry <File, ParseException> aEntry : aErrors.entrySet ()) LOGGER.info (" " + aEntry.getKey ().getAbsolutePath () + ":\n" + aEntry.getValue ().getMessage () + "\n"); LOGGER.info ("OK: " + nFilesOK + "; Error: " + nFilesError); }
Example #8
Source File: MainCreateJAXBBinding22.java From ph-ubl with Apache License 2.0 | 5 votes |
@Nonnull private static Iterable <File> _getFileList (final String sPath) { return CollectionHelper.getSorted (new FileSystemIterator (sPath).withFilter (IFileFilter.filenameEndsWith (".xsd")) .withFilter (IFileFilter.filenameMatchNoRegEx ("^CCTS.*", ".*xmldsig.*", ".*XAdES.*")), Comparator.comparing (File::getName)); }
Example #9
Source File: MainCreateEnumsGenericode21.java From ph-ubl with Apache License 2.0 | 5 votes |
public static void main (final String [] args) throws JCodeModelException, IOException { for (final File aFile : new FileSystemRecursiveIterator (new File ("src/main/resources/codelists")).withFilter (IFileFilter.filenameEndsWith (".gc"))) { final CodeListDocument aCodeList10 = new Genericode10CodeListMarshaller ().read (aFile); if (aCodeList10 != null) _createGenericode10 (aFile, aCodeList10); } new JCMWriter (s_aCodeModel).build (new File ("src/main/java")); }
Example #10
Source File: MainCreateEnumsGenericode23.java From ph-ubl with Apache License 2.0 | 5 votes |
public static void main (final String [] args) throws JCodeModelException, IOException { for (final File aFile : new FileSystemRecursiveIterator (new File ("src/main/resources/codelists")).withFilter (IFileFilter.filenameEndsWith (".gc"))) if (!aFile.getName ().equals ("BinaryObjectMimeCode-2.3-incl-deprecated.gc") && !aFile.getName ().equals ("PackagingTypeCode-2.3-incl-deleted.gc") && !aFile.getName ().equals ("UnitOfMeasureCode-2.3-incl-deleted.gc")) { final CodeListDocument aCodeList10 = new Genericode10CodeListMarshaller ().read (aFile); if (aCodeList10 != null) _createGenericode10 (aFile, aCodeList10); } new JCMWriter (s_aCodeModel).build (new File ("src/main/java")); }
Example #11
Source File: MainCreateEnumsGenericode20.java From ph-ubl with Apache License 2.0 | 5 votes |
public static void main (final String [] args) throws JCodeModelException, IOException { for (final File aFile : new FileSystemRecursiveIterator (new File ("src/main/resources/codelists")).withFilter (IFileFilter.filenameEndsWith (".gc"))) { System.out.println (aFile.getName ()); final CodeListDocument aCodeList04 = new Genericode04CodeListMarshaller ().read (aFile); if (aCodeList04 != null) _createGenericode04 (aFile, aCodeList04); else throw new IllegalStateException ("Failed to read codelist file " + aFile); } new JCMWriter (s_aCodeModel).build (new File ("src/main/java")); }
Example #12
Source File: MainCreateEnumsGenericode22.java From ph-ubl with Apache License 2.0 | 5 votes |
public static void main (final String [] args) throws JCodeModelException, IOException { for (final File aFile : new FileSystemRecursiveIterator (new File ("src/main/resources/codelists")).withFilter (IFileFilter.filenameEndsWith (".gc"))) { final CodeListDocument aCodeList10 = new Genericode10CodeListMarshaller ().read (aFile); if (aCodeList10 != null) _createGenericode10 (aFile, aCodeList10); } new JCMWriter (s_aCodeModel).build (new File ("src/main/java")); }
Example #13
Source File: MainCreateJAXBBinding23.java From ph-ubl with Apache License 2.0 | 5 votes |
@Nonnull private static Iterable <File> _getFileList (final String sPath) { return CollectionHelper.getSorted (new FileSystemIterator (sPath).withFilter (IFileFilter.filenameEndsWith (".xsd")) .withFilter (IFileFilter.filenameMatchNoRegEx ("^CCTS.*", ".*xmldsig.*", ".*XAdES.*")), Comparator.comparing (File::getName)); }
Example #14
Source File: AbstractFuncTestCSSReader.java From ph-css with Apache License 2.0 | 4 votes |
protected final void testReadGood (@Nonnull final String sBaseDir) { final File aBaseDir = new File (sBaseDir); if (!aBaseDir.exists ()) throw new IllegalArgumentException ("BaseDir " + sBaseDir + " does not exist!"); for (final File aFile : new FileSystemRecursiveIterator (aBaseDir).withFilter (IFileFilter.filenameEndsWith (".css"))) { final String sKey = aFile.getAbsolutePath (); if (m_bDebug) m_aLogger.info ("Filename: " + sKey); final CollectingCSSParseErrorHandler aErrorHdl = new CollectingCSSParseErrorHandler (); m_aReaderSettings.setCustomErrorHandler (aErrorHdl.and (new LoggingCSSParseErrorHandler ())); final CascadingStyleSheet aCSS = CSSReader.readFromFile (aFile, m_aReaderSettings); assertNotNull (sKey, aCSS); // May have errors or not if (m_bDebug) m_aLogger.info ("Parse errors: " + aErrorHdl.getAllParseErrors ().toString ()); CommonsTestHelper.testDefaultSerialization (aCSS); // Write optimized version and compare it String sCSS = new CSSWriter (m_aWriterSettings.setOptimizedOutput (true)).getCSSAsString (aCSS); assertNotNull (sKey, sCSS); if (m_bDebug) m_aLogger.info ("Created CSS: " + sCSS); final CascadingStyleSheet aCSSReRead = CSSReader.readFromStringReader (sCSS, m_aReaderSettings); assertNotNull ("Failed to parse " + sKey + ":\n" + sCSS, aCSSReRead); assertEquals (sKey + "\n" + sCSS, aCSS, aCSSReRead); // Write non-optimized version and compare it sCSS = new CSSWriter (m_aWriterSettings.setOptimizedOutput (false)).getCSSAsString (aCSS); assertNotNull (sKey, sCSS); if (m_bDebug) m_aLogger.info ("Read and re-created CSS: " + sCSS); assertEquals (sKey, aCSS, CSSReader.readFromStringReader (sCSS, m_aReaderSettings)); // Write non-optimized and code-removed version and ensure it is not // null sCSS = new CSSWriter (m_aWriterSettings.setOptimizedOutput (false) .setRemoveUnnecessaryCode (true)).getCSSAsString (aCSS); assertNotNull (sKey, sCSS); assertNotNull (sKey, CSSReader.readFromStringReader (sCSS, m_aReaderSettings)); // Restore value :) m_aWriterSettings.setRemoveUnnecessaryCode (false); } }
Example #15
Source File: MainCreateJAXBBinding21.java From ph-ubl with Apache License 2.0 | 4 votes |
@Nonnull private static Iterable <File> _getFileList (final String sPath) { return CollectionHelper.getSorted (new FileSystemIterator (sPath).withFilter (IFileFilter.filenameEndsWith (".xsd")), Comparator.comparing (File::getName)); }
Example #16
Source File: MainCreateJAXBBinding20.java From ph-ubl with Apache License 2.0 | 4 votes |
@Nonnull private static Iterable <File> _getFileList (final String sPath) { return CollectionHelper.getSorted (new FileSystemIterator (sPath).withFilter (IFileFilter.filenameEndsWith (".xsd")), Comparator.comparing (File::getName)); }