jodd.lagarto.adapter.htmlstapler
Class HtmlStaplerBundlesManager

java.lang.Object
  extended by jodd.lagarto.adapter.htmlstapler.HtmlStaplerBundlesManager

public class HtmlStaplerBundlesManager
extends java.lang.Object

HTML resources bundles manager.


Nested Class Summary
static class HtmlStaplerBundlesManager.Strategy
           
 
Field Summary
protected  java.util.Map<java.lang.String,java.lang.String> actionBundles
           
protected  int bundleCount
           
protected  java.lang.String bundleFilenamePrefix
           
protected  java.lang.String bundleFolder
           
protected  java.lang.String contextPath
           
protected  boolean downloadLocal
           
protected  java.lang.String localAddressAndPort
           
protected  java.lang.String localFilesEncoding
           
protected  java.util.Map<java.lang.String,java.lang.String> mirrors
           
protected  boolean sortResources
           
protected  java.lang.String staplerServletPath
           
protected  HtmlStaplerBundlesManager.Strategy strategy
           
protected  java.lang.String webRoot
           
 
Constructor Summary
HtmlStaplerBundlesManager(javax.servlet.ServletContext servletContext, HtmlStaplerBundlesManager.Strategy strategy)
          Creates new instance, initialize it and stores it in servlet context.
 
Method Summary
protected  void createBundle(java.lang.String contextPath, java.lang.String actionPath, java.lang.String bundleId, java.util.List<java.lang.String> sources)
          Creates bundle file by loading resource files content.
protected  java.io.File createBundleFile(java.lang.String bundleId)
          Creates bundle file.
protected  java.lang.String createDigest(java.lang.String source)
          Creates digest i.e. bundle id from given string.
protected  java.lang.String fixCssRelativeUrls(java.lang.String content, java.lang.String src)
          Returns the content with all relative URLs fixed.
protected  java.lang.String fixRelativeUrl(java.lang.String url, java.lang.String offsetPath)
          For a given URL (optionally quoted), produces CSS URL where relative paths are fixed and prefixed with offsetPath.
 java.lang.String getBundleFilenamePrefix()
          Returns prefix of all bundle file names.
 java.lang.String getBundleFolder()
          Returns bundles folder.
static HtmlStaplerBundlesManager getBundlesManager(javax.servlet.http.HttpServletRequest servletRequest)
          Returns bundles manager.
static HtmlStaplerBundlesManager getBundlesManager(javax.servlet.ServletContext servletContext)
          Returns bundles manager from servlet context.
 java.lang.String getLocalAddressAndPort()
          Returns local address and port for downloading local resources.
 java.lang.String getLocalFilesEncoding()
          Returns local files encoding.
 java.lang.String getStaplerServletPath()
          Returns HtmlStaplerServlet servlet path.
 HtmlStaplerBundlesManager.Strategy getStrategy()
          Returns current strategy.
 java.lang.String getWebRoot()
          Returns current web root.
protected  boolean isCssResource(java.lang.String src)
          Returns true if resource is CSS, so the CSS urls can be fixed.
 boolean isDownloadLocal()
          Returns true if local resource files are downloaded and not loaded from file system.
protected  boolean isExternalResource(java.lang.String link)
          Returns true if resource link has to be downloaded.
 boolean isSortResources()
          Returns true if resources are sorted before bundle id (a digest) is created.
 java.io.File lookupBundleFile(java.lang.String bundleId)
          Lookups for bundle file.
 java.lang.String lookupBundleId(java.lang.String actionPath)
          Lookups for a bundle id for a given action.
protected  java.lang.String onResourceContent(java.lang.String content)
          Invoked before resource content is stored in the bundle.
 java.lang.String registerBundle(java.lang.String contextPath, java.lang.String actionPath, java.lang.String tempBundleId, java.util.List<java.lang.String> sources)
          Registers new bundle that consist of provided list of source paths.
 java.lang.String registerNewBundleId()
          Registers new, temporary bundle id for given action path.
 void reset()
          Clears all settings and removes all created bundle files from file system.
