//# 0 errors, 119 messages
//#
/*
    //#newmediaobjecttask.java:1:1: class: net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask
    //#newmediaobjecttask.java:1:1: method: net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask.net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask__static_init
 * Copyright (c) 2003-2005, Simon Brown
 * 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 Pebble 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.
 */
package net.sourceforge.pebble.ant.metaweblog;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Hashtable;
import java.util.Vector;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.apache.xmlrpc.XmlRpcClient;

/**
 * Ant task to post a file to a blog via the MetaWeblog API.
 *
 * @author    Simon Brown
 */
public class NewMediaObjectTask extends Task {
    //#newmediaobjecttask.java:49: method: void net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask.net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask()
    //#newmediaobjecttask.java:49: Warning: method not available
    //#    -- call on void org.apache.tools.ant.Task()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask
    //#    method: void net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask()
    //#    unanalyzed callee: void org.apache.tools.ant.Task()
    //#input(void net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask()): this
    //#output(void net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask()): this.handler
    //#post(void net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask()): this.handler == &"metaWeblog"

  private String blogid;
  private String username;
  private String password;
  private String src;
  private String dest;
  private String url;
  private String handler = "metaWeblog";
    //#newmediaobjecttask.java:57: end of method: void net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask.net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask()

  /**
   * Performs the work of this task.
   *
   * @throws org.apache.tools.ant.BuildException   if something goes wrong
   */
  public void execute() throws BuildException {

    try {
      System.out.println("Calling " + handler + ".newMediaObject at " + url);
    //#newmediaobjecttask.java:67: method: void net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask.execute()
    //#input(void execute()): java.lang.System.out
    //#input(void execute()): this
    //#input(void execute()): this.blogid
    //#input(void execute()): this.dest
    //#input(void execute()): this.handler
    //#input(void execute()): this.password
    //#input(void execute()): this.src
    //#input(void execute()): this.url
    //#input(void execute()): this.username
    //#pre[2] (void execute()): init'ed(this.blogid)
    //#pre[3] (void execute()): init'ed(this.dest)
    //#pre[4] (void execute()): init'ed(this.handler)
    //#pre[5] (void execute()): init'ed(this.password)
    //#pre[6] (void execute()): init'ed(this.src)
    //#pre[7] (void execute()): init'ed(this.url)
    //#pre[8] (void execute()): init'ed(this.username)
    //#presumption(void execute()): java.lang.System.out != null
    //#presumption(void execute()): org.apache.xmlrpc.XmlRpcClient:execute(...)@87 != null
    //#unanalyzed(void execute()): Effects-of-calling:java.io.File
    //#unanalyzed(void execute()): Effects-of-calling:java.io.FileInputStream
    //#unanalyzed(void execute()): Effects-of-calling:java.io.File:length
    //#unanalyzed(void execute()): Effects-of-calling:java.io.InputStream:read
    //#unanalyzed(void execute()): Effects-of-calling:java.io.InputStream:close
      System.out.println(" blogid=" + blogid);
      System.out.println(" username=" + username);
      System.out.println(" password=********");
      System.out.println(" name=" + dest);
      System.out.println(" type=" + "");

      XmlRpcClient xmlrpc = new XmlRpcClient(url);
    //#newmediaobjecttask.java:74: Warning: method not available
    //#    -- call on void org.apache.xmlrpc.XmlRpcClient(String)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask
    //#    method: void execute()
    //#    unanalyzed callee: void org.apache.xmlrpc.XmlRpcClient(String)
      Vector params = new Vector();
      params.add(blogid);
      params.add(username);
      params.add(password);

      Hashtable struct = new Hashtable();
      struct.put("name", dest);
      struct.put("type", "");
      struct.put("bits", readFile());

      params.add(struct);

      struct = (Hashtable)xmlrpc.execute(handler + ".newMediaObject", params);
    //#newmediaobjecttask.java:87: Warning: method not available
    //#    -- call on Object org.apache.xmlrpc.XmlRpcClient:execute(String, Vector)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask
    //#    method: void execute()
    //#    unanalyzed callee: Object org.apache.xmlrpc.XmlRpcClient:execute(String, Vector)

      System.out.println("URL for media object is " + struct.get("url"));

    } catch (Exception e) {
      throw new BuildException(e);
    }
  }
    //#newmediaobjecttask.java:94: end of method: void net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask.execute()

