/** * This file Copyright (c) 2013 Magnolia International * Ltd. (http://www.magnolia-cms.com). All rights reserved. * * * This file is dual-licensed under both the Magnolia * Network Agreement and the GNU General Public License. * You may elect to use one or the other of these licenses. * * This file is distributed in the hope that it will be * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the * implied warranty of MERCHANTABILITY or FITNESS FOR A * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT. * Redistribution, except as permitted by whichever of the GPL * or MNA you select, is prohibited. * * 1. For the GPL license (GPL), you can redistribute and/or * modify this file under the terms of the GNU General * Public License, Version 3, as published by the Free Software * Foundation. You should have received a copy of the GNU * General Public License, Version 3 along with this program; * if not, write to the Free Software Foundation, Inc., 51 * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * 2. For the Magnolia Network Agreement (MNA), this file * and the accompanying materials are made available under the * terms of the MNA which accompanies this distribution, and * is available at http://www.magnolia-cms.com/mna.html * * Any modifications to this file must keep this entire header * intact. * */ package info.magnolia.jcr.wrapper; import info.magnolia.jcr.decoration.ContentDecoratorNodeWrapper; import info.magnolia.repository.RepositoryConstants; import java.io.InputStream; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Calendar; import java.util.List; import javax.jcr.AccessDeniedException; import javax.jcr.Binary; import javax.jcr.InvalidItemStateException; import javax.jcr.ItemExistsException; import javax.jcr.ItemNotFoundException; import javax.jcr.Node; import javax.jcr.PathNotFoundException; import javax.jcr.Property; import javax.jcr.ReferentialIntegrityException; import javax.jcr.RepositoryException; import javax.jcr.UnsupportedRepositoryOperationException; import javax.jcr.Value; import javax.jcr.ValueFormatException; import javax.jcr.lock.LockException; import javax.jcr.nodetype.ConstraintViolationException; import javax.jcr.nodetype.NoSuchNodeTypeException; import javax.jcr.version.Version; import javax.jcr.version.VersionException; /** * Wrapper to handle all content modifications necessary for keeping activation up to date. */ public class LastUpdateNodeWrapper extends ContentDecoratorNodeWrapper { private List saveOnSave = new ArrayList(); public LastUpdateNodeWrapper(Node node, LastUpdateContentDecorator lastUpdateContentDecorator) { super(node, lastUpdateContentDecorator); } @Override public Property setProperty(String name, BigDecimal value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException { final Property prop = super.setProperty(name, value); this.updateLastModified(prop); return prop; } @Override public void setPrimaryType(String nodeTypeName) throws NoSuchNodeTypeException, VersionException, ConstraintViolationException, LockException, RepositoryException { super.setPrimaryType(nodeTypeName); this.updateLastModified(); } @Override public Property setProperty(String name, Binary value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException { final Property prop = super.setProperty(name, value); this.updateLastModified(prop); return prop; } @Override public Property setProperty(String name, boolean value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException { final Property prop = super.setProperty(name, value); this.updateLastModified(prop); return prop; } @Override public Property setProperty(String name, Calendar value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException { final Property prop = super.setProperty(name, value); this.updateLastModified(prop); return prop; } @Override public Property setProperty(String name, double value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException { final Property prop = super.setProperty(name, value); this.updateLastModified(prop); return prop; } @Override public Property setProperty(String name, InputStream value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException { final Property prop = super.setProperty(name, value); this.updateLastModified(prop); return prop; } @Override public Property setProperty(String name, long value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException { final Property prop = super.setProperty(name, value); this.updateLastModified(prop); return prop; } @Override public Property setProperty(String name, Node value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException { final Property prop = super.setProperty(name, value); this.updateLastModified(prop); return prop; } @Override public Property setProperty(String name, String value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException { final Property prop = super.setProperty(name, value); this.updateLastModified(prop); return prop; } @Override public Property setProperty(String name, String value, int type) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException { final Property prop = super.setProperty(name, value, type); this.updateLastModified(prop); return prop; } @Override public Property setProperty(String name, String[] values) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException { final Property prop = super.setProperty(name, values); this.updateLastModified(prop); return prop; } @Override public Property setProperty(String name, String[] values, int type) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException { final Property prop = super.setProperty(name, values, type); this.updateLastModified(prop); return prop; } @Override public Property setProperty(String name, Value value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException { final Property prop = super.setProperty(name, value); this.updateLastModified(prop); return prop; } @Override public Property setProperty(String name, Value value, int type) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException { final Property prop = super.setProperty(name, value, type); this.updateLastModified(prop); return prop; } @Override public Property setProperty(String name, Value[] values) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException { final Property prop = super.setProperty(name, values); this.updateLastModified(prop); return prop; } @Override public Property setProperty(String name, Value[] values, int type) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException { final Property prop = super.setProperty(name, values, type); this.updateLastModified(prop); return prop; } @Override public Node addNode(String relPath) throws ItemExistsException, PathNotFoundException, VersionException, ConstraintViolationException, LockException, RepositoryException { Node node = super.addNode(relPath); this.updateLastModified(); return node; } @Override public Node addNode(String relPath, String primaryNodeTypeName) throws ItemExistsException, PathNotFoundException, NoSuchNodeTypeException, LockException, VersionException, ConstraintViolationException, RepositoryException { Node node = super.addNode(relPath, primaryNodeTypeName); this.updateLastModified(); return node; } @Override public void orderBefore(String srcChildRelPath, String destChildRelPath) throws UnsupportedRepositoryOperationException, VersionException, ConstraintViolationException, ItemNotFoundException, LockException, RepositoryException { super.orderBefore(srcChildRelPath, destChildRelPath); String path = this.getPath() + "/" + srcChildRelPath; this.updateLastModified(path); this.saveOnSave.add(srcChildRelPath); } @Override public void doneMerge(Version version) throws VersionException, InvalidItemStateException, UnsupportedRepositoryOperationException, RepositoryException { super.doneMerge(version); this.updateLastModified(); } @Override public void remove() throws VersionException, LockException, ConstraintViolationException, AccessDeniedException, RepositoryException { Node parent = this.getParent(); super.remove(); // as insane as it might look we might need to update lud on parent in case this is the component in a page, but not otherwise! (except maybe for data) if (RepositoryConstants.WEBSITE.equals(this.getSession().getWorkspace().getName())) { getContentDecorator().updateLastModified(parent.getSession(), parent.getPath()); } } @Override public void restore(String versionName, boolean removeExisting) throws VersionException, ItemExistsException, UnsupportedRepositoryOperationException, LockException, InvalidItemStateException, RepositoryException { super.restore(versionName, removeExisting); this.updateLastModified(); } @Override public void restore(Version version, boolean removeExisting) throws VersionException, ItemExistsException, InvalidItemStateException, UnsupportedRepositoryOperationException, LockException, RepositoryException { super.restore(version, removeExisting); this.updateLastModified(); } @Override public void restore(Version version, String relPath, boolean removeExisting) throws PathNotFoundException, ItemExistsException, VersionException, ConstraintViolationException, UnsupportedRepositoryOperationException, LockException, InvalidItemStateException, RepositoryException { super.restore(version, relPath, removeExisting); this.updateLastModified(); } @Override public void restoreByLabel(String versionLabel, boolean removeExisting) throws VersionException, ItemExistsException, UnsupportedRepositoryOperationException, LockException, InvalidItemStateException, RepositoryException { super.restoreByLabel(versionLabel, removeExisting); this.updateLastModified(); } @Override public void save() throws AccessDeniedException, ItemExistsException, ConstraintViolationException, InvalidItemStateException, ReferentialIntegrityException, VersionException, LockException, NoSuchNodeTypeException, RepositoryException { super.save(); // we modified status of child node. This is not necessary when session.save() is called instead of node.save() for (String child : saveOnSave) { this.getNode(child).save(); } saveOnSave.clear(); } private void updateLastModified() throws PathNotFoundException, RepositoryException { if (this.isNew()) { // node itself is not saved, nothing to do return; } getContentDecorator().updateLastModified(this.getSession(), this.getPath()); } private void updateLastModified(String path) throws PathNotFoundException, RepositoryException { if (this.isNew()) { // node itself is not saved, nothing to do return; } getContentDecorator().updateLastModified(this.getSession(), path); } private void updateLastModified(Property prop) throws PathNotFoundException, RepositoryException { if (this.isNew()) { // node itself is not saved, nothing to do return; } getContentDecorator().updateLastModifiedProperty(this.getSession(), prop.getName(), this.getPath()); } }