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.common.web.template;
009:
010: //base classes
011: import java.util.ArrayList;
012: import java.util.HashMap;
013: import java.util.StringTokenizer;
014:
015: //project specific classes
016: import org.jfolder.common.UnexpectedSystemException;
017: import org.jfolder.common.utils.misc.CommonSeparators;
018: import org.jfolder.common.utils.misc.MiscHelper;
019:
020: //other classes
021:
022: public class ConsoleTemplateSession {
023:
024: //
025: public final static String TOGGLE_LINK_SEPARATOR = CommonSeparators.TOGGLE_LINK_SEPARATOR;//",";
026: final static String DONT_RECORD_THIS_BRANCH = "DONT_RECORD_THIS_BRANCH";
027: private final static String DROP_DOWN_BOX = "DROP_DOWN_BOX";
028: private final static String TEXT_BOX = "TEXT_BOX";
029: private final static String TEXT_AREA = "TEXT_AREA";
030: private final static String RADIO_BUTTON = "RADIO_BUTTON";
031: private final static String TAG_BASE = "TAG_BASE";
032: private final static String TREE_BASE = "TREE_BASE";
033: private final static String TEXT_BASE = "TEXT_BASE";
034: private final static String MACRO_POINTER = "MACRO_POINTER";
035: private final static String TABLE_BUTTON = "TABLE_BUTTON";
036: private final static String FILE_UPLOAD = "FILE_UPLOAD";
037: private final static String STATIC_IMAGE = "STATIC_IMAGE";
038: private final static String HIDDEN_FIELD = "HIDDEN_FIELD";
039: private final static String TOGGLE_CALLER = "TOGGLE_CALLER";
040: private final static String WEB_PAGE_VIEW_HIGHLIGHT = "WEB_PAGE_VIEW_HIGHLIGHT";
041: private final static String ANCHOR_POINT = "ANCHOR_POINT";
042: private final static String WEB_PAGE_VIEW_POP_UP = "WEB_PAGE_VIEW_POP_UP";
043: private final static String WEB_PAGE_VIEW_ITERATIVE_SUB_SECTION = "WEB_PAGE_VIEW_ITERATIVE_SUB_SECTION";
044:
045: public final static String CREATION_OF_CONCEPT_TAG = "CREATION_OF_CONCEPT_TAG";
046: //
047: public final static String COMPONENT_MENU_LAUNCH_POINT = "MENU_LAUNCH_POINT";
048: public final static String COMPONENT_MENU = "MENU";
049: //
050: public final static String STUDIO_EDIT_INPUT = "STUDIO_EDIT_INPUT";
051: //public final static String STUDIO_EDIT_INPUT_SUPPORT =
052: // "STUDIO_EDIT_INPUT_SUPPORT";
053: public final static String STUDIO_EDIT_INPUT_OPTION = "STUDIO_EDIT_INPUT_OPTION";
054: public final static String STUDIO_EDIT_INPUT_OTHER = "STUDIO_EDIT_INPUT_OTHER";
055: //
056: private final static String MENU_ITEM = "MENU_ITEM";
057: //
058: private final static String CREATION_PARAMETER_CALLER = "CREATION_PARAMETER_CALLER";
059: private final static String TEMPLATE_VIEW = "TEMPLATE_VIEW";
060: //
061: private final static String WEB_PAGE_VIEW_POP_UP_CALLER = "WEB_PAGE_VIEW_POP_UP_CALLER";
062:
063: //
064: private ArrayList toggleLinkList = null;
065: private String previousToggleLink = null;
066: //
067: private ArrayList menuLists = null;
068: //
069: private PageSetupContext psc = null;
070:
071: protected ConsoleTemplateSession() {
072:
073: //
074: this .toggleLinkList = new ArrayList();
075: //
076: this .psc = PageSetupContext.newPageSetupContext();
077:
078: }
079:
080: public void prepareConsolePageContentUsage() {
081: this .toggleLinkList = new ArrayList();
082: this .menuLists = new ArrayList();
083: }
084:
085: public void commitConsolePageContentUsage() {
086: if (this .toggleLinkList.size() > 0) {
087: throw new UnexpectedSystemException(
088: "Non-empty Toggle Link Queue ("
089: + this .toggleLinkList + ")");
090: }
091: }
092:
093: //
094: public PageSetupContext getPageSetupContext() {
095: return this .psc;
096: }
097:
098: //
099: public void pushToggleLink(String inLinkPart) {
100: pushToggleLinkName(inLinkPart);
101: }
102:
103: protected void pushToggleLinkSection(String inLinkPart) {
104: pushToggleLinkName(encodeAsSectionToggleLink(inLinkPart));
105: }
106:
107: protected void pushToggleLinkComponent(String inLinkPart) {
108: pushToggleLinkName(encodeAsComponentToggleLink(inLinkPart));
109: }
110:
111: private void pushToggleLinkName(String inLinkPart) {
112: this .toggleLinkList.add(inLinkPart);
113: }
114:
115: public void pushToggleLinkToggleCaller() {
116: pushToggleLinkComponent(TOGGLE_CALLER);
117: }
118:
119: public void pushToggleLinkStudioEditInput() {
120: pushToggleLinkComponent(STUDIO_EDIT_INPUT);
121: }
122:
123: public void pushToggleLinkMenuItem() {
124: pushToggleLinkComponent(MENU_ITEM);
125: }
126:
127: public void pushToggleLinkCreationParameterCaller() {
128: pushToggleLinkComponent(CREATION_PARAMETER_CALLER);
129: }
130:
131: //public void pushToggleLinkStudioEditInputSupport() {
132: // pushToggleLinkComponent(STUDIO_EDIT_INPUT_SUPPORT);
133: //}
134: //public void pushToggleLinkStudioEditInputOption() {
135: // pushToggleLinkComponent(STUDIO_EDIT_INPUT_OPTION);
136: //}
137: public final static String getMainToggleSectionPart() {
138: return encodeAsSectionToggleLink(ConsoleTemplateFunctionsContext.MAIN_TOGGLE_SECTION);
139: }
140:
141: public final static String getDontRecordThisBranchPart() {
142: return encodeAsComponentToggleLink(DONT_RECORD_THIS_BRANCH);
143: }
144:
145: public final static String getCreationOfConceptTagPart() {
146: return encodeAsSectionToggleLink(CREATION_OF_CONCEPT_TAG);
147: }
148:
149: //
150: public void pushToggleLinkStudioEditInputOther() {
151: pushToggleLinkComponent(STUDIO_EDIT_INPUT_OTHER);
152: }
153:
154: public void pushToggleLinkDropDownBox() {
155: pushToggleLinkComponent(DROP_DOWN_BOX);
156: }
157:
158: public void pushToggleLinkTagBase() {
159: pushToggleLinkComponent(TAG_BASE);
160: }
161:
162: public void pushToggleLinkTreeBase() {
163: pushToggleLinkComponent(TREE_BASE);
164: }
165:
166: public void pushToggleLinkTextBase() {
167: pushToggleLinkComponent(TEXT_BASE);
168: }
169:
170: public void pushToggleLinkTextArea() {
171: pushToggleLinkComponent(TEXT_AREA);
172: }
173:
174: public void pushToggleLinkTextBox() {
175: pushToggleLinkComponent(TEXT_BOX);
176: }
177:
178: public void pushToggleLinkRadioButton() {
179: pushToggleLinkComponent(RADIO_BUTTON);
180: }
181:
182: public void pushToggleLinkTableButton() {
183: pushToggleLinkComponent(TABLE_BUTTON);
184: }
185:
186: public void pushToggleLinkFileUpload() {
187: pushToggleLinkComponent(FILE_UPLOAD);
188: }
189:
190: public void pushToggleLinkStaticImage() {
191: pushToggleLinkComponent(STATIC_IMAGE);
192: }
193:
194: public void pushToggleLinkHiddenField() {
195: pushToggleLinkComponent(HIDDEN_FIELD);
196: }
197:
198: public void pushToggleLinkAnchorPoint() {
199: pushToggleLinkComponent(ANCHOR_POINT);
200: }
201:
202: public void pushToggleLinkDontRecordThisBranch() {
203: pushToggleLinkComponent(DONT_RECORD_THIS_BRANCH);
204: }
205:
206: public void pushToggleLinkWebPageViewPopUp() {
207: pushToggleLinkComponent(WEB_PAGE_VIEW_POP_UP);
208: }
209:
210: public void pushToggleLinkWebPageViewPopUpCaller() {
211: pushToggleLinkComponent(WEB_PAGE_VIEW_POP_UP_CALLER);
212: }
213:
214: public void pushToggleLinkWebPageViewIterativeSubSection() {
215: pushToggleLinkComponent(WEB_PAGE_VIEW_ITERATIVE_SUB_SECTION);
216: }
217:
218: public void pushToggleLinkTemplateView() {
219: pushToggleLinkComponent(TEMPLATE_VIEW);
220: }
221:
222: //
223: //
224: public final static String getAnchorPointPartName() {
225: return encodeAsComponentToggleLink(ANCHOR_POINT);
226: }
227:
228: public final static String getTextAreaPartName() {
229: return encodeAsComponentToggleLink(TEXT_AREA);
230: }
231:
232: public final static String getTextBoxPartName() {
233: return encodeAsComponentToggleLink(TEXT_BOX);
234: }
235:
236: public final static String getHiddenFieldPartName() {
237: return encodeAsComponentToggleLink(HIDDEN_FIELD);
238: }
239:
240: public final static String getDropDownBoxPartName() {
241: return encodeAsComponentToggleLink(DROP_DOWN_BOX);
242: }
243:
244: public final static String getFileUploadPartName() {
245: return encodeAsComponentToggleLink(FILE_UPLOAD);
246: }
247:
248: public final static String getTableButtonPartName() {
249: return encodeAsComponentToggleLink(TABLE_BUTTON);
250: }
251:
252: public final static String getMenuItemPartName() {
253: return encodeAsComponentToggleLink(MENU_ITEM);
254: }
255:
256: //
257: //
258: //protected void pushToggleLinkCreationTable() {
259: // pushToggleLinkSection(CREATION_OF_CONCEPT_TAG);
260: //}
261: //
262: public final static boolean isToggleLinkPartComponent(
263: String inLinkPart) {
264: return (inLinkPart.startsWith("[") && inLinkPart.endsWith("]"));
265: }
266:
267: public final static boolean isToggleLinkPartSection(
268: String inLinkPart) {
269: return (inLinkPart.startsWith("(") && inLinkPart.endsWith(")"));
270: }
271:
272: public final static boolean isToggleLinkPartNormal(String inLinkPart) {
273: return (!isToggleLinkPartComponent(inLinkPart) && !isToggleLinkPartSection(inLinkPart));
274: }
275:
276: //
277: public final static boolean isToggleLinkStudioEditInput(
278: String inLinkPart) {
279: //
280: return (inLinkPart.equals("[" + STUDIO_EDIT_INPUT + "]"));
281: }
282:
283: public final static boolean isToggleLinkStudioEditInputOther(
284: String inLinkPart) {
285: //
286: return (inLinkPart.equals("[" + STUDIO_EDIT_INPUT_OTHER + "]"));
287: }
288:
289: //
290: private final static String encodeAsSectionToggleLink(String inValue) {
291: return ("(" + inValue + ")");
292: }
293:
294: private final static String encodeAsComponentToggleLink(
295: String inValue) {
296: return ("[" + inValue + "]");
297: }
298:
299: //
300: public void popToggleLink() {
301: this .toggleLinkList.remove(this .toggleLinkList.size() - 1);
302: }
303:
304: protected void setToggleLink(ArrayList inToggleLink) {
305: this .toggleLinkList = inToggleLink;
306: }
307:
308: public ArrayList getToggleLinkAsArrayList() {
309: return ((ArrayList) this .toggleLinkList.clone());
310: }
311:
312: public ArrayList getToggleLinkSubSectionAsList(int inIndex) {
313:
314: ArrayList outValue = getToggleLinkAsArrayList();
315:
316: for (int i = 0; i < inIndex; i++) {
317: outValue.remove(0);
318: }
319:
320: return outValue;
321: }
322:
323: //public final static ArrayList getCandidateToggleLinkAsArrayList(
324: // String inValue) {
325: // //
326: // return convertHandleToArrayList(inValue, TOGGLE_LINK_SEPARATOR);
327: //}
328: public final static String getToggleLinkFromArrayList(
329: ArrayList inList) {
330: return MiscHelper.reassembleHandle(inList,
331: TOGGLE_LINK_SEPARATOR);
332: }
333:
334: public final static ArrayList getToggleLinkFromString(String inValue) {
335: return MiscHelper.parseHandle(inValue, TOGGLE_LINK_SEPARATOR);
336: }
337:
338: public String getToggleLink() {
339:
340: String outValue = null;
341:
342: outValue = getToggleLinkFromArrayList(this .toggleLinkList);
343: this .previousToggleLink = outValue;
344:
345: return outValue;
346: }
347:
348: public String getPreviousToggleLink() {
349: return this .previousToggleLink;
350: }
351:
352: //
353: protected void registerMenu(ArrayList inToggleLink,
354: MenuBranch inBranch, HashMap inTableProps,
355: HashMap inTableStyles, HashMap inCellProps,
356: HashMap inCellStyles, Integer inTextLimit, Object inCtmb) {
357: //
358: Object o[] = new Object[] { inToggleLink, inBranch,
359: inTableProps, inTableStyles, inCellProps, inCellStyles,
360: inTextLimit, inCtmb };
361: this .menuLists.add(o);
362: }
363:
364: public int getMenuCount() {
365: return this .menuLists.size();
366: }
367:
368: public ArrayList getMenuToggleLink(int inIndex) {
369:
370: ArrayList outValue = null;
371:
372: Object o[] = (Object[]) this .menuLists.get(inIndex);
373: outValue = (ArrayList) o[0];
374:
375: return outValue;
376: }
377:
378: protected MenuBranch getMenuBranch(int inIndex) {
379:
380: MenuBranch outValue = null;
381:
382: Object o[] = (Object[]) this .menuLists.get(inIndex);
383: outValue = (MenuBranch) o[1];
384:
385: return outValue;
386: }
387:
388: protected HashMap getMenuTableProps(int inIndex) {
389:
390: HashMap outValue = null;
391:
392: Object o[] = (Object[]) this .menuLists.get(inIndex);
393: outValue = (HashMap) o[2];
394:
395: return outValue;
396: }
397:
398: protected HashMap getMenuTableStyles(int inIndex) {
399:
400: HashMap outValue = null;
401:
402: Object o[] = (Object[]) this .menuLists.get(inIndex);
403: outValue = (HashMap) o[2];
404:
405: return outValue;
406: }
407:
408: protected HashMap getMenuCellProps(int inIndex) {
409:
410: HashMap outValue = null;
411:
412: Object o[] = (Object[]) this .menuLists.get(inIndex);
413: outValue = (HashMap) o[4];
414:
415: return outValue;
416: }
417:
418: protected HashMap getMenuCellStyles(int inIndex) {
419:
420: HashMap outValue = null;
421:
422: Object o[] = (Object[]) this .menuLists.get(inIndex);
423: outValue = (HashMap) o[5];
424:
425: return outValue;
426: }
427:
428: protected Integer getMenuTextLimit(int inIndex) {
429:
430: Integer outValue = null;
431:
432: Object o[] = (Object[]) this .menuLists.get(inIndex);
433: outValue = (Integer) o[6];
434:
435: return outValue;
436: }
437:
438: public Object getMenuConceptTagBranch(int inIndex) {
439:
440: Object outValue = null;
441:
442: Object o[] = (Object[]) this .menuLists.get(inIndex);
443: outValue = o[7];
444:
445: return outValue;
446: }
447:
448: //
449: protected final static String getMacroPointerId() {
450:
451: StringBuffer outValue = new StringBuffer();
452:
453: outValue
454: .append(encodeAsSectionToggleLink(ConsoleTemplateFunctionsContext.MAIN_TOGGLE_SECTION));
455: outValue.append(TOGGLE_LINK_SEPARATOR);
456: outValue
457: .append(encodeAsComponentToggleLink(DONT_RECORD_THIS_BRANCH));
458: outValue.append(TOGGLE_LINK_SEPARATOR);
459: outValue.append(encodeAsComponentToggleLink(MACRO_POINTER));
460:
461: return outValue.toString();
462: }
463:
464: protected final static String getWebPageViewHighlight() {
465:
466: StringBuffer outValue = new StringBuffer();
467:
468: outValue
469: .append(encodeAsSectionToggleLink(ConsoleTemplateFunctionsContext.MAIN_TOGGLE_SECTION));
470: outValue.append(TOGGLE_LINK_SEPARATOR);
471: outValue
472: .append(encodeAsComponentToggleLink(DONT_RECORD_THIS_BRANCH));
473: outValue.append(TOGGLE_LINK_SEPARATOR);
474: outValue
475: .append(encodeAsComponentToggleLink(WEB_PAGE_VIEW_HIGHLIGHT));
476:
477: return outValue.toString();
478: }
479: //
480: //protected final static String convertArrayListIntoHandle(
481: // ArrayList inList, String inSeparator) {
482: //
483: // StringBuffer outValue = new StringBuffer();
484: //
485: // for (int i = 0; i < inList.size(); i++) {
486: // if (i > 0) {
487: // outValue.append(inSeparator);
488: // }
489: // outValue.append(inList.get(i));
490: // }
491: //
492: // return outValue.toString();
493: //}
494: //
495: //protected final static ArrayList convertHandleToArrayList(
496: // String inHandle, String inSeparator) {
497: //
498: // ArrayList outValue = new ArrayList();
499: //
500: // StringTokenizer st = new StringTokenizer(inHandle, inSeparator);
501: // while (st.hasMoreTokens()) {
502: // outValue.add(st.nextToken());
503: // }
504: //
505: // return outValue;
506: //}
507: }
|