public class GoogleDriveBlobProvider extends Object implements BlobProvider, BatchUpdateBlobProvider
| Modifier and Type | Class and Description |
|---|---|
static class |
GoogleDriveBlobProvider.FileInfo
Information about a file stored in Google Drive.
|
| Modifier and Type | Field and Description |
|---|---|
protected static String |
BLOB_CONVERSION_BLOB |
protected static String |
BLOB_CONVERSION_KEY |
protected static String |
BLOB_CONVERSIONS_FACET |
protected static String |
BLOB_CONVERSIONS_PROPERTY |
static String |
CLIENT_ID_PROP |
static String |
DEFAULT_EXPORT_MIMETYPE |
protected static com.google.api.client.util.ObjectParser |
JSON_PARSER |
static int |
PREFERRED_ICON_SIZE |
static String |
PREFIX |
static String |
SERVICE_ACCOUNT_ID_PROP |
static String |
SERVICE_ACCOUNT_P12_PATH_PROP |
MAX_RESULT| Constructor and Description |
|---|
GoogleDriveBlobProvider() |
| Modifier and Type | Method and Description |
|---|---|
protected static URI |
asURI(String link)
Parse a
URI. |
List<DocumentModel> |
checkChangesAndUpdateBlob(List<DocumentModel> docs)
Check the given list of document for change and update if needed.
|
void |
close()
Closes this blob provider and releases resources that may be held by it.
|
protected InputStream |
doGet(String user,
URI url)
Executes a GET request with the user's credentials.
|
protected <T> T |
executeAndCache(String cacheKey,
com.google.api.services.drive.DriveRequest<T> request,
Class<T> aClass)
Executes a
DriveRequest and caches the unparsed response. |
ManagedBlob |
freezeVersion(ManagedBlob blob,
Document doc)
Returns a new managed blob pointing to a fixed version of the original blob.
|
protected String |
getAlternateUrl(ManagedBlob blob) |
protected com.google.api.services.drive.model.App |
getApp(String user,
String appId) |
List<AppLink> |
getAppLinks(String username,
ManagedBlob blob)
Returns a list of application links for the given blob.
|
Map<String,URI> |
getAvailableConversions(ManagedBlob blob,
BlobManager.UsageHint hint)
Gets a map of available MIME type conversions and corresponding
URI for a managed blob. |
protected ManagedBlob |
getBlob(GoogleDriveBlobProvider.FileInfo fileInfo)
Gets the blob for a Google Drive file.
|
String |
getBlobPrefix() |
protected Cache |
getCache() |
String |
getClientId() |
InputStream |
getConvertedStream(ManagedBlob blob,
String mimeType,
DocumentModel doc)
Gets an
InputStream for a conversion to the given MIME type. |
protected com.google.api.client.auth.oauth2.Credential |
getCredential(String user) |
protected CredentialFactory |
getCredentialFactory() |
protected String |
getDigest(com.google.api.services.drive.model.File file) |
protected String |
getDownloadUrl(ManagedBlob blob)
Gets the URL to which we can redirect to let the user download the file.
|
protected String |
getEmbedUrl(ManagedBlob blob)
Gets the URL to which we can redirect to let the user see a preview of the file.
|
protected Map<String,String> |
getExportLinks(ManagedBlob blob)
Gets the export link.
|
protected com.google.api.services.drive.model.File |
getFile(GoogleDriveBlobProvider.FileInfo fileInfo)
Retrieves a
File resource and caches the unparsed response. |
protected GoogleDriveBlobProvider.FileInfo |
getFileInfo(ManagedBlob blob)
Removes the prefix from the key.
|
protected String |
getKey(GoogleDriveBlobProvider.FileInfo fileInfo)
Adds the prefix to the key.
|
protected OAuth2ServiceProvider |
getOAuth2Provider() |
String |
getPageProviderNameForUpdate() |
protected com.google.api.services.drive.model.File |
getPartialFile(String user,
String fileId,
String... fields)
Retrieve a partial
File resource. |
protected com.google.api.services.drive.model.Revision |
getRevision(GoogleDriveBlobProvider.FileInfo fileInfo)
Retrieves a
Revision resource and caches the unparsed response. |
protected com.google.api.services.drive.model.RevisionList |
getRevisionList(GoogleDriveBlobProvider.FileInfo fileInfo)
Retrieves the list of
Revision resources for a file. |
protected com.google.api.services.drive.Drive |
getService(String user) |
protected String |
getServiceUser(String username) |
InputStream |
getStream(ManagedBlob blob)
Gets an
InputStream for the data of a managed blob. |
protected InputStream |
getStream(ManagedBlob blob,
URI uri) |
protected String |
getStreamUrl(ManagedBlob blob)
Gets the URL from which we can stream the content of the file.
|
InputStream |
getThumbnail(ManagedBlob blob)
Gets an
InputStream for a thumbnail of a managed blob. |
protected String |
getThumbnailUrl(ManagedBlob blob)
Gets the URL from which we can stream a thumbnail.
|
URI |
getURI(ManagedBlob blob,
BlobManager.UsageHint usage,
javax.servlet.http.HttpServletRequest servletRequest)
Gets an
URI for the content of a managed blob. |
void |
initialize(String blobProviderId,
Map<String,String> properties)
Initializes the blob provider.
|
protected boolean |
isChanged(Blob blob,
com.google.api.services.drive.model.File file) |
protected boolean |
isDigestChanged(Blob blob,
com.google.api.services.drive.model.File file) |
protected boolean |
isFilenameChanged(Blob blob,
com.google.api.services.drive.model.File file) |
boolean |
isVersion(ManagedBlob blob)
Returns true if version of the blob is a version.
|
Blob |
readBlob(BlobManager.BlobInfo blobInfo)
Reads a
Blob from storage. |
protected Blob |
retrieveBlobConversion(ManagedBlob blob,
String mimeType,
DocumentModel doc)
Retrieve a stored conversion of the given blob
|
protected void |
storeBlobConversion(Document doc,
String blobKey,
Blob blob)
Store a conversion of the given blob
|
boolean |
supportsWrite()
Checks if write is supported
|
String |
writeBlob(Blob blob,
Document doc)
Writes a
Blob to storage and returns information about it. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetBinaryManagerprocessDocumentsUpdatepublic static final int PREFERRED_ICON_SIZE
public static final String PREFIX
public static final String SERVICE_ACCOUNT_ID_PROP
public static final String SERVICE_ACCOUNT_P12_PATH_PROP
public static final String CLIENT_ID_PROP
public static final String DEFAULT_EXPORT_MIMETYPE
protected static final String BLOB_CONVERSIONS_FACET
protected static final String BLOB_CONVERSIONS_PROPERTY
protected static final String BLOB_CONVERSION_KEY
protected static final String BLOB_CONVERSION_BLOB
protected static final com.google.api.client.util.ObjectParser JSON_PARSER
public GoogleDriveBlobProvider()
public void initialize(String blobProviderId, Map<String,String> properties) throws IOException
BlobProviderinitialize in interface BlobProviderblobProviderId - the blob provider id for this binary managerproperties - initialization propertiesIOExceptionpublic void close()
BlobProviderclose in interface BlobProviderpublic Blob readBlob(BlobManager.BlobInfo blobInfo)
BlobProviderBlob from storage.readBlob in interface BlobProviderblobInfo - the blob informationpublic boolean supportsWrite()
BlobProvidersupportsWrite in interface BlobProvidertrue if write is supportedpublic String writeBlob(Blob blob, Document doc)
BlobProviderBlob to storage and returns information about it.
Called to store a user-created blob.
writeBlob in interface BlobProviderblob - the blobdoc - the document to which this blob belongspublic URI getURI(ManagedBlob blob, BlobManager.UsageHint usage, javax.servlet.http.HttpServletRequest servletRequest) throws IOException
BlobProviderURI for the content of a managed blob.getURI in interface BlobProviderblob - the managed blobusage - BlobManager.UsageHintservletRequest - the servlet request, or nullURI, or null if none availableIOExceptionpublic Map<String,URI> getAvailableConversions(ManagedBlob blob, BlobManager.UsageHint hint) throws IOException
BlobProviderURI for a managed blob.getAvailableConversions in interface BlobProviderblob - the managed blobhint - BlobManager.UsageHintURI, which may be emptyIOExceptionpublic InputStream getThumbnail(ManagedBlob blob) throws IOException
BlobProviderInputStream for a thumbnail of a managed blob.
Like all InputStream, the result must be closed when done with it to avoid resource leaks.
getThumbnail in interface BlobProviderblob - the managed blobIOExceptionprotected String getStreamUrl(ManagedBlob blob) throws IOException
Will return null if this is a native Google document.
IOExceptionprotected String getDownloadUrl(ManagedBlob blob) throws IOException
IOExceptionprotected String getAlternateUrl(ManagedBlob blob) throws IOException
IOExceptionprotected String getEmbedUrl(ManagedBlob blob) throws IOException
IOExceptionprotected String getThumbnailUrl(ManagedBlob blob) throws IOException
IOExceptionprotected Map<String,String> getExportLinks(ManagedBlob blob) throws IOException
IOExceptionpublic InputStream getStream(ManagedBlob blob) throws IOException
BlobProviderInputStream for the data of a managed blob.
Like all InputStream, the result must be closed when done with it to avoid resource leaks.
getStream in interface BlobProviderblob - the managed blobIOExceptionpublic InputStream getConvertedStream(ManagedBlob blob, String mimeType, DocumentModel doc) throws IOException
BlobProviderInputStream for a conversion to the given MIME type.
Like all InputStream, the result must be closed when done with it to avoid resource leaks.
getConvertedStream in interface BlobProviderblob - the managed blobmimeType - the MIME type to convert todoc - the document that holds the blobnull if no conversion is available for the given MIME typeIOExceptionprotected InputStream getStream(ManagedBlob blob, URI uri) throws IOException
IOExceptionpublic List<AppLink> getAppLinks(String username, ManagedBlob blob) throws IOException
BlobProvidergetAppLinks in interface BlobProviderIOExceptionprotected String getServiceUser(String username)
protected com.google.api.services.drive.model.App getApp(String user, String appId) throws IOException
IOExceptionpublic ManagedBlob freezeVersion(ManagedBlob blob, Document doc) throws IOException
BlobProviderfreezeVersion in interface BlobProviderblob - the original managed blobdoc - the document that holds the blobnull if no change is neededIOExceptionprotected void storeBlobConversion(Document doc, String blobKey, Blob blob)
protected Blob retrieveBlobConversion(ManagedBlob blob, String mimeType, DocumentModel doc)
protected ManagedBlob getBlob(GoogleDriveBlobProvider.FileInfo fileInfo) throws IOException
fileInfo - the file infoIOExceptionprotected boolean isDigestChanged(Blob blob, com.google.api.services.drive.model.File file)
protected boolean isFilenameChanged(Blob blob, com.google.api.services.drive.model.File file)
protected String getKey(GoogleDriveBlobProvider.FileInfo fileInfo)
protected GoogleDriveBlobProvider.FileInfo getFileInfo(ManagedBlob blob)
protected com.google.api.client.auth.oauth2.Credential getCredential(String user) throws IOException
IOExceptionprotected CredentialFactory getCredentialFactory()
protected com.google.api.services.drive.Drive getService(String user) throws IOException
IOExceptionprotected com.google.api.services.drive.model.File getPartialFile(String user, String fileId, String... fields) throws IOException
File resource.IOExceptionprotected com.google.api.services.drive.model.File getFile(GoogleDriveBlobProvider.FileInfo fileInfo) throws IOException
File resource and caches the unparsed response.File resourceIOExceptionprotected com.google.api.services.drive.model.Revision getRevision(GoogleDriveBlobProvider.FileInfo fileInfo) throws IOException
Revision resource and caches the unparsed response.Revision resourceIOExceptionprotected <T> T executeAndCache(String cacheKey, com.google.api.services.drive.DriveRequest<T> request, Class<T> aClass) throws IOException
DriveRequest and caches the unparsed response.IOExceptionprotected com.google.api.services.drive.model.RevisionList getRevisionList(GoogleDriveBlobProvider.FileInfo fileInfo) throws IOException
Revision resources for a file.Revision resourcesIOExceptionprotected InputStream doGet(String user, URI url) throws IOException
IOExceptionpublic String getClientId()
protected OAuth2ServiceProvider getOAuth2Provider()
public List<DocumentModel> checkChangesAndUpdateBlob(List<DocumentModel> docs)
BatchUpdateBlobProvidercheckChangesAndUpdateBlob in interface BatchUpdateBlobProviderpublic String getPageProviderNameForUpdate()
getPageProviderNameForUpdate in interface BatchUpdateBlobProviderpublic String getBlobPrefix()
getBlobPrefix in interface BatchUpdateBlobProviderpublic boolean isVersion(ManagedBlob blob)
BlobProviderisVersion in interface BlobProviderblob - the managed blobCopyright © 2015 Nuxeo SA. All rights reserved.