org.silverpeas.attachment.repository
Class DocumentRepository

java.lang.Object
  extended by org.silverpeas.attachment.repository.DocumentRepository

@Named(value="documentRepository")
public class DocumentRepository
extends Object

Author:
ehugonnet

Constructor Summary
DocumentRepository()
           
 
Method Summary
 void addContent(javax.jcr.Session session, SimpleDocumentPK documentPk, SimpleAttachment attachment)
          Add the content.
 SimpleDocumentPK changeVersionState(javax.jcr.Session session, SimpleDocumentPK documentPk, String comment)
          Change the management of versions of the document if the document is checkouted.
 SimpleDocumentPK copyDocument(javax.jcr.Session session, HistorisedDocument document, WAPrimaryKey destination)
          Copy the document to another attached object.
 SimpleDocumentPK copyDocument(javax.jcr.Session session, SimpleDocument document, WAPrimaryKey destination)
          Copy the document to another attached object.
 void copyFullContent(SimpleDocument origin, SimpleDocument copy)
           
 void copyMultilangContent(SimpleDocument origin, SimpleDocument copy)
           
 SimpleDocumentPK createDocument(javax.jcr.Session session, SimpleDocument document)
          Create file attached to an object who is identified by "PK" SimpleDocument object contains an attribute who identifie the link by a foreign key.
 void deleteContent(javax.jcr.Node documentNode, String instanceId)
           
 void deleteDocument(javax.jcr.Session session, SimpleDocumentPK documentPk)
          Delete a file attached to an object who is identified by "PK" SimpleDocument object contains an attribute who identifie the link by a foreign key.
 void duplicateContent(SimpleDocument origin, SimpleDocument document)
           
 void fillNodeName(javax.jcr.Session session, SimpleDocument document)
           
 SimpleDocument findDocumentById(javax.jcr.Session session, SimpleDocumentPK documentPk, String lang)
           
 SimpleDocument findDocumentByOldSilverpeasId(javax.jcr.Session session, String instanceId, long oldSilverpeasId, boolean versioned, String lang)
           
 SimpleDocument findLast(javax.jcr.Session session, String instanceId, String foreignId)
          The last document in an instance with the specified foreignId.
 InputStream getContent(javax.jcr.Session session, SimpleDocumentPK pk, String lang)
          Get the content.
 List<SimpleDocument> listAllDocumentsByComponentId(javax.jcr.Session session, String instanceId, String language)
          Search all the documents related to the component instance identified by the specified identifier.
 SimpleDocumentList<SimpleDocument> listAllDocumentsByForeignId(javax.jcr.Session session, String instanceId, String foreignId, String language)
          Search all the documents of any type in an instance with the specified foreignId.
 List<SimpleDocument> listComponentDocumentsByOwner(javax.jcr.Session session, String instanceId, String owner, String language)
          Search all the documents in an instance with the specified owner.
 List<SimpleDocument> listDocumentsByComponentIdAndType(javax.jcr.Session session, String instanceId, DocumentType type, String language)
          Search all the documents in an instance with the specified type.
 SimpleDocumentList<SimpleDocument> listDocumentsByForeignId(javax.jcr.Session session, String instanceId, String foreignId, String language)
          Search all the documents of type attachment in an instance with the specified foreignId.
 SimpleDocumentList<SimpleDocument> listDocumentsByForeignIdAndType(javax.jcr.Session session, String instanceId, String foreignId, DocumentType type, String language)
          Search all the documents in an instance with the specified foreignId.
 List<SimpleDocument> listDocumentsLockedByUser(javax.jcr.Session session, String usedId, String language)
           
 List<SimpleDocument> listDocumentsRequiringWarning(javax.jcr.Session session, Date alertDate, String language)
          Search all the documents in an instance which are locked at the alert date.
 List<SimpleDocument> listDocumentsToUnlock(javax.jcr.Session session, Date expiryDate, String language)
          Search all the documents in an instance requiring to be unlocked at the specified date.
 List<SimpleDocument> listExpiringDocuments(javax.jcr.Session session, Date expiryDate, String language)
          Search all the documents in an instance which are expiring at the specified date.
 boolean lock(javax.jcr.Session session, SimpleDocument document, String owner)
          Lock a document if it is versionned to create a new work in progress version.
 void mergeAttachment(javax.jcr.Session session, SimpleDocument attachment, SimpleDocument clone)
           
 SimpleDocumentPK moveDocument(javax.jcr.Session session, SimpleDocument document, WAPrimaryKey destination)
          Move the document to another attached object.
 void moveFullContent(SimpleDocument origin, SimpleDocument copy)
           
 void moveMultilangContent(SimpleDocument origin, SimpleDocument copy)
           
