Added ability to post to post via the Blogger API.

This commit is contained in:
Erik C. Thauvin 2004-07-24 12:20:05 +00:00
parent 4b7ea52793
commit 38544a1b56
11 changed files with 282 additions and 450 deletions

View file

@ -36,15 +36,13 @@
*/
package net.thauvin.lifeblogger;
import java.awt.*;
import java.io.File;
import java.io.IOException;
/**
* The <code>LifeBlog</code> abstract class provides the base functionality used by all blog ({@link LifeFTP}, {@link
* LifeMediaObject}, etc.) actions.
* The <code>LifeBlog</code> abstract class provides the base functionality for file transfer-based ({@link LifeFTP},
* {@link LifeMediaObject}, etc.) actions.
*
* @author Erik C. Thauvin
* @version $Revision$, $Date$
@ -52,43 +50,18 @@ import java.io.IOException;
* @created Jul 20, 2004
* @since 1.0
*/
public abstract class LifeBlog extends Thread
public abstract class LifeBlog extends LifeAction
{
/**
* The file to upload/store.
*/
private final File _file;
/**
* The Thinlet instance.
*/
private final LifeBlogger _thinlet;
/**
* The Transfer dialog.
*/
private final Object _dialog;
/**
* The file name.
*/
private final String _filename;
/**
* The host name.
*/
private final String _host;
/**
* The login name.
*/
private final String _login;
/**
* The password.
*/
private final String _password;
/**
* The path/location.
*/
@ -111,33 +84,13 @@ public abstract class LifeBlog extends Thread
File file)
throws IOException
{
_thinlet = thinlet;
_dialog = getThinlet().parse("transfer.xml");
_host = host;
_login = login;
_password = password;
super(thinlet, host, login, password);
_path = path;
_filename = filename;
_file = file;
}
/**
* Performs the action.
*
* @see Thread#run()
*/
public abstract void run();
/**
* Returns the Transfer dialog.
*
* @return The dialog.
*/
protected final Object getDialog()
{
return _dialog;
}
/**
* Returns the file.
*
@ -158,36 +111,6 @@ public abstract class LifeBlog extends Thread
return _filename;
}
/**
* Returns the host name.
*
* @return The host.
*/
protected final String getHost()
{
return _host;
}
/**
* Returns the login name.
*
* @return The login.
*/
protected final String getLogin()
{
return _login;
}
/**
* Returns the password.
*
* @return The password.
*/
protected final String getPassword()
{
return _password;
}
/**
* Returns the path/location.
*
@ -197,28 +120,4 @@ public abstract class LifeBlog extends Thread
{
return _path;
}
/**
* Returns the Thinlet instance.
*
* @return The Thinlet.
*/
protected final LifeBlogger getThinlet()
{
return _thinlet;
}
/**
* Displays an alert message.
*
* @param message The message to display.
*/
protected final void alert(String message)
{
Toolkit.getDefaultToolkit().beep();
getThinlet().setIcon(getThinlet().find(getDialog(), "iconlbl"), "icon", getThinlet().getIcon("/icon/error.gif"));
getThinlet().setString(getThinlet().find(getDialog(), "message"), "text", message);
getThinlet().setBoolean(getThinlet().find(getDialog(), "closebtn"), "enabled", true);
}
}

View file

