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.macro.v1;
009:
010: //base classes
011: import java.io.IOException;
012: import java.util.ArrayList;
013: import java.util.HashMap;
014: import javax.xml.parsers.ParserConfigurationException;
015: import org.w3c.dom.Document;
016: import org.w3c.dom.Element;
017: import org.w3c.dom.Node;
018: import org.w3c.dom.NodeList;
019: import org.xml.sax.SAXException;
020:
021: //project specific classes
022: import org.jfolder.common.UnexpectedSystemException;
023: import org.jfolder.common.tagging.AppraiseConceptTagContext;
024: import org.jfolder.common.tagging.CompoundConceptTagConstraintContext;
025: import org.jfolder.common.tagging.ConceptTag;
026: import org.jfolder.common.tagging.ConceptTagCharacteristic;
027: import org.jfolder.common.tagging.ConceptTagCharacteristicHolder;
028: import org.jfolder.common.tagging.ConceptTagConstraint;
029: import org.jfolder.common.tagging.ConceptTagConstraintHolder;
030: import org.jfolder.common.tagging.ConceptTagConstraintTemplate;
031: import org.jfolder.common.tagging.DynamicConceptTagConstraintContext;
032: import org.jfolder.common.tagging.InitializeConceptTagContext;
033: import org.jfolder.common.tagging.RootConceptTagHolder;
034: import org.jfolder.common.tagging.StaticConceptTagConstraintContext;
035: import org.jfolder.common.tagging.StudioConceptTagInstanceInfoContext;
036: import org.jfolder.common.tagging.StudioConceptTagTypeInfoContext;
037: import org.jfolder.common.utils.misc.MiscHelper;
038: import org.jfolder.common.utils.web.ParameterSet;
039: import org.jfolder.common.utils.xml.XMLHelper;
040: import org.jfolder.common.web.template.ConsoleParameterContext;
041: import org.jfolder.common.web.template.ConsoleTemplateSession;
042: import org.jfolder.common.web.template.PageSetupContext;
043: import org.jfolder.common.web.template.RcthConstraintBuilder;
044: import org.jfolder.common.web.template.RecordActionContext;
045: import org.jfolder.common.web.template.SubmitActionParameters;
046: import org.jfolder.console.macro.ConsoleMacro;
047: import org.jfolder.console.macro.ConsoleMacroTag;
048: import org.jfolder.console.macro.ConsoleMacroTagHelper;
049: import org.jfolder.console.macro.IterativeConsoleMacroTag;
050:
051: //other classes
052:
053: public class RootV1ConsoleMacroTag implements ConsoleMacro,
054: ConsoleMacroTag {
055:
056: //
057: private final static String CONTENT_TXT = "content.txt";
058:
059: //characteristics
060: private ConceptTagCharacteristic pageCtchar = null;
061: //
062: ////pane details
063: //private final static String PANE_CTCON = "pane";
064: //private final static String PANE_TITLE = "Pane";
065: //private final static String PANE_SHORT_DESCRIPTION = "Pane";
066: //
067: ////property details
068: //private final static String PROPERTY_CTCON = "property";
069: //private final static String PROPERTY_TITLE = "Property";
070: //private final static String PROPERTY_SHORT_DESCRIPTION = "Property";
071: //
072: ////name of property details
073: //private final static String PROPERTY_CTCON_NAME_CTCTEMP = "name";
074: //private final static String PROPERTY_CTCON_NAME_TITLE = "Name";
075: //private final static String PROPERTY_CTCON_NAME_SHORT_DESCRIPTION =
076: //"Name";
077: //
078: ////value of property details
079: //private final static String PROPERTY_CTCON_VALUE_CTCTEMP = "value";
080: //private final static String PROPERTY_CTCON_VALUE_TITLE = "Value";
081: //private final static String PROPERTY_CTCON_VALUE_SHORT_DESCRIPTION =
082: // "Value";
083:
084: //
085: private int currentPage = 0;
086: private int startAtIndex = 0;
087: private int endAtIndex = 0;
088: private HashMap variables = null;
089: //
090: private String nextPageDescription = null;
091:
092: ///////////////////////////////////
093:
094: //
095: //page details
096: private final static String PAGE_CTCON = "page";
097: private final static String PAGE_TITLE = "Page";
098: private final static String PAGE_SHORT_DESCRIPTION = "Page";
099: //
100: //from-handle of page details
101: private final static String PAGE_CTCON_FROM_HANDLE_CTCTEMP = "from-handle";
102: private final static String PAGE_CTCON_FROM_HANDLE_TITLE = "From Handle";
103: private final static String PAGE_CTCON_FROM_HANDLE_SHORT_DESCRIPTION = "From Handle";
104: //
105: //alias-from-handle of page details
106: private final static String PAGE_CTCON_ALIAS_FROM_HANDLE_CTCTEMP = "alias-from-handle";
107: private final static String PAGE_CTCON_ALIAS_FROM_HANDLE_TITLE = "Alias From Handle";
108: private final static String PAGE_CTCON_ALIAS_FROM_HANDLE_SHORT_DESCRIPTION = "Alias From Handle";
109: //
110: //source-page of page details
111: private final static String PAGE_CTCON_SOURCE_PAGE_CTCTEMP = "source-page";
112: private final static String PAGE_CTCON_SOURCE_PAGE_TITLE = "Source Page";
113: private final static String PAGE_CTCON_SOURCE_PAGE_SHORT_DESCRIPTION = "Source Page";
114: //
115: //destination-page of page details
116: private final static String PAGE_CTCON_DESTINATION_PAGE_CTCTEMP = "destination-page";
117: private final static String PAGE_CTCON_DESTINATION_PAGE_TITLE = "Destination Page";
118: private final static String PAGE_CTCON_DESTINATION_PAGE_SHORT_DESCRIPTION = "Destination Page";
119: //
120: ////tree-state of page details
121: //private final static String PAGE_CTCON_TREE_STATE_CTCTEMP =
122: // "tree-state";
123: //private final static String PAGE_CTCON_TREE_STATE_TITLE = "Tree State";
124: //private final static String
125: // PAGE_CTCON_TREE_STATE_SHORT_DESCRIPTION = "Tree State";
126: //
127: //description of page details
128: private final static String PAGE_CTCON_DESCRIPTION_CTCTEMP = "description";
129: private final static String PAGE_CTCON_DESCRIPTION_TITLE = "Description";
130: private final static String PAGE_CTCON_DESCRIPTION_SHORT_DESCRIPTION = "Description";
131: //
132: //action of page details
133: private final static String PAGE_CTCON_ACTION_CTCTEMP = "action";
134: private final static String PAGE_CTCON_ACTION_TITLE = "Action";
135: private final static String PAGE_CTCON_ACTION_SHORT_DESCRIPTION = "Action";
136: //
137: //
138: //
139: //
140: //parameter of page details
141: //
142: private final static String PAGE_CTCON_PARAMETER_CTCTEMP = "parameter";
143: private final static String PAGE_CTCON_PARAMETER_TITLE = "Parameter";
144: private final static String PAGE_CTCON_PARAMETER_SHORT_DESCRIPTION = "Parameter";
145: //
146: private final static String PAGE_CTCON_PARAMETER_CTCTEMP_NAME_CTCTEMP = "name";
147: private final static String PAGE_CTCON_PARAMETER_CTCTEMP_NAME_TITLE = "Name";
148: private final static String PAGE_CTCON_PARAMETER_CTCTEMP_NAME_SHORT_DESCRIPTION = "Name";
149: //
150: private final static String PAGE_CTCON_PARAMETER_CTCTEMP_FILE_NAME_CTCTEMP = "file-name";
151: private final static String PAGE_CTCON_PARAMETER_CTCTEMP_FILE_NAME_TITLE = "File Name";
152: private final static String PAGE_CTCON_PARAMETER_CTCTEMP_FILE_NAME_SHORT_DESCRIPTION = "Name";
153: //
154: private final static String PAGE_CTCON_PARAMETER_CTCTEMP_VALUE_CTCTEMP = "value";
155: private final static String PAGE_CTCON_PARAMETER_CTCTEMP_VALUE_TITLE = "Value";
156: private final static String PAGE_CTCON_PARAMETER_CTCTEMP_VALUE_SHORT_DESCRIPTION = "Value";
157:
158: public void initialize(InitializeConceptTagContext inIctc) {
159:
160: //
161: ConceptTagConstraintHolder rootCtconh = ConceptTagConstraintHolder
162: .newInstance(inIctc);
163:
164: //constrain "page"
165: ConceptTagConstraint pageCtcon = ConceptTagConstraint
166: .newInstance(PAGE_CTCON, rootCtconh);
167: pageCtcon.setTitle(PAGE_TITLE);
168: pageCtcon.setShortDescription(PAGE_SHORT_DESCRIPTION);
169: //
170: CompoundConceptTagConstraintContext pageCctcc = CompoundConceptTagConstraintContext
171: .newInstance(pageCtcon);
172: //
173: //constrain "from-handle" of "page"
174: ConceptTagConstraintTemplate pageCtconFromHandleCtctemp = ConceptTagConstraintTemplate
175: .newInstance(PAGE_CTCON_FROM_HANDLE_CTCTEMP, pageCctcc);
176: //
177: StaticConceptTagConstraintContext pageCtconFromHandleSctcc = StaticConceptTagConstraintContext
178: .newInstance(pageCtconFromHandleCtctemp);
179: //
180: //constrain "alias-from-handle" of "page"
181: ConceptTagConstraintTemplate pageCtconAliasFromHandleCtctemp = ConceptTagConstraintTemplate
182: .newInstance(PAGE_CTCON_ALIAS_FROM_HANDLE_CTCTEMP,
183: pageCctcc);
184: //
185: StaticConceptTagConstraintContext pageCtconAliasFromHandleSctcc = StaticConceptTagConstraintContext
186: .newInstance(pageCtconAliasFromHandleCtctemp);
187: //
188: //constrain "source-page" of "page"
189: ConceptTagConstraintTemplate pageCtconSourcePageCtctemp = ConceptTagConstraintTemplate
190: .newInstance(PAGE_CTCON_SOURCE_PAGE_CTCTEMP, pageCctcc);
191: //
192: StaticConceptTagConstraintContext pageCtconSourcePageSctcc = StaticConceptTagConstraintContext
193: .newInstance(pageCtconSourcePageCtctemp);
194: //
195: //constrain "destination-page" of "page"
196: ConceptTagConstraintTemplate pageCtconDestinationPageCtctemp = ConceptTagConstraintTemplate
197: .newInstance(PAGE_CTCON_DESTINATION_PAGE_CTCTEMP,
198: pageCctcc);
199: //
200: StaticConceptTagConstraintContext pageCtconDestinationPageSctcc = StaticConceptTagConstraintContext
201: .newInstance(pageCtconDestinationPageCtctemp);
202: //
203: ////constrain "tree-state" of "page"
204: //ConceptTagConstraintTemplate pageCtconTreeStateCtctemp =
205: // ConceptTagConstraintTemplate.newInstance(
206: // PAGE_CTCON_TREE_STATE_CTCTEMP, pageCctcc);
207: //
208: //StaticConceptTagConstraintContext pageCtconTreeStateSctcc =
209: // StaticConceptTagConstraintContext.newInstance(
210: // pageCtconTreeStateCtctemp);
211: //
212: //constrain "description" of "page"
213: ConceptTagConstraintTemplate pageCtconDescriptionCtctemp = ConceptTagConstraintTemplate
214: .newInstance(PAGE_CTCON_DESCRIPTION_CTCTEMP, pageCctcc);
215: //
216: StaticConceptTagConstraintContext pageCtconDescriptionSctcc = StaticConceptTagConstraintContext
217: .newInstance(pageCtconDescriptionCtctemp);
218: //
219: //constrain "action" of "page"
220: ConceptTagConstraintTemplate pageCtconActionCtctemp = ConceptTagConstraintTemplate
221: .newInstance(PAGE_CTCON_ACTION_CTCTEMP, pageCctcc);
222: //
223: DynamicConceptTagConstraintContext pageCtconActionDctcc = DynamicConceptTagConstraintContext
224: .newInstance(pageCtconActionCtctemp);
225:
226: //
227: //
228: //constrain "parameter" of "page"
229: ConceptTagConstraintTemplate pageCtconParameterCtctemp = ConceptTagConstraintTemplate
230: .newInstance(PAGE_CTCON_PARAMETER_CTCTEMP, pageCctcc);
231: //
232: CompoundConceptTagConstraintContext pageCtconParameterCctcc = CompoundConceptTagConstraintContext
233: .newInstance(pageCtconParameterCtctemp);
234: //
235: //constrain "name" of "parameter" of "page"
236: ConceptTagConstraintTemplate pageCtconParameterCtctempNameCtctemp = ConceptTagConstraintTemplate
237: .newInstance(PAGE_CTCON_PARAMETER_CTCTEMP_NAME_CTCTEMP,
238: pageCtconParameterCctcc);
239: //
240: StaticConceptTagConstraintContext pageCtconParameterCtctempNameSctcc = StaticConceptTagConstraintContext
241: .newInstance(pageCtconParameterCtctempNameCtctemp);
242: //
243: //constrain "file-name" of "parameter" of "page"
244: ConceptTagConstraintTemplate pageCtconParameterCtctempFileNameCtctemp = ConceptTagConstraintTemplate
245: .newInstance(
246: PAGE_CTCON_PARAMETER_CTCTEMP_FILE_NAME_CTCTEMP,
247: pageCtconParameterCctcc);
248: //
249: StaticConceptTagConstraintContext pageCtconParameterCtctempFileNameSctcc = StaticConceptTagConstraintContext
250: .newInstance(pageCtconParameterCtctempFileNameCtctemp);
251: //
252: //constrain "value" of "parameter" of "page"
253: ConceptTagConstraintTemplate pageCtconParameterCtctempValueCtctemp = ConceptTagConstraintTemplate
254: .newInstance(
255: PAGE_CTCON_PARAMETER_CTCTEMP_VALUE_CTCTEMP,
256: pageCtconParameterCctcc);
257: //
258: StaticConceptTagConstraintContext pageCtconParameterCtctempValueSctcc = StaticConceptTagConstraintContext
259: .newInstance(pageCtconParameterCtctempValueCtctemp);
260:
261: inIctc.initialize();
262:
263: //
264: this .pageCtchar = pageCtcon.getCharacteristic();
265: }
266:
267: public void appraise(AppraiseConceptTagContext inCtic) {
268: if (inCtic instanceof StudioConceptTagInstanceInfoContext) {
269: StudioConceptTagInstanceInfoContext sctiic = (StudioConceptTagInstanceInfoContext) inCtic;
270: sctiic.setInstanceTitle("Console Macro");
271: sctiic.setInstanceDescription("Console Macro");
272: } else if (inCtic instanceof StudioConceptTagTypeInfoContext) {
273: StudioConceptTagTypeInfoContext scttic = (StudioConceptTagTypeInfoContext) inCtic;
274: scttic.setTypeTitle("Console Macro");
275: scttic.setTypeDescription("Console Macro");
276: }
277: }
278:
279: //
280: //
281: //
282: public ConceptTagCharacteristic generateNextPage(
283: String inFromHandle, String inAliasFromHandle,
284: String inSourPage, String inDestPage) {
285: //, String inTreeState) {
286: //
287: ConceptTagCharacteristic outValue = null;
288:
289: //
290: //
291: ConceptTagCharacteristicHolder pageCtcharh = this .pageCtchar
292: .createRegisteredHolder(this .pageCtchar
293: .getValueLength(), true);
294: //
295: ConceptTagCharacteristic fromHandleCtchar = pageCtcharh
296: .registerCharacteristic(PAGE_CTCON_FROM_HANDLE_CTCTEMP);
297: fromHandleCtchar.addValue(0, inFromHandle);
298: //
299: ConceptTagCharacteristic aliasFromHandleCtchar = pageCtcharh
300: .registerCharacteristic(PAGE_CTCON_ALIAS_FROM_HANDLE_CTCTEMP);
301: aliasFromHandleCtchar.addValue(0, inAliasFromHandle);
302: //
303: ConceptTagCharacteristic sourcePageCtchar = pageCtcharh
304: .registerCharacteristic(PAGE_CTCON_SOURCE_PAGE_CTCTEMP);
305: sourcePageCtchar.addValue(0, inSourPage);
306: //
307: ConceptTagCharacteristic destinationPageCtchar = pageCtcharh
308: .registerCharacteristic(PAGE_CTCON_DESTINATION_PAGE_CTCTEMP);
309: destinationPageCtchar.addValue(0, inDestPage);
310: //
311: //ConceptTagCharacteristic treeStateCtchar =
312: // pageCtcharh.registerCharacteristic(
313: // PAGE_CTCON_TREE_STATE_CTCTEMP);
314: //treeStateCtchar.addValue(0, inTreeState);
315: //
316: ConceptTagCharacteristic descriptionCtchar = pageCtcharh
317: .registerCharacteristic(PAGE_CTCON_DESCRIPTION_CTCTEMP);
318: if (this .nextPageDescription != null) {
319: descriptionCtchar.addValue(0, this .nextPageDescription);
320: this .nextPageDescription = null;
321: }
322: //
323: outValue = pageCtcharh
324: .registerCharacteristic(PAGE_CTCON_ACTION_CTCTEMP);
325:
326: return outValue;
327: }
328:
329: //
330: public void processRecordCommands(String inCommands,
331: String inFromHandle, String inAliasFromHandle,
332: String inSourPage, String inDestPage) {
333: //, String inTreeState) {
334: //
335: //MiscHelper.println("RootV1ConMacCt proRecCom - Not Implemented");
336: //MiscHelper.println("RootV1ConMacCt proRecCom - comm = " + inCommands);
337:
338: try {
339:
340: ConceptTagCharacteristic actionCtchar = generateNextPage(
341: inFromHandle, inAliasFromHandle, inSourPage,
342: inDestPage);
343:
344: Document doc = XMLHelper.loadDocument("<COMMANDS>"
345: + inCommands + "</COMMANDS>");
346: Element rootEle = doc.getDocumentElement();
347: NodeList nl = rootEle.getChildNodes();
348: for (int i = 0; i < nl.getLength(); i++) {
349: Node nextNode = nl.item(i);
350: if (nextNode instanceof Element) {
351: Element nextEle = (Element) nextNode;
352:
353: RecordActionContext nextRac = RecordActionContext
354: .newInstance(nextEle);
355:
356: //
357: if (nextRac
358: .isAction(SubmitActionParameters.STOP_RECORDING)) {
359: //
360: //don't record
361: } else if (!nextRac
362: .isAction(RecordActionContext.ACTION__IN_PAGE)) {
363: //
364: SubmitActionConsoleMacroTag.newInstance(
365: actionCtchar, nextRac);
366: } else {
367: //
368: if (nextRac
369: .isSubAction(RecordActionContext.SUB_ACTION__CLICK)) {
370: //
371: String id = nextRac
372: .getParameter(ConsoleParameterContext.FIRST_INPUT);
373: //
374: CursorClickConsoleMacroTag.newInstance(
375: actionCtchar, id);
376: } else if (nextRac
377: .isSubAction(RecordActionContext.SUB_ACTION__CHANGE_VALUE)) {
378: //
379: String id = nextRac
380: .getParameter(ConsoleParameterContext.FIRST_INPUT);
381: String value = nextRac
382: .getParameter(ConsoleParameterContext.SECOND_INPUT);
383: //
384: ChangeFormValueConsoleMacroTag.newInstance(
385: actionCtchar, id, value);
386: } else {
387: nextRac.unknownAction();
388: }
389: }
390: }
391: }
392: } catch (ParserConfigurationException pce) {
393: throw new UnexpectedSystemException(pce);
394: } catch (SAXException saxe) {
395: throw new UnexpectedSystemException(saxe);
396: } catch (IOException ioe) {
397: throw new UnexpectedSystemException(ioe);
398: }
399: }
400:
401: //
402: public void reset(String inStartDesc, String inEndDesc,
403: HashMap inVars) {
404:
405: //
406: this .startAtIndex = 0;
407: this .endAtIndex = this .pageCtchar.getValueLength();
408: //
409: if (inStartDesc != null
410: && getPageIndexOfDescription(inStartDesc) != -1) {
411: //
412: this .startAtIndex = getPageIndexOfDescription(inStartDesc);
413: }
414: //
415: if (inEndDesc != null
416: && getPageIndexOfDescription(inEndDesc) != -1) {
417: //
418: this .endAtIndex = getPageIndexOfDescription(inEndDesc);
419: }
420: //
421: this .variables = inVars;
422: //
423: this .currentPage = this .startAtIndex;
424: }
425:
426: public void postIncrementCommand(RootConceptTagHolder inRcth) {
427: //
428: ConceptTagCharacteristicHolder localCtcharh = getCurrentCommand();
429: //
430: ConceptTagCharacteristic actionCtchar = localCtcharh
431: .getCharacteristic(PAGE_CTCON_ACTION_CTCTEMP);
432: //
433: ConceptTag localCt = actionCtchar.getValueAsConceptTag(0, null);
434: //
435: if (localCt instanceof IterativeConsoleMacroTag) {
436: IterativeConsoleMacroTag localIcmt = ((IterativeConsoleMacroTag) localCt);
437: if (localIcmt.isCommandFinished(inRcth)) {
438: this .currentPage++;
439: }
440: } else {
441: this .currentPage++;
442: }
443: }
444:
445: public void preIncrementCommand(RootConceptTagHolder inRcth) {
446: //
447: while (!isDoneRunning()) {
448: //
449: //
450: ConceptTagCharacteristicHolder localCtcharh = getCurrentCommand();
451: //
452: ConceptTagCharacteristic actionCtchar = localCtcharh
453: .getCharacteristic(PAGE_CTCON_ACTION_CTCTEMP);
454: //
455: ConceptTag localCt = actionCtchar.getValueAsConceptTag(0,
456: null);
457: //
458: if (localCt instanceof IterativeConsoleMacroTag) {
459: IterativeConsoleMacroTag localIcmt = ((IterativeConsoleMacroTag) localCt);
460: if (localIcmt.isCommandFinished(inRcth)) {
461: this .currentPage++;
462: } else {
463: break;
464: }
465: } else {
466: break;
467: }
468: }
469: }
470:
471: /*
472: public void incrementCommandOld(RootConceptTagHolder inRcth) {
473: //
474: this.currentPage = incrementCommandProjectedIndexOld(inRcth);
475: //
476: }
477: private int incrementCommandProjectedIndexOld(RootConceptTagHolder inRcth) {
478: //
479: int outValue = this.currentPage;
480: //
481: //
482: //
483: ConceptTagCharacteristicHolder localCtcharh =
484: getCommandAtIndex(outValue);
485: //
486: ConceptTagCharacteristic actionCtchar =
487: localCtcharh.getCharacteristic(
488: PAGE_CTCON_ACTION_CTCTEMP);
489: //
490: ConceptTag localCt = actionCtchar.getValueAsConceptTag(0, null);
491: //
492: if (localCt instanceof IterativeConsoleMacroTag) {
493: IterativeConsoleMacroTag localIcmt =
494: ((IterativeConsoleMacroTag)localCt);
495: if (localIcmt.isCommandFinished(inRcth)) {
496: outValue++;
497: }
498: }
499: else {
500: outValue++;
501: }
502: //
503: //
504: //
505: while (!isDoneRunning(outValue)) {
506: //
507: //
508: localCtcharh = getCommandAtIndex(outValue);
509: //
510: actionCtchar = localCtcharh.getCharacteristic(
511: PAGE_CTCON_ACTION_CTCTEMP);
512: //
513: localCt = actionCtchar.getValueAsConceptTag(0, null);
514: //
515: if (localCt instanceof IterativeConsoleMacroTag) {
516: IterativeConsoleMacroTag localIcmt =
517: ((IterativeConsoleMacroTag)localCt);
518: if (localIcmt.isCommandFinished(inRcth)) {
519: outValue++;
520: }
521: }
522: else {
523: break;
524: }
525: }
526: //
527: //
528: return outValue;
529: }
530: */
531: public boolean isDoneRunning() {
532: return (this .currentPage >= this .endAtIndex);
533: //return isDoneRunning(this.currentPage);
534: //this.pageCtchar.getValueLength());
535: }
536:
537: //public boolean isDoneRunning(int inIndex) {
538: // return (inIndex >= this.endAtIndex);
539: // //this.pageCtchar.getValueLength());
540: //}
541: //public String getTreeState() {
542: //
543: // String outValue = null;
544: //
545: // ConceptTagCharacteristic treeCtchar =
546: // getCurrentCommand().getCharacteristic(
547: // PAGE_CTCON_TREE_STATE_CTCTEMP);
548: //
549: // outValue = treeCtchar.getValueAsString(0, null);
550: //
551: // return outValue;
552: //}
553: public boolean isMacroReset() {
554: return (this .currentPage == this .startAtIndex);
555: }
556:
557: private ConceptTagCharacteristicHolder getCurrentCommand() {
558: return this .pageCtchar.getValueAsHolder(this .currentPage, null);
559: //return getCommandAtIndex(this.currentPage);
560: }
561:
562: //private ConceptTagCharacteristicHolder getCommandAtIndex(int inIndex) {
563: // return this.pageCtchar.getValueAsHolder(inIndex, null);
564: //}
565: //
566: //
567: //
568: public void generateMacroCommands(PageSetupContext inPsc,
569: ConsoleTemplateSession inCts, RootConceptTagHolder inRcth,
570: HashMap inVars, String inFromHandle,
571: String inAliasFromHandle, String inSourcePage,
572: String inDestinationPage) {
573: //
574: //inPsc.resetMacroCommands();
575: //
576: ConceptTagCharacteristicHolder ctcharh = getCurrentCommand();
577: //
578: ConceptTagCharacteristic fromHandleCtchar = ctcharh
579: .getCharacteristic(PAGE_CTCON_FROM_HANDLE_CTCTEMP);
580: String fromHandle = fromHandleCtchar.getValueAsString(0, null);
581: //
582: ConceptTagCharacteristic aliasFromHandleCtchar = ctcharh
583: .getCharacteristic(PAGE_CTCON_ALIAS_FROM_HANDLE_CTCTEMP);
584: String aliasFromHandle = aliasFromHandleCtchar
585: .getValueAsString(0, null);
586: //
587: ConceptTagCharacteristic sourcePageCtchar = ctcharh
588: .getCharacteristic(PAGE_CTCON_SOURCE_PAGE_CTCTEMP);
589: String sourceWebPage = sourcePageCtchar.getValueAsString(0,
590: null);
591: //
592: ConceptTagCharacteristic destinationPageCtchar = ctcharh
593: .getCharacteristic(PAGE_CTCON_DESTINATION_PAGE_CTCTEMP);
594: String destinationWebPage = destinationPageCtchar
595: .getValueAsString(0, null);
596: //
597: ConceptTagCharacteristic actionCtchar = ctcharh
598: .getCharacteristic(PAGE_CTCON_ACTION_CTCTEMP);
599: for (int i = 0; i < actionCtchar.getValueLength(); i++) {
600: ConceptTag nextCt = actionCtchar.getValueAsConceptTag(i,
601: null);
602: ConsoleMacroTag nextCmct = (ConsoleMacroTag) nextCt;
603: nextCmct.generateMacroCommands(inPsc, inCts, inRcth,
604: this .variables, fromHandle, aliasFromHandle,
605: sourceWebPage, destinationWebPage);
606: }
607: }
608:
609: public int getCurrentIndex() {
610: return this .currentPage;
611: }
612:
613: public int getMacroCommandCount() {
614: return this .pageCtchar.getValueLength();
615: }
616:
617: //
618: //
619: //
620: //
621: //
622: public void addDescriptionToNextPage(String inDescription) {
623: this .nextPageDescription = inDescription;
624: }
625:
626: public ArrayList getPageDescriptions() {
627:
628: ArrayList outValue = new ArrayList();
629:
630: for (int i = 0; i < getMacroCommandCount(); i++) {
631: String nextDescription = getDescription(i);
632: if (nextDescription != null) {
633: outValue.add(nextDescription);
634: }
635: }
636:
637: return outValue;
638: }
639:
640: public int getPageIndexOfDescription(String inDescription) {
641:
642: int outValue = -1;
643:
644: for (int i = 0; i < getMacroCommandCount(); i++) {
645: String nextDescription = getDescription(i);
646: if (nextDescription != null && inDescription != null
647: && nextDescription.equals(inDescription)) {
648: //
649: outValue = i;
650: break;
651: //outValue.add(nextDescription);
652: }
653: }
654:
655: return outValue;
656: }
657:
658: public String getDescription(int inIndex) {
659:
660: String outValue = null;
661:
662: ConceptTagCharacteristicHolder ctcharh = this .pageCtchar
663: .getValueAsHolder(inIndex, null);
664:
665: ConceptTagCharacteristic descriptionCtchar = ctcharh
666: .getCharacteristic(PAGE_CTCON_DESCRIPTION_CTCTEMP);
667:
668: if (descriptionCtchar.getValueLength() > 0
669: && descriptionCtchar.isStatic(0, null)) {
670: //
671: outValue = descriptionCtchar.getValueAsString(0, null);
672: }
673:
674: return outValue;
675:
676: }
677:
678: //
679: //
680: //
681: //
682: public void loadRcthConstraintBuilderIfPresent(
683: PageSetupContext inPsc, RootConceptTagHolder inRcth) {
684: //
685: //int projectedIndex = incrementCommandProjectedIndex(inRcth);
686: //if (!isDoneRunning(projectedIndex) && inRcth != null) {
687: if (!isDoneRunning() && inRcth != null) {
688: //
689: ConceptTagCharacteristicHolder localCtcharh = getCurrentCommand();
690: // getCommandAtIndex(projectedIndex);
691: //
692: ConceptTagCharacteristic actionCtchar = localCtcharh
693: .getCharacteristic(PAGE_CTCON_ACTION_CTCTEMP);
694: //
695: ConceptTag localCt = actionCtchar.getValueAsConceptTag(0,
696: null);
697: //
698: if (localCt instanceof IterativeConsoleMacroTag) {
699: IterativeConsoleMacroTag localIcmt = ((IterativeConsoleMacroTag) localCt);
700: if (!localIcmt.isCommandFinished(inRcth)) {
701: //outValue++;
702: RcthConstraintBuilder localRcb = localIcmt
703: .getNextActionType(inRcth);
704: inPsc.setStudioMacroEdit(localRcb);
705: }
706: }
707: }
708: }
709:
710: public void initializeParameters(ParameterSet inPs) {
711: //
712: ConceptTagCharacteristicHolder pageCtcharh = this .pageCtchar
713: .getValueAsHolder((this .currentPage - 1), null);
714: //
715: //
716: if (pageCtcharh
717: .isCharacteristicPresent(PAGE_CTCON_PARAMETER_CTCTEMP)) {
718: //
719: ConceptTagCharacteristic parameterCtchar = pageCtcharh
720: .getCharacteristic(PAGE_CTCON_PARAMETER_CTCTEMP);
721: //
722: for (int i = 0; i < parameterCtchar.getValueLength(); i++) {
723: //
724: //
725: ConceptTagCharacteristicHolder parameterCtcharh = parameterCtchar
726: .getValueAsHolder(i, null);
727: //
728: //
729: //
730: ConceptTagCharacteristic nameCtchar = parameterCtcharh
731: .getCharacteristic(PAGE_CTCON_PARAMETER_CTCTEMP_NAME_CTCTEMP);
732: //
733: ConceptTagCharacteristic fileNameCtchar = parameterCtcharh
734: .getCharacteristic(PAGE_CTCON_PARAMETER_CTCTEMP_FILE_NAME_CTCTEMP);
735: //
736: ConceptTagCharacteristic valueCtchar = parameterCtcharh
737: .getCharacteristic(PAGE_CTCON_PARAMETER_CTCTEMP_VALUE_CTCTEMP);
738: //
739: //
740: //
741: String parameterName = null;
742: String parameterFileName = null;
743: String parameterValue = null;
744: byte parameterFileUpload[] = null;
745: //
746: parameterName = nameCtchar.getValueAsString(0, null);
747: parameterName = ConsoleMacroTagHelper.replaceEnvVars(
748: parameterName, this .variables);
749: if (fileNameCtchar.getValueLength() > 0) {
750: parameterFileName = fileNameCtchar
751: .getValueAsString(0, null);
752: parameterFileName = ConsoleMacroTagHelper
753: .replaceEnvVars(parameterFileName,
754: this .variables);
755: Object o[] = nameCtchar
756: .getLocalFile(0, CONTENT_TXT);
757: parameterFileUpload = ((byte[]) o[1]);
758: }
759: if (valueCtchar.getValueLength() > 0) {
760: parameterValue = valueCtchar.getValueAsString(0,
761: null);
762: parameterValue = ConsoleMacroTagHelper
763: .replaceEnvVars(parameterValue,
764: this .variables);
765: }
766: //
767: //
768: //
769: if (parameterFileName != null
770: && parameterFileUpload != null) {
771: //
772: inPs.removeParameterHolderIfPresent(parameterName);
773: inPs.addFileUpload(parameterName,
774: parameterFileName, parameterFileUpload);
775: } else if (parameterValue != null) {
776: //
777: inPs.removeParameterHolderIfPresent(parameterName);
778: inPs.addParameter(parameterName, parameterValue);
779: } else {
780: throw UnexpectedSystemException.unknownState();
781: }
782: //
783: //
784: //
785: //inPs.addFileUpload(
786: // nameCtchar.getValueAsString(0, null),
787: // fileNameCtchar.getValueAsString(0, null), ((byte[])o[1]));
788: }
789: }
790:
791: }
792:
793: //
794: public void addParameterAsFileUpload(String inName,
795: String inFileName, byte inContent[]) {
796: //
797: //
798: //
799: addParameter(inName, inFileName, inContent, null);
800: //
801: //
802: }
803:
804: public void addParameterAsString(String inName, String inValue) {
805: //
806: //
807: //
808: addParameter(inName, null, null, inValue);
809: //
810: //
811: }
812:
813: private void addParameter(String inName, String inFileName,
814: byte inContent[], String inValue) {
815: //
816: //
817: //
818: ConceptTagCharacteristicHolder pageCtcharh = this .pageCtchar
819: .getValueAsHolder(this .pageCtchar.getValueLength() - 1,
820: null);
821: //
822: ConceptTagCharacteristic parameterCtchar = null;
823: if (pageCtcharh
824: .isCharacteristicPresent(PAGE_CTCON_PARAMETER_CTCTEMP)) {
825: //
826: parameterCtchar = pageCtcharh
827: .getCharacteristic(PAGE_CTCON_PARAMETER_CTCTEMP);
828: } else {
829: parameterCtchar = pageCtcharh
830: .registerCharacteristic(PAGE_CTCON_PARAMETER_CTCTEMP);
831: }
832: //
833: ConceptTagCharacteristicHolder parameterCtcharh = parameterCtchar
834: .createRegisteredHolder(parameterCtchar
835: .getValueLength(), true);
836: //
837: //
838: //
839: ConceptTagCharacteristic nameCtchar = parameterCtcharh
840: .registerCharacteristic(PAGE_CTCON_PARAMETER_CTCTEMP_NAME_CTCTEMP);
841: //
842: ConceptTagCharacteristic fileNameCtchar = parameterCtcharh
843: .registerCharacteristic(PAGE_CTCON_PARAMETER_CTCTEMP_FILE_NAME_CTCTEMP);
844: //
845: ConceptTagCharacteristic valueCtchar = parameterCtcharh
846: .registerCharacteristic(PAGE_CTCON_PARAMETER_CTCTEMP_VALUE_CTCTEMP);
847: //
848: //
849: //
850: if (inName != null) {
851: nameCtchar.addValue(0, inName);
852: }
853: //
854: if (inFileName != null) {
855: fileNameCtchar.addValue(0, inFileName);
856: }
857: //
858: if (inContent != null) {
859: nameCtchar.createLocalFile(0, CONTENT_TXT, inContent);
860: }
861: //
862: if (inValue != null) {
863: valueCtchar.addValue(0, inValue);
864: }
865: //
866: //
867: //
868: //
869: //
870: //
871: //
872: //
873: }
874: }
|