package e4s.tutorial; import javax.servlet.http.HttpServletResponse; import e4s.util.E4Images; import e4s.html.*; import e4s.servlet.E4ModuleImplementation; import e4s.servlet.E4ServletImplementation_Intf; import e4s.servlet.E4ServletImplementation_Servlet; /** * Silent-Output example. This example demonstrates how to generate outputs * without any additional information to be used directly for XML input streams * or other purposes. In this case, a VCARD is created which will go directly into * the client's mail application (e.g. MS-Outlook). * * {@tutorial Example_Method_Silent} * * @see e4s.html.E4MethodSilent */ public class Example_MethodSilent extends E4ModuleImplementation { public static E4Method start = null; public static E4MethodSilent download = null; /** * Startup this module. */ public void start(HTML html) { html.Message(E4Message.CAPTION,"Silent output example"); html.P(); A href = html.A(download); href.IMG(E4Images.download); href.print(NBSP); href.FONT(FONT.ARIAL_smaller).print("Click here to download my VCARD"); } /** * This function is called after the user clicks on the download link. A VCARD structure will * be prepared and written out to the HTML element, beware not to use any other HTML tags, E4CSS or * E4JavaScript functions here. This function is defined as E4MethodSilent (instead E4Method). */ public void download(HTML html) { // this is the interface servlet context E4ServletImplementation_Intf servlet = getServlet(); // it is expected to be running as servlet - but let's check if (! (servlet instanceof E4ServletImplementation_Servlet)) throw new Error("This works only in servlet applications"); // this is the servlet response (refer to Tomcat documentation) HttpServletResponse response = ((E4ServletImplementation_Servlet)servlet).getResponse(); // change the header of our output response.setHeader("Content-Type","text/x-vcard"); response.setHeader("Content-Disposition","attachment; filename=element4solution.vcf"); response.setHeader("Connection","close"); // this output is simplified, it can be generated by a database html.println("BEGIN:VCARD"); html.println("VERSION:2.1"); html.println("N:Siegel;Robert;;Herr"); html.println("FN:Robert Siegel"); html.println("TITLE:CEO"); html.println("ORG:Door2solution Software Gmbh"); html.println("TEL;HOME;VOICE:+43 (2243) 21816"); html.println("URL;WORK:http://www.door2solution.com"); html.println("ADR;WORK:;;Max-Kahrer Gasse-5;Klosterneuburg;;3400;Österreich"); html.println("LABEL;WORK;ENCODING=QUOTED-PRINTABLE:Max-Kahrer Gasse-5=0D=0AKlosterneuburg 3400=0D=0A=D6sterreich"); html.println("EMAIL;PREF;INTERNET:office@door2solution.at"); html.println("REV:20070315T230420Z"); html.println("END:VCARD"); } }