@ -290,9 +290,20 @@ public class LifeBlogger extends Thinlet
}
finally
{
st.close();
rs.close();
con.close();
if (st != null)
{
st.close();
}
if (rs != null)
{
rs.close();
}
if (con != null)
{
con.close();
}
}
toggleButton(table, find(buttonsPanel, "blogbtn"));
@ -440,6 +451,14 @@ public class LifeBlogger extends Thinlet
_prefs.put("mw-password", Base64.encodeBytes(password.getBytes(), Base64.DONT_BREAK_LINES));
_prefs.put("mw-id", blogID);
if (_prefs.getProperty("blog-host") == null)
{
_prefs.put("blog-host", host);
_prefs.put("blog-login", login);
_prefs.put("blog-password", Base64.encodeBytes(password.getBytes(), Base64.DONT_BREAK_LINES));
_prefs.put("blog-id", blogID);
}
savePrefs();
closeDialog(dialog);
@ -453,34 +472,82 @@ public class LifeBlogger extends Thinlet
}
/**
* Toggles the given button based on the specified table selection.
* Preforms the post to blog action.
*
* @param table The table.
* @param button The button.
* @param dialog The post dialog,
* @param blogPanel The panel contaning the post data.
*
* @throws IOException If an error occurs while performing the action.
*/
public final void toggleButton(Object table, Object button)
public final void post(Object dialog, Object blogPanel)
throws IOException
{
setBoolean(button, "enabled", getSelectedIndex(table) != -1);
final String host = getString(find(blogPanel, "host"), "text");
final String blogID = getString(find(blogPanel, "blogid"), "text");
final String login = getString(find(blogPanel, "login"), "text");
final String password = getString(find(blogPanel, "password"), "text");
final String entry = getString(find(blogPanel, "entry"), "text");
if (host.length() <= 0)
{
alert("Please specify a XML-RPC URL.");
}
else if (login.length() <= 0)
{
alert("Please specify a login name.");
}
else if (password.length() <= 0)
{
alert("Please specify a password.");
}
else if (entry.length() <= 0)
{
alert("Please specify a post entry.");
}
else if (blogID.length() <= 0)
{
alert("Please specify a blog ID.");
}
else
{
_prefs.put("blog-host", host);
_prefs.put("blog-login", login);
_prefs.put("blog-password", Base64.encodeBytes(password.getBytes(), Base64.DONT_BREAK_LINES));
_prefs.put("blog-id", blogID);
savePrefs();
closeDialog(dialog);
final LifePost post =
new LifePost(this, host, blogID, login, password, getString(find(blogPanel, "entry"), "text"));
post.start();
}
}
/**
* Updates the table data.
* Displays the post to blog dialog.
*
* @param thinlet The Thinlet object.
* @param table The table to update.
* @param buttonsPanel The panel containing the buttons/label to update.
* @param url The URL pointing to the location of the media object.
* @param filename DOCUMENT ME!
*/
public final void updateTable(Thinlet thinlet, Object table, Object buttonsPanel)
public final void postDialog(String url, String filename)
{
thinlet.removeAll(table);
try
{
addTableRows(thinlet, table, buttonsPanel);
final Object post = parse("post.xml");
setString(find(post, "host"), "text", _prefs.getProperty("blog-host", ""));
setString(find(post, "blogid"), "text", _prefs.getProperty("blog-id", ""));
setString(find(post, "login"), "text", _prefs.getProperty("blog-login", ""));
setString(find(post, "password"), "text", new String(Base64.decode(_prefs.getProperty("blog-password", ""))));
setString(find(post, "entry"), "text",
"<img src=\"" + url + "\" alt=\"" + filename +
"\">\n<p>via <a href=\"http://www.thauvin.net/erik/lifeblogger/\">LifeBlogger</a></p>");
add(post);
}
catch (Exception e)
{
showException(e);
e.printStackTrace();
}
}
@ -492,7 +559,7 @@ public class LifeBlogger extends Thinlet
* @throws Exception If an error occurs while previewing the image.
*/
public final void preview(Object table)
throws Exception
throws Exception
{
final int selected = getSelectedIndex(table);
@ -554,6 +621,38 @@ public class LifeBlogger extends Thinlet
}
}
/**
* Toggles the given button based on the specified table selection.
*
* @param table The table.
* @param button The button.
*/
public final void toggleButton(Object table, Object button)
{
setBoolean(button, "enabled", getSelectedIndex(table) != -1);
}
/**
* Updates the table data.
*
* @param thinlet The Thinlet object.
* @param table The table to update.
* @param buttonsPanel The panel containing the buttons/label to update.
*/
public final void updateTable(Thinlet thinlet, Object table, Object buttonsPanel)
{
thinlet.removeAll(table);
try
{
addTableRows(thinlet, table, buttonsPanel);
}
catch (Exception e)
{
showException(e);
}
}
/**
* Displays an exception stacktrace.
*
@ -658,6 +757,7 @@ public class LifeBlogger extends Thinlet
setString(find(ftp, "filename"), "text", file.substring(file.lastIndexOf('\\') + 1));
setString(find(ftp, "host"), "text", _prefs.getProperty("host", ""));
setString(find(ftp, "login"), "text", _prefs.getProperty("login", "anonymous"));
setString(find(ftp, "path"), "text", _prefs.getProperty("path", ""));
setString(find(ftp, "password"), "text", new String(Base64.decode(_prefs.getProperty("password", ""))));
add(ftp);
requestFocus(find(ftp, "host"));

View file

@ -130,6 +130,7 @@ public class LifeFTP extends LifeBlog
else
{
getThinlet().closeDialog(getDialog());
getThinlet().postDialog(getPath() + (getPath().endsWith("/") ? "" : "/") + getFilename(), getFilename());
}
}
}

View file

@ -1,155 +0,0 @@
/*
* @(#)LifeMediaObjResponse.java
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the authors nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id$
*
*/
package net.thauvin.lifeblogger;
import thinlet.Thinlet;
import java.io.IOException;
import java.io.InputStream;
/**
* The <code>LifeMediaObjResponse</code> class uses the Thinlet DOM parser to process the metaWeblog.newMediaObject
* XML-RPC reponse.
*
* @author Erik C. Thauvin
* @version $Revision$, $Date$
*
* @created Jul 21, 2004
* @since 1.0
*/
public class LifeMediaObjResponse extends Thinlet
{
private final InputStream _inputStream;
private String _response;
/**
* Creates a new LifeMediaObjResponse object.
*
* @param inputStream The input stream.
*/
public LifeMediaObjResponse(InputStream inputStream)
{
_inputStream = inputStream;
}
/**
* Returns the XML-RPC response/fault string.
*
* @return The response string.
*/
public final String getResponse()
{
return _response;
}
/**
* Parses and validates the XML-RPC response.
*
* @return <code>true</code> is the response is valid, <code>false</code> if it is a fault.
*
* @throws IOException If an error occurs while processing the response.
*/
public final boolean isValidResponse()
throws IOException
{
try
{
final Object dom = parseDOM(_inputStream);
final Object params = getDOMNode(dom, "params", 0);
if (params != null)
{
final Object param = getDOMNode(params, "param", 0);
final Object value = getDOMNode(param, "value", 0);
final Object struct = getDOMNode(value, "struct", 0);
final Object member = getDOMNode(struct, "member", 0);
final Object url = getDOMNode(member, "value", 0);
final Object string = getDOMNode(url, "string", 0);
if (string == null)
{
_response = getDOMText(url);
}
else
{
_response = getDOMText(string);
}
return true;
}
else
{
final Object fault = getDOMNode(dom, "fault", 0);
final Object value = getDOMNode(fault, "value", 0);
final Object struct = getDOMNode(value, "struct", 0);
Object member = getDOMNode(struct, "member", 0);
if (getDOMCount(struct, "member") > 1)
{
member = getDOMNode(struct, "member", 1);
}
final Object error = getDOMNode(member, "value", 0);
final Object string = getDOMNode(error, "string", 0);
if (string != null)
{
_response = getDOMText(string);
}
else
{
throw new IOException("Could not parse the XML-RPC error response.");
}
return false;
}
}
catch (IOException e)
{
throw e;
}
finally
{
try
{
_inputStream.close();
}
catch (IOException ignore)
{
; // Do nothing
}
}
}
}

