public class FileSystemConnector extends WritableConnector implements Pageable
Connector implementation that exposes a single directory on the local file system. This connector has several
properties that must be configured via the RepositoryConfiguration:
directoryPath - The path to the file or folder that is to be accessed by this connector.readOnly - A boolean flag that specifies whether this source can create/modify/remove files
and directories on the file system to reflect changes in the JCR content. By default, sources are not read-only.addMimeTypeMixin - A boolean flag that specifies whether this connector should add the
'mix:mimeType' mixin to the 'nt:resource' nodes to include the 'jcr:mimeType' property. If set to true, the MIME
type is computed immediately when the 'nt:resource' node is accessed, which might be expensive for larger files. This is
false by default.extraPropertyStorage - An optional string flag that specifies how this source handles "extra"
properties that are not stored via file system attributes. See extraPropertiesStorage for details. By default, extra
properties are stored in the same Infinispan cache that the repository uses.exclusionPattern - Optional property that specifies a regular expression that is used to
determine which files and folders in the underlying file system are not exposed through this connector. Files and folders with
a name that matches the provided regular expression will not be exposed by this source.inclusionPattern - Optional property that specifies a regular expression that is used to
determine which files and folders in the underlying file system are exposed through this connector. Files and folders with a
name that matches the provided regular expression will be exposed by this source.| Inclusion Pattern | Exclusion Pattern | Examples |
|---|---|---|
| (.+)\\.txt$ | Includes only files and directories whose names end in ".txt" (e.g., "something.txt" ), but does
not include files and other folders such as "something.jar" or "something.txt.zip". |
|
| (.+)\\.txt$ | my.txt | Includes only files and directories whose names end in ".txt" (e.g., "something.txt" ) with the
exception of "my.txt", and does not include files and other folders such as "something.jar" or "
something.txt.zip". |
| my.txt | .+ | Excludes all files and directories except any named "my.txt". |
Connector.ExtraProperties| Constructor and Description |
|---|
FileSystemConnector() |
| Modifier and Type | Method and Description |
|---|---|
protected ExternalBinaryValue |
binaryFor(File file)
Utility method for creating a
BinaryValue for the given File object. |
protected void |
checkFileNotExcluded(String id,
File file)
Utility method to ensure that the file is writable by this connector.
|
protected boolean |
contentBasedSha1() |
protected ExternalBinaryValue |
createBinaryValue(File file)
Utility method to create a
BinaryValue object for the given file. |
protected File |
createFileForUrl(URL url) |
protected URL |
createUrlForFile(File file)
|
protected File |
fileFor(String id)
Utility method for obtaining the
File object that corresponds to the supplied identifier. |
ExternalBinaryValue |
getBinaryValue(String id)
Returns a binary value which is connector specific and which is never stored by ModeShape.
|
Document |
getChildren(PageKey pageKey)
Returns a document which represents the document of a parent node to which an optiona page of children has been added.
|
Document |
getDocumentById(String id)
Returns a
Document instance representing the document with a given id. |
String |
getDocumentId(String path)
Returns the id of an external node located at the given external path within the connector's exposed tree of content.
|
Collection<String> |
getDocumentPathsById(String id)
Return the path(s) of the external node with the given identifier.
|
boolean |
hasDocument(String id)
Checks if a document with the given id exists in the end-source.
|
protected String |
idFor(File file)
Utility method for determining the node identifier for the supplied file.
|
void |
initialize(NamespaceRegistry registry,
NodeTypeManager nodeTypeManager)
Initialize the connector.
|
protected boolean |
isContentNode(String id)
Utility method for determining if the supplied identifier is for the "jcr:content" child node of a file. * Subclasses may
override this method to change the format of the identifiers, but in that case should also override the
fileFor(String), isRoot(String), and idFor(File) methods. |
protected boolean |
isExcluded(File file)
Utility method to determine if the file is excluded by the inclusion/exclusion filter.
|
protected boolean |
isRoot(String id)
Utility method for determining if the node identifier is the identifier of the root node in this external source.
|
String |
newDocumentId(String parentId,
Name newDocumentName,
Name newDocumentPrimaryType)
Generates an identifier which will be assigned when a new document (aka. child) is created under an existing document
(aka.parent).
|
boolean |
removeDocument(String id)
Removes the document with the given id.
|
protected String |
sha1(File file)
Computes the SHA1 for the given file.
|
void |
storeDocument(Document document)
Stores the given document.
|
void |
updateDocument(DocumentChanges documentChanges)
Updates a document using the provided changes.
|
isReadonlycheckFieldNotNull, extraPropertiesFor, extraPropertiesStore, factories, getCacheTtlSeconds, getChildReference, getContext, getEnvironment, getLogger, getMimeTypeDetector, getRepositoryName, getSourceName, getTransactionManager, isQueryable, log, nameFrom, nameFrom, nameFrom, newChildReference, newConnectorChangedSet, newDocument, newPageDocument, pathFactory, pathFrom, pathFrom, propertyFactory, readDocument, setExtraPropertiesStore, shutdown, translator, writeDocumentpublic void initialize(NamespaceRegistry registry, NodeTypeManager nodeTypeManager) throws RepositoryException, IOException
ConnectorConnector.context,
Connector.logger, Connector.name, and Connector.repositoryName plus any fields that match configuration properties for the
connector.
By default this method does nothing, so it should be overridden by implementations to do a one-time initialization of any
internal components. For example, connectors can use the supplied registry and nodeTypeManager
objects to register custom namesapces and node types required by the external content.
This is an excellent place for connector to validate the connector-specific fields set by ModeShape via reflection during instantiation.
initialize in class Connectorregistry - the namespace registry that can be used to register custom namespaces; never nullnodeTypeManager - the node type manager that can be used to register custom node types; never nullRepositoryException - if operations on the NamespaceRegistry or NodeTypeManager failIOException - if any stream based operations fail (like importing cnd files)protected boolean isContentNode(String id)
fileFor(String), isRoot(String), and idFor(File) methods.id - the identifier; may not be nullisRoot(String),
fileFor(String),
idFor(File)protected File fileFor(String id)
File object that corresponds to the supplied identifier. Subclasses may override
this method to change the format of the identifiers, but in that case should also override the isRoot(String),
isContentNode(String), and idFor(File) methods.id - the identifier; may not be nullisRoot(String),
isContentNode(String),
idFor(File)protected boolean isRoot(String id)
fileFor(String), isContentNode(String), and idFor(File) methods.id - the identifier; may not be nullisContentNode(String),
fileFor(String),
idFor(File)protected String idFor(File file)
fileFor(String),
isContentNode(String), and isRoot(String) methods.file - the file; may not be nullisRoot(String),
isContentNode(String),
fileFor(String)protected ExternalBinaryValue binaryFor(File file)
BinaryValue for the given File object. Subclasses should rarely override this
method.file - the file; may not be nullprotected ExternalBinaryValue createBinaryValue(File file) throws IOException
BinaryValue object for the given file. Subclasses should rarely override this method,
since the UrlBinaryValue will be applicable in most situations.file - the file for which the BinaryValue is to be created; never nullIOException - if there is an error creating the valueprotected String sha1(File file)
contentBasedSha1()
flag and either take the URL of the file (using @see java.util.File#toURI().toURL() and return the SHA1 of the URL string
or return the SHA1 of the entire file content.file - a File instance; never nullprotected URL createUrlForFile(File file) throws IOException
URL object for the given file, to be used within the Binary value representing the "jcr:data"
property of a 'nt:resource' node.
Subclasses can override this method to transform the URL into something different. For example, if the files are being served by a web server, the overridden method might transform the file-based URL into the corresponding HTTP-based URL.
file - the file for which the URL is to be created; never nullIOException - if there is an error creating the URLprotected File createFileForUrl(URL url) throws URISyntaxException
URISyntaxExceptionprotected boolean contentBasedSha1()
protected boolean isExcluded(File file)
file - the fileprotected void checkFileNotExcluded(String id, File file)
id - the identifier of the nodefile - the fileDocumentStoreException - if the file is expected to be writable but is not or is excluded, or if the connector is
readonlypublic boolean hasDocument(String id)
ConnectorhasDocument in class Connectorid - a non-null string.true if such a document exists, false otherwise.public Document getDocumentById(String id)
ConnectorDocument instance representing the document with a given id. The document should have a "proper"
structure for it to be usable by ModeShape.getDocumentById in class Connectorid - a non-null stringDocument instance or nullpublic String getDocumentId(String path)
ConnectorgetDocumentId in class Connectorpath - a non-null string representing an external path, or "/" for the top-level node exposed by the
connectornullpublic Collection<String> getDocumentPathsById(String id)
ConnectorgetDocumentPathsById in class Connectorid - a non-null stringpublic ExternalBinaryValue getBinaryValue(String id)
ConnectorExternalBinaryValue, either UrlBinaryValue or
a custom subclass with connector-specific information.
Normally, the Connector.getDocumentById(String) method implementation will set binary values on properties of nodes, which
should create the same ExternalBinaryValue subclass that is returned by this method. The
ExternalBinaryValue.getId() value from that instance will be passed into this method.
getBinaryValue in class Connectorid - a String representing the identifier of the external binary which should have connector-specific meaning.
This identifier need not be the SHA-1 hash of the content.null if there is no such value with the given id.public boolean removeDocument(String id)
ConnectorremoveDocument in class Connectorid - a non-null string.public void storeDocument(Document document)
ConnectorstoreDocument in class Connectordocument - a non-null Document instance.public String newDocumentId(String parentId, Name newDocumentName, Name newDocumentPrimaryType)
ConnectornewDocumentId in class ConnectorparentId - a non-null String which represents the identifier of the parent under which the new
document will be created.newDocumentName - a non-null Name which represents the name that will be given
to the child documentnewDocumentPrimaryType - a non-null Name which represents the child document's
primary type.non-null String which will be assigned as the new identifier, or null which means
that no "special" id format is required. In this last case, the repository will auto-generate a random id.public void updateDocument(DocumentChanges documentChanges)
ConnectorupdateDocument in class ConnectordocumentChanges - a non-null DocumentChanges object which contains
granular information about all the changes.public Document getChildren(PageKey pageKey)
PageablePageWriter.addPage(String, String, long, long) should be used to add a
new page of children.getChildren in interface PageablepageKey - a non-null PageKey instance, which offers information about the page that should be
retrieved.non-null document representing the parent document.Copyright © 2008-2014 JBoss, a division of Red Hat. All Rights Reserved.