Class DocumentName
java.lang.Object
org.apache.rat.document.DocumentName
- All Implemented Interfaces:
Comparable<DocumentName>
- Direct Known Subclasses:
ArchiveEntryName
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 theroot. May not be null. Does NOT begin with adirSeparatorbaseName- the name of a directory or file from which this file is reported. A DocumentName with anameof "foo/bar/baz.txt" and abaseNameof "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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classThe Builder for a DocumentName.static final classThe file system information needed to process document names. -
Method Summary
Modifier and TypeMethodDescriptionasFile()Creates a file from the fully qualified document name.asPath()Creates a path from the document name.static DocumentName.Builderbuilder()Creates a Builder with the default file system info.static DocumentName.BuilderCreates a builder from a File.static DocumentName.Builderbuilder(FileSystem fileSystem) Creates a builder for the specified file system.static DocumentName.Builderbuilder(DocumentName documentName) Creates a builder from a document name.static DocumentName.Builderbuilder(DocumentName.FSInfo fsInfo) Creates a builder with the specified FSInfo instance.intcompareTo(DocumentName other) final booleanfsInfo()Returns the FSInfo for this document name.Gets the DocumentName for the basename of this DocumentName.Gets the fully qualified basename of the document.Returns the directory separator.getName()Gets the fully qualified name of the document.getPath()Gets the path of the document.getRoot()Gets the root for this document.Gets the last segment of the name.final inthashCode()booleanGets the case sensitivity flag.Gets the portion of the name that is not part of the base name.Gets the portion of the name that is not part of the base name.Creates a new DocumentName by adding the child to the current name.toString()Returns the localized file name.
-
Method Details
-
builder
Creates a Builder with the default file system info.- Returns:
- the builder.
- See Also:
-
builder
Creates a builder with the specified FSInfo instance.- Parameters:
fsInfo- the FSInfo to use for the builder.- Returns:
- a new builder.
-
builder
Creates a builder for the specified file system.- Parameters:
fileSystem- the file system to create the builder on.- Returns:
- a new builder.
-
builder
Creates a builder from a File. ThebaseNameis 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
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
Creates a file from the fully qualified document name.- Returns:
- a new File object.
-
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
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
Gets the fully qualified name of the document.- Returns:
- the fully qualified name of the document.
-
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
Gets the fully qualified basename of the document.- Returns:
- the fully qualified basename of the document.
-
getRoot
-
getBaseDocumentName
Gets the DocumentName for the basename of this DocumentName.- Returns:
- the DocumentName for the basename of this document name.
-
getDirectorySeparator
Returns the directory separator.- Returns:
- the directory separator.
-
fsInfo
Returns the FSInfo for this document name.- Returns:
- the FSInfo for this document name.
-
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
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
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:
trueif the name is case-sensitive.
-
toString
-
compareTo
- Specified by:
compareToin interfaceComparable<DocumentName>
-
equals
-
hashCode
-