001: /*
002: * Created on 8-Jul-2004
003: *
004: * TODO To change the template for this generated file go to
005: * Window - Preferences - Java - Code Style - Code Templates
006: */
007: package com.pk;
008:
009: import java.io.IOException;
010:
011: import javax.swing.LookAndFeel;
012:
013: import org.apache.commons.digester.Digester;
014: import org.xml.sax.SAXException;
015:
016: /**
017: * @author ctaylor
018: *
019: * TODO To change the template for this generated type comment go to Window -
020: * Preferences - Java - Code Style - Code Templates
021: */
022: public class ConfigDigester {
023: private Config tmpConfig = null;
024:
025: private String fileName = null;
026:
027: public Config createConfig() throws IOException, SAXException {
028: tmpConfig = new Config();
029: Digester digester = new Digester();
030:
031: digester.push(this );
032:
033: digester.addCallMethod("config/datasources/datasource",
034: "addDataSource", 4);
035: digester.addCallParam("config/datasources/datasource/name", 0);
036: digester
037: .addCallParam("config/datasources/datasource/driver", 1);
038: digester.addCallParam("config/datasources/datasource/url", 2);
039: digester.addCallParam(
040: "config/datasources/datasource/databaseDialectName", 3);
041: digester.addCallMethod("config/export/delimiterChar",
042: "setDelimiterChar", 1);
043: digester.addCallParam("config/export/delimiterChar", 0);
044: digester.addCallMethod("config/export/encloseByChar",
045: "setEncloseByChar", 1);
046: digester.addCallParam("config/export/encloseByChar", 0);
047: digester.addCallMethod("config/export/useCdata", "setUseCdata",
048: 1);
049: digester.addCallParam("config/export/useCdata", 0);
050: digester.addCallMethod("config/export/headerColor",
051: "setHeaderColor", 1);
052: digester.addCallParam("config/export/headerColor", 0);
053: digester.addCallMethod("config/export/borderColor",
054: "setBorderColor", 1);
055: digester.addCallParam("config/export/borderColor", 0);
056: digester.addCallMethod("config/export/altRowColor",
057: "setAltRowColor", 1);
058: digester.addCallParam("config/export/altRowColor", 0);
059: digester.addCallMethod("config/general/lafs/laf",
060: "addLookandFeel", 2);
061: digester.addCallParam("config/general/lafs/laf/class", 0);
062: digester.addCallParam("config/general/lafs/laf/selected", 1);
063: digester.addCallMethod("config/general/history",
064: "setHistoryMode", 1);
065: digester.addCallParam("config/general/history/mode", 0);
066:
067: digester.parse(fileName);
068: tmpConfig.orderConnections();
069: return tmpConfig;
070: }
071:
072: public void addDataSource(String name, String driver, String url,
073: String databaseDilectName) {
074: ConnectionConfig tmp = new ConnectionConfig();
075: tmp.setName(name);
076: tmp.setDriver(driver);
077: tmp.setUrl(url);
078: tmp.setDatabaseDialectName(databaseDilectName);
079: tmpConfig.addConnectionConfig(tmp);
080: }
081:
082: public void setDelimiterChar(String argDelimiterChar) {
083: tmpConfig.setExportDelimiterChar(argDelimiterChar);
084: }
085:
086: public void setEncloseByChar(String argEncloseByChar) {
087: tmpConfig.setEncloseByChar(argEncloseByChar);
088: }
089:
090: /**
091: * @return Returns the connectionConfigs.
092: */
093: /**
094: * @return Returns the fileName.
095: */
096: public String getFileName() {
097: return fileName;
098: }
099:
100: /**
101: * @param fileName
102: * The fileName to set.
103: */
104: public void setFileName(String fileName) {
105: this .fileName = fileName;
106: }
107:
108: public void setHeaderColor(String headerColor) {
109: tmpConfig.setHeaderColor(headerColor);
110: }
111:
112: public void setBorderColor(String borderColor) {
113: tmpConfig.setBorderColor(borderColor);
114: }
115:
116: public void setAltRowColor(String altRowColor) {
117: tmpConfig.setAltRowColor(altRowColor);
118: }
119:
120: public void setUseCdata(String useCdata) {
121: if (useCdata != null && useCdata.equalsIgnoreCase("TRUE")) {
122: tmpConfig.setUseCdata(true);
123: } else {
124: tmpConfig.setUseCdata(false);
125: }
126: }
127:
128: public void addLookandFeel(String argClass, String argSelected) {
129: try {
130: Class tmpClass = Class.forName(argClass);
131:
132: tmpConfig.addLookandFeel((LookAndFeel) tmpClass
133: .newInstance());
134: if (argSelected != null
135: && argSelected.equalsIgnoreCase("true")) {
136: tmpConfig.setSelectedLookAndFeel((LookAndFeel) tmpClass
137: .newInstance());
138: }
139: } catch (ClassNotFoundException ex) {
140: ex.printStackTrace();
141: } catch (InstantiationException e) {
142: e.printStackTrace();
143: } catch (IllegalAccessException e) {
144: e.printStackTrace();
145: }
146: }
147:
148: public void setHistoryMode(String argHistoryMode) {
149: int tmpHistoryMode = Config.HISTORY_MODE_ALL;
150: try {
151: tmpHistoryMode = Integer.parseInt(argHistoryMode);
152: } catch (Throwable ex) {
153: tmpHistoryMode = Config.HISTORY_MODE_ALL;
154: }
155: if (tmpHistoryMode != Config.HISTORY_MODE_ALL
156: && tmpHistoryMode != Config.HISTORY_MODE_DIFF_FROM_LAST
157: && tmpHistoryMode != Config.HISTORY_MODE_UNIQUE) {
158: tmpHistoryMode = Config.HISTORY_MODE_ALL;
159: }
160: tmpConfig.setHistoryMode(tmpHistoryMode);
161: }
162:
163: }
|