Initial import.

This commit is contained in:
Erik C. Thauvin 2004-07-22 11:26:01 +00:00
commit 7e410fa987
44 changed files with 3873 additions and 0 deletions

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,224 @@
/*
* @(#)LifeBlog.java
*
* Copyright (c) 2004, Erik C. Thauvin (http://www.thauvin.net/erik/)
* All rights reserved.
*
* 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 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.
*
* @author Erik C. Thauvin
* @version $Revision$, $Date$
*
* @created Jul 20, 2004
* @since 1.0
*/
public abstract class LifeBlog extends Thread
{
/**
* 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.
*/
private final String _path;
/**
* Creates a new LifeBlog object.
*
* @param thinlet The Thinlet instance.
* @param host The host.
* @param login The login name.
* @param password The password.
* @param path The path/location.
* @param filename The name of the file to upload/store.
* @param file The file to upload.
*
* @throws IOException If an error occurs while creating the object.
*/
protected LifeBlog(LifeBlogger thinlet, String host, String login, String password, String path, String filename,
File file)
throws IOException
{
_thinlet = thinlet;
_dialog = getThinlet().parse("transfer.xml");
_host = host;
_login = login;
_password = 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.
*
* @return The file.
*/
protected final File getFile()
{
return _file;
}
/**
* Returns the file name.
*
* @return The file name.
*/
protected final String getFilename()
{
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.
*
* @return The path.
*/
protected final String getPath()
{
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

@ -0,0 +1,598 @@
/*
* @(#)LifeBlogger.java
*
* Copyright (c) 2004, Erik C. Thauvin (http://www.thauvin.net/erik/)
* All rights reserved.
*
* 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.FrameLauncher;
import thinlet.Thinlet;
import java.awt.*;
import java.io.*;
import java.net.URL;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.Properties;
import javax.swing.*;
/**
* The <code>LifeBlogger</code> class uploads/posts Lifeblog's favorite data to a blog.
*
* @author Erik C. Thauvin
* @version $Revision$, $Date$
*
* @created Jul 19, 2004
* @since 1.0
*/
public class LifeBlogger extends Thinlet
{
private static final String DRIVER = "SQLite.JDBCDriver";
private static final String PREFS =
System.getProperty("user.home") + File.separator + ReleaseInfo.getProject() + ".properties";
private static final String JDBC_PREFIX = "jdbc:sqlite:/";
private static final String DATABASE = "\\DataBase\\NokiaLifeblogDataBase.db";
private final Properties _prefs = new Properties();
private File _homeDir = new File(System.getProperty("user.home") + "\\My Documents\\NokiaLifeblogData");
private String _action;
/**
* Creates a new LifeBlogger object.
*
* @throws IOException DOCUMENT ME!
*/
private LifeBlogger()
throws IOException
{
setFont(new Font("SansSerif", Font.PLAIN, 11));
FileInputStream fis = null;
try
{
fis = new FileInputStream(PREFS);
_prefs.load(fis);
}
catch (IOException e)
{
e.printStackTrace(System.err);
}
finally
{
if (fis != null)
{
try
{
fis.close();
}
catch (IOException ignore)
{
; // Do nothing
}
}
}
_homeDir = new File(_prefs.getProperty("home", _homeDir.getAbsolutePath()));
_action = _prefs.getProperty("via", "ftp");
try
{
Class.forName(DRIVER);
}
catch (Exception e)
{
e.printStackTrace();
}
final Object main = parse("main.xml");
setBoolean(find(main, _action), "selected", true);
add(main);
}
/**
* The main program.
*
* @param args The command line arguments.
*/
public static void main(String[] args)
{
try
{
new FrameLauncher("LifeBlogger",
(new ImageIcon(LifeBlogger.class.getResource("/icon/icon.gif"))).getImage(),
new LifeBlogger(), 400, 400, true);
}
catch (Exception e)
{
e.printStackTrace();
}
}
/**
* Sets the blog action.
*
* @param action The action
*/
public final void setAction(String action)
{
_action = action;
_prefs.put("via", _action);
savePrefs();
}
/**
* Displays the about dialog.
*/
public final void about()
{
try
{
final Object about = parse("about.xml");
setString(about, "text", "About " + ReleaseInfo.getProject());
setString(find(about, "version"), "text",
"Version " + ReleaseInfo.getVersion() + " - Build " + ReleaseInfo.getBuildNumber());
final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
setString(find(about, "date"), "text", sdf.format(ReleaseInfo.getBuildDate()));
add(about);
}
catch (Exception e)
{
e.printStackTrace();
}
}
/**
* Populates the table rows.
*
* @param thinlet The Thinlet object.
* @param table The table to populate.
* @param buttonsPanel The panel containing the buttons/label to update.
*
* @throws Exception If an error occurs while populate the table.
*/
public final void addTableRows(Thinlet thinlet, Object table, Object buttonsPanel)
throws Exception
{
if (!_homeDir.exists())
{
final JFileChooser fc = new JFileChooser();
fc.setDialogTitle("Select Nokia LifeBlog document directory:");
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fc.setMultiSelectionEnabled(false);
fc.setAcceptAllFileFilterUsed(false);
final int res = fc.showOpenDialog(this);
if (res == JFileChooser.APPROVE_OPTION)
{
_homeDir = fc.getSelectedFile();
_prefs.put("home", _homeDir.getAbsolutePath());
savePrefs();
}
}
final Connection con = DriverManager.getConnection(JDBC_PREFIX + _homeDir.getAbsolutePath() + DATABASE);
final Statement st = con.createStatement();
final ResultSet rs =
st.executeQuery("SELECT * FROM HooverObject WHERE MobileFavourite = 'true' ORDER BY TimeStamp DESC");
Object row;
Object cell;
String ts;
String name;
boolean first = true;
int found = 0;
while (rs.next())
{
ts = rs.getString("TimeStamp");
name = rs.getString("name");
row = Thinlet.create("row");
cell = Thinlet.create("cell");
thinlet.setString(cell, "text", name);
if (name.toLowerCase().endsWith("jpg"))
{
thinlet.setIcon(cell, "icon", getIcon("/icon/image.gif"));
}
else if (name.toLowerCase().endsWith("3gp"))
{
thinlet.setIcon(cell, "icon", getIcon("/icon/movie.gif"));
}
else
{
thinlet.setIcon(cell, "icon", getIcon("/icon/text.gif"));
}
thinlet.putProperty(cell, "oid", rs.getString("HooverObjectID"));
thinlet.add(row, cell);
cell = Thinlet.create("cell");
thinlet.setString(cell, "text", ts.substring(0, ts.lastIndexOf(':')));
thinlet.add(row, cell);
if (first)
{
thinlet.setBoolean(row, "selected", true);
first = false;
}
thinlet.add(table, row);
found++;
}
thinlet.setString(find(buttonsPanel, "favslbl"), "text", "Favorites: " + found);
st.close();
rs.close();
con.close();
toggleButton(table, find(buttonsPanel, "blogbtn"));
}
/**
* Performs the blog action.
*
* @param table The table containing the selected item to perform the action on.
*
* @throws Exception If an error occurs while performing the action.
*/
public final void blog(Object table)
throws Exception
{
final int selected = getSelectedIndex(table);
if (selected != -1)
{
final Object row = getItem(table, selected);
final String name = String.valueOf(getProperty(getItem(row, 0), "oid"));
final Connection con = DriverManager.getConnection(JDBC_PREFIX + _homeDir.getAbsolutePath() + DATABASE);
final Statement st = con.createStatement();
final ResultSet rs = st.executeQuery("SELECT * FROM BinaryItem WHERE HooverObjectID = " + name);
if (rs.next())
{
if ("ftp".equals(_action))
{
ftpDialog(_homeDir.getAbsolutePath() + "\\DataStore" + rs.getString("Pathname") +
rs.getString("Filename"));
}
else
{
mwDialog(_homeDir.getAbsolutePath() + "\\DataStore" + rs.getString("Pathname") +
rs.getString("Filename"), rs.getString("ObjectMimeType"));
}
}
st.close();
rs.close();
con.close();
}
}
/**
* Closes the given dialog.
*
* @param dialog The dialog to close.
*/
public final void closeDialog(Object dialog)
{
remove(dialog);
}
/**
* Extis the main program.
*/
public final void exit()
{
System.exit(0);
}
/**
* Preforms the FTP action.
*
* @param dialog The FTP dialog,
* @param ftpPanel The panel contaning the FTP data.
*
* @throws IOException If an error occurs while performing the action.
*/
public final void ftp(Object dialog, Object ftpPanel)
throws IOException
{
final String host = getString(find(ftpPanel, "host"), "text");
final String login = getString(find(ftpPanel, "login"), "text");
final String password = getString(find(ftpPanel, "password"), "text");
final String path = getString(find(ftpPanel, "path"), "text");
final String filename = getString(find(ftpPanel, "filename"), "text");
if (host.length() <= 0)
{
alert("Please specify a host name.");
}
else if (login.length() <= 0)
{
alert("Please specify a login name.");
}
else if (filename.length() <= 0)
{
alert("Please specify a file name.");
}
else
{
_prefs.put("host", host);
_prefs.put("login", login);
_prefs.put("password", password);
_prefs.put("path", path);
savePrefs();
closeDialog(dialog);
final LifeFTP ftp =
new LifeFTP(this, host, login, password, path, filename,
new File(getString(find(ftpPanel, "file"), "text")));
ftp.start();
}
}
/**
* Preforms the MetaWeblog action.
*
* @param dialog The MetaWeblog dialog,
* @param mwPanel The panel contaning the MetaWeblog data.
*
* @throws IOException If an error occurs while performing the action.
*/
public final void metaWeblog(Object dialog, Object mwPanel)
throws IOException
{
final String host = getString(find(mwPanel, "host"), "text");
final String login = getString(find(mwPanel, "login"), "text");
final String password = getString(find(mwPanel, "password"), "text");
final String filename = getString(find(mwPanel, "filename"), "text");
final String blogID = getString(find(mwPanel, "blogid"), "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 (filename.length() <= 0)
{
alert("Please specify a file name.");
}
else if (blogID.length() <= 0)
{
alert("Please specify a blog ID.");
}
else
{
_prefs.put("mw-host", host);
_prefs.put("mw-login", login);
_prefs.put("mw-password", password);
_prefs.put("mw-id", blogID);
savePrefs();
closeDialog(dialog);
final LifeMediaObject mw =
new LifeMediaObject(this, host, blogID, login, password, filename,
String.valueOf(getProperty(find(mwPanel, "file"), "mtype")),
new File(getString(find(mwPanel, "file"), "text")));
mw.start();
}
}
/**
* 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.
*
* @param thr The exception.
*/
protected final void showException(Throwable thr)
{
final StringWriter writer = new StringWriter();
thr.printStackTrace(new PrintWriter(writer));
final String trace = writer.toString().replace('\r', ' ').replace('\t', ' ');
String thrclass = thr.getClass().getName();
thrclass = thrclass.substring(thrclass.lastIndexOf('.') + 1);
try
{
final Object dialog = parse("exception.xml");
setString(dialog, "text", thrclass);
setString(find(dialog, "message"), "text", thr.getMessage());
setString(find(dialog, "stacktrace"), "text", trace);
Toolkit.getDefaultToolkit().beep();
add(dialog);
requestFocus(find(dialog, "closebtn"));
}
catch (Exception e)
{
e.printStackTrace();
}
}
// Displays an alert.
private void alert(String message)
{
Toolkit.getDefaultToolkit().beep();
try
{
final Object alert = parse("alert.xml");
setString(find(alert, "message"), "text", message);
add(alert);
requestFocus(find(alert, "closebtn"));
}
catch (Exception e)
{
e.printStackTrace();
}
}
// Display the FTP dialog.
private void ftpDialog(String file)
{
try
{
final Object ftp = parse("ftp.xml");
setString(find(ftp, "file"), "text", file);
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, "password"), "text", _prefs.getProperty("password", ""));
add(ftp);
requestFocus(find(ftp, "host"));
}
catch (Exception e)
{
e.printStackTrace();
}
}
// Display the MetaWeblog dialog.
private void mwDialog(String file, String mimeType)
{
try
{
final Object mw = parse("metaweblog.xml");
setString(find(mw, "file"), "text", file);
putProperty(find(mw, "file"), "mtype", mimeType);
setString(find(mw, "filename"), "text", file.substring(file.lastIndexOf('\\') + 1));
setString(find(mw, "host"), "text", _prefs.getProperty("mw-host", ""));
setString(find(mw, "login"), "text", _prefs.getProperty("mw-login", "anonymous"));
setString(find(mw, "password"), "text", _prefs.getProperty("mw-password", ""));
setString(find(mw, "blogid"), "text", _prefs.getProperty("mw-id", ""));
add(mw);
requestFocus(find(mw, "host"));
}
catch (Exception e)
{
e.printStackTrace();
}
}
// Saves the properties.
private void savePrefs()
{
FileOutputStream out = null;
try
{
out = new FileOutputStream(PREFS);
_prefs.store(out, ReleaseInfo.getProject() + ' ' + ReleaseInfo.getVersion());
out.close();
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
if (out != null)
{
try
{
out.close();
}
catch (IOException ignore)
{
; // Do nothing
}
}
}
}
}

View file

@ -0,0 +1,145 @@
/*
* @(#)LifeFTP.java
*
* Copyright (c) 2004, Erik C. Thauvin (http://www.thauvin.net/erik/)
* All rights reserved.
*
* 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 org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
/**
* The <code>LifeFTP</code> class stores/uploads a file to a FTP server.
*
* @author Erik C. Thauvin
* @version $Revision$, $Date$
*
* @created Jul 20, 2004
* @since 1.0
*/
public class LifeFTP extends LifeBlog
{
/**
* Creates a new LifeFTP object.
*
* @param thinlet The Thinlet object.
* @param host The FTP host.
* @param login The FTP login username.
* @param password The FTP login password.
* @param path The FTP path to upload to.
* @param filename The name of the file to upload.
* @param file The file to upload.
*
* @throws IOException If an error occurs while creating the object.
*/
public LifeFTP(LifeBlogger thinlet, String host, String login, String password, String path, String filename,
File file)
throws IOException
{
super(thinlet, host, login, password, path, filename, file);
}
/**
* Performs the FTP transfer.
*
* @see Thread#run()
*/
public final void run()
{
boolean success = false;
try
{
getThinlet().add(getDialog());
final FTPClient ftp = new FTPClient();
ftp.connect(getHost());
ftp.login(getLogin(), getPassword());
success = FTPReply.isPositiveCompletion(ftp.getReplyCode());
if (!success)
{
alert("Invalid login and/or password.");
}
else
{
if (getPath().length() > 0)
{
ftp.changeWorkingDirectory(getPath());
success = FTPReply.isPositiveCompletion(ftp.getReplyCode());
if (!success)
{
alert("Could not access specified path.");
}
}
if (success)
{
final BufferedInputStream bis = new BufferedInputStream(new FileInputStream(getFile()));
ftp.storeFile(getFilename(), bis);
bis.close();
success = FTPReply.isPositiveCompletion(ftp.getReplyCode());
if (!success)
{
alert("An error occurred: " + ftp.getReplyString());
}
else
{
getThinlet().closeDialog(getDialog());
}
}
}
ftp.disconnect();
}
catch (IOException e)
{
getThinlet().closeDialog(getDialog());
getThinlet().showException(e);
}
}
}

View file

@ -0,0 +1,135 @@
/*
* @(#)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);
_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);
final Object member = getDOMNode(struct, "member", 0);
final Object error = getDOMNode(member, "value", 0);
final Object string = getDOMNode(error, "string", 0);
_response = getDOMText(string);
return false;
}
}
catch (IOException e)
{
throw e;
}
finally
{
try
{
_inputStream.close();
}
catch (IOException ignore)
{
; // Do nothing
}
}
}
}

View file

@ -0,0 +1,216 @@
/*
* @(#)LifeMediaObject.java
*
* Copyright (c) 2004, Erik C. Thauvin (http://www.thauvin.net/erik/)
* All rights reserved.
*
* 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 java.awt.*;
import java.awt.datatransfer.StringSelection;
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
/**
* The <code>LifeMediaObject</code> class posts a new media object via the metaWeblog.newMediaObject XML-RPC call.
*
* @author Erik C. Thauvin
* @version $Revision$, $Date$
*
* @created Jul 21, 2004
* @since 1.0
*/
public class LifeMediaObject extends LifeBlog
{
private final String _blogID;
private final String _mimeType;
/**
* Creates a new LifeMediaObject object.
*
* @param thinlet The Thinlet instance.
* @param url The MetaWeblog XML-RPC URL.
* @param blogID The blog ID.
* @param login The MetaWeblog login username.
* @param password The MetaWeblog login password.
* @param filename The name of the object to store.
* @param mimeType The object's MIME type.
* @param file The file to store.
*
* @throws IOException If an error occurs while creating the object.
*/
public LifeMediaObject(LifeBlogger thinlet, String url, String blogID, String login, String password,
String filename, String mimeType, File file)
throws IOException
{
super(thinlet, url, login, password, "", filename, file);
_mimeType = mimeType;
_blogID = blogID;
}
/**
* Performs the action.
*
* @see Thread#run()
*/
public final void run()
{
FileInputStream fis = null;
final BufferedReader input = null;
try
{
getThinlet().add(getDialog());
final URL url = new URL(getHost());
if (!"http".equalsIgnoreCase(url.getProtocol()))
{
throw new IOException("Unsupported URL protocol: " + url.getProtocol());
}
// The following is a little hackish.
// A better way would be to generate the request to a temporary file.
final long len = getFile().length();
if (len > Integer.MAX_VALUE)
{
throw new IOException("Sorry. The file is too large.");
}
fis = new FileInputStream(getFile());
final byte[] bytes = new byte[(int) getFile().length()];
int offset = 0;
int numRead = 0;
while ((offset < bytes.length) && ((numRead = fis.read(bytes, offset, bytes.length - offset)) >= 0))
{
offset += numRead;
}
if (offset < bytes.length)
{
throw new IOException("Could not completely read file: " + getFile().getName());
}
final StringBuffer start =
new StringBuffer("<?xml version=\"1.0\"?><methodCall><methodName>metaWeblog.newMediaObject</methodName><params><param><value><string>").append(_blogID)
.append("</string></value></param><param><value><string>")
.append(getLogin())
.append("</string></value></param><param><value><string>")
.append(getPassword())
.append("</string></value></param><param><value><struct><member><name>bits</name><value><base64>");
final String bits = Base64.encodeBytes(bytes);
final StringBuffer end =
new StringBuffer("</base64></value></member><member><name>name</name><value><string>").append(getFilename())
.append("</string></value></member><member><name>type</name><value><string>")
.append(_mimeType)
.append("</string></value></member></struct></value></param></params></methodCall>");
final URLConnection urlConn = url.openConnection();
urlConn.setDoInput(true);
urlConn.setDoOutput(true);
urlConn.setUseCaches(false);
urlConn.setRequestProperty("Content-Length", String.valueOf(start.length() + bits.length() + end.length()));
urlConn.setRequestProperty("Content-Type", "text/xml");
final DataOutputStream output = new DataOutputStream(urlConn.getOutputStream());
output.write(start.toString().getBytes());
output.flush();
output.write(bits.getBytes());
output.flush();
output.write(end.toString().getBytes());
output.flush();
output.close();
final LifeMediaObjResponse xmlrpc = new LifeMediaObjResponse(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);
}
else
{
alert(xmlrpc.getResponse());
}
}
catch (IOException e)
{
getThinlet().closeDialog(getDialog());
getThinlet().showException(e);
}
finally
{
if (input != null)
{
try
{
input.close();
}
catch (IOException e)
{
; // Do nothing
}
}
if (fis != null)
{
try
{
fis.close();
}
catch (IOException ignore)
{
; // Do nothing
}
}
}
}
}

View file

@ -0,0 +1,51 @@
/* Created by JReleaseInfo AntTask from Open Source Competence Group */
/* Creation date Thu Jul 22 04:13:17 PDT 2004 */
package net.thauvin.lifeblogger;
import java.util.Date;
/**
* This class provides information gathered from the build environment.
*
* @author JReleaseInfo AntTask
*/
public class ReleaseInfo {
/** buildDate (set during build process to 1090494797296L). */
private static Date buildDate = new Date(1090494797296L);
/**
* Get buildDate (set during build process to Thu Jul 22 04:13:17 PDT 2004).
* @return Date buildDate
*/
public static final Date getBuildDate() { return buildDate; }
/**
* Get buildNumber (set during build process to 77).
* @return int buildNumber
*/
public static final int getBuildNumber() { return 77; }
/** version (set during build process to "0.1.0"). */
private static String version = new String("0.1.0");
/**
* Get version (set during build process to "0.1.0").
* @return String version
*/
public static final String getVersion() { return version; }
/** project (set during build process to "LifeBlogger"). */
private static String project = new String("LifeBlogger");
/**
* Get project (set during build process to "LifeBlogger").
* @return String project
*/
public static final String getProject() { return project; }
}

View file

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<dialog name="dialog" icon="/icon/info.gif" text="About" modal="true"
columns="1" top="8" left="8" bottom="8" right="8" gap="8">
<label alignment="center" weightx="1" background="#FFFFFF" foreground="#FFFFFF" icon="/icon/logo.gif"/>
<panel top="4" columns="1" left="8" bottom="0" gap="0" right="8">
<label alignment="left" weightx="1" text="Written by Erik C. Thauvin"/>
</panel>
<panel top="0" columns="1" left="8" bottom="0" gap="0" right="8">
<label alignment="left" weightx="1" text="Based on a concept developed by:"/>
</panel>
<panel top="0" columns="1" left="32" bottom="0" gap="0" right="8">
<label alignment="left" weightx="1" text="Russell Beattie"/>
<label alignment="left" weightx="1" text="Matt Croydon"/>
<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"/>
</panel>
<panel top="0" columns="1" left="8" bottom="4" gap="0" right="8">
<label alignment="center" weightx="1" icon="/icon/thinlet.gif"/>
</panel>
<separator/>
<panel top="0" columns="1" left="8" bottom="0" right="8" gap="0" halign="center">
<label name="version" alignment="center"/>
<label name="date" alignment="center"/>
</panel>
<button text="Close" halign="center" action="closeDialog(dialog)"/>
</dialog>

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<dialog name="alert" icon="/icon/help.gif" text="Error Message" modal="true" columns="2" top="8" left="8" bottom="8" right="8" gap="8">
<label icon="/icon/error.gif" valign="top"/>
<textarea wrap="true" editable="false" border="false" name="message" columns="45" rows="4" start="-1" end="-1"/>
<button text="Close" colspan="2" halign="center" action="closeDialog(alert)"/>
</dialog>

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<dialog name="exception" icon="/icon/help.gif" modal="true"
columns="1" top="8" left="8" bottom="8" right="8" gap="8">
<label name="message"/>
<textarea name="stacktrace" editable="false" width="300" height="150" weightx="1" weighty="1"/>
<button name="closebtn" text="Close" halign="center" action="closeDialog(exception)"/>
</dialog>

View file

@ -0,0 +1,15 @@
<?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">
<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"/>
<label text="Login:"/><textfield name="login"/>
<label text="Password:"/><passwordfield name="password"/>
<label text="Path:"/><textfield name="path"/>
<label text="Filename:"/><textfield name="filename"/>
</panel>
<panel columns="2" halign="right" gap="4">
<button name="cancelbtn" text="Cancel" icon="/icon/exit.gif" action="closeDialog(dialog)"/>
<button name="sendbtn" text="Send" icon="/icon/go.gif" action="ftp(dialog, ftp)"/>
</panel>
</dialog>

View file

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<panel name="mainpanel" columns="1">
<menubar weightx="1">
<menu text="File" mnemonic="0">
<menuitem text="Exit" action="exit()" icon="/icon/exit.gif" mnemonic="1"/>
</menu>
<menu text="Blog" mnemonic="0">
<checkboxmenuitem name="ftp" text="Via FTP" group="via" mnemonic="4" action="setAction(this.name)"/>
<checkboxmenuitem name="mv" text="Via MetaWeblog" group="via" mnemonic="4" action="setAction(this.name)"/>
</menu>
<menu text="Help" mnemonic="0">
<menuitem text="About" action="about()" icon="/icon/about.gif" mnemonic="0"/>
</menu>
</menubar>
<panel gap="4" top="3" left="3" bottom="3" right="3" columns="1" weighty="1">
<table name="table" weightx="1" weighty="1" init="addTableRows(thinlet, table, btns)" action="toggleButton(this, blogbtn)">
<header>
<column text="Name" width="270"/>
<column text="Date"/>
</header>
</table>
<panel name="btns" gap="4" halign="right" colspan="2" weightx="1">
<label name="favslbl"/>
<button name="refreshbtn" text="Refresh" icon="/icon/refresh.gif" action="updateTable(thinlet, table, btns)"/>
<button name="blogbtn" text="Blog" icon="/icon/go.gif" enabled="false" action="blog(table)"/>
</panel>
</panel>
</panel>

View file

@ -0,0 +1,15 @@
<?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">
<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="Blog ID:"/><textfield name="blogid"/>
<label text="Login:"/><textfield name="login"/>
<label text="Password:"/><passwordfield name="password"/>
<label text="Filename:"/><textfield name="filename"/>
</panel>
<panel columns="2" halign="right" gap="4">
<button name="cancelbtn" text="Cancel" icon="/icon/exit.gif" action="closeDialog(dialog)"/>
<button name="sendbtn" text="Send" icon="/icon/go.gif" action="metaWeblog(dialog, mw)"/>
</panel>
</dialog>

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<dialog name="transfer" icon="/icon/help.gif" text="Uploading..." modal="true" columns="2" top="8" left="8" bottom="8" right="8" gap="8">
<label name="iconlbl" icon="/icon/wait.gif" valign="top"/>
<textarea wrap="true" editable="false" border="false" name="message" columns="45" rows="4" text="Uploading... Please wait..." start="-1" end="-1"/>
<button name="closebtn" text="Close" colspan="2" halign="center" action="closeDialog(transfer)" enabled="false"/>
</dialog>