001    /* PAVLOV -- Multiple Choice Study System
002     * Copyright (C) 2000 - 2004 T.J. Willis
003     * 
004     * This program is free software; you can redistribute it and/or
005     * modify it under the terms of the GNU General Public License
006     * as published by the Free Software Foundation; either version 2
007     * of the License, or (at your option) any later version.
008     *      
009     * This program is distributed in the hope that it will be useful,
010     * but WITHOUT ANY WARRANTY; without even the implied warranty of
011     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012     * GNU General Public License for more details.
013     *          
014     * You should have received a copy of the GNU General Public License
015     * along with this program; if not, write to the Free Software
016     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
017     *  
018     * $Header: /cvsroot/pavlov/net/sourceforge/pavlov/main/Skin.java,v 1.2 2004/07/01 05:50:20 tj_willis Exp $
019     */ 
020    package net.sourceforge.pavlov.main;
021    
022    import java.io.*;
023    import java.net.*;
024    import org.apache.log4j.*;
025    import net.sourceforge.steelme.*;
026    
027    /**
028     * Describe class <code>DefaultTemplateKit</code> here.
029     *
030     * @author <a href="mailto:tj_willis@users.sourceforge.net">T.J. Willis</a>
031     * @version 1.0
032     * @since 1.1
033     */
034    public class Skin extends DefaultTemplateKit
035    {
036        private static Category cat
037            = Category.getInstance(Skin.class.getName());    
038    
039        File directory;
040    
041        public Skin(File directory){
042            this.directory = directory;
043        }
044    
045        public String getLoginTemplate(){
046            try {
047                File f = new File(directory,"Logon.vm");
048                return getText(f.toURL());
049            } catch (Exception e) { cat.error("getting login template",e);return null; }
050        }
051    
052        public String getLibraryTemplate(){
053            try {
054                File f = new File(directory,"Library.vm");
055                return getText(f.toURL());
056            } catch (Exception e) { cat.error("getting library template",e);return null; }
057        }
058    
059        public String getQuizTemplate(){
060            try {
061                File f = new File(directory,"QuizPanel.vm");
062                return getText(f.toURL());
063            } catch (Exception e) { cat.error("getting quiz template",e);return null; }
064        }
065    
066        public String getWelcomeTemplate(){
067            try {
068                File f = new File(directory,"Welcome.vm");
069                return getText(f.toURL());
070            } catch (Exception e) { cat.error("getting welcome template",e);return null; }
071        }
072    
073        public SteelmeTheme getTheme(){
074            try {
075                File f = new File(directory,"Theme.theme");
076                return new SteelmeTheme(f);
077            } catch (Exception e) { cat.error("getting theme",e);return null; }
078    
079        }
080    
081        public File getBaseDir(){
082            try {
083                return directory;
084            } catch (Exception e) { cat.error("getting base dir",e);return null; }
085        }
086    
087        /**
088         * Describe <code>getText</code> method here.
089         *
090         * @param textUrl a <code>String</code> value
091         * @exception java.net.MalformedURLException if an error occurs
092         * @exception java.io.IOException if an error occurs
093         */
094        protected String getText (String textUrl)
095            throws java.net.MalformedURLException, java.io.IOException {
096            if (textUrl == null) {
097                return null;
098            }
099            URL u = null;
100            u = new URL (textUrl);
101            return getText (u);
102        }
103    
104        /**
105         * Describe <code>getText</code> method here.
106         *
107         * @param textURL an <code>URL</code> value
108         * @exception java.io.IOException if an error occurs
109         *
110        protected String getText (URL textURL) throws java.io.IOException {
111            StringBuffer cont = new StringBuffer ();
112    
113            InputStream is = textURL.openStream ();
114            InputStreamReader isr = new InputStreamReader (is);
115            BufferedReader in = new BufferedReader (isr);
116            String foo = in.readLine ();
117            while (foo != null) {
118                cont.append (foo).append ("\n");    // += foo +"\n";
119                foo = in.readLine ();
120            }
121            return cont.toString ();
122    
123            }
124        */
125    
126    }
127