1 package de.webman.template.eventhandler; 2 3 import com.teamkonzept.db.*; 4 import com.teamkonzept.webman.mainint.db.queries.*; 5 import com.teamkonzept.webman.mainint.events.*; 6 import com.teamkonzept.webman.mainint.*; 7 import com.teamkonzept.webman.*; 8 import com.teamkonzept.web.*; 9 import com.teamkonzept.lib.*; 10 11 import java.sql.*; 12 import java.io.*; 13 14 21 public class TESaveHandler extends DefaultEventHandler implements FrameConstants, ParameterTypes 22 { 23 private TESaveHandler() 24 {} 25 26 private static TESaveHandler instance = new TESaveHandler(); 27 28 30 31 public static TESaveHandler getInstance() 32 { 33 return instance; 34 } 35 36 46 public void handleEvent(TKEvent evt) throws TKException 47 { 48 try 49 { 50 String tmplName = evt.getParameter( PARAMETER, "TEMPLATE_NAME" ); 51 if (!TEUtils.isValidTemplateName(tmplName)) 52 throw new TKUserException("Ungueltiger Name", WRONG_TEMPLATE_NAME, USER_SEVERITY, true, null); 53 if(TEUtils.templateNameExists(tmplName)) 55 throw new TKUserException("Name schon vergeben", DUPLICATE_PATHNAME, USER_SEVERITY, true, null); 56 57 TKQuery q = TKDBManager.newQuery(TKDBTmplNew.class); 59 q.setQueryParams( "TEMPLATE_NAME", tmplName ); 60 q.execute(); 61 62 String tempID = null; 63 String tempname = null; 64 ResultSet rs = q.fetchResultSet(); 65 if (rs.next()) 66 { 67 tempID = Integer.toString(rs.getInt("TEMPLATE_ID")); 68 tempname = rs.getString("TEMPLATE_NAME"); 69 } 70 71 72 String path = evt.getHttpInterface().getDocumentRoot() + File.separator + TemplateUtils.getGenerationDirectory() + tmplName; 75 path = path.replace ('/',File.separatorChar); 76 int last = path.lastIndexOf(File.separatorChar); 78 if(last != -1) 79 { 80 String dirs = path.substring(0, last); 82 File f = new File(dirs); 84 f.mkdirs(); 85 } 86 87 try 88 { 89 File file = new File(path); 91 file.createNewFile(); 92 } 93 catch (IOException ioe) 94 { 95 throw WebmanExceptionHandler.getException(ioe); 96 } 97 catch (SecurityException se) 98 { 99 throw WebmanExceptionHandler.getException(se); 100 } 101 102 TKHTMLTemplate frame = evt.getPrepHTMLTemplate( "f_te.tmpl" ); 103 HTMLUtils.fillFrameSet( frame, LEFT_FRAME_WIDTH_SMALL, "TE_SHOWLIST", "TE_EDIT" ); 104 frame.set("TEMPLATE_ID", tempID); 106 frame.set("TEMPLATE_NAME", tempname); 107 frame.set( evt.getParams().getClass( PARAMETER ) ); 108 WebManEvent.fillEventsIntoTemplate(evt.getRemoteUser(), frame, ContextConstants.TEMPLATES); 109 evt.finishTemplate(frame); 110 } 111 catch (Throwable e) 112 { 113 throw WebmanExceptionHandler.getException(e); 114 } 115 } 116 123 public boolean isHandler(TKEvent evt) 124 { 125 return evt.getName().equalsIgnoreCase("TE_SAVE"); 126 } 127 } 128 | Popular Tags |