Package org.pentaho.reporting.libraries.repository

## Class RepositoryUtilities

- java.lang.Object
- - org.pentaho.reporting.libraries.repository.RepositoryUtilities

-     public class RepositoryUtilities
      extends java.lang.Object

  A collection of repository related helper methods that make it easier to work with repositories.
  Author:
    Thomas Morgner

- - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `static java.lang.String` | `buildName​(ContentEntity entity, java.lang.String separator)` | Builds a string of an absolute pathname for the given entity and using the given separator to separate filename segments..
    `static java.lang.String[]` | `buildNameArray​(ContentEntity entity)` | Builds a absolute pathname for the given entity.
    `static ContentItem` | `createItem​(Repository repository, java.lang.String[] name)` | Tries to create a content item with the given path-name in the repository.
    `static ContentLocation` | `createLocation​(Repository repository, java.lang.String[] name)` | Tries to create a content location with the given path-name in the repository.
    `static ContentEntity` | `getEntity​(Repository repository, java.lang.String[] name)` | Returns the content entity for the given path name.
    `static int` | `getZipLevel​(ContentItem item)` | Computes the declared Zip-Compression level for the given content-item.
    `static int` | `getZipMethod​(ContentItem item)` | Computes the declared Zip-Compression mode for the given content-item.
    `static boolean` | `isExistsEntity​(Repository repository, java.lang.String[] name)` | Checks whether a given pathname points to a valid content entity.
    `static boolean` | `isInvalidPathName​(java.lang.String name)` | Checks whether the given entity name is valid for filesystems.
    `static java.lang.String[]` | `split​(java.lang.String name, java.lang.String separator)` | Splits a string on the given separator.
    `static java.lang.String[]` | `splitPath​(java.lang.String name, java.lang.String separator)` | Splits a string on the given separator.
    `static void` | `writeAsZip​(java.io.OutputStream outputStream, Repository repository)` | Writes the given repository as ZIP-File into the given output stream.
    `static void` | `writeToZipStream​(java.util.zip.ZipOutputStream zipOutputStream, Repository repository)` | Writes the given repository to the given ZIP-output stream.

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### getEntity

          public static ContentEntity getEntity​(Repository repository,
                                                java.lang.String[] name)
                                         throws ContentIOException

      Returns the content entity for the given path name.
      Parameters:
        `repository` - the repository from where to retrieve the content entity.
        `name` - the path name as array of name-segments.
      Returns:
        the entity at the position, never null.
      Throws:
        `ContentIOException` - if the path did not point to a valid content entity.
      See Also:
        `splitPath(String, String)`

    - #### isExistsEntity

          public static boolean isExistsEntity​(Repository repository,
                                               java.lang.String[] name)
                                        throws ContentIOException

      Checks whether a given pathname points to a valid content entity.
      Parameters:
        `repository` - the repository from where to retrieve the content entity.
        `name` - the path name as array of name-segments.
      Returns:
        true, if the entity exists, false otherwise.
      Throws:
        `ContentIOException` - if an unexpected repository error occured.
      See Also:
        `splitPath(String, String)`

    - #### createItem

          public static ContentItem createItem​(Repository repository,
                                               java.lang.String[] name)
                                        throws ContentIOException

      Tries to create a content item with the given path-name in the repository. This call will succeed if and only if all but the last segment of the name point to Content-Locations and if the content-item does not yet exist.
      Parameters:
        `repository` - the repository in which a new entity should be created.
        `name` - the name of the new entity as path name.
      Returns:
        the newly created content-item.
      Throws:
        `ContentIOException` - if an repository error occured or if the path was not valid.

    - #### createLocation

          public static ContentLocation createLocation​(Repository repository,
                                                       java.lang.String[] name)
                                                throws ContentIOException

      Tries to create a content location with the given path-name in the repository. This call will succeed if and only if all but the last segment of the name point to Content-Locations and if the content-entity does not yet exist.
      Parameters:
        `repository` - the repository in which a new entity should be created.
        `name` - the name of the new entity as path name.
      Returns:
        the newly created content-location.
      Throws:
        `ContentIOException` - if an repository error occured or if the path was not valid.

    - #### splitPath

          public static java.lang.String[] splitPath​(java.lang.String name,
                                                     java.lang.String separator)

      Splits a string on the given separator. Multiple occurences of the separator are unified into a single separator.
      Parameters:
        `name` - the path name.
        `separator` - the separator on which to split.
      Returns:
        the name as array of atomar path elements.

    - #### split

          public static java.lang.String[] split​(java.lang.String name,
                                                 java.lang.String separator)

      Splits a string on the given separator. Multiple occurences of the separator result in empty strings as path elements in the returned array.
      Parameters:
        `name` - the path name.
        `separator` - the separator on which to split.
      Returns:
        the name as array of atomar path elements.

    - #### buildNameArray

          public static java.lang.String[] buildNameArray​(ContentEntity entity)

      Builds a absolute pathname for the given entity.
      Parameters:
        `entity` - the entity for which the pathname should be computed.
      Returns:
        the absolute path.

    - #### buildName

          public static java.lang.String buildName​(ContentEntity entity,
                                                   java.lang.String separator)

      Builds a string of an absolute pathname for the given entity and using the given separator to separate filename segments..
      Parameters:
        `entity` - the entity for which the pathname should be computed.
        `separator` - the filename separator.
      Returns:
        the absolute path.

    - #### isInvalidPathName

          public static boolean isInvalidPathName​(java.lang.String name)

      Checks whether the given entity name is valid for filesystems. This method rejects filenames that either contain a slash ('/') or backslash ('\') which both are commonly used path-separators and it rejects filenames that contain only dots (as the dot names are used as directory traversal names).
      Parameters:
        `name` - the filename that should be tested. This name must be a single name section, not a full path.
      Returns:
        true, if the pathname is valid, false otherwise.

    - #### writeAsZip

          public static void writeAsZip​(java.io.OutputStream outputStream,
                                        Repository repository)
                                 throws java.io.IOException,
                                        ContentIOException

      Writes the given repository as ZIP-File into the given output stream.
      Parameters:
        `outputStream` - the output stream that should receive the zipfile.
        `repository` - the repository that should be written.
      Throws:
        `java.io.IOException` - if an IO error prevents the writing of the file.
        `ContentIOException` - if a repository related IO error occurs.

    - #### writeToZipStream

          public static void writeToZipStream​(java.util.zip.ZipOutputStream zipOutputStream,
                                              Repository repository)
                                       throws java.io.IOException,
                                              ContentIOException

      Writes the given repository to the given ZIP-output stream.
      Parameters:
        `zipOutputStream` - the output stream that represents the ZipFile to be generated.
        `repository` - the repository that should be written.
      Throws:
        `java.io.IOException` - if an IO error prevents the writing of the file.
        `ContentIOException` - if a repository related IO error occurs.

    - #### getZipLevel

          public static int getZipLevel​(ContentItem item)

      Computes the declared Zip-Compression level for the given content-item. If the content-items attributes do not contain a definition, the default compression is used instead.
      Parameters:
        `item` - the content item for which the compression factor should be computed.
      Returns:
        the compression level.

    - #### getZipMethod

          public static int getZipMethod​(ContentItem item)

      Computes the declared Zip-Compression mode for the given content-item. If the content-items attributes do not contain a valid definition, the default compression is used instead.
      Parameters:
        `item` - the content item for which the compression mode should be computed.
      Returns:
        the compression mode, either ZipOutputStream.DEFLATED or ZipOutputStream.STORED.