  private byte[] readFile() throws Exception {
    byte bytes[];
    File file = new File(src);
    //#newmediaobjecttask.java:98: method: byte[] net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask.readFile()
    //#input(byte[] readFile()): this
    //#input(byte[] readFile()): this.src
    //#output(byte[] readFile()): new byte[](readFile#3) num objects
    //#output(byte[] readFile()): return_value.length
    //#output(byte[] readFile()): return_value
    //#new obj(byte[] readFile()): new byte[](readFile#3)
    //#pre[2] (byte[] readFile()): init'ed(this.src)
    //#presumption(byte[] readFile()): java.io.File:length(...)@100 >= 0
    //#post(byte[] readFile()): return_value == &new byte[](readFile#3)
    //#post(byte[] readFile()): new byte[](readFile#3) num objects == 1
    //#post(byte[] readFile()): (soft) return_value.length <= 18_446_744_073_709_551_615
    InputStream in = new FileInputStream(src);
    bytes = new byte[(int)file.length()];
    in.read(bytes);
    in.close();

    return bytes;
    //#newmediaobjecttask.java:104: end of method: byte[] net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask.readFile()
  }

  /**
   * Sets the blog id.
   *
   * @param blogid    a String
   */
  public void setBlogid(String blogid) {
    this.blogid = blogid;
    //#newmediaobjecttask.java:113: method: void net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask.setBlogid(String)
    //#input(void setBlogid(String)): blogid
    //#input(void setBlogid(String)): this
    //#output(void setBlogid(String)): this.blogid
    //#post(void setBlogid(String)): this.blogid == blogid
    //#post(void setBlogid(String)): init'ed(this.blogid)
  }
    //#newmediaobjecttask.java:114: end of method: void net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask.setBlogid(String)

  /**
   * Sets the XML-RPC username.
   *
   * @param username    a String
   */
  public void setUsername(String username) {
    this.username = username;
    //#newmediaobjecttask.java:122: method: void net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask.setUsername(String)
    //#input(void setUsername(String)): this
    //#input(void setUsername(String)): username
    //#output(void setUsername(String)): this.username
    //#post(void setUsername(String)): this.username == username
    //#post(void setUsername(String)): init'ed(this.username)
  }
    //#newmediaobjecttask.java:123: end of method: void net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask.setUsername(String)

  /**
   * Sets the XML-RPC password.
   *
   * @param password    a String
   */
  public void setPassword(String password) {
    this.password = password;
    //#newmediaobjecttask.java:131: method: void net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask.setPassword(String)
    //#input(void setPassword(String)): password
    //#input(void setPassword(String)): this
    //#output(void setPassword(String)): this.password
    //#post(void setPassword(String)): this.password == password
    //#post(void setPassword(String)): init'ed(this.password)
  }
    //#newmediaobjecttask.java:132: end of method: void net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask.setPassword(String)

  /**
   * Sets the URL of the XML-RPC call.
   *
   * @param url   the URL as a String
   */
  public void setUrl(String url) {
    this.url = url;
    //#newmediaobjecttask.java:140: method: void net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask.setUrl(String)
    //#input(void setUrl(String)): this
    //#input(void setUrl(String)): url
    //#output(void setUrl(String)): this.url
    //#post(void setUrl(String)): this.url == url
    //#post(void setUrl(String)): init'ed(this.url)
  }
    //#newmediaobjecttask.java:141: end of method: void net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask.setUrl(String)

