xlawrence 2005/04/22 16:01:22 CEST
Modified files: (Branch: JAHIA-4-1-BRANCH)
src/java/org/jahia/blogs BlogPingListener.java BlogTester.java
src/java/org/jahia/blogs/actions EditPostAction.java
Log:
Enable TB support
Revision Changes Path
1.1.2.2 +4 -1 jahia/src/java/org/jahia/blogs/BlogPingListener.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/src/java/org/jahia/blogs/BlogPingListener.java.diff?r1=1.1.2.1&r2=1.1.2.2&f=h
1.1.2.3 +5 -5 jahia/src/java/org/jahia/blogs/BlogTester.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/src/java/org/jahia/blogs/BlogTester.java.diff?r1=1.1.2.2&r2=1.1.2.3&f=h
1.1.2.6 +141 -7
jahia/src/java/org/jahia/blogs/actions/EditPostAction.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/src/java/org/jahia/blogs/actions/EditPostAction.java.diff?r1=1.1.2.5&r2=1.1.2.6&f=h
Index: BlogPingListener.java
===================================================================
RCS file:
/home/cvs/repository/jahia/src/java/org/jahia/blogs/Attic/BlogPingListener.java,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- BlogPingListener.java 22 Apr 2005 12:56:07 -0000 1.1.2.1
+++ BlogPingListener.java 22 Apr 2005 14:01:21 -0000 1.1.2.2
@@ -100,12 +100,15 @@
}
}
+ /**
+ * Does the same as containerAdded
+ */
public void containerUpdated(JahiaEvent je) {
containerAdded(je);
}
/**
- *
+ * Get the URL of a given post
*/
protected String getPostURL(JahiaEvent je, JahiaContainer container,
ContentPage page) throws JahiaException {
Index: BlogTester.java
===================================================================
RCS file:
/home/cvs/repository/jahia/src/java/org/jahia/blogs/Attic/BlogTester.java,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -r1.1.2.2 -r1.1.2.3
--- BlogTester.java 21 Apr 2005 15:40:27 -0000 1.1.2.2
+++ BlogTester.java 22 Apr 2005 14:01:21 -0000 1.1.2.3
@@ -132,12 +132,12 @@
String[] params = {postID};
String name = "mt.getTrackbackPings";
- log.info("Executing "+name);
- String result = execute(xmlrpc, name, toVector(params)).toString();
- log.info("Result of "+name+": "+result);
-
log.info("Sending ping...");
- result = sendPing(postID);
+ String result = sendPing(postID);
log.info("Result of ping: "+result);
+
+ log.info("Executing "+name);
+ result = execute(xmlrpc, name, toVector(params)).toString();
+ log.info("Result of "+name+": "+result);
}
}
Index: EditPostAction.java
===================================================================
RCS file:
/home/cvs/repository/jahia/src/java/org/jahia/blogs/actions/Attic/EditPostAction.java,v
retrieving revision 1.1.2.5
retrieving revision 1.1.2.6
diff -u -r1.1.2.5 -r1.1.2.6
--- EditPostAction.java 21 Apr 2005 08:19:56 -0000 1.1.2.5
+++ EditPostAction.java 22 Apr 2005 14:01:21 -0000 1.1.2.6
@@ -37,6 +37,8 @@
package org.jahia.blogs.actions;
+import org.jahia.blogs.BlogPingListener;
+
import org.jahia.blogs.model.MetaPostInfo;
import org.jahia.blogs.model.PostInfo;
@@ -55,6 +57,8 @@
import org.jahia.services.version.EntryLoadRequest;
+import org.jahia.data.events.JahiaEvent;
+
import org.jahia.exceptions.JahiaException;
import org.apache.commons.lang.StringUtils;
@@ -65,6 +69,7 @@
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Vector;
+import java.util.Enumeration;
/**
* Action used to edit a post from the Jahia content repository. Compliant
with
@@ -82,7 +87,7 @@
private Hashtable struct;
private boolean publish;
- /**
+ /**
* Creates a new instance of EditPostAction (Blogger API)
*/
public EditPostAction(String appKey, String postID, String userName,
@@ -96,7 +101,7 @@
this.publish = publish;
}
- /**
+ /**
* Creates a new instance of EditPostAction (MetaWeblog API)
*/
public EditPostAction(String postID, String userName, String password,
@@ -126,7 +131,7 @@
// Load the Container and check the structure
final JahiaContainer postContainer = super.getContainer(Integer.
parseInt(postID), jParams.getLocale().toString());
-
+
if (!postContainer.checkWriteAccess(user)) {
throw new JahiaException(
"You do not have write access to Post: "+postID,
@@ -163,7 +168,7 @@
fieldValue = (String)struct.get(MetaPostInfo.TITLE);
content = (String)struct.get(MetaPostInfo.DESCRIPTION);
Vector categories = (Vector)struct.get(MetaPostInfo.CATEGORIES);
- super.setCategories(categories, postContainer);
+ super.setCategories(categories, postContainer);
}
JahiaField field = postContainer.getField(fieldName);
@@ -175,15 +180,122 @@
super.setValue(field, content);
// set posting date
- fieldName = super.containerNames.getValue(containerNames.POST_DATE);
+ fieldName = super.containerNames.getValue(containerNames.POST_DATE);
field = postContainer.getField(fieldName);
field.setObject(Long.toString(System.currentTimeMillis()));
-
+
// set the author of the message
fieldName =
super.containerNames.getValue(containerNames.POST_AUTHOR);
field = postContainer.getField(fieldName);
field.setValue(userName);
+ // check if extra Movable Type are present in the struct
+ if (struct != null) {
+
+ fieldName = containerNames.getValue(containerNames.POST_EXCERPT);
+ field = postContainer.getField(fieldName);
+ if (struct.containsKey(MetaPostInfo.MT_EXCERPT)) {
+ String excerpt = (String)struct.get(MetaPostInfo.MT_EXCERPT);
+
+ if (excerpt != null && excerpt.length() > 0) {
+ field.setValue(excerpt);
+ }
+ }
+
+ fieldName =
containerNames.getValue(containerNames.POST_KEYWORDS);
+ field = postContainer.getField(fieldName);
+ if (struct.containsKey(MetaPostInfo.MT_KEYWORDS)) {
+ String keywords =
(String)struct.get(MetaPostInfo.MT_KEYWORDS);
+
+ if (keywords != null && keywords.length() > 0) {
+ field.setValue(keywords);
+ }
+ }
+
+ // Urls sent by the client
+ Vector tbURLs = (Vector)struct.get(MetaPostInfo.MT_TB_PING_URLS);
+
+ if (tbURLs != null && tbURLs.size() > 0) {
+
+ JahiaContainerDefinition def =
JahiaContainerDefinitionsRegistry.
+ getInstance().getDefinition(jParams.getSiteID(),
+
containerNames.getValue(containerNames.BLOG_TB_PING_LIST));
+
+ JahiaContainerList pingURLs = postContainer.getContainerList(
+
containerNames.getValue(containerNames.BLOG_TB_PING_LIST));
+
+ int listID = 0, aclID = 0;
+ if (pingURLs != null && pingURLs.getID() > 0) {
+ listID = pingURLs.getID();
+ }
+
+ Vector existingPings = getExistingPingURLs(pingURLs);
+ for (int i=0; i<tbURLs.size(); i++) {
+ String url = (String)tbURLs.get(i);
+
+ // url is allready stored, don't add it again
+ if (existingPings.contains(url)) continue;
+
+ // load the containerlist after each newly added
container
+ if (i > 0) {
+ pingURLs = containerService.loadContainerList(
+ listID, LoadFlags.ALL, jParams);
+ }
+
+ // check that the containerList exists
+ if (pingURLs != null && pingURLs.getID() > 0) {
+ listID = pingURLs.getID();
+ aclID = pingURLs.getAclID();
+
+ } else {
+ listID = aclID = 0;
+ }
+
+ JahiaContainer pingURLContainer = new JahiaContainer(
+ 0, jParams.getJahiaID(), jParams.getPageID(),
+ listID, 0, aclID, def.getID(), 0,
+ EntryLoadRequest.STAGING_WORKFLOW_STATE);
+
+ // Save the new Container
+ containerService.saveContainer(pingURLContainer,
+ postContainer.getID(), jParams);
+
+ // Load the Container and check the structure
+ pingURLContainer =
super.getContainer(pingURLContainer.getID(),
+ jParams.getLocale().toString());
+
+ log.debug("pingURLContainer: "+pingURLContainer.getID());
+ listID = pingURLContainer.getListID();
+ log.debug("on list: "+listID);
+
+ field = pingURLContainer.getField(containerNames.
+ getValue(containerNames.TB_PING_URL));
+ field.setValue(url);
+
+ containerService.saveContainer(pingURLContainer,
+ postContainer.getID(), jParams);
+
+ // Notify the listener so it can send the ping
+ JahiaEvent theEvent = new JahiaEvent(this, jParams,
+ pingURLContainer);
+ BlogPingListener l = new BlogPingListener();
+ l.containerAdded(theEvent);
+
+ if (i == 0) {
+
super.activateContainerList(pingURLContainer.getListID(),
+ user, pingURLContainer.getPageID());
+ }
+
+ if (publish) {
+ super.activateContainer(pingURLContainer.getID(),
user);
+ }
+
+ pingURLContainer = null;
+ url = null;
+ }
+ }
+ }
+
containerService.saveContainer(postContainer, 0, jParams);
if (publish) {
@@ -193,6 +305,28 @@
super.flushPageCacheThatDisplayContainer(postContainer);
log.debug("Post: "+postContainer.getID()+ " edited");
- return new Boolean(true);
+ return new Boolean(true);
+ }
+
+ /**
+ *
+ */
+ protected Vector getExistingPingURLs(JahiaContainerList list)
+ throws JahiaException {
+ Vector result = new Vector();
+
+ if (list == null) return result;
+
+ Enumeration en = list.getContainers();
+
+ while (en.hasMoreElements()) {
+ JahiaContainer c = (JahiaContainer)en.nextElement();
+ JahiaField f = c.getField(containerNames.getValue(containerNames.
+ TB_PING_URL));
+
+ result.addElement(f.getValue());
+
+ }
+ return result;
}
}