Summary - Standalone
The standalone file summary can be generated by creating a com.glasswall.analysissummary.FileSummary
object.
API
Constructors
public FileSummary(
Path inputFilePath,
int sessionStatus,
String lastErrorMessage,
String processMessage,
InputStream analysisInputStream,
boolean skipUnsupportedFileTypes
) throws SAXException, ParserConfigurationException, IOException
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.String processMessage
- The process message from GW2FileSessionStatus. If this null or empty then it won't be included in the summary.InputStream analysisInputStream
- Input stream containing the analysis report to be included.boolean skipUnsupportedFileTypes
- boolean indicating whether unsupported file types should be skipped.
Instance Methods
public String getFileName()
Returns the filename of the processed file.
Returns:
The absolute file path of the processed file.
public String getProcessMessage()
Returns the file session process message. This will be null if the process message was not specified.
Returns:
File session process message.
public EngineOutcome getEngineOutcome()
Returns an EngineOutcome
enum indicating whether the processed file was Managed
, NonConforming
, or Unsupported
.
Returns:
An EngineOutcome
enum.
public String getErrorMessage()
Returns the error message if the file is non-conforming. This will be null if the file is managed.
Returns:
The error message.
public Map<String, Long> getSanitisedItems()
Returns a map of the sanitised items along with their count.
Returns:
A map of sanitised items with their counts.
public Map<String, Long> getAllowedItems()
Returns a map of the allowed items along with their count.
Returns:
A map of allowed items with their counts.
public Map<String, Long> getRemedyItems()
Returns a map of the remedy items along with their count.
Returns:
A map of remedy items with their counts.
API Example
File input_directory = new File("Input");
File output_directory = new File("Output");
output_directory.mkdirs();
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 the Glasswall engine
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);
// Create a file summary
try (FileInputStream stream = new FileInputStream(analysis_output_path))
{
FileSummary file_summary = new FileSummary(
file.toPath(),
run_status,
error_message,
session_status.summaryDescription,
stream,
true // true to skip unsupported file types
);
// TODO - do something with the file summary
}
}
catch (Exception ex)
{
System.err.println("Exception occurred: " + ex.getMessage());
}
}