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.function.v1;
009:
010: //base classes
011:
012: //project specific classes
013: import org.jfolder.common.SelfArgumentlessConstructor;
014: import org.jfolder.common.StandardDataTypes;
015: import org.jfolder.common.UnexpectedSystemException;
016: import org.jfolder.common.function.BaseCommonFunctionCompatibilityTag;
017: import org.jfolder.common.function.WebPageTagInstanceViewContext;
018: import org.jfolder.common.function.WebPageTagInstanceViewContextInfo;
019: import org.jfolder.common.tagging.AppraiseConceptTagContext;
020: import org.jfolder.common.tagging.ConceptTag;
021: import org.jfolder.common.tagging.ConceptTagCharacteristic;
022: import org.jfolder.common.tagging.ConceptTagConstraint;
023: import org.jfolder.common.tagging.ConceptTagConstraintHolder;
024: import org.jfolder.common.tagging.ConceptTagFlagsHelper;
025: import org.jfolder.common.tagging.ConceptTagHelper;
026: import org.jfolder.common.tagging.DetermineClassConceptTagContext;
027: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagContext;
028: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagException;
029: import org.jfolder.common.tagging.DynamicConceptTagConstraintContext;
030: import org.jfolder.common.tagging.InitializeConceptTagContext;
031: import org.jfolder.common.tagging.ReturnableConceptTag;
032: import org.jfolder.common.tagging.SelectionCriteriaForReturnableConceptTag;
033: import org.jfolder.common.tagging.StaticConceptTagConstraintContext;
034: import org.jfolder.common.tagging.StudioConceptTagCreParInfoContext;
035: import org.jfolder.common.tagging.StudioConceptTagInstanceInfoContext;
036: import org.jfolder.common.tagging.StudioConceptTagTypeInfoContext;
037: import org.jfolder.common.tagging.ValueAndClassForConceptTag;
038: import org.jfolder.common.utils.misc.CommonExpressions;
039: import org.jfolder.common.utils.misc.MiscHelper;
040:
041: //other classes
042:
043: public class CommonFunctionListAddAllTag extends
044: BaseCommonFunctionCompatibilityTag implements
045: SelfArgumentlessConstructor {
046:
047: //characteristics
048: private ConceptTagCharacteristic listCtchar = null;
049: private ConceptTagCharacteristic indexCtchar = null;
050: private ConceptTagCharacteristic valueCtchar = null;
051:
052: //list details
053: private final static String LIST_CTCON = "list";
054: private final static String LIST_TITLE = "List";
055: private final static String LIST_SHORT_DESCRIPTION = "List";
056: //
057: private final static String INDEX_CTCON = "index";
058: private final static String INDEX_TITLE = "Index";
059: private final static String INDEX_SHORT_DESCRIPTION = "Index";
060: //
061: private final static String VALUE_CTCON = "value";
062: private final static String VALUE_TITLE = "Value";
063: private final static String VALUE_SHORT_DESCRIPTION = "Value";
064:
065: public void initialize(InitializeConceptTagContext inIctc) {
066:
067: //
068: ConceptTagConstraintHolder rootCtconh = ConceptTagConstraintHolder
069: .newInstance(inIctc);
070:
071: //constrain "list"
072: ConceptTagConstraint listCtcon = ConceptTagConstraint
073: .newInstance(LIST_CTCON, rootCtconh);
074: //
075: listCtcon.setTitle(LIST_TITLE);
076: listCtcon.setShortDescription(LIST_SHORT_DESCRIPTION);
077: //
078: //
079: listCtcon.setMinimumLength(1);
080: listCtcon.setMaximumLength(1);
081: //
082: DynamicConceptTagConstraintContext listDctcc = DynamicConceptTagConstraintContext
083: .newInstance(listCtcon);
084: listDctcc.getValidator().allowReturnOfOnlyList();
085: listDctcc.getValidator().filterDirectChildOfRootAndHtml();
086: //
087:
088: //constrain "index"
089: ConceptTagConstraint indexCtcon = ConceptTagConstraint
090: .newInstance(INDEX_CTCON, rootCtconh);
091: //
092: indexCtcon.setTitle(INDEX_TITLE);
093: indexCtcon.setShortDescription(INDEX_SHORT_DESCRIPTION);
094: //
095: //
096: indexCtcon.setMinimumLength(0);
097: indexCtcon.setMaximumLength(1);
098: //
099: DynamicConceptTagConstraintContext indexDctcc = DynamicConceptTagConstraintContext
100: .newInstance(indexCtcon);
101: indexDctcc.getValidator().allowReturnOfOnlyList();
102: indexDctcc.getValidator().filterDirectChildOfRootAndHtml();
103: //
104: StaticConceptTagConstraintContext indexSctcc = StaticConceptTagConstraintContext
105: .newInstance(indexCtcon);
106: indexSctcc.setRegularExpression(
107: CommonExpressions.NON_NEGATIVE_INTEGER,
108: "Value must be non-negative integer");
109:
110: //constrain "value"
111: ConceptTagConstraint valueCtcon = ConceptTagConstraint
112: .newInstance(VALUE_CTCON, rootCtconh);
113: //
114: valueCtcon.setTitle(VALUE_TITLE);
115: valueCtcon.setShortDescription(VALUE_SHORT_DESCRIPTION);
116: //
117: //
118: valueCtcon.setMinimumLength(1);
119: valueCtcon.setMaximumLength(1);
120: //
121: DynamicConceptTagConstraintContext valueDctcc = DynamicConceptTagConstraintContext
122: .newInstance(valueCtcon);
123: valueDctcc.getValidator().allowReturnOfOnlyList();
124: valueDctcc.getValidator().filterDirectChildOfRootAndHtml();
125: //
126:
127: //
128: ConceptTagFlagsHelper
129: .pushNonIterativeCommonFunctionDepth(inIctc);
130: inIctc.initialize();
131: ConceptTagFlagsHelper
132: .popNonIterativeCommonFunctionDepth(inIctc);
133:
134: //initialize characteristics
135: this .listCtchar = listCtcon.getCharacteristic();
136: this .indexCtchar = indexCtcon.getCharacteristic();
137: this .valueCtchar = valueCtcon.getCharacteristic();
138: }
139:
140: public void appraise(AppraiseConceptTagContext inActc) {
141:
142: if (inActc instanceof StudioConceptTagInstanceInfoContext) {
143:
144: StudioConceptTagInstanceInfoContext sctiic = (StudioConceptTagInstanceInfoContext) inActc;
145:
146: //
147: sctiic.setInstanceTitle("Add Another List");
148: sctiic.setInstanceDescription("Add Another List");
149: } else if (inActc instanceof StudioConceptTagTypeInfoContext) {
150:
151: StudioConceptTagTypeInfoContext scttic = (StudioConceptTagTypeInfoContext) inActc;
152:
153: scttic.setTypeTitle("Add Another List");
154: scttic.setTypeDescription("Add Another List");
155: } else if (inActc instanceof WebPageTagInstanceViewContext) {
156:
157: WebPageTagInstanceViewContext wptivc = (WebPageTagInstanceViewContext) inActc;
158:
159: WebPageTagInstanceViewContextInfo info = wptivc
160: .getInfoAsNonHtml();
161:
162: //
163: //
164: WebPageTagInstanceViewContextInfo insertInfo = info
165: .createNonHtmlInfo();
166: insertInfo.setNonHtmlContent("Insert All Values In (");
167: WebPageTagInstanceViewContext.displayView(this .valueCtchar,
168: insertInfo, wptivc);
169: //
170: //
171: WebPageTagInstanceViewContextInfo intoInfo = info
172: .createNonHtmlInfo();
173: intoInfo.setNonHtmlContent(") Into (");
174: WebPageTagInstanceViewContext.displayView(this .listCtchar,
175: intoInfo, wptivc);
176: //
177: //
178: WebPageTagInstanceViewContextInfo startingInfo = info
179: .createNonHtmlInfo();
180: if (this .indexCtchar.getValueLength() > 0) {
181: startingInfo.setNonHtmlContent(") Starting At Index (",
182: ")");
183: WebPageTagInstanceViewContext.displayView(
184: this .indexCtchar, startingInfo, wptivc);
185: //startingInfo.setEndContent(")");
186: } else {
187: startingInfo.setNonHtmlContent(") Starting At Its End");
188: }
189: } else if (inActc instanceof SelectionCriteriaForReturnableConceptTag) {
190:
191: SelectionCriteriaForReturnableConceptTag scfrct = (SelectionCriteriaForReturnableConceptTag) inActc;
192:
193: scfrct.canReturnNothing();
194: scfrct.declareFormatAsPlain();
195: } else if (inActc instanceof StudioConceptTagCreParInfoContext) {
196:
197: StudioConceptTagCreParInfoContext scpc = (StudioConceptTagCreParInfoContext) inActc;
198: }
199: }
200:
201: public void determineValueAndClass(
202: DetermineValueAndClassConceptTagContext inDvacctc) {
203:
204: try {
205: ValueAndClassForConceptTag listVacfct = this .listCtchar
206: .getDetermineValueAndClass(0, inDvacctc);
207:
208: Object index = StandardDataTypes.getListLength(listVacfct
209: .getValue());
210: //
211: if (this .indexCtchar.getValueLength() > 0) {
212: if (this .indexCtchar.isStatic(0, inDvacctc)) {
213: //
214: index = StandardDataTypes
215: .getDecimalInstance(this .indexCtchar
216: .getValueAsString(0, inDvacctc));
217: } else {
218: ValueAndClassForConceptTag indexVacfct = this .indexCtchar
219: .getDetermineValueAndClass(0, inDvacctc);
220: //
221: index = indexVacfct.getValue();
222: }
223: }
224:
225: ValueAndClassForConceptTag valueVacfct = this .valueCtchar
226: .getDetermineValueAndClass(0, inDvacctc);
227:
228: StandardDataTypes.addListToList(listVacfct.getValue(),
229: index, valueVacfct.getValue());
230:
231: inDvacctc
232: .setDetermineValueAndClass(ValueAndClassForConceptTag
233: .newNothing());
234: } catch (DetermineValueAndClassConceptTagException dvaccte) {
235: inDvacctc.setDetermineException(dvaccte);
236: }
237: }
238:
239: public void determineClass(DetermineClassConceptTagContext inDcctc) {
240: inDcctc.setDetermineClass(StandardDataTypes.getNothingClass());
241: }
242:
243: public Object createUninitializedSelf() {
244: return new CommonFunctionListAddAllTag();
245: }
246:
247: }
|