protected  java.lang.String resolveRealActionPath(java.lang.String actionPath)
          Resolves real action path for given one.
 void setBundleFilenamePrefix(java.lang.String bundleFilenamePrefix)
          Sets the prefix of bundle file names stored on disk.
 void setBundleFolder(java.lang.String bundleFolder)
          Sets bundle folder.
 void setDownloadLocal(boolean downloadLocal)
          Sets if local resource files should be downloaded or loaded from file system.
 void setLocalAddressAndPort(java.lang.String localAddressAndPort)
          Specifies local address and port for downloading local resources.
 void setLocalFilesEncoding(java.lang.String localFilesEncoding)
          Sets local files encoding.
 void setSortResources(boolean sortResources)
          Sets the resources sorting before bundle id (i.e. a digest) is created.
 void setStaplerServletPath(java.lang.String staplerServletPath)
          Sets registered path for HtmlStaplerServlet as registered in web.xml.
 void setWebRoot(java.lang.String webRoot)
          Sets web root, i.e. real path to the exploded files.
 BundleAction start(javax.servlet.http.HttpServletRequest servletRequest, java.lang.String bundleName)
          Starts bundle usage by creating new BundleAction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bundleCount

protected int bundleCount

actionBundles

protected java.util.Map<java.lang.String,java.lang.String> actionBundles

mirrors

protected java.util.Map<java.lang.String,java.lang.String> mirrors

localFilesEncoding

protected java.lang.String localFilesEncoding

webRoot

protected java.lang.String webRoot

bundleFolder

protected java.lang.String bundleFolder

staplerServletPath

protected java.lang.String staplerServletPath

bundleFilenamePrefix

protected java.lang.String bundleFilenamePrefix

localAddressAndPort

protected java.lang.String localAddressAndPort

downloadLocal

protected boolean downloadLocal

sortResources

protected boolean sortResources

contextPath

protected final java.lang.String contextPath

strategy

protected final HtmlStaplerBundlesManager.Strategy strategy
Constructor Detail

HtmlStaplerBundlesManager

public HtmlStaplerBundlesManager(javax.servlet.ServletContext servletContext,
                                 HtmlStaplerBundlesManager.Strategy strategy)
Creates new instance, initialize it and stores it in servlet context.

Method Detail

getBundlesManager

public static HtmlStaplerBundlesManager getBundlesManager(javax.servlet.http.HttpServletRequest servletRequest)
Returns bundles manager.


getBundlesManager

public static HtmlStaplerBundlesManager getBundlesManager(javax.servlet.ServletContext servletContext)
Returns bundles manager from servlet context.


start

public BundleAction start(javax.servlet.http.HttpServletRequest servletRequest,
                          java.lang.String bundleName)
Starts bundle usage by creating new BundleAction.


getStrategy

public HtmlStaplerBundlesManager.Strategy getStrategy()
Returns current strategy.


isSortResources

public boolean isSortResources()
Returns true if resources are sorted before bundle id (a digest) is created. When sorting is enabled, two pages will share the same bundle even if they list resources in different order.


setSortResources

public void setSortResources(boolean sortResources)
Sets the resources sorting before bundle id (i.e. a digest) is created.


getWebRoot

public java.lang.String getWebRoot()
Returns current web root.


setWebRoot

public void setWebRoot(java.lang.String webRoot)
Sets web root, i.e. real path to the exploded files. Web root is used to load local resource files.


getBundleFolder

public java.lang.String getBundleFolder()
Returns bundles folder. By default, it is a system temp folder.


setBundleFolder

public void setBundleFolder(java.lang.String bundleFolder)
Sets bundle folder.


getStaplerServletPath

public java.lang.String getStaplerServletPath()
Returns HtmlStaplerServlet servlet path. Must be the same as in web.xml.


setStaplerServletPath

