newposttask.java

### File Source: newposttask.java

             /*
        P/P   *  Method: net.sourceforge.pebble.ant.metaweblog.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.metaweblog;
        33
        34  import java.util.Hashtable;
        35  import java.util.StringTokenizer;
        36  import java.util.Vector;
        37
        38  import org.apache.tools.ant.BuildException;
        39  import org.apache.tools.ant.Task;
        40  import org.apache.xmlrpc.XmlRpcClient;
        41
        42  /**
        43   * Ant task to post to a blog via the MetaWeblog API.
        44   *
        45   * @author    Simon Brown
        46   */
             /*
        P/P   *  Method: void net.sourceforge.pebble.ant.metaweblog.NewPostTask()
              *
              *  Postconditions:
              *    this.handler == &"metaWeblog"
              */
        47  public class NewPostTask extends 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 = "metaWeblog";
        57
        58    /**
        59     * Performs the work of this task.
        60     *
        61     * @throws org.apache.tools.ant.BuildException   if something goes wrong
        62     */
        63    public void execute() throws BuildException {
        64
        65      try {
                   /*
        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
                    *    java.util.StringTokenizer:nextToken(...)@88 != null
                    *
                    *  Test Vectors:
                    *    this.category: Addr_Set{null}, Inverse{null}
                    *    java.util.StringTokenizer:hasMoreTokens(...)@87: {1}, {0}
                    */
        66        System.out.println("Calling " + handler + ".newPost at " + url);
        67        System.out.println(" blogid=" + blogid);
        68        System.out.println(" username=" + username);
        69        System.out.println(" password=********");
        70        System.out.println(" title=" + title);
        71        System.out.println(" content=" + content);
        72        System.out.println(" category=" + category);
        73        System.out.println(" publish=true");
        74
        75        XmlRpcClient xmlrpc = new XmlRpcClient(url);
        76        Vector params = new Vector();
        77        params.add(blogid);
        78        params.add(username);
        79        params.add(password);
        80
        81        Hashtable struct = new Hashtable();
        82        struct.put("title", title);
        83        struct.put("description", content);
        84        Vector categories = new Vector();
        85        if (category != null) {
        86          StringTokenizer tok = new StringTokenizer(category, ",");
        87          while (tok.hasMoreTokens()) {
        88            categories.add(tok.nextToken().trim());
        89          }
        90        }
        91        struct.put("categories", categories);
        92
        93        params.add(struct);
        94        params.add(Boolean.TRUE);
        95        Object postId = xmlrpc.execute(handler + ".newPost", params);
        96
        97        System.out.println("New post id is " + postId);
        98
        99      } catch (Exception e) {
       100        throw new BuildException(e);
       101      }
       102    }
       103
       104    /**
       105     * Sets the blog id.
       106     *
       107     * @param blogid    a String
       108     */
       109    public void setBlogid(String blogid) {
                 /*
        P/P       *  Method: void setBlogid(String)
                  *
                  *  Postconditions:
                  *    this.blogid == blogid
                  *    init'ed(this.blogid)
                  */
       110      this.blogid = blogid;
       111    }
       112
       113    /**
       114     * Sets the XML-RPC username.
       115     *
       116     * @param username    a String
       117     */
       118    public void setUsername(String username) {
                 /*
        P/P       *  Method: void setUsername(String)
                  *
                  *  Postconditions:
                  *    this.username == username
                  *    init'ed(this.username)
                  */
       119      this.username = username;
       120    }
       121
       122    /**
       123     * Sets the XML-RPC password.
       124     *
       125     * @param password    a String
       126     */
       127    public void setPassword(String password) {
                 /*
        P/P       *  Method: void setPassword(String)
                  *
                  *  Postconditions:
                  *    this.password == password
                  *    init'ed(this.password)
                  */
       128      this.password = password;
       129    }
       130
       131    /**
       132     * Sets the title of the blog entry.
       133     *
       134     * @param title   the blog entry title
       135     */
       136    public void setTitle(String title) {
                 /*
        P/P       *  Method: void setTitle(String)
                  *
                  *  Postconditions:
                  *    this.title == title
                  *    init'ed(this.title)
                  */
       137      this.title = title;
       138    }
       139
       140    /**
       141     * Sets the blog entry content.
       142     *
       143     * @param content   the blog entry content
       144     */
       145    public void setContent(String content) {
                 /*
        P/P       *  Method: void setContent(String)
                  *
                  *  Postconditions:
                  *    this.content == content
                  *    init'ed(this.content)
                  */
       146      this.content = content;
       147    }
       148
       149    /**
       150     * Sets the category to which the blog entry should be added to.
       151     *
       152     * @param category    the category ID as a String
       153     */
       154    public void setCategory(String category) {
                 /*
        P/P       *  Method: void setCategory(String)
                  *
                  *  Postconditions:
                  *    this.category == category
                  *    init'ed(this.category)
                  */
       155      this.category = category;
       156    }
       157
       158    /**
       159     * Sets the URL of the XML-RPC call.
       160     *
       161     * @param url   the URL as a String
       162     */
       163    public void setUrl(String url) {
                 /*
        P/P       *  Method: void setUrl(String)
                  *
                  *  Postconditions:
                  *    this.url == url
                  *    init'ed(this.url)
                  */
       164      this.url = url;
       165    }
       166
       167    /**
       168     * Sets the name of the XML-RPC Blogger API handler (e.g. "blogger").
       169     *
       170     * @param handler   the name of the handler as a String
       171     */
       172    public void setHandler(String handler) {
                 /*
        P/P       *  Method: void setHandler(String)
                  *
                  *  Postconditions:
                  *    this.handler == handler
                  *    init'ed(this.handler)
                  */
       173      this.handler = handler;
       174    }
       175
       176  }

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