Class FileTool
java.lang.Object
java.util.Observable
com.nomagic.magicreport.engine.Tool
com.nomagic.magicreport.engine.ConcurrentTool
com.nomagic.magicreport.engine.tools.FileTool
- All Implemented Interfaces:
ITool,IVariable,Serializable,Cloneable
- Direct Known Subclasses:
ReportFileTool
This class enables to generate output report file in the template file.
- Since:
- Jul 2, 2007
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.nomagic.magicreport.engine.ConcurrentTool
ConcurrentTool.ConsumeObjectNested classes/interfaces inherited from interface com.nomagic.magicreport.engine.ITool
ITool.HTMLString, ITool.RetainedString, ITool.Void -
Field Summary
FieldsFields inherited from class com.nomagic.magicreport.engine.Tool
context, properties -
Constructor Summary
ConstructorsConstructorDescriptionFileTool(ITemplateEngine engine) Create a file tool with default global engine. -
Method Summary
Modifier and TypeMethodDescriptioncomputeName(String directory, String name) Create pathname string from given directory, name.computeName(String directory, String name, String fileType) Create pathname string from given directory, name, and file type.voidconsume(ConcurrentTool.ConsumeObject consumeObject) Consumes this object so that it will be processed in the default manner.Copy an input file to output file with the same name in binary format.protected StringCopy an input file to output file in binary format.Copy an input file to output file in binary format.Copy an input file to output file with the same name in binary format.Copy an input file to output file in binary format.A shortcut to create file which output filename is same as a name of template file and no import context object.protected StringGenerate the report output by using the template file.A shortcut to create file which output filename is same as a name of template file.Generate the report output from given template file.protected StringGenerate the report output by using the template file.A shortcut to create file which output filename is template name and no import context object.A shortcut to create file which output filename is template name.Generate the report output from given template name.Deprecated.protected Stringcreate(String templateDir, String templateFileName, String outputDir, String outputFileName, Object importedObject) Generate the report output by using the template file.createAndWait(File templateFile) Invoke a new template engine to generate a report and return the path to output file.protected StringInvoke a new template engine to generate a report and return the path to output file.createAndWait(File templateFile, Object contextValue) Invoke a new template engine to generate a report and return the path to output file.createAndWait(File templateFile, String outputFileName, Object contextValue) Invoke a new template engine to generate a report and return the path to output file.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.Invoke a new template engine to generate a report and return the path to output file.createAndWait(File templateFile, Map<String, Object> context) Invoke a new template engine to generate a report and return the path to output file.createAndWait(String templateFileName) Invoke a new template engine to generate a report and return the path to output file.createAndWait(String templateFileName, Object contextValue) Invoke a new template engine to generate a report and return the path to output file.createAndWait(String templateFileName, String outputFileName, Object contextValue) Invoke a new template engine to generate a report and return the path to output file.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.Invoke a new template engine to generate a report and return the path to output file.createAndWait(String templateFileName, Map<String, Object> context) Invoke a new template engine to generate a report and return the path to output file.protected voidCreate directorybooleanTests whether the file denoted bypathnameexists.protected StringgetResultPath(String resultFromProcess, String originalPath) Get result path.protected booleanCheck null object or empty string.protected StringresolveOutputFileName(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'silentCreate(File templateFile) A shortcut to create file which output filename is same as a name of input template file and no import context object.silentCreate(File templateFile, Object importObject) A shortcut to create file which output filename is same as a name of input template file.silentCreate(File templateFile, String outputFileName, Object importObject) Generate the report output from given template file.silentCreate(String template) A shortcut to create file which output filename is template name and no import context object.silentCreate(String template, Object importObject) A shortcut to create file which output filename is template name.silentCreate(String template, String outputFileName, Object importObject) Generate the report output from given template name.silentCreate(String templateType, String template, String outputname, Object importObject) Deprecated.Methods inherited from class com.nomagic.magicreport.engine.ConcurrentTool
destroy, getCustomPoolSize, isNoSpaceException, isRunning, offerMethods inherited from class com.nomagic.magicreport.engine.Tool
clone, getContext, getProperties, getProperty, getProperty, notifyObservers, setContext, setPropertiesMethods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, setChanged
-
Field Details
-
CONTEXT_NAME
Contains a context name.- See Also:
-
-
Constructor Details
-
FileTool
Create a file tool with default global engine.- Parameters:
engine- default global engine
-
-
Method Details
-
silentCreate
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
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
A shortcut to create file which output filename is template name.
For example:$file.silentCreate('overview.html','')
IfimportObjectis an instance ofjava.util.Map, key-value of Map will be used as name-value of context.- Parameters:
template- the input template nameimportObject- 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
A shortcut to create file which output filename is same as a name of input template file.
For example:$file.silentCreate($iFile,'')
IfimportObjectis an instance ofjava.util.Map, key-value of Map will be used as name-value of context.- Parameters:
templateFile- the input template fileimportObject- 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','')
IfimportObjectis an instance ofjava.util.Map, key-value of Map will be used as name-value of context.- Parameters:
template- the input template nameoutputFileName- the output file nameimportObject- 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','')
IfimportObjectis an instance ofjava.util.Map, key-value of Map will be used as name-value of context.- Parameters:
templateFile- the input template fileoutputFileName- the output file nameimportObject- 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 Deprecated.Generate the report output from given template name.
For example:$file.silentCreate('html','overview','overview','')
IfimportObjectis an instance ofjava.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 extensionoutputname- 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
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
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
A shortcut to create file which output filename is template name.
For example:<a href="$file.create('overview.html','')">overview.html</a>
IfimportObjectis an instance ofjava.util.Map, key-value of Map will be used as name-value of context.- Parameters:
template- the input template nameimportObject- 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
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>
IfimportObjectis an instance ofjava.util.Map, key-value of Map will be used as name-value of context.- Parameters:
templateFile- the input template fileimportObject- 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>
IfimportObjectis an instance ofjava.util.Map, key-value of Map will be used as name-value of context.- Parameters:
templateFileName- the input template file nameoutputFileName- the output file nameimportObject- 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>
IfimportObjectis an instance ofjava.util.Map, key-value of Map will be used as name-value of context.- Parameters:
templateFile- the input template fileoutputFileName- the output file nameimportObject- 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 Deprecated.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 extensionoutputname- 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
Consumes this object so that it will be processed in the default manner.- Specified by:
consumein classConcurrentTool- Parameters:
consumeObject- consume object- See Also:
-
copy
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
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
-
copy
Copy an input file to output file in binary format.
For example:<img src="$file.copy('icon.gif','icon.gif')">- Parameters:
inputFileName- the input filenameoutputFileName- the output filename- Returns:
- the output pathname. It will return empty string, if there is any error.
-
copy
Copy an input file to output file in binary format.
For example:<img src="$file.copy($iconFile,'icon.gif')">- Parameters:
inputFile- the input fileoutputFileName- the output filename- Returns:
- the output pathname. It will return empty string, if there is any error.
-
copy
Copy an input file to output file in binary format.
For example:<img src="$file.copy($iIcon, $oIcon)">- Parameters:
inputFile- the input fileoutputFile- the output file- Returns:
- the output pathname. It will return empty string, if there is any error.
-
exists
Tests whether the file denoted bypathnameexists. 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:
trueif and only if the file or directory denoted by this name exists;falseotherwise
-
computeName
Create pathname string from given directory, name.- Parameters:
directory- a parent directory of filename- a name of file (exclude extension)- Returns:
- pathname from given directory, name.
-
computeName
Create pathname string from given directory, name, and file type.- Parameters:
directory- a parent directory of filename- a name of file (exclude extension)fileType- type of file. e.g. rtf, txt, html- Returns:
- pathname string to filename
-
createAndWait
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
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
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
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
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
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
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
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
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
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
Check null object or empty string.- Parameters:
obj- object to check- Returns:
- true if specific object is null or empty string.
-
getResultPath
Get result path. If result is empty, return original path- Parameters:
resultFromProcess- path from processoriginalPath- specific output file name- Returns:
- result path
-
createDir
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 nameoutputFileName- original output file nametemplateFile- real template file- Returns:
- outputFileName
-
create(String, String, Object)