1 package de.webman.generator; 2 3 import java.io.*; 4 import java.sql.*; 5 6 import com.teamkonzept.lib.*; 7 import com.teamkonzept.db.*; 8 import com.teamkonzept.field.TKUploadField; 10 import com.teamkonzept.webman.db.TKWebmanDBManager; 11 import org.apache.log4j.Category; 12 import de.webman.content.Content; 13 import de.webman.util.log4j.WebmanCategory; 14 36 public class SiteTreeValidator implements SiteTreeVisitor 37 { 38 39 40 private static WebmanCategory cat = (WebmanCategory)WebmanCategory.getInstance(SiteTreeValidator.class); 41 42 private String docRootPath; 43 private String templatePath; 44 private int numErrors; 45 private int numWarnings; 46 47 52 public SiteTreeValidator (String docRootPath, String templatePath) 53 { 54 this.docRootPath = docRootPath; 55 this.templatePath = templatePath; 56 } 57 58 61 public void initDB() throws TKException 62 { 63 TKWebmanDBManager.initConnection("/webmandb.ini", false); 64 TKUploadField.initStaticsForUpload(docRootPath); 66 } 67 68 74 public void deinitDB(boolean doClose) throws TKException 75 { 76 try 77 { 78 TKWebmanDBManager.deregister(doClose); 79 } 80 catch (SQLException sqle) 81 { 82 throw new TKSQLError(sqle); 83 } 84 } 85 86 90 public void validate () throws Throwable 91 { 92 GeneratorContext context = GeneratorContext.setup(); 93 SiteNode site; 94 try 95 { 96 site = context.siteNodes.buildSiteTree(); 97 } 98 catch (Throwable t) 99 { 100 cat.error("Unable to complete validation due to the following error:", t); 101 throw t; 102 } 103 apply(site); 104 } 105 106 110 public void apply(SiteNode node) 111 { 112 if (node == null) 113 return; 114 115 numErrors = 0; 116 numWarnings = 0; 117 118 try 119 { 120 node.accept(this); 121 } 122 catch (Exception e) 123 { 124 cat.warn("SiteTreeValidator.apply ", e); 125 } 126 cat.info("...validation finished with " + numErrors 127 + " errors and " + numWarnings + " warnings"); 128 } 129 130 public void visitSiteNode(SiteNode node) throws Exception 131 { 132 node.getLevel(); 134 } 135 136 public void visitSiteDocument(SiteDocument doc) throws Exception 137 { 138 checkTemplate(doc); 139 140 for (int i = 0; i < doc.getContents().size(); ++i) 141 { 142 checkContent((SiteContentIntegration) doc.getContents().elementAt(i)); 143 } 144 } 145 146 private void checkTemplate(SiteDocument doc) 147 { 148 String templateName = templatePath + File.separator + doc.getTemplateName(); 149 150 try 151 { 152 FileReader fis = new FileReader(templateName); 153 if (fis.ready() == false) 154 throw new IOException(); 155 fis.close(); 156 } 157 catch (FileNotFoundException e) 158 { 159 cat.error("Error: Unable to find template " 160 + templateName + " used by document " + doc.getPath()); 161 } 162 catch (IOException e) 163 { 164 cat.error("Error: Unable to read from file " 165 + templateName + " used by document " + doc.getPath()); 166 } 167 } 168 169 private void checkContent(SiteContentIntegration contentInt) 170 { 171 if (contentInt == null) 172 { 173 return; 174 } 175 176 SiteContentNode contentNode = contentInt.getContentNode(); 177 if (contentNode == null) 178 { 179 return; 180 } 181 for (int i = 0; i < contentNode.getContents().size(); ++i) 183 { 184 SiteContent content = (SiteContent) contentNode.getContents().elementAt(i); 185 if (content.isGeneratableVersion()) { 186 return; } 188 } 189 190 if (contentNode.getType() == SiteContentNode.NODE_TYPE_GROUP) 191 { 192 cat.warn("Warnung: Group Content " + contentNode.getShortName() + " attached to presentation component " 193 + contentInt.getShortName() + " of site document " + contentInt.getSourceDocument().path() 194 + " does not contain any released or valid version", WebmanCategory.ALL); 195 } 196 else 197 { 198 cat.error("Error: Single Content " + contentNode.getShortName() + " attached to presentation component " 199 + contentInt.getShortName() + " of site document " + contentInt.getSourceDocument().path() 200 + " is not a released version", WebmanCategory.ALL); 201 } 202 } 203 204 } 205 | Popular Tags |