KickJava   Java API By Example, From Geeks To Geeks.

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


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.ServletResources;
41
42 import org.jahia.registries.JahiaContainerDefinitionsRegistry;
43
44 import org.jahia.data.containers.JahiaContainerList;
45 import org.jahia.data.containers.JahiaContainer;
46 import org.jahia.data.containers.JahiaContainerDefinition;
47
48 import org.jahia.data.fields.JahiaField;
49
50 import org.jahia.services.version.EntryLoadRequest;
51
52 import org.jahia.services.usermanager.JahiaUser;
53 import org.jahia.services.usermanager.JahiaGroup;
54 import org.jahia.services.usermanager.JahiaGroupManagerService;
55
56 import org.jahia.exceptions.JahiaException;
57
58 import org.apache.log4j.Logger;
59
60
61 /**
62  * Action used to Add a TrackBack ping to a given post
63  *
64  * @author Xavier Lawrence
65  */

66 public class AddTrackBackPingAction extends AbstractAction {
67     
68     // log4j logger
69
static Logger log = Logger.getLogger(AddTrackBackPingAction.class);
70     
71     private String JavaDoc postID;
72     private String JavaDoc title;
73     private String JavaDoc excerpt;
74     private String JavaDoc url;
75     private String JavaDoc blogName;
76     
77     /** Creates a new instance of AddTrackBackPingAction */
78     public AddTrackBackPingAction(String JavaDoc postID, String JavaDoc title, String JavaDoc excerpt,
79             String JavaDoc url, String JavaDoc blogName) {
80         this.postID = postID;
81         this.title = title;
82         this.excerpt = excerpt;
83         this.url = url;
84         this.blogName = blogName;
85     }
86     
87     /**
88      * Adds a TrackBack ping to the given post
89      */

90     public Object JavaDoc execute() throws JahiaException {
91         // Create commmon resources
92
super.init();
93         
94         // Load the Container and check the structure
95
final JahiaContainer postContainer = super.getContainer(
96                 Integer.parseInt(postID));
97         
98         if (postContainer == null) {
99             throw new JahiaException("Post: "+postID+
100                     " does not exist", "Container: "+postID+ " does not exist",
101                     JahiaException.ENTRY_NOT_FOUND,
102                     JahiaException.WARNING_SEVERITY);
103         }
104         
105         log.debug("Working on post: "+postContainer.getID());
106         
107         super.changePage(postContainer.getPageID());
108         
109         JahiaContainerDefinition def = JahiaContainerDefinitionsRegistry.
110                 getInstance().getDefinition(jParams.getSiteID(),
111                 containerNames.getValue(containerNames.BLOG_TB_LIST));
112         
113         JahiaContainerList trackBacks = postContainer.getContainerList(
114                 super.containerNames.getValue(containerNames.BLOG_TB_LIST));
115         
116         int listID, aclID;
117         if (trackBacks == null || trackBacks.getID() < 1) {
118             log.debug("Storing the first TB...");
119             listID = aclID = 0;
120             
121         } else {
122             listID = trackBacks.getID();
123             aclID = trackBacks.getAclID();
124         }
125         
126         JahiaContainer pingContainer = new JahiaContainer(
127                 0, jParams.getJahiaID(), jParams.getPageID(),
128                 listID, 0, aclID, def.getID(), 0,
129                 EntryLoadRequest.STAGING_WORKFLOW_STATE);
130         
131         // Save the new Container
132
containerService.saveContainer(pingContainer,
133                 postContainer.getID(), jParams);
134         
135         // Load the Container and check the structure
136
pingContainer = super.getContainer(pingContainer.getID(),
137                 jParams.getLocale().toString());
138         
139         log.debug("Working on container: "+pingContainer.getID());
140         
141         String JavaDoc fieldName = containerNames.getValue(containerNames.TB_URL);
142         JahiaField field = pingContainer.getField(fieldName);
143         field.setValue(url);
144         
145         fieldName = containerNames.getValue(containerNames.TB_PING_IP);
146         field = pingContainer.getField(fieldName);
147         String JavaDoc senderIP = ServletResources.getCurrentRequest().getRemoteAddr();
148         field.setValue(senderIP);
149         
150         if (title != null && title.length() > 0) {
151             fieldName = containerNames.getValue(containerNames.TB_TITLE);
152             field = pingContainer.getField(fieldName);
153             field.setValue(title);
154         }
155         
156         if (excerpt != null && excerpt.length() > 0) {
157             fieldName = containerNames.getValue(containerNames.TB_EXCERPT);
158             field = pingContainer.getField(fieldName);
159             super.setValue(field, excerpt);
160         }
161         
162         if (blogName != null && blogName.length() > 0) {
163             fieldName = containerNames.getValue(containerNames.TB_BLOG_NAME);
164             field = pingContainer.getField(fieldName);
165             field.setValue(blogName);
166         }
167         
168         JahiaGroup rootGroup = servicesRegistry.getJahiaGroupManagerService().
169                 lookupGroup(jParams.getSiteID(),
170                 JahiaGroupManagerService.ADMINISTRATORS_GROUPNAME);
171         
172         JahiaUser user = (JahiaUser)rootGroup.getRecursiveUserMembers().
173                 iterator().next();
174         
175         if (listID == 0) {
176             super.activateContainerList(pingContainer.getListID(),
177                     user, pingContainer.getPageID());
178         }
179         
180         containerService.saveContainer(postContainer, 0, jParams);
181         
182         containerService.saveContainer(pingContainer, postContainer.getID(),
183                 jParams);
184         
185         super.activateContainer(pingContainer.getID(), user);
186         super.activateContainer(postContainer.getID(), user);
187         
188         log.debug("Trackback added...");
189         return new Boolean JavaDoc(true);
190     }
191 }
192
Popular Tags