Class DocumentName

java.lang.Object
org.apache.rat.document.DocumentName
All Implemented Interfaces:
Comparable<DocumentName>
Direct Known Subclasses:
ArchiveEntryName

public class DocumentName extends Object implements Comparable<DocumentName>
The name for a document. The DocumentName is an immutable structure that handles all the intricacies of file naming on various operating systems. DocumentNames have several components:
  • root - where in the file system the name starts (e.g C:\ on Microsoft Windows). May be empty but not null.
  • dirSeparator - the separator between name segments (e.g. "\" on Microsoft Windows, "/" on linux). May not be empty or null.
  • name - the name of the file relative to the root. May not be null. Does NOT begin with a dirSeparator
  • baseName - the name of a directory or file from which this file is reported. A DocumentName with a name of "foo/bar/baz.txt" and a baseName of "foo" will be reported as "bar/baz.txt". May not be null.
  • isCaseSensitive - identifies if the underlying file system is case-sensitive.

DocumentNames are generally used to represent files on the files system. However, they are also used to represent files within an archive. When representing a file in an archive the baseName is the name of the enclosing archive document.

  • Method Details

    • builder

      public static DocumentName.Builder builder()
      Creates a Builder with the default file system info.
      Returns:
      the builder.
      See Also:
    • builder

      public static DocumentName.Builder builder(DocumentName.FSInfo fsInfo)
      Creates a builder with the specified FSInfo instance.
      Parameters:
      fsInfo - the FSInfo to use for the builder.
      Returns:
      a new builder.
    • builder

      public static DocumentName.Builder builder(FileSystem fileSystem)
      Creates a builder for the specified file system.
      Parameters:
      fileSystem - the file system to create the builder on.
      Returns:
      a new builder.
    • builder

      public static DocumentName.Builder builder(File file)
      Creates a builder from a File. The baseName is set to the file name if it is a directory otherwise it is set to the directory containing the file.
      Parameters:
      file - The file to set defaults from.
      Returns:
      the builder.
    • builder

      public static DocumentName.Builder builder(DocumentName documentName)
      Creates a builder from a document name. The builder will be configured to create a clone of the DocumentName.
      Parameters:
      documentName - the document name to set the defaults from.
      Returns:
      the builder.
    • asFile

      public File asFile()
      Creates a file from the fully qualified document name.
      Returns:
      a new File object.
    • asPath

      public Path asPath()
      Creates a path from the document name. This method uses the fully qualified name without the root. this results in a relative file name from the root.
      Returns:
      a new Path object.
    • resolve

      public DocumentName resolve(String child)
      Creates a new DocumentName by adding the child to the current name. Resulting documentName will have the same base name. Directory separator is normalized to the directory separator for this file system. If the child string:
      Is blank
      This DocumentName is returned.
      Starts with the file system root
      The root must match the root of this DocumentName and the directory structure must start with the directory structure of the basename for this DocumentName.
      Starts with the directory separator character
      Result will be a tree starting at the directory specified by the basename.
      Does not start with a directory separator character
      Result will be a tree starting at the directory specified by this DocumentName
      Parameters:
      child - the child to add (must use directory separator from this document name).
      Returns:
      the new document name with the same baseName, directory sensitivity and case sensitivity as this one.
      Throws:
      IllegalArgumentException - if the child specifies a different root from this document name.
    • getName

      public String getName()
      Gets the fully qualified name of the document.
      Returns:
      the fully qualified name of the document.
    • getPath

      public String getPath()
      Gets the path of the document. This is the fully qualified name without the root but starting with a path separator.
      Returns:
      the path of the document.
    • getBaseName

      public String getBaseName()
      Gets the fully qualified basename of the document.
      Returns:
      the fully qualified basename of the document.
    • getRoot

      public String getRoot()
      Gets the root for this document.
      Returns:
      the root for this document.
    • getBaseDocumentName

      public DocumentName getBaseDocumentName()
      Gets the DocumentName for the basename of this DocumentName.
      Returns:
      the DocumentName for the basename of this document name.
    • getDirectorySeparator

      public String getDirectorySeparator()
      Returns the directory separator.
      Returns:
      the directory separator.
    • fsInfo

      public DocumentName.FSInfo fsInfo()
      Returns the FSInfo for this document name.
      Returns:
      the FSInfo for this document name.
    • localized

      public String localized()
      Gets the portion of the name that is not part of the base name. The resulting name will always start with the directory separator.
      Returns:
      the portion of the name that is not part of the base name.
    • localized

      public String localized(String dirSeparator)
      Gets the portion of the name that is not part of the base name. The resulting name will always start with the directory separator.
      Parameters:
      dirSeparator - The character(s) to use to separate directories in the result.
      Returns:
      the portion of the name that is not part of the base name.
    • getShortName

      public String getShortName()
      Gets the last segment of the name. This is the part after the last directory separator.
      Returns:
      the last segment of the name.
    • isCaseSensitive

      public boolean isCaseSensitive()
      Gets the case sensitivity flag.
      Returns:
      true if the name is case-sensitive.
    • toString

      public String toString()
      Returns the localized file name.
      Overrides:
      toString in class Object
      Returns:
      the localized file name.
    • compareTo

      public int compareTo(DocumentName other)
      Specified by:
      compareTo in interface Comparable<DocumentName>
    • equals

      public final boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object