mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
Merged 5.1.N (5.1.2) to 5.2.N (5.2.1)
125605 rmunteanu: Merged 5.1.1 (5.1.1) to 5.1.N (5.1.2) 125498 slanglois: MNT-16155 Update source headers - remove svn:eol-style property on Java and JSP source files git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@125783 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,72 +1,72 @@
|
||||
package org.alfresco.repo.blog;
|
||||
|
||||
/**
|
||||
* Base blog implementation class. Extend this when writting a blog integration implementation.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public abstract class BaseBlogIntegrationImplementation implements BlogIntegrationImplementation
|
||||
{
|
||||
/** Blog integration service */
|
||||
private BlogIntegrationService blogIntegrationService;
|
||||
|
||||
/** Integration name */
|
||||
private String name;
|
||||
|
||||
/** Display name */
|
||||
private String displayName;
|
||||
|
||||
/**
|
||||
* Sets the blog integration service
|
||||
*
|
||||
* @param blogIntegrationService the blog integration service
|
||||
*/
|
||||
public void setBlogIntegrationService(BlogIntegrationService blogIntegrationService)
|
||||
{
|
||||
this.blogIntegrationService = blogIntegrationService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the blog implementation with the blog integration service.
|
||||
*/
|
||||
public void register()
|
||||
{
|
||||
this.blogIntegrationService.register(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of the blog integration service
|
||||
*
|
||||
* @param name the name
|
||||
*/
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.blog.BlogIntegrationImplementation#getName()
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the display name
|
||||
*
|
||||
* @param displayName the display name
|
||||
*/
|
||||
public void setDisplayName(String displayName)
|
||||
{
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.blog.BlogIntegrationImplementation#getDisplayName()
|
||||
*/
|
||||
public String getDisplayName()
|
||||
{
|
||||
return this.displayName;
|
||||
}
|
||||
}
|
||||
package org.alfresco.repo.blog;
|
||||
|
||||
/**
|
||||
* Base blog implementation class. Extend this when writting a blog integration implementation.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public abstract class BaseBlogIntegrationImplementation implements BlogIntegrationImplementation
|
||||
{
|
||||
/** Blog integration service */
|
||||
private BlogIntegrationService blogIntegrationService;
|
||||
|
||||
/** Integration name */
|
||||
private String name;
|
||||
|
||||
/** Display name */
|
||||
private String displayName;
|
||||
|
||||
/**
|
||||
* Sets the blog integration service
|
||||
*
|
||||
* @param blogIntegrationService the blog integration service
|
||||
*/
|
||||
public void setBlogIntegrationService(BlogIntegrationService blogIntegrationService)
|
||||
{
|
||||
this.blogIntegrationService = blogIntegrationService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the blog implementation with the blog integration service.
|
||||
*/
|
||||
public void register()
|
||||
{
|
||||
this.blogIntegrationService.register(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of the blog integration service
|
||||
*
|
||||
* @param name the name
|
||||
*/
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.blog.BlogIntegrationImplementation#getName()
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the display name
|
||||
*
|
||||
* @param displayName the display name
|
||||
*/
|
||||
public void setDisplayName(String displayName)
|
||||
{
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.blog.BlogIntegrationImplementation#getDisplayName()
|
||||
*/
|
||||
public String getDisplayName()
|
||||
{
|
||||
return this.displayName;
|
||||
}
|
||||
}
|
||||
|
@@ -1,189 +1,189 @@
|
||||
package org.alfresco.repo.blog;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.BlogIntegrationModel;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* Blog details. Contains the detail of a blog.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public class BlogDetails implements BlogIntegrationModel
|
||||
{
|
||||
/** Node that has the blog details aspect applied */
|
||||
private NodeRef nodeRef;
|
||||
|
||||
/** The blog implementation name (eg: wordpress, typepad, etc) */
|
||||
private String implementationName;
|
||||
|
||||
/** The blog id */
|
||||
private String blogId;
|
||||
|
||||
/** The blog URL */
|
||||
private String url;
|
||||
|
||||
/** The user name */
|
||||
private String userName;
|
||||
|
||||
/** The password */
|
||||
private String password;
|
||||
|
||||
/** The display name of the blog */
|
||||
private String name;
|
||||
|
||||
/** The description of the blog */
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* Create a BlogDetails object from a node that has the blogDetails aspect applied.
|
||||
*
|
||||
* @param nodeService the node service
|
||||
* @param nodeRef the node reference
|
||||
* @return BlogDetails the blog details
|
||||
*/
|
||||
public static BlogDetails createBlogDetails(NodeService nodeService, NodeRef nodeRef)
|
||||
{
|
||||
// Check for the blog details aspect
|
||||
if (nodeService.hasAspect(nodeRef, ASPECT_BLOG_DETAILS) == false)
|
||||
{
|
||||
throw new BlogIntegrationRuntimeException("Can not create blog details object since node does not have blogDetails aspect.");
|
||||
}
|
||||
|
||||
// Get the blog details
|
||||
Map<QName, Serializable> props = nodeService.getProperties(nodeRef);
|
||||
return new BlogDetails(
|
||||
(String)props.get(PROP_BLOG_IMPLEMENTATION),
|
||||
(String)props.get(PROP_ID),
|
||||
(String)props.get(PROP_URL),
|
||||
(String)props.get(PROP_USER_NAME),
|
||||
(String)props.get(PROP_PASSWORD),
|
||||
(String)props.get(PROP_NAME),
|
||||
(String)props.get(PROP_DESCRIPTION),
|
||||
nodeRef);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param implementationName the implementation name
|
||||
* @param blogId the blog id
|
||||
* @param url the blog URL
|
||||
* @param userName the user name
|
||||
* @param password the password
|
||||
* @param name the name
|
||||
* @param description the description
|
||||
*/
|
||||
public BlogDetails(String implementationName, String blogId, String url, String userName, String password, String name, String description)
|
||||
{
|
||||
this(implementationName, blogId, url, userName, password, name, description, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param implementationName the implementation name
|
||||
* @param blogId the blog id
|
||||
* @param url the blog URL
|
||||
* @param userName the user name
|
||||
* @param password the password
|
||||
* @param name the name
|
||||
* @param description the description
|
||||
* @param nodeRef the node reference
|
||||
*/
|
||||
public BlogDetails(String implementationName, String blogId, String url, String userName, String password, String name, String description, NodeRef nodeRef)
|
||||
{
|
||||
this.implementationName = implementationName;
|
||||
this.blogId = blogId;
|
||||
this.url = url;
|
||||
this.userName = userName;
|
||||
this.password = password;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.nodeRef = nodeRef;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the node reference
|
||||
*
|
||||
* @return NodeRef the node reference
|
||||
*/
|
||||
public NodeRef getNodeRef()
|
||||
{
|
||||
return nodeRef;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the implementation name
|
||||
*
|
||||
* @return String the implementation name
|
||||
*/
|
||||
public String getImplementationName()
|
||||
{
|
||||
return this.implementationName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the blog id
|
||||
*
|
||||
* @return String the blog id
|
||||
*/
|
||||
public String getBlogId()
|
||||
{
|
||||
return this.blogId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the blog URL
|
||||
*
|
||||
* @return String the blog URL
|
||||
*/
|
||||
public String getUrl()
|
||||
{
|
||||
return this.url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user name
|
||||
*
|
||||
* @return String the user name
|
||||
*/
|
||||
public String getUserName()
|
||||
{
|
||||
return this.userName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the password
|
||||
*
|
||||
* @return String the password
|
||||
*/
|
||||
public String getPassword()
|
||||
{
|
||||
return this.password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name
|
||||
*
|
||||
* @return String the name
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the description
|
||||
*
|
||||
* @return String the description
|
||||
*/
|
||||
public String getDescription()
|
||||
{
|
||||
return description;
|
||||
}
|
||||
}
|
||||
package org.alfresco.repo.blog;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.BlogIntegrationModel;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* Blog details. Contains the detail of a blog.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public class BlogDetails implements BlogIntegrationModel
|
||||
{
|
||||
/** Node that has the blog details aspect applied */
|
||||
private NodeRef nodeRef;
|
||||
|
||||
/** The blog implementation name (eg: wordpress, typepad, etc) */
|
||||
private String implementationName;
|
||||
|
||||
/** The blog id */
|
||||
private String blogId;
|
||||
|
||||
/** The blog URL */
|
||||
private String url;
|
||||
|
||||
/** The user name */
|
||||
private String userName;
|
||||
|
||||
/** The password */
|
||||
private String password;
|
||||
|
||||
/** The display name of the blog */
|
||||
private String name;
|
||||
|
||||
/** The description of the blog */
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* Create a BlogDetails object from a node that has the blogDetails aspect applied.
|
||||
*
|
||||
* @param nodeService the node service
|
||||
* @param nodeRef the node reference
|
||||
* @return BlogDetails the blog details
|
||||
*/
|
||||
public static BlogDetails createBlogDetails(NodeService nodeService, NodeRef nodeRef)
|
||||
{
|
||||
// Check for the blog details aspect
|
||||
if (nodeService.hasAspect(nodeRef, ASPECT_BLOG_DETAILS) == false)
|
||||
{
|
||||
throw new BlogIntegrationRuntimeException("Can not create blog details object since node does not have blogDetails aspect.");
|
||||
}
|
||||
|
||||
// Get the blog details
|
||||
Map<QName, Serializable> props = nodeService.getProperties(nodeRef);
|
||||
return new BlogDetails(
|
||||
(String)props.get(PROP_BLOG_IMPLEMENTATION),
|
||||
(String)props.get(PROP_ID),
|
||||
(String)props.get(PROP_URL),
|
||||
(String)props.get(PROP_USER_NAME),
|
||||
(String)props.get(PROP_PASSWORD),
|
||||
(String)props.get(PROP_NAME),
|
||||
(String)props.get(PROP_DESCRIPTION),
|
||||
nodeRef);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param implementationName the implementation name
|
||||
* @param blogId the blog id
|
||||
* @param url the blog URL
|
||||
* @param userName the user name
|
||||
* @param password the password
|
||||
* @param name the name
|
||||
* @param description the description
|
||||
*/
|
||||
public BlogDetails(String implementationName, String blogId, String url, String userName, String password, String name, String description)
|
||||
{
|
||||
this(implementationName, blogId, url, userName, password, name, description, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param implementationName the implementation name
|
||||
* @param blogId the blog id
|
||||
* @param url the blog URL
|
||||
* @param userName the user name
|
||||
* @param password the password
|
||||
* @param name the name
|
||||
* @param description the description
|
||||
* @param nodeRef the node reference
|
||||
*/
|
||||
public BlogDetails(String implementationName, String blogId, String url, String userName, String password, String name, String description, NodeRef nodeRef)
|
||||
{
|
||||
this.implementationName = implementationName;
|
||||
this.blogId = blogId;
|
||||
this.url = url;
|
||||
this.userName = userName;
|
||||
this.password = password;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.nodeRef = nodeRef;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the node reference
|
||||
*
|
||||
* @return NodeRef the node reference
|
||||
*/
|
||||
public NodeRef getNodeRef()
|
||||
{
|
||||
return nodeRef;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the implementation name
|
||||
*
|
||||
* @return String the implementation name
|
||||
*/
|
||||
public String getImplementationName()
|
||||
{
|
||||
return this.implementationName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the blog id
|
||||
*
|
||||
* @return String the blog id
|
||||
*/
|
||||
public String getBlogId()
|
||||
{
|
||||
return this.blogId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the blog URL
|
||||
*
|
||||
* @return String the blog URL
|
||||
*/
|
||||
public String getUrl()
|
||||
{
|
||||
return this.url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user name
|
||||
*
|
||||
* @return String the user name
|
||||
*/
|
||||
public String getUserName()
|
||||
{
|
||||
return this.userName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the password
|
||||
*
|
||||
* @return String the password
|
||||
*/
|
||||
public String getPassword()
|
||||
{
|
||||
return this.password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name
|
||||
*
|
||||
* @return String the name
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the description
|
||||
*
|
||||
* @return String the description
|
||||
*/
|
||||
public String getDescription()
|
||||
{
|
||||
return description;
|
||||
}
|
||||
}
|
||||
|
@@ -1,66 +1,66 @@
|
||||
package org.alfresco.repo.blog;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Blog integration implementation interface
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public interface BlogIntegrationImplementation
|
||||
{
|
||||
/**
|
||||
* Gets the name of the blog integration
|
||||
*
|
||||
* @return String the name of the blog integration
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Gets the display name of the blog integration
|
||||
*
|
||||
* @return String the display name of the blog integration
|
||||
*/
|
||||
String getDisplayName();
|
||||
|
||||
/**
|
||||
* Create a new post on the blog.
|
||||
*
|
||||
* @param blogDetails the blog details
|
||||
* @param title the title of the post
|
||||
* @param body the body of the post
|
||||
* @param publish indicates whether the post is published or not
|
||||
* @return String the newly created post id
|
||||
*/
|
||||
String newPost(BlogDetails blogDetails, String title, String body, boolean publish);
|
||||
|
||||
/**
|
||||
* Update an exisiting blog post
|
||||
*
|
||||
* @param blogDetails BlogDetails
|
||||
* @param postId String
|
||||
* @param title String
|
||||
* @param body String
|
||||
* @param publish boolean
|
||||
* @return boolean
|
||||
*/
|
||||
boolean updatePost(BlogDetails blogDetails, String postId, String title, String body, boolean publish);
|
||||
|
||||
/**
|
||||
* Get the details of an existing blog post
|
||||
*
|
||||
* @param blogDetails BlogDetails
|
||||
* @param postId String
|
||||
* @return Map
|
||||
*/
|
||||
Map<String, Object> getPost(BlogDetails blogDetails, String postId);
|
||||
|
||||
/**
|
||||
* Delete an existing blog post
|
||||
*
|
||||
* @param blogDetails BlogDetails
|
||||
* @param postId String
|
||||
* @return boolean
|
||||
*/
|
||||
boolean deletePost(BlogDetails blogDetails, String postId);
|
||||
}
|
||||
package org.alfresco.repo.blog;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Blog integration implementation interface
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public interface BlogIntegrationImplementation
|
||||
{
|
||||
/**
|
||||
* Gets the name of the blog integration
|
||||
*
|
||||
* @return String the name of the blog integration
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Gets the display name of the blog integration
|
||||
*
|
||||
* @return String the display name of the blog integration
|
||||
*/
|
||||
String getDisplayName();
|
||||
|
||||
/**
|
||||
* Create a new post on the blog.
|
||||
*
|
||||
* @param blogDetails the blog details
|
||||
* @param title the title of the post
|
||||
* @param body the body of the post
|
||||
* @param publish indicates whether the post is published or not
|
||||
* @return String the newly created post id
|
||||
*/
|
||||
String newPost(BlogDetails blogDetails, String title, String body, boolean publish);
|
||||
|
||||
/**
|
||||
* Update an exisiting blog post
|
||||
*
|
||||
* @param blogDetails BlogDetails
|
||||
* @param postId String
|
||||
* @param title String
|
||||
* @param body String
|
||||
* @param publish boolean
|
||||
* @return boolean
|
||||
*/
|
||||
boolean updatePost(BlogDetails blogDetails, String postId, String title, String body, boolean publish);
|
||||
|
||||
/**
|
||||
* Get the details of an existing blog post
|
||||
*
|
||||
* @param blogDetails BlogDetails
|
||||
* @param postId String
|
||||
* @return Map
|
||||
*/
|
||||
Map<String, Object> getPost(BlogDetails blogDetails, String postId);
|
||||
|
||||
/**
|
||||
* Delete an existing blog post
|
||||
*
|
||||
* @param blogDetails BlogDetails
|
||||
* @param postId String
|
||||
* @return boolean
|
||||
*/
|
||||
boolean deletePost(BlogDetails blogDetails, String postId);
|
||||
}
|
||||
|
@@ -1,58 +1,58 @@
|
||||
package org.alfresco.repo.blog;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
|
||||
/**
|
||||
* Blog integration runtime exception
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public class BlogIntegrationRuntimeException extends AlfrescoRuntimeException
|
||||
{
|
||||
private static final long serialVersionUID = -159901552962025003L;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param msgId String
|
||||
*/
|
||||
public BlogIntegrationRuntimeException(String msgId)
|
||||
{
|
||||
super(msgId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param msgId String
|
||||
* @param msgParams Object[]
|
||||
*/
|
||||
public BlogIntegrationRuntimeException(String msgId, Object[] msgParams)
|
||||
{
|
||||
super(msgId, msgParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param msgId String
|
||||
* @param cause Throwable
|
||||
*/
|
||||
public BlogIntegrationRuntimeException(String msgId, Throwable cause)
|
||||
{
|
||||
super(msgId, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param msgId String
|
||||
* @param msgParams Object[]
|
||||
* @param cause Throwable
|
||||
*/
|
||||
public BlogIntegrationRuntimeException(String msgId, Object[] msgParams, Throwable cause)
|
||||
{
|
||||
super(msgId, msgParams, cause);
|
||||
}
|
||||
|
||||
}
|
||||
package org.alfresco.repo.blog;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
|
||||
/**
|
||||
* Blog integration runtime exception
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public class BlogIntegrationRuntimeException extends AlfrescoRuntimeException
|
||||
{
|
||||
private static final long serialVersionUID = -159901552962025003L;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param msgId String
|
||||
*/
|
||||
public BlogIntegrationRuntimeException(String msgId)
|
||||
{
|
||||
super(msgId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param msgId String
|
||||
* @param msgParams Object[]
|
||||
*/
|
||||
public BlogIntegrationRuntimeException(String msgId, Object[] msgParams)
|
||||
{
|
||||
super(msgId, msgParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param msgId String
|
||||
* @param cause Throwable
|
||||
*/
|
||||
public BlogIntegrationRuntimeException(String msgId, Throwable cause)
|
||||
{
|
||||
super(msgId, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param msgId String
|
||||
* @param msgParams Object[]
|
||||
* @param cause Throwable
|
||||
*/
|
||||
public BlogIntegrationRuntimeException(String msgId, Object[] msgParams, Throwable cause)
|
||||
{
|
||||
super(msgId, msgParams, cause);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,72 +1,72 @@
|
||||
package org.alfresco.repo.blog;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* Blog integration service.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*
|
||||
*/
|
||||
public interface BlogIntegrationService
|
||||
{
|
||||
/**
|
||||
* Register a new blog integration implementation with the service
|
||||
*
|
||||
* @param implementation the implementation
|
||||
*/
|
||||
void register(BlogIntegrationImplementation implementation);
|
||||
|
||||
/**
|
||||
* Get the named blog integration implementation, null if name not recognised
|
||||
*
|
||||
* @param implementationName the implementation name
|
||||
* @return BlogIntegrationImplementation the blog integration implementation
|
||||
*/
|
||||
BlogIntegrationImplementation getBlogIntegrationImplementation(String implementationName);
|
||||
|
||||
/**
|
||||
* Get a list of the registered integration implementations.
|
||||
*
|
||||
* @return List<BlogIntegrationImplementaion> list of registered blog integration implementations
|
||||
*/
|
||||
List<BlogIntegrationImplementation> getBlogIntegrationImplementations();
|
||||
|
||||
/**
|
||||
* Given a node reference, gets a list of 'in scope' BlogDetails.
|
||||
*
|
||||
* The node itself and then the primary parent hierarchy is searched and any blog details found returned in
|
||||
* a list, with the 'nearest' first.
|
||||
*
|
||||
* @param nodeRef the node reference
|
||||
* @return List<BlogDetails> list of the blog details found 'in scope' for the node, empty if none found
|
||||
*/
|
||||
List<BlogDetails> getBlogDetails(NodeRef nodeRef);
|
||||
|
||||
/**
|
||||
* Posts the content of a node to the blog specified
|
||||
*
|
||||
* @param blogDetails BlogDetails
|
||||
* @param nodeRef NodeRef
|
||||
* @param contentProperty QName
|
||||
* @param publish boolean
|
||||
*/
|
||||
void newPost(BlogDetails blogDetails, NodeRef nodeRef, QName contentProperty, boolean publish);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param nodeRef NodeRef
|
||||
* @param contentProperty QName
|
||||
* @param publish boolean
|
||||
*/
|
||||
void updatePost(NodeRef nodeRef, QName contentProperty, boolean publish);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param nodeRef NodeRef
|
||||
*/
|
||||
void deletePost(NodeRef nodeRef);
|
||||
}
|
||||
package org.alfresco.repo.blog;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* Blog integration service.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*
|
||||
*/
|
||||
public interface BlogIntegrationService
|
||||
{
|
||||
/**
|
||||
* Register a new blog integration implementation with the service
|
||||
*
|
||||
* @param implementation the implementation
|
||||
*/
|
||||
void register(BlogIntegrationImplementation implementation);
|
||||
|
||||
/**
|
||||
* Get the named blog integration implementation, null if name not recognised
|
||||
*
|
||||
* @param implementationName the implementation name
|
||||
* @return BlogIntegrationImplementation the blog integration implementation
|
||||
*/
|
||||
BlogIntegrationImplementation getBlogIntegrationImplementation(String implementationName);
|
||||
|
||||
/**
|
||||
* Get a list of the registered integration implementations.
|
||||
*
|
||||
* @return List<BlogIntegrationImplementaion> list of registered blog integration implementations
|
||||
*/
|
||||
List<BlogIntegrationImplementation> getBlogIntegrationImplementations();
|
||||
|
||||
/**
|
||||
* Given a node reference, gets a list of 'in scope' BlogDetails.
|
||||
*
|
||||
* The node itself and then the primary parent hierarchy is searched and any blog details found returned in
|
||||
* a list, with the 'nearest' first.
|
||||
*
|
||||
* @param nodeRef the node reference
|
||||
* @return List<BlogDetails> list of the blog details found 'in scope' for the node, empty if none found
|
||||
*/
|
||||
List<BlogDetails> getBlogDetails(NodeRef nodeRef);
|
||||
|
||||
/**
|
||||
* Posts the content of a node to the blog specified
|
||||
*
|
||||
* @param blogDetails BlogDetails
|
||||
* @param nodeRef NodeRef
|
||||
* @param contentProperty QName
|
||||
* @param publish boolean
|
||||
*/
|
||||
void newPost(BlogDetails blogDetails, NodeRef nodeRef, QName contentProperty, boolean publish);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param nodeRef NodeRef
|
||||
* @param contentProperty QName
|
||||
* @param publish boolean
|
||||
*/
|
||||
void updatePost(NodeRef nodeRef, QName contentProperty, boolean publish);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param nodeRef NodeRef
|
||||
*/
|
||||
void deletePost(NodeRef nodeRef);
|
||||
}
|
||||
|
@@ -1,351 +1,351 @@
|
||||
package org.alfresco.repo.blog;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.BlogIntegrationModel;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.service.cmr.repository.AssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* Blog integration service implementation
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public class BlogIntegrationServiceImpl implements BlogIntegrationService, BlogIntegrationModel
|
||||
{
|
||||
/** Node service */
|
||||
private NodeService nodeService;
|
||||
|
||||
/** Content service */
|
||||
private ContentService contentService;
|
||||
|
||||
/** Registered blog integration implemenatations */
|
||||
private Map<String, BlogIntegrationImplementation> implementations = new HashMap<String, BlogIntegrationImplementation>(5);
|
||||
|
||||
/** Supported mimetypes */
|
||||
public static List<String> supportedMimetypes = new ArrayList<String>(5);
|
||||
|
||||
/** Static initialisation of supported mimetypes */
|
||||
static
|
||||
{
|
||||
supportedMimetypes.add(MimetypeMap.MIMETYPE_TEXT_PLAIN);
|
||||
supportedMimetypes.add(MimetypeMap.MIMETYPE_HTML);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the node service
|
||||
*
|
||||
* @param nodeService the node service
|
||||
*/
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the content service
|
||||
*
|
||||
* @param contentService the content service
|
||||
*/
|
||||
public void setContentService(ContentService contentService)
|
||||
{
|
||||
this.contentService = contentService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.blog.BlogIntegrationService#register(org.alfresco.repo.blog.BlogIntegrationImplementation)
|
||||
*/
|
||||
public void register(BlogIntegrationImplementation implementation)
|
||||
{
|
||||
if (this.implementations.containsKey(implementation.getName()) == true)
|
||||
{
|
||||
throw new BlogIntegrationRuntimeException("A blog implementation with name '" + implementation.getName() + "' has already been registered.");
|
||||
}
|
||||
this.implementations.put(implementation.getName(), implementation);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.blog.BlogIntegrationService#getBlogIntegrationImplementation(java.lang.String)
|
||||
*/
|
||||
public BlogIntegrationImplementation getBlogIntegrationImplementation(String implementationName)
|
||||
{
|
||||
return this.implementations.get(implementationName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.blog.BlogIntegrationService#getBlogIntegrationImplementations()
|
||||
*/
|
||||
public List<BlogIntegrationImplementation> getBlogIntegrationImplementations()
|
||||
{
|
||||
return new ArrayList<BlogIntegrationImplementation>(this.implementations.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.blog.BlogIntegrationService#getBlogDetails(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
public List<BlogDetails> getBlogDetails(NodeRef nodeRef)
|
||||
{
|
||||
List<BlogDetails> result = new ArrayList<BlogDetails>(5);
|
||||
|
||||
// First check the node itself
|
||||
if (this.nodeService.hasAspect(nodeRef, ASPECT_BLOG_DETAILS) == true)
|
||||
{
|
||||
result.add(BlogDetails.createBlogDetails(this.nodeService, nodeRef));
|
||||
}
|
||||
|
||||
// Now walk up the parent hiearchy adding details as they are found
|
||||
getBlogDetailsImpl(nodeRef, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method that recurses up the primary parent hierarchy checking for
|
||||
* blog details
|
||||
*
|
||||
* @param nodeRef the node reference
|
||||
* @param blogDetails list of blog details
|
||||
*/
|
||||
private void getBlogDetailsImpl(NodeRef nodeRef, List<BlogDetails> blogDetails)
|
||||
{
|
||||
// Check the parent assoc
|
||||
ChildAssociationRef parentAssoc = this.nodeService.getPrimaryParent(nodeRef);
|
||||
if (parentAssoc != null)
|
||||
{
|
||||
// Check for the blog details
|
||||
NodeRef parent = parentAssoc.getParentRef();
|
||||
if (parent != null)
|
||||
{
|
||||
if (this.nodeService.hasAspect(parent, ASPECT_BLOG_DETAILS) == true)
|
||||
{
|
||||
blogDetails.add(BlogDetails.createBlogDetails(this.nodeService, parent));
|
||||
}
|
||||
|
||||
// Recurse
|
||||
getBlogDetailsImpl(parent, blogDetails);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.blog.BlogIntegrationService#newPost(BlogDetails, NodeRef, QName, boolean)
|
||||
*/
|
||||
public void newPost(BlogDetails blogDetails, NodeRef nodeRef, QName contentProperty, boolean publish)
|
||||
{
|
||||
// Get the blog implementation
|
||||
BlogIntegrationImplementation implementation = getImplementation(blogDetails.getImplementationName());
|
||||
|
||||
// Check that this node has not already been posted to a blog
|
||||
if (this.nodeService.hasAspect(nodeRef, ASPECT_BLOG_POST) == true)
|
||||
{
|
||||
throw new BlogIntegrationRuntimeException("Can not create new blog post since this conten has already been posted to a blog.");
|
||||
}
|
||||
|
||||
// Get the posts body
|
||||
ContentReader contentReader = this.contentService.getReader(nodeRef, contentProperty);
|
||||
if (contentReader == null)
|
||||
{
|
||||
throw new BlogIntegrationRuntimeException("No content found for new blog entry.");
|
||||
}
|
||||
|
||||
// Check the mimetype
|
||||
String body = null;
|
||||
if (supportedMimetypes.contains(contentReader.getMimetype()) == true)
|
||||
{
|
||||
// Get the content
|
||||
body = contentReader.getContentString();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new BlogIntegrationRuntimeException("The content mimetype '" + contentReader.getMimetype() + "' is not supported.");
|
||||
}
|
||||
|
||||
// Get the posts title
|
||||
String title = (String)this.nodeService.getProperty(nodeRef, ContentModel.PROP_TITLE);
|
||||
if (title == null || title.length() == 0)
|
||||
{
|
||||
if (body.length() > 23)
|
||||
{
|
||||
// Get the title from the first 22 character plus ' ...'
|
||||
title = body.substring(0, 23) + " ...";
|
||||
}
|
||||
else
|
||||
{
|
||||
title = body;
|
||||
}
|
||||
}
|
||||
|
||||
// Post the new blog entry
|
||||
String postId = implementation.newPost(blogDetails, title, body, true);
|
||||
|
||||
// Get the blog details node if the is one
|
||||
NodeRef blogDetailsNodeRef = blogDetails.getNodeRef();
|
||||
if (blogDetailsNodeRef != null)
|
||||
{
|
||||
// Now get the details of the newly created post
|
||||
Map<String, Object> details = implementation.getPost(blogDetails, postId);
|
||||
String link = (String)details.get("link");
|
||||
|
||||
// Add the details of the new post to the node
|
||||
Map<QName, Serializable> props = new HashMap<QName, Serializable>(5);
|
||||
props.put(PROP_POST_ID, postId);
|
||||
if (link != null)
|
||||
{
|
||||
props.put(PROP_LINK, link);
|
||||
}
|
||||
Date now = new Date();
|
||||
props.put(PROP_POSTED, now);
|
||||
props.put(PROP_LAST_UPDATE, now);
|
||||
props.put(PROP_PUBLISHED, Boolean.valueOf(publish));
|
||||
this.nodeService.addAspect(nodeRef, ASPECT_BLOG_POST, props);
|
||||
|
||||
// Associate to the blog details
|
||||
this.nodeService.createAssociation(nodeRef, blogDetailsNodeRef, ASSOC_BLOG_DETAILS);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the blog implementation based on its name
|
||||
*
|
||||
* @param implementationName the implementation name
|
||||
* @return BlogIntegrationImplementation the blog integration
|
||||
*/
|
||||
private BlogIntegrationImplementation getImplementation(String implementationName)
|
||||
{
|
||||
if (this.implementations.containsKey(implementationName) == false)
|
||||
{
|
||||
throw new BlogIntegrationRuntimeException("There is no blog implementation present for '" + implementationName + "'");
|
||||
}
|
||||
return this.implementations.get(implementationName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.blog.BlogIntegrationService#updatePost(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName, boolean)
|
||||
*/
|
||||
public void updatePost(NodeRef nodeRef, QName contentProperty, boolean publish)
|
||||
{
|
||||
// Get the blog details and post id
|
||||
BlogDetails blogDetails = null;
|
||||
String postId = null;
|
||||
if (this.nodeService.hasAspect(nodeRef, ASPECT_BLOG_POST) == true)
|
||||
{
|
||||
List<AssociationRef> assocs = this.nodeService.getTargetAssocs(nodeRef, ASSOC_BLOG_DETAILS);
|
||||
if (assocs.size() == 0)
|
||||
{
|
||||
throw new BlogIntegrationRuntimeException("Can not resolve blog details for update because blogDetails association is not populated.");
|
||||
}
|
||||
else
|
||||
{
|
||||
blogDetails = BlogDetails.createBlogDetails(this.nodeService, assocs.get(0).getTargetRef());
|
||||
postId = (String)this.nodeService.getProperty(nodeRef, PROP_POST_ID);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new BlogIntegrationRuntimeException("Can not update blog post as this node has not been previously posted to a blog.");
|
||||
}
|
||||
|
||||
// Get the blog implementation
|
||||
BlogIntegrationImplementation implementation = getImplementation(blogDetails.getImplementationName());
|
||||
|
||||
// Get the posts title
|
||||
String title = (String)this.nodeService.getProperty(nodeRef, ContentModel.PROP_TITLE);
|
||||
if (title == null || title.length() == 0)
|
||||
{
|
||||
throw new BlogIntegrationRuntimeException("No title available for update blog post. Set the title property and re-try.");
|
||||
}
|
||||
|
||||
// Get the posts body
|
||||
ContentReader contentReader = this.contentService.getReader(nodeRef, contentProperty);
|
||||
if (contentReader == null)
|
||||
{
|
||||
throw new BlogIntegrationRuntimeException("No content found for update blog entry.");
|
||||
}
|
||||
|
||||
// Check the mimetype
|
||||
String body = null;
|
||||
if (supportedMimetypes.contains(contentReader.getMimetype()) == true)
|
||||
{
|
||||
// Get the content
|
||||
body = contentReader.getContentString();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new BlogIntegrationRuntimeException("The content mimetype '" + contentReader.getMimetype() + "' is not supported.");
|
||||
}
|
||||
|
||||
// Update the blog post
|
||||
boolean result = implementation.updatePost(blogDetails, postId, title, body, publish);
|
||||
|
||||
// Check the return result
|
||||
if (result == false)
|
||||
{
|
||||
throw new BlogIntegrationRuntimeException("The update of the post unexpectedly failed. Check your blog for more information.");
|
||||
}
|
||||
|
||||
// Now get the details of the newly created post
|
||||
Map<String, Object> details = implementation.getPost(blogDetails, postId);
|
||||
String link = (String)details.get("link");
|
||||
|
||||
// Update the post details accordingly
|
||||
Map<QName, Serializable> props = this.nodeService.getProperties(nodeRef);
|
||||
Date now = new Date();
|
||||
props.put(PROP_LAST_UPDATE, now);
|
||||
props.put(PROP_PUBLISHED, Boolean.valueOf(publish));
|
||||
props.put(PROP_LINK, link);
|
||||
this.nodeService.setProperties(nodeRef, props);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.blog.BlogIntegrationService#deletePost(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
public void deletePost(NodeRef nodeRef)
|
||||
{
|
||||
// Get the blog details and post id
|
||||
BlogDetails blogDetails = null;
|
||||
String postId = null;
|
||||
if (this.nodeService.hasAspect(nodeRef, ASPECT_BLOG_POST) == true)
|
||||
{
|
||||
List<AssociationRef> assocs = this.nodeService.getTargetAssocs(nodeRef, ASSOC_BLOG_DETAILS);
|
||||
if (assocs.size() == 0)
|
||||
{
|
||||
throw new BlogIntegrationRuntimeException("Can not resolve blog details for delete because blogDetails association is not populated.");
|
||||
}
|
||||
else
|
||||
{
|
||||
blogDetails = BlogDetails.createBlogDetails(this.nodeService, assocs.get(0).getTargetRef());
|
||||
postId = (String)this.nodeService.getProperty(nodeRef, PROP_POST_ID);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new BlogIntegrationRuntimeException("Can not delete blog post as this node has not been previously posted to a blog.");
|
||||
}
|
||||
|
||||
// Get the blog implementation
|
||||
BlogIntegrationImplementation implementation = getImplementation(blogDetails.getImplementationName());
|
||||
|
||||
// Delete the post
|
||||
boolean result = implementation.deletePost(blogDetails, postId);
|
||||
|
||||
// Check the return result
|
||||
if (result == false)
|
||||
{
|
||||
throw new BlogIntegrationRuntimeException("Deleting the post unexpectedly failed. Check your blog for more information.");
|
||||
}
|
||||
|
||||
// Remove the postDetails aspect from the node
|
||||
this.nodeService.removeAspect(nodeRef, ASPECT_BLOG_POST);
|
||||
}
|
||||
}
|
||||
package org.alfresco.repo.blog;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.BlogIntegrationModel;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.service.cmr.repository.AssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* Blog integration service implementation
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public class BlogIntegrationServiceImpl implements BlogIntegrationService, BlogIntegrationModel
|
||||
{
|
||||
/** Node service */
|
||||
private NodeService nodeService;
|
||||
|
||||
/** Content service */
|
||||
private ContentService contentService;
|
||||
|
||||
/** Registered blog integration implemenatations */
|
||||
private Map<String, BlogIntegrationImplementation> implementations = new HashMap<String, BlogIntegrationImplementation>(5);
|
||||
|
||||
/** Supported mimetypes */
|
||||
public static List<String> supportedMimetypes = new ArrayList<String>(5);
|
||||
|
||||
/** Static initialisation of supported mimetypes */
|
||||
static
|
||||
{
|
||||
supportedMimetypes.add(MimetypeMap.MIMETYPE_TEXT_PLAIN);
|
||||
supportedMimetypes.add(MimetypeMap.MIMETYPE_HTML);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the node service
|
||||
*
|
||||
* @param nodeService the node service
|
||||
*/
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the content service
|
||||
*
|
||||
* @param contentService the content service
|
||||
*/
|
||||
public void setContentService(ContentService contentService)
|
||||
{
|
||||
this.contentService = contentService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.blog.BlogIntegrationService#register(org.alfresco.repo.blog.BlogIntegrationImplementation)
|
||||
*/
|
||||
public void register(BlogIntegrationImplementation implementation)
|
||||
{
|
||||
if (this.implementations.containsKey(implementation.getName()) == true)
|
||||
{
|
||||
throw new BlogIntegrationRuntimeException("A blog implementation with name '" + implementation.getName() + "' has already been registered.");
|
||||
}
|
||||
this.implementations.put(implementation.getName(), implementation);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.blog.BlogIntegrationService#getBlogIntegrationImplementation(java.lang.String)
|
||||
*/
|
||||
public BlogIntegrationImplementation getBlogIntegrationImplementation(String implementationName)
|
||||
{
|
||||
return this.implementations.get(implementationName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.blog.BlogIntegrationService#getBlogIntegrationImplementations()
|
||||
*/
|
||||
public List<BlogIntegrationImplementation> getBlogIntegrationImplementations()
|
||||
{
|
||||
return new ArrayList<BlogIntegrationImplementation>(this.implementations.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.blog.BlogIntegrationService#getBlogDetails(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
public List<BlogDetails> getBlogDetails(NodeRef nodeRef)
|
||||
{
|
||||
List<BlogDetails> result = new ArrayList<BlogDetails>(5);
|
||||
|
||||
// First check the node itself
|
||||
if (this.nodeService.hasAspect(nodeRef, ASPECT_BLOG_DETAILS) == true)
|
||||
{
|
||||
result.add(BlogDetails.createBlogDetails(this.nodeService, nodeRef));
|
||||
}
|
||||
|
||||
// Now walk up the parent hiearchy adding details as they are found
|
||||
getBlogDetailsImpl(nodeRef, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method that recurses up the primary parent hierarchy checking for
|
||||
* blog details
|
||||
*
|
||||
* @param nodeRef the node reference
|
||||
* @param blogDetails list of blog details
|
||||
*/
|
||||
private void getBlogDetailsImpl(NodeRef nodeRef, List<BlogDetails> blogDetails)
|
||||
{
|
||||
// Check the parent assoc
|
||||
ChildAssociationRef parentAssoc = this.nodeService.getPrimaryParent(nodeRef);
|
||||
if (parentAssoc != null)
|
||||
{
|
||||
// Check for the blog details
|
||||
NodeRef parent = parentAssoc.getParentRef();
|
||||
if (parent != null)
|
||||
{
|
||||
if (this.nodeService.hasAspect(parent, ASPECT_BLOG_DETAILS) == true)
|
||||
{
|
||||
blogDetails.add(BlogDetails.createBlogDetails(this.nodeService, parent));
|
||||
}
|
||||
|
||||
// Recurse
|
||||
getBlogDetailsImpl(parent, blogDetails);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.blog.BlogIntegrationService#newPost(BlogDetails, NodeRef, QName, boolean)
|
||||
*/
|
||||
public void newPost(BlogDetails blogDetails, NodeRef nodeRef, QName contentProperty, boolean publish)
|
||||
{
|
||||
// Get the blog implementation
|
||||
BlogIntegrationImplementation implementation = getImplementation(blogDetails.getImplementationName());
|
||||
|
||||
// Check that this node has not already been posted to a blog
|
||||
if (this.nodeService.hasAspect(nodeRef, ASPECT_BLOG_POST) == true)
|
||||
{
|
||||
throw new BlogIntegrationRuntimeException("Can not create new blog post since this conten has already been posted to a blog.");
|
||||
}
|
||||
|
||||
// Get the posts body
|
||||
ContentReader contentReader = this.contentService.getReader(nodeRef, contentProperty);
|
||||
if (contentReader == null)
|
||||
{
|
||||
throw new BlogIntegrationRuntimeException("No content found for new blog entry.");
|
||||
}
|
||||
|
||||
// Check the mimetype
|
||||
String body = null;
|
||||
if (supportedMimetypes.contains(contentReader.getMimetype()) == true)
|
||||
{
|
||||
// Get the content
|
||||
body = contentReader.getContentString();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new BlogIntegrationRuntimeException("The content mimetype '" + contentReader.getMimetype() + "' is not supported.");
|
||||
}
|
||||
|
||||
// Get the posts title
|
||||
String title = (String)this.nodeService.getProperty(nodeRef, ContentModel.PROP_TITLE);
|
||||
if (title == null || title.length() == 0)
|
||||
{
|
||||
if (body.length() > 23)
|
||||
{
|
||||
// Get the title from the first 22 character plus ' ...'
|
||||
title = body.substring(0, 23) + " ...";
|
||||
}
|
||||
else
|
||||
{
|
||||
title = body;
|
||||
}
|
||||
}
|
||||
|
||||
// Post the new blog entry
|
||||
String postId = implementation.newPost(blogDetails, title, body, true);
|
||||
|
||||
// Get the blog details node if the is one
|
||||
NodeRef blogDetailsNodeRef = blogDetails.getNodeRef();
|
||||
if (blogDetailsNodeRef != null)
|
||||
{
|
||||
// Now get the details of the newly created post
|
||||
Map<String, Object> details = implementation.getPost(blogDetails, postId);
|
||||
String link = (String)details.get("link");
|
||||
|
||||
// Add the details of the new post to the node
|
||||
Map<QName, Serializable> props = new HashMap<QName, Serializable>(5);
|
||||
props.put(PROP_POST_ID, postId);
|
||||
if (link != null)
|
||||
{
|
||||
props.put(PROP_LINK, link);
|
||||
}
|
||||
Date now = new Date();
|
||||
props.put(PROP_POSTED, now);
|
||||
props.put(PROP_LAST_UPDATE, now);
|
||||
props.put(PROP_PUBLISHED, Boolean.valueOf(publish));
|
||||
this.nodeService.addAspect(nodeRef, ASPECT_BLOG_POST, props);
|
||||
|
||||
// Associate to the blog details
|
||||
this.nodeService.createAssociation(nodeRef, blogDetailsNodeRef, ASSOC_BLOG_DETAILS);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the blog implementation based on its name
|
||||
*
|
||||
* @param implementationName the implementation name
|
||||
* @return BlogIntegrationImplementation the blog integration
|
||||
*/
|
||||
private BlogIntegrationImplementation getImplementation(String implementationName)
|
||||
{
|
||||
if (this.implementations.containsKey(implementationName) == false)
|
||||
{
|
||||
throw new BlogIntegrationRuntimeException("There is no blog implementation present for '" + implementationName + "'");
|
||||
}
|
||||
return this.implementations.get(implementationName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.blog.BlogIntegrationService#updatePost(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName, boolean)
|
||||
*/
|
||||
public void updatePost(NodeRef nodeRef, QName contentProperty, boolean publish)
|
||||
{
|
||||
// Get the blog details and post id
|
||||
BlogDetails blogDetails = null;
|
||||
String postId = null;
|
||||
if (this.nodeService.hasAspect(nodeRef, ASPECT_BLOG_POST) == true)
|
||||
{
|
||||
List<AssociationRef> assocs = this.nodeService.getTargetAssocs(nodeRef, ASSOC_BLOG_DETAILS);
|
||||
if (assocs.size() == 0)
|
||||
{
|
||||
throw new BlogIntegrationRuntimeException("Can not resolve blog details for update because blogDetails association is not populated.");
|
||||
}
|
||||
else
|
||||
{
|
||||
blogDetails = BlogDetails.createBlogDetails(this.nodeService, assocs.get(0).getTargetRef());
|
||||
postId = (String)this.nodeService.getProperty(nodeRef, PROP_POST_ID);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new BlogIntegrationRuntimeException("Can not update blog post as this node has not been previously posted to a blog.");
|
||||
}
|
||||
|
||||
// Get the blog implementation
|
||||
BlogIntegrationImplementation implementation = getImplementation(blogDetails.getImplementationName());
|
||||
|
||||
// Get the posts title
|
||||
String title = (String)this.nodeService.getProperty(nodeRef, ContentModel.PROP_TITLE);
|
||||
if (title == null || title.length() == 0)
|
||||
{
|
||||
throw new BlogIntegrationRuntimeException("No title available for update blog post. Set the title property and re-try.");
|
||||
}
|
||||
|
||||
// Get the posts body
|
||||
ContentReader contentReader = this.contentService.getReader(nodeRef, contentProperty);
|
||||
if (contentReader == null)
|
||||
{
|
||||
throw new BlogIntegrationRuntimeException("No content found for update blog entry.");
|
||||
}
|
||||
|
||||
// Check the mimetype
|
||||
String body = null;
|
||||
if (supportedMimetypes.contains(contentReader.getMimetype()) == true)
|
||||
{
|
||||
// Get the content
|
||||
body = contentReader.getContentString();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new BlogIntegrationRuntimeException("The content mimetype '" + contentReader.getMimetype() + "' is not supported.");
|
||||
}
|
||||
|
||||
// Update the blog post
|
||||
boolean result = implementation.updatePost(blogDetails, postId, title, body, publish);
|
||||
|
||||
// Check the return result
|
||||
if (result == false)
|
||||
{
|
||||
throw new BlogIntegrationRuntimeException("The update of the post unexpectedly failed. Check your blog for more information.");
|
||||
}
|
||||
|
||||
// Now get the details of the newly created post
|
||||
Map<String, Object> details = implementation.getPost(blogDetails, postId);
|
||||
String link = (String)details.get("link");
|
||||
|
||||
// Update the post details accordingly
|
||||
Map<QName, Serializable> props = this.nodeService.getProperties(nodeRef);
|
||||
Date now = new Date();
|
||||
props.put(PROP_LAST_UPDATE, now);
|
||||
props.put(PROP_PUBLISHED, Boolean.valueOf(publish));
|
||||
props.put(PROP_LINK, link);
|
||||
this.nodeService.setProperties(nodeRef, props);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.blog.BlogIntegrationService#deletePost(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
public void deletePost(NodeRef nodeRef)
|
||||
{
|
||||
// Get the blog details and post id
|
||||
BlogDetails blogDetails = null;
|
||||
String postId = null;
|
||||
if (this.nodeService.hasAspect(nodeRef, ASPECT_BLOG_POST) == true)
|
||||
{
|
||||
List<AssociationRef> assocs = this.nodeService.getTargetAssocs(nodeRef, ASSOC_BLOG_DETAILS);
|
||||
if (assocs.size() == 0)
|
||||
{
|
||||
throw new BlogIntegrationRuntimeException("Can not resolve blog details for delete because blogDetails association is not populated.");
|
||||
}
|
||||
else
|
||||
{
|
||||
blogDetails = BlogDetails.createBlogDetails(this.nodeService, assocs.get(0).getTargetRef());
|
||||
postId = (String)this.nodeService.getProperty(nodeRef, PROP_POST_ID);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new BlogIntegrationRuntimeException("Can not delete blog post as this node has not been previously posted to a blog.");
|
||||
}
|
||||
|
||||
// Get the blog implementation
|
||||
BlogIntegrationImplementation implementation = getImplementation(blogDetails.getImplementationName());
|
||||
|
||||
// Delete the post
|
||||
boolean result = implementation.deletePost(blogDetails, postId);
|
||||
|
||||
// Check the return result
|
||||
if (result == false)
|
||||
{
|
||||
throw new BlogIntegrationRuntimeException("Deleting the post unexpectedly failed. Check your blog for more information.");
|
||||
}
|
||||
|
||||
// Remove the postDetails aspect from the node
|
||||
this.nodeService.removeAspect(nodeRef, ASPECT_BLOG_POST);
|
||||
}
|
||||
}
|
||||
|
@@ -1,208 +1,208 @@
|
||||
package org.alfresco.repo.blog;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.xmlrpc.XmlRpcException;
|
||||
import org.apache.xmlrpc.client.XmlRpcClient;
|
||||
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
|
||||
|
||||
/**
|
||||
* Default blog integration implementation. Uses various standard XML PRC blogging API to satisfy the
|
||||
* blog integration implementation interface.
|
||||
*
|
||||
* Based on origional contribution by Sudhakar Selvaraj.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public abstract class DefaultBlogIntegrationImplementation extends BaseBlogIntegrationImplementation
|
||||
{
|
||||
/** Blog actions */
|
||||
protected static final String ACTION_NEW_POST = "metaWeblog.newPost";
|
||||
protected static final String ACTION_EDIT_POST = "metaWeblog.editPost";
|
||||
protected static final String ACTION_GET_POST = "metaWeblog.getPost";
|
||||
protected static final String ACTION_DELETE_POST = "blogger.deletePost";
|
||||
|
||||
/**
|
||||
* Gets the XML RPC end point URL for the given blog details.
|
||||
*
|
||||
* @param blogDetails blog details
|
||||
* @return String the end point URL
|
||||
*/
|
||||
protected abstract String getEndpointURL(BlogDetails blogDetails);
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.blog.BlogIntegrationImplementation#newPost(org.alfresco.repo.blog.BlogDetails, java.lang.String, java.lang.String, boolean)
|
||||
*/
|
||||
public String newPost(BlogDetails blogDetails, String title, String body, boolean publish)
|
||||
{
|
||||
// Create the hash table containing details of the post's content
|
||||
Hashtable<String, Object> content = new Hashtable<String, Object>();
|
||||
content.put("title", title);
|
||||
content.put("description", body);
|
||||
|
||||
// Create a list of parameters
|
||||
List<Object> params = new ArrayList<Object>(5);
|
||||
params.add(blogDetails.getBlogId());
|
||||
params.add(blogDetails.getUserName());
|
||||
params.add(blogDetails.getPassword());
|
||||
params.add(content);
|
||||
params.add(publish);
|
||||
|
||||
// Create the new post
|
||||
return (String)execute(getEndpointURL(blogDetails), ACTION_NEW_POST, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.blog.BlogIntegrationImplementation#updatePost(org.alfresco.repo.blog.BlogDetails, java.lang.String, java.lang.String, java.lang.String, boolean)
|
||||
*/
|
||||
public boolean updatePost(BlogDetails blogDetails, String postId, String title, String body, boolean publish)
|
||||
{
|
||||
// Create the hash table containing details of the post's content
|
||||
Hashtable<String, Object> content = new Hashtable<String, Object>();
|
||||
content.put("title", title);
|
||||
content.put("description", body);
|
||||
|
||||
// Create a list of parameters
|
||||
List<Object> params = new ArrayList<Object>(5);
|
||||
params.add(postId);
|
||||
params.add(blogDetails.getUserName());
|
||||
params.add(blogDetails.getPassword());
|
||||
params.add(content);
|
||||
params.add(publish);
|
||||
|
||||
// Create the new post
|
||||
Object result = execute(getEndpointURL(blogDetails), ACTION_EDIT_POST, params);
|
||||
|
||||
if (result.getClass().equals(Boolean.class))
|
||||
{
|
||||
return ((Boolean)result).booleanValue();
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.blog.BlogIntegrationImplementation#getPost(org.alfresco.repo.blog.BlogDetails, java.lang.String)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<String, Object> getPost(BlogDetails blogDetails, String postId)
|
||||
{
|
||||
// Create a list of parameters
|
||||
List<Object> params = new ArrayList<Object>(3);
|
||||
params.add(postId);
|
||||
params.add(blogDetails.getUserName());
|
||||
params.add(blogDetails.getPassword());
|
||||
|
||||
// Get the post details
|
||||
return (Map<String, Object>)execute(getEndpointURL(blogDetails), ACTION_GET_POST, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.blog.BlogIntegrationImplementation#deletePost(org.alfresco.repo.blog.BlogDetails, java.lang.String)
|
||||
*/
|
||||
public boolean deletePost(BlogDetails blogDetails, String postId)
|
||||
{
|
||||
// Create a list of parameters
|
||||
List<Object> params = new ArrayList<Object>(5);
|
||||
// Use the blog id for the app key
|
||||
params.add(blogDetails.getBlogId());
|
||||
params.add(postId);
|
||||
params.add(blogDetails.getUserName());
|
||||
params.add(blogDetails.getPassword());
|
||||
params.add(true);
|
||||
|
||||
// Delete post
|
||||
Object result = execute(getEndpointURL(blogDetails), ACTION_DELETE_POST, params);
|
||||
if (result.getClass().equals(Boolean.class))
|
||||
{
|
||||
return ((Boolean)result).booleanValue();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to get the XML RPC client
|
||||
*
|
||||
* @param url String
|
||||
* @return XmlRpcClient
|
||||
*/
|
||||
private XmlRpcClient getClient(String url)
|
||||
{
|
||||
XmlRpcClient client = null;
|
||||
try
|
||||
{
|
||||
client = new XmlRpcClient();
|
||||
XmlRpcClientConfigImpl conf = new XmlRpcClientConfigImpl();
|
||||
conf.setServerURL(new URL(url));
|
||||
conf.setEncoding("UTF-8");
|
||||
client.setConfig(conf);
|
||||
}
|
||||
catch (MalformedURLException exception)
|
||||
{
|
||||
throw new BlogIntegrationRuntimeException("Blog url '" + url + "' is invalid.", exception);
|
||||
}
|
||||
|
||||
return client;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes an XML RPC method
|
||||
*
|
||||
* @param url String
|
||||
* @param method String
|
||||
* @param params List<Object>
|
||||
* @return Object
|
||||
*/
|
||||
protected Object execute(String url, String method, List<Object> params)
|
||||
{
|
||||
Object result = null;
|
||||
|
||||
try
|
||||
{
|
||||
XmlRpcClient client = getClient(url);
|
||||
result = client.execute(method, params);
|
||||
}
|
||||
catch (XmlRpcException exception)
|
||||
{
|
||||
throw new BlogIntegrationRuntimeException("Failed to execute blog action '" + method + "' @ url '" + url + "'", exception);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks a url for a protocol and adds http if none present
|
||||
*
|
||||
* @param url the url
|
||||
* @return String the checked url
|
||||
*/
|
||||
protected String checkForProtocol(String url)
|
||||
{
|
||||
if (url.indexOf("://") == -1)
|
||||
{
|
||||
url = "http://" + url;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the url for a trailing slash and adds one if none present
|
||||
*
|
||||
* @param url the url
|
||||
* @return String the checked url
|
||||
*/
|
||||
protected String checkForTrainlingSlash(String url)
|
||||
{
|
||||
if (url.endsWith("/") == false)
|
||||
{
|
||||
url = url + "/";
|
||||
}
|
||||
return url;
|
||||
}
|
||||
}
|
||||
package org.alfresco.repo.blog;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.xmlrpc.XmlRpcException;
|
||||
import org.apache.xmlrpc.client.XmlRpcClient;
|
||||
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
|
||||
|
||||
/**
|
||||
* Default blog integration implementation. Uses various standard XML PRC blogging API to satisfy the
|
||||
* blog integration implementation interface.
|
||||
*
|
||||
* Based on origional contribution by Sudhakar Selvaraj.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public abstract class DefaultBlogIntegrationImplementation extends BaseBlogIntegrationImplementation
|
||||
{
|
||||
/** Blog actions */
|
||||
protected static final String ACTION_NEW_POST = "metaWeblog.newPost";
|
||||
protected static final String ACTION_EDIT_POST = "metaWeblog.editPost";
|
||||
protected static final String ACTION_GET_POST = "metaWeblog.getPost";
|
||||
protected static final String ACTION_DELETE_POST = "blogger.deletePost";
|
||||
|
||||
/**
|
||||
* Gets the XML RPC end point URL for the given blog details.
|
||||
*
|
||||
* @param blogDetails blog details
|
||||
* @return String the end point URL
|
||||
*/
|
||||
protected abstract String getEndpointURL(BlogDetails blogDetails);
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.blog.BlogIntegrationImplementation#newPost(org.alfresco.repo.blog.BlogDetails, java.lang.String, java.lang.String, boolean)
|
||||
*/
|
||||
public String newPost(BlogDetails blogDetails, String title, String body, boolean publish)
|
||||
{
|
||||
// Create the hash table containing details of the post's content
|
||||
Hashtable<String, Object> content = new Hashtable<String, Object>();
|
||||
content.put("title", title);
|
||||
content.put("description", body);
|
||||
|
||||
// Create a list of parameters
|
||||
List<Object> params = new ArrayList<Object>(5);
|
||||
params.add(blogDetails.getBlogId());
|
||||
params.add(blogDetails.getUserName());
|
||||
params.add(blogDetails.getPassword());
|
||||
params.add(content);
|
||||
params.add(publish);
|
||||
|
||||
// Create the new post
|
||||
return (String)execute(getEndpointURL(blogDetails), ACTION_NEW_POST, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.blog.BlogIntegrationImplementation#updatePost(org.alfresco.repo.blog.BlogDetails, java.lang.String, java.lang.String, java.lang.String, boolean)
|
||||
*/
|
||||
public boolean updatePost(BlogDetails blogDetails, String postId, String title, String body, boolean publish)
|
||||
{
|
||||
// Create the hash table containing details of the post's content
|
||||
Hashtable<String, Object> content = new Hashtable<String, Object>();
|
||||
content.put("title", title);
|
||||
content.put("description", body);
|
||||
|
||||
// Create a list of parameters
|
||||
List<Object> params = new ArrayList<Object>(5);
|
||||
params.add(postId);
|
||||
params.add(blogDetails.getUserName());
|
||||
params.add(blogDetails.getPassword());
|
||||
params.add(content);
|
||||
params.add(publish);
|
||||
|
||||
// Create the new post
|
||||
Object result = execute(getEndpointURL(blogDetails), ACTION_EDIT_POST, params);
|
||||
|
||||
if (result.getClass().equals(Boolean.class))
|
||||
{
|
||||
return ((Boolean)result).booleanValue();
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.blog.BlogIntegrationImplementation#getPost(org.alfresco.repo.blog.BlogDetails, java.lang.String)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<String, Object> getPost(BlogDetails blogDetails, String postId)
|
||||
{
|
||||
// Create a list of parameters
|
||||
List<Object> params = new ArrayList<Object>(3);
|
||||
params.add(postId);
|
||||
params.add(blogDetails.getUserName());
|
||||
params.add(blogDetails.getPassword());
|
||||
|
||||
// Get the post details
|
||||
return (Map<String, Object>)execute(getEndpointURL(blogDetails), ACTION_GET_POST, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.blog.BlogIntegrationImplementation#deletePost(org.alfresco.repo.blog.BlogDetails, java.lang.String)
|
||||
*/
|
||||
public boolean deletePost(BlogDetails blogDetails, String postId)
|
||||
{
|
||||
// Create a list of parameters
|
||||
List<Object> params = new ArrayList<Object>(5);
|
||||
// Use the blog id for the app key
|
||||
params.add(blogDetails.getBlogId());
|
||||
params.add(postId);
|
||||
params.add(blogDetails.getUserName());
|
||||
params.add(blogDetails.getPassword());
|
||||
params.add(true);
|
||||
|
||||
// Delete post
|
||||
Object result = execute(getEndpointURL(blogDetails), ACTION_DELETE_POST, params);
|
||||
if (result.getClass().equals(Boolean.class))
|
||||
{
|
||||
return ((Boolean)result).booleanValue();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to get the XML RPC client
|
||||
*
|
||||
* @param url String
|
||||
* @return XmlRpcClient
|
||||
*/
|
||||
private XmlRpcClient getClient(String url)
|
||||
{
|
||||
XmlRpcClient client = null;
|
||||
try
|
||||
{
|
||||
client = new XmlRpcClient();
|
||||
XmlRpcClientConfigImpl conf = new XmlRpcClientConfigImpl();
|
||||
conf.setServerURL(new URL(url));
|
||||
conf.setEncoding("UTF-8");
|
||||
client.setConfig(conf);
|
||||
}
|
||||
catch (MalformedURLException exception)
|
||||
{
|
||||
throw new BlogIntegrationRuntimeException("Blog url '" + url + "' is invalid.", exception);
|
||||
}
|
||||
|
||||
return client;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes an XML RPC method
|
||||
*
|
||||
* @param url String
|
||||
* @param method String
|
||||
* @param params List<Object>
|
||||
* @return Object
|
||||
*/
|
||||
protected Object execute(String url, String method, List<Object> params)
|
||||
{
|
||||
Object result = null;
|
||||
|
||||
try
|
||||
{
|
||||
XmlRpcClient client = getClient(url);
|
||||
result = client.execute(method, params);
|
||||
}
|
||||
catch (XmlRpcException exception)
|
||||
{
|
||||
throw new BlogIntegrationRuntimeException("Failed to execute blog action '" + method + "' @ url '" + url + "'", exception);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks a url for a protocol and adds http if none present
|
||||
*
|
||||
* @param url the url
|
||||
* @return String the checked url
|
||||
*/
|
||||
protected String checkForProtocol(String url)
|
||||
{
|
||||
if (url.indexOf("://") == -1)
|
||||
{
|
||||
url = "http://" + url;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the url for a trailing slash and adds one if none present
|
||||
*
|
||||
* @param url the url
|
||||
* @return String the checked url
|
||||
*/
|
||||
protected String checkForTrainlingSlash(String url)
|
||||
{
|
||||
if (url.endsWith("/") == false)
|
||||
{
|
||||
url = url + "/";
|
||||
}
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
@@ -1,36 +1,36 @@
|
||||
package org.alfresco.repo.blog.typepad;
|
||||
|
||||
import org.alfresco.repo.blog.BlogDetails;
|
||||
import org.alfresco.repo.blog.DefaultBlogIntegrationImplementation;
|
||||
|
||||
/**
|
||||
* Typepad integration implementation
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public class TypepadIntegration extends DefaultBlogIntegrationImplementation
|
||||
{
|
||||
/**
|
||||
* @see org.alfresco.repo.blog.DefaultBlogIntegrationImplementation#getEndpointURL(org.alfresco.repo.blog.BlogDetails)
|
||||
*/
|
||||
@Override
|
||||
protected String getEndpointURL(BlogDetails blogDetails)
|
||||
{
|
||||
return "http://www.typepad.com/t/api";
|
||||
}
|
||||
|
||||
/**
|
||||
* For some reason typepad returns a hash table rather than the expected boolean result.
|
||||
*
|
||||
* @see org.alfresco.repo.blog.BlogIntegrationImplementation#deletePost(org.alfresco.repo.blog.BlogDetails, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public boolean deletePost(BlogDetails blogDetails, String postId)
|
||||
{
|
||||
// NOTE: At the time of testing typepad.com failed when making this call, for now the implementation is
|
||||
// being overriden to return success
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
package org.alfresco.repo.blog.typepad;
|
||||
|
||||
import org.alfresco.repo.blog.BlogDetails;
|
||||
import org.alfresco.repo.blog.DefaultBlogIntegrationImplementation;
|
||||
|
||||
/**
|
||||
* Typepad integration implementation
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public class TypepadIntegration extends DefaultBlogIntegrationImplementation
|
||||
{
|
||||
/**
|
||||
* @see org.alfresco.repo.blog.DefaultBlogIntegrationImplementation#getEndpointURL(org.alfresco.repo.blog.BlogDetails)
|
||||
*/
|
||||
@Override
|
||||
protected String getEndpointURL(BlogDetails blogDetails)
|
||||
{
|
||||
return "http://www.typepad.com/t/api";
|
||||
}
|
||||
|
||||
/**
|
||||
* For some reason typepad returns a hash table rather than the expected boolean result.
|
||||
*
|
||||
* @see org.alfresco.repo.blog.BlogIntegrationImplementation#deletePost(org.alfresco.repo.blog.BlogDetails, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public boolean deletePost(BlogDetails blogDetails, String postId)
|
||||
{
|
||||
// NOTE: At the time of testing typepad.com failed when making this call, for now the implementation is
|
||||
// being overriden to return success
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,23 +1,23 @@
|
||||
package org.alfresco.repo.blog.wordpress;
|
||||
|
||||
import org.alfresco.repo.blog.BlogDetails;
|
||||
import org.alfresco.repo.blog.DefaultBlogIntegrationImplementation;
|
||||
|
||||
/**
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public class WordPressIntegration extends DefaultBlogIntegrationImplementation
|
||||
{
|
||||
private static String ENDPOINT = "xmlrpc.php";
|
||||
|
||||
/**
|
||||
* @see DefaultBlogIntegrationImplementation#getEndpointURL(BlogDetails)
|
||||
*/
|
||||
@Override
|
||||
protected String getEndpointURL(BlogDetails blogDetails)
|
||||
{
|
||||
String endpoint = checkForProtocol(blogDetails.getUrl());
|
||||
return checkForTrainlingSlash(endpoint) + ENDPOINT;
|
||||
}
|
||||
|
||||
}
|
||||
package org.alfresco.repo.blog.wordpress;
|
||||
|
||||
import org.alfresco.repo.blog.BlogDetails;
|
||||
import org.alfresco.repo.blog.DefaultBlogIntegrationImplementation;
|
||||
|
||||
/**
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public class WordPressIntegration extends DefaultBlogIntegrationImplementation
|
||||
{
|
||||
private static String ENDPOINT = "xmlrpc.php";
|
||||
|
||||
/**
|
||||
* @see DefaultBlogIntegrationImplementation#getEndpointURL(BlogDetails)
|
||||
*/
|
||||
@Override
|
||||
protected String getEndpointURL(BlogDetails blogDetails)
|
||||
{
|
||||
String endpoint = checkForProtocol(blogDetails.getUrl());
|
||||
return checkForTrainlingSlash(endpoint) + ENDPOINT;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user