Class LayoutLoader

java.lang.Object
cl.obcom.desktopfx.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(Desktop desktop, URI layoutURI)
      Creates a new LayoutLoader instance.
      Parameters:
      desktop - the Desktop application instance.
      layoutURI - the URI used to download layouts.
      Throws:
      NullPointerException - if an argument 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.
    • getVerifyLayoutSignatures

      public boolean getVerifyLayoutSignatures()
      Returns true if the signatures of downloaded layouts are verified.
      Returns:
      true if the signatures of downloaded layouts are verified.
    • setVerifyLayoutSignatures

      public void setVerifyLayoutSignatures(boolean value)
      Changes whether the signatures of downloaded layouts are verified.
      Parameters:
      value - if true the signatures of downloaded layouts will be verified. Otherwise the signatures will be assigned to layouts without verification.
    • getLayout

      public Layout getLayout(String name) throws Exception
      Returns the Layout with the specified name. If the layout is not available in the cache, it is downloaded, compiled, stored in the cache and returned to the caller of this method. The signature of the downloaded layout will be verified if getVerifyLayoutSignatures() returns true, otherwise the signature will be assigned to the layout without verification.
      Parameters:
      name - name of the required Layout.
      Returns:
      the Layout with the specified name.
      Throws:
      NullPointerException - if name is null.
      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.
      IllegalArgumentException - 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.