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.ConceptTagCharacteristic;
021: import org.jfolder.common.tagging.ConceptTagConstraint;
022: import org.jfolder.common.tagging.ConceptTagConstraintHolder;
023: import org.jfolder.common.tagging.ConceptTagFlagsHelper;
024: import org.jfolder.common.tagging.DetermineClassConceptTagContext;
025: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagContext;
026: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagException;
027: import org.jfolder.common.tagging.DynamicConceptTagConstraintContext;
028: import org.jfolder.common.tagging.InitializeConceptTagContext;
029: import org.jfolder.common.tagging.SelectionCriteriaForReturnableConceptTag;
030: import org.jfolder.common.tagging.StaticConceptTagConstraintContext;
031: import org.jfolder.common.tagging.StudioConceptTagCreParInfoContext;
032: import org.jfolder.common.tagging.StudioConceptTagInstanceInfoContext;
033: import org.jfolder.common.tagging.StudioConceptTagTypeInfoContext;
034: import org.jfolder.common.tagging.ValueAndClassForConceptTag;
035: import org.jfolder.common.utils.misc.MiscHelper;
036:
037: //other classes
038:
039: public class CommonFunctionStrIsRegExprMatchTag extends
040: BaseCommonFunctionCompatibilityTag implements
041: SelfArgumentlessConstructor {
042:
043: //
044: private ConceptTagCharacteristic patternCtchar = null;
045: private ConceptTagCharacteristic valueCtchar = null;
046:
047: //variable details
048: private final static String PATTERN_CTCON = "pattern";
049: private final static String PATTERN_TITLE = "Pattern to match";
050: private final static String PATTERN_SHORT_DESCRIPTION = "Pattern compared against value";
051:
052: //value details
053: private final static String VALUE_CTCON = "value";
054: private final static String VALUE_TITLE = "Value";
055: private final static String VALUE_SHORT_DESCRIPTION = "Value of this string";
056:
057: //
058:
059: public void initialize(InitializeConceptTagContext inIctc) {
060:
061: //
062: ConceptTagConstraintHolder rootCtconh = ConceptTagConstraintHolder
063: .newInstance(inIctc);
064: //
065: //rootCtconh.getAttributes().setStudioVisibleOnlyOnError(true);
066: //rootCtconh.getStyles().setStudioVisibleOnlyOnError(true);
067:
068: //constrain "pattern"
069: ConceptTagConstraint patternCtcon = ConceptTagConstraint
070: .newInstance(PATTERN_CTCON, rootCtconh);
071: patternCtcon.setTitle(PATTERN_TITLE);
072: patternCtcon.setShortDescription(PATTERN_SHORT_DESCRIPTION);
073: patternCtcon.setMinimumLength(1);
074: patternCtcon.setMaximumLength(1);
075: //
076: StaticConceptTagConstraintContext patternSctcc = StaticConceptTagConstraintContext
077: .newInstance(patternCtcon);
078: //
079: patternSctcc.addDefaultValue("PatternHere");
080: //
081:
082: //constrain "value"
083: ConceptTagConstraint valueCtcon = ConceptTagConstraint
084: .newInstance(VALUE_CTCON, rootCtconh);
085: valueCtcon.setTitle(VALUE_TITLE);
086: valueCtcon.setShortDescription(VALUE_SHORT_DESCRIPTION);
087: valueCtcon.setMinimumLength(1);
088: valueCtcon.setMaximumLength(1);
089: //
090: DynamicConceptTagConstraintContext valueDctcc = DynamicConceptTagConstraintContext
091: .newInstance(valueCtcon);
092: valueDctcc.getValidator().filterDirectChildOfRootAndHtml();
093:
094: //
095: ConceptTagConstraint unconstrainedCtcon = rootCtconh
096: .getUndefinedConstraint();
097: //unconstrainedCtcon.setStudioVisibleOnlyOnError(true);
098:
099: //
100: ConceptTagFlagsHelper
101: .pushNonIterativeCommonFunctionDepth(inIctc);
102: inIctc.initialize();
103: ConceptTagFlagsHelper
104: .popNonIterativeCommonFunctionDepth(inIctc);
105:
106: //
107: //post initialization validation
108: //TO DO: compare class against value
109:
110: //
111: this .patternCtchar = patternCtcon.getCharacteristic();
112: this .valueCtchar = valueCtcon.getCharacteristic();
113: }
114:
115: public void appraise(AppraiseConceptTagContext inActc) {
116:
117: if (inActc instanceof StudioConceptTagInstanceInfoContext) {
118:
119: StudioConceptTagInstanceInfoContext sctiic = (StudioConceptTagInstanceInfoContext) inActc;
120:
121: sctiic.setInstanceTitle("Compare To RegEx");
122: sctiic.setInstanceDescription("Compare To RegEx");
123: } else if (inActc instanceof StudioConceptTagTypeInfoContext) {
124:
125: StudioConceptTagTypeInfoContext scttic = (StudioConceptTagTypeInfoContext) inActc;
126:
127: scttic.setTypeTitle("Compare To RegEx");
128: scttic.setTypeDescription("Compare To RegEx");
129: } else if (inActc instanceof WebPageTagInstanceViewContext) {
130:
131: WebPageTagInstanceViewContext wptivc = (WebPageTagInstanceViewContext) inActc;
132:
133: WebPageTagInstanceViewContextInfo info = wptivc
134: .getInfoAsNonHtml();
135:
136: //
137: //
138: WebPageTagInstanceViewContextInfo addInfo = info
139: .createNonHtmlInfo();
140: addInfo.setNonHtmlContent("Compare String (");
141: WebPageTagInstanceViewContext.displayView(this .valueCtchar,
142: addInfo, wptivc, "???");
143: //
144: //
145: WebPageTagInstanceViewContextInfo indexInfo = info
146: .createNonHtmlInfo();
147: //if (this.indexCtchar.getValueLength() > 0) {
148: indexInfo.setNonHtmlContent(") To Expression (", ")");
149: WebPageTagInstanceViewContext.displayView(
150: this .patternCtchar, indexInfo, wptivc, "???");
151: //indexInfo.setEndContent(")");
152: //}
153: //else {
154: // indexInfo.setStartContent(") To The End Of (");
155: //}
156: //
157: //
158: //
159: //WebPageTagInstanceViewContextInfo listInfo =
160: // info.createNonHtmlInfo();
161: //WebPageTagInstanceViewContext.displayView(
162: // this.listCtchar, listInfo, wptivc);
163: } else if (inActc instanceof SelectionCriteriaForReturnableConceptTag) {
164:
165: SelectionCriteriaForReturnableConceptTag scfrct = (SelectionCriteriaForReturnableConceptTag) inActc;
166:
167: scfrct.canReturnBoolean();
168: scfrct.declareFormatAsPlain();
169: } else if (inActc instanceof StudioConceptTagCreParInfoContext) {
170:
171: StudioConceptTagCreParInfoContext scpc = (StudioConceptTagCreParInfoContext) inActc;
172: }
173: }
174:
175: public void determineValueAndClass(
176: DetermineValueAndClassConceptTagContext inDvacctc) {
177:
178: try {
179: ValueAndClassForConceptTag vacfct = null;
180:
181: String pattern = this .patternCtchar.getValueAsString(0,
182: inDvacctc);
183: ValueAndClassForConceptTag valueVac = this .valueCtchar
184: .getDetermineValueAndClass(0, inDvacctc);
185: boolean result = MiscHelper.isRegularExpressionMatch(
186: valueVac.getValue().toString(), pattern, false);
187:
188: vacfct = ValueAndClassForConceptTag.newBoolean(new Boolean(
189: result));
190:
191: inDvacctc.setDetermineValueAndClass(vacfct);
192: } catch (DetermineValueAndClassConceptTagException dvaccte) {
193: inDvacctc.setDetermineException(dvaccte);
194: }
195: }
196:
197: public void determineClass(DetermineClassConceptTagContext inDcctc) {
198:
199: inDcctc.setDetermineClass(StandardDataTypes.getBooleanClass());
200: }
201:
202: public Object createUninitializedSelf() {
203: return new CommonFunctionStrIsRegExprMatchTag();
204: }
205:
206: }
|