GenericLookAndFeel.java
00001 package edu.virtualschool.jwaa;
00002 import java.text.SimpleDateFormat;
00003 import java.util.ArrayList;
00004 import java.util.Iterator;
00005 import java.util.Locale;
00006
00007 import org.apache.log4j.Logger;
00008
00009 import edu.virtualschool.VirtualSchoolNavigationBar;
00010
00021 public class GenericLookAndFeel
00022 {
00023 public String keywords;
00024 public String description;
00025 public String author;
00026 public String email;
00027 public String version;
00028 public String copyright;
00029 public String documentRoot;
00030
00031 public String pageHeader1;
00032 public String pageHeader2;
00033 public String pageTrailer1;
00034 public String pageTrailer2;
00035 final public MetaPage firstNavBarRow;
00036
00037 public SimpleDateFormat date = new SimpleDateFormat("dd MMM yyyy", Locale.US);
00038 private final static Logger logger = Logger.getLogger(GenericLookAndFeel.class.getName());
00039
00040 public GenericLookAndFeel(
00041 String keywords,
00042 String description,
00043 String author,
00044 String email,
00045 String version,
00046 String copyright,
00047 String documentRoot,
00048 String selected
00049 )
00050 {
00051 this.keywords = keywords;
00052 this.description = description;
00053 this.author = author;
00054 this.email = email;
00055 this.version = version;
00056 this.copyright = copyright;
00057 this.documentRoot = documentRoot;
00058 this.firstNavBarRow = new VirtualSchoolNavigationBar(selected);
00059
00060 this.pageHeader1 =
00061 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \n"+
00062 " \"http://www.w3.org/TR/REC-html40/loose.dtd\">\n"+
00063 "<html>\n"+
00064 " <head><title>";
00065
00066 this.pageHeader2 =
00067 "</title>\n"+
00068 " <meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n"+
00069 " <meta name=\"keywords\" content=\""+keywords+"\">\n"+
00070 " <meta name=\"description\" content=\""+description+"\">\n"+
00071 " <meta name=\"author\" content=\""+author+"\">\n"+
00072 " <meta name=\"revisit-after\" content=\"20 days\">\n"+
00073 " <meta http-equiv=\"keywords\" content=\""+keywords+"\">\n"+
00074 " <meta http-equiv=\"Reply-to\" content=\""+email+"\"> \n"+
00075 " <link href=\"/css/innerPage.css\" rel=\"stylesheet\" type=\"text/css\">\n"+
00076 " <link href=\"/css/print.css\" rel=\"stylesheet\" type=\"text/css\" media=\"print\">\n"+
00077 "</head>\n"+
00078 "<body>\n"+
00079 "\n"+
00080 "<div class=\"top\">\n"+
00081 " <a href=\"/\"><img src=\"/pix/vs.jpg\" align=\"bottom\" alt=\"\" height=\"53\" width=\"420\"></a>\n"+
00082 "</div>\n";
00083
00084
00085 this.pageTrailer1 = "\n"+
00086 "<br clear=\"all\"/>"+
00087 "<div class=\"bottom\">\n"+
00088 " <table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">\n"+
00089 " <tr><td colspan=\"3\"><hr></td></tr>\n"+
00090 " <tr>\n"+
00091 " <td align=\"left\">"+version+"</a></td>\n"+
00092 " <td align=\"center\"><a href=\"/cox\">"+copyright+"</a></td>\n"+
00093 " <td align=\"right\">";
00094
00095 this.pageTrailer2 = "</td>\n"+
00096 " </tr>\n"+
00097 " </table> \n"+
00098 " <center>\n"+
00099 " Served by <a href=\"http://johncompanies.com\">John Companies</a>\n"+
00100 " </center>\n"+
00101 "</div>\n"+
00102 " </body>\n"+
00103 "</html>\n"+"";
00104 }
00110 public void sendPrefix(GenericPage page) throws Fault
00111 {
00112 sendPrefix(page, page.meta.defaultTitle);
00113 }
00121 public void sendPrefix(GenericPage page, Object title) throws Fault
00122 {
00123 page.send(pageHeader1+title+pageHeader2);
00124 page.send("<div class=\"navbar\">");
00125 page.send(computeNavigationBar(page));
00126 page.send("</div>");
00127 page.send("<div class=\"title\">\n <h1 align=\"center\">"+title+"</h1>\n</div>\n");
00128 page.send("<div class=\"page\">");
00129 }
00135 public void sendPostfix(GenericPage page) throws Fault
00136 {
00137 page.send("</div>");
00138 page.send(pageTrailer1+date.format(TimeUtil.now())+pageTrailer2);
00139 }
00144 public String computeNavigationBar(GenericPage page)
00145 {
00146 int row=1;
00147 AccountAbstraction person = page.getAccount();
00148 StringBuffer buf = new StringBuffer();
00149 ArrayList list = page.meta.getRootPath();
00150 list.add(firstNavBarRow);
00151 for (int i = list.size()-1; i >= 0; i--)
00152 {
00153 Object object = list.get(i);
00154 MetaPage parent = (MetaPage)object;
00155 StringBuffer cells = new StringBuffer();
00156 for (Iterator it = parent.childrenIterator(); it.hasNext(); )
00157 {
00158 MetaPage child = (MetaPage)it.next();
00159 if (child == null || child.defaultAnchor == null || child.defaultAnchor.equals(""))
00160 continue;
00161 else if (child.allowsAccessBy(person))
00162 {
00163 cells.append((child.isSelected || list.contains(child)) ? " <td class=\"highlight\">" : " <td>");
00164 cells.append(page.emitLink(child));
00165 cells.append("</td>\n");
00166 }
00167 }
00168 if (!cells.toString().equals(""))
00169 buf.append(
00170 "<table class=\"row"+row+"\" width=\"100%\">\n"+
00171 " <tr>\n"+cells+"\n </tr>\n"+
00172 "</table>\n");
00173 row++;
00174 }
00175 return buf.toString();
00176 }
00177 }