Package org.jbake.app

Class FileUtil


  • public class FileUtil
    extends java.lang.Object
    Provides File related functions
    • Field Detail

      • URI_SEPARATOR_CHAR

        public static final java.lang.String URI_SEPARATOR_CHAR
        See Also:
        Constant Field Values
    • Constructor Detail

      • FileUtil

        public FileUtil()
    • Method Detail

      • getFileFilter

        public static java.io.FileFilter getFileFilter​(JBakeConfiguration config)
        Filters files based on their file extension.
        Parameters:
        config - the jbake configuration
        Returns:
        Object for filtering files
      • getFileFilter

        @Deprecated
        public static java.io.FileFilter getFileFilter()
        Deprecated.
        Filters files based on their file extension.
        Returns:
        Object for filtering files
      • getDataFileFilter

        public static java.io.FileFilter getDataFileFilter()
        Filters files based on their file extension - only find data files (i.e. files with .yaml or .yml extension)
        Returns:
        Object for filtering files
      • getNotContentFileFilter

        public static java.io.FileFilter getNotContentFileFilter​(JBakeConfiguration config)
        Gets the list of files that are not content files based on their extension.
        Parameters:
        config - the jbake configuration
        Returns:
        FileFilter object
      • getNotContentFileFilter

        @Deprecated
        public static java.io.FileFilter getNotContentFileFilter()
        Gets the list of files that are not content files based on their extension.
        Returns:
        FileFilter object
      • directoryOnlyIfNotIgnored

        public static boolean directoryOnlyIfNotIgnored​(java.io.File file,
                                                        JBakeConfiguration config)
        Ignores directory (and children) if it contains a file named in the configuration as a marker to ignore the directory.
        Parameters:
        file - the file to test
        config - the jbake configuration
        Returns:
        true if file is directory and not ignored
      • directoryOnlyIfNotIgnored

        @Deprecated
        public static boolean directoryOnlyIfNotIgnored​(java.io.File file)
        Ignores directory (and children) if it contains a file named ".jbakeignore".
        Parameters:
        file - the file to test
        Returns:
        true if file is directory and not ignored
      • isExistingFolder

        public static boolean isExistingFolder​(java.io.File f)
      • getRunningLocation

        public static java.io.File getRunningLocation()
                                               throws java.lang.Exception
        Works out the folder where JBake is running from.
        Returns:
        File referencing folder JBake is running from
        Throws:
        java.lang.Exception - when application is not able to work out where is JBake running from
      • fileExt

        public static java.lang.String fileExt​(java.io.File src)
      • fileExt

        public static java.lang.String fileExt​(java.lang.String name)
      • sha1

        public static java.lang.String sha1​(java.io.File sourceFile)
                                     throws java.lang.Exception
        Computes the hash of a file or directory.
        Parameters:
        sourceFile - the original file or directory
        Returns:
        an hex string representing the SHA1 hash of the file or directory.
        Throws:
        java.lang.Exception - if any IOException of SecurityException occured
      • asPath

        public static java.lang.String asPath​(java.io.File file)
        platform independent file.getPath()
        Parameters:
        file - the file to transform, or null
        Returns:
        The result of file.getPath() with all path Separators beeing a "/", or null Needed to transform Windows path separators into slashes.
      • asPath

        public static java.lang.String asPath​(java.lang.String path)
        platform independent file.getPath()
        Parameters:
        path - the path to transform, or null
        Returns:
        The result will have all platform path separators replaced by "/".
      • getPathToRoot

        public static java.lang.String getPathToRoot​(JBakeConfiguration config,
                                                     java.io.File rootPath,
                                                     java.io.File sourceFile)
        Given a file inside content it return the relative path to get to the root.

        Example: /content and /content/tags/blog will return '../..'

        Parameters:
        sourceFile - the file to calculate relative path for
        rootPath - the root path
        config - the jbake configuration
        Returns:
        the relative path to get to the root
      • getUriPathToDestinationRoot

        public static java.lang.String getUriPathToDestinationRoot​(JBakeConfiguration config,
                                                                   java.io.File sourceFile)
      • getUriPathToContentRoot

        public static java.lang.String getUriPathToContentRoot​(JBakeConfiguration config,
                                                               java.io.File sourceFile)
      • isFileInDirectory

        public static boolean isFileInDirectory​(java.io.File file,
                                                java.io.File directory)
                                         throws java.io.IOException
        Utility method to determine if a given file is located somewhere in the directory provided.
        Parameters:
        file - used to check if it is located in the provided directory.
        directory - to validate whether or not the provided file resides.
        Returns:
        true if the file is somewhere in the provided directory, false if it is not.
        Throws:
        java.io.IOException - if the canonical path for either of the input directories can't be determined.