protected  javax.jcr.Node prepareComponentAttachments(javax.jcr.Session session, String instanceId, String folder)
           
 void prepareComponentAttachments(String instanceId, String folder)
           
 boolean removeContent(javax.jcr.Session session, SimpleDocumentPK documentPk, String language)
          Remove the content for the specified language.
 void removeVersionnable(javax.jcr.Session session, SimpleDocumentPK documentPk)
          Remove the version feature to an existing document.
 void saveForbiddenDownloadForRoles(javax.jcr.Session session, SimpleDocument document)
          Save the optional slv:forbiddenDownloadForRoles simple document property (MIXIN).
 void setClone(javax.jcr.Session session, SimpleDocument original, SimpleDocument clone)
          Add the document's clone id to the document even if it is locked.
 void setOrder(javax.jcr.Session session, SimpleDocument document)
          Update the document order.
 void setVersionnable(javax.jcr.Session session, SimpleDocumentPK documentPk)
          Add the version feature to an existing document.
 long storeContent(SimpleDocument document, InputStream in)
           
 long storeContent(SimpleDocument document, InputStream in, boolean update)
           
 SimpleDocument unlock(javax.jcr.Session session, SimpleDocument document, boolean restore)
          Unlock a document if it is versionned to create a new version or to restore a previous one.
 SimpleDocument unlockFromContentDeletion(javax.jcr.Session session, SimpleDocument document)
          Unlock a document if it is versionned from a context into which a language content has just been deleted.
 void updateDocument(javax.jcr.Session session, SimpleDocument document, boolean updateLastModifiedData)
          Create file attached to an object who is identified by "PK" SimpleDocument object contains an attribute who identifie the link by a foreign key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DocumentRepository

public DocumentRepository()
Method Detail

prepareComponentAttachments

public void prepareComponentAttachments(String instanceId,
                                        String folder)
                                 throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

prepareComponentAttachments

protected javax.jcr.Node prepareComponentAttachments(javax.jcr.Session session,
                                                     String instanceId,
                                                     String folder)
                                              throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

createDocument

public SimpleDocumentPK createDocument(javax.jcr.Session session,
                                       SimpleDocument document)
                                throws javax.jcr.RepositoryException
Create file attached to an object who is identified by "PK" SimpleDocument object contains an attribute who identifie the link by a foreign key.

Parameters:
session -
document -
Returns:
Throws:
javax.jcr.RepositoryException

moveDocument

public SimpleDocumentPK moveDocument(javax.jcr.Session session,
                                     SimpleDocument document,
                                     WAPrimaryKey destination)
                              throws javax.jcr.RepositoryException
Move the document to another attached object.

Parameters:
session -
document -
destination -
Returns:
Throws:
javax.jcr.RepositoryException

copyDocument

public SimpleDocumentPK copyDocument(javax.jcr.Session session,
                                     SimpleDocument document,
                                     WAPrimaryKey destination)
                              throws javax.jcr.RepositoryException
Copy the document to another attached object.

Parameters:
session -
document -
destination - the foreingId holding reference to the copy.
Returns:
Throws:
javax.jcr.RepositoryException

copyDocument

public SimpleDocumentPK copyDocument(javax.jcr.Session session,
                                     HistorisedDocument document,
                                     WAPrimaryKey destination)
                              throws javax.jcr.RepositoryException,
                                     IOException
Copy the document to another attached object.

Parameters:
session -
document -
destination - the foreingId holding reference to the copy.
Returns:
Throws:
javax.jcr.RepositoryException
IOException

updateDocument

public void updateDocument(javax.jcr.Session session,
                           SimpleDocument document,
                           boolean updateLastModifiedData)
                    throws javax.jcr.RepositoryException,
                           IOException
Create file attached to an object who is identified by "PK" SimpleDocument object contains an attribute who identifie the link by a foreign key.

Parameters:
session -
document -
updateLastModifiedData -
Throws:
javax.jcr.RepositoryException
IOException

saveForbiddenDownloadForRoles

