Class ReportWriter

java.lang.Object
ca.spatial.reportwriter.ReportWriter
All Implemented Interfaces:
EditableTableModel, Comparator<Report>, EventListener, TreeModelListener, TableModel
Direct Known Subclasses:
ComparisonWriter

public class ReportWriter extends Object implements Comparator<Report>, TreeModelListener, EditableTableModel
A class providing the framework for a report writer. The ReportWriter provides supporting methods for cataloging, retrieving and generating reports. Initially the report catalog is empty. Reports are added using the addReport method. Some reports include java applets to display histogram data. In previous version of the report writer these applets would be included by default. Applet support requires Java, and this can sometimes be a problem for some viewers. In order to prevent viewing problems Java applet support is now disabled by default. To reenable applets within reports include the following code in the Patchworks_Init section of the PIN file:
 reportWriter.addDefaultParam("chart.applet", "true");
 
Author:
Tom Moore
See Also:
Report
  • Constructor Details

    • ReportWriter

      public ReportWriter(String label, PatchServer server)
      Create an empty ReportWriter
      Parameters:
      label - the name of this report container
      server - the server that this ReportWriter will be embedded in to
  • Method Details

    • getServer

      public PatchServer getServer()
      Get the http server object
    • getDocBase

      public String getDocBase()
      Get the document base for this report writer
    • addKnownReport

      public void addKnownReport(String name, ReportConfigurator rc)
    • addBasicKnownReports

      public void addBasicKnownReports()
    • addAnalysisKnownReports

      public void addAnalysisKnownReports()
    • getKnownReports

      public HashMap<String,​LabeledObject> getKnownReports()
      Get a map of all of the known report templates in this ReportWriter. The templates can be used to instantiate new reports.
    • addSupportFile

      public void addSupportFile(String filename, boolean autoload)
      Add a support file to the ReportWriter. This file will be automatically copied in to the 'html' scenario folder and can be used in any of the reports. For example, a logo image can be added to the 'html' folder and then refered to by the reports.

      If you add css or js files then the report writer can add the required links so that file will be loaded with the reports after the base css and js files have been loaded. Specify the autoload parameter to be true for this feature. The autoload parameter will be ignored if the file is not a css or js file.

      The support files will be referenced from their original locations when you are viewing reports from within Patchworks. If you make a change to the file the change will show up the next time you view the report.

      When you save a scenario the custom files will be copied in to the scenario folder, and will no longer reference the original files. Even if the original file is deleted, the copy in the html folder will still remain.

      Parameters:
      filename - the name of the file to use
      autoload - for css and js files, indicate if links should be generated in the report header to automatically load the file. If set to false then the files will be copied to the html folder but they will not be automatically referenced from the reports.
    • getSupportFiles

      public Map<String,​ReportWriter.SupportFile> getSupportFiles()
    • pad

      public static String pad(String st, int size, boolean rightJustify)
      Pad a string with blank characters. The extra spacing may be added to the right or left end of the string.
      Parameters:
      st - The input string
      size - The requested width of the output string
      rightJustify - A flag to indicate how the input string should be justified within the output. If true then right justify.
    • getLength

      public long getLength(String reportName, Map<String,​Object> param)
    • setDefaultParams

      public static void setDefaultParams(String[][] param)
      Set a list of parameters that will be used as a default on all reports. These defaults will be over ridden by defaults that are specfied on individual reports.

      The parameters influence the display of the report or of the chart. The default parameters are merged with parameters that are provided on the query string with the report URL. The parameters on the URL will over ride the default parameters.

      Very few reports support parameters, but this mechanism will be used in future to support some form of report customization. See the Report class description for documenation of commonly used parameters. See the Parameter notes in the class description of each individual report for report-specific parameters.

      Parameters:
      param - The list of name/value pairs of default parameters.
    • addDefaultParam

      public static void addDefaultParam(String key, Object value)
      Add a parameter pair to the default list
    • getDefaultParam

      public static Object getDefaultParam(String key)
    • doReport

      public void doReport(String reportName, String filename)
      Generate a report and sent the output to the named file.
      Parameters:
      reportName - The file name of the report (including the extension).
      filename - The name of the file to store the report in
    • doReport

      public Object doReport(String reportName, String filename, Map<String,​Object> param, Object cache)
      Generate a report and sent the output to the named file.
      Parameters:
      reportName - The file name of the report (including the extension).
      filename - The name of the file to store the report in
      param - A hashmap containing report parameters
      cache - An object holding cached repor results. In most cases this should be a null value.
    • doReport

      public Object doReport(String reportName, PrintStream out, Map<String,​Object> param, Object cache)
      Invoke a report and sent the output to the open stream.
      Parameters:
      reportName - The name of the report (including the extension).
      out - A stream to contain the output
      param - A hashmap containing report parameters.
      cache - An object holding cached report results. In most cases this should be a null value.
    • doAllReports

      public void doAllReports(Frame owner, String directory, String stage)
      Output all known reports into the specified directory
      Parameters:
      directory - A directory to contain the reports
      stage - A scenario name used to label the report
    • updateReports

      public void updateReports(String scenario, String regex)
      This method will update just the reports whose filenames are matched by the regular expression. None of the other files will be altered. The checksum file will not be updated, so the updated reports will show as being modified.
      Parameters:
      scenario - The name of the scenario folder
      regex - A regular expression that identifies the files to be saved.
    • saveStage

      public void saveStage(Frame owner, String directory)
      Save all reports to a named directory. The stage name label on the reports will be taken from the final component of the directory path.
      Parameters:
      directory - The name of the directory to contain the reports
    • saveStage

      public void saveStage(String directory)
    • saveStage

      public void saveStage(Frame owner, File directory)
      Save all reports to a named directory. The stage name label on the reports will be taken from the final component of the directory path.
      Parameters:
      directory - A File pointing to the directory to contain the reports
    • saveStage

      public void saveStage(Frame owner, File directory, String stage)
      Save all reports to a named directory.
      Parameters:
      directory - A File pointing to the directory to contain the reports
      stage - A scenario name used to label the report
    • saveStage

      public void saveStage(Frame owner)
      Save all reports to a named directory. A FileChooser will be used to obtain a directory path. The stage name label on the reports will be taken from the final component of the directory path.
    • saveReport

      public void saveReport(String report, String scenarioFolder)
      Explicitly save out a report Call this for name of the report that you want to save. All parts of the report will be saved automatically (e.g. PNG, CSV, HTML). E.g. saveReport("landscape/index.html", "scenarios/GCF_landscapeGuide_5");
    • saveFolder

      public void saveFolder(String folder, String scenarioFolder)
      Save out the contents of a folder, plus the index files that point to it.
       reportWriter.saveFolder("indicators/mapReports", "Scenario_6");
       
      Parameters:
      folder - The folder that the reports are stored in within the report writer.
      scenarioFolder - The name of the top-level folder on disk to save the reports into.
    • getReportList

      public HashMap<String,​Report> getReportList()
      Retrieve a hashmap listing all documents visible to this report writer.
    • knownReport

      public Report knownReport(String reportName)
      Test if a document is known by the reportWriter.
      Parameters:
      reportName - The name of the report in question.
    • containsReport

      public boolean containsReport(Report r)
      Test if this reportWriter container contains the report object.
    • addReport

      public Report addReport(Report r)
      Add a report definition to the ReportWriter catalog.
      Parameters:
      r - The report to be added
    • addHiddenReport

      public void addHiddenReport(Report r)
      Add a report definition that will not be exposed to the ReportWriter catalog.
      Parameters:
      r - The report to be added
    • removeReport

      public void removeReport(String filename)
      Remove a report from the ReportWriter. If the report is an IndexReport then all reports in that folder will also be removed.

      Parameters:
      filename - The filename of the report to remove. This should be the same name as was used to add the report.
    • getReports

      public Map<String,​Report> getReports()
      Get the reports hashtable
    • getHiddenReports

      public Map<String,​Report> getHiddenReports()
    • getHandlers

      public ArrayList<Report> getHandlers()
      Get the default handlers
    • getReportTree

      public PathTree getReportTree()
      Get the reports hashtable
    • compare

      public int compare(Report o1, Report o2)
      Comparator interface to sort dhandler names in order of decreasing length of name.
      Specified by:
      compare in interface Comparator<Report>
    • treeNodesChanged

      public void treeNodesChanged(TreeModelEvent e)
      Specified by:
      treeNodesChanged in interface TreeModelListener
    • treeNodesInserted

      public void treeNodesInserted(TreeModelEvent e)
      Specified by:
      treeNodesInserted in interface TreeModelListener
    • treeNodesRemoved

      public void treeNodesRemoved(TreeModelEvent e)
      Specified by:
      treeNodesRemoved in interface TreeModelListener
    • treeStructureChanged

      public void treeStructureChanged(TreeModelEvent e)
      Specified by:
      treeStructureChanged in interface TreeModelListener
    • updateNode

      public void updateNode(Report r)
    • buildList

      public static Vector<LabeledObject> buildList(String file, Component parent)
      Build a list of directories to search. The list will include all sub-folders of the current analysis folder that contain the specified file, plus the current scenario.
      Parameters:
      file - The name of a file that must be contained in the sub-folders in order for them to be included in the comparison list.
      parent - A reference to the parent window component. This value may be null, in which case the search starts in the current analysis folder. If the value is non-null, the method will display a file chooser to locate another directory to be used to start the search.
      Returns:
      A list of folders that meet the criteria. Note that a new list object is created each time this method is invoked.
    • addComparisonKnownReports

      public void addComparisonKnownReports(ReportWriter rw)
    • adjustList

      public void adjustList(Window parent)
    • addCurrent

      public void addCurrent()
      Add the local HTTP server to the internal list
    • addCurrent

      public static void addCurrent(Vector<LabeledObject> list)
      Add the local HTTP server to the specified list
    • addPath

      public void addPath(String name, String pathname)
      Add a scneario folder to the internal list of comparison folders.
      Parameters:
      name - The label name for this scenario.
      pathname - The path to the scenario folder.
    • addPath

      public static void addPath(Vector<LabeledObject> list, String name, String pathname)
      Add a scenario folder to the specified list of comparison folders.
      Parameters:
      list - The list to change.
      name - The label name for this scenario.
      pathname - The path to the scenario folder.
    • addPath

      public void addPath(String name, File path)
      Add a scenario folder to the list of comparison folders.
      Parameters:
      name - The label name for this scenario.
      path - A file object representing the scenario folder.
    • addPath

      public static void addPath(Vector<LabeledObject> fileList, String name, File path)
      Add a scenario folder to the specified list of comparison folders.
      Parameters:
      fileList - The list to change.
      name - The label name for this scenario.
      path - The path to the scenario folder.
    • clearPaths

      public void clearPaths()
      Clear all paths from the list of comparison folders.
    • clearPaths

      public void clearPaths(Vector fileList)
      Clear all paths from the specified list.
    • getFileList

      public Vector getFileList()
      Get the list of comparison folders.
    • addTableModelListener

      public void addTableModelListener(TableModelListener l)
      Specified by:
      addTableModelListener in interface TableModel
    • getColumnClass

      public Class getColumnClass(int columnIndex)
      Specified by:
      getColumnClass in interface TableModel
    • getColumnCount

      public int getColumnCount()
      Specified by:
      getColumnCount in interface TableModel
    • getColumnName

      public String getColumnName(int columnIndex)
      Specified by:
      getColumnName in interface TableModel
    • getRowCount

      public int getRowCount()
      Specified by:
      getRowCount in interface TableModel
    • getValueAt

      public Object getValueAt(int rowIndex, int columnIndex)
      Specified by:
      getValueAt in interface TableModel
    • isCellEditable

      public boolean isCellEditable(int rowIndex, int columnIndex)
      Specified by:
      isCellEditable in interface TableModel
    • removeTableModelListener

      public void removeTableModelListener(TableModelListener l)
      Specified by:
      removeTableModelListener in interface TableModel
    • setValueAt

      public void setValueAt(Object aValue, int rowIndex, int columnIndex)
      Specified by:
      setValueAt in interface TableModel
    • addRow

      public void addRow(Component parent)
      Description copied from interface: EditableTableModel
      Add a row to the table using default values. Optionally provide a reference to the parent window in case a dialog needs to be shown.
      Specified by:
      addRow in interface EditableTableModel
    • addRow

      public void addRow(Object[] rowData)
      Description copied from interface: EditableTableModel
      Add a row to the table. The number of items in the rowData array must match the number of columns in the table.
      Specified by:
      addRow in interface EditableTableModel
    • removeRow

      public void removeRow(int row)
      Description copied from interface: EditableTableModel
      Remove the row specified by the row number.
      Specified by:
      removeRow in interface EditableTableModel
    • moveRow

      public void moveRow(int from, int to)
      Description copied from interface: EditableTableModel
      Move the specified row to a new location
      Specified by:
      moveRow in interface EditableTableModel