Home of: [Atelier "FUJIGURUMA"] >> [PageMixer hosted by SourceForge.net]

SEE "For Readers of English Version",
or Japanese version of this page

Get 'InputStream'

This section explains how to customize getting InputStream, to create Producer, with PageServlet.

Overview

Class diagram

Class diagram in this section is shown below:

Class diagram
Class diagram (click for large figure)

Classes which you must define are colored, and other are already defined.

Class names

In this tutorial, abbreviated class names are used. Complete names are shown below.

Classes of PageMixer framework

NotationFull name
ClassLoaderLocator jp.ne.dti.lares.foozy.pagemixer.page.ClassLoaderLocator
LocalFSLocator jp.ne.dti.lares.foozy.pagemixer.page.LocalFSLocator
Locator jp.ne.dti.lares.foozy.pagemixer.page.Locator
LocatorFactory jp.ne.dti.lares.foozy.pagemixer.servlet.LocatorFactory
PageServlet jp.ne.dti.lares.foozy.pagemixer.servlet.PageServlet
Producer jp.ne.dti.lares.foozy.pagemixer.mixer.Producer
ServletContextLocator jp.ne.dti.lares.foozy.pagemixer.servlet.ServletContextLocator
WebAppLocator jp.ne.dti.lares.foozy.pagemixer.servlet.WebAppLocator

Tutorial specific classes

No tutorial specific class is explained in this section.

Purpose of customization

Please see "Render locale sensitively" section for detail about getting InputStream as 'resource' management.

Choose Locator implementation

PageMixer provides "LocatorFactory" for customization of getting InputStream of 'resource'. LocatorFactory is used to create Locator.

In addition to ClassLoaderLocator and LocalFSLocator explained in "Render locale sensitively", PageMixer provides ServletContextLocator and WebAppLocator for Servlet environment. And LocatorFactory default implementation chooses one of them by configuration(as explained later).

ServletContextLocator is derived from ClassLoaderLocator.

This tries to get InputStream by getResourceAsStream of ServletContext at first. Then this invokes getInputStream(String) of base class.

WebAppLocator is derived from LocalFSLocator.

This passes getRealPath("") result of ServletContext as base directory to constructor of LocalFSLocator. So, this tries to get InputStream of resoures under own web application directory.

ServletContextLocator can not examine whether resource base of InputStream is modified or not since last access, so can not allow you to "reload" resource. In other hand, Servlet container, which does not make extracted WAR image on runtime, may not allow you to use WebAppLocator. But I do not know such implementation.

Please see API document and source code of them about detail to define custom LocatorFactory, even though you may satisfy your needs by pre-defined classes in almost all cases.

Configuration

Parameters for base class

LocatorFactory accepts Servet initialize parameter(s) shown below:

name description
locator.reloadable whether Servlet wants to reload resource when modified. in other words, this causes choice of WebAppLocator if this is "true", or ServletContextLocator otherwise. default value of this is "true".

Parameter to use choosen class

To use your custom LocatorFactory, you should specify "servlet.locatorFactory" Servlet init-param in deployment descriptor as shown below.


<init-param>
  <param-name>
    servlet.locatorFactory
  </param-name>
  <param-value>
    name of your custom LocatorFactory
  </param-value>
</init-param>

Specify custom LocatorFactory

To next section "Create 'Producer'"