XSLTProcessor

Carlos Quiroz

Revision History
Revision $Revision: 1.1 $$Date: 2002/01/13 13:55:14 $

Introduction

The XSLTProcessor can be used to customize the output of the HttpAdaptor. It basically takes the XML output of the HttpAdaptor and process it by using XSL. This enables you to customize the look as you wish. Normally the processing will produce HTML files you can display in a standard browser.

The actual files to be used are specified via the File property. This points to dir where the template files are. Optionally you can package all your files in a .jar or .zip file and deliver that instead.

The processor identifies which xsl template to use from the HTTP request. i.e. if the request is mbean it will try to find a mbean.xsl file and use it to process the resulting XML tree. You can modify this by passing a template variable. For instance. http://host:port/mbean?objectname=Test:name=test1&template=testmbean In that case the HttpAdaptor will build a mbean resulting tree but instead of being processed using the mbean.xsl, it will use testmbean.xsl.

If you need to deliver extra files like images or raw HTML, you can add it to the target filesystem. The processor know a few MIME types which are classified according to the extension. This includes:

  • GIF images: extension=".gif", MIME type: "image/gif"

  • PNG images: extension=".png", MIME type: "image/png"

  • JPG images: extension=".jpg", MIME type: "image/jpg"

  • HTML raw files: extension=".html,.html", MIME type: "text/html"

  • HTML raw files: extension=".css", MIME type: "text/css"

You can add extra MIME type with the addMimeType method.

Attributes

The XSLTProcessor has the following attributes and operations that you can use to customize the operation.

  • File: Determines where to look for xsl files. If the target file is a dir, it assumes that xsl files are located on the dir. Otherwise if it points to a .jar or .zip files, it assumes that the files are located there. Pointing it to a file system is especially useful for testing.

  • PathInJar: Sets the dir in the jar file where xsl files reside

  • UseJar: Read-only. It tells whether the processor is reading from a jar file

  • UsePath: Read-only. It tells whether the processor is reading from a dir

  • UseCache: Indicates whether to cache the transformation objects. This speeds-up the process. It is usually set to true, but you can set it to false for easier testing

  • addMimeType: Adds a mime type in the form of a addMimeType(".pdf", "application/pdf"). The XSLTProcessor will use th given MIME type for files with the given extension

For example you can set the attributes as follow:

	
ObjectName processorName = new ObjectName("Server:name=XSLTProcessor");
server.createMBean("openjmx.adaptor.http.XSLTProcessor", processorName, null);

// set it to use a dir
server.setAttribute(processorName, new Attribute("File", "/home/tibu/devel/openjmx/src/core/openjmx/adaptor/http/xsl"));

// set it to use a compressed file
server.setAttribute(processorName, new Attribute("File", "/home/tibu/skins.jar"));

// set the target dir
server.setAttribute(processorName, new Attribute("PathInJar", "/openjmx/adaptor/http/xsl"));

// set not to use cache
server.setAttribute(processorName, new Attribute("UseCache", Boolean.FALSE));

// adds a mime type
server.invoke(processorName, "addMimeType", new Object[] {".pdf", "application/pdf"}, new String[] {"java.lang.String", "java.lang.String"});
	
				

XSL Development

If you want to develop your own GUI, please refer to the xsl sources of the GUI delivered in the openjmx-tools.jar file

An important element to help you in the development are implicit param passed to the template. This includes all the request variables in the form of request.variable params. For instance with the follwing request

http://host.port/mbean?objectname=Test:name=test1&template=testmbean

There will be two paramaters request.objectname and request.template