The following code example renders an HTML form using the Forms web service API. The name of the form design is Loan.xdp. A toolbar is added to the HTML form as well a file attachment. (See Rendering Forms as HTML.)/** Ensure that you create the Java proxy classes to use* base64 encoding. This is required to populate a BLOB* object with data or retrieve data from a BLOB object.** For information, see "Creating Java proxy classes using Apache Axis"* in Programming with LiveCycle ES.*/import java.io.FileInputStream;import java.io.IOException;import java.util.HashMap;import javax.servlet.Servlet;import javax.servlet.ServletException;import javax.servlet.ServletOutputStream;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.xml.rpc.holders.LongHolder;import javax.xml.rpc.holders.StringHolder;import com.adobe.idp.services.BLOB;import com.adobe.idp.services.FormsService;import com.adobe.idp.services.OutputType;import com.adobe.idp.services.FormsServiceServiceLocator;import com.adobe.idp.services.HTMLRenderSpec;import com.adobe.idp.services.HTMLToolbar;import com.adobe.idp.services.TransformTo;import com.adobe.idp.services.URLSpec;import com.adobe.idp.services.holders.BLOBHolder;import com.adobe.idp.services.holders.FormsResultHolder;public class RenderHTMLFormsWS extends HttpServlet implements Servlet {public void doGet(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException {doPost(req,resp);}public void doPost(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException {try{//Create a FormsService object and set authentication valuescom.adobe.idp.services.FormsServiceServiceLocator sl = new FormsServiceServiceLocator();FormsService formsOb = sl.getFormsService();((javax.xml.rpc.Stub)formsOb)._setProperty(javax.xml.rpc.Stub.USERNAME_PROPERTY, "administrator");((javax.xml.rpc.Stub)formsOb)._setProperty(javax.xml.rpc.Stub.PASSWORD_PROPERTY, "password");//Create an HTMLRenderSpec object to store//HTML run-time optionsHTMLRenderSpec htmlRS = new HTMLRenderSpec();htmlRS.setHTMLToolbar(HTMLToolbar.Vertical);//Render the HTML form within full HTML tagshtmlRS.setOutputType(OutputType.FullHTMLTags);//Specify file attachments to attach to the formFileInputStream fileAttachment = new FileInputStream("C:\\rideau1.jpg");BLOB attachment1 = new BLOB();int len = fileAttachment.available();byte []fileStream = new byte[len] ;fileAttachment.read(fileStream);attachment1.setBinaryData(fileStream);String fileName = "rideau1.jpg";//Create a HashMap object to store file attachmentsHashMap fileAttachments = new HashMap();fileAttachments.put(fileName, attachment1);//Specify URI values used by the Forms serviceURLSpec uriValues = new URLSpec();uriValues.setApplicationWebRoot("http://localhost:8080/FormsWSQS");uriValues.setContentRootURI("C:\\Adobe");uriValues.setTargetURL("http://localhost:8080/FormsWSQS/HandleData");//Create class holder objectsBLOBHolder outRenderPDFFormResultDoc = new BLOBHolder();FormsResultHolder formsResult = new FormsResultHolder();BLOBHolder blobHolder = new BLOBHolder();LongHolder longHolder = new LongHolder();StringHolder stringHolder = new StringHolder();StringHolder stringHolder2 = new StringHolder();//Invoke the renderHTMLForm method to render//an HTML formformsOb.renderHTMLForm("Loan.xdp",TransformTo.MSDHTML,null,htmlRS ,"",uriValues,null,outRenderPDFFormResultDoc,blobHolder,longHolder,stringHolder,stringHolder2,formsResult);//Create a BLOB object that contains form dataBLOB formData = formsResult.value.getOutputContent();//Get the content type of the response and//set the HttpServletResponse objects content typeString contentType = formData.getContentType();resp.setContentType(contentType);//Create a ServletOutputStream objectServletOutputStream oOutput = resp.getOutputStream();//Create a byte array that stores form data in the BLOB objectbyte[] cContent = formData.getBinaryData();//Write a byte stream back to the web browser.//Pass the byte arrayoOutput.write(cContent);}catch (Exception e) {System.out.println("The following error occurred during this operation " +e.getMessage());}}}
| Programming with LiveCycle ES (LiveDocs) |
| Adobe LiveCycle ES Update 1 |
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/livecycle/8.2/programLC/programmer/help/000077.html