LifeBlog
abstract class provides the base functionality used by all blog ({@link LifeFTP}, {@link
- * LifeMediaObject}, etc.) actions.
+ * The LifeBlog
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);
- }
}
diff --git a/src/net/thauvin/lifeblogger/LifeBlogger.java b/src/net/thauvin/lifeblogger/LifeBlogger.java
index aa74906..c7b3141 100644
--- a/src/net/thauvin/lifeblogger/LifeBlogger.java
+++ b/src/net/thauvin/lifeblogger/LifeBlogger.java
@@ -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",
+ "via LifeBlogger
"); + 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")); diff --git a/src/net/thauvin/lifeblogger/LifeFTP.java b/src/net/thauvin/lifeblogger/LifeFTP.java index 9b026ff..0f6152a 100644 --- a/src/net/thauvin/lifeblogger/LifeFTP.java +++ b/src/net/thauvin/lifeblogger/LifeFTP.java @@ -130,6 +130,7 @@ public class LifeFTP extends LifeBlog else { getThinlet().closeDialog(getDialog()); + getThinlet().postDialog(getPath() + (getPath().endsWith("/") ? "" : "/") + getFilename(), getFilename()); } } } diff --git a/src/net/thauvin/lifeblogger/LifeMediaObjResponse.java b/src/net/thauvin/lifeblogger/LifeMediaObjResponse.java deleted file mode 100644 index e2807fd..0000000 --- a/src/net/thauvin/lifeblogger/LifeMediaObjResponse.java +++ /dev/null @@ -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; - - -/** - * TheLifeMediaObjResponse
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 true
is the response is valid, false
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
- }
- }
- }
-}
diff --git a/src/net/thauvin/lifeblogger/LifeMediaObject.java b/src/net/thauvin/lifeblogger/LifeMediaObject.java
index cb10b94..4637e91 100644
--- a/src/net/thauvin/lifeblogger/LifeMediaObject.java
+++ b/src/net/thauvin/lifeblogger/LifeMediaObject.java
@@ -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 LifeMediaObject
class posts a new media object via the metaWeblog.newMediaObject XML-RPC call.
+ * The LifeMediaObject
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
{
diff --git a/src/net/thauvin/lifeblogger/ReleaseInfo.java b/src/net/thauvin/lifeblogger/ReleaseInfo.java
index cd5a7e7..bf3ced4 100644
--- a/src/net/thauvin/lifeblogger/ReleaseInfo.java
+++ b/src/net/thauvin/lifeblogger/ReleaseInfo.java
@@ -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"). */
diff --git a/src/net/thauvin/lifeblogger/about.xml b/src/net/thauvin/lifeblogger/about.xml
index ef0f959..35aa1c1 100644
--- a/src/net/thauvin/lifeblogger/about.xml
+++ b/src/net/thauvin/lifeblogger/about.xml
@@ -14,7 +14,7 @@