보고서
요약 보고서
요약 보고서 예제
<?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
생성자
SummaryReport() throws ParserConfigurationException, DOMException
SummaryReport(boolean skipUnsupportedFileTypes) throws ParserConfigurationException, DOMException
매개변수:
boolean skipUnsupportedFileTypes- skipUnsupportedFileTypes 플래그를 설정합니다. 이 플래그를 지정하지 않으면 skip unsupported file types는false로 설정됩니다.
인스턴스 메서드
void setSkipUnsupportedFileTypes(boolean skipUnsupportedFileTypes)
지원되지 않는 파일 형식 건너뛰기 플래그의 setter입니다.
매개변수:
boolean skipUnsupportedFileTypes- 지원되지 않는 파일 형식 건너뛰기 플래그를 설정합니다.
boolean getSkipUnsupportedFileTypes()
지원되지 않는 파일 형식 건너뛰기 플래그의 getter입니다.
반환값:
true이면 지원되지 않는 파일 형식을 건너뛰고, 그렇지 않으면 false입니다.
void addAnalysisReport(
Path inputFilePath,
int sessionStatus,
String lastErrorMessage,
String processMessage,
InputStream analysisInputStream
) throws SAXException, ParserConfigurationException, IOException
요약 보고서에 새 Glasswall 분석 보고서를 추가합니다.
매개변수:
Path inputFilePath- 처리된 파일의 파일 경로입니다.int sessionStatus- GW2RunSession의 반환 상태입니다.String lastErrorMessage- [GW2FileErrorMsg]/embedded-engine/embedded-engine-gw2fileerrormsg)의 오류 메시지입니다. 이 값이 null이거나 비어 있으면 요약 보고서에 포함되지 않습니다.String processMessage- GW2FileSessionStatus의 프로세스 메시지입니다. 이 값이 null이거나 비어 있으면 요약 보고서에 포함되지 않습니다.InputStream analysisInputStream- 포함할 분석 보고서가 들어 있는 입력 스트림입니다.
void addAnalysisReport(FileSummary summary) throws SAXException, ParserConfigurationException, IOException
요약 보고서에 새 Glasswall 파일 요약을 추가합니다.
매개변수:
FileSummary summary- 요약 보고서에 추가할 요약 정보입니다.
public void generateSummaryReport(Writer writer) throws TransformerConfigurationException, TransformerException
제공된 분석 보고서에서 XML 요약 보고서를 생성합니다.
매개변수:
Writer writer- 요약 보고서가 기록될 writer입니다.
public void generateSummaryReport(Writer writer, Transformer transformer) throws TransformerException
지정된 transformer를 사용하여 제공된 분석 보고서에서 XML 요약 보고서를 생성합니다.
매개변수:
Writer writer- 요약 보고서가 기록될 writer입니다.Transformer transformer- XML 보고서 생성에 사용될 transformer입니다.
API 예제
요약 보고서 기능은 com.glasswall.analysissummary.SummaryReport 클래스에 구현되어 있습니다. 먼저 클래스의 인스턴스를 생성한 다음, 요약 보고서에 포함될 각 분석 보고서에 대해 addAnalysisReport를 호출하고, 마지막에 generateSummaryReport를 호출하여 요약 보고서를 생성합니다. 예시는 아래와 같습니다:
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 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);
// 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);
}