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.workflow.model.template.v1;
009:
010: //base classes
011: import java.io.IOException;
012: import javax.xml.parsers.ParserConfigurationException;
013: import org.w3c.dom.Document;
014: import org.xml.sax.SAXException;
015:
016: //project specific classes
017: import org.jfolder.common.tagging.AppraiseConceptTagContext;
018: import org.jfolder.common.tagging.ConceptTagCharacteristic;
019: import org.jfolder.common.tagging.ConceptTagConstraint;
020: import org.jfolder.common.tagging.ConceptTagConstraintHolder;
021: import org.jfolder.common.tagging.ConceptTagHelper;
022: import org.jfolder.common.tagging.DetermineClassConceptTagContext;
023: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagContext;
024: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagException;
025: import org.jfolder.common.tagging.InitializeConceptTagContext;
026: import org.jfolder.common.tagging.ReturnableConceptTag;
027: import org.jfolder.common.tagging.StaticConceptTagConstraintContext;
028: import org.jfolder.common.tagging.StudioConceptTagInstanceInfoContext;
029: import org.jfolder.common.tagging.StudioConceptTagTypeInfoContext;
030: import org.jfolder.common.tagging.ValueAndClassForConceptTag;
031: import org.jfolder.common.utils.misc.CommonExpressions;
032: import org.jfolder.common.utils.misc.MiscHelper;
033: import org.jfolder.common.utils.xml.XMLHelper;
034: import org.jfolder.workflow.model.template.*;
035: import org.jfolder.workflow.model.trigger.WorkflowTrigger;
036:
037: //other classes
038:
039: public class IsTriggerTextPresentWorkflowTemplateTag implements
040: ReturnableConceptTag {
041:
042: //ConceptTag characteristic
043: private ConceptTagCharacteristic pathCtchar = null;
044:
045: //path details
046: private final static String PATH_CTCON = "path";
047: private final static String PATH_TITLE = "Path";
048: private final static String PATH_SHORT_DESCRIPTION = "Path to the element in the trigger containing the text";
049:
050: //TO DO: elaborate above
051:
052: public void initialize(InitializeConceptTagContext inIctc) {
053:
054: //
055: ConceptTagConstraintHolder rootCtconh = ConceptTagConstraintHolder
056: .newInstance(inIctc);
057:
058: //constrain "path"
059: ConceptTagConstraint pathCtcon = ConceptTagConstraint
060: .newInstance(PATH_CTCON, rootCtconh);
061: pathCtcon.setTitle(PATH_TITLE);
062: pathCtcon.setShortDescription(PATH_SHORT_DESCRIPTION);
063: //
064: StaticConceptTagConstraintContext pathSctcc = StaticConceptTagConstraintContext
065: .newInstance(pathCtcon);
066: pathSctcc.setRegularExpression(CommonExpressions.ANY_STRING);
067: //
068: pathSctcc.addDefaultValue("XMLPATH");
069: //TO DO: provide better default
070: //TO DO: define regular expression
071:
072: inIctc.initialize();
073:
074: //initialize characteristics
075: this .pathCtchar = pathCtcon.getCharacteristic();
076:
077: }
078:
079: public void appraise(AppraiseConceptTagContext inCtic) {
080: if (inCtic instanceof StudioConceptTagInstanceInfoContext) {
081: StudioConceptTagInstanceInfoContext sctiic = (StudioConceptTagInstanceInfoContext) inCtic;
082: sctiic.setInstanceTitle("Is Trigger Text Present");
083: sctiic
084: .setInstanceDescription("Determines if text is present within a trigger element");
085: } else if (inCtic instanceof StudioConceptTagTypeInfoContext) {
086: StudioConceptTagTypeInfoContext scttic = (StudioConceptTagTypeInfoContext) inCtic;
087: scttic.setTypeTitle("Is Trigger Text Present");
088: scttic
089: .setTypeDescription("Determines if text is present within a trigger element");
090: }
091: }
092:
093: public void determineValueAndClass(
094: DetermineValueAndClassConceptTagContext inRvacc) {
095:
096: inRvacc
097: .setDetermineException(new DetermineValueAndClassConceptTagException(
098: "Not Implemented"));
099:
100: //ValueAndClassForConceptTag outValue = null;
101:
102: /*
103: ComponentsForReturnableScriptTag wcfrt =
104: ScriptTagHelper.getComponentsForReturnableScriptTag(inRvacc);
105:
106: TriggerData t = wcfrt.getTriggerData();
107:
108: //X-Path creation and validation
109: String xpathData = null;
110:
111: if (this.pathTc.isStatic()) {
112: xpathData = this.pathTc.getValueAsString();
113: }
114: else if (this.pathTc.isDynamic()) {
115:
116: ValueAndClass outValue =
117: this.pathTc.getDetermineValueAndClass(inRvacc);
118:
119: if (vac.getValue() == null) {
120: throw new DetermineValueAndClassConceptTagException(
121: "Path value cannot be null");
122: }
123: else if (vac.getValue() instanceof String) {
124: xpathData = (String)vac.getValue();
125: }
126: else {
127: throw new DetermineValueAndClassConceptTagException(
128: "Path value is not of type String");
129: }
130: }
131: else {
132: throw new DetermineValueAndClassConceptTagException(
133: "Compound value is not allowed here");
134: }
135:
136: String xpathErrors = XMLHelper.isXPathValid(xpathData);
137:
138: if (xpathErrors != null) {
139: throw new DetermineValueAndClassConceptTagException("X-Path '"
140: + xpathData
141: + "' is invalid for the following reasons - " + xpathErrors);
142: }
143:
144: //trigger document creation and validation
145: Document doc = null;
146: try {
147: doc = XMLHelper.loadDocument(t.getDataAsString());
148: }
149: catch (ParserConfigurationException pce) {
150: throw new DetermineValueAndClassConceptTagException(pce);
151: }
152: catch (SAXException saxe) {
153: throw new DetermineValueAndClassConceptTagException(saxe);
154: }
155: catch (IOException ioe) {
156: throw new DetermineValueAndClassConceptTagException(ioe);
157: }
158:
159: return ValueAndClassFactory.newValueAndClass(
160: new Boolean(XMLHelper.getXPathElement(doc, xpathData) != null),
161: Boolean.TYPE);
162: */
163:
164: //return outValue;
165: }
166:
167: public void determineClass(DetermineClassConceptTagContext inRcc) {
168: inRcc.setDetermineClass(Boolean.TYPE);
169: }
170: }
|