1 import com.teamkonzept.lib.*; 2 import com.teamkonzept.publishing.markups.*; 3 4 import com.teamkonzept.web.*; 5 import com.teamkonzept.field.*; 6 import com.teamkonzept.field.db.*; 7 8 import com.teamkonzept.db.*; 9 10 import com.teamkonzept.webman.*; 11 import com.teamkonzept.webman.db.*; 12 import com.teamkonzept.webman.db.queries.*; 13 import de.webman.generator.*; 14 import com.teamkonzept.field.db.queries.*; 15 16 import java.io.*; 17 import java.util.*; 18 import java.sql.*; 19 import java.text.*; 20 21 25 public class WMExportContents { 26 27 28 public static void main( String [] args ) throws Exception 29 { 30 31 if (args.length < 2) 32 { 33 return; 34 } 35 36 String docRoot = args[0]; 37 String exportDir = args[1]; 38 39 TKWebmanDBManager.initConnection("/webmandb.ini", false); 40 TKUploadField.initStaticsForUpload(docRoot); 42 44 try { 45 registerAllFields(); 46 47 GeneratorContext.setup (); 48 49 String cmd = null; 50 String par = null; 51 52 if (args.length > 1) { 53 54 63 64 String arg = args[1]; 65 int pos = arg.indexOf ("="); 66 if ((pos > 0) && (pos < arg.length()-1)) { 67 68 cmd = arg.substring (0,pos).trim(); 69 par = arg.substring (pos+1,arg.length()).trim(); 70 } 71 } 72 73 74 TKHashtable pathes = TKContentPathes.getContentPathes(); 75 76 TKQuery q = TKWebmanDBManager.newQuery(TKDBContentDir.class); 77 q.execute(); 78 ResultSet rs = q.fetchResultSet(); 79 80 while( rs.next() ) { 81 82 85 int contentNodeId = rs.getInt( "CONTENT_NODE_ID" ); 86 int formId = rs.getInt( "CONTENT_FORM" ); 87 int nodeType = rs.getInt( "CONTENT_NODE_TYPE" ); 88 89 String contentPath = (String ) pathes.get (new Integer (contentNodeId)); 90 91 String nodeName = rs.getString( "CONTENT_NODE_NAME" ); 92 String nodeShortName = rs.getString( "CONTENT_NODE_SHORTNAME" ); 93 94 if (contentPath == null) { 95 96 continue; 97 } 98 99 File fullPath = new File ((contentPath).replace ('/',File.separatorChar)); 100 String contentFn = fullPath.getName(); 101 contentPath = fullPath.getParent(); 102 103 if (contentPath == null) { 104 105 continue; 106 } 107 108 if (contentFn == null) { 109 110 continue; 111 } 112 113 if (nodeName == null) nodeShortName = ""; 114 if (nodeShortName == null) nodeShortName = ""; 115 116 TKFormDBData data = new TKFormDBData( formId ); 117 TKFormDBInterface.Get( data ); 118 TKBaseField field = TKFieldRegistry.getFieldFromDB( data ); 119 120 122 TKContentDBData cdata = null; 123 TKContentDBInterface.Get( cdata ); 124 Object contentData = field.getDataFromDB( cdata ); 125 126 TKMarkupAdmin.setup(); 127 128 TKHTMLTemplate tt = 129 new TKHTMLTemplate( "file:"+docRoot+"/templates/export/ce_fields.tmpl" ); 130 131 tt.set( "CONTENT_NODE_NAME", nodeName ); 132 tt.set( "CONTENT_NODE_TYPE", new Integer (nodeType)); 133 tt.set( "CONTENT_NODE_ID", new Integer (contentNodeId) ); 134 tt.set( "CONTENT_FORM", new Integer (formId) ); 135 136 field.fillIntoTemplate( tt, contentData, "" ); 137 tt.doTagSubstitution(); 138 139 String baseDir = (exportDir+"/"+contentPath).replace ('/',File.separatorChar); 140 File expDir = new File( baseDir ); 141 142 if( expDir.exists() ) { 143 if( !expDir.isDirectory() ) { 144 continue; 145 } 146 147 } else if( !expDir.mkdirs() ) { 148 continue; 149 } 150 151 File outFile = new File( expDir, contentFn+".xml" ); 152 153 FileOutputStream f = new FileOutputStream( outFile ); 154 PrintStream outf = new PrintStream(f); 155 tt.printTemplate( outf ); 156 outf.close(); 157 } 158 } 159 catch( Throwable e ) { 160 TKWebmanDBManager.deregister( true ); 161 e.printStackTrace( System.out ); 162 } 163 164 TKWebmanDBManager.deregister( false ); 165 } 166 167 public static void registerAllFields() throws Throwable 169 { 170 171 TKQuery q = TKWebmanDBManager.newQuery(TKDBFormFieldClassGet.class); 173 q.execute(); 174 ResultSet rs = q.fetchResultSet(); 175 176 TKVector classVector = new TKVector(); 178 while(rs.next()){ 179 String rowArray[] = { rs.getString("FIELD_TYPE"), rs.getString("FIELD_CLASS") }; 180 classVector.addElement(rowArray); 181 } 182 183 for (int i=0; i < classVector.size(); i++) { 185 Object element = classVector.elementAt(i); 186 String classInfoArray[] = (String []) element; 187 189 TKFieldRegistry.registry.registerClass(classInfoArray[0], classInfoArray[1]); 190 } 191 192 } 193 194 } 195 | Popular Tags |