public void setStaplerServletPath(java.lang.String staplerServletPath)
Sets registered path for HtmlStaplerServlet as registered in web.xml.


getBundleFilenamePrefix

public java.lang.String getBundleFilenamePrefix()
Returns prefix of all bundle file names.


setBundleFilenamePrefix

public void setBundleFilenamePrefix(java.lang.String bundleFilenamePrefix)
Sets the prefix of bundle file names stored on disk.


getLocalFilesEncoding

public java.lang.String getLocalFilesEncoding()
Returns local files encoding. By default its UTF8.


setLocalFilesEncoding

public void setLocalFilesEncoding(java.lang.String localFilesEncoding)
Sets local files encoding.


getLocalAddressAndPort

public java.lang.String getLocalAddressAndPort()
Returns local address and port for downloading local resources.


setLocalAddressAndPort

public void setLocalAddressAndPort(java.lang.String localAddressAndPort)
Specifies local address and port for downloading local resources. By default its "http://localhost:8080".


isDownloadLocal

public boolean isDownloadLocal()
Returns true if local resource files are downloaded and not loaded from file system.


setDownloadLocal

public void setDownloadLocal(boolean downloadLocal)
Sets if local resource files should be downloaded or loaded from file system.


createBundleFile

protected java.io.File createBundleFile(java.lang.String bundleId)
Creates bundle file.


lookupBundleFile

public java.io.File lookupBundleFile(java.lang.String bundleId)
Lookups for bundle file.


lookupBundleId

public java.lang.String lookupBundleId(java.lang.String actionPath)
Lookups for a bundle id for a given action. Returns null if action still has no bundle. Returns an empty string if action has an empty bundle.


registerNewBundleId

public java.lang.String registerNewBundleId()
Registers new, temporary bundle id for given action path. This id is used on first bundle usage, later it will be replaces with real bundle id.


registerBundle

public java.lang.String registerBundle(java.lang.String contextPath,
                                       java.lang.String actionPath,
                                       java.lang.String tempBundleId,
                                       java.util.List<java.lang.String> sources)
Registers new bundle that consist of provided list of source paths. Returns the real bundle id, as provided one is just a temporary bundle id.


createDigest

protected java.lang.String createDigest(java.lang.String source)
Creates digest i.e. bundle id from given string. Returned digest must be filename safe, for all platforms.


createBundle

protected void createBundle(java.lang.String contextPath,
                            java.lang.String actionPath,
                            java.lang.String bundleId,
                            java.util.List<java.lang.String> sources)
                     throws java.io.IOException
Creates bundle file by loading resource files content. If bundle file already exist it will not be recreated!

Throws:
java.io.IOException

isExternalResource

protected boolean isExternalResource(java.lang.String link)
Returns true if resource link has to be downloaded. By default, if resource link starts with "http://" or with "https://" it will be considered as external resource.


onResourceContent

protected java.lang.String onResourceContent(java.lang.String content)
Invoked before resource content is stored in the bundle. May be us used for additional resource processing, such as compressing, cleaning etc. By default it just returns unmodified content.


resolveRealActionPath

protected java.lang.String resolveRealActionPath(java.lang.String actionPath)
Resolves real action path for given one. When some URLs are dynamically created, many different links points to the same page. Use this to prevent memory leaking.


reset

public void reset()
Clears all settings and removes all created bundle files from file system.


isCssResource

protected boolean isCssResource(java.lang.String src)
Returns true if resource is CSS, so the CSS urls can be fixed.


fixCssRelativeUrls

protected java.lang.String fixCssRelativeUrls(java.lang.String content,
                                              java.lang.String src)
Returns the content with all relative URLs fixed.


fixRelativeUrl

protected java.lang.String fixRelativeUrl(java.lang.String url,
                                          java.lang.String offsetPath)
For a given URL (optionally quoted), produces CSS URL where relative paths are fixed and prefixed with offsetPath.



Copyright © 2003-2012 Jodd Team