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 import java.io.*; 11 12 19 public class TEUpdateHandler extends DefaultEventHandler implements ParameterTypes, FrameConstants { 20 private TEUpdateHandler() 21 {} 22 23 private static TEUpdateHandler instance = new TEUpdateHandler(); 24 25 public static TEUpdateHandler getInstance() 26 { 27 return instance; 28 } 29 public void handleEvent(TKEvent evt) throws TKException 30 { 31 try 32 { 33 36 String tmplId = evt.getParameter( PARAMETER, "TEMPLATE_ID" ); 37 String tmplName = evt.getParameter( PARAMETER, "TEMPLATE_NAME" ); 39 if (!TEUtils.isValidTemplateName(tmplName)) 41 { 42 throw new TKUserException("Ungueltiger Name", WRONG_TEMPLATE_NAME, USER_SEVERITY, false, null); 43 } 44 String tmplOldName = null; 46 tmplOldName = evt.getParameter( PARAMETER, "TEMPLATE_OLD_NAME" ); 47 String tmplCopyName = null; 49 tmplCopyName = evt.getParameter( PARAMETER, "TEMPLATE_COPY_NAME" ); 50 51 if( tmplOldName != null ) 52 { 53 File dateiOrig = new File(evt.getHttpInterface().getDocumentRoot() +File.separator + TemplateUtils.getGenerationDirectory() + tmplOldName ); 56 File dateiNew = new File(evt.getHttpInterface().getDocumentRoot() +File.separator + TemplateUtils.getGenerationDirectory() + tmplName ); 57 58 dateiOrig.renameTo(dateiNew); 60 61 TKQuery q = TKDBManager.newQuery(TKDBTmplUpdate.class); 63 q.setQueryParams( "TEMPLATE_ID", new Integer ( tmplId ) ); 64 q.setQueryParams( "TEMPLATE_NAME", tmplName ); 65 q.execute(); 66 q.fetchResultSet(); 67 } 68 else if( tmplCopyName != null ) 69 { 70 File dateiOld = new File(evt.getHttpInterface().getDocumentRoot() +File.separator + TemplateUtils.getGenerationDirectory() + tmplCopyName ); 72 File dateiNew = new File(evt.getHttpInterface().getDocumentRoot() +File.separator + TemplateUtils.getGenerationDirectory() + tmplName ); 73 FileReader in = new FileReader(dateiOld); 74 FileWriter out = new FileWriter(dateiNew); 75 int c; 77 while ((c = in.read()) != -1) 78 { 79 out.write(c); 80 } 81 in.close(); 82 out.close(); 83 84 TKQuery query = TKDBManager.newQuery(TKDBTmplNew.class); 86 query.setQueryParams( "TEMPLATE_NAME", tmplName ); 87 query.execute(); 88 query.fetchResultSet(); 89 } 90 91 TKHTMLTemplate frame = evt.getPrepHTMLTemplate( "f_te.tmpl" ); 92 HTMLUtils.fillFrameSet( frame, LEFT_FRAME_WIDTH_SMALL, "TE_SHOWLIST", "EMPTY" ); 93 WebManEvent.fillEventsIntoTemplate(evt.getRemoteUser(), frame, ContextConstants.TEMPLATES); 94 evt.finishTemplate(frame); 95 } 96 catch (Throwable t) 97 { 98 throw WebmanExceptionHandler.getException(t); 99 } 100 101 } 102 public boolean isHandler(TKEvent evt) 103 { 104 return evt.getName().equalsIgnoreCase("TE_UPDATE"); 105 } 106 } 107 | Popular Tags |