jodd.lagarto.htmlstapler
Class HtmlStaplerBundlesManager

java.lang.Object
  extended by jodd.lagarto.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 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 notFoundExceptionEnabled
           
protected  boolean sortResources
           
protected  java.lang.String staplerPath
           
protected  HtmlStaplerBundlesManager.Strategy strategy
           
protected  java.lang.String webRoot
           
 
Constructor Summary
HtmlStaplerBundlesManager(java.lang.String contextPath, java.lang.String webRoot, HtmlStaplerBundlesManager.Strategy strategy)
          Creates new instance and initialize it.
 
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 in bundleFolder/staplerPath.
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 getBundleFolder()
          Returns bundles folder.
 java.lang.String getLocalAddressAndPort()
          Returns local address and port for downloading local resources.
 java.lang.String getLocalFilesEncoding()
          Returns local files encoding.
 java.lang.String getStaplerPath()
          Returns stapler 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 isNotFoundExceptionEnabled()
          Returns true if exception will be thrown when resource is not found.
 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.
 java.io.File lookupGzipBundleFile(java.io.File file)
          Locates gzipped version of bundle file.
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.lang.String bundleContentType, 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 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 setNotFoundExceptionEnabled(boolean notFoundExceptionEnabled)
          Sets if exception should be thrown when some resource is not found.
 void setSortResources(boolean sortResources)
          Sets the resources sorting before bundle id (i.e. a digest) is created.
 void setStaplerPath(java.lang.String staplerPath)
          Sets stapler path.
 BundleAction start(java.lang.String servletPath, 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

webRoot

protected final java.lang.String webRoot

contextPath

protected final java.lang.String contextPath

strategy

protected final HtmlStaplerBundlesManager.Strategy strategy

localFilesEncoding

protected java.lang.String localFilesEncoding

bundleFolder

protected java.lang.String bundleFolder

staplerPath

protected java.lang.String staplerPath

localAddressAndPort

protected java.lang.String localAddressAndPort

downloadLocal

protected boolean downloadLocal

sortResources

protected boolean sortResources

notFoundExceptionEnabled

protected boolean notFoundExceptionEnabled
Constructor Detail

HtmlStaplerBundlesManager

public HtmlStaplerBundlesManager(java.lang.String contextPath,
                                 java.lang.String webRoot,
                                 HtmlStaplerBundlesManager.Strategy strategy)
Creates new instance and initialize it.

Method Detail

start

public BundleAction start(java.lang.String servletPath,
                          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.


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.


getStaplerPath

public java.lang.String getStaplerPath()
Returns stapler path. It is both the file system folder name and the web folder name.


setStaplerPath

public void setStaplerPath(java.lang.String staplerPath)
Sets stapler path.


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.


isNotFoundExceptionEnabled

public boolean isNotFoundExceptionEnabled()
Returns true if exception will be thrown when resource is not found.


setNotFoundExceptionEnabled

public void setNotFoundExceptionEnabled(boolean notFoundExceptionEnabled)
Sets if exception should be thrown when some resource is not found. If not enabled, the error will be logged as a warning.


createBundleFile

protected java.io.File createBundleFile(java.lang.String bundleId)
Creates bundle file in bundleFolder/staplerPath. Only file object is created, not the file content.


lookupBundleFile

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


lookupGzipBundleFile

public java.io.File lookupGzipBundleFile(java.io.File file)
                                  throws java.io.IOException
Locates gzipped version of bundle file. If gzip file does not exist, it will be created.

Throws:
java.io.IOException

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.lang.String bundleContentType,
                                       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