Example of Creating exacro-xeni Extended Interface - DRM

How to apply the DRM solution with the extended interface should be implemented as the method guided by the DRM solution. As various methods and possibilities are provided for each DRM solution, in this document, a general scenario is described.

There are 2 ways of applying DRM to the Excel file:

In this document, only the description of how to apply DRM in the Server is provided.

DRM Applied Excel Import & Export Scenario

For Import of the DRM-applied Excel file, it is uploaded to the server from the Nexacro Platform, and the server disables the received Excel file using the method provided by the DRM solution to convert it to the PlatformData of the Nexacro Platform and transmit to the Nexacro Platform.

When exporting the Grid as an Excel file, the Grid data received from the Nexacro Platform is created as an Excel file, and it is converted to the DRM-applied Excel file through the method provided by the DRM solution for the Excel file location to be transmitted to the Nexacro Platform as a URL.

The XeniExtendBase Interface Inheritance

nexacro17-xeni => XeniExcelDataStorageBase Interface Inheritance

Create the XeniDrmSample class that inherited the XeniExtendBase (nexacro17-xeni => XeniExcelDataStorageBase). Import each package to a reference, and the package provided by the DRM solution as well.

package com.nexacro.xeni.util;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.servlet.http.HttpServletResponse;

import com.nexacro.xapi.data.DataSet;
import com.nexacro.xapi.data.PlatformData;
import com.nexacro.xapi.data.VariableList;
import com.nexacro.xapi.tx.HttpPlatformResponse;
import com.nexacro.xapi.tx.PlatformType;

public class XeniDrmSample implements XeniExtendBase {

Please refer to the provided sample for the full source of the XeniDrmSample.

Method Implementation

loadTargetStream

In the above scenario, loadTargetStream() is implemented to open the Excel file in the specified path and transmit the file stream without any other implementation.

public InputStream loadTargetStream(String filepath) throws Exception {
	File file = new File(filepath);
	return new FileInputStream(file);
}

saveImportStream

This method converts the Excel file received from the Nexacro Platform to PlatformData.

saveImportStream() checks the path received as the parameter. If the specified path does not exist, then create a new one.

int nIdx = filepath.lastIndexOf("/");
String sPath = filepath.substring(0, nIdx);
String fileName = filepath.substring(nIdx + 1);
String srcFile = sPath + "/__temp_" + fileName;

File file = new File(sPath);
if(file.exists() == false) {
	file.mkdirs();
}
Create and save a temporary file by adding the prefix "__temp_" to the specified path for the DRM-applied Excel file stream received as the parameter.
OutputStream out = new FileOutputStream(srcFile);

byte[] buf = new byte[1024];
int length = 0;
while((length = in.read(buf)) > 0) {
	out.write(buf, 0, length);
}

out.flush();
out.close();
in.close();
Disable the temporary file (DRM applied file) saved in the specified path using the DRM disable method provided by the DRM solution. Follow the DRM solution guide for the required parameter of the DRM method and the exception processing for the execution result.
boolean isSuccess = DrmUtil.extractDRM(srcFile, filepath);
If the DRM disable method is successfully processed, then return the DRM-applied temporary file.
File delFile = new File(srcFile);
if(delFile.exists()) {
	file.delete();
}

The conversion of the DRM-disabled Excel file to PlatformData does not need to be implemented, as it is processed inside Nexacro-xeni, and it is also not open to change.

saveExportStream

This method implements the function of transmitting the URL that can be downloaded from the Nexacro Platform by converting the grid transmitted to the Nexacro Platform into an Excel file.

Check if the path received as the parameter exists. If not, create a new one.

Since the function to convert the grid data to the Excel file is processed inside Nexacro-xeni, it does not need to be implemented here. It is received as the parameter "ByteArrayOutputStream out".
int nIdx = filepath.lastIndexOf("/");
String sPath = filepath.substring(0, nIdx);
String fileName = filepath.substring(nIdx + 1);
String srcFile = sPath + "/__temp_" + fileName;

File file = new File(sPath);
if(file.exists() == false) {
	file.mkdirs();
}
Create and save the Excel file stream (before applying DRM) in Nexacro-xeni with a temporary file name (prefix "__temp_") in the specified path.
FileOutputStream fout = new FileOutputStream(srcFile);
fout.write(out.toByteArray());

fout.close();
out.close();
Crete the temporary file in which the DRM is not applied as the DRM-applied file using the method provided by the DRM solution. For detailed implementation, please follow the DRM solution guide.
String id = varlist.getString("id");
String name = varlist.getString("name");
String code = varlist.getString("code");
String dept = varlist.getString("dept");
		boolean isSuccess = DrmUtil.packagingDRM(srcFile, filepath, id, name, code, dept);

Delete the used temporary file if the DRM application is successful.

File delFile = new File(srcFile);
if(delFile.exists()) {
	file.delete();
}

Store the DRM-applied Excel file information (URL) and the conversion result in PlatformData and transmit it to the Nexacro Platform.

DataSet dsRes = CommUtil.getDatasetExportResponse(dscmd);

PlatformData resData = new PlatformData();
VariableList varList = resData.getVariableList();

varList.add("ErrorCode", 0);
varList.add("ErrorMsg", "SUCCESS");

dsRes.set(0, "url", fileurl);
resData.addDataSet(dsRes);

HttpPlatformResponse platformRes = new HttpPlatformResponse(response, PlatformType.CONTENT_TYPE_SSV, "UTF-8");
platformRes.setData(resData);
platformRes.sendData();

return 0;

If you have any information to transmit to the Nexacro Platform, then you can add it to this location.