Class TemplateHelper

java.lang.Object
com.nomagic.magicdraw.magicreport.helper.TemplateHelper

@OpenApiAll public class TemplateHelper extends Object
Provide helper methods for template such as create and save.
Since:
May 10, 2007
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Constants for Default DOCBOOK type.
    static final String
     
    static final String
    Constants for DOCBOOK type.
    static final String
    Constants for DOCX type.
    static final String
    Constants for HTML type.
    static final org.apache.logging.log4j.Logger
     
    static final String
    Constants for ODP type.
    static final String
    Constants for ODS type.
    static final String
    Constants for ODT type.
    static final String
    Constants for PPTX type.
    static final String
     
    static final String
    Delete property name.
    static final String
    Reload property name.
    static final String
    Save property name.
    static final String
    Constants for RTF type.
    static final String
    Constants for template extension.
    static final String
    Constants for TXT type.
    static final String
    Constants for XLSX type.
    static final String
    Constants for XML type.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Register a listener for the PropertyChange event.
    static boolean
    checkEdition(com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean bean, com.nomagic.magicdraw.lic.MDVersion version)
    Return true if this template is valid to MDVersion.
    static String
    checkRequiredPlugins(com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean bean)
     
    static void
     
    static File
    createTemplateFile(com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean templateBean)
    Create a directory or file from given template bean.
    static File
    createTemplateFile(String templateName)
    Create a directory or file from given template name.
    static Icon
    createTemplateIcon(com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean templateBean)
    Create and return icon for this template bean.
    static void
    exportZip(File zipFile, com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean templateBean)
    Export template bean to zip file with default progress status.
    static void
    exportZip(File zipFile, com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean templateBean, ProgressStatus progress)
    Export template bean to zip file.
    static void
    exportZip(File zipFile, com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean templateBean, ProgressStatus progress, List<File> includedFiles)
    Export template bean to zip file.
    static boolean
    extractZip(File zipFile, File destinationDir, ProgressStatus progress)
     
    static com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean
    findTemplateBean(String catName, String templName)
    Get the templateBean by given category name and template name.
    static void
    Fire an existing PropertyChangeEvent to any registered listeners.
    static void
    firePropertyChange(Object source, String propertyName, Object oldValue, Object newValue)
    Report a bound property update to any registered listeners.
    static Set<File>
    Get custom location that store template.
    static String
    getDefaultReportKey(com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean templateBean)
    Return a key for default report preference.
     
    static String
    getOutputReportKey(com.nomagic.magicdraw.magicreport.ui.bean.ReportBean reportBean)
    Return a key for output report preference.
    static com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean
    Return existing template bean from the template path.
    static com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean
    getTemplateBeanByName(String catName, String templateName)
    Get template bean by category name and template name
    static File
    getTemplateFile(com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean templateBean)
     
    static File
    getTemplateFile(com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean templateBean, boolean revolveDir)
     
    static String
    Consider template type from file extension.
    static String
    getViewerReportKey(com.nomagic.magicdraw.magicreport.ui.bean.ReportBean reportBean)
    Return a key for viewer report preference.
    static com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean
    importZip(File zipFile, boolean copyToData)
    Import zip file to template bean.
    static com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean
    importZip(File zipFile, boolean copyToData, ProgressStatus progress)
    Import zip file to template bean.
    static boolean
    isFileExternal(File file, com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean templateBean)
     
    static List<com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean>
    listAvailableTemplates(com.nomagic.magicdraw.lic.MDVersion version, com.nomagic.magicdraw.usermodes.UserMode userMode)
    Return a list of available template to MDVersion and Perspective.
    static void
    Load and Unzip MRZip template file from template directory.
    static List<com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean>
    This method will automatically load all template file from "data" directory of report plugin and return a List of TemplateBean.
    static List<com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean>
    listTemplates(boolean forceReload)
    Load all template files from report plugin "data" directory and return to List of TemplateBean.
    static com.nomagic.magicdraw.magicreport.ui.bean.ReportBean
    loadReport(File reportFile)
    Create a ReportBean from given reportFile.
    static void
    loadReportDataAndConfig(File templateDir, com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean templateBean)
     
    static com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean
    loadTemplate(File templateFile)
    Create a TemplateBean from given templateFile.
    static com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean
    loadTemplate(File templateFile, boolean checkValid)
    Create a TemplateBean from given templateFile.
    static void
    loadTemplateBean(com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean templateBean, Document document)
     
    static com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean
     
    static com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean
    reloadTemplate(com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean templateBean)
    Force the application to remove this template from cache and then reload it from file.
    static void
    removeImportHistory(File[] importedMrzipFiles)
     
    static void
    Remove a listener for the PropertyChange event.
    static void
    removeTemplate(com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean templateBean)
    Delete a template file from physical storage.
    static void
    saveReport(com.nomagic.magicdraw.magicreport.ui.bean.ReportBean reportBean)
    Create a new report file from ReportBean.
    static void
    saveReport(com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean templateBean, com.nomagic.magicdraw.magicreport.ui.bean.ReportBean reportBean)
    Create a new report file from ReportBean.
    static void
    saveTemplate(com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean templateBean)
    Create a new template file from TemplateBean.
    static void
    Unzip MRZip Templates files.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • TemplateHelper

      public TemplateHelper()
  • Method Details

    • listTemplates

      public static List<com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean> listTemplates()
      This method will automatically load all template file from "data" directory of report plugin and return a List of TemplateBean. TemplateBean is a container of template information.
      Returns:
      a List of TemplateBean from "data" directory.
      Throws:
      AccessControlException - when unable to locate and create directory for data
      See Also:
    • listAvailableTemplates

      public static List<com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean> listAvailableTemplates(@CheckForNull com.nomagic.magicdraw.lic.MDVersion version, @CheckForNull com.nomagic.magicdraw.usermodes.UserMode userMode)
      Return a list of available template to MDVersion and Perspective.
      Parameters:
      version - MDVersion
      userMode - UserMode
      Returns:
      a list of available template after filter out
      See Also:
    • checkEdition

      public static boolean checkEdition(com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean bean, @CheckForNull com.nomagic.magicdraw.lic.MDVersion version)
      Return true if this template is valid to MDVersion.
      Parameters:
      version - MDVersion
      Returns:
      true if this template is valid to given MDVersion; otherwise false.
    • checkRequiredPlugins

      public static String checkRequiredPlugins(com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean bean)
      Returns:
      empty string if all required plugins are ok. Otherwise, a multiline info message for each missing/outdated plugin
    • addPropertyChangeListener

      public static void addPropertyChangeListener(PropertyChangeListener listener)
      Register a listener for the PropertyChange event. When a Template changes its value it should fire a PropertyChange event on all registered PropertyChangeListeners.
      Parameters:
      listener - An object to be invoked when a PropertyChange event is fired.
    • removePropertyChangeListener

      public static void removePropertyChangeListener(PropertyChangeListener listener)
      Remove a listener for the PropertyChange event.
      Parameters:
      listener - The PropertyChange listener to be removed.
    • firePropertyChange

      public static void firePropertyChange(Object source, String propertyName, @CheckForNull Object oldValue, Object newValue)
      Report a bound property update to any registered listeners. No event is fired if old and new are equal and non-null.
      Parameters:
      source - property source
      propertyName - The programmatic name of the property that was changed.
      oldValue - The old value of the property.
      newValue - The new value of the property.
    • firePropertyChange

      public static void firePropertyChange(PropertyChangeEvent evt)
      Fire an existing PropertyChangeEvent to any registered listeners. No event is fired if the given event's old and new values are equal and non-null.
      Parameters:
      evt - The PropertyChangeEvent object.
    • listTemplates

      public static List<com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean> listTemplates(boolean forceReload)
      Load all template files from report plugin "data" directory and return to List of TemplateBean.
      Parameters:
      forceReload - true if you want this method to reload template from disk; false use template from cache.
      Returns:
      a List of TemplateBean from "data" directory.
      Throws:
      AccessControlException - when unable to locate and create directory for data
      See Also:
    • listMRZipTemplates

      public static void listMRZipTemplates()
      Load and Unzip MRZip template file from template directory.
    • unzipMRZipTemplates

      public static void unzipMRZipTemplates(File[] mrZipFile)
      Unzip MRZip Templates files.
      Parameters:
      mrZipFile - file
    • removeImportHistory

      public static void removeImportHistory(File[] importedMrzipFiles)
    • reloadTemplate

      public static com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean reloadTemplate(com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean templateBean)
      Force the application to remove this template from cache and then reload it from file.
      Parameters:
      templateBean - a target template
      Returns:
      TemplateBean or null if invalid template file format.
    • getTemplateBean

      public static com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean getTemplateBean(String path)
      Return existing template bean from the template path.
      Parameters:
      path - path of template TemplateBean.getPath()
      Returns:
      the TemplateBean
    • getTemplateBeanByName

      public static com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean getTemplateBeanByName(String catName, String templateName)
      Get template bean by category name and template name
      Parameters:
      catName - template category name
      templateName - template name
      Returns:
      template bean
    • loadTemplate

      public static com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean loadTemplate(File templateFile)
      Create a TemplateBean from given templateFile. If template file is not valid template format, return null.
      Parameters:
      templateFile - a File for template
      Returns:
      TemplateBean or null if invalid template file format.
    • loadTemplate

      @CheckForNull public static com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean loadTemplate(File templateFile, boolean checkValid) throws com.nomagic.magicreport.TemplateException
      Create a TemplateBean from given templateFile. If template file is not valid template format, return null.
      Parameters:
      templateFile - a File for template
      checkValid - true if this template file require format checking
      Returns:
      TemplateBean or null if invalid template file format.
      Throws:
      com.nomagic.magicreport.TemplateException - if the template file is not valid format and check parameter is true.
    • loadReportDataAndConfig

      public static void loadReportDataAndConfig(File templateDir, com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean templateBean)
    • importZip

      public static com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean importZip(File zipFile, boolean copyToData) throws IOException
      Import zip file to template bean.
      Parameters:
      zipFile - an input zip file.
      copyToData - copy template to data folder after successfully extract.
      Returns:
      templateBean a template bean
      Throws:
      IOException - when unable to import zip file.
      See Also:
    • importZip

      @CheckForNull public static com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean importZip(File zipFile, boolean copyToData, ProgressStatus progress) throws IOException
      Import zip file to template bean.
      Parameters:
      zipFile - an input zip file.
      copyToData - copy template to data folder after successfully extract.
      progress - the progress status
      Returns:
      templateBean a template bean
      Throws:
      IOException - when unable to import zip file.
      See Also:
    • extractZip

      public static boolean extractZip(File zipFile, File destinationDir, ProgressStatus progress) throws IOException
      Throws:
      IOException
    • exportZip

      public static void exportZip(File zipFile, com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean templateBean) throws IOException
      Export template bean to zip file with default progress status.
      Parameters:
      zipFile - a output zip file.
      templateBean - a template bean
      Throws:
      IOException - when unable to export zip file.
      See Also:
    • exportZip

      public static void exportZip(File zipFile, com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean templateBean, ProgressStatus progress) throws IOException
      Export template bean to zip file.
      Parameters:
      zipFile - a output zip file.
      templateBean - a template bean
      progress - the progress status
      Throws:
      IOException - when unable to export zip file.
      See Also:
    • exportZip

      public static void exportZip(File zipFile, com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean templateBean, ProgressStatus progress, List<File> includedFiles) throws IOException
      Export template bean to zip file.
      Parameters:
      zipFile - a output zip file.
      templateBean - a template bean
      progress - the progress status
      includedFiles - other files to be included in this zip
      Throws:
      IOException - when unable to export zip file.
      See Also:
    • isFileExternal

      public static boolean isFileExternal(File file, com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean templateBean)
      Parameters:
      templateBean -
      file - to check
      Returns:
      true if checked file resides outside the template package
    • getTemplateFile

      public static File getTemplateFile(com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean templateBean)
    • getTemplateFile

      public static File getTemplateFile(com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean templateBean, boolean revolveDir)
    • loadReport

      public static com.nomagic.magicdraw.magicreport.ui.bean.ReportBean loadReport(File reportFile)
      Create a ReportBean from given reportFile. If report file is not valid report format, return null.
      Parameters:
      reportFile - a File for report
      Returns:
      ReportBean or null if invalid report file format.
    • saveTemplate

      public static void saveTemplate(com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean templateBean) throws IOException
      Create a new template file from TemplateBean. If TemplateBean.getPath() exists, write a template file to this value; if value doesn't exists create a new file with TemplateBean.getName() as template filename.
      Parameters:
      templateBean - a Template Bean
      Throws:
      IOException - if the template was not successfully created
    • loadTemplateBean

      public static com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean loadTemplateBean(File file) throws IOException
      Throws:
      IOException
    • loadTemplateBean

      public static void loadTemplateBean(com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean templateBean, Document document) throws IOException
      Throws:
      IOException
    • saveReport

      public static void saveReport(com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean templateBean, com.nomagic.magicdraw.magicreport.ui.bean.ReportBean reportBean) throws IOException
      Create a new report file from ReportBean. If ReportBean.getFileName() exists, write a report file to this value; if value doesn't exists create a new file with TemplateBean.getName() as template filename.
      Parameters:
      templateBean - a TemplateBean
      reportBean - a ReportBean
      Throws:
      IOException - if the template was not successfully created
    • saveReport

      public static void saveReport(com.nomagic.magicdraw.magicreport.ui.bean.ReportBean reportBean) throws IOException
      Create a new report file from ReportBean. If ReportBean.getFileName() exists, write a report file to this value; if value doesn't exists throw IOException.
      Parameters:
      reportBean - a ReportBean
      Throws:
      IOException - if the report was not successfully created
    • removeTemplate

      public static void removeTemplate(com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean templateBean) throws IOException
      Delete a template file from physical storage. Physical storage meaning that template file will not be able to recovery after successfully deleted.
      Parameters:
      templateBean - a Template Bean
      Throws:
      IOException - if the template was not successfully deleted
    • createTemplateFile

      public static File createTemplateFile(com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean templateBean) throws IOException
      Create a directory or file from given template bean. This method use template name as a directory name.
      Parameters:
      templateBean - a template bean
      Returns:
      File references to template bean
      Throws:
      IOException - if false to create directory.
    • createTemplateFile

      public static File createTemplateFile(String templateName) throws IOException
      Create a directory or file from given template name.
      Parameters:
      templateName - a template name
      Returns:
      File references to template bean
      Throws:
      IOException - if false to create directory.
    • findTemplateBean

      public static com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean findTemplateBean(@CheckForNull String catName, String templName)
      Get the templateBean by given category name and template name.
      Parameters:
      catName - categoryName or null
      templName - the template name
      Returns:
      the TemplateBean
    • getTemplateType

      public static String getTemplateType(String extension)
      Consider template type from file extension.
      Parameters:
      extension - a file extension.
      Returns:
      a template type.
    • createTemplateIcon

      public static Icon createTemplateIcon(com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean templateBean)
      Create and return icon for this template bean.
      Parameters:
      templateBean - a template bean
      Returns:
      template icon
    • getIconByFileExtension

      public static ResizableIcon getIconByFileExtension(String ext)
    • getDefaultReportKey

      public static String getDefaultReportKey(com.nomagic.magicdraw.magicreport.ui.bean.TemplateBean templateBean) throws IllegalArgumentException
      Return a key for default report preference. A key is a concatenation of #hashCode() and ";default".
      Parameters:
      templateBean - a template bean
      Returns:
      a key.
      Throws:
      IllegalArgumentException - illegal argument is used.
    • getOutputReportKey

      public static String getOutputReportKey(com.nomagic.magicdraw.magicreport.ui.bean.ReportBean reportBean) throws IllegalArgumentException
      Return a key for output report preference. A key is a concatenation of {@link ReportBean#getModel()#getID()} and ";output" or {@link ReportBean#getFileName()#hashCode()} + ";output".
      Parameters:
      reportBean - a report bean
      Returns:
      a key.
      Throws:
      IllegalArgumentException - illegal argument is used.
    • getViewerReportKey

      public static String getViewerReportKey(com.nomagic.magicdraw.magicreport.ui.bean.ReportBean reportBean) throws IllegalArgumentException
      Return a key for viewer report preference. A key is a concatenation of {@link ReportBean#getModel()#getID()} and ";viewer" or {@link ReportBean#getFileName()#hashCode()} + ";viewer".
      Parameters:
      reportBean - a report bean
      Returns:
      a key.
      Throws:
      IllegalArgumentException - illegal argument is used.
    • getCustomTemplateLocations

      public static Set<File> getCustomTemplateLocations()
      Get custom location that store template.
      Returns:
      list of custom location
    • clearCachedElements

      public static void clearCachedElements()