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: import java.io.IOException;
012:
013: //project specific classes
014: import org.jfolder.common.SelfArgumentlessConstructor;
015: import org.jfolder.common.StandardDataTypes;
016: import org.jfolder.common.UnexpectedSystemException;
017: import org.jfolder.common.function.BaseCommonFunctionCompatibilityTag;
018: import org.jfolder.common.function.ComponentsForReturnableWebPageTag;
019: import org.jfolder.common.function.WebPageTagHelper;
020: import org.jfolder.common.function.WebPageTagInstanceViewContext;
021: import org.jfolder.common.function.WebPageTagInstanceViewContextInfo;
022: import org.jfolder.common.tagging.AppraiseConceptTagContext;
023: import org.jfolder.common.tagging.ConceptTagCharacteristic;
024: import org.jfolder.common.tagging.ConceptTagConstraint;
025: import org.jfolder.common.tagging.ConceptTagConstraintHolder;
026: import org.jfolder.common.tagging.ConceptTagFlagsHelper;
027: import org.jfolder.common.tagging.DetermineClassConceptTagContext;
028: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagContext;
029: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagException;
030: import org.jfolder.common.tagging.DynamicConceptTagConstraintContext;
031: import org.jfolder.common.tagging.InitializeConceptTagContext;
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: import org.jfolder.common.utils.xml.XMLHelper;
041: import org.jfolder.security.audit.SecurityAudit;
042: import org.jfolder.security.audit.SimpleSecurityAudit;
043: import org.jfolder.security.model.UserHolder;
044:
045: //import org.jfolder.services.workflow.WorkflowServiceCaller;
046: //import org.jfolder.services.workflow.WorkflowServiceCallerFactory;
047: //import org.jfolder.workflow.model.WorkflowComponentIdentifyUpdatesContext;
048: //import org.jfolder.workflow.model.instance.WorkflowInstance;
049: //import org.jfolder.workflow.model.instance.WorkflowInstanceUpdates;
050: //import org.jfolder.workflow.model.trigger.WorkflowTrigger;
051:
052: //other classes
053:
054: public class CommonFunctionActionFireTrigDataTag extends
055: BaseCommonFunctionCompatibilityTag implements
056: SelfArgumentlessConstructor {
057:
058: //characteristics
059: private ConceptTagCharacteristic messageCtchar = null;
060:
061: //message details
062: private final static String MESSAGE_CTCON = "message";
063: private final static String MESSAGE_TITLE = "Message";
064: private final static String MESSAGE_SHORT_DESCRIPTION = "Message used to create workflow-instance";
065:
066: public void initialize(InitializeConceptTagContext inIctc) {
067:
068: //
069: ConceptTagConstraintHolder rootCtconh = ConceptTagConstraintHolder
070: .newInstance(inIctc);
071: //
072: //rootCtconh.getAttributes().setStudioVisibleOnlyOnError(true);
073: //rootCtconh.getStyles().setStudioVisibleOnlyOnError(true);
074:
075: //constrain "message"
076: ConceptTagConstraint messageCtcon = ConceptTagConstraint
077: .newInstance(MESSAGE_CTCON, rootCtconh);
078: messageCtcon.setMinimumLength(1);
079: messageCtcon.setLengthUnbounded(true);
080: messageCtcon.setTitle(MESSAGE_TITLE);
081: messageCtcon.setShortDescription(MESSAGE_SHORT_DESCRIPTION);
082: //
083: StaticConceptTagConstraintContext messageSctcc = StaticConceptTagConstraintContext
084: .newInstance(messageCtcon);
085: messageSctcc.setRegularExpression(CommonExpressions.ANY_STRING);
086: messageSctcc.setMultiLine(true);
087: //
088: DynamicConceptTagConstraintContext messageDctcc = DynamicConceptTagConstraintContext
089: .newInstance(messageCtcon);
090: messageDctcc.getValidator().allowReturnOfOnlyString();
091: messageDctcc.getValidator().filterDirectChildOfRootAndHtml();
092: //
093: messageSctcc.addDefaultValue("<blank-trigger/>");
094:
095: //constrain unconstrained
096: ConceptTagConstraint unconstrainedCtcon = rootCtconh
097: .getUndefinedConstraint();
098: //unconstrainedCtcon.setStudioVisibleOnlyOnError(true);
099:
100: //
101: ConceptTagFlagsHelper
102: .pushNonIterativeCommonFunctionDepth(inIctc);
103: inIctc.initialize();
104: ConceptTagFlagsHelper
105: .popNonIterativeCommonFunctionDepth(inIctc);
106:
107: //initialize characteristics
108: this .messageCtchar = messageCtcon.getCharacteristic();
109:
110: }
111:
112: public void appraise(AppraiseConceptTagContext inActc) {
113:
114: if (inActc instanceof StudioConceptTagInstanceInfoContext) {
115:
116: StudioConceptTagInstanceInfoContext sctiic = (StudioConceptTagInstanceInfoContext) inActc;
117:
118: StringBuffer titleSb = new StringBuffer("FireTriggerData(");
119: StringBuffer descSb = new StringBuffer("FireTriggerData(");
120: for (int i = 0; i < this .messageCtchar.getValueLength(); i++) {
121: if (this .messageCtchar
122: .isHolderWithConceptTag(i, inActc)) {
123: StudioConceptTagInstanceInfoContext nextSctiic = this .messageCtchar
124: .getInstanceInformation(i);
125:
126: titleSb.append(nextSctiic.getInstanceTitle());
127: descSb.append(nextSctiic.getInstanceDescription());
128: } else if (this .messageCtchar.isStatic(i, inActc)) {
129: titleSb.append(this .messageCtchar.getValueAsString(
130: i, inActc));
131: descSb.append(this .messageCtchar.getValueAsString(
132: i, inActc));
133: }
134: }
135: titleSb.append(")");
136: descSb.append(")");
137: sctiic.setInstanceTitle(titleSb.toString());
138: sctiic.setInstanceDescription(descSb.toString());
139: } else if (inActc instanceof StudioConceptTagTypeInfoContext) {
140:
141: StudioConceptTagTypeInfoContext scttic = (StudioConceptTagTypeInfoContext) inActc;
142:
143: scttic.setTypeTitle("Fire trigger data");
144: scttic.setTypeDescription("Fire trigger data");
145: } else if (inActc instanceof WebPageTagInstanceViewContext) {
146:
147: WebPageTagInstanceViewContext wptivc = (WebPageTagInstanceViewContext) inActc;
148:
149: WebPageTagInstanceViewContextInfo info = wptivc
150: .getInfoAsNonHtml();
151: info.setNonHtmlContent("FireTrigData - Not Impl");
152: //wptivc.getInfo().setStartContent("");
153: //wptivc.getInfo().setMiddleContent("");
154: //wptivc.getInfo().setEndContent("");
155: } else if (inActc instanceof SelectionCriteriaForReturnableConceptTag) {
156:
157: SelectionCriteriaForReturnableConceptTag scfrct = (SelectionCriteriaForReturnableConceptTag) inActc;
158:
159: scfrct.canReturnNothing();
160: scfrct.declareFormatAsPlain();
161: } else if (inActc instanceof StudioConceptTagCreParInfoContext) {
162:
163: StudioConceptTagCreParInfoContext scpc = (StudioConceptTagCreParInfoContext) inActc;
164: }
165: }
166:
167: public void determineValueAndClass(
168: DetermineValueAndClassConceptTagContext inDvacctc) {
169:
170: try {
171: ValueAndClassForConceptTag vacfct = null;
172:
173: //ComponentsForReturnableWebPageTag cfrwt =
174: // WebPageTagHelper.getComponentsForReturnableWebPageTag(
175: // inDvacctc);
176:
177: if (true) {
178: throw UnexpectedSystemException.notImplemented();
179: }
180:
181: String fullMessage = "";
182: //MiscHelper.println("this.messageTc.getValueLength() = "
183: // + this.messageTc.getValueLength());
184: for (int i = 0; i < this .messageCtchar.getValueLength(); i++) {
185: //MiscHelper.println("this.messageTc.getValueAsString(i) = "
186: // + this.messageTc.getValueAsString(i));
187: if (this .messageCtchar.isStatic(i, inDvacctc)) {
188: fullMessage = fullMessage
189: + this .messageCtchar.getValueAsString(i,
190: inDvacctc);
191: } else {
192: ValueAndClassForConceptTag messageVac = this .messageCtchar
193: .getDetermineValueAndClass(i, inDvacctc);
194: fullMessage = fullMessage + messageVac.getValue();
195: }
196: }
197:
198: //MiscHelper.println(
199: // "TagFireTrig::rvac fullMes = '" + fullMessage + "'");
200:
201: fullMessage = null;//appendApplication(
202: // cfrwt.getApplicationName(), fullMessage);
203:
204: UserHolder uh = null;//cfrwt.getCurrentUser();
205: if (true) {
206: throw UnexpectedSystemException.notImplemented();
207: }
208:
209: //SecurityAudit wa =
210: // //SecurityAudit.newInstance(
211: // //uh, SecurityAudit.INITIAL_ID, "Web Page Submission",
212: // //WorkflowTrigger.SUBMITTED, MiscHelper.currentGMT());
213: // SimpleSecurityAudit.newInstance(uh.getUserIdentity(),
214: // SecurityAudit.INITIAL_ID, "Web Page Submission",
215: // WorkflowTrigger.SUBMITTED, MiscHelper.currentUTC(),
216: // null, null, false);
217: //
218: //WorkflowTrigger td = WorkflowTrigger.newInstance();
219: //td.setDataAsString(fullMessage);
220: //
221: //WorkflowInstance wi = WorkflowInstance.newInstance();
222: //wi.setWorkflowTrigger(td);
223: //
224: //WorkflowComponentIdentifyUpdatesContext wciuc =
225: // WorkflowComponentIdentifyUpdatesContext.newInstance(wa);
226: //
227: if (true) {
228: throw UnexpectedSystemException.notImplemented();
229: }
230: //WorkflowServiceCaller wsc =
231: // WorkflowServiceCallerFactory.getWorkflowServiceCaller(null);
232: //WorkflowLifecycle wl =
233: // WorkflowLifecycleFactory.getWorkflowLifecycle();
234:
235: //wl.submitTriggerData(null, td);
236: //wsc.updateWorkflowInstance(
237: // (WorkflowInstanceUpdates)wi.identifyUpdates(wciuc));
238:
239: //wl.close();
240:
241: vacfct = ValueAndClassForConceptTag.newNothing();
242:
243: inDvacctc.setDetermineValueAndClass(vacfct);
244: } catch (DetermineValueAndClassConceptTagException dvaccte) {
245: inDvacctc.setDetermineException(dvaccte);
246: }
247: }
248:
249: public void determineClass(DetermineClassConceptTagContext inDcctc) {
250: inDcctc.setDetermineClass(StandardDataTypes.getNothingClass());
251: }
252:
253: private final static String appendApplication(String inApplication,
254: String inContent) {
255:
256: //try {
257: String outValue = null;
258:
259: final String APPLICATION_ATTRIBUTE = "application";
260:
261: int splitIndex = 0;
262: //MiscHelper.println(
263: //"TagFireTrigDataWebTag inApp= " + inApplication);
264: //MiscHelper.println("TagFireTrigDataWebTag inCon= " + inContent);
265: //MiscHelper.println("TagFireTrigDataWebTag split= " + splitIndex);
266: while (inContent.charAt(splitIndex) != '>'
267: || getDoubleQuoteCount(inContent.substring(0,
268: splitIndex)) % 2 != 0) {
269:
270: splitIndex++;
271: //MiscHelper.println("TagFireTrigDataWebTag split="
272: //+ splitIndex);
273: }
274:
275: if (inContent.charAt(splitIndex - 1) == '/') {
276: splitIndex--;
277: }
278:
279: String applicationAttribute = (" " + APPLICATION_ATTRIBUTE
280: + "=\"" + XMLHelper.fromStringToCData(inApplication) + "\"");
281:
282: outValue = inContent.substring(0, splitIndex)
283: + applicationAttribute
284: + inContent.substring(splitIndex);
285:
286: return outValue;
287: //}
288: //catch (IOException ioe) {
289: // throw new UnexpectedSystemException(ioe);
290: //}
291: }
292:
293: private final static int getDoubleQuoteCount(String inValue) {
294:
295: int outValue = 0;
296:
297: int currentStartIndex = -1;
298:
299: while (inValue.indexOf('"', currentStartIndex + 1) != -1) {
300: currentStartIndex = inValue.indexOf('"',
301: currentStartIndex + 1);
302: outValue++;
303: }
304:
305: return outValue;
306: }
307:
308: public Object createUninitializedSelf() {
309: return new CommonFunctionActionFireTrigDataTag();
310: }
311: }
|