Class LayoutLoader

java.lang.Object
cl.netswitch.lib.layout.LayoutLoader

public final class LayoutLoader extends Object
Collection of reusable Layout instances. If a required Layout is not in the collection, it is loaded from the specified layoutURI and added to the collection.

The layoutURI must contain at least one occurrence of the marker "*". Before each download, all occurrences of this marker are replaced with the name of the layout. In this way, the resulting URL gets targeted specifically to the required layout. Examples of valid URLs:

 http://www.netswitch.cl/layouts/*.jsp
 file:///C:/netswitch/layouts/*.asp
  • Constructor Details

    • LayoutLoader

      public LayoutLoader(URI layoutURI)
      Constructs a new LayoutLoader instance.
      Parameters:
      layoutURI - the URI used to download layouts.
      Throws:
      NullPointerException - if layoutURI is null.
      IllegalArgumentException - if layoutURI is invalid.
  • Method Details

    • layouts

      public Collection<Layout> layouts()
      Returns an unmodifiable collection with the layouts contained in this LayoutLoader.
      Returns:
      an unmodifiable collection with the layouts contained in this LayoutLoader.
    • clear

      public void clear()
      Clears (removes) all layouts from the cache.
    • getLayout

      public Layout getLayout(String name) throws Exception
      Returns a Layout with the specified name. If the Layout is not in the cache, it downloads its specification, compiles it, verifies its MD5 signature (or checksum), and then stores the resulting Layout in the cache.
      Parameters:
      name - name of the required Layout.
      Returns:
      the required Layout.
      Throws:
      NullPointerException - if name is null or empty.
      Exception - if an error occurs while loading the layout.
    • putLayout

      public void putLayout(Layout layout)
      Adds a layout to the collection of layouts of this LayoutLoader. The layout must be non-null and complete as defined by the Layout.isComplete() method.
      Parameters:
      layout - the layout to add to this LayoutLoader.
      Throws:
      NullPointerException - if layout is null.
      IllegalStateException - if layout is not complete.
    • download

      public String download(String name) throws Exception
      Downloads the specification of the Layout with the given name. The layout spacification will be downloaded from the location specified by the specified layoutURI.
      Parameters:
      name - the name of the required Layout.
      Returns:
      a string with the specification of the Layout.
      Throws:
      NullPointerException - if name is null.
      Exception - if an error occurs while loading the layout.