001    /*
002     * ftp4j - A pure Java FTP client library
003     * 
004     * Copyright (C) 2008 Carlo Pelliccia (www.sauronsoftware.it)
005     * 
006     * This program is free software: you can redistribute it and/or modify
007     * it under the terms of the GNU General Public License as published by
008     * the Free Software Foundation, either version 3 of the License, or
009     * (at your option) any later version.
010     *
011     * This program is distributed in the hope that it will be useful,
012     * but WITHOUT ANY WARRANTY; without even the implied warranty of
013     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014     * GNU General Public License for more details.
015     *
016     * You should have received a copy of the GNU General Public License
017     * along with this program.  If not, see <http://www.gnu.org/licenses/>.
018     */
019    package it.sauronsoftware.ftp4j.extrecognizers;
020    
021    import java.io.BufferedReader;
022    import java.io.InputStreamReader;
023    import java.util.StringTokenizer;
024    
025    /**
026     * <p>
027     * This is the default FTPTextualExtensionRecognizer for every new FTPClient
028     * object. It recognizes as textual these extensions:
029     * </p>
030     * 
031     * <pre>
032     * abc acgi aip asm asp c c cc cc com conf cpp csh css cxx def el etx f f f77
033     * f90 f90 flx for for g h h hh hh hlb htc htm html htmls htt htx idc jav jav
034     * java java js ksh list log lsp lst lsx m m mar mcf p pas php pl pl pm py rexx
035     * rt rt rtf rtx s scm scm sdml sgm sgm sgml sgml sh shtml shtml spc ssi talk
036     * tcl tcsh text tsv txt uil uni unis uri uris uu uue vcs wml wmls wsc xml zsh
037     * </pre>
038     * 
039     * <p>
040     * These extensions are loaded from the file textualexts within the package. The
041     * file can be manipulated to add or remove extensions, but it's more convenient
042     * to plug a ParametricTextualExtensionRecognizer instance in the client.
043     * </p>
044     * 
045     * @author Carlo Pelliccia
046     */
047    public class DefaultTextualExtensionRecognizer extends
048                    ParametricTextualExtensionRecognizer {
049    
050            /**
051             * Lock object.
052             */
053            private static final Object lock = new Object();
054    
055            /**
056             * The singleton instance.
057             */
058            private static DefaultTextualExtensionRecognizer instance = null;
059    
060            /**
061             * This one returns the default instance of the class.
062             * 
063             * @return An instance of the class.
064             */
065            public static DefaultTextualExtensionRecognizer getInstance() {
066                    synchronized (lock) {
067                            if (instance == null) {
068                                    instance = new DefaultTextualExtensionRecognizer();
069                            }
070                    }
071                    return instance;
072            }
073    
074            /**
075             * It builds the instance.
076             */
077            private DefaultTextualExtensionRecognizer() {
078                    BufferedReader r = null;
079                    try {
080                            r = new BufferedReader(new InputStreamReader(getClass()
081                                            .getResourceAsStream("textualexts")));
082                            String line;
083                            while ((line = r.readLine()) != null) {
084                                    StringTokenizer st = new StringTokenizer(line);
085                                    while (st.hasMoreTokens()) {
086                                            addExtension(st.nextToken());
087                                    }
088                            }
089                    } catch (Exception e) {
090                            ;
091                    } finally {
092                            if (r != null) {
093                                    try {
094                                            r.close();
095                                    } catch (Throwable t) {
096                                            ;
097                                    }
098                            }
099                    }
100            }
101    
102    }