~ubuntu-branches/ubuntu/oneiric/tuxguitar/oneiric

« back to all changes in this revision

Viewing changes to TuxGuitar/src/org/herac/tuxguitar/io/base/TGSongWriter.java

  • Committer: Bazaar Package Importer
  • Author(s): Philippe Coval
  • Date: 2008-06-19 00:30:30 UTC
  • mto: (5.1.2 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20080619003030-h719szrhsngou7c6
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Created on 19-dic-2005
 
3
 *
 
4
 * TODO To change the template for this generated file go to
 
5
 * Window - Preferences - Java - Code Style - Code Templates
 
6
 */
 
7
package org.herac.tuxguitar.io.base;
 
8
 
 
9
import java.io.File;
 
10
import java.io.FileOutputStream;
 
11
import java.util.Iterator;
 
12
 
 
13
import org.herac.tuxguitar.song.factory.TGFactory;
 
14
import org.herac.tuxguitar.song.models.TGSong;
 
15
 
 
16
/**
 
17
 * @author julian
 
18
 *
 
19
 * TODO To change the template for this generated type comment go to
 
20
 * Window - Preferences - Java - Code Style - Code Templates
 
21
 */
 
22
public class TGSongWriter {
 
23
        
 
24
        public TGSongWriter(){
 
25
                super();
 
26
        }
 
27
        
 
28
        public void write(TGFactory factory,TGSong song,String path) throws TGFileFormatException{
 
29
                try {
 
30
                        Iterator it = TGFileFormatManager.instance().getOutputStreams();
 
31
                        while(it.hasNext()){
 
32
                                TGOutputStreamBase writer = (TGOutputStreamBase)it.next();
 
33
                                if(isSupportedExtension(writer,path)){
 
34
                                        writer.init(factory,new FileOutputStream(new File(path)));
 
35
                                        writer.writeSong(song);
 
36
                                        return;
 
37
                                }
 
38
                        }
 
39
                } catch (Throwable t) {
 
40
                        throw new TGFileFormatException(t);
 
41
                }
 
42
                throw new TGFileFormatException("Unsupported file format");
 
43
        }
 
44
        
 
45
        private boolean isSupportedExtension(TGOutputStreamBase writer,String path){
 
46
                int index = path.lastIndexOf(".");
 
47
                if(index > 0){
 
48
                        return writer.isSupportedExtension(path.substring(index));
 
49
                }
 
50
                return false;
 
51
        }
 
52
        
 
53
}