1 package de.webman.template.eventhandler; 2 3 import java.io.*; 4 import java.sql.*; 5 import com.teamkonzept.db.*; 6 import com.teamkonzept.webman.WebManEvent; 7 import com.teamkonzept.lib.*; 8 import com.teamkonzept.lib.templates.*; 9 import com.teamkonzept.webman.mainint.events.*; 10 import com.teamkonzept.webman.mainint.*; 11 import com.teamkonzept.web.*; 12 import com.oroinc.text.regex.*; 13 import com.teamkonzept.webman.mainint.db.queries.template.CheckTemplateDependency; 14 import com.teamkonzept.webman.mainint.db.queries.template.CheckTemplateExists; 15 16 22 public class TEUtils implements TemplateTypes, UserCodes, ParameterTypes 23 { 24 33 public static boolean showSavedText( TKEvent evt ) throws Throwable , FileNotFoundException 34 { 35 try 36 { 37 TKHTMLTemplate t = evt.getPrepHTMLTemplate( "te_editTmpl.tmpl" ); 38 String tmplName = evt.getParameter( PARAMETER, "TEMPLATE_NAME" ); 39 String tmplId = evt.getParameter( PARAMETER, "TEMPLATE_ID" ); 40 t.set( "TEMPLATE_NAME", tmplName ); 41 t.set( "TEMPLATE_ID", tmplId ); 42 43 String s = TKTemplateCache.getSource("file://"+ evt.getHttpInterface().getDocumentRoot() + File.separator + TemplateUtils.getGenerationDirectory() + tmplName); 45 t.set("TEMPLATE_TEXT", s); 46 47 WebManEvent.fillEventsIntoTemplate(evt.getRemoteUser(), t, ContextConstants.TEMPLATES); 48 evt.finishTemplate(t); 49 } 50 catch (Throwable e) 51 { 52 throw WebmanExceptionHandler.getException(e); 53 } 54 return true; 55 } 56 64 public static boolean isValidTemplateName( String name ) throws TKException, Throwable 65 { 66 try 67 { 68 String cName = name.toUpperCase(); 69 isValidName(name ); 71 return cName.endsWith(TK_TEMPLATE) || cName.endsWith(JSP_TEMPLATE) || cName.endsWith(XSLT_TEMPLATE); 72 } 73 catch (Throwable e) 74 { 75 throw WebmanExceptionHandler.getException(e); 76 } 77 } 78 79 public static boolean isValidName( String name ) throws Throwable 80 { 81 if( name == null || name.equals( "" ) ) 82 { 83 throw new TKUserException("Es muß ein Name angegeben werden", NO_PATHNAME, USER_SEVERITY, true, null); 85 } 86 87 PatternMatcher matcher = TKReg.getMatcher(); 88 PatternCompiler compiler = TKReg.getCompiler(); 89 Pattern patNotAllowed; 90 91 patNotAllowed = compiler.compile( "[^a-zA-Z_0-9\\-./]" ); 94 if( matcher.contains( name, patNotAllowed ) ) 95 { 96 throw new TKUserException("Kein gültiger Pfadname: " + name, NO_VALID_PATHNAME, USER_SEVERITY, true, null); 98 } else { 99 return true; 100 } 101 } 102 103 112 public static boolean templateNameExists ( String name ) throws Throwable 113 { 114 TKQuery q = TKDBManager.newQuery(CheckTemplateExists.class); 115 q.setQueryParams( "TEMPLATE_NAME", name ); 116 q.execute(); 117 ResultSet rs = q.fetchResultSet(); 118 if (rs.next()) 119 { return true; 121 } 122 else 123 { return false; 125 } 126 } 127 128 136 public static TKVector getDependencies(Integer templateId) throws SQLException 137 { 138 TKVector references = new TKVector(); 139 140 TKQuery q = TKDBManager.newQuery(CheckTemplateDependency.class); 141 q.setQueryParams( "TEMPLATE_ID", templateId ); 142 q.execute(); 143 ResultSet rs = q.fetchResultSet(); 144 while (rs.next()) 145 { 146 TKHashtable temp = new TKHashtable(); 147 String name = rs.getString("PRESENTATION_NAME"); 148 temp.put("REF2", name ); 149 references.addElement(temp); 150 } 151 return references; 152 } 153 } 154 | Popular Tags |