/**
   * Parse the tmp file for tag data and create associated song
   *
   * @param dfi
   * @return song created from tag data
   */
  public static Song parseFileForSong(DiskFileItem dfi) { // TODO Think about where to move this.
    File audioFile = new File(dfi.getStoreLocation().toString().replace(".tmp", ".mp3"));
    //	"."+dfi.getContentType().substring(dfi.getContentType().indexOf("/")+1)));

    if (!dfi.getStoreLocation().renameTo(audioFile)) {
      log.error(
          "rename failed - store location:" + dfi.getStoreLocation() + ", audio file:" + audioFile);
    }

    AudioFile f = null;
    try {
      f = AudioFileIO.read(audioFile);
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    Tag tag = f.getTag();
    if (tag == null) {
      tag = f.getTagOrCreateAndSetDefault();
    }
    Song song = new Song();
    try {
      song.setArtist(tag.getFirst(FieldKey.ARTIST));
      song.setAlbum(tag.getFirst(FieldKey.ALBUM));
      song.setTitle(tag.getFirst(FieldKey.TITLE));
      song.setYear(tag.getFirst(FieldKey.YEAR));
      song.setTrack(tag.getFirst(FieldKey.TRACK));
      song.setFilename(dfi.getName());
    } catch (KeyNotFoundException knfe) {
      log.error("song key not found", knfe);
    }
    return song;
  }
  /*
   * (non-Javadoc)
   *
   * @see org.apache.struts2.dispatcher.multipart.MultiPartRequest#getFileNames(java.lang.String)
   */
  @Override
  public String[] getFileNames(String fieldName) {
    List<FileItem> items = files.get(fieldName);

    if (items == null) {
      return null;
    }

    List<String> fileNames = new ArrayList<String>(items.size());
    for (int i = 0; i < items.size(); i++) {
      DiskFileItem fileItem = (DiskFileItem) items.get(i);
      fileNames.add(getCanonicalName(fileItem.getName()));
    }

    return (String[]) fileNames.toArray(new String[fileNames.size()]);
  }
  public void fileUpload(
      CommandArgument argument, HttpServletRequest request, HttpServletResponse response) {

    ServletFileUpload upload =
        new ServletFileUpload(
            new LiferayFileItemFactory(UploadServletRequestImpl.DEFAULT_TEMP_DIR));

    List<FileItem> items = null;

    try {
      items = upload.parseRequest(request);
    } catch (FileUploadException fue) {
      throw new FCKException(fue);
    }

    Map<String, Object> fields = new HashMap<String, Object>();

    for (FileItem item : items) {
      if (item.isFormField()) {
        fields.put(item.getFieldName(), item.getString());
      } else {
        fields.put(item.getFieldName(), item);
      }
    }

    DiskFileItem fileItem = (DiskFileItem) fields.get("NewFile");

    String fileName = StringUtil.replace(fileItem.getName(), "\\", "/");
    String[] fileNameArray = StringUtil.split(fileName, "/");
    fileName = fileNameArray[fileNameArray.length - 1];

    String extension = _getExtension(fileName);

    String returnValue = null;

    try {
      returnValue = fileUpload(argument, fileName, fileItem.getStoreLocation(), extension);
    } catch (FCKException fcke) {
      Throwable cause = fcke.getCause();

      returnValue = "203";

      if (cause != null) {
        String causeString = GetterUtil.getString(cause.toString());

        if ((causeString.indexOf("NoSuchFolderException") != -1)
            || (causeString.indexOf("NoSuchGroupException") != -1)) {

          returnValue = "204";
        } else if (causeString.indexOf("ImageNameException") != -1) {
          returnValue = "205";
        } else if (causeString.indexOf("FileNameException") != -1) {
          returnValue = "206";
        } else if (causeString.indexOf("PrincipalException") != -1) {
          returnValue = "207";
        } else {
          throw fcke;
        }
      }

      _writeUploadResponse(returnValue, response);
    }

    _writeUploadResponse(returnValue, response);
  }