View Javadoc
1   /**
2    * This file Copyright (c) 2015 Magnolia International
3    * Ltd.  (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10   * This file is distributed in the hope that it will be
11   * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12   * implied warranty of MERCHANTABILITY or FITNESS FOR A
13   * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14   * Redistribution, except as permitted by whichever of the GPL
15   * or MNA you select, is prohibited.
16   *
17   * 1. For the GPL license (GPL), you can redistribute and/or
18   * modify this file under the terms of the GNU General
19   * Public License, Version 3, as published by the Free Software
20   * Foundation.  You should have received a copy of the GNU
21   * General Public License, Version 3 along with this program;
22   * if not, write to the Free Software Foundation, Inc., 51
23   * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24   *
25   * 2. For the Magnolia Network Agreement (MNA), this file
26   * and the accompanying materials are made available under the
27   * terms of the MNA which accompanies this distribution, and
28   * is available at http://www.magnolia-cms.com/mna.html
29   *
30   * Any modifications to this file must keep this entire header
31   * intact.
32   *
33   */
34  package info.magnolia.jcr.decoration;
35  
36  import info.magnolia.jcr.wrapper.DelegateVersionManagerWrapper;
37  
38  import javax.jcr.AccessDeniedException;
39  import javax.jcr.InvalidItemStateException;
40  import javax.jcr.MergeException;
41  import javax.jcr.NoSuchWorkspaceException;
42  import javax.jcr.Node;
43  import javax.jcr.NodeIterator;
44  import javax.jcr.RepositoryException;
45  import javax.jcr.UnsupportedRepositoryOperationException;
46  import javax.jcr.lock.LockException;
47  import javax.jcr.version.Version;
48  import javax.jcr.version.VersionException;
49  import javax.jcr.version.VersionHistory;
50  import javax.jcr.version.VersionManager;
51  
52  /**
53   * VersionManager wrapper that applies wrappers and filtering by delegating to a {@link ContentDecorator}.
54   *
55   * @param <D> implementation of decorator.
56   */
57  public class ContentDecoratorVersionManagerWrapper<D extends ContentDecorator> extends DelegateVersionManagerWrapper {
58  
59      private final D contentDecorator;
60  
61      public ContentDecoratorVersionManagerWrapper(VersionManager versionManager, D contentDecorator) {
62          super(versionManager);
63          this.contentDecorator = contentDecorator;
64      }
65  
66      public D getContentDecorator() {
67          return contentDecorator;
68      }
69  
70      @Override
71      public Version checkin(String absPath) throws VersionException, UnsupportedRepositoryOperationException, InvalidItemStateException, LockException, RepositoryException {
72          return wrapVersion(super.checkin(absPath));
73      }
74  
75      @Override
76      public Version checkpoint(String absPath) throws VersionException, UnsupportedRepositoryOperationException, InvalidItemStateException, LockException, RepositoryException {
77          return wrapVersion(super.checkpoint(absPath));
78      }
79  
80      @Override
81      public VersionHistory getVersionHistory(String absPath) throws UnsupportedRepositoryOperationException, RepositoryException {
82          return wrapVersionHistory(super.getVersionHistory(absPath));
83      }
84  
85      @Override
86      public Version getBaseVersion(String absPath) throws UnsupportedRepositoryOperationException, RepositoryException {
87          return wrapVersion(super.getBaseVersion(absPath));
88      }
89  
90      @Override
91      public NodeIterator merge(String absPath, String srcWorkspace, boolean bestEffort) throws NoSuchWorkspaceException, AccessDeniedException, MergeException, LockException, InvalidItemStateException, RepositoryException {
92          return wrapNodeIterator(super.merge(absPath, srcWorkspace, bestEffort));
93      }
94  
95      @Override
96      public NodeIterator merge(String absPath, String srcWorkspace, boolean bestEffort, boolean isShallow) throws NoSuchWorkspaceException, AccessDeniedException, MergeException, LockException, InvalidItemStateException, RepositoryException {
97          return wrapNodeIterator(super.merge(absPath, srcWorkspace, bestEffort, isShallow));
98      }
99  
100     @Override
101     public Node createConfiguration(String absPath) throws UnsupportedRepositoryOperationException, RepositoryException {
102         return wrapNode(super.createConfiguration(absPath));
103     }
104 
105     @Override
106     public Node setActivity(Node activity) throws UnsupportedRepositoryOperationException, RepositoryException {
107         Node previousActivity = super.setActivity(activity);
108         return previousActivity != null ? wrapNode(previousActivity) : null;
109     }
110 
111     @Override
112     public Node getActivity() throws UnsupportedRepositoryOperationException, RepositoryException {
113         Node activity = super.getActivity();
114         return activity != null ? wrapNode(activity) : null;
115     }
116 
117     @Override
118     public Node createActivity(String title) throws UnsupportedRepositoryOperationException, RepositoryException {
119         return wrapNode(super.createActivity(title));
120     }
121 
122     @Override
123     public NodeIterator merge(Node activityNode) throws VersionException, AccessDeniedException, MergeException, LockException, InvalidItemStateException, RepositoryException {
124         return wrapNodeIterator(super.merge(activityNode));
125     }
126 
127     protected Node wrapNode(Node node) {
128         return contentDecorator.wrapNode(node);
129     }
130 
131     protected NodeIterator wrapNodeIterator(NodeIterator nodeIterator) {
132         return contentDecorator.wrapNodeIterator(nodeIterator);
133     }
134 
135 
136     protected Version wrapVersion(Version version) {
137         return contentDecorator.wrapVersion(version);
138     }
139 
140     protected VersionHistory wrapVersionHistory(VersionHistory versionHistory) {
141         return contentDecorator.wrapVersionHistory(versionHistory);
142     }
143 }