public void saveForbiddenDownloadForRoles(javax.jcr.Session session,
                                          SimpleDocument document)
                                   throws javax.jcr.RepositoryException
Save the optional slv:forbiddenDownloadForRoles simple document property (MIXIN). This saving works with versionable documents without changing the major and minor version. This property is transverse between all versions.

Parameters:
session -
document -
Throws:
javax.jcr.RepositoryException

setClone

public void setClone(javax.jcr.Session session,
                     SimpleDocument original,
                     SimpleDocument clone)
              throws javax.jcr.RepositoryException
Add the document's clone id to the document even if it is locked.

Parameters:
session - the JCR session.
original - the original document to be cloned.
clone - the cone of the original document.
Throws:
javax.jcr.RepositoryException

setOrder

public void setOrder(javax.jcr.Session session,
                     SimpleDocument document)
              throws javax.jcr.RepositoryException
Update the document order. This is a unique operation since the order propery is not versionable.

Parameters:
session -
document -
Throws:
javax.jcr.RepositoryException

deleteDocument

public void deleteDocument(javax.jcr.Session session,
                           SimpleDocumentPK documentPk)
                    throws javax.jcr.RepositoryException
Delete a file attached to an object who is identified by "PK" SimpleDocument object contains an attribute who identifie the link by a foreign key.

Parameters:
session -
documentPk -
Throws:
javax.jcr.RepositoryException

changeVersionState

public SimpleDocumentPK changeVersionState(javax.jcr.Session session,
                                           SimpleDocumentPK documentPk,
                                           String comment)
                                    throws javax.jcr.RepositoryException,
                                           IOException
Change the management of versions of the document if the document is checkouted. If the document is currently with version management, then all history is removed and the document becomes a simple document with no more version management. If the document has no version management then a new public version is created and the document becomes a document with a version history management.

Parameters:
session -
documentPk - the id of the document.
comment -
Throws:
javax.jcr.RepositoryException
IOException

findDocumentById

public SimpleDocument findDocumentById(javax.jcr.Session session,
                                       SimpleDocumentPK documentPk,
                                       String lang)
                                throws javax.jcr.RepositoryException
Parameters:
session -
documentPk -
lang -
Returns:
Throws:
javax.jcr.RepositoryException

findDocumentByOldSilverpeasId

public SimpleDocument findDocumentByOldSilverpeasId(javax.jcr.Session session,
                                                    String instanceId,
                                                    long oldSilverpeasId,
                                                    boolean versioned,
                                                    String lang)
                                             throws javax.jcr.RepositoryException
Parameters:
session -
instanceId -
oldSilverpeasId -
versioned -
lang -
Returns:
Throws:
javax.jcr.RepositoryException

findLast

public SimpleDocument findLast(javax.jcr.Session session,
                               String instanceId,
                               String foreignId)
                        throws javax.jcr.RepositoryException
The last document in an instance with the specified foreignId.

Parameters:
session - the current JCR session.
instanceId - the component id containing the documents.
foreignId - the id of the container owning the documents.
Returns:
the last document in an instance with the specified foreignId.
Throws:
javax.jcr.RepositoryException

listDocumentsByForeignId

public SimpleDocumentList<SimpleDocument> listDocumentsByForeignId(javax.jcr.Session session,
                                                                   String instanceId,
                                                                   String foreignId,
                                                                   String language)
                                                            throws javax.jcr.RepositoryException
Search all the documents of type attachment in an instance with the specified foreignId.

Parameters:
session - the current JCR session.
instanceId - the component id containing the documents.
foreignId - the id of the container owning the documents.
language - the language in which the documents are required.
Returns:
an ordered list of the documents.
Throws:
javax.jcr.RepositoryException

listAllDocumentsByForeignId

public SimpleDocumentList<SimpleDocument> listAllDocumentsByForeignId(javax.jcr.Session session,
                                                                      String instanceId,
                                                                      String foreignId,
                                                                      String language)
                                                               throws javax.jcr.RepositoryException
Search all the documents of any type in an instance with the specified foreignId.

Parameters:
session - the current JCR session.
instanceId - the component id containing the documents.
foreignId - the id of the container owning the documents.
language - the language in which the documents are required.
Returns:
an ordered list of the documents.
Throws:
javax.jcr.RepositoryException

listDocumentsByForeignIdAndType

public SimpleDocumentList<SimpleDocument> listDocumentsByForeignIdAndType(javax.jcr.Session session,
                                                                          String instanceId,
                                                                          String foreignId,
                                                                          DocumentType type,
                                                                          String language)
                                                                   throws javax.jcr.RepositoryException
Search all the documents in an instance with the specified foreignId.

Parameters:
session - the current JCR session.
instanceId - the component id containing the documents.
foreignId - the id of the container owning the documents.
type - thetype of required documents.
language - the language in which the documents are required.
Returns:
an ordered list of the documents.
Throws:
javax.jcr.RepositoryException

listDocumentsByComponentIdAndType

public List<SimpleDocument> listDocumentsByComponentIdAndType(javax.jcr.Session session,
                                                              String instanceId,
                                                              DocumentType type,
                                                              String language)
                                                       throws javax.jcr.RepositoryException
Search all the documents in an instance with the specified type.

Parameters:
session - the current JCR session.
instanceId - the component id containing the documents.
type - thetype of required documents.
language - the language in which the documents are required.
Returns:
an ordered list of the documents.
Throws:
javax.jcr.RepositoryException

listAllDocumentsByComponentId

public List<SimpleDocument> listAllDocumentsByComponentId(javax.jcr.Session session,
                                                          String instanceId,
                                                          String language)
                                                   throws javax.jcr.RepositoryException
Search all the documents related to the component instance identified by the specified identifier.

Parameters:
session - the current JCR session.
instanceId - the component id containing the documents.
language - the language in which the documents are required.
Returns:
an ordered list of the documents.
Throws:
javax.jcr.RepositoryException

listComponentDocumentsByOwner

public List<SimpleDocument> listComponentDocumentsByOwner(javax.jcr.Session session,
                                                          String instanceId,
                                                          String owner,
                                                          String language)
                                                   throws javax.jcr.RepositoryException
Search all the documents in an instance with the specified owner.

Parameters:
session - the current JCR session.
instanceId - the component id containing the documents.
owner - the id of the user owning the document.
language - the language in which the documents are required.
Returns:
an ordered list of the documents.
Throws:
javax.jcr.RepositoryException

listDocumentsLockedByUser

public List<SimpleDocument> listDocumentsLockedByUser(javax.jcr.Session session,
                                                      String usedId,
                                                      String language)
                                               throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

listExpiringDocuments

public List<SimpleDocument> listExpiringDocuments(javax.jcr.Session session,
                                                  Date expiryDate,
                                                  String language)
                                           throws javax.jcr.RepositoryException
Search all the documents in an instance which are expiring at the specified date.

Parameters:
session - the current JCR session.
expiryDate - the date when the document reservation should expire.
language - the language in which the documents are required.
Returns:
an ordered list of the documents.
Throws:
javax.jcr.RepositoryException

listDocumentsRequiringWarning

public List<SimpleDocument> listDocumentsRequiringWarning(javax.jcr.Session session,
                                                          Date alertDate,
                                                          String language)
                                                   throws javax.jcr.RepositoryException
Search all the documents in an instance which are locked at the alert date.

Parameters:
session - the current JCR session.
alertDate - the date when the document reservation should send an alert.
language - the language in which the documents are required.
Returns:
an ordered list of the documents.
Throws:
javax.jcr.RepositoryException

listDocumentsToUnlock

public List<SimpleDocument> listDocumentsToUnlock(javax.jcr.Session session,
                                                  Date expiryDate,
                                                  String language)
                                           throws javax.jcr.RepositoryException
Search all the documents in an instance requiring to be unlocked at the specified date.

Parameters:
session - the current JCR session.
expiryDate - the date when the document reservation should expire.
language - the language in which the documents are required.
Returns:
an ordered list of the documents.
Throws:
javax.jcr.RepositoryException

addContent

public void addContent(javax.jcr.Session session,
                       SimpleDocumentPK documentPk,
                       SimpleAttachment attachment)
                throws javax.jcr.RepositoryException
Add the content.

Parameters:
session - the current JCR session.
documentPk - the document which content is to be added.
attachment - the attachment metadata.
Throws:
javax.jcr.RepositoryException

getContent

public InputStream getContent(javax.jcr.Session session,
                              SimpleDocumentPK pk,
                              String lang)
                       throws javax.jcr.RepositoryException,
                              IOException
Get the content.

Parameters:
session - the current JCR session.
pk - the document which content is to be added.
lang - the content language.
Returns:
the attachment binary content.
Throws:
javax.jcr.RepositoryException
IOException

removeContent

public boolean removeContent(javax.jcr.Session session,
                             SimpleDocumentPK documentPk,
                             String language)
                      throws javax.jcr.RepositoryException
Remove the content for the specified language. If no other content exists, then the document node is deleted.

Parameters:
session - the current JCR session.
documentPk - the document which content is to be removed.
language - the language of the content which is to be removed.
Returns:
false if the document has no child node after the content remove, true otherwise.
Throws:
javax.jcr.RepositoryException

lock

public boolean lock(javax.jcr.Session session,
                    SimpleDocument document,
                    String owner)
             throws javax.jcr.RepositoryException
Lock a document if it is versionned to create a new work in progress version.

Parameters:
session -
document -
owner - the user locking the node.
Returns:
true if node has be checked out - false otherwise.
Throws:
javax.jcr.RepositoryException

unlock

public SimpleDocument unlock(javax.jcr.Session session,
                             SimpleDocument document,
                             boolean restore)
                      throws javax.jcr.RepositoryException
Unlock a document if it is versionned to create a new version or to restore a previous one. By using this method, the metadata of the content are always updated.

Parameters:
session - the current JCR open session to perform actions.
document - the document data from which all needed identifiers are retrieved.
restore - true to restore the previous version if any.
Returns:
the result of unlock(Session, SimpleDocument, boolean, boolean) execution.
Throws:
javax.jcr.RepositoryException

unlockFromContentDeletion

public SimpleDocument unlockFromContentDeletion(javax.jcr.Session session,
                                                SimpleDocument document)
                                         throws javax.jcr.RepositoryException
Unlock a document if it is versionned from a context into which a language content has just been deleted. This method does not update the metadata of the content in order to obtain an efficient content deletion.

Parameters:
session - the current JCR open session to perform actions.
document - the document data from which all needed identifiers are retrieved.
Returns:
the result of unlock(Session, SimpleDocument, boolean, boolean) execution.
Throws:
javax.jcr.RepositoryException

setVersionnable

public void setVersionnable(javax.jcr.Session session,
                            SimpleDocumentPK documentPk)
                     throws javax.jcr.RepositoryException
Add the version feature to an existing document. If the document has already the version feature, nothing is done.

Parameters:
session -
documentPk -
Throws:
javax.jcr.RepositoryException

removeVersionnable

public void removeVersionnable(javax.jcr.Session session,
                               SimpleDocumentPK documentPk)
                        throws javax.jcr.RepositoryException
Remove the version feature to an existing document. If the document doesn't have already the version feature, nothing is done.

Parameters:
session -
documentPk -
Throws:
javax.jcr.RepositoryException

fillNodeName

public void fillNodeName(javax.jcr.Session session,
                         SimpleDocument document)
                  throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

storeContent

public long storeContent(SimpleDocument document,
                         InputStream in,
                         boolean update)
                  throws javax.jcr.RepositoryException,
                         IOException
Throws:
javax.jcr.RepositoryException
IOException

storeContent

public long storeContent(SimpleDocument document,
                         InputStream in)
                  throws javax.jcr.RepositoryException,
                         IOException
Throws:
javax.jcr.RepositoryException
IOException

duplicateContent

public void duplicateContent(SimpleDocument origin,
                             SimpleDocument document)
                      throws IOException,
                             javax.jcr.RepositoryException
Throws:
IOException
javax.jcr.RepositoryException

deleteContent

public void deleteContent(javax.jcr.Node documentNode,
                          String instanceId)
                   throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

copyMultilangContent

public void copyMultilangContent(SimpleDocument origin,
                                 SimpleDocument copy)
                          throws IOException
Throws:
IOException

copyFullContent

public void copyFullContent(SimpleDocument origin,
                            SimpleDocument copy)
                     throws IOException
Throws:
IOException

moveMultilangContent

public void moveMultilangContent(SimpleDocument origin,
                                 SimpleDocument copy)
                          throws IOException
Throws:
IOException

moveFullContent

public void moveFullContent(SimpleDocument origin,
                            SimpleDocument copy)
                     throws IOException
Throws:
IOException

mergeAttachment

public void mergeAttachment(javax.jcr.Session session,
                            SimpleDocument attachment,
                            SimpleDocument clone)
                     throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException


Copyright © 2016 Silverpeas. All Rights Reserved.