KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > module > admininterface > commands > DeleteCommand


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 2006 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.module.admininterface.commands;
14
15 import info.magnolia.cms.core.Content;
16 import info.magnolia.cms.util.AlertUtil;
17 import info.magnolia.context.Context;
18 import info.magnolia.context.MgnlContext;
19
20 import org.apache.commons.lang.StringUtils;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24
25 /**
26  * the command to delete one node
27  * @author jackie
28  */

29 public class DeleteCommand extends BaseRepositoryCommand {
30
31     private static Logger log = LoggerFactory.getLogger(DeleteCommand.class);
32
33     public boolean execute(Context ctx) {
34         try {
35             String JavaDoc parentPath = StringUtils.substringBeforeLast(getPath(), "/");
36             String JavaDoc label = StringUtils.substringAfterLast(getPath(), "/");
37             
38             Content parentNode = MgnlContext.getHierarchyManager(this.getRepository()).getContent(parentPath);
39             parentNode.delete(label);
40             parentNode.save();
41         }
42         catch (Exception JavaDoc e) {
43             AlertUtil.setException("cannot do delete", e, ctx);
44             return false;
45         }
46         return true;
47     }
48
49 }
50
Popular Tags