View Javadoc
1   /**
2    * This file Copyright (c) 2013-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.audit;
35  
36  import info.magnolia.jcr.decoration.ContentDecoratorPropertyWrapper;
37  import info.magnolia.jcr.util.NodeTypes;
38  
39  import java.io.InputStream;
40  import java.math.BigDecimal;
41  import java.util.Calendar;
42  
43  import javax.jcr.AccessDeniedException;
44  import javax.jcr.Binary;
45  import javax.jcr.ItemNotFoundException;
46  import javax.jcr.Node;
47  import javax.jcr.Property;
48  import javax.jcr.RepositoryException;
49  import javax.jcr.Value;
50  import javax.jcr.ValueFormatException;
51  import javax.jcr.lock.LockException;
52  import javax.jcr.nodetype.ConstraintViolationException;
53  import javax.jcr.version.VersionException;
54  
55  /**
56   * A Property wrapper implementation which inform
57   * Magnolia audit logging content decorator {@link info.magnolia.audit.MgnlAuditLoggingContentDecorator} about modify action on the property parent node.
58   */
59  public class MgnlAuditLoggingContentDecoratorPropertyWrapper extends ContentDecoratorPropertyWrapper<MgnlAuditLoggingContentDecorator> {
60  
61      public MgnlAuditLoggingContentDecoratorPropertyWrapper(Property property, MgnlAuditLoggingContentDecorator contentDecorator) {
62          super(property, contentDecorator);
63      }
64  
65      @Override
66      public void setValue(Value value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
67          super.setValue(value);
68          logActionModify();
69      }
70  
71      @Override
72      public void setValue(Value[] values) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
73          super.setValue(values);
74          logActionModify();
75      }
76  
77      @Override
78      public void setValue(String value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
79          super.setValue(value);
80          logActionModify();
81      }
82  
83      @Override
84      public void setValue(String[] values) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
85          super.setValue(values);
86          logActionModify();
87      }
88  
89      @Override
90      public void setValue(InputStream value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
91          super.setValue(value);
92  
93          logActionModify();
94      }
95  
96      @Override
97      public void setValue(Binary value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
98          super.setValue(value);
99          logActionModify();
100     }
101 
102     @Override
103     public void setValue(long value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
104         super.setValue(value);
105         logActionModify();
106     }
107 
108     @Override
109     public void setValue(double value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
110         super.setValue(value);
111         logActionModify();
112     }
113 
114     @Override
115     public void setValue(BigDecimal value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
116         super.setValue(value);
117         logActionModify();
118     }
119 
120     @Override
121     public void setValue(Calendar value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
122         super.setValue(value);
123         logActionModify();
124     }
125 
126     @Override
127     public void setValue(boolean value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
128         super.setValue(value);
129         logActionModify();
130     }
131 
132     @Override
133     public void setValue(Node value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
134         super.setValue(value);
135         logActionModify();
136     }
137 
138     private void logActionModify() throws RepositoryException, ItemNotFoundException, AccessDeniedException {
139         final String name = this.getName();
140         if (name.startsWith(NodeTypes.JCR_PREFIX) || name.startsWith(NodeTypes.MGNL_PREFIX)) {
141             // do not audit system or our prop updates (same as for metadata updates in old API)
142             return;
143         }
144         getContentDecorator().logActionModify(getParent());
145     }
146 
147 }