KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > WebManValidator


1 import java.io.*;
2
3 import com.teamkonzept.lib.*;
4 import com.teamkonzept.webman.db.TKWebmanDBManager;
5 import de.webman.generator.*;
6 import org.apache.log4j.Category;
7
8 /**
9  * Entry class for site validation.
10  * This class makes a (fast) validation of a webman site
11  * and checks if it can be generated.
12  * Checks performed at the moment are
13  * 1. existence of all needed templates
14  * 2. existence of generatable contents for all single contents.
15  * Errors and warnings are written to a Writer.
16  * To use the class create an instance of the WebManValidator and
17  * call its validate() method.
18  * @author $Author: mischa $
19  * @version $Revision: 1.13 $
20  */

21 public class WebManValidator
22 {
23     private Writer out;
24     private SiteTreeValidator validator;
25             
26     /**
27      * @param docRootPath the (absolute) path to the web applications document root
28      * @param out the writer to which warnings and errors are written
29      * @param genHTMLOutput write HTML-output (a trialing <br> and different colors for errors and warnings)
30     */

31     public WebManValidator(String JavaDoc docRootPath, Writer out, boolean genHTMLOutput)
32     {
33         String JavaDoc templatePath = docRootPath + File.separator + TemplateUtils.getGenerationDirectory();
34         validator = new SiteTreeValidator(docRootPath, templatePath);
35                 
36         if (genHTMLOutput) {
37             makeHTMLValidator(out);
38         }
39         else {
40             makeStdValidator(out);
41         }
42         this.out = out;
43     }
44
45     /**
46      * Validates the site.
47      * @return true: validation could be performed
48      * false: an (internal) error coocured during validation
49      */

50     public boolean validate()
51     {
52         boolean retval = true;
53         
54         try {
55             validator.initDB();
56             validator.validate();
57         }
58         catch (Throwable JavaDoc e)
59         {
60             PrintWriter pout = new PrintWriter(out);
61             e.printStackTrace(pout);
62             pout.flush();
63             retval = false;
64         }
65         finally {
66             try {
67                 validator.deinitDB(!retval);
68             }
69             catch (TKException e) {
70                e.printStackTrace(new PrintWriter(out));
71             }
72         }
73         
74         return retval;
75     }
76     
77     /**
78      * Initializes the validator for HTMLized output on the Writer out.
79     */

80     private void makeHTMLValidator(Writer out)
81     {
82         /*
83         validator.setStdWriter(genWrappingWriter(out, "", "<br>"));
84         validator.setWarningWriter(genWrappingWriter(out, "<font color=\"ff9900\">", "</font><br>"));
85         validator.setErrorWriter(genWrappingWriter(out, "<font color=\"ff0000\">", "</font><br>"));
86         */

87     }
88     
89     /**
90      * Initializes the validator with writer out.
91      */

92     private void makeStdValidator(Writer out)
93     {
94         /*
95         validator.setStdWriter(out);
96         validator.setWarningWriter(out);
97         validator.setErrorWriter(out);
98         */

99     }
100     
101     public static void main(String JavaDoc[] args)
102     {
103         if (args.length < 1) {
104             printUsage();
105             return;
106         }
107         
108         boolean genHTMLOutput = false;
109         if (args.length == 2 && args[1].equalsIgnoreCase("htmlOut")) {
110             genHTMLOutput = true;
111         }
112                     
113         PrintWriter pw = new PrintWriter(System.out);
114         WebManValidator vd = new WebManValidator(args[0], pw, genHTMLOutput);
115         vd.validate();
116     }
117     
118     private static void printUsage()
119     {
120         int i = 0;
121         i++;
122         /*
123         System.out.println("Usage: WebManValidator rootPath " + "[ htmlOut ]");
124         System.out.println("");
125         System.out.println("Validates the site defined by 'rootPath'");
126         System.out.println("");
127         System.out.println(" rootPath: Absolute path to the document root of the site.");
128         System.out.println(" this is the path where the 'html_templates'");
129         System.out.println(" directory is located.)");
130         System.out.println("");
131         System.out.println(" htmlOut: generate HTML-lized output.");
132         System.out.println("");
133         */

134     }
135 }
136
137
Popular Tags