Tuesday Dec 08, 2009

Glassfis: Using saxon XSL Processor instat of xerces

Glassfish Application server provides an Xerces XSL Processor. This processor did only support XSL 1.0 but no XSL 2.0 which comes with a lot of additional functions.

So in a Web Application which is doing some XML/XSL transformation the xerces processor will be used per default. To change this behavior you can simply copy the saxon processor into the /lib folder of your web module.

Or if you are using maven add the following dependency into your pom.xml

<dependency>
<groupId>net.sf.saxon</groupId>
<artifactId>saxon</artifactId>
<version>8.7</version>
</dependency>

Thats it. Now your web module will run with saxon xml/xsl and you can work with all the cool XSL 2.0 functions.

Friday Nov 07, 2008

Generate MS-Word from Servlet will not work in IE ??

Today I spent a very long time to figure out why my JEE Servlet was unable to generate a dynamic MS Word document. - No the servlet dose generate a dynamic MS Word document!. But IE 7.0 in Windows XP with MS Office 2007 was not able to open the generated MS Word document! This was strange because using Firefox on Windows or also using Firefox on Linux Plattform works perfect! So why the hell IE on windows did not open MS Word?

After a long long frustrating period I found out that the solution is to not only set the ContentType to 'application/ms-word' but also set two additional header attributes to get word open on Windows Plattform.

So my servlet output code looks like this - at it works:

public class TestServlet extends javax.servlet.http.HttpServlet {

HttpServletRequest request;
HttpServletResponse response;

protected void doGet(HttpServletRequest arequest,
HttpServletResponse aresponse) throws ServletException, IOException {
this.request = arequest;
this.response = aresponse;
String sEncoding = "utf-8";
response.setCharacterEncoding(sEncoding);
response.setContentLength(5);
response.setContentType("application/msword;charset=utf-8");

response.setHeader("Content-disposition", "attachment; filename"
+ "Example.doc");
response.setHeader("Pragma", "public");
response.setHeader("Cache-Control", "cache");
response.setHeader("Cache-Control", "must-revalidate");

ServletOutputStream out = response.getOutputStream();
out.println("Hallo");
out.flush();
out.close();

}

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}

A helpful thread about this topic can be read here:

http://forums.sun.com/thread.jspa?threadID=586671

I can not understand wy Microsoft always needs so much welfare? "Convention over configuration" seems not be the rule for Microsoft.....