Quick Start (SOAP mode): Rendering an HTML form that uses a CSS file using the Java API

The following code example renders an HTML form using the Forms service Client API. The name of the custom CSS file that is referenced is custom.css . (See Rendering HTML Forms Using Custom CSS Files.)

/* 
    * This Java Quick Start uses the following JAR files 
    * 1. adobe-forms-client.jar 
    * 2. adobe-livecycle-client.jar 
    * 3. adobe-usermanager-client.jar 
    * 4. activation.jar (required for SOAP mode) 
    * 5. axis.jar (required for SOAP mode) 
    * 6. commons-codec-1.3.jar (required for SOAP mode) 
    * 7. commons-collections-3.2.jar  (required for SOAP mode) 
    * 8. commons-discovery.jar (required for SOAP mode) 
    * 9. commons-logging.jar (required for SOAP mode) 
    * 10. dom3-xml-apis-2.5.0.jar (required for SOAP mode) 
    * 11. jaxen-1.1-beta-9.jar (required for SOAP mode) 
    * 12. jaxrpc.jar (required for SOAP mode) 
    * 13. log4j.jar (required for SOAP mode) 
    * 14. mail.jar (required for SOAP mode) 
    * 15. saaj.jar (required for SOAP mode) 
    * 16. wsdl4j.jar (required for SOAP mode) 
    * 17. xalan.jar (required for SOAP mode) 
    * 18. xbean.jar (required for SOAP mode) 
    * 19. xercesImpl.jar (required for SOAP mode) 
    *  
    *  (Because Forms quick starts are implemented as Java servlets, it is  
    *  not necessary to include J2EE specific JAR files - the Java project 
    *  that contains this quick start is exported as a WAR file which 
    *  is deployed to the J2EE application server) 
    *   
    *  These JAR files are located in the following path: 
    * <install directory>/sdk/client-libs/common 
    *  
    * For complete details about the location of these JAR files,  
    * see "Including AEM Forms library files" in Programming with AEM forms 
    */ 
import java.io.IOException; 
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 com.adobe.livecycle.formsservice.client.*; 
 
import java.util.*; 
import java.io.InputStream; 
import com.adobe.idp.Document; 
import com.adobe.idp.dsc.clientsdk.ServiceClientFactory; 
import com.adobe.idp.dsc.clientsdk.ServiceClientFactoryProperties; 
 
import java.io.FileInputStream; 
 
 
public class RenderHTMLCSS 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{ 
                //Set connection properties required to invoke AEM Forms                                 
                Properties connectionProps = new Properties(); 
                connectionProps.setProperty(ServiceClientFactoryProperties.DSC_DEFAULT_SOAP_ENDPOINT, "jnp://[server]:[port]"); 
                connectionProps.setProperty(ServiceClientFactoryProperties.DSC_TRANSPORT_PROTOCOL,ServiceClientFactoryProperties.DSC_SOAP_PROTOCOL);           
                connectionProps.setProperty(ServiceClientFactoryProperties.DSC_SERVER_TYPE, "JBoss"); 
                connectionProps.setProperty(ServiceClientFactoryProperties.DSC_CREDENTIAL_USERNAME, "administrator"); 
                connectionProps.setProperty(ServiceClientFactoryProperties.DSC_CREDENTIAL_PASSWORD, "password"); 
             
                //Create a FormsServiceClient object 
                ServiceClientFactory myFactory = ServiceClientFactory.createInstance(connectionProps); 
                FormsServiceClient formsClient = new FormsServiceClient(myFactory);  
         
                //Set parameter values for the (Deprecated) renderHTMLForm method 
                String formName = "Applications/FormsApplication/1.0/FormsFolder/Loan.xdp";  
                byte[]    cData = "".getBytes(); 
                Document oInputData = new Document(cData); 
                String userAgent = "" ; 
                                     
                //Create an HTMLRenderSpec object to store HTML run-time options 
                HTMLRenderSpec htmlRS = new HTMLRenderSpec(); 
                                                                         
                //Specify the locale value 
                htmlRS.setLocale("en_US"); 
                 
                //Specify a custom CSS file to use 
                htmlRS.setCustomCSSURI("C:\\Adobe\custom.css"); 
                 
                //Render the HTML form within full HTML tags 
                htmlRS.setOutputType(OutputType.FullHTMLTags); 
                                                                 
                //Specify URI values that are required to render a form 
                URLSpec uriValues = new URLSpec();  
                uriValues.setApplicationWebRoot("http://[server]:[port]/FormsQS"); 
                uriValues.setContentRootURI("repository:///"); 
                uriValues.setTargetURL("http://[server]:[port]/FormsQS/HandleData"); 
                                 
                //Specify file attachments 
                FileInputStream myForm = new FileInputStream("C:\\Attach1.txt");  
                Document attachment1 = new Document(myForm); 
                FileInputStream myForm2 = new FileInputStream("C:\\Attach2.txt");  
                Document attachment2 = new Document(myForm2); 
                String fileName = "Attach1.txt"; 
                String fileName2 = "Attach2.txt"; 
                     
                Map fileAttachments = new HashMap(); 
                fileAttachments.put(fileName, attachment1);  
                fileAttachments.put(fileName2, attachment2);  
                         
                //Invoke the (Deprecated) renderHTMLForm method 
                FormsResult formOut = formsClient.renderHTMLForm( 
                    formName,               //formQuery 
                    TransformTo.MSDHTML,    //transformTo 
                    oInputData,             //inDataDoc 
                    htmlRS,                    //renderHTMLSpec 
                    userAgent,                //User Agent 
                    uriValues,                //urlSpec 
                    fileAttachments            //attachments 
                    ); 
         
                //Create a Document object that stores form data 
                Document myData = formOut.getOutputContent(); 
         
                //Get the content type of the response and 
                //set the HttpServletResponse object's content type 
                String contentType = myData.getContentType();  
                resp.setContentType(contentType); 
         
                //Create a ServletOutputStream object 
                ServletOutputStream oOutput = resp.getOutputStream(); 
         
                //Create an InputStream object 
                InputStream inputStream = myData.getInputStream(); 
         
                //Write the data stream to the web browser 
                byte[] data = new byte[4096]; 
                int bytesRead = 0; 
                while ((bytesRead = inputStream.read(data)) > 0) 
                { 
                    oOutput.write(data, 0, bytesRead); 
                } 
         
            }catch (Exception e) { 
                     System.out.println("The following exception occurred: "+e.getMessage()); 
             } 
    } 
}

// Ethnio survey code removed