Expand my Community achievements bar.

Vesatility of the script QPac

Avatar

Former Community Member
I was writing a servlet to call the Render QPac but had difficulty passing data as I would keep getting an error "Content no allowed in prolog". The data I was passing was valid xml but realised it was a limitation of the QPac. I could have wrote the xml data file to disk then passed the path but that isn't a great solution.



I discovered I could duplicate the functionality of the Render QPac (with more versatility). You can pass in your process variables from your servlet

Add the following code to your script QPac:



import com.adobe.fm.FMConstants;

import com.adobe.formServer.client.EJBClient;

import com.adobe.formServer.interfaces.IFormServer;

import com.adobe.formServer.interfaces.IOutputContext;

import com.adobe.formServer.interfaces.RenderFormException;

import com.adobe.idp.Context;

import com.adobe.idp.um.api.AuthenticationManager;

import com.adobe.idp.um.api.UMException;

import com.adobe.idp.um.api.UMFactory;

import com.adobe.idp.um.api.UMConstants;

import com.adobe.idp.um.api.infomodel.AuthResult;

import com.adobe.idp.Document;



import com.adobe.workflow.pat.service.PATAbstractService;

import com.adobe.workflow.pat.service.PATExecutionContext;

import com.adobe.workflow.pat.service.PATServiceException;

import com.adobe.workflow.pat.service.PATServiceResult;



import com.adobe.workflow.pat.service.PATServiceContext;



Context context = null;

IOutputContext iOutputContext=null;

String formTemplate="";

String formPref="";

Document data=null;

String options="";

String userAgent="";

String webRoot="";

String targetURL="";

String contentURI="";

String baseURL="";

com.adobe.idp.Document outDoc=null;



try {

AuthenticationManager manager = UMFactory.getInstance().getAuthenticationManager();

Context context = new Context();

AuthResult result = manager.getAuthResultOnBehalfOfUser(

"LiveCycle Form Manager System User",

UMConstants.SpecialDefaultPrincipals.DOMAIN_DEFAULT,

new Context());

context.initPrincipal(result);



IFormServer oFS = new EJBClient();



if(oFS!=null){

oFS.setInvocationContext(context);

}



formTemplate = patExecContext.getProcessDataStringValue("/process_data/@templatepath");

formPref = patExecContext.getProcessDataStringValue("/process_data/@formpref");

data = (Document)patExecContext.getProcessDataValue("/process_data/@data");

options = patExecContext.getProcessDataStringValue("/process_data/@options");

targetURL = patExecContext.getProcessDataStringValue("/process_data/@targeturl");

contentURI = patExecContext.getProcessDataStringValue("/process_data/@contenturi");

baseURL = patExecContext.getProcessDataStringValue("/process_data/@baseurl");



iOutputContext = oFS.renderForm(formTemplate, //template name

formPref, //render preference

data, options, userAgent, webRoot, //App URL

targetURL, contentURI, //ContentRoot URI

baseURL);







outDoc = new com.adobe.idp.Document(iOutputContext.getOutputContent());

outDoc.setContentType(iOutputContext.getContentType());



patExecContext.setProcessDataValue("/process_data/@output",outDoc);





} catch (UMException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

catch (RenderFormException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}
1 Reply

Avatar

Former Community Member
Very cool - this does indeed show the versatility of the Script QPac.

For readers of this post please note that the script QPac by default is an "Interactive" QPac - meaning that if you use it in a workflow that you intend to get results from a sycnronousInvoke() that it will not return the results immediately. In order to get the resulting PDF you must call getResults().

This can be tweaked by deploying another ScriptQPac which is NOT an interactive QPac. To do this you must modify the component.xml file in the Script QPac to say false and repackage the jar file. Once you deploy this workflow you will notice that you can use the QPac in Syncronous Workflow calls, and the results will be returned.

Note: once you make this change do not use the "interactive" checkbox in the script qpac.

Good luck!

Will