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:33: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:
------------------------------
    Description: 
{code:java}
// wrong 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";
    
    private static File getUserHome() {
        return toDirectory(System.getProperty("user.home"));
    }

    private static File getTempDirectory() {
        return toDirectory(System.getProperty("java.io.tmpdir"));
    }

    private static File toDirectory(String path) {
        if (path != null) {
            File dir = new File(path);
            if (dir.exists()) {
                return dir;
            }
        }
        return null;
    }
    
    /**
     * Returns the default font cache file.
     *
     * @param forWriting
     *            true if the user directory should be created
     * @return the default font cache file
     */
    public static File getDefaultCacheFile(boolean forWriting) {
        File userHome = getUserHome();
        if (userHome != null) {
            File fopUserDir = new File(userHome, FOP_USER_DIR);
            if (forWriting) {
                boolean writable = fopUserDir.canWrite();
                if (!fopUserDir.exists()) {
                    writable = fopUserDir.mkdir();
                }
                if (!writable) {
                    userHome = getTempDirectory();
                    fopUserDir = new File(userHome, FOP_USER_DIR);
                    fopUserDir.mkdir();
                }
            }
            return new File(fopUserDir, DEFAULT_CACHE_FILENAME);
        }
        return new File(FOP_USER_DIR);
    }
{code}


{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}



  was:

{code:java}
// wrong 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";
    
    private static File getUserHome() {
        return toDirectory(System.getProperty("user.home"));
    }

    private static File getTempDirectory() {
        return toDirectory(System.getProperty("java.io.tmpdir"));
    }

    private static File toDirectory(String path) {
        if (path != null) {
            File dir = new File(path);
            if (dir.exists()) {
                return dir;
            }
        }
        return null;
    }
    
    /**
     * Returns the default font cache file.
     *
     * @param forWriting
     *            true if the user directory should be created
     * @return the default font cache file
     */
    public static File getDefaultCacheFile(boolean forWriting) {
        File userHome = getUserHome();
        if (userHome != null) {
            File fopUserDir = new File(userHome, FOP_USER_DIR);
            if (forWriting) {
                boolean writable = fopUserDir.canWrite();
                if (!fopUserDir.exists()) {
                    writable = fopUserDir.mkdir();
                }
                if (!writable) {
                    userHome = getTempDirectory();
                    fopUserDir = new File(userHome, FOP_USER_DIR);
                    fopUserDir.mkdir();
                }
            }
            return new File(fopUserDir, DEFAULT_CACHE_FILENAME);
        }
        return new File(FOP_USER_DIR);
    }
{code}


{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}



        Summary: FontCache.toDirectory() and FontCache.getDefaultCacheFile() working not correct  (was: FontCache.toDirectory and FontCache.getDefaultCacheFile working not correct)

> 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}
> // wrong 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";
>     
>     private static File getUserHome() {
>         return toDirectory(System.getProperty("user.home"));
>     }
>     private static File getTempDirectory() {
>         return toDirectory(System.getProperty("java.io.tmpdir"));
>     }
>     private static File toDirectory(String path) {
>         if (path != null) {
>             File dir = new File(path);
>             if (dir.exists()) {
>                 return dir;
>             }
>         }
>         return null;
>     }
>     
>     /**
>      * Returns the default font cache file.
>      *
>      * @param forWriting
>      *            true if the user directory should be created
>      * @return the default font cache file
>      */
>     public static File getDefaultCacheFile(boolean forWriting) {
>         File userHome = getUserHome();
>         if (userHome != null) {
>             File fopUserDir = new File(userHome, FOP_USER_DIR);
>             if (forWriting) {
>                 boolean writable = fopUserDir.canWrite();
>                 if (!fopUserDir.exists()) {
>                     writable = fopUserDir.mkdir();
>                 }
>                 if (!writable) {
>                     userHome = getTempDirectory();
>                     fopUserDir = new File(userHome, FOP_USER_DIR);
>                     fopUserDir.mkdir();
>                 }
>             }
>             return new File(fopUserDir, DEFAULT_CACHE_FILENAME);
>         }
>         return new File(FOP_USER_DIR);
>     }
> {code}
> {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)