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 java.util.ArrayList;
013: import java.util.HashMap;
014:
015: //project specific classes
016: import org.jfolder.common.files.BaseVirtualFileSystemHolder;
017: import org.jfolder.common.files.VirtualFileSystemDirectory;
018: import org.jfolder.common.files.VirtualFileSystemFile;
019: import org.jfolder.common.files.VirtualFileSystemHolder;
020: import org.jfolder.common.tagging.ConceptRollupTag;
021: import org.jfolder.common.utils.misc.MiscHelper;
022: import org.jfolder.common.utils.xml.XMLHelper;
023: import org.jfolder.common.web.template.ConsoleParameterContext;
024: import org.jfolder.common.web.template.SubmitActionContext;
025: import org.jfolder.common.web.template.SubmitActionParameters;
026: import org.jfolder.console.base.ConsolePageContext;
027: import org.jfolder.console.base.ConsolePageParameters;
028: import org.jfolder.console.base.ConsolePageSession;
029: import org.jfolder.dms.model.DocumentFileSystemDirectory;
030: import org.jfolder.dms.model.DocumentFileSystemFile;
031: import org.jfolder.dms.model.DocumentFileSystemRoot;
032: import org.jfolder.services.workflow.WorkflowServiceCaller;
033: import org.jfolder.services.workflow.WorkflowServiceCallerFactory;
034:
035: //other classes
036:
037: public class DocumentSystemContext extends ConsolePageContext {
038:
039: private final static String BUTTON__SAVE_DEFAULT = "BUTTON__SAVE_DEFAULT";
040: private final static String BUTTON__LOAD_DEFAULT = "BUTTON__LOAD_DEFAULT";
041: private final static String BUTTON__DELETE = "BUTTON__DELETE";
042: private final static String BUTTON__C_FILE = "BUTTON__C_FILE";
043: private final static String BUTTON__C_DIR = "BUTTON__C_DIR";
044:
045: private DocumentSystemContext(ConsolePageSession inCps) {
046: super (inCps);
047: }
048:
049: public final static DocumentSystemContext newInstance(
050: ConsolePageSession inCps) {
051:
052: DocumentSystemContext outValue = null;
053:
054: outValue = new DocumentSystemContext(inCps);
055:
056: return outValue;
057: }
058:
059: public String getFromPage() {
060: //
061: //
062: return ConsolePageParameters.SERVLET_DOCUMENT_SYSTEM;
063: }
064:
065: public String getHandleExtension() {
066: return NULL_HANDLE;
067: }
068:
069: //ConsoleScreenHelper
070: protected void renderConsolePage() throws IOException {
071:
072: startCommonPage();
073:
074: ConsolePageSession cs = getConsolePageSession();
075: DocumentFileSystemRoot dsr = cs.getDocumentSystemRoot();
076:
077: //
078: startEnclosingTableAndRowAndCell(alignCenter(null));
079: startAndEndStretchTableAndRowAndCell("<hr/>");
080: //
081: startAndEndSimpleTableAndRowAndCell(3, "Document System",
082: getFontStyle(20, ARIAL, BLACK));
083: //
084: startAndEndStretchTableAndRowAndCell("<hr/>");
085: //
086: if (dsr != null) {
087: startTable(3);
088: startRow();
089: startAndEndCell(3, "SECTION = " + dsr.getSection());
090: endRow();
091: startRow();
092: startAndEndCell(3, "SUB_SECTION = " + dsr.getSubSection());
093: endRow();
094: startRow();
095: startAndEndCell(3, "VERSION = " + dsr.getVersion());
096: endRow();
097: endTable();
098: startAndEndStretchTableAndRowAndCell("<hr/>");
099: listContents(new ArrayList(), dsr);
100: startAndEndStretchTableAndRowAndCell("<hr/>");
101: //
102: startTable(3);
103: startRow();
104: startAndEndCell(1, "New Directory");
105: startAndEndCell(2, createTextBox(
106: SubmitActionParameters.DIRECTORY, "", null, null,
107: null, null, null));
108: endCell();
109: endRow();
110: endTable();
111: //
112: startAndEndStretchTableAndRowAndCell("<hr/>");
113: //
114: startTable(3);
115: startRow();
116: startAndEndCell(1, "New File");
117: startAndEndCell(2, createFileUpload(
118: SubmitActionParameters.FILE, null));
119: endCell();
120: endRow();
121: endTable();
122: //
123: startAndEndStretchTableAndRowAndCell("<hr/>");
124: //
125: startTable(3);
126: startRow();
127: startCell(3, alignCenter(null));
128: SubmitActionContext sacSaveDefault = SubmitActionContext
129: .newInstance(this );
130: //
131: sacSaveDefault.addAction(
132: ConsoleParameterContext.FIRST_INPUT,
133: singleQuotes(SubmitActionParameters.SAVE));
134: sacSaveDefault.addAction(
135: ConsoleParameterContext.SECOND_INPUT,
136: singleQuotes(SubmitActionParameters.DEFAULT));
137: //sacDatabaseAccess.setGoToPage(
138: // ConsolePageParameters.SERVLET_DATABASE_ACCESS);
139: createButton(BUTTON__SAVE_DEFAULT, "Save Default", 150,
140: submitActionCall(sacSaveDefault), null, null, null,
141: null);
142: endCell();
143: endRow();
144: endTable();
145: } else {
146: startAndEndSimpleTableAndRowAndCell(3,
147: "No Document System Selected", getFontStyle(12,
148: ARIAL, BLACK));
149: }
150: //
151: startAndEndStretchTableAndRowAndCell("<hr/>");
152: //
153: //
154: startTable(3);
155: startRow();
156: startCell(3, alignCenter(null));
157: SubmitActionContext sacLoadDefault = SubmitActionContext
158: .newInstance(this );
159: //
160: sacLoadDefault.addAction(ConsoleParameterContext.FIRST_INPUT,
161: singleQuotes(SubmitActionParameters.LOAD));
162: sacLoadDefault.addAction(ConsoleParameterContext.SECOND_INPUT,
163: singleQuotes(SubmitActionParameters.DEFAULT));
164: //sacDatabaseAccess.setGoToPage(
165: // ConsolePageParameters.SERVLET_DATABASE_ACCESS);
166: createButton(BUTTON__LOAD_DEFAULT, "Load Default", 150,
167: submitActionCall(sacLoadDefault), null, null, null,
168: null);
169: endCell();
170: endRow();
171: endTable();
172: //
173: startAndEndStretchTableAndRowAndCell("<hr/>");
174: //
175: endEnclosingTableAndRowAndCell();
176:
177: endCommonPage();
178: }
179:
180: private void listContents(ArrayList inDir,
181: VirtualFileSystemHolder inVsh) throws IOException {
182:
183: //
184: String dirName = BaseVirtualFileSystemHolder
185: .parseDirectoryArray(inDir);
186:
187: //
188: ArrayList localDirs = inVsh.getLocalDirectories();
189: for (int i = 0; i < localDirs.size(); i++) {
190: //String nextDirName = (String)localDirs.get(i);
191: VirtualFileSystemDirectory nextDir = (VirtualFileSystemDirectory) localDirs
192: .get(i);
193: //
194: inDir.add(nextDir.getName());
195: listContents(inDir, nextDir);
196: inDir.remove(inDir.size() - 1);
197: }
198:
199: //
200: listContent((inDir.size() > 0), dirName, null);
201: //startAndEndSimpleTableAndRowAndCell(3, dirName);
202: ArrayList localFiles = inVsh.getLocalFiles();
203: for (int i = 0; i < localFiles.size(); i++) {
204: //String nextFileHandle = (String)localFiles.get(i);
205: VirtualFileSystemFile nextFile = (VirtualFileSystemFile) localFiles
206: .get(i);
207: //
208: //MiscHelper.println("nextFile(" + i + ") = " + nextFile);
209: //MiscHelper.println("nextFile(" + i + "),content = "
210: // + nextFile.getContent());
211: listContent(true, dirName + nextFile.getName(),
212: new Integer(nextFile.getContent().length));
213: //startAndEndSimpleTableAndRowAndCell(
214: // 3, dirName + nextFile.getName());
215: }
216: }
217:
218: private void listContent(boolean inDeletable, String inName,
219: Integer inSize) throws IOException {
220: //
221: startAndEndStretchTableAndRowAndCell("<hr/>");
222: //
223: startTable(3);
224: startRow();
225: //
226: startCell(1, alignCenter(null));
227: if (inDeletable) {
228: SubmitActionContext sacDelete = SubmitActionContext
229: .newInstance(this );
230: //
231: sacDelete.addAction(ConsoleParameterContext.FIRST_INPUT,
232: singleQuotes(SubmitActionParameters.DELETE));
233: //
234: String fullName = inName;
235: //String parentDir = null;
236: //String localComponent = null;
237: //
238: if (fullName
239: .endsWith(VirtualFileSystemHolder.DIRECTORY_SEPARATOR)) {
240: //
241: fullName = fullName.substring(0, fullName.length()
242: - VirtualFileSystemHolder.DIRECTORY_SEPARATOR
243: .length());
244: }
245: int index = fullName
246: .lastIndexOf(VirtualFileSystemHolder.DIRECTORY_SEPARATOR);
247: String parentDir = fullName.substring(0, index
248: + VirtualFileSystemHolder.DIRECTORY_SEPARATOR
249: .length());
250: String localComponent = fullName.substring(parentDir
251: .length());
252:
253: //
254: if (inSize != null) {
255: //
256: sacDelete.addAction(
257: ConsoleParameterContext.SECOND_INPUT,
258: singleQuotes(SubmitActionParameters.FILE));
259: //
260: sacDelete.addParameter(
261: ConsoleParameterContext.FIRST_INPUT,
262: singleQuotes(parentDir));
263: sacDelete.addParameter(
264: ConsoleParameterContext.SECOND_INPUT,
265: singleQuotes(localComponent));
266: } else {
267: //
268: sacDelete.addAction(
269: ConsoleParameterContext.SECOND_INPUT,
270: singleQuotes(SubmitActionParameters.DIRECTORY));
271: //
272: sacDelete.addParameter(
273: ConsoleParameterContext.FIRST_INPUT,
274: singleQuotes(parentDir));
275: sacDelete.addParameter(
276: ConsoleParameterContext.SECOND_INPUT,
277: singleQuotes(localComponent));
278: }
279: //sacDatabaseAccess.setGoToPage(
280: // ConsolePageParameters.SERVLET_DATABASE_ACCESS);
281: createButton(BUTTON__DELETE, "Delete", 75,
282: submitActionCall(sacDelete), null, null, null, null);
283: } else {
284: simpleAndPrint(" ");
285: }
286: //
287: if (inSize == null) {
288: SubmitActionContext sacCreateFile = SubmitActionContext
289: .newInstance(this );
290: //
291: sacCreateFile.addAction(
292: ConsoleParameterContext.FIRST_INPUT,
293: singleQuotes(SubmitActionParameters.CREATE));
294: sacCreateFile.addAction(
295: ConsoleParameterContext.SECOND_INPUT,
296: singleQuotes(SubmitActionParameters.FILE));
297: //
298: sacCreateFile.addParameter(
299: ConsoleParameterContext.FIRST_INPUT,
300: singleQuotes(inName));
301: createButton(BUTTON__C_FILE, "C File", 75,
302: submitActionCall(sacCreateFile), null, null, null,
303: null);
304: //
305: SubmitActionContext sacCreateDirectory = SubmitActionContext
306: .newInstance(this );
307: //
308: sacCreateDirectory.addAction(
309: ConsoleParameterContext.FIRST_INPUT,
310: singleQuotes(SubmitActionParameters.CREATE));
311: sacCreateDirectory.addAction(
312: ConsoleParameterContext.SECOND_INPUT,
313: singleQuotes(SubmitActionParameters.DIRECTORY));
314: //
315: sacCreateDirectory.addParameter(
316: ConsoleParameterContext.FIRST_INPUT,
317: singleQuotes(inName));
318: createButton(BUTTON__C_DIR, "C Dir", 75,
319: submitActionCall(sacCreateDirectory), null, null,
320: null, null);
321: }
322: endCell();
323: if (inSize != null) {
324: startAndEndCell(2, inName + " (" + inSize + " bytes)");
325: } else {
326: startAndEndCell(2, inName);
327: }
328: //
329: endRow();
330: endTable();
331: }
332: }
|