001: package de.webman.content.eventhandler;
002:
003: import com.teamkonzept.web.*;
004: import com.teamkonzept.webman.*;
005: import com.teamkonzept.webman.db.TKWebmanDBManager;
006: import com.teamkonzept.webman.mainint.*;
007: import com.teamkonzept.webman.mainint.db.*;
008: import com.teamkonzept.webman.mainint.db.queries.*;
009: import com.teamkonzept.webman.mainint.events.*;
010: import com.teamkonzept.lib.*;
011: import com.teamkonzept.field.*;
012: import com.teamkonzept.field.db.*;
013: import com.teamkonzept.db.*;
014: import com.teamkonzept.publishing.markups.*;
015:
016: import java.sql.*;
017: import java.io.*;
018:
019: /**
020: * Exportieren von Content
021: * @author $Author: alex $
022: * @version $Revision: 1.6 $
023: */
024: public class CEExportHandler extends DefaultEventHandler implements
025: ParameterTypes, FrameConstants, DatabaseDefaults {
026: private CEExportHandler() {
027: }
028:
029: private static CEExportHandler instance = new CEExportHandler();
030:
031: public static CEExportHandler getInstance() {
032: return instance;
033: }
034:
035: public void handleEvent(TKEvent evt) throws TKException {
036: try {
037: /*
038: CEUtils.checkEvent(evt);
039:
040: TKHTMLTemplate t = evt.getPrepHTMLTemplate( "ce_fields.tmpl" );
041: ContentContext ceContext = CEUtils.keepCEContext( evt, t );
042:
043: TKFormDBData data = new TKFormDBData( ceContext.formId.intValue() );
044: TKFormDBInterface.Get( data );
045: TKBaseField field = TKFieldRegistry.getFieldFromDB( data );
046: TKHashtable fieldContext = new TKHashtable();
047:
048: Object realData = field.compileData( "", evt.getParams().getClass( PARAMETER ), fieldContext );
049:
050: field.fillIntoTemplate( t, realData, "" );
051:
052: evt.finishTemplate(t);
053:
054: TKHashtable pathes = TKContentPathes.getContentPathes();
055: int nodeId = ceContext.conNodeType.intValue() == GROUP_INTEGER.intValue() ? ceContext.groupConNodeId : ceContext.conNodeId;
056:
057: String contentPath = (String) pathes.get (new Integer (nodeId));
058: String contentFn = ceContext.conNodeShortName;
059:
060: if (contentPath == null)
061: {
062: return;
063: }
064:
065: if (ceContext.conNodeType.intValue() == SINGLE_INTEGER.intValue()) {
066:
067: File fullPath = new File ((contentPath).replace ('/',File.separatorChar));
068: contentFn = fullPath.getName();
069: contentPath = fullPath.getParent();
070: }
071:
072: TKMarkupAdmin.setup();
073: TKHTMLTemplate tt = evt.getPrepHTMLTemplate( "export/ce_fields.tmpl" );
074: ceContext.fillIntoTemplate (tt);
075: field.fillIntoTemplate( tt, realData, "" );
076: tt.doTagSubstitution();
077:
078: String baseDir = (evt.getHttpInterface().getDocumentRoot()+"/export/content/"+contentPath)
079: .replace ('/',File.separatorChar);
080:
081: File expDir = new File( baseDir );
082:
083: if( expDir.exists() ) {
084: if( !expDir.isDirectory() ) {
085: return ;
086: }
087:
088: } else if( !expDir.mkdirs() ) {
089: return ;
090: }
091:
092: File outFile = new File( expDir, contentFn+".xml" );
093: FileOutputStream f = new FileOutputStream( outFile );
094: PrintStream outf = new PrintStream(f);
095: tt.printTemplate( outf );
096: outf.close();
097: */
098: throw new RuntimeException("Event not implemented : "
099: + evt.getName());
100:
101: } catch (Throwable e) {
102: // TO DO : Analyze Exception !
103: throw WebmanExceptionHandler.getException(e);
104: }
105: }
106:
107: public boolean isHandler(TKEvent evt) {
108: return evt.getName().equalsIgnoreCase("CE_EXPORT");
109: }
110: }
|