D
- The document typepublic class DocumentFileSource<D> extends Object implements DocumentSource<D>
DocumentDescriptor.getDependencies()
.
Documents added to the file source exist only in memory, and are not actually saved to a file.
Modifier and Type | Field and Description |
---|---|
static String |
IGNORE_POSTFIXES_VARIABLE
Name of environment variable for ignoring filename postfixes.
|
Constructor and Description |
---|
DocumentFileSource(File basePath,
String defaultName,
String preferredExtension,
long minimumTimeBetweenValidityChecks)
Constructs a document file source.
|
DocumentFileSource(String identifier,
File basePath,
String defaultName,
String preferredExtension,
long minimumTimeBetweenValidityChecks)
Constructs a document file source.
|
DocumentFileSource(String identifier,
File basePath,
String defaultName,
String preferredExtension,
String preExtension,
long minimumTimeBetweenValidityChecks)
Constructs a document file source.
|
Modifier and Type | Method and Description |
---|---|
File |
getBasePath()
The base path.
|
com.threecrickets.scripturian.internal.FiledDocumentDescriptor<D> |
getCachedDocumentDescriptor(String documentName)
Gets a document descriptor for the document if it's in the cache.
|
Charset |
getCharset()
The charset to use for reading files.
|
String |
getDefaultName()
If the name used in
getDocument(String) points to a directory,
then this file name in that directory will be used instead. |
DocumentDescriptor<D> |
getDocument(String documentName)
Gets a document by its name.
|
DocumentDescriptor<D> |
getDocument(String documentName,
boolean read)
Gets the document descriptor, with support for caching descriptors.
|
Collection<DocumentDescriptor<D>> |
getDocuments()
Access to all available documents.
|
String |
getIdentifier()
The identifier for this document source.
|
CopyOnWriteArrayList<String> |
getIgnorePostfixes()
The filename postfixes to ignore.
|
long |
getMinimumTimeBetweenValidityChecks()
Attempts to call
getDocument(String) for a specific name within
less than this time from the previous call will return the cached
descriptor without checking if it is valid. |
String |
getPreExtension()
An optional magic "pre-extension" to require for all documents.
|
String |
getPreferredExtension()
An extension to prefer if more than one file with the same name is in a
directory.
|
String |
getRelativeFilePath(File file)
Gets the file's path relative to the base path.
|
void |
setCharset(Charset charset) |
void |
setDefaultName(String defaultName) |
DocumentDescriptor<D> |
setDocument(String documentName,
String sourceCode,
String tag,
D document)
Allows adding or changing documents.
|
DocumentDescriptor<D> |
setDocumentIfAbsent(String documentName,
String sourceCode,
String tag,
D document)
Allows for atomically adding or changing documents.
|
void |
setMinimumTimeBetweenValidityChecks(long minimumTimeBetweenValidityChecks) |
void |
setPreExtension(String preExtension) |
void |
setPreferredExtension(String preferredExtension) |
String |
toString() |
public static final String IGNORE_POSTFIXES_VARIABLE
public DocumentFileSource(File basePath, String defaultName, String preferredExtension, long minimumTimeBetweenValidityChecks)
basePath
- The base pathdefaultName
- If the name used in getDocument(String)
points to a
directory, then this file name in that directory will be used
instead; note that if an extension is not specified, then the
first file in the directory with this name, with any extension,
will be usedpreferredExtension
- An extension to prefer if more than one file with the same name is
in a directoryminimumTimeBetweenValidityChecks
- See getMinimumTimeBetweenValidityChecks()
public DocumentFileSource(String identifier, File basePath, String defaultName, String preferredExtension, long minimumTimeBetweenValidityChecks)
identifier
- The identifierbasePath
- The base pathdefaultName
- If the name used in getDocument(String)
points to a
directory, then this file name in that directory will be used
instead; note that if an extension is not specified, then the
first file in the directory with this name, with any extension,
will be usedpreferredExtension
- An extension to prefer if more than one file with the same name is
in a directoryminimumTimeBetweenValidityChecks
- See getMinimumTimeBetweenValidityChecks()
public DocumentFileSource(String identifier, File basePath, String defaultName, String preferredExtension, String preExtension, long minimumTimeBetweenValidityChecks)
identifier
- The identifierbasePath
- The base pathdefaultName
- If the name used in getDocument(String)
points to a
directory, then this file name in that directory will be used
instead; note that if an extension is not specified, then the
first file in the directory with this name, with any extension,
will be usedpreferredExtension
- An extension to prefer if more than one file with the same name is
in a directorypreExtension
- An optional magic "pre-extension" to require for all documentsminimumTimeBetweenValidityChecks
- See getMinimumTimeBetweenValidityChecks()
public File getBasePath()
public String getDefaultName()
getDocument(String)
points to a directory,
then this file name in that directory will be used instead. If an
extension is not specified, then the preferred extension will be used.setDefaultName(String)
public void setDefaultName(String defaultName)
defaultName
- The default namegetDefaultName()
public String getPreferredExtension()
setPreferredExtension(String)
public void setPreferredExtension(String preferredExtension)
preferredExtension
- The preferred extensiongetPreferredExtension()
public String getPreExtension()
setPreExtension(String)
public void setPreExtension(String preExtension)
preExtension
- The pre-extensiongetPreExtension()
public CopyOnWriteArrayList<String> getIgnorePostfixes()
public long getMinimumTimeBetweenValidityChecks()
getDocument(String)
for a specific name within
less than this time from the previous call will return the cached
descriptor without checking if it is valid. A value of -1 disables all
validity checking.setMinimumTimeBetweenValidityChecks(long)
public void setMinimumTimeBetweenValidityChecks(long minimumTimeBetweenValidityChecks)
minimumTimeBetweenValidityChecks
- The minimum time between validity checks in millisecondsgetMinimumTimeBetweenValidityChecks()
public Charset getCharset()
Note that the default is always UTF-8, not the underlying JVM's default charset, which may be inconsistently set across diverse runtime environments.
setCharset(Charset)
public void setCharset(Charset charset)
charset
- The charsetgetCharset()
public String getRelativeFilePath(File file)
file
- The filepublic com.threecrickets.scripturian.internal.FiledDocumentDescriptor<D> getCachedDocumentDescriptor(String documentName)
documentName
- The document namepublic DocumentDescriptor<D> getDocument(String documentName, boolean read) throws DocumentException
setMinimumTimeBetweenValidityChecks(long)
.documentName
- The document nameread
- Whether to read the source code from the fileDocumentException
- In case of a document retrieval errorpublic DocumentDescriptor<D> getDocument(String documentName) throws DocumentException
DocumentSource
getDocument
in interface DocumentSource<D>
documentName
- The document's nameDocumentException
- In case of a document retrieval errorDocumentSource.getDocument(String)
public DocumentDescriptor<D> setDocument(String documentName, String sourceCode, String tag, D document) throws DocumentException
DocumentSource
setDocument
in interface DocumentSource<D>
documentName
- The document's namesourceCode
- The source code for the documenttag
- The tagdocument
- The documentDocumentException
- In case of a document retrieval errorDocumentSource.setDocument(String, String, String, Object)
public DocumentDescriptor<D> setDocumentIfAbsent(String documentName, String sourceCode, String tag, D document) throws DocumentException
DocumentSource
setDocumentIfAbsent
in interface DocumentSource<D>
documentName
- The document's namesourceCode
- The source code for the documenttag
- The tagdocument
- The document instanceDocumentException
- In case of a document retrieval errorDocumentSource.setDocumentIfAbsent(String, String, String, Object)
public Collection<DocumentDescriptor<D>> getDocuments()
DocumentSource
Note that not all implementations support this operation.
getDocuments
in interface DocumentSource<D>
DocumentSource.getDocuments()
public String getIdentifier()
DocumentSource
getIdentifier
in interface DocumentSource<D>
DocumentSource.getIdentifier()
Copyright © 2009-2015 Three Crickets LLC.