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.util.HashMap;
012:
013: //project specific classes
014: import org.jfolder.common.tagging.AppraiseConceptTagContext;
015: import org.jfolder.common.tagging.CompoundConceptTagConstraintContext;
016: import org.jfolder.common.tagging.ConceptTagCharacteristic;
017: import org.jfolder.common.tagging.ConceptTagCharacteristicHolder;
018: import org.jfolder.common.tagging.ConceptTagConstraint;
019: import org.jfolder.common.tagging.ConceptTagConstraintHolder;
020: import org.jfolder.common.tagging.ConceptTagConstraintTemplate;
021: import org.jfolder.common.tagging.DynamicConceptTagConstraintContext;
022: import org.jfolder.common.tagging.InitializeConceptTagContext;
023: import org.jfolder.common.tagging.RootConceptTagHolder;
024: import org.jfolder.common.tagging.StaticConceptTagConstraintContext;
025: import org.jfolder.common.tagging.StudioConceptTagInstanceInfoContext;
026: import org.jfolder.common.tagging.StudioConceptTagTypeInfoContext;
027: import org.jfolder.common.web.template.ConsoleTemplateSession;
028: import org.jfolder.common.web.template.PageSetupContext;
029: import org.jfolder.console.macro.ConsoleMacro;
030: import org.jfolder.console.macro.ConsoleMacroTag;
031: import org.jfolder.console.macro.ConsoleMacroTagHelper;
032:
033: //other classes
034:
035: public class GoToConsoleMacroTag implements ConsoleMacroTag {
036:
037: ////characteristics
038: private ConceptTagCharacteristic idCtchar = null;
039:
040: //id details
041: private final static String ID_CTCON = "id";
042: private final static String ID_TITLE = "ID";
043: private final static String ID_SHORT_DESCRIPTION = "ID";
044:
045: ///////////////////////////////////
046:
047: public void initialize(InitializeConceptTagContext inIctc) {
048:
049: //
050: ConceptTagConstraintHolder rootCtconh = ConceptTagConstraintHolder
051: .newInstance(inIctc);
052:
053: //constrain "id"
054: ConceptTagConstraint idCtcon = ConceptTagConstraint
055: .newInstance(ID_CTCON, rootCtconh);
056: idCtcon.setTitle(ID_TITLE);
057: idCtcon.setShortDescription(ID_SHORT_DESCRIPTION);
058: //
059: StaticConceptTagConstraintContext idSctcc = StaticConceptTagConstraintContext
060: .newInstance(idCtcon);
061:
062: //
063: inIctc.initialize();
064:
065: //
066: this .idCtchar = idCtcon.getCharacteristic();
067: }
068:
069: //
070: public void appraise(AppraiseConceptTagContext inCtic) {
071: if (inCtic instanceof StudioConceptTagInstanceInfoContext) {
072: StudioConceptTagInstanceInfoContext sctiic = (StudioConceptTagInstanceInfoContext) inCtic;
073: sctiic.setInstanceTitle("Go To");
074: sctiic.setInstanceDescription("Go To");
075: } else if (inCtic instanceof StudioConceptTagTypeInfoContext) {
076: StudioConceptTagTypeInfoContext scttic = (StudioConceptTagTypeInfoContext) inCtic;
077: scttic.setTypeTitle("Go To");
078: scttic.setTypeDescription("Go To");
079: }
080: }
081:
082: //
083: public final static GoToConsoleMacroTag newInstance(
084: ConceptTagCharacteristic inCtchar, String inId) {
085: //
086: GoToConsoleMacroTag outValue = null;
087:
088: outValue = new GoToConsoleMacroTag();
089: //
090: ConceptTagCharacteristicHolder nextCtcharh = inCtchar.addValue(
091: inCtchar.getValueLength(), outValue, true);
092: //
093: ConceptTagCharacteristic nextIdCtchar = nextCtcharh
094: .registerCharacteristic(ID_CTCON);
095: nextIdCtchar.addValue(0, inId);
096: //
097:
098: return outValue;
099: }
100:
101: //
102: public void generateMacroCommands(PageSetupContext inPsc,
103: ConsoleTemplateSession inCts, RootConceptTagHolder inRcth,
104: HashMap inVars, String inFromHandle,
105: String inAliasFromHandle, String inSourcePage,
106: String inDestinationPage) {
107: //
108: String id = this .idCtchar.getValueAsString(0, null);
109: id = ConsoleMacroTagHelper.replaceEnvVars(id, inVars);
110: //
111: inPsc.addMacroCommand(getGoToCall(id));
112: }
113:
114: //
115: protected final static String getGoToCall(String inId) {
116:
117: StringBuffer outValue = new StringBuffer();
118:
119: outValue.append("macroGoTo('" + inId + "')");
120:
121: return outValue.toString();
122: }
123: }
|