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 javax.jcr.Node;
20  import javax.jcr.Property;
21  
22  import org.apache.commons.chain.Context;
23  import org.exoplatform.services.cms.impl.Utils;
24  import org.exoplatform.services.command.action.Action;
25  import org.exoplatform.services.wcm.core.NodetypeConstant;
26  
27  /**
28   * Created by The eXo Platform SARL
29   * Author : Nguyen Anh Vu
30   *          vu.nguyen@exoplatform.com
31   * Aug 17, 2010
32   * 3:09:32 PM
33   */
34  /**
35   * Store node name
36   *
37   */
38  public class AddNodeNameAction implements Action {
39  
40   public boolean execute(Context context) throws Exception {
41     Object item = context.get("currentItem");
42     Node node = (item instanceof Property) ? ((Property)item).getParent() :
43                                              (Node)item;
44     if(node.isNodeType("nt:resource")) node = node.getParent();
45  
46     if(node.canAddMixin("exo:sortable")) {
47       node.addMixin("exo:sortable");
48     }
49  
50     if (!node.hasProperty("exo:name")) {
51         node.setProperty("exo:name", node.getName());
52     }
53     
54     if(node.isNodeType(NodetypeConstant.EXO_SYMLINK)) {
55    	 if (!node.hasProperty("exo:title")) {
56         node.setProperty("exo:title", Utils.getTitle(node));
57       }
58     }
59  
60     return false;
61   }
62  
63  }