コード例 #1
0
 /**
  * Change a playlist name
  *
  * @param plfOld
  * @param sNewName
  * @return new playlist
  */
 public Playlist changePlaylistFileName(Playlist plfOld, String sNewName) throws JajukException {
   synchronized (PlaylistManager.getInstance().getLock()) {
     // check given name is different
     if (plfOld.getName().equals(sNewName)) {
       return plfOld;
     }
     // check if this file still exists
     if (!plfOld.getFio().exists()) {
       throw new JajukException(135);
     }
     java.io.File ioNew =
         new java.io.File(
             plfOld.getFio().getParentFile().getAbsolutePath()
                 + java.io.File.separator
                 + sNewName);
     // recalculate file ID
     plfOld.getDirectory();
     String sNewId = PlaylistManager.createID(sNewName, plfOld.getDirectory());
     // create a new playlist (with own fio and sAbs)
     Playlist plfNew = new Playlist(sNewId, sNewName, plfOld.getDirectory());
     plfNew.setProperties(plfOld.getProperties()); // transfert all
     // properties
     // (inc id and
     // name)
     plfNew.setProperty(XML_ID, sNewId); // reset new id and name
     plfNew.setProperty(XML_NAME, sNewName); // reset new id and name
     // check file name and extension
     if (plfNew.getName().lastIndexOf('.') != plfNew.getName().indexOf('.') // just
         // one
         // '.'
         || !(Util.getExtension(ioNew).equals(EXT_PLAYLIST))) { // check
       // extension
       Messages.showErrorMessage(134);
       throw new JajukException(134);
     }
     // check if future file exists (under windows, file.exists
     // return true even with different case so we test file name is
     // different)
     if (!ioNew.getName().equalsIgnoreCase(plfOld.getName()) && ioNew.exists()) {
       throw new JajukException(134);
     }
     // try to rename file on disk
     try {
       plfOld.getFio().renameTo(ioNew);
     } catch (Exception e) {
       throw new JajukException(134);
     }
     // OK, remove old file and register this new file
     hmItems.remove(plfOld.getID());
     if (!hmItems.containsKey(sNewId)) {
       hmItems.put(sNewId, plfNew);
     }
     // change directory reference
     plfNew.getDirectory().changePlaylistFile(plfOld, plfNew);
     return plfNew;
   }
 }
コード例 #2
0
 /**
  * Change a playlist name.
  *
  * @param plfOld DOCUMENT_ME
  * @param sNewName DOCUMENT_ME
  * @return new playlist
  * @throws JajukException the jajuk exception
  */
 public synchronized Playlist changePlaylistFileName(Playlist plfOld, String sNewName)
     throws JajukException {
   // check given name is different
   if (plfOld.getName().equals(sNewName)) {
     return plfOld;
   }
   // check if this file still exists
   if (!plfOld.getFIO().exists()) {
     throw new JajukException(135);
   }
   java.io.File ioNew =
       new java.io.File(
           plfOld.getFIO().getParentFile().getAbsolutePath() + java.io.File.separator + sNewName);
   // recalculate file ID
   plfOld.getDirectory();
   String sNewId = PlaylistManager.createID(sNewName, plfOld.getDirectory());
   // create a new playlist (with own fio and sAbs)
   Playlist plfNew = new Playlist(sNewId, sNewName, plfOld.getDirectory());
   // Transfer all properties (id and name)
   // We use a shallow copy of properties to avoid any properties share between
   // two items
   plfNew.setProperties(plfOld.getShallowProperties());
   plfNew.setProperty(Const.XML_ID, sNewId); // reset new id and name
   plfNew.setProperty(Const.XML_NAME, sNewName); // reset new id and name
   // check file name and extension
   if (plfNew.getName().lastIndexOf('.') != plfNew.getName().indexOf('.') // just
       // one
       // '.'
       || !(UtilSystem.getExtension(ioNew).equals(Const.EXT_PLAYLIST))) { // check
     // extension
     Messages.showErrorMessage(134);
     throw new JajukException(134);
   }
   // check if future file exists (under windows, file.exists
   // return true even with different case so we test file name is
   // different)
   if (!ioNew.getName().equalsIgnoreCase(plfOld.getName()) && ioNew.exists()) {
     throw new JajukException(134);
   }
   // try to rename file on disk
   try {
     boolean result = plfOld.getFIO().renameTo(ioNew);
     if (!result) {
       throw new IOException();
     }
   } catch (Exception e) {
     throw new JajukException(134, e);
   }
   // OK, remove old file and register this new file
   removeItem(plfOld);
   registerItem(plfNew);
   return plfNew;
 }