Class FileTool

All Implemented Interfaces:
ITool, IVariable, Serializable, Cloneable
Direct Known Subclasses:
ReportFileTool

@OpenApiAll public class FileTool extends ConcurrentTool
This class enables to generate output report file in the template file.
Since:
Jul 2, 2007
See Also:
  • Field Details

  • Constructor Details

    • FileTool

      public FileTool(ITemplateEngine engine)
      Create a file tool with default global engine.
      Parameters:
      engine - default global engine
  • Method Details

    • silentCreate

      public ITool.Void silentCreate(String template) throws ParseErrorException
      A shortcut to create file which output filename is template name and no import context object.

      For example:

      
          $file.silentCreate('overview.html')
       
      Parameters:
      template - the input template name
      Returns:
      void
      Throws:
      ParseErrorException - when template has a syntax or other error which prevents it from being parsed.
    • silentCreate

      public ITool.Void silentCreate(File templateFile) throws ParseErrorException
      A shortcut to create file which output filename is same as a name of input template file and no import context object.
      For example:
      
          $file.silentCreate($iFile)
       
      Parameters:
      templateFile - the input template file
      Returns:
      void
      Throws:
      ParseErrorException - when template has a syntax or other error which prevents it from being parsed.
    • silentCreate

      public ITool.Void silentCreate(String template, Object importObject) throws ParseErrorException
      A shortcut to create file which output filename is template name.
      For example:
      
          $file.silentCreate('overview.html','')
       

      If importObject is an instance of java.util.Map, key-value of Map will be used as name-value of context.
      Parameters:
      template - the input template name
      importObject - the object reference, which will be DefaultElement in the template file. You can use DefaultElement variable in the template file for getting the data.
      Returns:
      void
      Throws:
      ParseErrorException - when template has a syntax or other error which prevents it from being parsed.
    • silentCreate

      public ITool.Void silentCreate(File templateFile, Object importObject) throws ParseErrorException
      A shortcut to create file which output filename is same as a name of input template file.
      For example:
      
          $file.silentCreate($iFile,'')
       

      If importObject is an instance of java.util.Map, key-value of Map will be used as name-value of context.
      Parameters:
      templateFile - the input template file
      importObject - the object reference, which will be DefaultElement in the template file. You can use DefaultElement variable in the template file for getting the data.
      Returns:
      void
      Throws:
      ParseErrorException - when template has a syntax or other error which prevents it from being parsed.
    • silentCreate

      public ITool.Void silentCreate(String template, String outputFileName, Object importObject) throws ParseErrorException
      Generate the report output from given template name.
      For example:
      
          $file.silentCreate('overview.html','overview.html','')
       

      If importObject is an instance of java.util.Map, key-value of Map will be used as name-value of context.
      Parameters:
      template - the input template name
      outputFileName - the output file name
      importObject - the object reference, which will be DefaultElement in the template file. You can use DefaultElement variable in the template file for getting the data.
      Returns:
      void
      Throws:
      ParseErrorException - when template has a syntax or other error which prevents it from being parsed.
    • silentCreate

      public ITool.Void silentCreate(File templateFile, String outputFileName, Object importObject) throws ParseErrorException
      Generate the report output from given template file.
      For example:
      
          $file.silentCreate($iFile,'overview.html','')
       

      If importObject is an instance of java.util.Map, key-value of Map will be used as name-value of context.
      Parameters:
      templateFile - the input template file
      outputFileName - the output file name
      importObject - the object reference, which will be DefaultElement in the template file. You can use DefaultElement variable in the template file for getting the data.
      Returns:
      void
      Throws:
      ParseErrorException - when template has a syntax or other error which prevents it from being parsed.
    • silentCreate

      @Deprecated public ITool.Void silentCreate(String templateType, String template, String outputname, Object importObject) throws ParseErrorException
      Generate the report output from given template name.
      For example:
      
          $file.silentCreate('html','overview','overview','')
       

      If importObject is an instance of java.util.Map, key-value of Map will be used as name-value of context.
      Parameters:
      templateType - the template type such rtf, html, htm.
      template - the input pathname string without extension
      outputname - the output file name, not include any extension.
      importObject - the object reference, which will be DefaultElement in the template file. You can use DefaultElement variable in the template file for getting the data.
      Returns:
      void
      Throws:
      ParseErrorException - when template has a syntax or other error which prevents it from being parsed.
    • create

      public String create(String template) throws ParseErrorException
      A shortcut to create file which output filename is template name and no import context object.
      For example:
      
          <a href="$file.create('overview.html')">overview.html</a>
       
      Parameters:
      template - the input template name
      Returns:
      the output pathname. It will return empty string, if there is any error.
      Throws:
      ParseErrorException - when template has a syntax or other error which prevents it from being parsed.
    • create

      public String create(File templateFile) throws ParseErrorException
      A shortcut to create file which output filename is same as a name of template file and no import context object.
      For example:
      
          <a href="$file.create($aFile)">overview.html</a>
       
      Parameters:
      templateFile - the input template file
      Returns:
      the output pathname. It will return empty string, if there is any error.
      Throws:
      ParseErrorException - when template has a syntax or other error which prevents it from being parsed.
    • create

      public String create(String template, Object importObject) throws ParseErrorException
      A shortcut to create file which output filename is template name.
      For example:
      
          <a href="$file.create('overview.html','')">overview.html</a>
       

      If importObject is an instance of java.util.Map, key-value of Map will be used as name-value of context.
      Parameters:
      template - the input template name
      importObject - the object reference, which will be DefaultElement in the template file. You can use DefaultElement variable in the template file for getting the data.
      Returns:
      the output pathname. It will return empty string, if there is any error.
      Throws:
      ParseErrorException - when template has a syntax or other error which prevents it from being parsed.
    • create

      public String create(File templateFile, Object importObject) throws ParseErrorException
      A shortcut to create file which output filename is same as a name of template file.
      For example:
      
          <a href="$file.create($iFile,'')">overview.html</a>
       

      If importObject is an instance of java.util.Map, key-value of Map will be used as name-value of context.
      Parameters:
      templateFile - the input template file
      importObject - the object reference, which will be DefaultElement in the template file. You can use DefaultElement variable in the template file for getting the data.
      Returns:
      the output pathname. It will return empty string, if there is any error.
      Throws:
      ParseErrorException - when template has a syntax or other error which prevents it from being parsed.
    • create

      public String create(String templateFileName, String outputFileName, Object importObject) throws ParseErrorException
      Generate the report output from given template name.
      For example:
      
          <a href="$file.create('overview.html','overview.html','')">overview.html</a>
       

      If importObject is an instance of java.util.Map, key-value of Map will be used as name-value of context.
      Parameters:
      templateFileName - the input template file name
      outputFileName - the output file name
      importObject - the object reference, which will be DefaultElement in the template file. You can use DefaultElement variable in the template file for getting the data.
      Returns:
      the output pathname. It will return empty string, if there is any error.
      Throws:
      ParseErrorException - when template has a syntax or other error which prevents it from being parsed.
    • create

      public String create(File templateFile, String outputFileName, Object importObject) throws ParseErrorException
      Generate the report output from given template file.
      For example:
      
          <a href="$file.create($iFile,'overview.html','')">overview.html</a>
       

      If importObject is an instance of java.util.Map, key-value of Map will be used as name-value of context.
      Parameters:
      templateFile - the input template file
      outputFileName - the output file name
      importObject - the object reference, which will be DefaultElement in the template file. You can use DefaultElement variable in the template file for getting the data.
      Returns:
      the output pathname. It will return empty string, if there is any error.
      Throws:
      ParseErrorException - when template has a syntax or other error which prevents it from being parsed.
    • create

      @Deprecated public String create(String templateType, String template, String outputname, Object importObject) throws ParseErrorException
      Generate the report output from given template name.
      For example:
      
          <a href="$file.create('html','overview','overview','')">overview.html</a>
       
      Parameters:
      templateType - the template type such rtf, html, htm.
      template - the input pathname string without extension
      outputname - the output file name, not include any extension.
      importObject - the object reference, which will be DefaultElement in the template file. You can use DefaultElement variable in the template file for getting the data.
      Returns:
      the output pathname. It will return empty string, if there is any error.
      Throws:
      ParseErrorException - when template has a syntax or other error which prevents it from being parsed.
    • create

      protected String create(String templateDir, String templateFileName, String outputDir, String outputFileName, Object importedObject) throws ParseErrorException
      Generate the report output by using the template file.
      Parameters:
      templateDir - the directory of the template.
      templateFileName - the template file name.
      outputDir - the directory of the output report.
      outputFileName - the output file name, not include any extension.
      importedObject - the object reference, which will be DefaultElement in the template file. You can use DefaultElement variable in the template file for getting the data.
      Returns:
      the output pathname. It will return empty string, if there is any error.
      Throws:
      ParseErrorException - when template has a syntax or other error which prevents it from being parsed.
    • create

      protected String create(File templateFile, String outputDir, String outputFileName, Object importedObject) throws ParseErrorException
      Generate the report output by using the template file.
      Parameters:
      templateFile - the template file.
      outputDir - the directory of the output report.
      outputFileName - the output file name, not include any extension.
      importedObject - the object reference, which will be DefaultElement in the template file. You can use DefaultElement variable in the template file for getting the data.
      Returns:
      the output pathname. It will return empty string, if there is any error.
      Throws:
      ParseErrorException - when template has a syntax or other error which prevents it from being parsed.
    • create

      protected String create(File templateFile, File outputFile, Object importedObject) throws ParseErrorException
      Generate the report output by using the template file.
      Parameters:
      templateFile - the template file.
      outputFile - the output file.
      importedObject - the object reference, which will be DefaultElement in the template file. You can use DefaultElement variable in the template file for getting the data.
      Returns:
      the output pathname. It will return empty string, if there is any error.
      Throws:
      ParseErrorException - when template has a syntax or other error which prevents it from being parsed.
    • consume

      public void consume(ConcurrentTool.ConsumeObject consumeObject)
      Consumes this object so that it will be processed in the default manner.
      Specified by:
      consume in class ConcurrentTool
      Parameters:
      consumeObject - consume object
      See Also:
    • copy

      public String copy(String inputFileName)
      Copy an input file to output file with the same name in binary format.
      For example:
      
          <img src="$file.copy('icon.gif')">
       
      Parameters:
      inputFileName - the input filename
      Returns:
      the output pathname. It will return empty string, if there is any error.
    • copy

      public String copy(File inputFile)
      Copy an input file to output file with the same name in binary format.
      For example:
      
          <img src="$file.copy($iFile)">
       
      Parameters:
      inputFile - the input file
      Returns:
      the output pathname. It will return empty string, if there is any error.
    • copy

      public List<String> copy(Map<String,String> fileMap)
    • copy

      public String copy(String inputFileName, String outputFileName)
      Copy an input file to output file in binary format.
      For example:
      
         <img src="$file.copy('icon.gif','icon.gif')">
       
      Parameters:
      inputFileName - the input filename
      outputFileName - the output filename
      Returns:
      the output pathname. It will return empty string, if there is any error.
    • copy

      public String copy(File inputFile, String outputFileName)
      Copy an input file to output file in binary format.
      For example:
      
         <img src="$file.copy($iconFile,'icon.gif')">
       
      Parameters:
      inputFile - the input file
      outputFileName - the output filename
      Returns:
      the output pathname. It will return empty string, if there is any error.
    • copy

      protected String copy(File inputFile, File outputFile)
      Copy an input file to output file in binary format.
      For example:
      
         <img src="$file.copy($iIcon, $oIcon)">
       
      Parameters:
      inputFile - the input file
      outputFile - the output file
      Returns:
      the output pathname. It will return empty string, if there is any error.
    • exists

      public boolean exists(String pathname)
      Tests whether the file denoted by pathname exists. By default, current directory will be referred to template location.
      For example:
      
              $file.exists("$template.resourcesLocation/myimage.png")
              $file.exists("C:/myfolder/myimage.png")
              $file.exists("mytemplate.txt")
       
      Parameters:
      pathname - A pathname string
      Returns:
      true if and only if the file or directory denoted by this name exists; false otherwise
    • computeName

      public String computeName(String directory, String name)
      Create pathname string from given directory, name.
      Parameters:
      directory - a parent directory of file
      name - a name of file (exclude extension)
      Returns:
      pathname from given directory, name.
    • computeName

      public String computeName(String directory, String name, String fileType)
      Create pathname string from given directory, name, and file type.
      Parameters:
      directory - a parent directory of file
      name - a name of file (exclude extension)
      fileType - type of file. e.g. rtf, txt, html
      Returns:
      pathname string to filename
    • createAndWait

      public String createAndWait(String templateFileName)
      Invoke a new template engine to generate a report and return the path to output file. The output report will be named by template file name.
      Parameters:
      templateFileName - an input template file name.
      Returns:
      an absolute path to output file.
    • createAndWait

      public String createAndWait(File templateFile)
      Invoke a new template engine to generate a report and return the path to output file. The output report will be named by template file name.
      Parameters:
      templateFile - an input template file.
      Returns:
      an absolute path to output file.
    • createAndWait

      public String createAndWait(String templateFileName, Object contextValue)
      Invoke a new template engine to generate a report and return the path to output file. The output report will be named by template file name.
      Parameters:
      templateFileName - an input template file name.
      contextValue - additional object adding to new template context with default $importer name.
      Returns:
      an absolute path to output file.
    • createAndWait

      public String createAndWait(File templateFile, Object contextValue)
      Invoke a new template engine to generate a report and return the path to output file. The output report will be named by template file name.
      Parameters:
      templateFile - an input template file name.
      contextValue - additional object adding to new template context with default $importer name.
      Returns:
      an absolute path to output file.
    • createAndWait

      public String createAndWait(String templateFileName, String outputFileName, Object contextValue)
      Invoke a new template engine to generate a report and return the path to output file.

      "importer" will be used as a name of context value.

      Parameters:
      templateFileName - an input template file name.
      outputFileName - an output report file name.
      contextValue - additional object adding to new template context with default $importer name.
      Returns:
      an absolute path to output file.
    • createAndWait

      public String createAndWait(File templateFile, String outputFileName, Object contextValue)
      Invoke a new template engine to generate a report and return the path to output file.

      "importer" will be used as a name of context value.

      Parameters:
      templateFile - an input template file.
      outputFileName - an output report file name.
      contextValue - additional object adding to new template context with default $importer name.
      Returns:
      an absolute path to output file.
    • createAndWait

      public String createAndWait(String templateFileName, String outputFileName, String contextName, Object contextValue)
      Invoke a new template engine to generate a report and return the path to output file.
      Parameters:
      templateFileName - an input template file name.
      outputFileName - an output report file name.
      contextName - adding object context's name.
      contextValue - additional object adding to new template context.
      Returns:
      an absolute path to output file.
    • createAndWait

      public String createAndWait(File templateFile, String outputFileName, String contextName, Object contextValue)
      Invoke a new template engine to generate a report and return the path to output file.
      Parameters:
      templateFile - an input template file.
      outputFileName - an output report file name.
      contextName - adding object context's name.
      contextValue - additional object adding to new template context.
      Returns:
      an absolute path to output file.
    • createAndWait

      public String createAndWait(String templateFileName, Map<String,Object> context)
      Invoke a new template engine to generate a report and return the path to output file. The output report will be named by template file name.
      Parameters:
      templateFileName - an input template file name.
      context - additional context adding to new template.
      Returns:
      an absolute path to output file.
    • createAndWait

      public String createAndWait(File templateFile, Map<String,Object> context)
      Invoke a new template engine to generate a report and return the path to output file. The output report will be named by template file name.
      Parameters:
      templateFile - an input template file.
      context - additional context adding to new template.
      Returns:
      an absolute path to output file.
    • createAndWait

      public String createAndWait(String templateFileName, String outputFileName, Map<String,Object> context)
      Invoke a new template engine to generate a report and return the path to output file.
      Parameters:
      templateFileName - an input template file name.
      outputFileName - an output report file name.
      context - additional context adding to new template.
      Returns:
      an absolute path to output file.
    • createAndWait

      public String createAndWait(File templateFile, String outputFileName, Map<String,Object> context)
      Invoke a new template engine to generate a report and return the path to output file.
      Parameters:
      templateFile - an input template file.
      outputFileName - an output report file name.
      context - additional context adding to new template.
      Returns:
      an absolute path to output file.
    • createAndWait

      protected String createAndWait(File templateFile, File outputFile, Map<String,Object> context)
      Invoke a new template engine to generate a report and return the path to output file.
      Parameters:
      templateFile - an input template file.
      outputFile - an output report file.
      context - additional context adding to new template.
      Returns:
      an absolute path to output file.
    • isEmpty

      protected boolean isEmpty(Object obj)
      Check null object or empty string.
      Parameters:
      obj - object to check
      Returns:
      true if specific object is null or empty string.
    • getResultPath

      protected String getResultPath(String resultFromProcess, String originalPath)
      Get result path. If result is empty, return original path
      Parameters:
      resultFromProcess - path from process
      originalPath - specific output file name
      Returns:
      result path
    • createDir

      protected void createDir(File outputDirectory)
      Create directory
      Parameters:
      outputDirectory - directory path
    • resolveOutputFileName

      protected String resolveOutputFileName(String templateFileName, String outputFileName, File templateFile)
      Sometime the name of real template file is not match to original template file name.
      In case user does not specify output file name, we cannot assign the templateFileName to be outputFileName without checking.
      e.g., templateFileName = "mdp://attachedFile#_1234"
      templateFile = C://tmp//test.docx
      So, outputFileName should be 'test.docx' not 'mdp://attachedFile#_1234'
      Parameters:
      templateFileName - original template file name
      outputFileName - original output file name
      templateFile - real template file
      Returns:
      outputFileName