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.console.web.develop.workflow.template;
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.UnexpectedSystemException;
018: import org.jfolder.common.tagging.ConceptTag;
019: import org.jfolder.common.tagging.ConceptTagCharacteristicHolder;
020: import org.jfolder.common.tagging.ConceptTagConstraintHolder;
021: import org.jfolder.common.tagging.RootConceptTagHolder;
022: import org.jfolder.common.utils.web.ParameterSet;
023: import org.jfolder.common.utils.xml.XMLHelper;
024: import org.jfolder.common.web.template.SubmitActionContext;
025: import org.jfolder.common.web.template.SubmitActionParameters;
026: import org.jfolder.console.base.BaseStudioFrameServlet;
027: import org.jfolder.console.base.ConsolePageContext;
028: import org.jfolder.console.base.ConsoleSession;
029: import org.jfolder.project.model.ProjectSystem;
030: import org.jfolder.security.model.UserHolder;
031: import org.jfolder.workflow.model.template.WorkflowTemplateTagHelper;
032: import org.jfolder.workflow.model.template.v1.core.StartWorkflowTemplateTag;
033: import org.jfolder.workflow.model.template.v1.core.StateWorkflowTemplateTag;
034: import org.jfolder.workflow.model.template.v1.core.StopWorkflowTemplateTag;
035:
036: //other classes
037:
038: public class DevelopWorkflowTemplateServlet extends
039: BaseStudioFrameServlet {
040:
041: public DevelopWorkflowTemplateServlet() {
042: }
043:
044: //protected boolean checkAccess(UserHolder inUser) {
045: //
046: // boolean outValue = false;
047: //
048: // UserAuthorizationAndAccessControl uaaac =
049: // UserHelper.getUserAuthorizationAndAccessControl();
050: //
051: // outValue = isDeveloper(uaaac, inUser);
052: //
053: // return outValue;
054: //}
055:
056: public ConsolePageContext process(ConsoleSession inCs,
057: UserHolder inUser, ParameterSet inPs,
058: SubmitActionContext inSac) throws IOException {
059:
060: //try {
061: ConsolePageContext outValue = null;
062:
063: //MiscHelper.println(
064: // "ScriptStudioFrameServlet-Action = " + inSac.getAction());
065: //MiscHelper.println(
066: // "ScriptStudioFrameServlet-2Action = " + inSac.getSubAction());
067:
068: if (commonActions(inCs, inUser, inPs, inSac)) {
069: //MiscHelper.println("common actions executed");
070: } else if (inSac.isAction(SubmitActionParameters.DO_NOTHING)) {
071: } else if (inSac.isAction(SubmitActionParameters.OPEN)) {
072:
073: inCs
074: .setStudioFrameState(BaseStudioFrameServlet.HIGH_LEVEL_MODE);
075:
076: String appName = inSac.getFirstParameter();
077: inCs.setOpenApplication(appName);
078:
079: //ProjectApplicationSet was = inCs.getProjectApplicationSet();
080: ProjectSystem wa = inCs.getUserProjectSystem(appName);
081: //ProjectScript ws = wa.getScript();
082: ////MiscHelper.println();
083: //String content = ws.getContent();
084: ////MiscHelper.println("CONTENT = " + content);
085: //Document doc = XMLHelper.loadDocument(content);
086: //RootConceptTagHolder rsth =
087: // WorkflowTemplateTagHelper.getRootConceptTagHolder(
088: // doc, null, null, ws.getName());
089: //
090: ////MiscHelper.println("ValueLength = "
091: //// + rsth.getConceptTagCharacteristic().getValueLength());
092: ////MiscHelper.println("Frame,rsth = " + rsth);
093: //inCs.setRootHolder(rsth);
094:
095: //MiscHelper.println("WebStudioFrame Remove following statement"
096: // + (new java.util.Date()));
097: //for (int i = 0; i < 100; i++) {
098: // rsth.revalidate();
099: //}
100: //MiscHelper.println("WebStudioFrame Remove previous statement"
101: // + (new java.util.Date()));
102: } else if (inSac.isAction(SubmitActionParameters.UPDATE,
103: SubmitActionParameters.COORDINATES)) {
104:
105: //MiscHelper.println("PARAMETER1 = "
106: // + inSac.getFirstParameter());
107: //MiscHelper.println("PARAMETER2 = "
108: // + inSac.getSecondParameter());
109: //MiscHelper.println("PARAMETER3 = "
110: //+ inSac.getThirdParameter());
111:
112: processDeltaCoorAction(inCs.getRootHolder(), inSac
113: .getFirstParameter(), Integer.parseInt(inSac
114: .getSecondParameter()), Integer.parseInt(inSac
115: .getThirdParameter()));
116: } else {
117: inSac.unknownAction();
118: }
119:
120: outValue = DevelopWorkflowTemplateContext.newInstance(inCs);
121:
122: return outValue;
123: //}
124: //catch (ParserConfigurationException pce) {
125: // throw new UnexpectedSystemException(pce);
126: //}
127: //catch (SAXException saxe) {
128: // throw new UnexpectedSystemException(saxe);
129: //}
130: //catch (IOException ioe) {
131: // throw new UnexpectedSystemException(ioe);
132: //}
133: }
134:
135: private final static void processDeltaCoorAction(
136: RootConceptTagHolder inRsth, String inCode, int inDeltaX,
137: int inDeltaY) {
138:
139: ConceptTagConstraintHolder ctconh = WorkflowTemplateTagHelper
140: .getNearestConceptTag(inRsth, inCode,
141: new StringBuffer());
142:
143: ConceptTag tag = ctconh.getCharacteristicHolder()
144: .getConceptTag();
145: if (tag instanceof StartWorkflowTemplateTag) {
146: StartWorkflowTemplateTag startTag = (StartWorkflowTemplateTag) tag;
147: startTag.setXCord((startTag.getXCord() + inDeltaX) + "");
148: startTag.setYCord((startTag.getYCord() + inDeltaY) + "");
149: } else if (tag instanceof StateWorkflowTemplateTag) {
150: StateWorkflowTemplateTag stateTag = (StateWorkflowTemplateTag) tag;
151: stateTag.setXCord((stateTag.getXCord() + inDeltaX) + "");
152: stateTag.setYCord((stateTag.getYCord() + inDeltaY) + "");
153: } else if (tag instanceof StopWorkflowTemplateTag) {
154: StopWorkflowTemplateTag stopTag = (StopWorkflowTemplateTag) tag;
155: stopTag.setXCord((stopTag.getXCord() + inDeltaX) + "");
156: stopTag.setYCord((stopTag.getYCord() + inDeltaY) + "");
157: }
158:
159: }
160:
161: protected void saveChanges(ConsoleSession inCs, UserHolder inUser,
162: ParameterSet inPs, SubmitActionContext inSac) {
163:
164: //
165: RootConceptTagHolder rcth = inCs.getRootHolder();
166: String saveText = rcth.getXMLRepresentation();
167: //
168: String appName = inCs.getOpenApplication();
169: //String webPage = inCs.getOpenWebPage();
170: //
171: //ProjectApplicationSet was = inCs.getProjectApplicationSet();
172: //ProjectApplication wa = was.getApplication(appName);
173: //ProjectScript ps = wa.getScript();
174: ////ProjectWebPage wwp = wa.getWebPage(webPage);
175: ////
176: //ps.setContent(saveText);
177: ////
178: //inCs.saveProjectApplicationSet();
179: throw UnexpectedSystemException.notImplemented();
180: }
181: }
|