KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > WMExportContents


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 /**
22  * @author $Author: mischa $
23  * @version $Revision: 1.10 $
24 */

25 public class WMExportContents {
26
27
28     public static void main( String JavaDoc[] args ) throws Exception JavaDoc
29     {
30
31         if (args.length < 2)
32         {
33             return;
34         }
35
36         String JavaDoc docRoot = args[0];
37         String JavaDoc exportDir = args[1];
38
39         TKWebmanDBManager.initConnection("/webmandb.ini", false);
40         //TKWebmanInit.init(docRoot);
41
TKUploadField.initStaticsForUpload(docRoot);
42         //headers.put( "Content-type", "text/plain" );
43

44         try {
45             registerAllFields();
46
47             GeneratorContext.setup ();
48
49             String JavaDoc cmd = null;
50             String JavaDoc par = null;
51
52             if (args.length > 1) {
53
54                 /* Das hier geht bei einigen Release-St„nden in die Hose ...
55
56                 MessageFormat mf = new MessageFormat("{0}={1}");
57                 Object[] objs = mf.parse(args[1],new ParsePosition(0));
58
59                 if (objs != null) {
60                     cmd = objs.length > 0 ? ((String) objs[0]) : null;
61                     par = objs.length > 1 ? ((String) objs[1]) : null;
62                 } */

63
64                 String JavaDoc 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                 // int leftNr = rs.getInt( "LEFT_NR" );
83
// int rightNr = rs.getInt( "RIGHT_NR" );
84

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 JavaDoc contentPath = (String JavaDoc) pathes.get (new Integer JavaDoc (contentNodeId));
90
91                 String JavaDoc nodeName = rs.getString( "CONTENT_NODE_NAME" );
92                 String JavaDoc 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 JavaDoc 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                 /* TKContentDBData cdata = new TKContentDBData( contentId );
121                 */

122                 TKContentDBData cdata = null;
123                 TKContentDBInterface.Get( cdata );
124                 Object JavaDoc 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 JavaDoc (nodeType));
133                 tt.set( "CONTENT_NODE_ID", new Integer JavaDoc (contentNodeId) );
134                 tt.set( "CONTENT_FORM", new Integer JavaDoc (formId) );
135
136                 field.fillIntoTemplate( tt, contentData, "" );
137                 tt.doTagSubstitution();
138
139                 String JavaDoc 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 JavaDoc e ) {
160             TKWebmanDBManager.deregister( true );
161             e.printStackTrace( System.out );
162         }
163
164         TKWebmanDBManager.deregister( false );
165     }
166
167     //***************************************************************************
168
public static void registerAllFields() throws Throwable JavaDoc
169     {
170
171         //---- Die Tabelle FIELD_CLASS ausleisen und in einem Vector speichern ----//
172
TKQuery q = TKWebmanDBManager.newQuery(TKDBFormFieldClassGet.class);
173         q.execute();
174         ResultSet rs = q.fetchResultSet();
175
176         //---- FIELD_TYPE = CLASS_ID FIELD_CLASS = PATH ----//
177
TKVector classVector = new TKVector();
178         while(rs.next()){
179             String JavaDoc rowArray[] = { rs.getString("FIELD_TYPE"), rs.getString("FIELD_CLASS") };
180             classVector.addElement(rowArray);
181         }
182
183         //---- Alle Fields registrieren ----//
184
for (int i=0; i < classVector.size(); i++) {
185             Object JavaDoc element = classVector.elementAt(i);
186             String JavaDoc classInfoArray[] = (String JavaDoc[]) element;
187             //TKHttp.out() .println("<br><b>CLASS_ID:</b>"+classInfoArray[0]+" | <b>PATH:</b>"+classInfoArray[1]);
188

189             TKFieldRegistry.registry.registerClass(classInfoArray[0], classInfoArray[1]);
190         }
191
192     }
193
194 }
195
Popular Tags