Java Wrapper Summary Report
    • PDF

    Java Wrapper Summary Report

    • PDF

    Article summary

    The Java wrapper has additional functionality that can generate a summary report from a given set of analysis reports. The summary report provides an easy to see overview of the work that was carried out on the file. It contains the following items:

    • The filename of the file that was processed.
    • The process message from the GW2FileSessionStatus API.
    • The last error message from GW2FileErrorMsg API, if the file was non-conforming.
    • Additional information that contains a list of sanitised or allowed items with their respective counts. For example, 5 instances of Metadata that have been sanitised.

    The summary report has a flag for skipping unsupported file types. When this is set to true then unsupported file types will have the EngineOutcome set to Unsupported with the LastErrorMessage set to Skipping unsupported filetype.

    Summary Report example

    <?xml version="1.0" encoding="UTF-8"?>
    <ContentGroups>
      <!-- Example of a conforming file -->
      <ContentGroup>
        <AdditionalInformation>
          <AllowedItems>
            <AllowedItem InstanceCount="3">External Hyperlinks</AllowedItem>
            <AllowedItem InstanceCount="2">Metadata</AllowedItem>
          </AllowedItems>
          <SanitisationItems>
            <SanitisationItem InstanceCount="25">Embedded File</SanitisationItem>
          </SanitisationItems>
        </AdditionalInformation>
        <FileName>/home/glasswall/Documents/Example.doc</FileName>
        <ProcessMessage>Remedies Applied</ProcessMessage>
        <EngineOutcome>Managed</EngineOutcome>
        <LastErrorMessage/>
      </ContentGroup>
      <!-- Example of a non-conforming file -->
      <ContentGroup>
        <AdditionalInformation>
          <AllowedItems>
            <AllowedItem InstanceCount="22">Metadata</AllowedItem>
          </AllowedItems>
        </AdditionalInformation>
        <FileName>/home/glasswall/Documents/Example2.docx</FileName>
        <ProcessMessage>Issues Found</ProcessMessage>
        <EngineOutcome>Non-conforming</EngineOutcome>
        <LastErrorMessage>End of stream 'xl/workbook.xml' not reached</LastErrorMessage>
      </ContentGroup>
      <!-- Example of an unsupported file type when the skip unsupported file types flag is set to true -->
      <ContentGroup>
        <AdditionalInformation/>
        <FileName>/home/glasswall/Documents/UnsupportedFileType.cat</FileName>
        <ProcessMessage/>
        <EngineOutcome>Unsupported</EngineOutcome>
        <LastErrorMessage>Skipping unsupported filetype</LastErrorMessage>
      </ContentGroup>
      <!-- Example of an unsupported file type when the skip unsupported file types flag is set to false -->
      <ContentGroup>
        <AdditionalInformation/>
        <FileName>/home/glasswall/Documents/UnsupportedFileType.cat</FileName>
        <ProcessMessage>Issues Found</ProcessMessage>
        <EngineOutcome>Non-conforming</EngineOutcome>
        <LastErrorMessage>Unable to determine file type</LastErrorMessage>
      </ContentGroup>
    </ContentGroups>
    

    API

    Constructors

    SummaryReport() throws ParserConfigurationException, DOMException
    SummaryReport(boolean skipUnsupportedFileTypes) throws ParserConfigurationException, DOMException
    

    Parameters:

    • boolean skipUnsupportedFileTypes - This sets the skip unsupported file types flag. If this flag is not specified then the skip unsupported file types will be set to false.

    Instance Methods

    void setSkipUnsupportedFileTypes(boolean skipUnsupportedFileTypes)
    

    Setter for the skip unsupported file types flag.

    Parameters:

    • boolean skipUnsupportedFileTypes - This sets the skip unsupported file types flag.

    boolean getSkipUnsupportedFileTypes()
    

    Getter for the skip unsupported file types flag.

    Returns:
    true if unsupported file types should be skipped, and false otherwise.


    void addAnalysisReport(
            Path inputFilePath,
            int sessionStatus,
            String lastErrorMessage,
            String processMessage,
            InputStream analysisInputStream
        ) throws SAXException, ParserConfigurationException, IOException
    

    Add a new Glasswall analysis report to the summary report.

    Parameters:

    • Path inputFilePath - The file path of the file that was processed.
    • int sessionStatus - The return status from GW2RunSession.
    • String lastErrorMessage - The error message from GW2FileErrorMsg. If this is null or empty then it won't be included in the summary report.
    • String processMessage - The process message from GW2FileSessionStatus. If this null or empty then it won't be included in the summary report.
    • InputStream analysisInputStream - Input stream containing the analysis report to be included.

    public void generateSummaryReport(Writer writer) throws TransformerConfigurationException, TransformerException
    

    Generate a summary report from the provided analysis reports.

    Parameters:

    • Writer writer - A writer where the summary report will be written to.

    API Example

    The summary report functionality is implemented in com.glasswall.analysissummary.SummaryReport class. First an instance of the class is created, addAnalysisReport is then called for each analysis report that will be included in the summary report, and then generateSummaryReport is called at the end to generate the summary report. An example can be seen below:

    File input_directory = new File("Input");
    File output_directory = new File("Output");
    
    output_directory.mkdirs();
    
    SummaryReport summary_report = new SummaryReport();
    summary_report.setSkipUnsupportedFileTypes(true); // Optionally set the skip unsupported file types flag
    
    for (File file : input_directory.listFiles())
    {
        if (file.isDirectory())
            continue;
    
        try (Core2JavaBridge gw = new Core2JavaBridge())
        {
            // Create the output path for file and analysis report
            String file_output_path = Paths.get(output_directory.getAbsolutePath().toString(), file.getName()).toString();
            String analysis_output_path = file_output_path + ".xml";
    
            // Run the file through Glasswall
            int session = gw.GW2OpenSession();
            gw.GW2RegisterInputFile(session, file.getAbsolutePath());
            gw.GW2RegisterAnalysisFile(session, analysis_output_path, 0);
            gw.GW2RegisterOutFile(session, file_output_path);
            int run_status = gw.GW2RunSession(session);
    
            // Retrieve the error message if the file is non-conforming
            String error_message = null;
    
            if (run_status < 0)
                error_message = gw.GW2FileErrorMsgString(session);
    
            // Retrieve the session status along with the session description
            FileSessionStatus session_status = gw.GW2FileSessionStatusResult(session);
    
            // Add the analysis report to the summary report
            try (FileInputStream stream = new FileInputStream(analysis_output_path))
            {
                summary_report.addAnalysisReport(file.toPath(), run_status, error_message, session_status.summaryDescription, stream);
            }
        }
        catch (Exception ex)
        {
            System.err.println("Exception occurred: " + ex.getMessage());
        }
    }
    
    // Write the summary report to `SummaryReport.xml` file
    try (BufferedWriter writer = Files.newBufferedWriter(
            Paths.get(output_directory.getAbsolutePath().toString(), "SummaryReport.xml"), 
            StandardCharsets.UTF_8, 
            StandardOpenOption.TRUNCATE_EXISTING, 
            StandardOpenOption.CREATE, 
            StandardOpenOption.WRITE))
    {
        summary_report.generateSummaryReport(writer);
    }
    

    Was this article helpful?