/**
  * adds a parameter to the request; if the parameter is a File, the file is uploaded, otherwise
  * the string value of the parameter is passed in the request
  *
  * @param name parameter name
  * @param object parameter value, a File or anything else that can be stringified
  * @throws IOException
  */
 public void setParameter(String name, Object object) throws IOException {
   if (object instanceof File) {
     setParameter(name, (File) object);
   } else {
     setParameter(name, object.toString());
   }
 }
 /**
  * adds parameters to the request
  *
  * @param parameters "name-to-value" map of parameters; if a value is a file, the file is
  *     uploaded, otherwise it is stringified and sent in the request
  * @throws IOException
  */
 public void setParameters(Map parameters) throws IOException {
   if (parameters == null) return;
   for (Iterator i = parameters.entrySet().iterator(); i.hasNext(); ) {
     Map.Entry entry = (Map.Entry) i.next();
     setParameter(entry.getKey().toString(), entry.getValue());
   }
 }
  /**
   * This method will execute an update to the Sound Library. What this means is that it will do two
   * things. The first thing it will do is upload the file described to the library folder. Next, it
   * will execute an update to the SQl database with the information given. Becuase all of the
   * fields must be filled out, it will throw an exception if any of them are left blank.
   *
   * <p>Once it executes the update, it will read the response from the server and will return a
   * boolean value based on the response. A sucess will return a true and a failure will return a
   * false.
   *
   * @return Success or Failure
   * @throws java.lang.Exception
   */
  public boolean executeUpload() throws Exception {

    // Create a new ClientHTTPRequest
    ClientHttpRequest post = new ClientHttpRequest(page_url);

    // Set the parameters needed to update
    post.setParameter("FileName", new File(file_path));
    post.setParameter("Title", title);
    post.setParameter("Author", author);
    post.setParameter("Genre", genre);
    post.setParameter("Tags", tags);

    // Post the request and read in the response stream
    InputStream response_stream = post.post();

    // XML processing code modified from example at:
    // http://java.sun.com/developer/technicalArticles/xml/JavaTechandXML/
    // Get a new DocumentBuilder
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    // Parse the xml returned by the server
    try {
      reply = builder.parse(response_stream);
    } catch (Exception e) {
      // Pass it on up!
      throw e;
    }
    // Get our list of errors. Hopefully 0 elements
    NodeList errors = reply.getElementsByTagName("Error");
    // NodeList warnings = reply.getElementsByTagName( "Warning" );
    // get our list of successes. Hopefully 1
    NodeList successes = reply.getElementsByTagName("Success");

    // If there were successes, return true
    if (successes.getLength() > 0) response = true;
    // otherwise, return false. I didn't use an if-else statement because
    // although there should never be a success AND a failure, I want to be
    // able to handle it just in case.
    if (errors.getLength() > 0) response = false;

    // Finally, return the response
    return (response);
  }
 /**
  * post the POST request to the server, with the specified parameters
  *
  * @param name1 first parameter name
  * @param value1 first parameter value
  * @param name2 second parameter name
  * @param value2 second parameter value
  * @param name3 third parameter name
  * @param value3 third parameter value
  * @param name4 fourth parameter name
  * @param value4 fourth parameter value
  * @return input stream with the server response
  * @throws IOException
  * @see setParameter
  */
 public InputStream post(
     String name1,
     Object value1,
     String name2,
     Object value2,
     String name3,
     Object value3,
     String name4,
     Object value4)
     throws IOException {
   setParameter(name1, value1);
   return post(name2, value2, name3, value3, name4, value4);
 }
 /**
  * post the POST request to the server, with the specified parameter
  *
  * @param name parameter name
  * @param value parameter value
  * @return input stream with the server response
  * @throws IOException
  * @see setParameter
  */
 public InputStream post(String name, Object value) throws IOException {
   setParameter(name, value);
   return post();
 }
 /**
  * adds parameters to the request
  *
  * @param parameters array of parameter names and values (parameters[2*i] is a name,
  *     parameters[2*i + 1] is a value); if a value is a file, the file is uploaded, otherwise it
  *     is stringified and sent in the request
  * @throws IOException
  */
 public void setParameters(Object[] parameters) throws IOException {
   if (parameters == null) return;
   for (int i = 0; i < parameters.length - 1; i += 2) {
     setParameter(parameters[i].toString(), parameters[i + 1]);
   }
 }
 /**
  * adds a file parameter to the request
  *
  * @param name parameter name
  * @param file the file to upload
  * @throws IOException
  */
 public void setParameter(String name, File file) throws IOException {
   setParameter(name, file.getPath(), new FileInputStream(file));
 }