This document explains how the user can expand the basic Import and Export functions of the Excel files in Nexacro-xeni by using the extended interface of Nexacro-xeni provided by the Nexacro Platform.
In order to implement the user's specialized function, implementation of a separate, specialized logic by the user with the extended interface provided in the Nexacro-xeni is required.
Extend Nexacro-xeni Interface
Nexacro-xeni provides an interface for user extension development. The user can add the function as defined by the user before creating Grid Data from the Nexacro Platform as the Excel file through the implementation of the provided interface. Also, additional tasks can be implemented before converting the Excel file from the Nexacro Platform to Grid Data.
The user can implement the following additional functions by using the Extend Nexacro-xeni interface. Also, desired functions within the scope of not damaging the default execution steps of Nexacro-xeni can be additionally implemented.
Function to disable DRM off the DRM-applied Excel file and apply DRM to the created Excel file
Function to save the Excel file in the Database and read from the Database (not using the file system)
Other additional functions of user logic
The Extend Nexacro-xeni interface provides the following methods.
loadTargetStream
saveImportStream
saveExportStream
These methods can be implemented by inheriting the XeniExtendBase (nexacro17-xeni => XeniExcelDataStorageBase) interface. To use the implemented interface, the class implemented by the user must be registered in the corresponding properties file to be used.
Conversion of the Excel file to PlatformData and conversion of the PlatformData to Excel are implemented inside the Nexacro-xeni and additional functions on these are now allowed.
loadTargetStream
public InputStream loadTargetStream(String filepath)
This interface is used to specify the source of PlatformData to be created by Nexacro-xeni.
When the DRM function is applied: Implement to return the DRM-disabled Excel file received from the Nexacro Platform. In other words, implement the same as the sample provided. (XeniDrmSample.java)
public InputStream loadTargetStream(String filepath) throws Exception { File file = new File(filepath); return new FileInputStream(file); }
saveImportStream
String saveImportStream(VariableList varlist, InputStream in, String filepath)
This is an interface that saves the Excel file received from the Nexacro Platform as PlatformData. It saves the Excel file (InputStream) from the Nexacro Platform in the specified directory (filepath) or Database, and it returns the Key (filepath) of the saved Database or file path (filepath).
The implementation of the interface can be freely extended by including the basic Excel Import logic below.
Check the specified directory (filepath) and create if it does not exist
Create the FileOutputStream file in the specified directory (filepath)
Read the received Excel file (InputStream in) and save it in FileOutputStream
Close FileOutputStream
public String saveImportStream(VariableList varlist, InputStream in, String filepath) throws Exception { int nIdx = filepath.lastIndexOf("/"); String sPath = filepath.substring(0, nIdx); File file = new File(sPath); if (file.exists() == false) { file.mkdirs(); } // write input stream to file OutputStream out = new FileOutputStream(filepath); 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(); return null; }
saveExportStream
int saveExportStream(VariableList varlist, DataSet dscmd, ByteArrayOutputStream out, String filepath, String fileurl, HttpServletResponse response)
It saves the Grid data received from the Nexacro Platform as an Excel file and transmits the saved path (Key) to the client to enable the download.
It can be freely extended by including the basic Excel Import logic below.
Create if the directory of the filepath (Excel file name) passed as a parameter does not exist
Save the converted Excel Stream (ByteArrayOutputStream out) received as the parameter in the created Excel file
Transmit PlatformData, including the download URL and file name, to the Nexacro Platform
The created Excel file is automatically deleted as per the environment setting
public int saveExportStream(VariableList varlist, DataSet dscmd, ByteArrayOutputStream out, String filepath, String fileurl, HttpServletResponse response) throws Exception { int nIdx = filepath.lastIndexOf("/"); String sPath = filepath.substring(0, nIdx); File file = new File(sPath); if (file.exists() == false) { file.mkdirs(); } FileOutputStream fout = new FileOutputStream(filepath); fout.write(out.toByteArray()); fout.close(); out.close(); 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; }
Configuration to Use XeniExtendBase
Copying XeniExtendBase Implementation Class File
1
Implement the extended XeniExtendBase (nexacro17-xeni => XeniExcelDataStorageBase) interface, and then copy the implemented class file to the following path to use.
The extended class name can be changed.
nexacro-xeni > WEB-INF > classes
2
To use the developed class, create the xeni.properties file in one of the paths below.
nexacro-xeni > WEB-INF > classes
nexacro-xeni > WEB-INF > lib
Path defined in CLASSPATH
3
Register the developed class name in the xeni.properties file as the extended interface of Nexacro-xeni.
For nexacro14-xeni (xeni.properties file)
xeni.exportimport.extend={User Package Name}.{User Class Name} ex) xeni.exportimport.extend=com.nexacro.xeni.util.XeniExtendUseFile
For nexacro17-xeni (xeni.properties file)
xeni.exportimport.storage={User Package Name}.{User Class Name} ex) xeni.exportimport.storage=com.nexacro17.xeni.extend.XeniExcelDataStorageDef