public class I18nModuleBuilder extends JavaScriptModuleBuilder
JavaScriptModuleBuilder
to add support for expanding
the response for root level (non-locale specific) i18n requests to include the
local specific versions of the requested resource for the locales specified in
the request.
Expanding the response to include resources that were not requested requires the module names be exported in the define functions of anonymous modules, so don't do this if exporting module names is disabled, or if the optimization level is 'none'.
IExtensionInitializer.IExtensionRegistrar
ILayerListener.EventType
Modifier and Type | Field and Description |
---|---|
static String |
OPTION_DISABLE_LOCALE_EXPANSION |
MODULE_EXPANDED_DEPS
Constructor and Description |
---|
I18nModuleBuilder() |
Modifier and Type | Method and Description |
---|---|
ModuleBuild |
build(String mid,
IResource resource,
javax.servlet.http.HttpServletRequest request,
List<ICacheKeyGenerator> keyGens)
Returns a
ModuleBuild object containing the processed (built)
output for the requested module. |
protected IAggregator |
getAggregator() |
List<ICacheKeyGenerator> |
getCacheKeyGenerators(IAggregator aggregator)
This method may be called, before
IModuleBuilder.build(String, IResource, HttpServletRequest, List)
is called by a separate worker thread, to obtain a cache key generator
for this builder. |
protected List<String> |
getExpandedModules(String mid,
IResource resource,
javax.servlet.http.HttpServletRequest request,
List<ICacheKeyGenerator> keyGens) |
boolean |
handles(String mid,
IResource resource)
Returns true if this module builder handles the specified resource
|
String |
layerBeginEndNotifier(ILayerListener.EventType type,
javax.servlet.http.HttpServletRequest request,
List<IModule> modules,
Set<String> dependentFeatures)
Listener notification callback that is called for the event specified by
type . |
generateModuleIdReg, getCacheKeyGenerators, getCompilationLevel, getJSSource, initialize, isScript, moduleNameIdEncodingBeginAMD, moduleNameIdEncodingBeginLayer, moduleNameIdEncodingEndLayer, shutdown
public static String OPTION_DISABLE_LOCALE_EXPANSION
public ModuleBuild build(String mid, IResource resource, javax.servlet.http.HttpServletRequest request, List<ICacheKeyGenerator> keyGens) throws Exception
IModuleBuilder
ModuleBuild
object containing the processed (built)
output for the requested module.
If an error occurs, this method can throw an exception, or else let an exception that occurs at a lower level propagate up. How the exception gets handled depends largely on whether or not development mode is enabled.
If development mode is not enabled, then the exception is converted to a ServletException and allowed to propagate to the servlet container. This will result in an error response being returned to the client.
If development mode is enabled, then exceptions thrown by this method are handled by creating a module build containing code to invoke console.error() on the client, specifying the exception message as the error text, and the aggregated response is flagged as an error response to prevent caching of the response either on the server or on the client. The content value which is returned by the define function is an empty string.
If a builder would like to handle errors in development mode differently,
either by providing partial content or to have more control over what is
displayed in the client console, then this method can return the error
content in the build output and use the ModuleBuild
constructor
that allows you to specify an error flag. Specifying true for the error
flag will cause the aggregated response containing this module build to
be flagged as an error and the build output will not be cached either on
the server or on the client.
If the request attribute specified by
IHttpTransport.EXPORTMODULENAMES_REQATTRNAME
is false, then this
method SHOULD return an anonymous module, however, if the request
attribute is true, then this method MUST return a named module (the first
parameter of the define function for the module must be the value
specified by mid
).
If, for some reason, a module builder is unable to provide named modules
for a request, then the module builder should register a
ILayerListener
service with the OSGi service registry,
specifying the name of the aggregator as the name
property of the
service, and then set the value of the
IHttpTransport.EXPORTMODULENAMES_REQATTRNAME
request attribute to
false in the
ILayerListener.layerBeginEndNotifier(ILayerListener.EventType, HttpServletRequest, List, Set)
method.
This method may choose to return a build containing multiple named
modules if the request attribute specified by
IHttpTransport.EXPORTMODULENAMES_REQATTRNAME
is true. A builder
that provides i18n resource modules, for example, may choose to include
additional, locale specific, resource modules based on the request
locale(s), however, this may only be done if all the modules in a
response are named. If anonymous modules are being requested (i.e. the
request attribute specified by
IHttpTransport.EXPORTMODULENAMES_REQATTRNAME
is false), then only
the requested module may be included in the build output, regardless of
whether or not the module builds provided by this builder are named.
The module builder may update one or more of the cache key generators in
keyGens
by specifying a new list of cache key generators in
the returned ModuleBuild
object. When a new list is provided,
the cached cache key generator list for this module, and any layers
containing this module, are updated. If this method returns the same list
object specified by keyGens
in the ModuleBuild
, then no updates of the cached key generators are performed. Most module
builders will have no need to update a cached key generator list once it
has been created and should just return
keyGens
in the ModuleBuild
object, however, if
keyGens
is null,
then a new cache key generator list containing only non-provisional
cache key generators MUST be provided in the returned ModuleBuild
.
A module builder should always return the same sized cache key generator
list for any given resource, and the cache key generators in the list
must be the same class, and in the same sequence, for all responses for
the same resource. Note that subclasses of this class may add their own
cache key generators to the result list, so keyGens
may be
larger than what this method previously returned because it contains
contributions from the subclasses. If this class wishes to update the
cache key generator list, it should not try to include any of these
added cache key generators in the new list. It should only include its
own cache key generators. Subclasses are responsible for detecting that
the superclass has updated the list in the result and then adding their
own cache key generators to the new result.
build
in interface IModuleBuilder
build
in class JavaScriptModuleBuilder
mid
- The module idresource
- The resource object for the source module.request
- The HTTP request objectkeyGens
- List of cache key generators for this module that was
obtained by a previous call to this method or
IModuleBuilder.getCacheKeyGenerators(IAggregator)
. If null,
then the ModuleBuild
returned by this method must
specify a new list of non-provisional cache key generators,
otherwise, this method may return a ModuleBuild
object
that specifies keyGen
for the cache key generator.ModuleBuild
objectException
protected List<String> getExpandedModules(String mid, IResource resource, javax.servlet.http.HttpServletRequest request, List<ICacheKeyGenerator> keyGens) throws IOException
IOException
public String layerBeginEndNotifier(ILayerListener.EventType type, javax.servlet.http.HttpServletRequest request, List<IModule> modules, Set<String> dependentFeatures)
ILayerListener
type
. If the returned string is not null, then the value
will be added to the response stream either before, or after, the layer
content, depending on the event type.layerBeginEndNotifier
in interface ILayerListener
layerBeginEndNotifier
in class JavaScriptModuleBuilder
type
- Indicates whether a layer is starting or finishing.request
- The HTTP request object.modules
- The list of modules in the layer. Note that modules added to
the layer by module builders using the
ModuleBuild.addExtraModule(String)
in the list. For the BEGIN_MODULE event, the list contains
only the single module that is being added to the layer.dependentFeatures
- Output - If the returned value depends on any features specified
in the request, then those features should be added to
dependentFeatures
. These will be included in the
construction of the cache key for the layer.public List<ICacheKeyGenerator> getCacheKeyGenerators(IAggregator aggregator)
IModuleBuilder
IModuleBuilder.build(String, IResource, HttpServletRequest, List)
is called by a separate worker thread, to obtain a cache key generator
for this builder. If cache keys for this builder depend on module
content, then this method should return a provisional cache key
generator, which generates cache keys based on information in the request
only. Provisional cache keys may be more exclusive than non-provisional
cache keys in matching requests to module builds.
If this method returns a provisional cache key generator, then
IModuleBuilder.build(String, IResource, HttpServletRequest, List)
will be called with a null cache key generator list and that method
MUST return a
ModuleBuild
object with a new immutable list of non-provisional cache key
generators when subsequently called for the same request.
getCacheKeyGenerators
in interface IModuleBuilder
getCacheKeyGenerators
in class JavaScriptModuleBuilder
aggregator
- The aggregator instancepublic boolean handles(String mid, IResource resource)
IModuleBuilder
handles
in interface IModuleBuilder
handles
in class JavaScriptModuleBuilder
mid
- the module idresource
- the resource for the module idprotected IAggregator getAggregator()
Copyright © 2011-2015 IBM. All Rights Reserved.