Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

HTMLGeneratorWriter.java

Go to the documentation of this file.
00001 package cedar.jetweb.html;
00002 
00003 import java.io.BufferedWriter;
00004 import java.io.IOException;
00005 import java.io.PrintWriter;
00006 
00007 import java.util.Map;
00008 import java.util.HashMap;
00009 import java.util.Map.Entry;
00010 import java.util.Set;
00011 
00012 import cedar.jetweb.*;
00013 import cedar.jetweb.generator.Generator;
00014 
00022 public class HTMLGeneratorWriter extends HTMLWriter {
00023 
00024 
00025     public HTMLGeneratorWriter(PrintWriter out, String newservletpath){
00026     super(out,newservletpath);
00027     }
00028     public HTMLGeneratorWriter(String fname, String newservletpath){
00029     super(fname,newservletpath);
00030     }
00031     public HTMLGeneratorWriter(BufferedWriter out, String newServletPath ){
00032     super(out,newServletPath);  
00033     }
00034 
00035 
00046     public static void listSetParameters(HTMLWriter op,Generator gen,
00047                      boolean modifiable) throws JetWebException {
00048     
00049     BufferedWriter ofile = op.getWriter();
00050 
00051     Set<Map.Entry<String,Integer>> intParameters;
00052     Set<Map.Entry<String,Double>>  realParameters;
00053     Set<Map.Entry<String,HashMap<Integer,Integer>>> intArrays;
00054     Set<Map.Entry<String,HashMap<Integer,Double>>> realArrays;
00055 
00056     try {
00057         ofile.write("<table><tr>");
00058         ofile.write("<td colspan=4>");
00059         ofile.write("<hr noshade size=3>");
00060 
00061         ofile.write("</td></tr><tr>");
00062         ofile.write("<td colspan=5>");
00063         if (modifiable) {
00064         ofile.write("<p>Enter "+gen.getName()+"-"+gen.getVersion()
00065                 +" parameters below and add them before submission</p>");
00066         } else {
00067         ofile.write("<p> Generator: "+gen.getName()+"-"+gen.getVersion()
00068                 +" Parameters: </p>");
00069         }
00070         ofile.write("</td></tr>");
00071 
00072 
00073         // First the integer parameters.
00074         intParameters = gen.getIntParameters().entrySet(); 
00075         int counter=0;
00076         ofile.write("<tr>");
00077         for (Map.Entry<String,Integer> entry : intParameters){
00078         
00079         ofile.write("<td align=\"top\"><p>"+entry.getKey()+"<br/>");
00080         ofile.newLine();
00081         if (modifiable) {
00082             ofile.write(HTMLUtils.writeInputBox(entry.getKey(),
00083                             "comment",entry.getValue()));
00084         } else {
00085             ofile.write(entry.getValue().toString());
00086         }
00087         ofile.newLine();
00088         ofile.write("</p></td>");
00089         counter++;
00090         if (counter>5) {
00091             ofile.write("</tr><tr>");
00092             counter=0;
00093         }
00094         }
00095 
00096         // Now the real parameters.
00097         realParameters = gen.getRealParameters().entrySet(); 
00098         counter=0;
00099         ofile.write("<tr>");
00100         for (Map.Entry<String,Double> entry : realParameters){
00101         String parName = entry.getKey();
00102         if(gen.inModel(parName)){
00103             ofile.write("<td align=\"top\"><p>"+entry.getKey()+"<br/>");
00104             ofile.newLine();
00105             if (modifiable) {
00106             ofile.write(HTMLUtils.writeInputBox
00107                     (entry.getKey(),
00108                      "comment",dform.format(entry.getValue())));
00109             } else {
00110             ofile.write(dform.format(entry.getValue()));
00111             }
00112             ofile.newLine();
00113             ofile.write("</p></td>");
00114             counter++;
00115             if (counter>5) {
00116             ofile.write("</tr><tr>");
00117             counter=0;
00118             }
00119         }
00120         }
00121 
00122 
00123 
00124         // Now the integer arrays.
00125         intArrays = gen.getIntParameterArrays().entrySet(); 
00126         for (Map.Entry<String,HashMap<Integer,Integer>> entry : intArrays){
00127         
00128         String arrayName = entry.getKey(); 
00129         ofile.write("<tr><td align=\"top\"><p>"+arrayName+" Array<br/></td></tr>");
00130         ofile.newLine();
00131 
00132         Set<Map.Entry<Integer,Integer>> array = entry.getValue().entrySet();
00133         ofile.write("<tr>");
00134         counter=0;
00135         for (Map.Entry<Integer,Integer> arrayEntry : array){
00136 
00137             Integer value = arrayEntry.getValue();
00138             Integer index = arrayEntry.getKey();            
00139             ofile.write("<td align='left'>");
00140             ofile.write(arrayName+"("+index+")");
00141             if (modifiable) {
00142             ofile.write(HTMLUtils.writeInputBox(arrayName+"-"+index,null,value));
00143             } else {
00144             ofile.write(value.toString());
00145             }
00146 
00147             ofile.write("</td>");
00148             ofile.newLine();
00149             counter++;
00150             if (counter>5) {
00151             ofile.write("</tr><tr>");
00152             counter=0;
00153             }
00154         }
00155         }
00156         // Now the real arrays.
00157         realArrays = gen.getRealParameterArrays().entrySet(); 
00158         for (Map.Entry<String,HashMap<Integer,Double>> entry : realArrays){
00159         
00160         String arrayName = entry.getKey(); 
00161         if(gen.inModel(arrayName)){
00162             ofile.write("<tr>");
00163             ofile.write
00164             ("<td align=\"top\"><p>" + 
00165              arrayName + 
00166              " Array<br/></td></tr>");
00167             ofile.newLine();
00168             
00169             ofile.write("<tr>");
00170             Set<Map.Entry<Integer,Double>> array = 
00171             entry.getValue().entrySet();
00172             counter=0;
00173             for (Map.Entry<Integer,Double> arrayEntry : array){
00174             
00175             Double value = arrayEntry.getValue();
00176             Integer index = arrayEntry.getKey();            
00177             ofile.write("<td align='left'>");
00178             ofile.write(arrayName+"("+index+")");
00179             if (modifiable) {
00180                 ofile.write
00181                 (HTMLUtils.writeInputBox
00182                  (arrayName + 
00183                   "-"+index,null,dform.format(value)));
00184             } else {
00185                 ofile.write(dform.format(value));
00186             }
00187             
00188             ofile.write("</td>");
00189             ofile.newLine();
00190             counter++;
00191             if (counter>5) {
00192                 ofile.write("</tr><tr>");
00193                 counter=0;
00194             }
00195             }
00196         }
00197         }
00198         
00199         ofile.write("</tr><tr><td colspan='5'><hr noshade size='3'/></td></tr>");
00200         ofile.write("</table>");
00201 
00202     } catch ( IOException e ) {
00203         System.out.println("problem writing form");
00204         return;
00205     }
00206     }
00207 
00211     public void display(Object object) throws JetWebException {
00212     try {
00213         Generator gen = (Generator)object;
00214         display(gen);
00215     } catch (ClassCastException cce) {
00216         throw new JetWebException(cce,"Attempt to display object as generator failed");
00217     }
00218     }
00219 
00229     public void display(Generator gen) throws JetWebException {
00230     
00231     Set<String> intNames;
00232     Set<String> realNames;
00233 
00234     Map<String,Integer> setIntParameters;
00235     Map<String,Double>  setRealParameters;
00236 
00237     Set<String> intArrayNames;
00238     Set<String> realArrayNames;
00239 
00240     Map<java.lang.String,HashMap<java.lang.Integer,Integer>> intArrays;
00241     Map<java.lang.String,HashMap<java.lang.Integer,Double>> realArrays;
00242 
00243     try {
00244         ofile.write("<table><tr>");
00245         ofile.write("<td colspan=4>");
00246         ofile.write("<hr noshade size=3>");
00247 
00248         ofile.write("<tr>");
00249         ofile.write("<td colspan=5>");
00250         if (modifiable) {
00251         ofile.write("<p>Enter "+gen.getName()+"-"+gen.getVersion()
00252                 +" parameters below and add them before submission</p>");
00253         } else {
00254         ofile.write("<p> Generator: "+gen.getName()+"-"+gen.getVersion()
00255                 +" Parameters: </p>");
00256         }
00257         ofile.write("</td></tr>");
00258 
00259         // First the integer parameters.
00260         setIntParameters = gen.getIntParameters(); 
00261         intNames = gen.getIntNames(); 
00262 
00263         int counter=0;
00264         ofile.write("<tr>");
00265         for (String name : intNames){
00266 
00267         Integer value = setIntParameters.get(name);
00268 
00269         ofile.write("<td align=\"top\"><p>"+name+"<br/>");
00270         ofile.newLine();
00271 
00272         if (modifiable) {
00273             ofile.write(HTMLUtils.writeInputBox(name,
00274                             "comment",value));
00275         } else {
00276             ofile.write(value.toString());
00277         }
00278         ofile.newLine();
00279         ofile.write("</p>");
00280         counter++;
00281         if (counter>5) {
00282             ofile.write("</tr><tr>");
00283             counter=0;
00284         }
00285         }
00286 
00287         // Now the real parameters.
00288         setRealParameters = gen.getRealParameters(); 
00289         realNames = gen.getRealNames(); 
00290         counter=0;
00291         ofile.write("<tr>");
00292         for (String name : realNames){
00293         if(gen.inModel(name)){
00294             Double value = setRealParameters.get(name);
00295             
00296             ofile.write("<td align=\"top\"><p>"+name+"<br/>");
00297             ofile.newLine();    
00298             if (value!=null){
00299             if (modifiable) {
00300                 ofile.write(HTMLUtils.writeInputBox(name,
00301                                 "comment",dform.format(value)));
00302             } else {
00303                 ofile.write(dform.format(value));
00304             }
00305             } else if (modifiable) {
00306             ofile.write(HTMLUtils.writeInputBox(name,"comment",null));
00307             }
00308             
00309             ofile.newLine();
00310             ofile.write("</p></td>");
00311             counter++;
00312             if (counter>5) {
00313             ofile.write("</tr><tr>");
00314             counter=0;
00315             }
00316         }
00317         }
00318         
00319         // Now the integer arrays.
00320         intArrayNames = gen.getIntArrayNames(); 
00321         intArrays = gen.getIntParameterArrays();
00322         for (String arrayName : intArrayNames){
00323         
00324         ofile.write("<tr><td align=\"top\"><p>"+arrayName+" Array</p></td></tr>");
00325         ofile.newLine();
00326         ofile.write("<tr>");
00327         counter=0;
00328 
00329         for (int aIndex=gen.getMinIndex(arrayName); 
00330              aIndex<=gen.getMaxIndex(arrayName); aIndex++){
00331 
00332             Integer value=null;
00333             if (intArrays.containsKey(arrayName)){
00334             HashMap<Integer,Integer> array = intArrays.get(arrayName);
00335             if (array.containsKey(aIndex)){
00336                 value = array.get(aIndex);
00337             }
00338             }
00339 
00340             ofile.write("<td align='left'>");
00341             ofile.write(arrayName+"("+aIndex+")");
00342             if (modifiable) {
00343             ofile.write(HTMLUtils.writeInputBox(arrayName+"-"+aIndex,null,value));
00344             } else {
00345             if (value!=null) ofile.write(value.toString());
00346             }
00347             
00348             ofile.write("</td>");
00349             ofile.newLine();
00350             counter++;
00351             if (counter>5) {
00352             ofile.write("</tr><tr>");
00353             counter=0;
00354             }
00355         }
00356 
00357         }
00358         ofile.write("<tr><td colspan='5'><hr noshade size='3'/></tr>");
00359 
00360         // Now the real arrays.
00361         realArrayNames = gen.getRealArrayNames(); 
00362         realArrays = gen.getRealParameterArrays();
00363         for (String arrayName : realArrayNames){
00364         if(gen.inModel(arrayName)){
00365             ofile.write("<tr><td align=\"top\"><p>"+arrayName+" Array</p></td></tr>");
00366             ofile.newLine();
00367             ofile.write("<tr>");
00368             counter=0;
00369             
00370             for (int aIndex=gen.getMinIndex(arrayName); 
00371              aIndex<=gen.getMaxIndex(arrayName); aIndex++){
00372             
00373             Double value=null;
00374             if (realArrays.containsKey(arrayName)){
00375                 HashMap<Integer,Double> array = realArrays.get(arrayName);
00376                 if (array.containsKey(aIndex)){
00377                 value = array.get(aIndex);
00378                 }
00379             }
00380             
00381             ofile.write("<td align='left'>");
00382             ofile.write(arrayName+"("+aIndex+")");
00383             if (value!=null){
00384                 if (modifiable) {
00385                 ofile.write(HTMLUtils.writeInputBox(arrayName+"-"+aIndex,
00386                                     null,dform.format(value)));
00387                 } else {
00388                 ofile.write(dform.format(value));
00389                 }
00390             } else if (modifiable){
00391                 ofile.write(HTMLUtils.writeInputBox(arrayName+"-"+aIndex,
00392                                 null,null));
00393             }
00394             
00395             ofile.write("</td>");
00396             ofile.newLine();
00397             counter++;
00398             if (counter>5) {
00399                 ofile.write("</tr><tr>");
00400                 counter=0;
00401             }
00402             }
00403         }
00404         }
00405 
00406         ofile.write("<tr><td colspan='5'><hr noshade size='3'/></tr>");
00407         ofile.write("</table>");
00408 
00409     } catch ( IOException e ) {
00410         System.out.println("problem writing form");
00411         return;
00412     }
00413     }
00414 
00415 
00419     public static void installedMessage(PrintWriter out, Generator gen) 
00420     throws JetWebException {
00421 
00422     try {
00423 
00424         BufferedWriter ofile = new BufferedWriter(out);
00425         
00426         ofile.write("<h3>Installation of "+gen.toString()+"</h3>");
00427         
00428         ofile.newLine();
00429         
00430         ofile.write("<h4>What has been done</h4>");
00431         ofile.newLine();
00432         ofile.write("<ul>");
00433         ofile.newLine();
00434         ofile.write("<li>The generator and version have been added to the generators table in the database.</li>");
00435         ofile.newLine();
00436         ofile.write("<li>The table of default generator parameters has been created and filled.</li>");
00437         ofile.write("</ul>");
00438         ofile.newLine();
00439         
00440         ofile.write("<h4>What you need to do</h4>");
00441         ofile.newLine();
00442         ofile.write("<ul>");
00443         ofile.newLine();
00444         ofile.write("<li>Either provide a subclass of cedar.jetweb.generator.Generator.java for "+gen.getName()+", if one does not exist already, or</li>");
00445         ofile.newLine();
00446         ofile.write("<li>Check that the existing implementation of cedar.jetweb.generator."+gen.getName()+" works for version "+gen.getVersion()+".</li>");
00447         ofile.write("</ul>");
00448         
00449         ofile.newLine();
00450         ofile.close();
00451     } catch (IOException e) {
00452         throw new JetWebException(e);
00453 
00454     }
00455     }
00456 
00457     /*
00458      * Write a message to say that the generator is already installed
00459      */
00460 
00461     public static void alreadyInstalledMessage(PrintWriter out, Generator gen) 
00462     throws JetWebException {
00463     
00464     try{
00465         BufferedWriter ofile = new BufferedWriter(out);
00466         ofile.write("<h3>Installation of "+gen.toString()+"</h3>");
00467         ofile.newLine();
00468         ofile.write("<h4>"+gen.toString()+
00469             " was already installed in the database</h4>");
00470         ofile.newLine();
00471         ofile.write("<h4>What you need to do</h4>");
00472         ofile.newLine();
00473         ofile.write("<ul>");
00474         ofile.newLine();
00475         ofile.write
00476         ("<li>If it does not already exist, you must " +
00477          "provide a subclass of cedar.jetweb.generator.Generator.java " +
00478          "for "+gen.getName()+" </li>");
00479 
00480         ofile.write("</ul>");
00481         ofile.newLine();
00482         ofile.newLine();
00483         ofile.close();
00484     }catch(IOException e){
00485         throw new JetWebException(e);
00486     }
00487 
00488     return;
00489     }    
00490 }

Generated Wed Jan 17 09:14:27 GMT 2007