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.dms;
009:
010: //base classes
011: import java.io.IOException;
012: import javax.servlet.ServletException;
013:
014: //project specific classes
015: import org.jfolder.common.UnexpectedSystemException;
016: import org.jfolder.common.entity.SystemEntityUpdatesContext;
017: import org.jfolder.common.files.VirtualFileSystemHolder;
018: import org.jfolder.common.tagging.ConceptTagCharacteristic;
019: import org.jfolder.common.tagging.RootConceptTagHolder;
020: import org.jfolder.common.utils.web.ParameterSet;
021: import org.jfolder.common.web.template.ConsoleParameterContext;
022: import org.jfolder.common.web.template.SubmitActionContext;
023: import org.jfolder.common.web.template.SubmitActionParameters;
024: import org.jfolder.console.base.BaseConsoleServlet;
025: import org.jfolder.console.base.ConsolePageContext;
026: import org.jfolder.console.base.ConsolePageSession;
027: import org.jfolder.dms.model.DocumentFileSystemRoot;
028: import org.jfolder.dms.model.DocumentFileSystemRootUpdates;
029: import org.jfolder.engines.call.GovernorCall;
030: import org.jfolder.engines.call.GovernorCallHelper;
031: import org.jfolder.security.model.UserHolder;
032: import org.jfolder.services.dms.DMSService;
033: import org.jfolder.services.dms.DMSServiceCallerFactory;
034:
035: //other classes
036:
037: public class DocumentSystemServlet extends BaseConsoleServlet {
038:
039: public DocumentSystemServlet() {
040: }
041:
042: protected boolean checkAccess(ConsolePageSession inCps)
043: throws IOException, ServletException {
044:
045: boolean outValue = false;
046:
047: outValue = (inCps.isDeveloper() || inCps.isAdministrator());
048:
049: return outValue;
050: }
051:
052: public ConsolePageContext process(ConsolePageSession inCps,
053: UserHolder inUser, ParameterSet inPs,
054: SubmitActionContext inSac) throws IOException,
055: ServletException {
056:
057: //
058: ConsolePageContext outValue = null;
059:
060: if (inSac.isAction(SubmitActionParameters.OPEN)) {
061: inCps.setDocumentSystemRoot(null);
062: } else if (inSac.isAction(SubmitActionParameters.DO_NOTHING)) {
063: } else if (inSac.isAction(SubmitActionParameters.LOAD,
064: SubmitActionParameters.DEFAULT)) {
065: //
066: //inCs.setDocumentSystemRoot(null);
067: //
068: RootConceptTagHolder dummyRcth = GovernorCallHelper
069: .createGovernorRequest("DUMMY", "DUMMY");
070: GovernorCall dummyGc = (GovernorCall) dummyRcth
071: .getFirstChildConceptTag();
072: ConceptTagCharacteristic dummyCtchar = dummyGc
073: .addPrepareArgumentAsSEntity();
074: //
075: DMSService ds = DMSServiceCallerFactory.getDMSService();
076: DocumentFileSystemRoot dsr = ds.accessDocumentSystem(
077: dummyCtchar, 0, "ADMIN", "SAMPLE");
078: //
079: inCps.setDocumentSystemRoot(dsr);
080: } else if (inSac.isAction(SubmitActionParameters.SAVE,
081: SubmitActionParameters.DEFAULT)) {
082: //
083: //
084: //
085: //
086: //
087: //
088: //
089: //
090: DMSService ds = DMSServiceCallerFactory.getDMSService();
091: //
092: RootConceptTagHolder dummy1Rcth = GovernorCallHelper
093: .createGovernorRequest("DUMMY", "DUMMY");
094: GovernorCall dummy1Gc = (GovernorCall) dummy1Rcth
095: .getFirstChildConceptTag();
096: ConceptTagCharacteristic dummy1Ctchar = dummy1Gc
097: .addPrepareArgumentAsSEntity();
098: SystemEntityUpdatesContext seuc1 = SystemEntityUpdatesContext
099: .newInstance(null, true, dummy1Ctchar, 0);
100: //
101: DocumentFileSystemRoot dsr1 = inCps.getDocumentSystemRoot();
102: DocumentFileSystemRootUpdates drsu = (DocumentFileSystemRootUpdates) dsr1
103: .getSystemEntityUpdates(seuc1);
104: //
105: ds.saveDocumentSystem(drsu);
106: //
107: //inCs.setDocumentSystemRoot(null);
108: //
109: RootConceptTagHolder dummy2Rcth = GovernorCallHelper
110: .createGovernorRequest("DUMMY", "DUMMY");
111: GovernorCall dummy2Gc = (GovernorCall) dummy2Rcth
112: .getFirstChildConceptTag();
113: ConceptTagCharacteristic dummy2Ctchar = dummy2Gc
114: .addPrepareArgumentAsSEntity();
115: //
116: //DMSService ds = DMSServiceCallerFactory.getDMSService();
117: DocumentFileSystemRoot dsr2 = ds.accessDocumentSystem(
118: dummy2Ctchar, 0, "ADMIN", "SAMPLE");
119: //
120: inCps.setDocumentSystemRoot(dsr2);
121: } else if (inSac.isAction(SubmitActionParameters.CREATE,
122: SubmitActionParameters.DIRECTORY)) {
123: //
124: DocumentFileSystemRoot dsr = inCps.getDocumentSystemRoot();
125: //
126: String parentDir = inSac.getParameter(inSac.FIRST_INPUT);
127: String childDir = inPs
128: .getParameter(SubmitActionParameters.DIRECTORY);
129: //
130: VirtualFileSystemHolder vsh = dsr
131: .getOrCreateAbsoluteDirectory(parentDir);
132: vsh.createDirectory(childDir);
133: } else if (inSac.isAction(SubmitActionParameters.CREATE,
134: SubmitActionParameters.FILE)) {
135: //
136: DocumentFileSystemRoot dsr = inCps.getDocumentSystemRoot();
137: //
138: String parentDir = inSac
139: .getParameter(ConsoleParameterContext.FIRST_INPUT);
140: byte childContent[] = inPs
141: .getParameterAsUpload(SubmitActionParameters.FILE);
142: String childName = inPs
143: .getUploadParameterName(SubmitActionParameters.FILE);
144: //
145: VirtualFileSystemHolder vsh = dsr
146: .getOrCreateAbsoluteDirectory(parentDir);
147: vsh.createFile(childName, childContent);
148: } else if (inSac.isAction(SubmitActionParameters.DELETE,
149: SubmitActionParameters.DIRECTORY)) {
150: //
151: DocumentFileSystemRoot dsr = inCps.getDocumentSystemRoot();
152: //
153: String parentDir = inSac
154: .getParameter(ConsoleParameterContext.FIRST_INPUT);
155: String childDir = inSac
156: .getParameter(ConsoleParameterContext.SECOND_INPUT);
157: //String childDir = inPs.getParameter(
158: // SubmitActionParameters.DIRECTORY);
159: //
160: VirtualFileSystemHolder vsh = dsr
161: .getOrCreateAbsoluteDirectory(parentDir);
162: vsh.removeDirectory(childDir);
163: } else if (inSac.isAction(SubmitActionParameters.DELETE,
164: SubmitActionParameters.FILE)) {
165: //
166: DocumentFileSystemRoot dsr = inCps.getDocumentSystemRoot();
167: //
168: String parentDir = inSac
169: .getParameter(ConsoleParameterContext.FIRST_INPUT);
170: String childName = inSac
171: .getParameter(ConsoleParameterContext.SECOND_INPUT);
172: //byte childContent[] = inPs.getParameterAsUpload(
173: // SubmitActionParameters.FILE);
174: //String childName = inPs.getUploadParameterName(
175: // SubmitActionParameters.FILE);
176: //
177: VirtualFileSystemHolder vsh = dsr
178: .getOrCreateAbsoluteDirectory(parentDir);
179: vsh.removeFile(childName);
180: } else {
181: throw UnexpectedSystemException.unknownState();
182: }
183:
184: outValue = DocumentSystemContext.newInstance(inCps);
185:
186: return outValue;
187:
188: }
189:
190: }
|