001: //** Copyright Statement ***************************************************
002: //The Salmon Open Framework for Internet Applications (SOFIA)
003: // Copyright (C) 1999 - 2002, Salmon LLC
004: //
005: // This program is free software; you can redistribute it and/or
006: // modify it under the terms of the GNU General Public License version 2
007: // as published by the Free Software Foundation;
008: //
009: // This program is distributed in the hope that it will be useful,
010: // but WITHOUT ANY WARRANTY; without even the implied warranty of
011: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: // GNU General Public License for more details.
013: //
014: // You should have received a copy of the GNU General Public License
015: // along with this program; if not, write to the Free Software
016: // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: //
018: // For more information please visit http://www.salmonllc.com
019: //** End Copyright Statement ***************************************************
020: package com.salmonllc.servlets;
021:
022: /////////////////////////
023: //$Archive: /SOFIA/SourceCode/com/salmonllc/servlets/DwInfoTranslator.java $
024: //$Author: Dan $
025: //$Revision: 13 $
026: //$Modtime: 10/06/04 3:10p $
027: /////////////////////////
028:
029: import java.io.*;
030: import java.util.*;
031:
032: import javax.servlet.ServletException;
033: import javax.servlet.http.*;
034: import javax.servlet.jsp.tagext.TagInfo;
035:
036: import com.salmonllc.fatwire.UEDataStore;
037: import com.salmonllc.fatwire.UEInfo;
038: import com.salmonllc.jsp.JspController;
039: import com.salmonllc.jsp.JspServlet;
040: import com.salmonllc.jsp.engine.PageContextImpl;
041: import com.salmonllc.jsp.engine.TagLibraryParser;
042: import com.salmonllc.localizer.LanguageResourceFinder;
043: import com.salmonllc.properties.Props;
044: import com.salmonllc.sitemap.SiteMap;
045: import com.salmonllc.sql.*;
046: import com.salmonllc.util.FilterFile;
047: import com.salmonllc.util.MessageLog;
048: import com.salmonllc.xml.XMLTransporter;
049:
050: /**
051: * This Servlet is used to provide server information to Dreamweaver.
052: */
053: public class DwInfoTranslator extends HttpServlet {
054:
055: public static final String INFO_TYPE = "INFOTYPE";
056: public static final String TABLE_NAME = "TABLENAME";
057: public static final String CONTENT_CLASS = "CONTENTCLASS";
058: public static final int DW_INFO_PROP = 1;
059: public static final int DW_INFO_TABLENAME = 2;
060: public static final int DW_INFO_TABLEFIELD = 3;
061: public static final int DW_INFO_UE_CONTENTCLASS = 4;
062: public static final int DW_INFO_UE_CONTENTFIELD = 5;
063: public static final int DW_INFO_XMLFILES = 6;
064: public static final int DW_INFO_XMLFIELDS = 7;
065: public static final int DW_INFO_ATTRIBUTE = 8;
066: public static final int DW_INFO_MODELTABLENAME = 9;
067: public static final int DW_INFO_MODELTABLEFIELD = 10;
068: public static final int DW_INFO_MODELTYPE = 11;
069: public static final int DW_INFO_LANGPREF = 12;
070: public static final int DW_INFO_SITEMAP = 14;
071:
072: private Hashtable _inputType = new Hashtable();
073:
074: public void buildInputType() {
075:
076: _inputType.clear();
077: _inputType.put("button", "com.salmonllc.html.HtmlSubmitButton");
078: _inputType.put("checkbox", "com.salmonllc.html.HtmlCheckBox");
079: _inputType.put("file", "com.salmonllc.html.HtmlFileUpload");
080: _inputType.put("hidden", "com.salmonllc.html.HtmlHiddenField");
081: _inputType.put("image", "com.salmonllc.html.HtmlSubmitImage");
082: _inputType.put("password",
083: "com.salmonllc.html.HtmlPasswordEdit");
084: _inputType.put("radio", "com.salmonllc.html.HtmlRadioButton");
085: _inputType.put("radiobutton",
086: "com.salmonllc.html.HtmlRadioButton");
087: _inputType.put("radiogroup",
088: "com.salmonllc.html.HtmlRadioButtonGroup");
089: _inputType.put("radiogroupbutton",
090: "com.salmonllc.html.HtmlRadioButtonGroup");
091: _inputType.put("select", "com.salmonllc.html.HtmlListBox");
092: _inputType.put("submit", "com.salmonllc.html.HtmlSubmitButton");
093: _inputType.put("text", "com.salmonllc.html.HtmlTextEdit");
094: _inputType.put("textarea",
095: "com.salmonllc.html.HtmlMultiLineTextEdit");
096: _inputType
097: .put("email", "com.salmonllc.html.HtmlEMailComponent");
098: _inputType.put("ssnmulti",
099: "com.salmonllc.html.HtmlSSNComponent");
100: _inputType.put("ssn",
101: "com.salmonllc.html.HtmlSSNSingleComponent");
102: _inputType
103: .put("state", "com.salmonllc.html.HtmlStateComponent");
104: _inputType.put("phone",
105: "com.salmonllc.html.HtmlTelephoneComponent");
106: _inputType
107: .put("zip", "com.salmonllc.html.HtmlZipCodeComponent");
108: _inputType.put("fraction",
109: "com.salmonllc.html.HtmlFractionComponent");
110: _inputType.put("decimal",
111: "com.salmonllc.html.HtmlDecimalComponent");
112: _inputType.put("date", "com.salmonllc.html.HtmlDateComponent");
113:
114: }
115:
116: public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
117: JspServlet.setUpApplicationContext(getServletContext(),req);
118: res.setStatus(HttpServletResponse.SC_OK);
119: int infoType = Integer.parseInt(req.getParameter(INFO_TYPE));
120:
121: String retStr = "";
122:
123: switch (infoType) {
124: case DW_INFO_PROP:
125: {
126: try {
127: String app = req.getParameter("Application");
128: File f = new File(Props.getPropsPath() + File.separatorChar + app + ".properties");
129: FileInputStream in = new FileInputStream(f);
130: Properties p = new Properties();
131: p.load(in);
132: Enumeration enum = p.propertyNames();
133: String property = "";
134: while (enum.hasMoreElements()) {
135: property = (String) enum.nextElement();
136: if (property.endsWith(".StartTag")) {
137: int idx = property.indexOf(".StartTag");
138: retStr += property.substring(0, idx) + ",";
139: }
140: }
141:
142: f = new File(Props.getPropsPath() + File.separatorChar + "System.properties");
143: in = new FileInputStream(f);
144: Properties sys = new Properties();
145: sys.load(in);
146: enum = sys.propertyNames();
147: while (enum.hasMoreElements()) {
148: property = (String) enum.nextElement();
149: if (property.endsWith(".StartTag") && p.getProperty(property) == null) {
150: int idx = property.indexOf(".StartTag");
151: retStr += property.substring(0, idx) + ",";
152: }
153: }
154:
155:
156: res.getOutputStream().print(retStr);
157:
158: } catch (Exception e) {
159: res.setStatus(HttpServletResponse.SC_NOT_FOUND);
160: MessageLog.writeErrorMessage("Error in doGet of DWInfoTranslator.Properties", e, this );
161: }
162: break;
163: }
164: case DW_INFO_TABLENAME:
165: {
166: try {
167: retStr = "";
168: String app = req.getParameter("Application");
169: DataDictionary dataDict = new DataDictionary(app);
170: Vector tableNames = dataDict.getTableNames();
171: for (int i = 0; i < tableNames.size(); i++)
172: retStr += tableNames.elementAt(i) + ",";
173:
174:
175: res.getOutputStream().print(retStr);
176:
177:
178: } catch (Exception e) {
179: res.setStatus(HttpServletResponse.SC_NOT_FOUND);
180: MessageLog.writeErrorMessage("Error in doGet of DWInfoTranslator.Tables", e, this );
181: }
182:
183: break;
184:
185: }
186:
187: case DW_INFO_TABLEFIELD:
188: {
189: try {
190: String tableName = req.getParameter(TABLE_NAME);
191: retStr = "";
192: String app = req.getParameter("Application");
193: DataDictionary dataDict = new DataDictionary(app);
194: Vector fieldNames = dataDict.getColumns(tableName);
195: for (int i = 0; i < fieldNames.size(); i++)
196: retStr += ((ColumnDefinition) fieldNames.elementAt(i)).getColumnName() + ",";
197:
198:
199: res.getOutputStream().print(retStr);
200:
201:
202: } catch (Exception e) {
203: res.setStatus(HttpServletResponse.SC_NOT_FOUND);
204: MessageLog.writeErrorMessage("Error in doGet of DWInfoTranslator.Tables", e, this );
205: }
206:
207: break;
208:
209: }
210: case DW_INFO_UE_CONTENTCLASS:
211: {
212: try {
213: UEInfo _ueInfo = new UEInfo();
214: Vector ccNames = _ueInfo.getContentClasses();
215: retStr = "";
216: for (int i = 0; i < ccNames.size(); i++)
217: retStr += ccNames.elementAt(i) + ",";
218:
219:
220: res.getOutputStream().print(retStr);
221:
222: } catch (Exception e) {
223: res.setStatus(HttpServletResponse.SC_NOT_FOUND);
224: MessageLog.writeErrorMessage("Error in doGet of DWInfoTranslator.UE_CONTENT", e, this );
225: }
226: break;
227: }
228: case DW_INFO_UE_CONTENTFIELD:
229: {
230: try {
231:
232: String ccName = req.getParameter(CONTENT_CLASS);
233:/* UEInfo _ueInfo = new UEInfo();
234:Vector ffNames = _ueInfo.getFieldNames(ccName);
235:retStr="";
236:for (int i=0;i < ffNames.size();i++)
237:retStr += ffNames.elementAt(i) + ",";
238:*/
239: PageContextImpl p = new PageContextImpl();
240: com.salmonllc.html.HttpServletResponseWrapper w = new com.salmonllc.html.HttpServletResponseDummy(res, null);
241: p.initialize(this , req, w, null, true, 128, false);
242: JspController cont = new JspController();
243: cont.setPageContext(p);
244: UEDataStore _ueData = new UEDataStore();
245: _ueData.buildBuffer(cont, ccName, null);
246: for (int i = 0; i < _ueData.getColumnCount(); i++)
247: retStr += _ueData.getColumnName(i) + ",";
248:
249:
250: res.getOutputStream().print(retStr);
251:
252: } catch (Exception e) {
253: res.setStatus(HttpServletResponse.SC_NOT_FOUND);
254: MessageLog.writeErrorMessage("Error in doGet of DWInfoTranslator.UE_CONTENTNAMES", e, this );
255: }
256: break;
257: }
258: case DW_INFO_XMLFILES:
259: {
260: try {
261: String app = req.getParameter("Application");
262: Props p = Props.getProps(app, null);
263:
264: String dataPath = p.getProperty(Props.XML_DATA_PATH);
265: if (dataPath != null) {
266: if (!dataPath.endsWith(File.separator))
267: dataPath += File.separator;
268: }
269: File dir = new File(dataPath);
270: if (!dir.isDirectory()) {
271: res.setStatus(HttpServletResponse.SC_NOT_FOUND);
272: MessageLog.writeDebugMessage("Error in doGet of DWInfoTranslator.XML_FILES.XML Directory Not Found", this );
273: break;
274: }
275: FilterFile filter = new FilterFile(".xml");
276:
277: String[] xmlFiles = dir.list();
278: for (int i = 0; i < xmlFiles.length; i++) {
279: if (filter.accept(dir, xmlFiles[i]))
280: retStr += xmlFiles[i] + ",";
281: }
282:
283:
284: res.getOutputStream().print(retStr);
285:
286: } catch (Exception e) {
287: res.setStatus(HttpServletResponse.SC_NOT_FOUND);
288: MessageLog.writeErrorMessage("Error in doGet of DWInfoTranslator.XML_FILES", e, this );
289: }
290: break;
291: }
292:
293: case DW_INFO_XMLFIELDS:
294: {
295: try {
296:
297: String app = req.getParameter("Application");
298: String xmlDef = req.getParameter("XMLDEF");
299: boolean useFile = new Boolean(req.getParameter("USEFILE")).booleanValue();
300: DataStore _dsXml = new DataStore(app);
301: Props p = Props.getProps(app, null);
302: String dataPath = p.getProperty(Props.XML_DATA_PATH);
303: if (dataPath != null) {
304: if (!dataPath.endsWith(File.separator))
305: dataPath += File.separator;
306: }
307:
308: if (useFile) {
309: File f = new File(dataPath + xmlDef);
310: if (f.exists()) {
311: XMLTransporter.xmlImport(f.getCanonicalPath(), _dsXml);
312: }
313: } else {
314: File f = null;
315: synchronized (this ) {
316: int i = 1;
317: f = new File(dataPath + "_tmpJsp1.xml");
318: while (f.exists()) {
319: f = new File(dataPath + "_tmpJsp" + i + ".xml");
320: i++;
321: }
322: FileOutputStream fout = new FileOutputStream(f);
323: PrintWriter w = new PrintWriter(fout);
324: w.print(xmlDef);
325: w.close();
326: }
327: XMLTransporter.xmlImport(f.getCanonicalPath(), _dsXml);
328: f.delete();
329: }
330:
331:
332: for (int i = 0; i < _dsXml.getColumnCount(); i++)
333: retStr += _dsXml.getColumnDatabaseName(i) + ",";
334:
335:
336: res.getOutputStream().print(retStr);
337:
338: } catch (Exception e) {
339: res.setStatus(HttpServletResponse.SC_NOT_FOUND);
340: MessageLog.writeErrorMessage("Error in doGet of DWInfoTranslator.XML_FIELDS", e, this );
341: }
342: break;
343: }
344: case DW_INFO_ATTRIBUTE:
345: {
346: try {
347: String app = req.getParameter("Application");
348: String taglib = req.getParameter("TagLib");
349: String tagName = req.getParameter("TagName").toLowerCase();
350: Hashtable tags = TagLibraryParser.getTags(taglib,app, getServletContext());
351: String infoClass = "";
352: if (tagName.startsWith("input")) {
353: buildInputType();
354: infoClass = (String) _inputType.get(tagName.substring(tagName.indexOf(",") + 1).toLowerCase());
355: } else {
356: TagInfo t = (TagInfo) tags.get(tagName);
357: infoClass = t.getInfoString();
358: }
359: Class classMethod = Class.forName(infoClass);
360: java.lang.reflect.Method[] _methods = classMethod.getMethods();
361: Vector methodVec = new Vector();
362: for (int i = 0; i < _methods.length; i++) {
363: if (_methods[i].getName().startsWith("set")) {
364: String methodName = _methods[i].getName().substring(3);
365: if (!methodVec.contains(methodName))
366: methodVec.addElement(methodName);
367: }
368: }
369: for (int i = 0; i < methodVec.size(); i++)
370: retStr += methodVec.elementAt(i) + ",";
371:
372:// TagAttributeInfo attribArray[] =t.getAttributes();
373:// for (int i=0;i<attribArray.length;i++)
374:// retStr += ((TagAttributeInfo)attribArray[i]).getName() + ",";
375:
376: res.getOutputStream().print(retStr);
377:
378: } catch (Exception e) {
379: res.setStatus(HttpServletResponse.SC_NOT_FOUND);
380: MessageLog.writeErrorMessage("Error in doGet of DWInfoTranslator.ATTRIBUTE", e, this );
381: }
382: break;
383: }
384: case DW_INFO_MODELTYPE:
385: {
386: try {
387: String model = req.getParameter("MODEL");
388: String app = req.getParameter("Application");
389: DataStoreBuffer dsb = DataStore.constructDataStore(model, app);
390: if (dsb == null)
391: res.getOutputStream().print("NONE");
392: else if (dsb instanceof BeanDataStore)
393: res.getOutputStream().print("BEAN");
394: else
395: res.getOutputStream().print("STANDARD");
396: } catch (Exception e) {
397: res.setStatus(HttpServletResponse.SC_NOT_FOUND);
398: MessageLog.writeErrorMessage("Error in doGet of DWInfoTranslator.ModelTables", e, this );
399: }
400:
401: break;
402:
403: }
404: case DW_INFO_MODELTABLENAME:
405: {
406: try {
407: StringBuffer rStr = new StringBuffer();
408: String app = req.getParameter("Application");
409: String model = req.getParameter("MODEL");
410: DataStoreBuffer dsb = DataStore.constructDataStore(model, app);
411: String[] tableNames = dsb.getTableList(false);
412: for (int i = 0; i < tableNames.length; i++) {
413: rStr.append(tableNames[i] + ",");
414: }
415:
416:
417: res.getOutputStream().print(rStr.toString());
418:
419:
420: } catch (Exception e) {
421: res.setStatus(HttpServletResponse.SC_NOT_FOUND);
422: MessageLog.writeErrorMessage("Error in doGet of DWInfoTranslator.ModelTables", e, this );
423: }
424:
425: break;
426:
427: }
428:
429: case DW_INFO_MODELTABLEFIELD:
430: {
431: try {
432: StringBuffer rStr = new StringBuffer();
433: String app = req.getParameter("Application");
434: String table = req.getParameter("TABLE");
435: String model = req.getParameter("MODEL");
436: DataStoreBuffer dsb = DataStore.constructDataStore(model, app);
437: String[] colList = dsb.getColumnList();
438: if (table == null || table.equals("")) {
439: for (int i = 0; i < colList.length; i++)
440: rStr.append(colList[i] + ",");
441: } else {
442: for (int i = 0; i < colList.length; i++) {
443: if (colList[i].startsWith(table))
444: rStr.append(colList[i].substring(colList[i].indexOf(".") + 1) + ",");
445: }
446: }
447:
448:
449: res.getOutputStream().print(rStr.toString());
450:
451:
452: } catch (Exception e) {
453: res.setStatus(HttpServletResponse.SC_NOT_FOUND);
454: MessageLog.writeErrorMessage("Error in doGet of DWInfoTranslator.ModelTableField", e, this );
455: }
456:
457: break;
458:
459: }
460: case DW_INFO_LANGPREF:
461: {
462: try{
463: String sLang = req.getParameter("LANGUAGE");
464: String sRefresh = req.getParameter("REFRESH");
465: if(sRefresh !=null && sRefresh.equalsIgnoreCase("true"))
466: LanguageResourceFinder.clearCache();
467:
468: Enumeration enumLangKeys = LanguageResourceFinder.getKeys(req.getParameter("Application"), sLang);
469: StringBuffer rStr = new StringBuffer();
470: if (enumLangKeys != null) {
471: while(enumLangKeys.hasMoreElements()){
472: Object oKey = enumLangKeys.nextElement();
473: if(oKey != null)
474: rStr.append((String)oKey + ",");
475: }
476: }
477: res.getOutputStream().print(rStr.toString());
478: //MessageLog.writeErrorMessage(" ++++++++++ enumLangKeys = "+sRetVal, this);
479: }catch(Exception ex){
480: res.setStatus(HttpServletResponse.SC_NOT_FOUND);
481: MessageLog.writeErrorMessage("Error in doGet of DWInfoTranslator.DefaultLang", ex, this );
482: }
483: break;
484: }
485: case DW_INFO_SITEMAP:
486: {
487: try{
488: String app = req.getParameter("Application");
489: SiteMap m = SiteMap.getSiteMap(app);
490:
491: Enumeration enumKeys = m.getEntryNames();
492: StringBuffer rStr = new StringBuffer();
493: if (enumKeys != null) {
494: while(enumKeys.hasMoreElements()){
495: Object oKey = enumKeys.nextElement();
496: if(oKey != null) {
497: rStr.append("%");
498: rStr.append((String)oKey );
499: rStr.append(",");
500: }
501: }
502: }
503: res.getOutputStream().print(rStr.toString());
504: }catch(Exception ex){
505: res.setStatus(HttpServletResponse.SC_NOT_FOUND);
506: MessageLog.writeErrorMessage("Error in doGet of DWInfoTranslator.SiteMap", ex, this );
507: }
508: break;
509: }
510:
511: }
512:
513: }
514:
515: public void doPost(HttpServletRequest req, HttpServletResponse res)
516: throws ServletException, IOException {
517: JspServlet.setUpApplicationContext(getServletContext(), req);
518: res.setStatus(HttpServletResponse.SC_OK);
519: try {
520: } catch (Exception e) {
521: MessageLog.writeErrorMessage(
522: "Dreamweaver Info Failed to Translate.", e, this);
523: }
524:
525: }
526: }
|