Chuyển đến nội dung chính

Độc lập

Tóm tắt - độc lập

Có thể tạo bản tóm tắt tệp độc lập bằng cách tạo một đối tượng com.glasswall.analysissummary.FileSummary.

API

Các hàm khởi tạo

public FileSummary(
Path inputFilePath,
int sessionStatus,
String lastErrorMessage,
String processMessage,
InputStream analysisInputStream,
boolean skipUnsupportedFileTypes
) throws SAXException, ParserConfigurationException, IOException

Tham số:

  • Path inputFilePath - Đường dẫn tệp của tệp đã được xử lý.
  • int sessionStatus - Trạng thái trả về từ GW2RunSession.
  • String lastErrorMessage - Thông báo lỗi từ GW2FileErrorMsg. Nếu giá trị này là null hoặc rỗng thì nó sẽ không được đưa vào bản tóm tắt.
  • String processMessage - Thông báo xử lý từ GW2FileSessionStatus. Nếu giá trị này là null hoặc rỗng thì nó sẽ không được đưa vào bản tóm tắt.
  • InputStream analysisInputStream - Luồng đầu vào chứa báo cáo phân tích sẽ được đưa vào.
  • boolean skipUnsupportedFileTypes - giá trị boolean cho biết liệu có nên bỏ qua các loại tệp không được hỗ trợ hay không.

Các phương thức thực thể

public String getFileName()

Trả về tên tệp của tệp đã được xử lý.

Trả về: Đường dẫn tệp tuyệt đối của tệp đã được xử lý.


public String getProcessMessage()

Trả về thông báo xử lý của phiên tệp. Giá trị này sẽ là null nếu thông báo xử lý không được chỉ định.

Trả về: Thông báo xử lý của phiên tệp.


public EngineOutcome getEngineOutcome()

Trả về một enum EngineOutcome cho biết liệu tệp đã xử lý là Managed, NonConforming hay Unsupported.

Trả về: Một enum EngineOutcome.


public String getErrorMessage()

Trả về thông báo lỗi nếu tệp không tuân thủ. Giá trị này sẽ là null nếu tệp được quản lý.

Trả về: Thông báo lỗi.


public Map<String, Long> getSanitisedItems()

Trả về một map của các mục đã được làm sạch cùng với số lượng của chúng.

Trả về: Một map các mục đã được làm sạch cùng với số lượng của chúng.


public Map<String, Long> getAllowedItems()

Trả về một map của các mục được cho phép cùng với số lượng của chúng.

Trả về: Một map các mục được cho phép cùng với số lượng của chúng.


public Map<String, Long> getRemedyItems()

Trả về một map của các mục khắc phục cùng với số lượng của chúng.

Trả về: Một map các mục khắc phục cùng với số lượng của chúng.

Ví dụ API

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());
}
}