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 CommonFunctionStrSubstringTag extends
044: BaseCommonFunctionCompatibilityTag implements
045: SelfArgumentlessConstructor {
046:
047: //characteristics
048: private ConceptTagCharacteristic stringCtchar = null;
049: private ConceptTagCharacteristic startIndexCtchar = null;
050: private ConceptTagCharacteristic endIndexCtchar = null;
051:
052: //string details
053: private final static String STRING_CTCON = "string";
054: private final static String STRING_TITLE = "String";
055: private final static String STRING_SHORT_DESCRIPTION = "String";
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 "string"
072: ConceptTagConstraint stringCtcon = ConceptTagConstraint
073: .newInstance(STRING_CTCON, rootCtconh);
074: //
075: stringCtcon.setTitle(STRING_TITLE);
076: stringCtcon.setShortDescription(STRING_SHORT_DESCRIPTION);
077: //
078: //
079: stringCtcon.setMinimumLength(1);
080: stringCtcon.setMaximumLength(1);
081: //
082: DynamicConceptTagConstraintContext stringDctcc = DynamicConceptTagConstraintContext
083: .newInstance(stringCtcon);
084: stringDctcc.getValidator().allowReturnOfOnlyString();
085: stringDctcc.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().allowReturnOfOnlyDecimal();
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().allowReturnOfOnlyDecimal();
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 .stringCtchar = stringCtcon.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 Substring");
154: sctiic.setInstanceDescription("Get Substring");
155: } else if (inActc instanceof StudioConceptTagTypeInfoContext) {
156:
157: StudioConceptTagTypeInfoContext scttic = (StudioConceptTagTypeInfoContext) inActc;
158:
159: scttic.setTypeTitle("Get Substring");
160: scttic.setTypeDescription("Get Substring");
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 =
172: // info.createNonHtmlInfo();
173: //
174: WebPageTagInstanceViewContextInfo firstInfo = info
175: .createNonHtmlInfo();
176: //
177: WebPageTagInstanceViewContextInfo secondInfo = info
178: .createNonHtmlInfo();
179: //
180: WebPageTagInstanceViewContextInfo thirdInfo = info
181: .createNonHtmlInfo();
182: //
183: //
184: firstInfo.setNonHtmlContent("Get Substring From (", ") ");
185: WebPageTagInstanceViewContext.displayView(
186: this .stringCtchar, firstInfo, wptivc, "???");
187: //
188: //
189: secondInfo.setNonHtmlContent("Starting From (", ") ");
190: WebPageTagInstanceViewContext.displayView(
191: this .startIndexCtchar, secondInfo, wptivc,
192: "Beginning");
193: //
194: //
195: thirdInfo.setNonHtmlContent("And Finishing At (", ") ");
196: WebPageTagInstanceViewContext.displayView(
197: this .endIndexCtchar, thirdInfo, wptivc, "End");
198: //
199: } else if (inActc instanceof SelectionCriteriaForReturnableConceptTag) {
200:
201: SelectionCriteriaForReturnableConceptTag scfrct = (SelectionCriteriaForReturnableConceptTag) inActc;
202:
203: scfrct.canReturnString();
204: scfrct.declareFormatAsPlain();
205: } else if (inActc instanceof StudioConceptTagCreParInfoContext) {
206:
207: StudioConceptTagCreParInfoContext scpc = (StudioConceptTagCreParInfoContext) inActc;
208: }
209: }
210:
211: public void determineValueAndClass(
212: DetermineValueAndClassConceptTagContext inDvacctc) {
213:
214: try {
215: ValueAndClassForConceptTag vacfct = null;
216:
217: //
218: ValueAndClassForConceptTag stringVacfct = this .stringCtchar
219: .getDetermineValueAndClass(0, inDvacctc);
220: //
221: //
222: Object startIndex = CommonFunctionListSubListTag.getIndex(
223: this .startIndexCtchar, StandardDataTypes
224: .getDecimalInstance("0"), inDvacctc);
225: //
226: Object endIndex = CommonFunctionListSubListTag.getIndex(
227: this .endIndexCtchar, StandardDataTypes
228: .getStringLength(stringVacfct.getValue()),
229: inDvacctc);
230: //
231: vacfct = ValueAndClassForConceptTag
232: .newString(StandardDataTypes.getSubString(
233: stringVacfct.getValue(), startIndex,
234: endIndex));
235: //
236: //
237: //
238: //
239: //Object o = StandardDataTypes.getSubList(
240: // listVacfct.getValue(), startIndex, endIndex);
241: //vacfct = ValueAndClassForConceptTag.newInstance(
242: // o, StandardDataTypes.getListClass());
243:
244: //vacfct = ValueAndClassForConceptTag.newDecimal(bd);
245:
246: inDvacctc.setDetermineValueAndClass(vacfct);
247: } catch (DetermineValueAndClassConceptTagException dvaccte) {
248: inDvacctc.setDetermineException(dvaccte);
249: }
250: }
251:
252: public void determineClass(DetermineClassConceptTagContext inDcctc) {
253: inDcctc.setDetermineClass(StandardDataTypes.getStringClass());
254: }
255:
256: public Object createUninitializedSelf() {
257: return new CommonFunctionStrSubstringTag();
258: }
259:
260: }
|