1 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 ; 54 import java.util.HashSet ; 55 56 62 public class DeletePostAction extends AbstractAction { 63 64 static Logger log = Logger.getLogger(DeletePostAction.class); 66 67 private String postID; 68 private boolean publish; 69 70 73 public DeletePostAction(String appKey, String postID, String userName, 74 String 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 86 public DeletePostAction(String postID, String userName, 87 String password, boolean publish) { 88 89 super.userName = userName; 90 super.password = password; 91 this.postID = postID; 92 this.publish = publish; 93 } 94 95 100 public Object execute() throws JahiaException { 101 102 super.init(); 104 105 final JahiaUser user = super.checkLogin(); 107 108 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 Set curLanguageCodes = new HashSet (); 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 (true); 152 } 153 } 154 | Popular Tags |