KickJava   Java API By Example, From Geeks To Geeks.

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


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.data.containers.JahiaContainer;
41
42 import org.jahia.services.usermanager.JahiaUser;
43
44 import org.jahia.services.categories.Category;
45
46 import org.jahia.exceptions.JahiaException;
47
48 import org.apache.log4j.Logger;
49
50 import java.util.Hashtable JavaDoc;
51 import java.util.Set JavaDoc;
52
53 /**
54  * Action used to get a user's post information from the Jahia content repository.
55  * Compliant with Blogger API's and MetaWeblog API's getPost method.
56  *
57  * @author Xavier Lawrence
58  */

59 public class GetPostAction extends AbstractAction {
60     
61     // log4j logger
62
static Logger log = Logger.getLogger(GetPostAction.class);
63     
64     private String JavaDoc postID;
65     private boolean meta;
66     
67     /**
68      * Creates a new instance of GetPostAction (Blogger API)
69      */

70     public GetPostAction(String JavaDoc appKey, String JavaDoc postID,
71             String JavaDoc userName, String JavaDoc password) {
72         super.appKey = appKey;
73         super.userName = userName;
74         super.password = password;
75         this.postID = postID;
76         meta = false;
77     }
78     
79     /**
80      * Creates a new instance of GetPostAction (MetaWeblog API)
81      */

82     public GetPostAction(String JavaDoc postID,
83             String JavaDoc userName, String JavaDoc password) {
84         super.userName = userName;
85         super.password = password;
86         this.postID = postID;
87         meta = true;
88     }
89     
90     /**
91      * Retrieves a given post.
92      *
93      * @return A Hashtable containing the post information
94      */

95     public Object JavaDoc execute() throws JahiaException {
96         
97         // Create commmon resources
98
super.init();
99         
100         // First check that the user is registered to this site.
101
final JahiaUser user = super.checkLogin();
102         
103         // Load the Container and check the structure
104
final JahiaContainer postContainer = super.getContainer(
105                 Integer.parseInt(postID));
106         
107         if (postContainer == null) {
108             throw new JahiaException("Post: "+postID+
109                     " does not exist", "Container: "+postID+ " does not exist",
110                     JahiaException.ENTRY_NOT_FOUND,
111                     JahiaException.WARNING_SEVERITY);
112         }
113        
114         log.debug("Working on container: "+postContainer.getID());
115         
116         // Prepare the return object
117
Hashtable JavaDoc postInfo;
118         if (meta) {
119            Set JavaDoc set = Category.getObjectCategories(postContainer.
120                    getContentContainer().getObjectKey());
121             postInfo = super.createMetaPostInfo(postContainer, set);
122         } else {
123             postInfo = super.createPostInfo(postContainer);
124         }
125         
126         log.debug("Post info is: "+ postInfo);
127         return postInfo;
128     }
129 }
130
Popular Tags