View file

@ -36,9 +36,6 @@
*/
package net.thauvin.lifeblogger;
import java.awt.*;
import java.awt.datatransfer.StringSelection;
import java.io.*;
import java.net.URL;
@ -46,7 +43,7 @@ import java.net.URLConnection;
/**
* The <code>LifeMediaObject</code> class posts a new media object via the metaWeblog.newMediaObject XML-RPC call.
* The <code>LifeMediaObject</code> class posts a new media object via the metaWeblog.newMediaObject XML-RPC method.
*
* @author Erik C. Thauvin
* @version $Revision$, $Date$
@ -165,19 +162,12 @@ public class LifeMediaObject extends LifeBlog
dos.close();
final LifeMediaObjResponse xmlrpc = new LifeMediaObjResponse(urlConn.getInputStream());
final LifeRPCResponse xmlrpc = new LifeRPCResponse(urlConn.getInputStream());
if (xmlrpc.isValidResponse())
{
getThinlet().setIcon(getThinlet().find(getDialog(), "iconlbl"), "icon",
getThinlet().getIcon("/icon/info.gif"));
getThinlet().setString(getThinlet().find(getDialog(), "message"), "text",
"The file can now be accessed at:\n\n" + xmlrpc.getResponse() +
"\n\nwhich has been copied to the clipboard.");
getThinlet().setBoolean(getThinlet().find(getDialog(), "closebtn"), "enabled", true);
final StringSelection ss = new StringSelection(xmlrpc.getResponse());
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, ss);
getThinlet().closeDialog(getDialog());
getThinlet().postDialog(xmlrpc.getResponse(), getFilename());
}
else
{

View file

@ -1,5 +1,5 @@
/* Created by JReleaseInfo AntTask from Open Source Competence Group */
/* Creation date Fri Jul 23 12:07:42 PDT 2004 */
/* Creation date Sat Jul 24 05:15:28 PDT 2004 */
package net.thauvin.lifeblogger;
import java.util.Date;
@ -12,21 +12,21 @@ import java.util.Date;
public class ReleaseInfo {
/** buildDate (set during build process to 1090609662812L). */
private static Date buildDate = new Date(1090609662812L);
/** buildDate (set during build process to 1090671328718L). */
private static Date buildDate = new Date(1090671328718L);
/**
* Get buildDate (set during build process to Fri Jul 23 12:07:42 PDT 2004).
* Get buildDate (set during build process to Sat Jul 24 05:15:28 PDT 2004).
* @return Date buildDate
*/
public static final Date getBuildDate() { return buildDate; }
/**
* Get buildNumber (set during build process to 101).
* Get buildNumber (set during build process to 107).
* @return int buildNumber
*/
public static final int getBuildNumber() { return 101; }
public static final int getBuildNumber() { return 107; }
/** version (set during build process to "0.1.0"). */

View file

@ -14,7 +14,7 @@
<label alignment="left" weightx="1" text="and Erik C. Thauvin"/>
</panel>
<panel top="0" columns="1" left="8" bottom="0" gap="0" right="8">
<label alignment="left" weightx="1" text="Logo made by Russell Beattie"/>
<label alignment="left" weightx="1" text="LifeBlogger is open source."/>
</panel>
<panel top="0" columns="1" left="8" bottom="4" gap="0" right="8">
<label alignment="center" weightx="1" icon="/icon/thinlet.gif"/>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<dialog name="dialog" text="Send via FTP" modal="false" columns="1" gap="4" top="4" left="4" bottom="4" right="4">
<dialog name="dialog" icon="/icon/icon.gif" text="Send via FTP" modal="false" columns="1" gap="4" top="4" left="4" bottom="4" right="4">
<panel name="ftp" columns="2" halign="right" gap="4">
<label text="File:"/><textfield name="file" columns="50" editable="false"/>
<label text="Host:"/><textfield name="host" start="0" end="1000"/>

View file

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<dialog name="dialog" text="Send via MetaWeblog" modal="false" columns="1" gap="4" top="4" left="4" bottom="4" right="4">
<dialog name="dialog" icon="/icon/icon.gif" text="Send via MetaWeblog" modal="false" columns="1" gap="4" top="4" left="4" bottom="4" right="4">
<panel name="mw" columns="2" halign="right" gap="4">
<label text="File:"/><textfield name="file" columns="50" editable="false"/>
<label text="URL:"/><textfield name="host" start="0" end="1000"/>
<label text="RPC URL:"/><textfield name="host" start="0" end="1000"/>
<label text="Blog ID:"/><textfield name="blogid"/>
<label text="Login:"/><textfield name="login"/>
<label text="Password:"/><passwordfield name="password"/>