KickJava   Java API By Example, From Geeks To Geeks.

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


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.MetaPostInfo;
41
42 import org.jahia.data.containers.JahiaContainerList;
43 import org.jahia.data.containers.JahiaContainer;
44
45 import org.jahia.data.fields.JahiaField;
46
47 import org.jahia.exceptions.JahiaException;
48
49 import org.apache.log4j.Logger;
50
51 import java.util.Vector JavaDoc;
52 import java.util.Hashtable JavaDoc;
53 import java.util.Enumeration JavaDoc;
54
55 /**
56  * Action used to get a post's TrackBakc pings from the Jahia content repository.
57  * Compliant with MovableType API's getTrackBackPings method.
58  *
59  * @author Xavier Lawrence
60  */

61 public class GetTrackBackPingsAction extends AbstractAction {
62     
63     // log4j logger
64
static Logger log = Logger.getLogger(GetTrackBackPingsAction.class);
65     
66     private String JavaDoc postID;
67     
68     /** Creates a new instance of GetTrackBackPingsAction */
69     public GetTrackBackPingsAction(String JavaDoc postID) {
70         this.postID = postID;
71     }
72     
73     /**
74      *
75      */

76     public Object JavaDoc execute() throws JahiaException {
77         
78         // Create commmon resources
79
super.init();
80         
81         // Load the Container and check the structure
82
final JahiaContainer postContainer = super.getContainer(
83                 Integer.parseInt(postID));
84         
85         if (postContainer == null) {
86             throw new JahiaException("Post: "+postID+
87                     " does not exist", "Container: "+postID+ " does not exist",
88                     JahiaException.ENTRY_NOT_FOUND,
89                     JahiaException.WARNING_SEVERITY);
90         }
91         
92         log.debug("Working on post: "+postContainer.getID());
93         
94         super.changePage(postContainer.getPageID());
95         
96         JahiaContainerList trackBacks = postContainer.getContainerList(
97                 super.containerNames.getValue(containerNames.BLOG_TB_LIST));
98         
99         if (trackBacks == null || trackBacks.getID() < 1) {
100             log.debug("No Trackbacks found");
101             return new Vector JavaDoc(0, 0);
102         }
103         
104         log.debug("Found "+trackBacks.size()+" trackbacks");
105         
106         Vector JavaDoc result = new Vector JavaDoc(trackBacks.size());
107         Enumeration JavaDoc e = trackBacks.getContainers();
108         
109         while (e.hasMoreElements()) {
110             Hashtable JavaDoc tb = new Hashtable JavaDoc(3);
111             JahiaContainer tbContainer = (JahiaContainer)e.nextElement();
112             
113             log.debug("Working on Container: "+tbContainer.getID());
114             
115             String JavaDoc fieldName = containerNames.getValue(containerNames.TB_BLOG_NAME);
116             JahiaField field = tbContainer.getField(fieldName);
117             if (field != null) tb.put(MetaPostInfo.PING_TITLE, field.getValue());
118             
119             fieldName = containerNames.getValue(containerNames.TB_URL);
120             field = tbContainer.getField(fieldName);
121             if (field != null) tb.put(MetaPostInfo.PING_URL, field.getValue());
122             
123             fieldName = containerNames.getValue(containerNames.TB_PING_IP);
124             field = tbContainer.getField(fieldName);
125             if (field != null) tb.put(MetaPostInfo.PING_IP, field.getValue());
126             
127             result.addElement(tb);
128         }
129         
130         log.debug("TrackBack Pings are: "+result);
131         return result;
132     }
133 }
134
Popular Tags