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.w3c.dom.Element;
015: import org.xml.sax.SAXException;
016:
017: //project specific classes
018: import org.jfolder.common.tagging.AppraiseConceptTagContext;
019: import org.jfolder.common.tagging.CompoundConceptTagConstraintContext;
020: import org.jfolder.common.tagging.ConceptTagCharacteristic;
021: import org.jfolder.common.tagging.ConceptTagCharacteristicHolder;
022: import org.jfolder.common.tagging.ConceptTagConstraint;
023: import org.jfolder.common.tagging.ConceptTagConstraintHolder;
024: import org.jfolder.common.tagging.ConceptTagConstraintTemplate;
025: import org.jfolder.common.tagging.DetermineClassConceptTagContext;
026: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagContext;
027: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagException;
028: import org.jfolder.common.tagging.InitializeConceptTagContext;
029: import org.jfolder.common.tagging.ReturnableConceptTag;
030: import org.jfolder.common.tagging.StaticConceptTagConstraintContext;
031: import org.jfolder.common.tagging.StudioConceptTagInstanceInfoContext;
032: import org.jfolder.common.tagging.StudioConceptTagTypeInfoContext;
033: import org.jfolder.common.tagging.ValueAndClassForConceptTag;
034: import org.jfolder.common.utils.xml.LinearXPath;
035: import org.jfolder.common.utils.xml.LinearXPathHelper;
036: import org.jfolder.common.utils.xml.XMLHelper;
037: import org.jfolder.workflow.model.template.*;
038: import org.jfolder.workflow.model.trigger.WorkflowTrigger;
039:
040: //other classes
041:
042: public class GetTriggerTextWorkflowTemplateTag implements
043: ReturnableConceptTag {
044:
045: //ConceptTag characteristic
046: private ConceptTagCharacteristic pathCtchar = null;
047:
048: //path details
049: private final static String PATH_CTCON = "path";
050: private final static String PATH_TITLE = "Path";
051: private final static String PATH_SHORT_DESCRIPTION = "Path to the element in the trigger containing the text";
052: //TO DO: elaborate above
053:
054: //segment details
055: private final static String PATH_CTCON_SEGMENT_CTCTEMP = "segment";
056: private final static String PATH_CTCON_SEGMENT_TITLE = "Segment";
057: private final static String PATH_CTCON_SEGMENT_SHORT_DESCRIPTION = "Name of XPath segment";
058:
059: //index details
060: private final static String PATH_CTCON_INDEX_CTCTEMP = "index";
061: private final static String PATH_CTCON_INDEX_TITLE = "Index";
062: private final static String PATH_CTCON_INDEX_SHORT_DESCRIPTION = "Index of XPath segment";
063:
064: public void initialize(InitializeConceptTagContext inIctc) {
065:
066: //
067: ConceptTagConstraintHolder rootCtconh = ConceptTagConstraintHolder
068: .newInstance(inIctc);
069:
070: //constrain "path"
071: ConceptTagConstraint pathCtcon = ConceptTagConstraint
072: .newInstance(PATH_CTCON, rootCtconh);
073: pathCtcon.setTitle(PATH_TITLE);
074: pathCtcon.setShortDescription(PATH_SHORT_DESCRIPTION);
075: pathCtcon.setMinimumLength(1);
076: pathCtcon.setLengthUnbounded(true);
077: //
078: CompoundConceptTagConstraintContext pathCctcc = CompoundConceptTagConstraintContext
079: .newInstance(pathCtcon);
080: //
081: pathCctcc.addDefaultValue();
082:
083: //constrain "segment" of "path"
084: ConceptTagConstraintTemplate pathCtconSegmentCtctemp = ConceptTagConstraintTemplate
085: .newInstance(PATH_CTCON_SEGMENT_CTCTEMP, pathCctcc);
086: pathCtconSegmentCtctemp.setTitle(PATH_CTCON_SEGMENT_TITLE);
087: pathCtconSegmentCtctemp
088: .setShortDescription(PATH_CTCON_SEGMENT_SHORT_DESCRIPTION);
089: //
090: StaticConceptTagConstraintContext pathCtconSegmentSctcc = StaticConceptTagConstraintContext
091: .newInstance(pathCtconSegmentCtctemp);
092: //
093: pathCtconSegmentSctcc.addDefaultValue("SegmentName");
094:
095: //constrain "index" of "path"
096: ConceptTagConstraintTemplate pathCtconIndexCtcont = ConceptTagConstraintTemplate
097: .newInstance(PATH_CTCON_INDEX_CTCTEMP, pathCctcc);
098: pathCtconIndexCtcont.setTitle(PATH_CTCON_INDEX_TITLE);
099: pathCtconIndexCtcont
100: .setShortDescription(PATH_CTCON_INDEX_SHORT_DESCRIPTION);
101: //
102: StaticConceptTagConstraintContext pathCtconIndexSctcc = StaticConceptTagConstraintContext
103: .newInstance(pathCtconIndexCtcont);
104: //
105: pathCtconIndexSctcc.addDefaultValue("1");
106:
107: inIctc.initialize();
108:
109: //initialize ConceptTag characteristics
110: this .pathCtchar = pathCtcon.getCharacteristic();
111:
112: }
113:
114: public void appraise(AppraiseConceptTagContext inCtic) {
115: if (inCtic instanceof StudioConceptTagInstanceInfoContext) {
116: StudioConceptTagInstanceInfoContext stiic = (StudioConceptTagInstanceInfoContext) inCtic;
117:
118: stiic.setInstanceTitle("Get Trigger Text");
119: stiic
120: .setInstanceDescription("Get the text within the element of a trigger");
121: /*
122: if (this.pathTc.getValueLength() == 1) {
123: //initialize first operand
124: String operandTitle1 = "";
125: String operandDesc1 = "";
126: if (this.pathTc.isStatic(0)) {
127: operandTitle1 = this.pathTc.getValueAsString(0);
128: operandDesc1 = this.pathTc.getValueAsString(0);
129: }
130: else if (this.pathTc.isDynamic(0)) {
131: StudioConceptTagInstanceInfoContext nextStiic =
132: this.pathTc.getConceptTagInstanceInformation(0);
133:
134: operandTitle1 = nextStiic.getConceptTagInstanceTitle();
135: operandDesc1 = nextStiic.getConceptTagInstanceDescription();
136: }
137: //set title and description
138: stiic.setConceptTagInstanceTitle(
139: "Trigger(" + operandTitle1 + "/(#text))");
140: stiic.setConceptTagInstanceDescription(
141: "Trigger(" + operandDesc1 + "/(#text))");
142: }
143: else {
144: stiic.setConceptTagInstanceTitle("(Error)");
145: stiic.setConceptTagInstanceDescription("(Error)");
146: }
147: */
148: } else if (inCtic instanceof StudioConceptTagTypeInfoContext) {
149: StudioConceptTagTypeInfoContext scttic = (StudioConceptTagTypeInfoContext) inCtic;
150: scttic.setTypeTitle("Get Trigger Text");
151: scttic
152: .setTypeDescription("Get the text within the element of a trigger");
153: }
154: }
155:
156: public void determineValueAndClass(
157: DetermineValueAndClassConceptTagContext inRvacc) {
158:
159: try {
160: ValueAndClassForConceptTag outValue = null;
161:
162: ComponentsForReturnableWorkflowTemplateTag wcfrt = WorkflowTemplateTagHelper
163: .getComponentsForReturnableWorkflowTemplateTag(inRvacc);
164:
165: WorkflowTrigger t = wcfrt.getWorkflowTrigger();
166:
167: ConceptTagCharacteristicHolder pathCtconh = this .pathCtchar
168: .getValueAsHolder(0, inRvacc);
169:
170: //ConceptTagConstraint segmentCtcon =
171: // pathCtconh.getConceptTagConstraint(
172: // PATH_CTCON_SEGMENT_CTCTEMP);
173: ConceptTagCharacteristic segmentCtchar = pathCtconh
174: .getCharacteristic(PATH_CTCON_SEGMENT_CTCTEMP);
175: String segment = segmentCtchar.getValueAsString(0, inRvacc);
176: //
177: //ConceptTagConstraint indexCtcon =
178: // pathCtconh.getConceptTagConstraint(PATH_CTCON_INDEX_CTCTEMP);
179: ConceptTagCharacteristic indexCtchar = pathCtconh
180: .getCharacteristic(PATH_CTCON_INDEX_CTCTEMP);
181: int index = Integer.parseInt(indexCtchar.getValueAsString(
182: 0, inRvacc));
183:
184: LinearXPath xpath = LinearXPath.r(segment);
185:
186: //note that this starts with 1, not 0
187: for (int i = 1; i < this .pathCtchar.getValueLength(); i++) {
188: //
189: pathCtconh = this .pathCtchar.getValueAsHolder(i,
190: inRvacc);
191: //
192: //segmentCtcon =
193: // pathCtconh.getConceptTagConstraint(
194: // PATH_CTCON_SEGMENT_CTCTEMP);
195: segmentCtchar = pathCtconh
196: .getCharacteristic(PATH_CTCON_SEGMENT_CTCTEMP);
197: segment = segmentCtchar.getValueAsString(0, inRvacc);
198: //
199: //indexCtcon = pathCtconh.getConceptTagConstraint(
200: // PATH_CTCON_INDEX_CTCTEMP);
201: indexCtchar = pathCtconh
202: .getCharacteristic(PATH_CTCON_INDEX_CTCTEMP);
203: index = Integer.parseInt(indexCtchar.getValueAsString(
204: 0, inRvacc));
205: //
206: xpath = xpath.b(segment, index);
207: }
208:
209: Document doc = XMLHelper.loadDocument(t.getDataAsString());
210: Element elementXpath = LinearXPathHelper.getXPathElement(
211: doc, xpath);
212: String xpathData = XMLHelper.getText(elementXpath);
213:
214: outValue = ValueAndClassForConceptTag.newInstance(
215: xpathData, String.class);
216:
217: inRvacc.setDetermineValueAndClass(outValue);
218: } catch (ParserConfigurationException pce) {
219: inRvacc.setDetermineException(pce);
220: } catch (SAXException saxe) {
221: inRvacc.setDetermineException(saxe);
222: } catch (IOException ioe) {
223: inRvacc.setDetermineException(ioe);
224: }
225: }
226:
227: public void determineClass(DetermineClassConceptTagContext inRcc) {
228: inRcc.setDetermineClass(String.class);
229: }
230:
231: /*
232: public void getConceptTagSummary(ConceptTagSummaryDescriptor tsd) {
233: //TO DO: placeholder, put meaningful description
234: if (tsd.getMimeType().equals(ConceptTagSummaryMimeType.TEXT_HTML)) {
235: tsd.appendData("Get text from trigger element <i>"
236: + this.pathAttr[0] + "</i>");
237: }
238: }
239: */
240: }
|