Class LanguageShuntFactory

All Implemented Interfaces:

public class LanguageShuntFactory
extends java.lang.Object
implements ShuntFactory

LanguageShuntFactory produces Shunts which determine mode based on the Accept-Language header submitted by the user agent.

Modes can be specified as "en", "fr", "zh-hk", and the like. Multiple modes can be assigned to the same view by comma-delimiting them ("en,fr"). In addition, a view can leave its mode unspecified to be a "default" view which will apply when no other mode is appropriate.

Choosing mode from the Accept-Language header follows the way browsers actually work rather than the HTTP spec. Go figure. There is no support for quality levels and preference is determined by simple order in the string. Furthermore, there is some magic regarding prefixed languages: After trying each of the languages specified, any prefixed languages are chopped one level and tried again. This process is repeated until nothing is left to try but the null mode.

For an example Accept-Language header "fr,zh-tw,zh-hk,no-nynorsk", the Shunt will check for modes in this order:

  1. fr
  2. zh-tw
  3. zh-hk
  4. no-nynorsk
  5. zh
  6. no
  7. the "null" mode

Hopefully this produces useful behavior.

Constructor Summary
Method Summary
 Shunt createShunt()
          Merely creates a shunt object.
 void init(org.jdom.Element factoryNode, javax.servlet.ServletConfig servletCfg)
          Does nothing.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public LanguageShuntFactory()
Method Detail


public void init(org.jdom.Element factoryNode,
                 javax.servlet.ServletConfig servletCfg)
Does nothing.

Specified by:
init in interface ShuntFactory
factoryNode - The XML element (and child nodes) configured in the Maverick configuration file.
servletCfg - So that the factory can get information from the container.


public Shunt createShunt()
                  throws ConfigException
Merely creates a shunt object.

Specified by:
createShunt in interface ShuntFactory
A new, empty shunt.
ConfigException - If something is wrong with the configuration.