PathAndTagCleaner.java :  » Music » nemadiy » org » imirsel » nema » model » util » Java Open Source

Java Open Source » Music » nemadiy 
nemadiy » org » imirsel » nema » model » util » PathAndTagCleaner.java
package org.imirsel.nema.model.util;

import java.io.File;

/**
 * 
 * @author kris.west@gmail.com
 *
 */
public class PathAndTagCleaner {

  /**
   * 
   */
  private static String WINDOWS_PATH_REGEX = "[A-Z]:\\\\";
    
  /**
   * 
   * @param aFile
   * @return the file name cleaned up
   */
  public static String convertFileToMIREX_ID(File aFile){
        String name = aFile.getName();
        String cleanName;
        //detect windows paths
        if (name.substring(0,3).matches(WINDOWS_PATH_REGEX)){
            cleanName = name.substring(name.lastIndexOf("\\")+1,name.length()).toLowerCase();
        }else{
            cleanName = name.toLowerCase();
        }
        int idx = cleanName.indexOf('.');
        if (idx != -1){
          cleanName = cleanName.substring(0,idx);
        }
        return cleanName;
    }
    
    /**
     * 
     * @param tag
     * @return the cleanedup tag
     */
    public static String cleanTag(String tag){
        return tag.toLowerCase().replaceAll("\\s+", "_").replaceAll("[^a-z0-9]", "");
    }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.