001    package net.sourceforge.mp3dings.export;
002    
003    /* Mp3dings - manage mp3 meta-information
004    * Copyright (C) 2003 Moritz Ringler
005    * $Id: PLSExporter.java 115 2007-11-05 23:46:25Z ringler $
006    *
007    * This program is free software; you can redistribute it and/or
008    * modify it under the terms of the GNU General Public License
009    * as published by the Free Software Foundation; either version 2
010    * of the License, or (at your option) any later version.
011    *
012    * This program is distributed in the hope that it will be useful,
013    * but WITHOUT ANY WARRANTY; without even the implied warranty of
014    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
015    * GNU General Public License for more details.
016    *
017    * You should have received a copy of the GNU General Public License
018    * along with this program; if not, write to the Free Software
019    * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
020    */
021    
022    import java.util.Map;
023    import net.sourceforge.mp3dings.Field;
024    import java.io.Serializable;
025    
026    /**Exports data as a PLS playlist.
027    * @author Moritz Ringler
028    * @version $Revision: 115 $ ($Date: 2007-11-06 00:46:25 +0100 (Di, 06 Nov 2007) $)
029    */
030    public class PLSExporter extends AbstractExporter implements Serializable{
031        static final long serialVersionUID = 1269083213584949630L;
032    
033        /** Creates a new PLSExporter with the encoding set to iso-latin (ISO-8859-1).
034        */
035        public PLSExporter(){
036            super();
037            super.setKeys(null,
038            new Field[]{Field.FULLPATH,
039                Field.ARTIST,
040                Field.TITLE,
041                Field.LENGTH,
042            Field.FILENAME},
043            null);
044            setEncoding("ISO-8859-1");
045        }
046    
047        /** Returns three lines making up one playlist entry.
048        * <pre>
049        *      File[fIndex]=[filepath]
050        *      Title[fIndex]=[artist] - [title]
051        *      Length[fIndex]=[length]
052        * </pre>
053        * @param index the number of the record that is currently exported,
054        * starting at 1
055        * @param blockdata a map containing the record data
056        */
057        public String getBlock(int index, Map blockdata){
058            index++;
059            StringBuffer sb = new StringBuffer(255);
060            /* line 1 */
061            sb.append("File").append(index).append('=');
062            sb.append(blockdata.get(Field.FULLPATH)).append("\n");
063            /* line 2 */
064            sb.append("Title").append(index).append('=');
065            sb.append(blockdata.get(Field.ARTIST)).append(" - ");
066            sb.append(blockdata.get(Field.TITLE)).append("\n");
067            /* line 3 */
068            Number len = (Number) blockdata.get(Field.LENGTH);
069            if(len == null){
070                len = new Integer(0);
071            }
072            sb.append("Length").append(index).append('=');
073            sb.append(len).append("\n");
074            return sb.toString();
075        }
076    
077        /** Returns the single line header for the playlist.
078        * <pre>
079        *      [playlist]
080        * </pre>
081        */
082        public String getHeader(){
083            return "[playlist]\n";
084        }
085    
086        /** Returns the the two-line footer for the playlist.
087        * @param numEntries the number of exported records
088        * <pre>
089        * NumberOfEntries=[numEntries]
090        * Version=2
091        * </pre>
092        */
093        public String getFooter(int numEntries){
094            return "NumberOfEntries="+numEntries+"\nVersion=2\n";
095        }
096    
097        /** Returns a string description of this exporter's target file type.
098        * @return the name of the target file type. Currently this is
099        * "PLS playlist (*.pls)", but this may change in future
100        * versions.
101        */
102        public String getName(){
103            return "PLS playlist (*.pls)";
104        }
105    
106        /** Returns the file extension for this exporter's target file type.
107        * @return a file extension including the leading dot. Currently this is
108        * ".pls", but this may change in future versions.
109        */
110        public String getExtension(){
111            return ".pls";
112        }
113    
114        /** Overriden to do nothing. This exporter uses no fields for the header and
115        * footer and
116        * <code>ARTIST</code>, <code>TITLE</code>, <code>FILENAME</code>,
117        * <code>FULLPATH</code>, and <code>LENGTH</code> as blockKeys.
118        */
119        public void setKeys(Object[] headerKeys, Object[] blockKeys, Object[] footerKeys){
120        }
121    }