Class MetadataResourceEngine

java.lang.Object
com.bc.ceres.metadata.MetadataResourceEngine

public class MetadataResourceEngine extends Object
A engine for processing text resources using velocity. It supports:
  • reading resources in XML or property format
  • reading of resources belonging to source(s)
  • allows to manipulate the used velocity context
  • writing the context using given templates
Since:
Ceres 0.13.2
  • Constructor Details

    • MetadataResourceEngine

      public MetadataResourceEngine(SimpleFileSystem simpleFileSystem)
      Creates the metadata engine.
      Parameters:
      simpleFileSystem - A abstraction of the used filesystem.
    • MetadataResourceEngine

      public MetadataResourceEngine(SimpleFileSystem simpleFileSystem, MetadataResourceResolver metadataResourceResolver)
      Creates the metadata engine.
      Parameters:
      simpleFileSystem - A abstraction of the used filesystem.
      metadataResourceResolver - A resolver for metadata resource names..
  • Method Details

    • getVelocityContext

      public org.apache.velocity.VelocityContext getVelocityContext()
      Return the used velocity context.
      Returns:
      the velocity context
    • readResource

      public Resource readResource(String name, String path) throws IOException
      Reads the resource with the given path and stores its content in the velocity context using the given key. If evaluate is set to true. The content will be evaluated using the current state of the velocity context.
      Parameters:
      name - The name under which the metadata are placed into the velocity context
      path - The path name of the metadata resource
      Returns:
      The resource
      Throws:
      IOException - If an I/O error occurs
    • readRelatedResource

      public void readRelatedResource(String sourceId, String sourcePath) throws IOException
      Reads the all metadata file belonging to the given source item and places them into a map registered as 'sourceMetadata' the velocity context. The 'sourceMetadata'-map contains the processed metadata files as another map. The map of metadata files can be retrieved using the key 'sourceId'.

      Metadata files belong to a source if they follow a naming pattern: For a given sourcePath "chl_a.nc", e.g. "chl_a-metadata.xml" and "chl_a-report.html" are considered.

      Parameters:
      sourceId - The name under which the metadata are placed in the 'sourceMetadata'-map
      sourcePath - The path name of the source item
      Throws:
      IOException - If an I/O error occurs
    • writeRelatedResource

      public void writeRelatedResource(String templatePath, String targetPath) throws IOException
      Writes metadata belonging to the given target item. For this the velocity template is evaluated using the current context.

      The target metadata files follow a naming pattern: For a given templatePath "report.xml.vm" and targetPath "chl_a.nc" a target metadata file "chl_a-report.xml" gets written.

      Parameters:
      templatePath - The path name of the velocity template
      targetPath - The path name of the target item
      Throws:
      IOException - If an I/O error occurs