/** * 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); }