  /**
   * Sets the name of the XML-RPC Blogger API handler (e.g. "blogger").
   *
   * @param handler   the name of the handler as a String
   */
  public void setHandler(String handler) {
    this.handler = handler;
    //#newmediaobjecttask.java:149: method: void net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask.setHandler(String)
    //#input(void setHandler(String)): handler
    //#input(void setHandler(String)): this
    //#output(void setHandler(String)): this.handler
    //#post(void setHandler(String)): this.handler == handler
    //#post(void setHandler(String)): init'ed(this.handler)
  }
    //#newmediaobjecttask.java:150: end of method: void net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask.setHandler(String)

  /**
   * Sets the source file.
   *
   * @param src   the source as a String
   */
  public void setSrc(String src) {
    this.src = src;
    //#newmediaobjecttask.java:158: method: void net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask.setSrc(String)
    //#input(void setSrc(String)): src
    //#input(void setSrc(String)): this
    //#output(void setSrc(String)): this.src
    //#post(void setSrc(String)): this.src == src
    //#post(void setSrc(String)): init'ed(this.src)
  }
    //#newmediaobjecttask.java:159: end of method: void net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask.setSrc(String)

  /**
   * Sets the destination file.
   *
   * @param dest   the destination as a String
   */
  public void setDest(String dest) {
    this.dest = dest;
    //#newmediaobjecttask.java:167: method: void net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask.setDest(String)
    //#input(void setDest(String)): dest
    //#input(void setDest(String)): this
    //#output(void setDest(String)): this.dest
    //#post(void setDest(String)): this.dest == dest
    //#post(void setDest(String)): init'ed(this.dest)
  }
    //#newmediaobjecttask.java:168: end of method: void net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask.setDest(String)

}
    //#output(net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask__static_init): __Descendant_Table[net/sourceforge/pebble/ant/metaweblog/NewMediaObjectTask]
    //#output(net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask__static_init): __Dispatch_Table.execute()V
    //#output(net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask__static_init): __Dispatch_Table.readFile()[B
    //#output(net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask__static_init): __Dispatch_Table.setBlogid(Ljava/lang/String;)V
    //#output(net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask__static_init): __Dispatch_Table.setDest(Ljava/lang/String;)V
    //#output(net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask__static_init): __Dispatch_Table.setHandler(Ljava/lang/String;)V
    //#output(net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask__static_init): __Dispatch_Table.setPassword(Ljava/lang/String;)V
    //#output(net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask__static_init): __Dispatch_Table.setSrc(Ljava/lang/String;)V
    //#output(net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask__static_init): __Dispatch_Table.setUrl(Ljava/lang/String;)V
    //#output(net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask__static_init): __Dispatch_Table.setUsername(Ljava/lang/String;)V
    //#post(net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask__static_init): __Descendant_Table[net/sourceforge/pebble/ant/metaweblog/NewMediaObjectTask] == &__Dispatch_Table
    //#post(net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask__static_init): __Dispatch_Table.execute()V == &execute
    //#post(net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask__static_init): __Dispatch_Table.readFile()[B == &readFile
    //#post(net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask__static_init): __Dispatch_Table.setBlogid(Ljava/lang/String;)V == &setBlogid
    //#post(net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask__static_init): __Dispatch_Table.setDest(Ljava/lang/String;)V == &setDest
    //#post(net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask__static_init): __Dispatch_Table.setHandler(Ljava/lang/String;)V == &setHandler
    //#post(net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask__static_init): __Dispatch_Table.setPassword(Ljava/lang/String;)V == &setPassword
    //#post(net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask__static_init): __Dispatch_Table.setSrc(Ljava/lang/String;)V == &setSrc
    //#post(net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask__static_init): __Dispatch_Table.setUrl(Ljava/lang/String;)V == &setUrl
    //#post(net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask__static_init): __Dispatch_Table.setUsername(Ljava/lang/String;)V == &setUsername
    //#newmediaobjecttask.java:: end of method: net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask.net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask__static_init
    //#newmediaobjecttask.java:: end of class: net.sourceforge.pebble.ant.metaweblog.NewMediaObjectTask
