MetaWeblogAPIHandler.java [plain text]
package org.blojsom.extension.xmlrpc.handlers;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.xmlrpc.XmlRpcException;
import org.blojsom.BlojsomException;
import org.blojsom.plugin.admin.event.AddBlogEntryEvent;
import org.blojsom.plugin.admin.event.UpdatedBlogEntryEvent;
import org.blojsom.plugin.admin.event.DeletedBlogEntryEvent;
import org.blojsom.blog.BlogCategory;
import org.blojsom.blog.BlogEntry;
import org.blojsom.blog.BlogUser;
import org.blojsom.blog.Blog;
import org.blojsom.fetcher.BlojsomFetcher;
import org.blojsom.util.BlojsomUtils;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.*;
import java.text.SimpleDateFormat;
public class MetaWeblogAPIHandler extends AbstractBlojsomAPIHandler {
private static final String METAWEBLOG_ACCEPTED_TYPES_IP = "blojsom-extension-metaweblog-accepted-types";
private static final String MEMBER_BLOGID = "blogid";
private static final String MEMBER_BLOGNAME = "blogName";
private static final String MEMBER_DESCRIPTION = "description";
private static final String MEMBER_HTML_URL = "htmlUrl";
private static final String MEMBER_RSS_URL = "rssUrl";
private static final String MEMBER_TITLE = "title";
private static final String MEMBER_LINK = "link";
private static final String MEMBER_NAME = "name";
private static final String MEMBER_TYPE = "type";
private static final String MEMBER_BITS = "bits";
private static final String MEMBER_PERMALINK = "permaLink";
private static final String MEMBER_DATE_CREATED = "dateCreated";
private static final String MEMBER_CATEGORIES = "categories";
private static final String MEMBER_POSTID = "postid";
private static final String MEMBER_URL = "url";
private static final String METAWEBLOG_API_PERMISSION = "post_via_metaweblog_api";
public static final String API_PREFIX = "metaWeblog";
private String _uploadDirectory;
private HashMap _acceptedMimeTypes;
private String _staticURLPrefix;
private Log _logger = LogFactory.getLog(MetaWeblogAPIHandler.class);
public MetaWeblogAPIHandler() {
}
public String getName() {
return API_PREFIX;
}
public void setBlogUser(BlogUser blogUser) throws BlojsomException {
_blogUser = blogUser;
_blog = _blogUser.getBlog();
_blogEntryExtension = _blog.getBlogProperty(BLOG_XMLRPC_ENTRY_EXTENSION_IP);
if (BlojsomUtils.checkNullOrBlank(_blogEntryExtension)) {
_blogEntryExtension = DEFAULT_BLOG_XMLRPC_ENTRY_EXTENSION;
}
_uploadDirectory = _configuration.getQualifiedResourceDirectory();
if (BlojsomUtils.checkNullOrBlank(_uploadDirectory)) {
throw new BlojsomException("No upload directory specified in blog configuration");
}
if (!_uploadDirectory.endsWith("/")) {
_uploadDirectory += "/";
}
_logger.debug("Upload directory for user [" + _blogUser.getId() + "] is " + _uploadDirectory);
_acceptedMimeTypes = new HashMap(3);
String acceptedMimeTypes = _blog.getBlogProperty(METAWEBLOG_ACCEPTED_TYPES_IP);
if (acceptedMimeTypes != null && !"".equals(acceptedMimeTypes)) {
String[] types = BlojsomUtils.parseCommaList(acceptedMimeTypes);
for (int i = 0; i < types.length; i++) {
String type = types[i];
type = type.toLowerCase();
_acceptedMimeTypes.put(type, type);
}
}
_staticURLPrefix = _configuration.getResourceDirectory();
if (!_staticURLPrefix.endsWith("/")) {
_staticURLPrefix += "/";
}
}
public Object getUsersBlogs(String appkey, String userid, String password) throws Exception {
_logger.debug("getUsersBlogs() Called ===[ SUPPORTED ]=======");
_logger.debug(" Appkey: " + appkey);
_logger.debug(" UserId: " + userid);
_logger.debug(" Password: *********");
try {
_authorizationProvider.loadAuthenticationCredentials(_blogUser);
_authorizationProvider.authorize(_blogUser, null, userid, password);
checkXMLRPCPermission(userid, METAWEBLOG_API_PERMISSION);
Vector result = new Vector();
BlogCategory[] _categories = _fetcher.fetchCategories(null, _blogUser);
if (_categories != null) {
for (int x = 0; x < _categories.length; x++) {
Hashtable _bloglist = new Hashtable(3);
BlogCategory _category = _categories[x];
String _blogid = _category.getCategory();
if (_blogid.length() > 1) {
_blogid = BlojsomUtils.removeInitialSlash(_blogid);
}
String _description = "";
Map _metadata = _category.getMetaData();
if (_metadata != null && _metadata.containsKey(NAME_KEY)) {
_description = (String) _metadata.get(NAME_KEY);
} else {
_description = _category.getEncodedCategory();
}
_bloglist.put(MEMBER_URL, _category.getCategoryURL());
_bloglist.put(MEMBER_BLOGID, _blogid);
_bloglist.put(MEMBER_BLOGNAME, _description);
result.add(_bloglist);
}
}
return result;
} catch (BlojsomException e) {
_logger.error("Failed to authenticate user [" + userid + "] with password [" + password + "]");
throw new XmlRpcException(AUTHORIZATION_EXCEPTION, AUTHORIZATION_EXCEPTION_MSG);
}
}
public Object getCategories(String blogid, String userid, String password) throws Exception {
_logger.debug("getCategories() Called =====[ SUPPORTED ]=====");
_logger.debug(" BlogId: " + blogid);
_logger.debug(" UserId: " + userid);
_logger.debug(" Password: *********");
try {
_authorizationProvider.loadAuthenticationCredentials(_blogUser);
_authorizationProvider.authorize(_blogUser, null, userid, password);
checkXMLRPCPermission(userid, METAWEBLOG_API_PERMISSION);
Hashtable result;
BlogCategory[] categories = _fetcher.fetchCategories(null, _blogUser);
if (categories != null) {
result = new Hashtable(categories.length);
for (int x = 0; x < categories.length; x++) {
Hashtable catlist = new Hashtable(3);
BlogCategory category = categories[x];
String categoryId = category.getCategory();
if (categoryId.length() > 1) {
categoryId = BlojsomUtils.removeInitialSlash(categoryId);
}
String description;
Map metadata = category.getMetaData();
if (metadata != null && metadata.containsKey(DESCRIPTION_KEY)) {
description = (String) metadata.get(DESCRIPTION_KEY);
} else {
description = category.getEncodedCategory();
}
catlist.put(MEMBER_DESCRIPTION, description);
catlist.put(MEMBER_HTML_URL, category.getCategoryURL());
catlist.put(MEMBER_RSS_URL, category.getCategoryURL() + "?flavor=rss2");
result.put(categoryId, catlist);
}
} else {
throw new XmlRpcException(NOBLOGS_EXCEPTION, NOBLOGS_EXCEPTION_MSG);
}
return result;
} catch (BlojsomException e) {
_logger.error("Failed to authenticate user [" + userid + "] with password [" + password + "]");
throw new XmlRpcException(AUTHORIZATION_EXCEPTION, AUTHORIZATION_EXCEPTION_MSG);
}
}
public String newPost(String blogid, String userid, String password, Hashtable struct, boolean publish) throws Exception {
_logger.debug("newPost() Called ===========[ SUPPORTED ]=====");
_logger.debug(" BlogId: " + blogid);
_logger.debug(" UserId: " + userid);
_logger.debug(" Password: *********");
_logger.debug(" Publish: " + publish);
blogid = BlojsomUtils.normalize(blogid);
if (struct.containsKey(MEMBER_CATEGORIES)) {
Vector categories = (Vector) struct.get(MEMBER_CATEGORIES);
if (categories.size() > 0) {
String categoryForPost = (String) categories.get(0);
blogid = BlojsomUtils.normalize(categoryForPost);
}
}
try {
_authorizationProvider.loadAuthenticationCredentials(_blogUser);
_authorizationProvider.authorize(_blogUser, null, userid, password);
checkXMLRPCPermission(userid, METAWEBLOG_API_PERMISSION);
String result = null;
File blogCategory = getBlogCategoryDirectory(blogid);
if (blogCategory.exists() && blogCategory.isDirectory()) {
Hashtable postcontent = struct;
String title = (String) postcontent.get(MEMBER_TITLE);
String description = (String) postcontent.get(MEMBER_DESCRIPTION);
String filename = BlojsomUtils.getBlogEntryFilename(title, description);
String outputfile = blogCategory.getAbsolutePath() + File.separator + filename;
Date dateCreated = (Date) postcontent.get(MEMBER_DATE_CREATED);
try {
File sourceFile = new File(outputfile + _blogEntryExtension);
int fileTag = 1;
while (sourceFile.exists()) {
sourceFile = new File(outputfile + "-" + fileTag + _blogEntryExtension);
fileTag++;
}
String postid = blogid + "?" + PERMALINK_PARAM + "=" + BlojsomUtils.urlEncode(sourceFile.getName());
BlogEntry entry = _fetcher.newBlogEntry();
HashMap attributeMap = new HashMap();
HashMap blogEntryMetaData = new HashMap();
attributeMap.put(SOURCE_ATTRIBUTE, sourceFile);
entry.setAttributes(attributeMap);
entry.setCategory(blogid);
if (BlojsomUtils.checkNullOrBlank(title)) {
title = null;
}
entry.setTitle(title);
entry.setDescription(description);
blogEntryMetaData.put(BLOG_ENTRY_METADATA_AUTHOR, userid);
if (dateCreated == null) {
blogEntryMetaData.put(BLOG_ENTRY_METADATA_TIMESTAMP, new Long(new Date().getTime()).toString());
} else {
blogEntryMetaData.put(BLOG_ENTRY_METADATA_TIMESTAMP, convertDateCreated(dateCreated, _blog));
}
entry.setMetaData(blogEntryMetaData);
entry.save(_blogUser);
entry.load(_blogUser);
result = postid;
_configuration.getEventBroadcaster().broadcastEvent(new AddBlogEntryEvent(this, new Date(), entry, _blogUser));
} catch (BlojsomException e) {
_logger.error(e);
throw new XmlRpcException(UNKNOWN_EXCEPTION, UNKNOWN_EXCEPTION_MSG);
}
}
return result;
} catch (BlojsomException e) {
_logger.error("Failed to authenticate user [" + userid + "] with password [" + password + "]");
throw new XmlRpcException(AUTHORIZATION_EXCEPTION, AUTHORIZATION_EXCEPTION_MSG);
}
}
public boolean editPost(String postid, String userid, String password, Hashtable struct, boolean publish) throws Exception {
_logger.debug("editPost() Called ========[ SUPPORTED ]=====");
_logger.debug(" PostId: " + postid);
_logger.debug(" UserId: " + userid);
_logger.debug(" Password: *********");
_logger.debug(" Publish: " + publish);
try {
_authorizationProvider.loadAuthenticationCredentials(_blogUser);
_authorizationProvider.authorize(_blogUser, null, userid, password);
checkXMLRPCPermission(userid, METAWEBLOG_API_PERMISSION);
boolean result = false;
String category = null;
String permalink = null;
String match = "?" + PERMALINK_PARAM + "=";
int pos = postid.indexOf(match);
if (pos == -1) {
Vector categories = (Vector) struct.get(MEMBER_CATEGORIES);
if (categories == null) {
throw new XmlRpcException(INVALID_POSTID, INVALID_POSTID_MSG);
} else {
category = (String) categories.get(0);
permalink = postid;
}
} else if (pos != -1) {
category = postid.substring(0, pos);
category = BlojsomUtils.normalize(category);
category = BlojsomUtils.urlDecode(category);
permalink = postid.substring(pos + match.length());
}
BlogCategory blogCategory = _fetcher.newBlogCategory();
blogCategory.setCategory(category);
blogCategory.setCategoryURL(_blog.getBlogURL() + category);
Map fetchMap = new HashMap();
fetchMap.put(BlojsomFetcher.FETCHER_CATEGORY, blogCategory);
fetchMap.put(BlojsomFetcher.FETCHER_PERMALINK, permalink);
BlogEntry[] entries = _fetcher.fetchEntries(fetchMap, _blogUser);
if (entries != null && entries.length > 0) {
BlogEntry entry = entries[0];
try {
Hashtable postcontent = struct;
String title = (String) postcontent.get(MEMBER_TITLE);
String description = (String) postcontent.get(MEMBER_DESCRIPTION);
Date dateCreated = (Date) postcontent.get(MEMBER_DATE_CREATED);
if (title == null) {
title = "No Title";
}
String hashable = description;
if (description.length() > MAX_HASHABLE_LENGTH) {
hashable = hashable.substring(0, MAX_HASHABLE_LENGTH);
}
Map blogEntryMetaData = entry.getMetaData();
entry.setTitle(title);
entry.setDescription(description);
if (dateCreated != null) {
blogEntryMetaData.put(BLOG_ENTRY_METADATA_TIMESTAMP, convertDateCreated(dateCreated, _blog));
}
entry.save(_blogUser);
result = true;
_configuration.getEventBroadcaster().broadcastEvent(new UpdatedBlogEntryEvent(this, new Date(), entry, _blogUser));
} catch (BlojsomException e) {
_logger.error(e);
throw new XmlRpcException(UNKNOWN_EXCEPTION, UNKNOWN_EXCEPTION_MSG);
}
} else {
throw new XmlRpcException(INVALID_POSTID, INVALID_POSTID_MSG);
}
return result;
} catch (BlojsomException e) {
_logger.error("Failed to authenticate user [" + userid + "] with password [" + password + "]");
throw new XmlRpcException(AUTHORIZATION_EXCEPTION, AUTHORIZATION_EXCEPTION_MSG);
}
}
public Object getPost(String postid, String userid, String password) throws Exception {
_logger.debug("getPost() Called =========[ SUPPORTED ]=====");
_logger.debug(" PostId: " + postid);
_logger.debug(" UserId: " + userid);
_logger.debug(" Password: *********");
try {
_authorizationProvider.loadAuthenticationCredentials(_blogUser);
_authorizationProvider.authorize(_blogUser, null, userid, password);
checkXMLRPCPermission(userid, METAWEBLOG_API_PERMISSION);
String category;
String permalink;
String match = "?" + PERMALINK_PARAM + "=";
int pos = postid.indexOf(match);
if (pos != -1) {
category = postid.substring(0, pos);
category = BlojsomUtils.normalize(category);
category = BlojsomUtils.urlDecode(category);
permalink = postid.substring(pos + match.length());
BlogCategory blogCategory = _fetcher.newBlogCategory();
blogCategory.setCategory(category);
blogCategory.setCategoryURL(_blog.getBlogURL() + category);
Map fetchMap = new HashMap();
fetchMap.put(BlojsomFetcher.FETCHER_CATEGORY, blogCategory);
fetchMap.put(BlojsomFetcher.FETCHER_PERMALINK, permalink);
BlogEntry[] entries = _fetcher.fetchEntries(fetchMap, _blogUser);
if (entries != null && entries.length > 0) {
BlogEntry entry = entries[0];
Hashtable postcontent = new Hashtable(3);
postcontent.put(MEMBER_TITLE, entry.getTitle());
postcontent.put(MEMBER_LINK, entry.getPermalink());
postcontent.put(MEMBER_DESCRIPTION, entry.getDescription());
postcontent.put(MEMBER_DATE_CREATED, entry.getDate());
postcontent.put(MEMBER_PERMALINK, entry.getLink());
postcontent.put(MEMBER_POSTID, entry.getId());
Vector postCategories = new Vector(1);
postCategories.add(entry.getCategory());
postcontent.put(MEMBER_CATEGORIES, postCategories);
return postcontent;
} else {
throw new XmlRpcException(INVALID_POSTID, INVALID_POSTID_MSG);
}
} else {
throw new XmlRpcException(INVALID_POSTID, INVALID_POSTID_MSG);
}
} catch (BlojsomException e) {
_logger.error("Failed to authenticate user [" + userid + "] with password [" + password + "]");
throw new XmlRpcException(AUTHORIZATION_EXCEPTION, AUTHORIZATION_EXCEPTION_MSG);
}
}
public boolean deletePost(String appkey, String postid, String userid, String password, boolean publish) throws Exception {
_logger.debug("deletePost() Called =====[ SUPPORTED ]=====");
_logger.debug(" Appkey: " + appkey);
_logger.debug(" PostId: " + postid);
_logger.debug(" UserId: " + userid);
_logger.debug(" Password: *********");
boolean result = false;
try {
_authorizationProvider.loadAuthenticationCredentials(_blogUser);
_authorizationProvider.authorize(_blogUser, null, userid, password);
checkXMLRPCPermission(userid, METAWEBLOG_API_PERMISSION);
String category;
String permalink;
String match = "?" + PERMALINK_PARAM + "=";
int pos = postid.indexOf(match);
if (pos != -1) {
category = postid.substring(0, pos);
category = BlojsomUtils.normalize(category);
category = BlojsomUtils.urlDecode(category);
permalink = postid.substring(pos + match.length());
Map fetchMap = new HashMap();
BlogCategory blogCategory = _fetcher.newBlogCategory();
blogCategory.setCategory(category);
blogCategory.setCategoryURL(_blog.getBlogURL() + category);
fetchMap.put(BlojsomFetcher.FETCHER_CATEGORY, blogCategory);
fetchMap.put(BlojsomFetcher.FETCHER_PERMALINK, permalink);
BlogEntry[] _entries = _fetcher.fetchEntries(fetchMap, _blogUser);
if (_entries != null && _entries.length > 0) {
try {
_entries[0].delete(_blogUser);
} catch (BlojsomException e) {
_logger.error(e);
throw new XmlRpcException(UNKNOWN_EXCEPTION, UNKNOWN_EXCEPTION_MSG);
}
result = true;
_configuration.getEventBroadcaster().broadcastEvent(new DeletedBlogEntryEvent(this, new Date(), _entries[0], _blogUser));
} else {
throw new XmlRpcException(INVALID_POSTID, INVALID_POSTID_MSG);
}
}
} catch (BlojsomException e) {
_logger.error("Failed to authenticate user [" + userid + "] with password [" + password + "]");
throw new XmlRpcException(AUTHORIZATION_EXCEPTION, AUTHORIZATION_EXCEPTION_MSG);
}
return result;
}
public Object getRecentPosts(String blogid, String userid, String password, int numberOfPosts) throws Exception {
_logger.debug("getRecentPosts() Called =========[ SUPPORTED ]=====");
_logger.debug(" BlogId: " + blogid);
_logger.debug(" UserId: " + userid);
_logger.debug(" Password: *********");
try {
_authorizationProvider.loadAuthenticationCredentials(_blogUser);
_authorizationProvider.authorize(_blogUser, null, userid, password);
checkXMLRPCPermission(userid, METAWEBLOG_API_PERMISSION);
blogid = BlojsomUtils.normalize(blogid);
BlogCategory category = _fetcher.newBlogCategory();
category.setCategory(blogid);
category.setCategoryURL(_blog.getBlogURL() + blogid);
Map fetchMap = new HashMap();
fetchMap.put(BlojsomFetcher.FETCHER_CATEGORY, category);
fetchMap.put(BlojsomFetcher.FETCHER_NUM_POSTS_INTEGER, new Integer(numberOfPosts));
BlogEntry[] entries = _fetcher.fetchEntries(fetchMap, _blogUser);
Vector blogEntries = new Vector();
Hashtable postcontent;
if (entries != null && entries.length > 0) {
blogEntries = new Vector(entries.length);
BlogEntry entry;
for (int i = 0; i < entries.length; i++) {
entry = entries[i];
postcontent = new Hashtable(7);
postcontent.put(MEMBER_TITLE, entry.getTitle());
postcontent.put(MEMBER_LINK, entry.getPermalink());
postcontent.put(MEMBER_DESCRIPTION, entry.getDescription());
postcontent.put(MEMBER_DATE_CREATED, entry.getDate());
postcontent.put(MEMBER_PERMALINK, entry.getLink());
postcontent.put(MEMBER_POSTID, entry.getId());
Vector postCategories = new Vector(1);
postCategories.add(entry.getCategory());
postcontent.put(MEMBER_CATEGORIES, postCategories);
blogEntries.add(postcontent);
}
}
return blogEntries;
} catch (BlojsomException e) {
_logger.error("Failed to authenticate user [" + userid + "] with password [" + password + "]");
throw new XmlRpcException(AUTHORIZATION_EXCEPTION, AUTHORIZATION_EXCEPTION_MSG);
}
}
public Object newMediaObject(String blogid, String userid, String password, Hashtable struct) throws Exception {
_logger.debug("newMediaObject() Called =[ SUPPORTED ]=====");
_logger.debug(" BlogId: " + blogid);
_logger.debug(" UserId: " + userid);
_logger.debug(" Password: *********");
try {
_authorizationProvider.loadAuthenticationCredentials(_blogUser);
_authorizationProvider.authorize(_blogUser, null, userid, password);
checkXMLRPCPermission(userid, METAWEBLOG_API_PERMISSION);
String name = (String) struct.get(MEMBER_NAME);
name = BlojsomUtils.getFilenameFromPath(name);
_logger.debug("newMediaObject name: " + name);
String type = (String) struct.get(MEMBER_TYPE);
_logger.debug("newMediaObject type: " + type);
byte[] bits = (byte[]) struct.get(MEMBER_BITS);
File uploadDirectory = new File(_uploadDirectory);
if (!uploadDirectory.exists()) {
_logger.error("Upload directory does not exist: " + uploadDirectory.toString());
throw new XmlRpcException(UNKNOWN_EXCEPTION, "Upload directory does not exist: " + uploadDirectory.toString());
}
if (_acceptedMimeTypes.containsKey(type.toLowerCase())) {
try {
File uploadDirectoryForUser = new File(uploadDirectory, _blogUser.getId());
if (!uploadDirectoryForUser.exists()) {
if (!uploadDirectoryForUser.mkdir()) {
_logger.error("Could not create upload directory for user: " + uploadDirectoryForUser.toString());
throw new XmlRpcException(UNKNOWN_EXCEPTION, "Could not create upload directory for user: " + _blogUser.getId());
}
}
File mediaObjectFile = new File(name); File parentDirs = mediaObjectFile.getParentFile();
if (parentDirs != null) {
String parentDirsString = parentDirs.toString();
if (parentDirsString.startsWith("/")) {
parentDirsString = parentDirsString.substring(1);
}
File uploadMediaDirectory = new File(uploadDirectoryForUser, parentDirsString);
_logger.debug("upload directory for this media object: " + uploadMediaDirectory.toString());
if (!uploadMediaDirectory.exists()) {
if (!uploadMediaDirectory.mkdirs()) {
_logger.error("Could not create upload directory: " + uploadMediaDirectory.toString());
throw new XmlRpcException(UNKNOWN_EXCEPTION, "Could not create upload directory: " + uploadMediaDirectory.toString());
}
}
}
String slashOrNot = "/";
if (_blogUser.getId().endsWith("/")) {
slashOrNot = "";
}
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(new File(uploadDirectoryForUser, name)));
bos.write(bits);
bos.close();
Hashtable returnStruct = new Hashtable(1);
String mediaURL = _blog.getBlogBaseURL() + _staticURLPrefix + BlojsomUtils.removeTrailingSlash(_blogUser.getId()) + "/" + name;
_logger.debug("newMediaObject URL: " + mediaURL);
returnStruct.put(MEMBER_URL, mediaURL);
return returnStruct;
} catch (IOException e) {
_logger.error(e);
throw new XmlRpcException(UNKNOWN_EXCEPTION, UNKNOWN_EXCEPTION_MSG);
}
} else {
_logger.error("MIME type not accepted. Received MIME type: " + type);
throw new XmlRpcException(UNKNOWN_EXCEPTION, "MIME type not accepted. Received MIME type: " + type);
}
} catch (BlojsomException e) {
_logger.error("Failed to authenticate user [" + userid + "] with password [" + password + "]");
throw new XmlRpcException(AUTHORIZATION_EXCEPTION, AUTHORIZATION_EXCEPTION_MSG);
}
}
public boolean setTemplate(String appkey, String blogid, String userid, String password, String template, String templateType) throws Exception {
_logger.debug("setTemplate() Called =====[ UNSUPPORTED ]=====");
_logger.debug(" Appkey: " + appkey);
_logger.debug(" BlogId: " + blogid);
_logger.debug(" UserId: " + userid);
_logger.debug(" Password: *********");
_logger.debug(" Template: " + template);
_logger.debug(" Type: " + templateType);
throw new XmlRpcException(UNSUPPORTED_EXCEPTION, UNSUPPORTED_EXCEPTION_MSG);
}
public String getTemplate(String appkey, String blogid, String userid, String password, String templateType) throws Exception {
_logger.debug("getTemplate() Called =====[ UNSUPPORTED ]=====");
_logger.debug(" Appkey: " + appkey);
_logger.debug(" BlogId: " + blogid);
_logger.debug(" UserId: " + userid);
_logger.debug(" Password: *********");
_logger.debug(" Type: " + templateType);
throw new XmlRpcException(UNSUPPORTED_EXCEPTION, UNSUPPORTED_EXCEPTION_MSG);
}
private String convertDateCreated(Date dateCreated, Blog blog) {
if (dateCreated == null) {
return Long.toString(new Date().getTime());
} else {
String timezoneID = blog.getBlogProperty("blog-timezone-id");
TimeZone timezone;
if (BlojsomUtils.checkNullOrBlank(timezoneID)) {
timezone = TimeZone.getDefault();
} else {
timezone = TimeZone.getTimeZone(timezoneID);
}
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(ISO_8601_DATE_FORMAT);
simpleDateFormat.setTimeZone(timezone);
long convertedDateTime = dateCreated.getTime();
try {
convertedDateTime = Long.parseLong(simpleDateFormat.format(dateCreated));
} catch (NumberFormatException e) {
}
return Long.toString(convertedDateTime);
}
}
}