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.admin.config.instance;
009:
010: //base classes
011: import java.io.ByteArrayInputStream;
012: import java.io.IOException;
013: import java.util.ArrayList;
014: import javax.servlet.ServletException;
015: import javax.xml.parsers.ParserConfigurationException;
016: import org.w3c.dom.Document;
017: import org.xml.sax.SAXException;
018:
019: //project specific classes
020: import org.jfolder.common.UnexpectedSystemException;
021: import org.jfolder.common.files.VirtualFileSystemFile;
022: import org.jfolder.common.files.VirtualFileSystemHolder;
023: import org.jfolder.common.tagging.ConceptRollupTag;
024: import org.jfolder.common.tagging.ConceptTag;
025: import org.jfolder.common.tagging.ConceptTagCharacteristic;
026: import org.jfolder.common.tagging.ConceptTagCharacteristicHolder;
027: import org.jfolder.common.tagging.ConceptTagConstraintHolder;
028: import org.jfolder.common.tagging.ConceptTagPreferences;
029: import org.jfolder.common.tagging.ConceptTagSetContext;
030: import org.jfolder.common.tagging.ConceptTagSetHolder;
031: import org.jfolder.common.tagging.RootConceptTagHolder;
032: import org.jfolder.common.utils.misc.MiscHelper;
033: import org.jfolder.common.utils.web.ParameterSet;
034: import org.jfolder.common.utils.xml.XMLHelper;
035: import org.jfolder.common.web.template.ConsoleParameterContext;
036: import org.jfolder.common.web.template.PageSetupContext;
037: import org.jfolder.common.web.template.SubmitActionContext;
038: import org.jfolder.common.web.template.SubmitActionParameters;
039: import org.jfolder.console.base.BaseRcthStudioServlet;
040: import org.jfolder.console.base.BaseRcthStudioSettings;
041: import org.jfolder.console.base.ConsolePageContext;
042: import org.jfolder.console.base.ConsolePageSession;
043: import org.jfolder.project.model.ProjectSystem;
044: import org.jfolder.security.model.UserHolder;
045: import org.jfolder.security.model.UserIdentity;
046: import org.jfolder.services.config.ConfigService;
047: import org.jfolder.services.config.ConfigServiceCallerFactory;
048:
049: //other classes
050:
051: public class ConfigInstanceServlet extends BaseRcthStudioServlet {
052:
053: public ConfigInstanceServlet() {
054: }
055:
056: protected boolean checkAccess(ConsolePageSession inCps)
057: throws IOException, ServletException {
058:
059: boolean outValue = false;
060:
061: outValue = (inCps.isAdministrator());
062:
063: return outValue;
064: }
065:
066: public ConsolePageContext subProcess(ConsolePageSession inCps,
067: UserHolder inUser, ParameterSet inPs,
068: SubmitActionContext inSac, BaseRcthStudioSettings inBrss)
069: throws IOException, ServletException {
070:
071: //
072:
073: ConfigInstanceContext outValue = null;
074:
075: String currentHighlightHandle = null;
076: //
077: Boolean currentTreeDeleteNotAdd = null;
078: String currentTreeHandle = null;
079: //
080: byte binaryContent[] = null;
081: String binaryContentName = null;
082: String binaryContentMimeType = null;
083:
084: if (inSac.isAction(SubmitActionParameters.OPEN)) {
085: //String appType = inSac.getFirstParameter();
086: //String appName = inSac.getSecondParameter();
087: //String fileType = inSac.getThirdParameter();
088: //String directory = inSac.getFourthParameter();
089: //String fileName = inSac.getFifthParameter();
090: //
091: inCps.getMessageHolder().setInformationHeader("Welcome");
092: //
093: //ProjectSystem projectSystem =
094: // inCs.getProjectSystem(appType, appName);
095: //
096: //VirtualFileSystemHolder pageVsh = projectSystem.getWebPages();
097: //
098: //VirtualFileSystemHolder localVsh =
099: // pageVsh.getOrCreateAbsoluteDirectory(directory);
100: //
101: //VirtualFileSystemFile localPage = localVsh.getFile(fileName);
102: //byte pageContent[] = localPage.getContent();
103: //
104: //RootConceptTagHolder localRcth =
105: // ConsoleMacroTagHelper.getEmptyMacro();
106: // ConceptRollupTag.getRootHolderFromList(pageContent);
107: //MiscHelper.println("ConMacServ localRcth.isErrorPresent() = "
108: // + localRcth.isErrorPresent());
109: //localRcth.validate();
110: //
111: ConfigService cs = ConfigServiceCallerFactory
112: .getConfigService();
113: inCps.setCurrentApplication(null, "ConfigInstance.zip",
114: null, null, null, cs
115: .getCopyOfCurrentConfigInstance(), null,
116: null);
117: //
118: } else if (inSac.isAction(SubmitActionParameters.DO_NOTHING)) {
119: }
120: //else if (inSac.isAction(SubmitActionParameters.IMPORT)) {
121: // //
122: // String fileSource = inSac.getFirstParameter();
123: // byte fileContent[] = inPs.getParameterAsUpload(fileSource);
124: // String fileName = inPs.getUploadParameterName(fileSource);
125: // //
126: // RootConceptTagHolder localRcth =
127: // ConceptRollupTag.getRootHolderFromList(fileContent);
128: // //
129: // inCs.setCurrentApplication(
130: // null, fileName, null, null, null, localRcth);
131: //}
132: else if (inSac.isAction(SubmitActionParameters.EXPORT)) {
133: binaryContent = ConceptRollupTag.getRollupFromList(inCps
134: .getCurrentApplicationRootHolder(), null);
135: binaryContentName = inCps.getCurrentApplicationName();
136: binaryContentMimeType = "application/download";
137: } else if (inSac.isAction(SubmitActionParameters.ADD,
138: SubmitActionParameters.CONCEPT_TAG)) {
139: //
140: //
141: accountForRcthTextChanges(inCps, inPs);
142: //
143: //
144: String parentCode = inSac
145: .getParameter(ConsoleParameterContext.FIRST_INPUT);
146: int addIndex = Integer
147: .parseInt(inSac
148: .getParameter(ConsoleParameterContext.SECOND_INPUT));
149: //
150: String ctNs = inSac
151: .getParameter(ConsoleParameterContext.THIRD_INPUT);
152: if (ctNs.length() == 0) {
153: ctNs = null;
154: }
155: String ctName = inSac
156: .getParameter(ConsoleParameterContext.FOURTH_INPUT);
157: //
158: RootConceptTagHolder localRcth = inCps
159: .getCurrentApplicationRootHolder();
160: ConceptTagCharacteristic localCtchar = localRcth
161: .getCharacteristic(parentCode);
162: //
163: ConceptTagPreferences localCtp = localRcth.getPreferences();
164: //
165: ConceptTagSetHolder ctsh = localCtp.getSetHolder();
166: Class ctClass = ctsh.getConceptTagClass(ctNs, ctName);
167: ConceptTag ct = (ConceptTag) MiscHelper
168: .newInstance(ctClass);
169: //
170: localCtchar.addValue(addIndex, ct, false);
171: //boolean localValidate = localCtp//
172: //localRcth
173: localRcth.validate();
174: //
175: //
176: //
177: currentTreeHandle = parentCode
178: + localCtp.getHandleConjunction() + addIndex;
179: currentTreeDeleteNotAdd = new Boolean(false);
180: //outValue.adjustNumericHandleWithCommonStems(
181: // fullHandle, inSac.getCommonStems(), false, localCtp);
182: } else if (inSac.isAction(SubmitActionParameters.REPLACE,
183: SubmitActionParameters.CONCEPT_TAG)) {
184: //
185: //
186: accountForRcthTextChanges(inCps, inPs);
187: //
188: //
189: String parentCode = inSac
190: .getParameter(ConsoleParameterContext.FIRST_INPUT);
191: int addIndex = Integer
192: .parseInt(inSac
193: .getParameter(ConsoleParameterContext.SECOND_INPUT));
194: //
195: String ctNs = inSac
196: .getParameter(ConsoleParameterContext.THIRD_INPUT);
197: if (ctNs.length() == 0) {
198: ctNs = null;
199: }
200: String ctName = inSac
201: .getParameter(ConsoleParameterContext.FOURTH_INPUT);
202: //
203: RootConceptTagHolder localRcth = inCps
204: .getCurrentApplicationRootHolder();
205: ConceptTagCharacteristic localCtchar = localRcth
206: .getCharacteristic(parentCode);
207: //
208: ConceptTagPreferences localCtp = localRcth.getPreferences();
209: //
210: ConceptTagSetHolder ctsh = localCtp.getSetHolder();
211: Class ctClass = ctsh.getConceptTagClass(ctNs, ctName);
212: ConceptTag ct = (ConceptTag) MiscHelper
213: .newInstance(ctClass);
214: //
215: localCtchar.replaceValueAndRemoveLocalFiles(addIndex, ct,
216: false);
217: //boolean localValidate = localCtp//
218: //localRcth
219: localRcth.validate();
220: //
221: //
222: //
223: currentTreeHandle = parentCode
224: + localCtp.getHandleConjunction() + addIndex;
225: currentTreeDeleteNotAdd = null;
226: //outValue.adjustNumericHandleWithCommonStems(
227: // fullHandle, inSac.getCommonStems(), false, localCtp);
228: } else if (inSac.isAction(SubmitActionParameters.ADD,
229: SubmitActionParameters.TEXT)) {
230: //
231: //
232: accountForRcthTextChanges(inCps, inPs);
233: //
234: //
235: String parentCode = inSac
236: .getParameter(ConsoleParameterContext.FIRST_INPUT);
237: int addIndex = Integer
238: .parseInt(inSac
239: .getParameter(ConsoleParameterContext.SECOND_INPUT));
240: //
241: String value = inSac.getParameter(inSac.THIRD_INPUT);
242: //
243: RootConceptTagHolder localRcth = inCps
244: .getCurrentApplicationRootHolder();
245: ConceptTagCharacteristic localCtchar = localRcth
246: .getCharacteristic(parentCode);
247: //
248: ConceptTagPreferences localCtp = localRcth.getPreferences();
249: //
250: //
251: localCtchar.addValue(addIndex, value);
252: localRcth.validate();
253: //
254: //
255: //
256: currentTreeHandle = parentCode
257: + localCtp.getHandleConjunction() + addIndex;
258: currentTreeDeleteNotAdd = new Boolean(false);
259: //outValue.adjustNumericHandleWithCommonStems(
260: // fullHandle, inSac.getCommonStems(), false, localCtp);
261: } else if (inSac.isAction(SubmitActionParameters.REPLACE,
262: SubmitActionParameters.TEXT)) {
263: //
264: //
265: accountForRcthTextChanges(inCps, inPs);
266: //
267: //
268: String parentCode = inSac
269: .getParameter(ConsoleParameterContext.FIRST_INPUT);
270: int addIndex = Integer
271: .parseInt(inSac
272: .getParameter(ConsoleParameterContext.SECOND_INPUT));
273: //
274: String value = inSac
275: .getParameter(ConsoleParameterContext.THIRD_INPUT);
276: //
277: RootConceptTagHolder localRcth = inCps
278: .getCurrentApplicationRootHolder();
279: ConceptTagCharacteristic localCtchar = localRcth
280: .getCharacteristic(parentCode);
281: //
282: ConceptTagPreferences localCtp = localRcth.getPreferences();
283: //
284: //
285: localCtchar
286: .replaceValueAndRemoveLocalFiles(addIndex, value);
287: localRcth.validate();
288: //
289: //
290: //
291: currentTreeHandle = parentCode
292: + localCtp.getHandleConjunction() + addIndex;
293: currentTreeDeleteNotAdd = null;
294: //outValue.adjustNumericHandleWithCommonStems(
295: // fullHandle, inSac.getCommonStems(), false, localCtp);
296: } else if (inSac.isAction(SubmitActionParameters.SAVE)) {
297: //
298: //
299: accountForRcthTextChanges(inCps, inPs);
300: //
301: //
302: ConfigService cs = ConfigServiceCallerFactory
303: .getConfigService();
304: cs.setCurrentConfigInstance(inCps
305: .getCurrentApplicationRootHolder());
306: //throw UnexpectedSystemException.notImplemented();
307: //byte localRcthContent[] = ConceptRollupTag.getRollupFromList(
308: // inCs.getCurrentApplicationRootHolder(), null);
309: //
310: //ProjectSystem projectSystem =
311: // inCs.getCurrentApplicationProjectSystem();
312: ////
313: //VirtualFileSystemHolder pageVsh = projectSystem.getWebPages();
314: ////
315: //VirtualFileSystemHolder localVsh =
316: // pageVsh.getOrCreateAbsoluteDirectory(
317: // inCs.getCurrentApplicationWebDocDirectory());
318: //
319: //byte localOrigContent[] =
320: // localVsh.getFile(
321: // inCs.getCurrentApplicationWebDocFile()).getContent();
322: //RootConceptTagHolder localOrigRcth =
323: // ConceptRollupTag.getRootHolderFromList(localOrigContent);
324: //MiscHelper.println("DevWebPagSer dir = "
325: // + inCs.getCurrentApplicationWebDocDirectory());
326: //MiscHelper.println("DevWebPagSer file = "
327: // + inCs.getCurrentApplicationWebDocFile());
328: //MiscHelper.println("DevWebPagSer origContentLength = "
329: // + localOrigContent.length);
330: //MiscHelper.println("DevWebPagSer currContentLength = "
331: // + localRcthContent.length);
332: //MiscHelper.println("DevWebPagSer origContent = "
333: // + localOrigRcth.getXMLRepresentation());
334: //MiscHelper.println("DevWebPagSer currContent = "
335: //+ inCs.getCurrentApplicationRootHolder().getXMLRepresentation());
336: //
337: //localVsh.updateFile(
338: // inCs.getCurrentApplicationWebDocFile(), localRcthContent);
339: //
340: //UserIdentity ui = inCs.getUserHolder().getUserIdentity();
341: //saveProjectSystem(projectSystem, ui);
342: } else if (inSac.isAction(SubmitActionParameters.MOVE)) {
343: currentHighlightHandle = inSac
344: .getParameter(ConsoleParameterContext.FIRST_INPUT);
345: //inCs.setCurrentApplication()
346: accountForRcthTextChanges(inCps, inPs);
347: }
348: //else if (commonActions(inCs, inUser, inPs, inSac)) {
349: // //MiscHelper.println("common actions executed");
350: //}
351: //else if (inSac.isAction(SubmitActionParameters.OPEN)) {
352: //
353: // inCs.setStudioFrameState(
354: // BaseStudioFrameServlet.HIGH_LEVEL_MODE);
355: //
356: // String appName = inSac.getFirstParameter();
357: // inCs.setOpenApplication(appName);
358: //
359: // //ProjectApplicationSet was = inCs.getProjectApplicationSet();
360: // ProjectSystem wa = inCs.getUserProjectSystem(appName);
361: // //ProjectScript ws = wa.getScript();
362: // ////MiscHelper.println();
363: // //String content = ws.getContent();
364: // ////MiscHelper.println("CONTENT = " + content);
365: // //Document doc = XMLHelper.loadDocument(content);
366: // //RootConceptTagHolder rsth =
367: // // WorkflowTemplateTagHelper.getRootConceptTagHolder(
368: // // doc, null, null, ws.getName());
369: // //
370: // ////MiscHelper.println("ValueLength = "
371: // ////
372: //+ rsth.getConceptTagCharacteristic().getValueLength());
373: // ////MiscHelper.println("Frame,rsth = " + rsth);
374: // //inCs.setRootHolder(rsth);
375: //
376: // //MiscHelper.println(
377: //"WebStudioFrame Remove following statement"
378: // // + (new java.util.Date()));
379: // //for (int i = 0; i < 100; i++) {
380: // // rsth.revalidate();
381: // //}
382: // //MiscHelper.println(
383: //"WebStudioFrame Remove previous statement"
384: // // + (new java.util.Date()));
385: //}
386: //else if (inSac.isAction(SubmitActionParameters.UPDATE,
387: // SubmitActionParameters.COORDINATES)) {
388: //
389: // //MiscHelper.println("PARAMETER1 = "
390: // // + inSac.getFirstParameter());
391: // //MiscHelper.println("PARAMETER2 = "
392: // // + inSac.getSecondParameter());
393: // //MiscHelper.println("PARAMETER3 = "
394: // //+ inSac.getThirdParameter());
395: //
396: // processDeltaCoorAction(
397: // inCs.getRootHolder(), inSac.getFirstParameter(),
398: // Integer.parseInt(inSac.getSecondParameter()),
399: // Integer.parseInt(inSac.getThirdParameter()));
400: //}
401: else {
402: inSac.unknownAction();
403: }
404:
405: //
406: outValue = ConfigInstanceContext.newInstance(inCps);
407: //
408: if (currentHighlightHandle != null) {
409: outValue.setHighlightHandle(currentHighlightHandle);
410: }
411: //
412: if (currentTreeHandle != null) {
413: RootConceptTagHolder localRcth = inCps
414: .getCurrentApplicationRootHolder();
415: ConceptTagPreferences localCtp = localRcth.getPreferences();
416: //
417: if (currentTreeDeleteNotAdd != null) {
418: outValue.adjustNumericHandleWithCommonStems(
419: currentTreeHandle, inSac.getCommonStems(),
420: currentTreeDeleteNotAdd.booleanValue(),
421: localCtp);
422: } else {
423: outValue.adjustNumericHandleWithCommonStems(
424: currentTreeHandle, inSac.getCommonStems(),
425: false, localCtp);
426: outValue.adjustNumericHandleWithCommonStems(
427: currentTreeHandle, inSac.getCommonStems(),
428: true, localCtp);
429: }
430: }
431: //
432: if (binaryContent != null && binaryContentName != null
433: && binaryContentMimeType != null) {
434: outValue.setOutputText(false);
435: outValue.getOutputStream().write(binaryContent, 0,
436: binaryContent.length);
437: outValue.setOutputFileName(binaryContentName);
438: outValue.setMimeType(binaryContentMimeType);
439: }
440:
441: return outValue;
442: }
443:
444: protected void saveChanges(ConsolePageSession inCps,
445: UserHolder inUser, ParameterSet inPs,
446: SubmitActionContext inSac) {
447: //
448: throw UnexpectedSystemException.notImplemented();
449: }
450: }
|