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/DefaultTemplateKit.java,v 1.4 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 026 /** 027 * A template kit that uses the files in resources/views. 028 * 029 * @author <a href="mailto:tj_willis@users.sourceforge.net">T.J. Willis</a> 030 * @version 1.0 031 * @since 1.1 032 */ 033 public class DefaultTemplateKit implements AbstractTemplateKit 034 { 035 private static Category cat 036 = Category.getInstance(DefaultTemplateKit.class.getName()); 037 038 public String getLoginTemplate(){ 039 try { 040 return getText("file:resources/skins/default/Logon.vm"); 041 } catch (Exception e) { cat.error("getting login template",e);return null; } 042 } 043 044 public String getLibraryTemplate(){ 045 try { 046 return getText("file:resources/skins/default/Library.vm"); 047 } catch (Exception e) { cat.error("getting library template",e);return null; } 048 } 049 050 public String getQuizTemplate(){ 051 try { 052 return getText("file:resources/skins/default/QuizPanel.vm"); 053 } catch (Exception e) { cat.error("getting quiz template",e);return null; } 054 } 055 056 public String getWelcomeTemplate(){ 057 try { 058 return getText("file:resources/skins/default/Welcome.vm"); 059 } catch (Exception e) { cat.error("getting welcome template",e);return null; } 060 } 061 062 public File getBaseDir(){ 063 try { 064 return new File("resources/skins/default"); 065 } catch (Exception e) { cat.error("getting base dir",e);return null; } 066 } 067 068 /** 069 * Describe <code>getText</code> method here. 070 * 071 * @param textUrl a <code>String</code> value 072 * @exception java.net.MalformedURLException if an error occurs 073 * @exception java.io.IOException if an error occurs 074 */ 075 protected String getText (String textUrl) 076 throws java.net.MalformedURLException, java.io.IOException { 077 if (textUrl == null) { 078 return null; 079 } 080 URL u = null; 081 u = new URL (textUrl); 082 return getText (u); 083 } 084 085 /** 086 * Describe <code>getText</code> method here. 087 * 088 * @param textURL an <code>URL</code> value 089 * @exception java.io.IOException if an error occurs 090 */ 091 protected String getText (URL textURL) throws java.io.IOException { 092 StringBuffer cont = new StringBuffer (); 093 094 InputStream is = textURL.openStream (); 095 InputStreamReader isr = new InputStreamReader (is); 096 BufferedReader in = new BufferedReader (isr); 097 String foo = in.readLine (); 098 while (foo != null) { 099 cont.append (foo).append ("\n"); // += foo +"\n"; 100 foo = in.readLine (); 101 } 102 is.close(); //FIXED: thanks FindBugs! 103 return cont.toString (); 104 105 } 106 107 } 108