newposttask.java

### File Source: newposttask.java

             /*
        P/P   *  Method: net.sourceforge.pebble.ant.blogger.NewPostTask__static_init
              */
         1  /*
         2   * Copyright (c) 2003-2005, Simon Brown
         3   * All rights reserved.
         4   *
         5   * Redistribution and use in source and binary forms, with or without
         6   * modification, are permitted provided that the following conditions are met:
         7   *
         8   *   - Redistributions of source code must retain the above copyright
         9   *     notice, this list of conditions and the following disclaimer.
        10   *
        11   *   - Redistributions in binary form must reproduce the above copyright
        12   *     notice, this list of conditions and the following disclaimer in
        13   *     the documentation and/or other materials provided with the
        14   *     distribution.
        15   *
        16   *   - Neither the name of Pebble nor the names of its contributors may
        17   *     be used to endorse or promote products derived from this software
        18   *     without specific prior written permission.
        19   *
        20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
        21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
        23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
        24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
        25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
        26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
        27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
        28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
        29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
        30   * POSSIBILITY OF SUCH DAMAGE.
        31   */
        32  package net.sourceforge.pebble.ant.blogger;
        33
        34  import java.util.Vector;
        35
        36  import org.apache.tools.ant.BuildException;
        37  import org.apache.tools.ant.Task;
        38  import org.apache.xmlrpc.XmlRpcClient;
        39
        40  /**
        41   * Ant task to post to a blog via the Blogger API.
        42   *
        43   * @author    Simon Brown
        44   */
             /*
        P/P   *  Method: void net.sourceforge.pebble.ant.blogger.NewPostTask()
              *
              *  Postconditions:
              *    this.handler == &"blogger"
              */
        45  public class NewPostTask extends Task {
        46
        47    private static final String APP_KEY = "Pebble Blogger API Ant Task";
        48
        49    private String blogid;
        50    private String username;
        51    private String password;
        52    private String title;
        53    private String content;
        54    private String category;
        55    private String url;
        56    private String handler = "blogger";
        57
        58    /**
        59     * Performs the work of this task.
        60     *
        61     * @throws BuildException   if something goes wrong
        62     */
        63    public void execute() throws BuildException {
        64
        65      // create the content
        66      //  - a <title> tag containing the title
        67      //  - a <category> tag containing a comma separated list of categories
        68      //  - the blog entry content
                 /*
        P/P       *  Method: void execute()
                  *
                  *  Preconditions:
                  *    init'ed(this.blogid)
                  *    init'ed(this.category)
                  *    init'ed(this.content)
                  *    init'ed(this.handler)
                  *    init'ed(this.password)
                  *    init'ed(this.title)
                  *    init'ed(this.url)
                  *    init'ed(this.username)
                  *
                  *  Presumptions:
                  *    init'ed(java.lang.Boolean.TRUE)
                  *    java.lang.System.out != null
                  *
                  *  Test Vectors:
                  *    this.category: Addr_Set{null}, Inverse{null}
                  *    this.title: Addr_Set{null}, Inverse{null}
                  *    java.lang.String:length(...)@70: {0}, {1..232-1}
                  *    java.lang.String:length(...)@75: {0}, {1..232-1}
                  */
        69      StringBuffer buf = new StringBuffer();
        70      if (title != null && title.length() > 0) {
        71        buf.append("<title>");
        72        buf.append(title);
        73        buf.append("</title>");
        74      }
        75      if (category != null && category.length() > 0) {
        76        buf.append("<category>");
        77        buf.append(category);
        78        buf.append("</category>");
        79      }
        80      buf.append(content);
        81
        82      try {
        83        System.out.println("Calling " + handler + ".newPost at " + url);
        84        System.out.println(" appkey=" + APP_KEY);
        85        System.out.println(" blogid=" + blogid);
        86        System.out.println(" username=" + username);
        87        System.out.println(" password=********");
        88        System.out.println(" content=" + buf.toString());
        89        System.out.println(" publish=true");
        90
        91        XmlRpcClient xmlrpc = new XmlRpcClient(url);
        92        Vector params = new Vector();
        93        params.add(APP_KEY);
        94        params.add(blogid);
        95        params.add(username);
        96        params.add(password);
        97        params.add(buf.toString());
        98        params.add(Boolean.TRUE);
        99        Object postId = xmlrpc.execute(handler + ".newPost", params);
       100
       101        System.out.println("New post id is " + postId);
       102
       103      } catch (Exception e) {
       104        throw new BuildException(e);
       105      }
       106    }
       107
       108    /**
       109     * Sets the blog id.
       110     *
       111     * @param blogid    a String
       112     */
       113    public void setBlogid(String blogid) {
                 /*
        P/P       *  Method: void setBlogid(String)
                  *
                  *  Postconditions:
                  *    this.blogid == blogid
                  *    init'ed(this.blogid)
                  */
       114      this.blogid = blogid;
       115    }
       116
       117    /**
       118     * Sets the XML-RPC username.
       119     *
       120     * @param username    a String
       121     */
       122    public void setUsername(String username) {
                 /*
        P/P       *  Method: void setUsername(String)
                  *
                  *  Postconditions:
                  *    this.username == username
                  *    init'ed(this.username)
                  */
       123      this.username = username;
       124    }
       125
       126    /**
       127     * Sets the XML-RPC password.
       128     *
       129     * @param password    a String
       130     */
       131    public void setPassword(String password) {
                 /*
        P/P       *  Method: void setPassword(String)
                  *
                  *  Postconditions:
                  *    this.password == password
                  *    init'ed(this.password)
                  */
       132      this.password = password;
       133    }
       134
       135    /**
       136     * Sets the title of the blog entry.
       137     *
       138     * @param title   the blog entry title
       139     */
       140    public void setTitle(String title) {
                 /*
        P/P       *  Method: void setTitle(String)
                  *
                  *  Postconditions:
                  *    this.title == title
                  *    init'ed(this.title)
                  */
       141      this.title = title;
       142    }
       143
       144    /**
       145     * Sets the blog entry content.
       146     *
       147     * @param content   the blog entry content
       148     */
       149    public void setContent(String content) {
                 /*
        P/P       *  Method: void setContent(String)
                  *
                  *  Postconditions:
                  *    this.content == content
                  *    init'ed(this.content)
                  */
       150      this.content = content;
       151    }
       152
       153    /**
       154     * Sets the category to which the blog entry should be added to.
       155     *
       156     * @param category    the category ID as a String
       157     */
       158    public void setCategory(String category) {
                 /*
        P/P       *  Method: void setCategory(String)
                  *
                  *  Postconditions:
                  *    this.category == category
                  *    init'ed(this.category)
                  */
       159      this.category = category;
       160    }
       161
       162    /**
       163     * Sets the URL of the XML-RPC call.
       164     *
       165     * @param url   the URL as a String
       166     */
       167    public void setUrl(String url) {
                 /*
        P/P       *  Method: void setUrl(String)
                  *
                  *  Postconditions:
                  *    this.url == url
                  *    init'ed(this.url)
                  */
       168      this.url = url;
       169    }
       170
       171    /**
       172     * Sets the name of the XML-RPC Blogger API handler (e.g. "blogger").
       173     *
       174     * @param handler   the name of the handler as a String
       175     */
       176    public void setHandler(String handler) {
                 /*
        P/P       *  Method: void setHandler(String)
                  *
                  *  Postconditions:
                  *    this.handler == handler
                  *    init'ed(this.handler)
                  */
       177      this.handler = handler;
       178    }
       179
       180  }

SofCheck Inspector Build Version : 2.22510

newposttask.java | 2010-Jun-25 19:40:32
newposttask.class | 2010-Jul-19 20:23:40
newposttask.class | 2010-Jul-16 19:33:52