1 package org.opensync.importexport;
2
3 import java.sql.Connection;
4 import java.sql.SQLException;
5
6 import org.opensync.tools.ConnectionPool;
7 import org.opensync.tools.DbFile;
8 import org.opensync.tools.PoolManager;
9 import org.opensync.tools.ThemesReference;
10 import org.opensync.tools.Utils;
11
12
13 /***
14 * When running CreateXmlFiles(), the files get created in the directory where you run java.
15 * Sample command line to run this program:
16 * java -classpath D:\cvs\magellan\src\sophieWeb\web\WEB-INF\classes;D:\cvs\magellan\src\sophieWeb\web\WEB-INF\lib\Piccolo.jar;D:\cvs\magellan\src\sophieWeb\web\WEB-INF\lib\saxon7.jar;D:\cvs\magellan\src\sophieWeb\web\WEB-INF\lib\xercesImpl.jar;D:\cvs\magellan\src\sophieWeb\web\WEB-INF\lib\oracleDriver.jar org.opensync.importexport.Test
17 * Make sure you change m_sConnectionsFile and m_sTablesFile to point at the proper files.
18 */
19
20 public class Test {
21
22 private ViewXml viewXml;
23 private DbFile dbfile;
24 private ThemesReference themesref;
25 private boolean m_bConnectionValid = false;
26 private ConnectionPool m_ConnectionPool = null;
27 private String m_sConnectionsFile = "D://cvs//magellan//src//sophieWeb//web//WEB-INF//config//connections.xml";
28 private String m_sTablesFile = "D://cvs//magellan//src//openSync//resources//etc//table//sophieDemo//tables.xml";
29
30 /***
31 * Constructor
32 */
33 public Test() {
34 }
35
36 public void InitConnectionPool() {
37 try {
38 PoolManager poolMgr = PoolManager.getInstance();
39 Utils.setDebug(false);
40 poolMgr.setConnectionPropertiesFile(m_sConnectionsFile);
41 poolMgr.setLogfile("Sophieweb.log");
42 poolMgr.init();
43 Connection conn = null;
44 m_ConnectionPool = poolMgr.getConnectionPool("sophieConnection");
45 if (m_ConnectionPool != null) {
46 conn = m_ConnectionPool.getConnection();
47 if (conn != null) {
48 m_bConnectionValid = true;
49 try {conn.close();}
50 catch (SQLException e) {
51 e.printStackTrace();
52 }
53 finally {
54 conn.close();
55 }
56 }
57 }
58 }catch (Exception ex) {
59 ex.printStackTrace();
60 }
61 }
62
63 /***
64 * Run import/export
65 */
66 public void ImportExport(){
67 try{
68 InitConnectionPool();
69
70 System.out.println("Start Init Tables.xml");
71 dbfile = new DbFile(m_sTablesFile);
72 System.out.println("End Init Tables.xml");
73
74 System.out.println("Start Init Themes.xml");
75 themesref = new ThemesReference(dbfile);
76 themesref.processThemeXml("themes.xml");
77 System.out.println("End Init Themes.xml");
78
79 System.out.println("Start Init query.......");
80 viewXml = new ViewXml("query_B_EQ1996.xml",dbfile,themesref);
81 ExportOfView exportOfView = new ExportOfView(m_ConnectionPool, viewXml.getView(viewXml.getKeyWordOfView()), null);
82 String xml = exportOfView.getDataListXml();
83 System.out.println(xml);
84
85
86
87
88 }
89 catch (Exception ex) {
90 ex.printStackTrace();
91 }
92 }
93
94 /***
95 * Create theme.xml, mappings, queries, and config file.
96 */
97 public void CreateXmlFiles(){
98 try{
99 System.out.println("Test::CreateXmlFiles - begin");
100 InitConnectionPool();
101 System.out.println("Test::CreateXmlFiles - reading tables.xml");
102 dbfile = new DbFile(m_sTablesFile);
103 System.out.println("Test::CreateXmlFiles - initializing CreateXmlFiles");
104 CreateXmlFiles xmlFiles = new CreateXmlFiles(m_ConnectionPool,dbfile,"sophieDemo");
105 System.out.println("Test::CreateXmlFiles - creating xml files");
106 xmlFiles.createConfigSyncXml();
107 xmlFiles.createThemesXml();
108 xmlFiles.createAllQueryXml();
109 xmlFiles.createAllMappingXml();
110 xmlFiles.createAllDescriptorsXml();
111 System.out.println("Test::CreateXmlFiles - end");
112 }
113 catch (Exception ex){
114 ex.printStackTrace();
115 }
116 }
117
118 /***
119 * main
120 * @param args
121 */
122 public static void main(String[] args) {
123 Test test = new Test();
124
125 test.CreateXmlFiles();
126 }
127 }
128