You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-dev@xmlgraphics.apache.org by "Vera Straube (JIRA)" <ji...@apache.org> on 2019/04/10 14:30:00 UTC

[jira] [Updated] (FOP-2857) FontCache.toDirectory and FontCache.getDefaultCacheFile working not correct

     [ https://issues.apache.org/jira/browse/FOP-2857?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Vera Straube updated FOP-2857:
------------------------------
    Summary: FontCache.toDirectory and FontCache.getDefaultCacheFile working not correct  (was: FontCache.toDirectory(String path) returns a file object that is not a directory)

> FontCache.toDirectory and FontCache.getDefaultCacheFile working not correct
> ---------------------------------------------------------------------------
>
>                 Key: FOP-2857
>                 URL: https://issues.apache.org/jira/browse/FOP-2857
>             Project: FOP
>          Issue Type: Bug
>          Components: font/unqualified
>    Affects Versions: 2.3
>            Reporter: Vera Straube
>            Priority: Critical
>
> {code:java}
> //correct code
> /** FOP's user directory name */
>    private static final String FOP_USER_DIR = ".fop";
>    
>    /** font cache file path */
>    private static final String DEFAULT_CACHE_FILENAME = "fop-fonts.cache";
>    
>    /** complete path to user directory*/
>    public static String getUserDir(){
>       return System.getProperty("user.home");
>    }
>    
>    /** complete path to FOP's user directory*/
>    public static String getFopUserDir(){
>       return getUserDir() + System.getProperty("file.separator") + FOP_USER_DIR;
>    }
>    
>    /** complete path to temp directory*/
>    public static String getTempDir(){
>       return System.getProperty("java.io.tmpdir");
>    }
>    
>    /** complete path to FOP's temp directory*/
>    public static String getFopTempDir(){
>       return getTempDir() + System.getProperty("file.separator") + FOP_USER_DIR;
>    }
>    
>    /**
>    * returns the file object of the existing directory or null
>    *
>    * @param path
>    *           complete path to the directory
>    * @param forWriting
>    *           true if the directory should be created if it not exists
>    * @return the file object of the existing directory or null
>    */
>    public static File toDirectory(String path, boolean forWriting)
>    {
>       File result = null;
>       if (path != null && !path.trim().isEmpty()) {
>          File tmp = new File(path);
>          if( tmp.exists() ){
>             result = tmp;
>          }else{
>             if(forWriting){
>                if( tmp.mkdirs() ){
>                   result = tmp;
>                }
>             }
>          }
>       }
>       return result;
>    }
>    
>    /**
>    * Returns the default font cache file.
>    *
>    * @param forWriting
>    *            true if the user directory should be created if it not exists
>    * @return the default font cache file
>    */
>    public static File getDefaultCacheFile(boolean forWriting) {
>       File result = new File(DEFAULT_CACHE_FILENAME);
>       File userHome = toDirectory(getUserDir(),false);
>       if(userHome!=null){
>          File fopUserDir = toDirectory(getFopUserDir(),forWriting);
>          if(fopUserDir!=null){
>             result = new File(fopUserDir,DEFAULT_CACHE_FILENAME);
>          }else{
>             File fopTempDir = toDirectory(getFopTempDir(),forWriting);
>             if(fopTempDir!=null){
>                result = new File(fopTempDir,DEFAULT_CACHE_FILENAME);
>             }
>          }
>       }
>       return result;
>    }
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)