Publication extensions let you customize the publication process. For example, you can use a post-delivery publication extension to clean up scope batches for high-volume publications. Or you can use a pre-delivery publication extension to include additional artifacts in the personalized publication content. An introduction to publication extension can be found in this blog post by christina.obry
There are three types of publication extensions:
In this blog, I will demonstrate a post-processing (pre-delivery) plugin to password protect publication articrafts (pdf & excel). As it is a post processing plugin, it will encrypt the pdf and excel documents generated by a publication and will return the encrypted documents back to the publication for delivery. The recipients will get the password protected documents.
Below are the pre-requisites to implement this publication extension:
Below is the source code for publication extension:
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import com.businessobjects.publisher.postprocessing.IPublicationPostProcessingContext;
import com.businessobjects.publisher.postprocessing.IPublicationPostProcessingPlugin;
import com.businessobjects.publisher.postprocessing.PluginTargetDestination;
import com.crystaldecisions.sdk.occa.infostore.IDestinationPluginArtifactFormat;
import com.crystaldecisions.sdk.occa.infostore.IInfoObject;
import com.crystaldecisions.sdk.occa.infostore.IInfoObjects;
import com.crystaldecisions.sdk.plugin.CeProgID;
import com.crystaldecisions.sdk.occa.infostore.*;
import java.io.*;
import com.itextpdf.text.pdf.*;
import com.itextpdf.text.*;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
import com.crystaldecisions.sdk.plugin.desktop.pdf.*;
import com.crystaldecisions.sdk.occa.infostore.*;
import java.io.IOException;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackageAccess;
import org.apache.poi.poifs.crypt.*;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class PasswordProtection implements IPublicationPostProcessingPlugin
{
public Collection getTargetDestinations() throws Exception
{
PluginTargetDestination inboxDestination = new PluginTargetDestination(CeProgID.MANAGED_DEST,
IDestinationPluginArtifactFormat.CeDistributionMode.FILTER_EXCLUDE_SOURCE_DOCUMENTS);
PluginTargetDestination smtpDestination = new PluginTargetDestination(CeProgID.SMTP,
IDestinationPluginArtifactFormat.CeDistributionMode.FILTER_EXCLUDE_SOURCE_DOCUMENTS);
PluginTargetDestination diskDestination = new PluginTargetDestination(CeProgID.DISKUNMANAGED,
IDestinationPluginArtifactFormat.CeDistributionMode.FILTER_EXCLUDE_SOURCE_DOCUMENTS);
PluginTargetDestination ftpDestination = new PluginTargetDestination(CeProgID.FTP,
IDestinationPluginArtifactFormat.CeDistributionMode.FILTER_EXCLUDE_SOURCE_DOCUMENTS);
PluginTargetDestination[] destinations = { inboxDestination, smtpDestination, diskDestination, ftpDestination };
return Arrays.asList(destinations);
}
public IInfoObjects handle(IPublicationPostProcessingContext context) throws Exception
{
//Below line retrieves the password text specified while creating the publication
String password = context.getOptions().toString();
//Below is the path to log file for this plugin on BO server
FileWriter outFile = new FileWriter("D:\\PubDemo\\logs\\" + System.currentTimeMillis()+".log");
outFile.write("hello!\n");
ArrayList docs = context.getDocuments();
Iterator docIt = docs.iterator();
IInfoObjects objs = context.getInfoStore().newInfoObjectCollection();
outFile.write("hello1!\n");
while (docIt.hasNext())
{
IInfoObject obj = (IInfoObject)docIt.next();
outFile.write("next step is get kind!\n");
String kind=obj.getKind();
outFile.write(kind);
if(kind.equals("Pdf"))
{
outFile.write("inside if and pdf!\n");
IFiles files = (IFiles)obj.getFiles();
IFile file2=(IFile) files.get(0);
InputStream iStream = ((IRemoteFile)files.get(0)).getInputStream();
//Path to create a copy of original excel document in publication. This will create a temp excel file on BO server in order to enable password protection.
OutputStream file = new FileOutputStream("D:\\12345678.pdf");
PdfReader reader = new PdfReader(iStream);
PdfStamper stamper=new PdfStamper(reader,file);
//Below line of code sets the password for temp pdf document
stamper.setEncryption(password.getBytes(), password.getBytes(),PdfWriter.ALLOW_PRINTING, PdfWriter.ENCRYPTION_AES_128);
stamper.close();
reader.close();
file.close();
/*Below line of code replaces the original pdf document with the password protected pdf document in temp directory and deletes the document in temp directory
after successfully replacing the original pdf file*/
file2=(IFile)files.replace(0,"D:\\12345678.pdf",true);
outFile.write(obj.getTitle() + "\n");
String newName = "Artifact - " + System.currentTimeMillis();
outFile.write("Renaming '" + obj.getTitle() + "' to " + newName);
}
else if (kind.equals("Excel"))
{
outFile.write("inside elseif and excel!\n");
IFiles files = (IFiles)obj.getFiles();
IFile file2=(IFile) files.get(0);
InputStream iStream = ((IRemoteFile)files.get(0)).getInputStream();
POIFSFileSystem poiFileSystem = new POIFSFileSystem();
EncryptionInfo info = new EncryptionInfo(poiFileSystem, EncryptionMode.standard);
Encryptor enc = info.getEncryptor();
enc.confirmPassword(password);
OPCPackage opc = OPCPackage.open(iStream);
OutputStream os = enc.getDataStream(poiFileSystem);
opc.save(os);
opc.close();
//Path to create a copy of original excel document in publication. This will create a temp excel file on BO server in order to enable password protection.
FileOutputStream fileOut = new FileOutputStream("D:\\12345678.xlsx");
poiFileSystem.writeFilesystem(fileOut);
fileOut.close();
/* Below line of code replaces the original excel document with the password protected pdf document in temp directory and deletes the document in temp directory
after successfully replacing the original excel file*/
file2=(IFile)files.replace(0,"D:\\12345678.xlsx",true);
outFile.write(obj.getTitle() + "\n");
String newName = "Artifact - " + System.currentTimeMillis();
}
objs.add(obj);
}
outFile.close();
//return method returns the password protected pdf, excel documents
return objs;
}
}
http://help.sap.com/businessobject/product_guides/boexir4/en/xi4_boejava_dg_en.zip
http://help.sap.com/businessobject/product_guides/boexir31/en/boesdk_java_dg_12_en.zip
For reference, I have attached encryption.jar file with this blog. However the file is attached with extension as .txt. You can download the file and then can change the extension to .jar.
Deployment Instructions:
<BOBJ_INST_DIR>\SAP BusinessObjects\SAP BusinessObjects EnterpriseXI 4.0 \ java\lib\publishingPlugins
Note: In a clustered environment, jar files are required to be placed on each node in BO cluster at the mentioned path.
bcmail-jdk16-1.46.jar
bcprov-jdk16-1.46.jar
itextpdf-5.2.1.jar
poi-3.12-20150511.jar
poi-ooxml-3.12-20150511.jar
poi-ooxml-schemas-3.12-20150511.jar
poi-scratchpad-3.12-20150511.jar
Note: In a clustered environment, all SIA's in the cluster are required to be restarted
How to enable password protection plugin for an existing or new publication:
After specifying text in the above highlighted fields, click on ‘Add’ Button for ‘Before Publication Delivery’ as highlighted in the above snapshot
Click on Save & Close to save the changes to publication.
Note: The option ''Publication Extension' to integrate publication extension with a publication is only available in CMC and not BI Launchpad.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
14 | |
10 | |
8 | |
7 | |
4 | |
4 | |
4 | |
4 | |
3 |