001: /*
002: * JFolder, Copyright 2001-2006 Gary Steinmetz
003: *
004: * Distributable under LGPL license.
005: * See terms of license at gnu.org.
006: */
007:
008: package org.jfolder.console.web.base;
009:
010: //base classes
011: import java.io.IOException;
012: import java.util.HashMap;
013:
014: //project specific classes
015: import org.jfolder.common.utils.xml.XMLHelper;
016: import org.jfolder.common.web.template.ConsoleParameterContext;
017: import org.jfolder.common.web.template.SubmitActionContext;
018: import org.jfolder.common.web.template.SubmitActionParameters;
019: import org.jfolder.console.base.ConsolePageContext;
020: import org.jfolder.console.base.ConsolePageParameters;
021: import org.jfolder.console.base.ConsolePageSession;
022: import org.jfolder.console.base.context.BaseSubBoxConsolePageContext;
023: import org.jfolder.project.model.ProjectSystem;
024:
025: //other classes
026:
027: public class SubAppPropConsolePageContext extends
028: BaseSubBoxConsolePageContext {
029:
030: private final static String BUTTON__CREATE = "BUTTON__CREATE";
031: private final static String BUTTON__UPDATE = "BUTTON__UPDATE";
032: private final static String BUTTON__DELETE = "BUTTON__DELETE";
033:
034: private ProjectSystem ps = null;
035: private ConsolePageSession cps = null;
036: //private int columnWidth = 0;
037: //private int height = 0;
038: //private String sideColor = null;
039: private String propName = null;
040: private String propValue = null;
041: private String propRegEx = null;
042: private String propDesc = null;
043: private String propErrMess = null;
044: private boolean existingProp = false;
045:
046: private SubAppPropConsolePageContext(ConsolePageSession inCps,
047: ProjectSystem inPs, boolean inExisting, String inPropName,
048: String inPropValue, String inPropRegEx, String inPropDesc,
049: String inPropErrMess, int inColumnWidth, int inHeight,
050: String inSideColor, ConsolePageContext inCpc) {
051:
052: super (constructName(inPs), inColumnWidth, inHeight,
053: inSideColor, inCpc);
054: //
055: this .ps = inPs;
056: this .cps = inCps;
057: //
058: this .propName = inPropName;
059: this .propValue = inPropValue;
060: this .propRegEx = inPropRegEx;
061: this .propDesc = inPropDesc;
062: this .propErrMess = inPropErrMess;
063: this .existingProp = inExisting;
064: //
065: //this.columnWidth = inColumnWidth;
066: //this.height = inHeight;
067: //this.sideColor = inSideColor;
068:
069: }
070:
071: private final static String constructName(ProjectSystem inPs) {
072: return "app_prop_" + userOrServer(!inPs.isDeployed())
073: + inPs.getName();
074: }
075:
076: private SubAppPropConsolePageContext(ConsolePageSession inCps,
077: ProjectSystem inPs, int inColumnWidth, int inHeight,
078: String inSideColor, ConsolePageContext inCpc) {
079:
080: this (inCps, inPs, false, null, null, null, null, null,
081: inColumnWidth, inHeight, inSideColor, inCpc);
082:
083: }
084:
085: private SubAppPropConsolePageContext(ConsolePageSession inCps,
086: ProjectSystem inPs, String inPropName, String inPropValue,
087: String inPropRegEx, String inPropDesc,
088: String inPropErrMess, int inColumnWidth, int inHeight,
089: String inSideColor, ConsolePageContext inCpc) {
090:
091: this (inCps, inPs, true, inPropName, inPropValue, inPropRegEx,
092: inPropDesc, inPropErrMess, inColumnWidth, inHeight,
093: inSideColor, inCpc);
094:
095: }
096:
097: protected final static SubAppPropConsolePageContext newInstance(
098: ConsolePageSession inCps, ProjectSystem inPs,
099: int inColumnWidth, int inHeight, String inSideColor,
100: ConsolePageContext inCpc) throws IOException {
101:
102: SubAppPropConsolePageContext outValue = null;
103:
104: if (inCpc.isSubConsolePageContextPresent(constructName(inPs))) {
105: Object o = inCpc
106: .getSubConsolePageContext(constructName(inPs));
107: outValue = (SubAppPropConsolePageContext) o;
108: } else {
109: outValue = new SubAppPropConsolePageContext(inCps, inPs,
110: inColumnWidth, inHeight, inSideColor, inCpc);
111: //inCpc.registerSubConsolePageContext(inName, outValue);
112: }
113:
114: outValue.copyFromParent(inCpc);
115: outValue.createConsolePage(inCpc.getWriter(), inCpc
116: .getPageSetupContext());
117:
118: return outValue;
119: }
120:
121: protected final static SubAppPropConsolePageContext newInstance(
122: ConsolePageSession inCps, ProjectSystem inPs,
123: String inPropName, String inPropValue, String inPropRegEx,
124: String inPropDesc, String inPropErrMess, int inColumnWidth,
125: int inHeight, String inSideColor, ConsolePageContext inCpc)
126: throws IOException {
127:
128: SubAppPropConsolePageContext outValue = null;
129:
130: outValue = new SubAppPropConsolePageContext(inCps, inPs,
131: inPropName, inPropValue, inPropRegEx, inPropDesc,
132: inPropErrMess, inColumnWidth, inHeight, inSideColor,
133: inCpc);
134:
135: outValue.copyFromParent(inCpc);
136: outValue.createConsolePage(inCpc.getWriter(), inCpc
137: .getPageSetupContext());
138:
139: return outValue;
140: }
141:
142: private final static String userOrServer(boolean inUser) {
143:
144: String outValue = null;
145:
146: if (inUser) {
147: outValue = "user";
148: } else {
149: outValue = "server";
150: }
151: outValue = outValue + "_";
152:
153: return outValue;
154: }
155:
156: //
157: //
158: protected void renderContent() throws IOException {
159: if (!this .existingProp) {
160: displayNewProperty(this .cps, this .ps);
161: } else {
162: displayExistingProperty(this .ps, this .propName,
163: this .propValue, this .propRegEx, this .propDesc,
164: this .propErrMess);
165: }
166: }
167:
168: private void displayNewProperty(ConsolePageSession inCs,
169: ProjectSystem inPs) throws IOException {
170:
171: String selectId = PROPERTIES_PREFIX + inPs.getName() + _SELECT;
172: //inSelectId = devAppsWebPagesSelect
173: HashMap styleSelect = getFontStyle(9, COURIER, BLACK);
174:
175: //startAndEndStretchTableAndRowAndCell("<hr/>");
176:
177: //startTable(2);
178: //startRow();
179: //startAndEndCell(1, "Properties", getFontStyle(14, ARIAL, BLACK));
180: //startCell(1, alignCenter(null));
181: ////
182: String nextNewName = ConsolePageParameters.CONSOLE_NEW_PROPERTY_NAME
183: + UNDERSCORE + inPs.getName();
184: nextNewName = XMLHelper.fromStringToCData(nextNewName);
185: //
186: String nextNewValue = ConsolePageParameters.CONSOLE_NEW_PROPERTY_VALUE
187: + UNDERSCORE + inPs.getName();
188: nextNewValue = XMLHelper.fromStringToCData(nextNewValue);
189: //
190: String nextNewRegEx = ConsolePageParameters.CONSOLE_NEW_PROPERTY_REG_EX
191: + UNDERSCORE + inPs.getName();
192: nextNewRegEx = XMLHelper.fromStringToCData(nextNewRegEx);
193: //
194: String nextNewDesc = ConsolePageParameters.CONSOLE_NEW_PROPERTY_DESC
195: + UNDERSCORE + inPs.getName();
196: nextNewDesc = XMLHelper.fromStringToCData(nextNewDesc);
197: //
198: String nextNewErrMess = ConsolePageParameters.CONSOLE_NEW_PROPERTY_ERR_MESS
199: + UNDERSCORE + inPs.getName();
200: nextNewErrMess = XMLHelper.fromStringToCData(nextNewErrMess);
201: //
202: printAndIndent("<table>");
203: //
204: printAndIndent("<tr>");
205: simpleAndPrint("<td>Name</td>");
206: printAndIndent("<td>");
207: simpleAndPrint(createTextBox(nextNewName, "PROP_NAME", null,
208: null, new Integer(15), null, null));
209: revertAndPrint("</td>");
210: printAndIndent("<td>");
211: //
212: SubmitActionContext sacCreate = SubmitActionContext
213: .newInstance(this );
214: //
215: sacCreate.addAction(ConsoleParameterContext.FIRST_INPUT,
216: singleQuotes(SubmitActionParameters.CREATE));
217: sacCreate.addAction(ConsoleParameterContext.SECOND_INPUT,
218: singleQuotes(SubmitActionParameters.PROPERTY));
219: //
220: sacCreate.addParameter(ConsoleParameterContext.FIRST_INPUT,
221: singleQuotes(SubmitActionParameters.USER));
222: sacCreate.addParameter(ConsoleParameterContext.SECOND_INPUT,
223: singleQuotes(inPs.getName()));
224: sacCreate.addParameter(ConsoleParameterContext.THIRD_INPUT,
225: "getPageComponent('" + nextNewName + "').value");
226: sacCreate.addParameter(ConsoleParameterContext.FOURTH_INPUT,
227: "getPageComponent('" + nextNewValue + "').value");
228: sacCreate.addParameter(ConsoleParameterContext.FIFTH_INPUT,
229: "getPageComponent('" + nextNewRegEx + "').value");
230: sacCreate.addParameter(ConsoleParameterContext.SIXTH_INPUT,
231: "getPageComponent('" + nextNewDesc + "').value");
232: sacCreate.addParameter(ConsoleParameterContext.SEVENTH_INPUT,
233: "getPageComponent('" + nextNewErrMess + "').value");
234: createButton(BUTTON__CREATE, "Create", 75,
235: submitActionCall(sacCreate), null, null, null, null);
236: //
237: revertAndPrint("</td>");
238: revertAndPrint("</tr>");
239: //
240: printAndIndent("<tr>");
241: simpleAndPrint("<td>Value</td>");
242: printAndIndent("<td>");
243: simpleAndPrint(createTextBox(nextNewValue, "PROP_VALUE", null,
244: null, new Integer(15), null, null));
245: revertAndPrint("</td>");
246: simpleAndPrint("<td>" + XMLHelper.NBSP_XML + "</td>");
247: revertAndPrint("</tr>");
248: //
249: printAndIndent("<tr>");
250: simpleAndPrint("<td>Description</td>");
251: printAndIndent("<td>");
252: simpleAndPrint(createTextBox(nextNewDesc, "PROP_DESC", null,
253: null, new Integer(15), null, null));
254: revertAndPrint("</td>");
255: simpleAndPrint("<td>" + XMLHelper.NBSP_XML + "</td>");
256: revertAndPrint("</tr>");
257: //
258: printAndIndent("<tr>");
259: simpleAndPrint("<td>Reg Ex</td>");
260: printAndIndent("<td>");
261: simpleAndPrint(createTextBox(nextNewRegEx, "PROP_REG_EX", null,
262: null, new Integer(15), null, null));
263: revertAndPrint("</td>");
264: simpleAndPrint("<td>" + XMLHelper.NBSP_XML + "</td>");
265: revertAndPrint("</tr>");
266: //
267: printAndIndent("<tr>");
268: simpleAndPrint("<td>Error Message</td>");
269: printAndIndent("<td>");
270: simpleAndPrint(createTextBox(nextNewErrMess, "PROP_ERR_MESS",
271: null, null, new Integer(15), null, null));
272: revertAndPrint("</td>");
273: simpleAndPrint("<td>" + XMLHelper.NBSP_XML + "</td>");
274: revertAndPrint("</tr>");
275: //
276: revertAndPrint("</table>");
277: //endCell();
278: //startCell(1, alignCenter(null));
279: //
280: //
281: ////
282: //endCell();
283: //
284: //endRow();
285: //endTable();
286:
287: //int topLeftMargin = getLeftMargin();
288: //setLeftMargin(topLeftMargin + 1);
289: //
290: //
291: //
292: //setLeftMargin(topLeftMargin);
293: }
294:
295: private void displayExistingProperty(ProjectSystem inPs,
296: String inName, String inValue, String inRegEx,
297: String inDesc, String inErrMes) throws IOException {
298: //
299: //startAndEndStretchTableAndRowAndCell("<hr/>");
300:
301: //startTable(2);
302: //startRow();
303: //startAndEndCell(1, "Properties", getFontStyle(14, ARIAL, BLACK));
304: //startCell(1, alignCenter(null));
305: ////
306: //String nextExistingName =
307: // ConsolePageParameters.CONSOLE_NEW_PROPERTY_NAME
308: // + UNDERSCORE + inPs.getName() + UNDERSCORE + inName;
309: //nextExistingName = XMLHelper.fromStringToCData(nextExistingName);
310: //
311: String nextExistingValue = ConsolePageParameters.CONSOLE_EXISTING_PROPERTY_VALUE
312: + UNDERSCORE + inPs.getName() + UNDERSCORE + inName;
313: nextExistingValue = XMLHelper
314: .fromStringToCData(nextExistingValue);
315: //
316: String nextExistingRegEx = ConsolePageParameters.CONSOLE_EXISTING_PROPERTY_REG_EX
317: + UNDERSCORE + inPs.getName() + UNDERSCORE + inName;
318: nextExistingRegEx = XMLHelper
319: .fromStringToCData(nextExistingRegEx);
320: //
321: String nextExistingDesc = ConsolePageParameters.CONSOLE_EXISTING_PROPERTY_DESC
322: + UNDERSCORE + inPs.getName() + UNDERSCORE + inName;
323: nextExistingDesc = XMLHelper
324: .fromStringToCData(nextExistingDesc);
325: //
326: String nextExistingErrMess = ConsolePageParameters.CONSOLE_EXISTING_PROPERTY_ERR_MESS
327: + UNDERSCORE + inPs.getName() + UNDERSCORE + inName;
328: nextExistingErrMess = XMLHelper
329: .fromStringToCData(nextExistingErrMess);
330: //
331: printAndIndent("<table>");
332: //
333: //printAndIndent("<tr>");
334: //simpleAndPrint("<td>Name</td>");
335: //printAndIndent("<td>");
336: //simpleAndPrint(createTextBox(nextExistingName, inName, null,
337: // new Integer(15), null, null));
338: //simpleAndPrint(inName);
339: //revertAndPrint("</td>");
340: //revertAndPrint("</tr>");
341: //
342: printAndIndent("<tr>");
343: simpleAndPrint("<td>Value</td>");
344: printAndIndent("<td>");
345: simpleAndPrint(createTextBox(nextExistingValue, inValue, null,
346: null, new Integer(15), null, null));
347: revertAndPrint("</td>");
348: printAndIndent("<td>");
349: //
350: SubmitActionContext sacUpdate = SubmitActionContext
351: .newInstance(this );
352: //
353: sacUpdate.addAction(ConsoleParameterContext.FIRST_INPUT,
354: singleQuotes(SubmitActionParameters.UPDATE));
355: sacUpdate.addAction(ConsoleParameterContext.SECOND_INPUT,
356: singleQuotes(SubmitActionParameters.PROPERTY));
357: //
358: sacUpdate.addParameter(ConsoleParameterContext.FIRST_INPUT,
359: singleQuotes(SubmitActionParameters.USER));
360: sacUpdate.addParameter(ConsoleParameterContext.SECOND_INPUT,
361: singleQuotes(inPs.getName()));
362: sacUpdate.addParameter(ConsoleParameterContext.THIRD_INPUT,
363: singleQuotes(inName));
364: sacUpdate.addParameter(ConsoleParameterContext.FOURTH_INPUT,
365: "getPageComponent('" + nextExistingValue + "').value");
366: sacUpdate.addParameter(ConsoleParameterContext.FIFTH_INPUT,
367: "getPageComponent('" + nextExistingRegEx + "').value");
368: sacUpdate.addParameter(ConsoleParameterContext.SIXTH_INPUT,
369: "getPageComponent('" + nextExistingDesc + "').value");
370: sacUpdate
371: .addParameter(ConsoleParameterContext.SEVENTH_INPUT,
372: "getPageComponent('" + nextExistingErrMess
373: + "').value");
374: createButton(BUTTON__UPDATE, "Update", 75,
375: submitActionCall(sacUpdate), null, null, null, null);
376: //
377: revertAndPrint("</td>");
378: revertAndPrint("</tr>");
379: //
380: printAndIndent("<tr>");
381: simpleAndPrint("<td>Description</td>");
382: printAndIndent("<td>");
383: simpleAndPrint(createTextBox(nextExistingDesc, inDesc, null,
384: null, new Integer(15), null, null));
385: revertAndPrint("</td>");
386: printAndIndent("<td>");
387: //
388: SubmitActionContext sacDelete = SubmitActionContext
389: .newInstance(this );
390: //
391: sacDelete.addAction(ConsoleParameterContext.FIRST_INPUT,
392: singleQuotes(SubmitActionParameters.DELETE));
393: sacDelete.addAction(ConsoleParameterContext.SECOND_INPUT,
394: singleQuotes(SubmitActionParameters.PROPERTY));
395: //
396: sacDelete.addParameter(ConsoleParameterContext.FIRST_INPUT,
397: singleQuotes(SubmitActionParameters.USER));
398: sacDelete.addParameter(ConsoleParameterContext.SECOND_INPUT,
399: singleQuotes(inPs.getName()));
400: sacDelete.addParameter(ConsoleParameterContext.THIRD_INPUT,
401: singleQuotes(inName));
402: createButton(BUTTON__DELETE, "Delete", 75,
403: submitActionCall(sacDelete), null, null, null, null);
404: //
405: revertAndPrint("</td>");
406: revertAndPrint("</tr>");
407: //
408: printAndIndent("<tr>");
409: simpleAndPrint("<td>Reg Ex</td>");
410: printAndIndent("<td>");
411: simpleAndPrint(createTextBox(nextExistingRegEx, inRegEx, null,
412: null, new Integer(15), null, null));
413: revertAndPrint("</td>");
414: simpleAndPrint("<td>" + XMLHelper.NBSP_XML + "</td>");
415: revertAndPrint("</tr>");
416: //
417: printAndIndent("<tr>");
418: simpleAndPrint("<td>Error Message</td>");
419: printAndIndent("<td>");
420: simpleAndPrint(createTextBox(nextExistingErrMess, inErrMes,
421: null, null, new Integer(15), null, null));
422: revertAndPrint("</td>");
423: simpleAndPrint("<td>" + XMLHelper.NBSP_XML + "</td>");
424: revertAndPrint("</tr>");
425: //
426: revertAndPrint("</table>");
427: //endCell();
428: //startCell(1, alignCenter(null));
429: //
430: //
431: //
432: ////
433: //endCell();
434: //
435: //endRow();
436: //
437: //
438: //endTable();
439: }
440: }
|