View Javadoc
1   /*
2    * Copyright (C) 2003-2008 eXo Platform SAS.
3    *
4    * This program is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Affero General Public License
6    * as published by the Free Software Foundation; either version 3
7    * of the License, or (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program; if not, see<http://www.gnu.org/licenses/>.
16   */
17  package org.exoplatform.services.cms.jcrext;
18  
19  import java.util.GregorianCalendar;
20  
21  import javax.jcr.Node;
22  import javax.jcr.Property;
23  
24  import org.apache.commons.chain.Context;
25  import org.exoplatform.services.command.action.Action;
26  import org.exoplatform.services.security.ConversationState;
27  
28  /**
29   * Created by The eXo Platform SARL
30   * Author : Dang Van Minh
31   *          minh.dang@exoplatform.com
32   * Nov 2, 2009
33   * 3:09:32 AM
34   */
35  /**
36   * Store all informations of node's modification
37   *
38   */
39  public class ModifyNodeAction implements Action {
40  
41    public boolean execute(Context context) throws Exception {
42      Object item = context.get("currentItem");
43      Node node = (item instanceof Property) ?
44                  ((Property)item).getParent() :
45                  (Node)item;
46      if(node.isNodeType("nt:resource")) node = node.getParent();
47      ConversationState conversationState = ConversationState.getCurrent();
48      String userName = (conversationState == null) ? node.getSession().getUserID() :
49                                                      conversationState.getIdentity().getUserId();
50      if(node.canAddMixin("exo:modify")) {
51        node.addMixin("exo:modify");
52      }
53      node.setProperty("exo:lastModifiedDate", new GregorianCalendar());
54      node.setProperty("exo:lastModifier",userName);
55      return false;
56    }
57  
58  }