XMLgate servlet 1.5

    It is a generic Java servlet that uses XSLT to provide final content from the given XML source and associated XSL stylesheet. You have to provide for this servlet a configuration file, where you can describe your XML data, XSL stylesheets and business rules how to proceed requests. Rules are parameterized by parameters from request's header (User-Agent and Accept). In other words each rule looks like: "if User-Agent is ... then use this XML data with this XSL stylesheet" or "if client accepts such content-type then use this XML data with this XSL stylesheet".
So for example depending on incoming request XMLgate can convert XML source into specific content (WML,HTML etc.) viewable for the device raised this request.

    the usage is standard:

a) copy XMLgatePackage.jar into WEB-INF/lib

b) describe XMLgate servlet in web.inf file. You must set an initial parameter for this servlet. Parameter name is config. This parameter describes a configuration file for XMLgate:
 


    <servlet>
     <servlet-name>XMLgate</servlet-name>
     <servlet-class>com.jsos.xmlgate.XMLgate</servlet-class>
     <init-param>
      <param-name>config</param-name>
      <param-value>path_to_your_configuration_file</param-value>
     </init-param>
    </servlet>

c) define a mapping:
 

    <servlet-mapping>
     <servlet-name>XMLgate</servlet-name>
     <url-pattern>/servlet/XMLgate</url-pattern>
    </servlet-mapping>

Now you can use this servlet:
 


    http://your_host/servlet/XMLgate

also you can pass configuration file as a parameter:
 


    http://your_host/servlet/XMLgate?config=path_to_your_configuration_file

Configuration file is XML file. You must define the following elements:
  - cache directory: any existing directory on your server for cached data.
  - one or more XML data sources. Source could be local (e.g.: c:/mydata/myfile.xml) or remote (e.g. : http://www.acme.com/source.xml)
  - one or more XSL data source. Source again could be local or remote
  - one or more business rules (how to select < XML,XSL > pair for the given request)
  - default response ( < XML,XSL > pair if all rules are failed).

Config => (cache, +xmlsource, +xslsource, +rule, default)

cache - defines cache directory. It is some existing directory on your server. Note: all files from this directory will be deleted!. E.g.:

<cache>c:/xml/tmp</cache>

xmlsource - defines xml source. Could be local or remote. Attributes are: name - unique name, cache - cache policy. Possible values are: -1 - static data, will be cached after the first usage, 0 - means no-cache, any positive integer value - defines cache time in seconds. E.g.:

<xmlsource name="first" cache="-1">c:/data/file1.xml</xmlsource>
<xmlsource name="second" cache="600">c:/data/file2.xml</xmlsource>

xslsource - defines xsl sheet. Could be local or remote. Attributes are: name - unique name, cache - cache policy. Possible values are: -1 - static data, will be cached after the first usage, 0 - means no-cache, any positive integer value - defines cache time in seconds. E.g.:

<xslsource name="first" cache="-1">c:/data/file1.xsl</xmlsource>
<xmlsource name="second" cache="0">http://www.acme.com/data.xsl</xmlsource>

rule - defines rule (condition, trigger). There are two forms:
   a) if user-agent header contains this string then use that pair of <XML-source, XSL-source> and that content-type for the output. E.g.: if user-agent header contains string MSIE than set content type to text/html and use the described pair of XML-source and XSL-source.

<rule agent="MSIE" xml="second" xsl="first" type="text/html"/>

   a) if accept header contains this string then use that pair of <XML-source, XSL-source> and that content-type for the output. E.g.: if client accepts wap.wml than set content type to text/vnd.wap.wml and use XML source with name first and XSL source with name second:

<rule accept="wap.wml" xml="first" xsl="second" type="text/vnd.wap.wml"/>

Attributes are: accept - defines accept header, agent - defines user-agent header, xml - xml source name, xsl - xsl source name, type - defines content-type for output.

default - defines default transformation (if all conditions are failed). Attributes are: xml - xml source name, xsl - xsl source name, type - defines content-type for output. E.g.:

<default xml="xml0" xsl="xsl0" type="text/html"/>

Notes:

1. Servlet uses JAXP for parsing XML files.

2. Config file can be saved anywhere on your server. You may use the full path for setting data file location.

    For downloading: 

    XMLgate package:  XMLgatePackage.jar   
    Sample of config file:  xmlgate.xml
 

  © Coldbeans     Comments?

See also JSOS - the largest collection of servlets and filters.

Also in Coldtags: