Class DocumentRepository


  • @Repository
    public class DocumentRepository
    extends Object
    Repository of documents attached to some contributions in Silverpeas. This repository abstracts and wraps the use of the JCR by providing an API to work with SimpleDocument objects. It is a low-level technical class.
    Author:
    ehugonnet
    • Constructor Detail

      • DocumentRepository

        public DocumentRepository()
      • DocumentRepository

        protected DocumentRepository​(org.silverpeas.core.contribution.attachment.repository.DocumentConverter converter)
    • Method Detail

      • 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
        Creates the specified document attached to a contribution in Silverpeas. The contribution has to be referred by the SimpleDocument.getForeignId() identifier.
        Parameters:
        session - a session in the JCR
        document - the document to create in the JCR
        Returns:
        the unique identifier of the document
        Throws:
        javax.jcr.RepositoryException - if the creation in the JCR failed.
      • moveDocument

        public SimpleDocumentPK moveDocument​(javax.jcr.Session session,
                                             SimpleDocument document,
                                             ResourceReference destination)
                                      throws javax.jcr.RepositoryException
        Moves the document to another attached contribution.
        Parameters:
        session - a session in the JCR
        document - an exising document in the JCR to move from its actual contribution to another one.
        destination - a reference to another contribution in Silverpeas. This contribution can be within another component instance.
        Returns:
        the new identifier of the moved document.
        Throws:
        javax.jcr.RepositoryException - if an error occurs while moving the document in the JCR.
      • copyDocument

        public SimpleDocumentPK copyDocument​(javax.jcr.Session session,
                                             SimpleDocument document,
                                             ResourceReference destination)
                                      throws javax.jcr.RepositoryException
        Copies the document to another contribution. The operation duplicates the document and attaches it to the other contribution.
        Parameters:
        session - the session in the JCR.
        document - the document to copy.
        destination - the reference to the other contribution. The contribution can be in another component instance.
        Returns:
        the identifier of the copied document.
        Throws:
        javax.jcr.RepositoryException - if an error occurs while copying the document in the JCR.
      • copyDocument

        public SimpleDocumentPK copyDocument​(javax.jcr.Session session,
                                             HistorisedDocument document,
                                             ResourceReference destination)
                                      throws javax.jcr.RepositoryException
        Copies the versioned document to another contribution in Silverpeas. The operation duplicates the document and all of its versions, and attaches them to the other contribution.
        Parameters:
        session - a session in the JCR
        document - the document with all of its versions to copy
        destination - the reference to the other contribution. It can be in another component instance.
        Returns:
        the identifier of the copied historized document.
        Throws:
        javax.jcr.RepositoryException - if an error occurs while copying the document and all of its versions in the repository.
      • updateDocument

        public void updateDocument​(javax.jcr.Session session,
                                   SimpleDocument document,
                                   boolean updateLastModifiedData)
                            throws javax.jcr.RepositoryException
        Updates the documents in the JCR. The specified document contains the new data with which the document in the JCR has to be updated. The document in the JCR is referred by the unique identifier of the specified document.
        Parameters:
        session - a session in the JCR
        document - the document to update
        updateLastModifiedData - a flag indicating if the modification date and the last modifier has to be explicitly done.
        Throws:
        javax.jcr.RepositoryException - if the update in the JCR fails.
      • saveForbiddenDownloadForRoles

        public void saveForbiddenDownloadForRoles​(javax.jcr.Session session,
                                                  SimpleDocument document)
                                           throws javax.jcr.RepositoryException
        Saves the optional slv:forbiddenDownloadForRoles document property (a mixin). This saving works with versionable documents without changing the major and minor version. This property is transverse between all versions.
        Parameters:
        session - a session in the JCR
        document - the document for which download has to be forbidden for some user roles.
        Throws:
        javax.jcr.RepositoryException - if an error occurs while saving the mixin.
      • saveDisplayableAsContent

        public void saveDisplayableAsContent​(javax.jcr.Session session,
                                             SimpleDocument document)
                                      throws javax.jcr.RepositoryException
        Saves the optional slv:displayableAsContent simple document property (a mixin). This saving works with versionable documents without changing the major and minor version. This property is transverse between all versions.
        Parameters:
        session - a session in the JCR
        document - the document for which the content can be automatically displayed.
        Throws:
        javax.jcr.RepositoryException - if an error occurs while saving the mixin.
      • saveEditableSimultaneously

        public void saveEditableSimultaneously​(javax.jcr.Session session,
                                               SimpleDocument document)
                                        throws javax.jcr.RepositoryException
        Saves the optional slv:editableSimultaneously simple document property (a mixin). This saving works with versionable documents without changing the major and minor version. This property is transverse between all versions.
        Parameters:
        session - a session in the JCR
        document - the document for which the simultaneous edition can be done.
        Throws:
        javax.jcr.RepositoryException - if an error occurs while saving the mixin.
      • setClone

        public void setClone​(javax.jcr.Session session,
                             SimpleDocument original,
                             SimpleDocument clone)
                      throws javax.jcr.RepositoryException
        Adds the document's clone id to the document even if it is locked. This saving works with versionable documents without changing the major and minor version. This property is transverse between all versions.
        Parameters:
        session - the JCR session.
        original - the original document to be cloned.
        clone - the cone of the original document.
        Throws:
        javax.jcr.RepositoryException - if an error occurs while setting the clone identifier to the document in the JCR.
      • 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 property is not versionable. This saving works with versionable documents without changing the major and minor version. This property is transverse between all versions.
        Throws:
        javax.jcr.RepositoryException
      • deleteDocument

        public void deleteDocument​(javax.jcr.Session session,
                                   SimpleDocumentPK documentPk)
                            throws javax.jcr.RepositoryException
        Deletes the document in the JCR referred by the specified identifier.
        Parameters:
        session - a session in the JCR.
        documentPk - the unique identifier of the document to delete.
        Throws:
        javax.jcr.RepositoryException - if the deletion of the document in the JCR fails.
      • 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 it is locked. If the document is currently with version management, then the whole versions history is removed and the document becomes a simple document with no more version history. If the document isn't versioned then a new public version is created and the document becomes a document with a version history management.
        Parameters:
        session - a session in the JCR
        documentPk - the id of the document.
        comment - the comment of the user about the first version in the case the versioning is enabled.
        Throws:
        javax.jcr.RepositoryException - if the version management switch fails
        IOException - if an error occurs while accessing the filesystem to create or remove versions of the related document
      • findDocumentById

        public SimpleDocument findDocumentById​(javax.jcr.Session session,
                                               SimpleDocumentPK documentPk,
                                               String lang)
                                        throws javax.jcr.RepositoryException
        Finds the document referred by the specified identifier and written in the given language. The document can be proposed in different languages, in this case the language parameter indicates the version of the document to find.
        Parameters:
        session - the session in the JCR.
        documentPk - the unique identifier of the document;
        lang - the language in which the document to find is written.
        Returns:
        the document or null if no such document exists.
        Throws:
        javax.jcr.RepositoryException - if an error occurs while looking for the document.
      • findDocumentByOldSilverpeasId

        public SimpleDocument findDocumentByOldSilverpeasId​(javax.jcr.Session session,
                                                            String instanceId,
                                                            long oldSilverpeasId,
                                                            boolean versioned,
                                                            String lang)
                                                     throws javax.jcr.RepositoryException
        Finds the document referred by its old unique identifier and in the given language. In old days of the management of the documents in Silverpeas, the documents were stored in a database, and they were uniquely identified by an identifier crafted by this database. After their transition to the JCR, a new schema of unique identifier has been applied to them and a need to maintain a map between old identifier and new one for older documents was required.
        Parameters:
        session - the session in the JCR.
        instanceId - the unique instance of the component in which the document is managed.
        oldSilverpeasId - the old unique identifier of the document.
        versioned - a boolean indicating if the document is or not versioned.
        lang - the language in which the document is written.
        Returns:
        the document or null if no such document exists.
        Throws:
        javax.jcr.RepositoryException - if an error occurs while looking for the document.
      • 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 - if an error occurs
      • 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 - if an error occurs
      • 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 - the type of required documents.
        language - the language in which the documents are required.
        Returns:
        an ordered list of the documents.
        Throws:
        javax.jcr.RepositoryException - if an error occurs
      • 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 - the type of required documents.
        language - the language in which the documents are required.
        Returns:
        an ordered list of the documents.
        Throws:
        javax.jcr.RepositoryException - if an error occurs
      • 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 - if an error occurs
      • 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 - if an error occurs
      • 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 - if an error occurs with the JCR
      • 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 - if an error occurs with the JCR
      • 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 - if an error occurs with the JCR
      • 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 - if an error occurs in the JCR
      • 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 - if an error occurs in the JCR
        IOException - if the access to the filesystem fails
      • 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 - if an error occurs in the JCR
      • checkout

        public boolean checkout​(javax.jcr.Session session,
                                SimpleDocument document,
                                String owner)
                         throws javax.jcr.RepositoryException
        Checkout the specified document if it is versioned to create a new work in progress version. In the JCR the versioned documents are protected for direct modifications. The checking out mechanism is a way to create a working copy of the document on which the modification will be done. Once the modifications done, don't forget to invoke one of the checkin methods to create a new version of the document from its modified working copy.

        Any non-versioned documents are by default modifiable and hence doesn't required to be explicitly checked out.

        Parameters:
        session - the session in the JCR
        document - the document to lock.
        owner - the user asking to checkout the node.
        Returns:
        true if node has be checked out, false otherwise.
        Throws:
        javax.jcr.RepositoryException - if an error occurs in the JCR
      • checkin

        public SimpleDocument checkin​(javax.jcr.Session session,
                                      SimpleDocument document,
                                      boolean restore)
                               throws javax.jcr.RepositoryException
        Checkin the specified document if it is versioned 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:
        document updated.
        Throws:
        javax.jcr.RepositoryException - if an error occurs in the JCR
      • checkinFromContentDeletion

        public SimpleDocument checkinFromContentDeletion​(javax.jcr.Session session,
                                                         SimpleDocument document)
                                                  throws javax.jcr.RepositoryException
        Checkin a document if it is versioned 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 document updated.
        Throws:
        javax.jcr.RepositoryException - if an error occurs in the JCR
      • fillNodeName

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

        public void deleteContent​(String instanceId,
                                  String nodeName)
      • mergeAttachment

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