KickJava   Java API By Example, From Geeks To Geeks.

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


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.blogs.model.BlogCategory;
41         
42 import org.jahia.data.containers.JahiaContainerList;
43 import org.jahia.data.containers.JahiaContainer;
44 import org.jahia.data.containers.JahiaContainerDefinition;
45
46 import org.jahia.data.fields.LoadFlags;
47 import org.jahia.data.fields.JahiaField;
48
49 import org.jahia.services.usermanager.JahiaUser;
50
51 import org.jahia.services.version.EntryLoadRequest;
52
53 import org.jahia.services.categories.Category;
54
55 import org.jahia.exceptions.JahiaException;
56
57 import java.util.Vector JavaDoc;
58 import java.util.Hashtable JavaDoc;
59
60 import org.apache.log4j.Logger;
61
62 /**
63  * Action used to set a post's categories pings into the Jahia content repository.
64  * Compliant with MovableType API's setPostCategories method.
65  *
66  * @author Xavier Lawrence
67  */

68 public class SetPostCategoriesAction extends AbstractAction {
69     
70         // log4j logger
71
static Logger log = Logger.getLogger(SetPostCategoriesAction.class);
72     
73     private String JavaDoc postID;
74     private Vector JavaDoc categories;
75     
76     /** Creates a new instance of SetPostCategories */
77     public SetPostCategoriesAction(String JavaDoc postID, String JavaDoc userName,
78             String JavaDoc passWord, Vector JavaDoc categories) {
79         this.postID = postID;
80         this.categories = categories;
81         super.userName = userName;
82         super.password = passWord;
83     }
84     
85     /**
86      */

87     public Object JavaDoc execute() throws JahiaException {
88     
89          // Create commmon resources
90
super.init();
91         
92         // First check that the user is registered to this site.
93
final JahiaUser user = super.checkLogin();
94         
95         // Load the Container and check the structure
96
final JahiaContainer postContainer = super.getContainer(Integer.
97                 parseInt(postID), jParams.getLocale().toString());
98         
99         log.debug("Working on container: "+postContainer.getID());
100         
101         // Prepare the return object ans set the categories for the given post
102
Vector JavaDoc categoryKeys = new Vector JavaDoc(categories.size());
103         for (int i=0; i<categories.size(); i++) {
104             categoryKeys.addElement(((Hashtable JavaDoc)categories.get(i)).get(
105                     BlogCategory.MT_CATEGORY_ID));
106         }
107         
108         super.setCategories(categoryKeys, postContainer);
109
110         log.debug("Post categories are: "+ categories);
111         return new Boolean JavaDoc(true);
112     }
113 }
114
Popular Tags