KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > blogs > actions > DeletePostAction


1 /*
2  * ____.
3  * __/\ ______| |__/\. _______
4  * __ .____| | \ | +----+ \
5  * _______| /--| | | - \ _ | : - \_________
6  * \\______: :---| : : | : | \________>
7  * |__\---\_____________:______: :____|____:_____\
8  * /_____|
9  *
10  * . . . i n j a h i a w e t r u s t . . .
11  *
12  *
13  *
14  * ----- BEGIN LICENSE BLOCK -----
15  * Version: JCSL 1.0
16  *
17  * The contents of this file are subject to the Jahia Community Source License
18  * 1.0 or later (the "License"); you may not use this file except in
19  * compliance with the License. You may obtain a copy of the License at
20  * http://www.jahia.org/license
21  *
22  * Software distributed under the License is distributed on an "AS IS" basis,
23  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
24  * for the rights, obligations and limitations governing use of the contents
25  * of the file. The Original and Upgraded Code is the Jahia CMS and Portal
26  * Server. The developer of the Original and Upgraded Code is JAHIA Ltd. JAHIA
27  * Ltd. owns the copyrights in the portions it created. All Rights Reserved.
28  *
29  * The Shared Modifications are Jahia View Helper.
30  *
31  * The Developer of the Shared Modifications is Jahia Solution Sàrl.
32  * Portions created by the Initial Developer are Copyright (C) 2002 by the
33  * Initial Developer. All Rights Reserved.
34  *
35  * ----- END LICENSE BLOCK -----
36  */

37
38 package org.jahia.blogs.actions;
39
40 import org.jahia.content.ContentContainerKey;
41 import org.jahia.content.ContentObject;
42
43 import org.jahia.data.containers.JahiaContainer;
44
45 import org.jahia.services.usermanager.JahiaUser;
46
47 import org.jahia.services.version.StateModificationContext;
48
49 import org.jahia.exceptions.JahiaException;
50
51 import org.apache.log4j.Logger;
52
53 import java.util.Set JavaDoc;
54 import java.util.HashSet JavaDoc;
55
56 /**
57  * Action used to delete a post from the Jahia content repository. Compliant with
58  * Blogger API's and MetaWeblog API's deletePost method.
59  *
60  * @author Xavier Lawrence
61  */

62 public class DeletePostAction extends AbstractAction {
63     
64     // log4j logger
65
static Logger log = Logger.getLogger(DeletePostAction.class);
66     
67     private String JavaDoc postID;
68     private boolean publish;
69     
70     /**
71      * Creates a new instance of DeletePostAction (Blogger API)
72      */

73     public DeletePostAction(String JavaDoc appKey, String JavaDoc postID, String JavaDoc userName,
74             String JavaDoc password, boolean publish) {
75         
76         super.appKey = appKey;
77         super.userName = userName;
78         super.password = password;
79         this.postID = postID;
80         this.publish = publish;
81     }
82     
83     /**
84      * Creates a new instance of DeletePostAction (MetaWeblog API)
85      */

86     public DeletePostAction(String JavaDoc postID, String JavaDoc userName,
87             String JavaDoc password, boolean publish) {
88         
89         super.userName = userName;
90         super.password = password;
91         this.postID = postID;
92         this.publish = publish;
93     }
94     
95     /**
96      * Deletes a given post.
97      *
98      * @return True if the deletion was succesfull
99      */

100     public Object JavaDoc execute() throws JahiaException {
101         
102         // Create commmon resources
103
super.init();
104         
105         // First check that the user is registered to this site.
106
final JahiaUser user = super.checkLogin();
107               
108         // Load the Container and check the structure
109
final JahiaContainer postContainer = super.getContainer(
110                 Integer.parseInt(postID), "en");
111         
112         if (postContainer == null) {
113             throw new JahiaException("Post: "+postID+
114                     " does not exist", "Container: "+postID+ " does not exist",
115                     JahiaException.ENTRY_NOT_FOUND,
116                     JahiaException.WARNING_SEVERITY);
117         }
118         
119         if (!postContainer.checkWriteAccess(user)) {
120             throw new JahiaException(
121                     "You do not have write access to Post: "+postID,
122                     "You do not have write access to Container: "+postID,
123                     JahiaException.ACL_ERROR,
124                     JahiaException.WARNING_SEVERITY);
125         }
126         
127         log.debug("About to delete container: "+postContainer.getID());
128         
129         // we only need to remove the shared language since this will
130
// automatically mark all sub languages for deletion too...
131
Set JavaDoc curLanguageCodes = new HashSet JavaDoc();
132         curLanguageCodes.add(ContentObject.SHARED_LANGUAGE);
133         curLanguageCodes.add(jParams.getLocale().toString());
134                 
135         StateModificationContext stateModifContext =
136                 new StateModificationContext(new ContentContainerKey(
137                 postContainer.getID()), curLanguageCodes, true);
138         stateModifContext.pushAllLanguages(true);
139         
140         containerService.markContainerLanguageForDeletion(postContainer.getID(),
141                 user, ContentObject.SHARED_LANGUAGE, stateModifContext);
142         
143         if (publish) {
144             super.changePage(postContainer.getPageID());
145             super.activateContainer(postContainer.getID(), user);
146         }
147         
148         super.flushPageCacheThatDisplayContainer(postContainer);
149         
150         log.debug("Post: "+postContainer.getID()+ " deleted");
151         return new Boolean JavaDoc(true);
152     }
153 }
154
Popular Tags