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 CommonFunctionListSubListTag extends
044: BaseCommonFunctionCompatibilityTag implements
045: SelfArgumentlessConstructor {
046:
047: //characteristics
048: private ConceptTagCharacteristic listCtchar = null;
049: private ConceptTagCharacteristic startIndexCtchar = null;
050: private ConceptTagCharacteristic endIndexCtchar = 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 START_INDEX_CTCON = "start-index";
058: private final static String START_INDEX_TITLE = "Start Index";
059: private final static String START_INDEX_SHORT_DESCRIPTION = "Start Index";
060: //
061: private final static String END_INDEX_CTCON = "end-index";
062: private final static String END_INDEX_TITLE = "End Index";
063: private final static String END_INDEX_SHORT_DESCRIPTION = "End Index";
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 "start-index"
089: ConceptTagConstraint startIndexCtcon = ConceptTagConstraint
090: .newInstance(START_INDEX_CTCON, rootCtconh);
091: //
092: startIndexCtcon.setTitle(START_INDEX_TITLE);
093: startIndexCtcon
094: .setShortDescription(START_INDEX_SHORT_DESCRIPTION);
095: //
096: //
097: startIndexCtcon.setMinimumLength(0);
098: startIndexCtcon.setMaximumLength(1);
099: //
100: DynamicConceptTagConstraintContext startIndexDctcc = DynamicConceptTagConstraintContext
101: .newInstance(startIndexCtcon);
102: startIndexDctcc.getValidator().allowReturnOfOnlyList();
103: startIndexDctcc.getValidator().filterDirectChildOfRootAndHtml();
104: //
105: StaticConceptTagConstraintContext startIndexSctcc = StaticConceptTagConstraintContext
106: .newInstance(startIndexCtcon);
107: startIndexSctcc.setRegularExpression(
108: CommonExpressions.NON_NEGATIVE_INTEGER,
109: "Value must be non-negative integer");
110:
111: //constrain "end-index"
112: ConceptTagConstraint endIndexCtcon = ConceptTagConstraint
113: .newInstance(END_INDEX_CTCON, rootCtconh);
114: //
115: endIndexCtcon.setTitle(END_INDEX_TITLE);
116: endIndexCtcon.setShortDescription(END_INDEX_SHORT_DESCRIPTION);
117: //
118: //
119: endIndexCtcon.setMinimumLength(0);
120: endIndexCtcon.setMaximumLength(1);
121: //
122: DynamicConceptTagConstraintContext endIndexDctcc = DynamicConceptTagConstraintContext
123: .newInstance(endIndexCtcon);
124: endIndexDctcc.getValidator().allowReturnOfOnlyList();
125: endIndexDctcc.getValidator().filterDirectChildOfRootAndHtml();
126: //
127: StaticConceptTagConstraintContext endIndexSctcc = StaticConceptTagConstraintContext
128: .newInstance(endIndexCtcon);
129: endIndexSctcc.setRegularExpression(
130: CommonExpressions.NON_NEGATIVE_INTEGER,
131: "Value must be non-negative integer");
132:
133: //
134: ConceptTagFlagsHelper
135: .pushNonIterativeCommonFunctionDepth(inIctc);
136: inIctc.initialize();
137: ConceptTagFlagsHelper
138: .popNonIterativeCommonFunctionDepth(inIctc);
139:
140: //initialize characteristics
141: this .listCtchar = listCtcon.getCharacteristic();
142: this .startIndexCtchar = startIndexCtcon.getCharacteristic();
143: this .endIndexCtchar = endIndexCtcon.getCharacteristic();
144: }
145:
146: public void appraise(AppraiseConceptTagContext inActc) {
147:
148: if (inActc instanceof StudioConceptTagInstanceInfoContext) {
149:
150: StudioConceptTagInstanceInfoContext sctiic = (StudioConceptTagInstanceInfoContext) inActc;
151:
152: //
153: sctiic.setInstanceTitle("Get Sub List");
154: sctiic.setInstanceDescription("Get Sub List");
155: } else if (inActc instanceof StudioConceptTagTypeInfoContext) {
156:
157: StudioConceptTagTypeInfoContext scttic = (StudioConceptTagTypeInfoContext) inActc;
158:
159: scttic.setTypeTitle("Get Sub List");
160: scttic.setTypeDescription("Get Sub List");
161: } else if (inActc instanceof WebPageTagInstanceViewContext) {
162:
163: WebPageTagInstanceViewContext wptivc = (WebPageTagInstanceViewContext) inActc;
164:
165: WebPageTagInstanceViewContextInfo info = wptivc
166: .getInfoAsNonHtml();
167:
168: //
169: //
170: //
171: WebPageTagInstanceViewContextInfo extractInfo = info
172: .createNonHtmlInfo();
173: //
174: if (this .startIndexCtchar.getValueLength() > 0) {
175: extractInfo.setNonHtmlContent(
176: "Extract Sub List From Index (", ")");
177: WebPageTagInstanceViewContext.displayView(
178: this .startIndexCtchar, extractInfo, wptivc);
179: //extractInfo.setEndContent(")");
180: } else {
181: extractInfo
182: .setNonHtmlContent("Extract Sub List From The Start Of");
183: }
184: //
185: //
186: //
187: WebPageTagInstanceViewContextInfo toInfo = info
188: .createNonHtmlInfo();
189: //
190: //
191: if (this .endIndexCtchar.getValueLength() > 0) {
192: toInfo.setNonHtmlContent(" To Index (", ") Of");
193: WebPageTagInstanceViewContext.displayView(
194: this .endIndexCtchar, toInfo, wptivc);
195: //toInfo.setEndContent(") Of");
196: } else {
197: toInfo.setNonHtmlContent("", " To The End Of");
198: }
199: //
200: //
201: //
202: WebPageTagInstanceViewContextInfo listInfo = info
203: .createNonHtmlInfo();
204: //
205: listInfo.setNonHtmlContent(" List (", ")");
206: WebPageTagInstanceViewContext.displayView(this .listCtchar,
207: listInfo, wptivc);
208: //listInfo.setEndContent(")");
209: } else if (inActc instanceof SelectionCriteriaForReturnableConceptTag) {
210:
211: SelectionCriteriaForReturnableConceptTag scfrct = (SelectionCriteriaForReturnableConceptTag) inActc;
212:
213: scfrct.canReturnList();
214: scfrct.declareFormatAsPlain();
215: } else if (inActc instanceof StudioConceptTagCreParInfoContext) {
216:
217: StudioConceptTagCreParInfoContext scpc = (StudioConceptTagCreParInfoContext) inActc;
218: }
219: }
220:
221: public void determineValueAndClass(
222: DetermineValueAndClassConceptTagContext inDvacctc) {
223:
224: try {
225: ValueAndClassForConceptTag vacfct = null;
226:
227: ValueAndClassForConceptTag listVacfct = this .listCtchar
228: .getDetermineValueAndClass(0, inDvacctc);
229:
230: Object startIndex = getIndex(this .startIndexCtchar,
231: StandardDataTypes.getDecimalInstance("0"),
232: inDvacctc);
233:
234: Object endIndex = getIndex(this .endIndexCtchar,
235: StandardDataTypes.getListLength(listVacfct
236: .getValue()), inDvacctc);
237:
238: //
239: //
240: //
241: //
242: Object o = StandardDataTypes.getSubList(listVacfct
243: .getValue(), startIndex, endIndex);
244: vacfct = ValueAndClassForConceptTag.newInstance(o,
245: StandardDataTypes.getListClass());
246:
247: //vacfct = ValueAndClassForConceptTag.newDecimal(bd);
248:
249: inDvacctc.setDetermineValueAndClass(vacfct);
250: } catch (DetermineValueAndClassConceptTagException dvaccte) {
251: inDvacctc.setDetermineException(dvaccte);
252: }
253: }
254:
255: protected final static Object getIndex(
256: ConceptTagCharacteristic inCtchar, Object inDefault,
257: DetermineValueAndClassConceptTagContext inDvacctc)
258: throws DetermineValueAndClassConceptTagException {
259: //
260: Object outValue = inDefault;
261:
262: if (inCtchar.getValueLength() > 0) {
263: if (inCtchar.isStatic(0, inDvacctc)) {
264: //
265: outValue = StandardDataTypes
266: .getDecimalInstance(inCtchar.getValueAsString(
267: 0, inDvacctc));
268: } else {
269: ValueAndClassForConceptTag indexVacfct = inCtchar
270: .getDetermineValueAndClass(0, inDvacctc);
271: //
272: outValue = indexVacfct.getValue();
273: }
274: }
275:
276: return outValue;
277: }
278:
279: public void determineClass(DetermineClassConceptTagContext inDcctc) {
280: inDcctc.setDetermineClass(StandardDataTypes.getListClass());
281: }
282:
283: public Object createUninitializedSelf() {
284: return new CommonFunctionListSubListTag();
285: }
286:
287: }
|