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.base;
009:
010: //base classes
011: import java.io.IOException;
012: import java.util.ArrayList;
013: import java.util.Collections;
014: import java.util.HashMap;
015: import java.util.HashSet;
016:
017: //project specific classes
018: import org.jfolder.common.UnexpectedSystemException;
019: import org.jfolder.common.files.BaseVirtualFileSystemHolder;
020: import org.jfolder.common.files.SimpleVirtualFileSystemProperties;
021: import org.jfolder.common.files.VirtualFileSystemDirectory;
022: import org.jfolder.common.files.VirtualFileSystemFile;
023: import org.jfolder.common.files.VirtualFileSystemHolder;
024: import org.jfolder.common.web.template.ConsoleParameterContext;
025: import org.jfolder.common.web.template.SubmitActionContext;
026: import org.jfolder.common.web.template.SubmitActionParameters;
027: import org.jfolder.console.base.ConsolePageContext;
028: import org.jfolder.console.base.ConsolePageParameters;
029: import org.jfolder.console.base.ConsolePageSession;
030: import org.jfolder.console.base.context.BaseSubBoxConsolePageContext;
031: import org.jfolder.project.model.ProjectSystem;
032:
033: //other classes
034:
035: public class SubAppDirConsolePageContext extends
036: BaseSubBoxConsolePageContext {
037:
038: //
039: public final static String PREFIX__DIRECTORY = "D_";
040: public final static String PREFIX__FILE = "F_";
041: //
042: private final static String I_DIRECTORY_IMAGE = "I_DIRECTORY_IMAGE";
043: //
044: private final static String TOG_CAL__DIRECTORY = "TOG_CAL__DIRECTORY";
045: //
046: private final static String IMAGE__DELETE = "IMAGE__DELETE";
047: private final static String IMAGE__EDIT = "IMAGE__EDIT";
048: //
049: private final static String SECTION_PREFIX__APP_DIR = "app_dir_";
050:
051: //
052: private ProjectSystem ps = null;
053: private String dirId = null;
054:
055: //private int columnWidth = 0;
056: //private int height = 0;
057: //private String sideColor = null;
058:
059: private SubAppDirConsolePageContext(ProjectSystem inPs,
060: int inColumnWidth, int inHeight, String inSideColor,
061: ConsolePageContext inCpc, String inDirId) {
062:
063: super (constructName(inPs), inColumnWidth, inHeight,
064: inSideColor, inCpc);
065: //
066: this .ps = inPs;
067: this .dirId = inDirId;
068: //this.columnWidth = inColumnWidth;
069: //this.height = inHeight;
070: //this.sideColor = inSideColor;
071:
072: }
073:
074: private final static String constructName(ProjectSystem inPs) {
075: return constructName(inPs.getName(), inPs.isDeployed());
076: }
077:
078: public final static String constructName(String inName,
079: boolean inDepl) {
080: return (SECTION_PREFIX__APP_DIR + userOrServer(!inDepl) + inName);
081: }
082:
083: protected final static SubAppDirConsolePageContext newInstance(
084: ProjectSystem inPs, int inColumnWidth, int inHeight,
085: String inSideColor, ConsolePageContext inCpc, String inDirId)
086: throws IOException {
087:
088: SubAppDirConsolePageContext outValue = null;
089:
090: if (inCpc.isSubConsolePageContextPresent(constructName(inPs))) {
091: Object o = inCpc
092: .getSubConsolePageContext(constructName(inPs));
093: outValue = (SubAppDirConsolePageContext) o;
094: } else {
095: outValue = new SubAppDirConsolePageContext(inPs,
096: inColumnWidth, inHeight, inSideColor, inCpc,
097: inDirId);
098: //inCpc.registerSubConsolePageContext(inName, outValue);
099: }
100:
101: outValue.copyFromParent(inCpc);
102: outValue.createConsolePage(inCpc.getWriter(), inCpc
103: .getPageSetupContext());
104:
105: return outValue;
106: }
107:
108: public final static String userOrServer(boolean inUser) {
109:
110: String outValue = null;
111:
112: if (inUser) {
113: outValue = "user";
114: } else {
115: outValue = "server";
116: }
117: outValue = outValue + "_";
118:
119: return outValue;
120: }
121:
122: //
123: //
124: protected void renderContent() throws IOException {
125: writeSubDirectory(
126: this .ps,// this.ps.getWebDocs(),
127: //writeSubDirectory(this.ps, this.ps.getWebDocs(),
128: this .ps.getWebDocsProperties(), new ArrayList(),
129: this .ps.getName());
130: }
131:
132: public final static HashMap getImageAttrs(SubmitActionContext inSac) {
133:
134: HashMap outValue = new HashMap();
135:
136: outValue.put("onmouseover", "this.style.cursor = 'pointer';");
137: outValue.put("onmouseout", "this.style.cursor = 'default';");
138: outValue.put("onclick", inSac.submitActionCall(true));
139:
140: return outValue;
141: }
142:
143: private void writeSubDirectory(
144: ProjectSystem inPs,// VirtualFileSystemHolder inWebDocsDir,
145: VirtualFileSystemHolder inWebDocsPropertiesDir,
146: ArrayList inCurrentDir, String inAppName)
147: throws IOException {
148:
149: HashMap subDirNames = new HashMap();
150: //addDirNames(inWebDocsDir, subDirNames);
151: addDirNames(inWebDocsPropertiesDir, subDirNames);
152: //
153: ConsolePageSession localCps = getConsolePageSession();
154: //
155: //HashMap imageAttrs = new HashMap();
156: //HashMap imageStyles = new HashMap();
157:
158: //
159: String fullDirName = BaseVirtualFileSystemHolder
160: .parseDirectoryArray(inCurrentDir);
161: String currentDirName = "(Home)";
162: String delDir = "";
163: if (inCurrentDir.size() > 0) {
164: currentDirName = (String) inCurrentDir.get(inCurrentDir
165: .size() - 1);
166: //
167: SubmitActionContext sacDelDir = SubmitActionContext
168: .newInstance(this );
169: sacDelDir.addAction(ConsoleParameterContext.FIRST_INPUT,
170: singleQuotes(SubmitActionParameters.DELETE));
171: sacDelDir.addAction(ConsoleParameterContext.SECOND_INPUT,
172: singleQuotes(SubmitActionParameters.DIRECTORY));
173: //
174: sacDelDir.addParameter(ConsoleParameterContext.FIRST_INPUT,
175: singleQuotes(SubmitActionParameters.USER));
176: sacDelDir.addParameter(
177: ConsoleParameterContext.SECOND_INPUT,
178: singleQuotes(inAppName));
179: sacDelDir.addParameter(ConsoleParameterContext.THIRD_INPUT,
180: singleQuotes(fullDirName));
181: //
182: sacDelDir
183: .setConfirm("'Are you sure you want to delete this directory?'");
184: //
185: //imageAttrs.clear();
186: //imageStyles.clear();
187: //
188: //imageAttrs.put("onmouseover", "this.style.cursor = 'pointer';");
189: //imageAttrs.put("onmouseout", "this.style.cursor = 'default';");
190: //imageAttrs.put("onclick", sacDelDir.submitActionCall());
191: //
192: delDir = padNbsp(1)
193: + createStaticImage(IMAGE__DELETE,
194: ConsolePageParameters.GIF_DELETE,
195: getImageAttrs(sacDelDir), null);
196: // + "<img src=\"" + ConsolePageParameters.GIF_DELETE
197: // + "\" onmouseover=\"this.style.cursor = 'pointer';"
198: // + "\" onmouseout=\"this.style.cursor = 'default';"
199: // + "\" onclick=\"" + sacDelDir.submitActionCall()
200: // + "\"/>";
201: }
202: //
203: //getConsolePageSession().pushToggleLink("I_DIRECTORY_IMAGE");
204: //String dirImageId = "getPageComponent('"
205: // + getConsolePageSession().getToggleLink() + "')";
206: //String dirImageId = getConsolePageSession().getToggleLink();
207: //getConsolePageSession().popToggleLink();
208: //
209:
210: String folderImage = null;
211: // + " if (" + dirImageId + ".src == '"
212: // + ConsolePageParameters.GIF_OPEN_FOLDER + "') {"
213: // //
214: // + dirImageId + ".src = '"
215: // + ConsolePageParameters.GIF_CLOSED_FOLDER
216: // + "';}"
217: // //
218: // + " else if (" + dirImageId + ".src == '"
219: // + ConsolePageParameters.GIF_CLOSED_FOLDER + "') {"
220: // //
221: // + dirImageId + ".src = '"
222: // + ConsolePageParameters.GIF_OPEN_FOLDER
223: // + "';}";
224: if (!true) {
225: folderImage = ConsolePageParameters.GIF_OPEN_FOLDER;
226: } else {
227: folderImage = ConsolePageParameters.GIF_CLOSED_FOLDER;
228: }
229: //
230: String folderGif = createStaticImage(I_DIRECTORY_IMAGE,
231: folderImage, null, null);
232: String dirImageId = getConsolePageSession()
233: .getPreviousToggleLink();
234: //
235: //
236: String action = "getPageComponent('" + this .dirId
237: + "').value = '" + fullDirName + "';";
238: action = action + " swapImages('" + dirImageId + "', '"
239: + ConsolePageParameters.GIF_OPEN_FOLDER + "', '"
240: + ConsolePageParameters.GIF_CLOSED_FOLDER + "');";
241: //
242: //
243: //String folderGif =
244: // "<img id=\"" + dirImageId + "\" src=\"" + folderImage + "\"/>";
245: simpleAndPrint(padNbsp((2 * inCurrentDir.size()))
246: + getAutoTogglingLinkWithTargetId(TOG_CAL__DIRECTORY,
247: folderGif + padNbsp(1) + currentDirName, action)
248: + delDir + "<br/>");
249: startAutoTogglingTableAndRowAndCell();
250: //
251: //
252: //
253: ArrayList subDirs = new ArrayList(subDirNames.keySet());
254: Collections.sort(subDirs);
255: for (int i = 0; i < subDirs.size(); i++) {
256: //
257: String nextSubDirUpperName = (String) subDirs.get(i);
258: String nextSubDirName = (String) subDirNames
259: .get(nextSubDirUpperName);
260: //
261: localCps.pushToggleLink(PREFIX__DIRECTORY + nextSubDirName);
262: //
263: inCurrentDir.add(nextSubDirName);
264: //
265: //
266: //VirtualFileSystemHolder subFilesDir =
267: // getDirOrNull(inFilesDir, nextSubDirName);
268: //VirtualFileSystemHolder subWebDocsDir =
269: // getDirOrNull(inWebDocsDir, nextSubDirName);
270: VirtualFileSystemHolder subWebDocsPropertiesDir = getDirOrNull(
271: inWebDocsPropertiesDir, nextSubDirName);
272: //VirtualFileSystemHolder subMacrosDir =
273: // getDirOrNull(inMacrosDir, nextSubDirName);
274: //VirtualFileSystemHolder subTemplatesDir =
275: // getDirOrNull(inTemplatesDir, nextSubDirName);
276: //VirtualFileSystemHolder subServletsDir =
277: // getDirOrNull(inServletsDir, nextSubDirName);
278: //if (subFilesDir == null && subPagesDir == null
279: // && subMacrosDir == null && subTemplatesDir == null
280: // && subServletsDir == null) {
281: // //do nothing
282: //}
283: if (subWebDocsPropertiesDir == null) {
284: //do nothing
285: } else {
286: //writeSubDirectory(subFilesDir, subPagesDir, subMacrosDir,
287: // subTemplatesDir, subServletsDir, inCurrentDir, inAppName);
288: writeSubDirectory(inPs, subWebDocsPropertiesDir,
289: inCurrentDir, inAppName);
290: }
291: //
292: inCurrentDir.remove(inCurrentDir.size() - 1);
293: localCps.popToggleLink();
294: }
295:
296: //
297: HashMap dirFiles = new HashMap();
298: //addFiles(inWebDocsDir, dirFiles);
299: addFiles(inWebDocsPropertiesDir, dirFiles);
300:
301: ArrayList fileList = new ArrayList(dirFiles.keySet());
302: Collections.sort(fileList);
303: for (int i = 0; i < fileList.size(); i++) {
304: //
305: String nextFileUpperName = (String) fileList.get(i);
306: VirtualFileSystemFile nextFile = (VirtualFileSystemFile) dirFiles
307: .get(nextFileUpperName);
308: String fullFileName = BaseVirtualFileSystemHolder
309: .parseDirectoryArray(inCurrentDir)
310: + nextFile.getName();
311: //
312: //
313: localCps.pushToggleLink(PREFIX__FILE + nextFile.getName());
314: //
315: SubmitActionContext sacDelGeneralFile = SubmitActionContext
316: .newInstance(this );
317: //
318: sacDelGeneralFile.addAction(
319: ConsoleParameterContext.FIRST_INPUT,
320: singleQuotes(SubmitActionParameters.DELETE));
321: //
322: sacDelGeneralFile
323: .setConfirm("'Are you sure you want to delete this file?'");
324: //
325: sacDelGeneralFile.addParameter(
326: ConsoleParameterContext.FIRST_INPUT,
327: singleQuotes(SubmitActionParameters.USER));
328: sacDelGeneralFile.addParameter(
329: ConsoleParameterContext.SECOND_INPUT,
330: singleQuotes(inAppName));
331: sacDelGeneralFile.addParameter(
332: ConsoleParameterContext.THIRD_INPUT,
333: singleQuotes(fullDirName));
334: sacDelGeneralFile.addParameter(
335: ConsoleParameterContext.FOURTH_INPUT,
336: singleQuotes(nextFile.getName()));
337: //
338: String editTextFile = "";
339: String textGifImage = ConsolePageParameters.GIF_TEXT;
340: //
341: //VirtualFileSystemFile svfspFile =
342: // inPs.getWebDocsProperties().;
343: SimpleVirtualFileSystemProperties svfsp = SimpleVirtualFileSystemProperties
344: .newInstance(nextFile.getContent());
345: //
346: if (inPs.isWebDocFile(svfsp)) {
347: //
348: sacDelGeneralFile.addAction(
349: ConsoleParameterContext.SECOND_INPUT,
350: singleQuotes(SubmitActionParameters.WEB_FILE));
351: if (inPs.isWebDocText(svfsp)) {
352: SubmitActionContext sacEditTextFile = SubmitActionContext
353: .newInstance(this );
354: //
355: sacEditTextFile
356: .setGoToPage(ConsolePageParameters.SERVLET_EDIT_TEXT_FILE_PAGE);
357: //
358: sacEditTextFile.addAction(
359: ConsoleParameterContext.FIRST_INPUT,
360: singleQuotes(SubmitActionParameters.OPEN));
361: //
362: sacEditTextFile.addParameter(
363: ConsoleParameterContext.FIRST_INPUT,
364: singleQuotes(SubmitActionParameters.USER));
365: sacEditTextFile.addParameter(
366: ConsoleParameterContext.SECOND_INPUT,
367: singleQuotes(inAppName));
368: sacEditTextFile
369: .addParameter(
370: ConsoleParameterContext.THIRD_INPUT,
371: singleQuotes(SubmitActionParameters.WEB_FILE));
372: sacEditTextFile.addParameter(
373: ConsoleParameterContext.FOURTH_INPUT,
374: singleQuotes(fullDirName));
375: sacEditTextFile.addParameter(
376: ConsoleParameterContext.FIFTH_INPUT,
377: singleQuotes(nextFile.getName()));
378: //
379: editTextFile = padNbsp(1)
380: + createStaticImage(
381: IMAGE__EDIT,
382: ConsolePageParameters.GIF_EDIT_BUTTON,
383: getImageAttrs(sacEditTextFile),
384: null);
385: // + "<img alt=\"Edit\" src=\""
386: // + ConsolePageParameters.GIF_EDIT_BUTTON
387: // + "\" onclick=\""
388: // + sacEditTextFile.submitActionCall()
389: // + "\" onmouseover=\"this.style.cursor = 'pointer';"
390: // + "\" onmouseout=\"this.style.cursor = 'default';"
391: // + "\"/>";
392: }
393: } else if (inPs.isWebDocPage(svfsp)
394: || inPs.isWebDocTemplate(svfsp)
395: || inPs.isWebDocMacro(svfsp)
396: || inPs.isWebDocBinary(svfsp)) {
397: //
398: if (inPs.isWebDocPage(svfsp)) {
399: textGifImage = ConsolePageParameters.GIF_WEB_PAGE;
400: } else if (inPs.isWebDocMacro(svfsp)) {
401: textGifImage = ConsolePageParameters.GIF_WEB_MACRO;
402: } else if (inPs.isWebDocBinary(svfsp)) {
403: textGifImage = ConsolePageParameters.GIF_WEB_BINARY;
404: } else if (inPs.isWebDocTemplate(svfsp)) {
405: textGifImage = ConsolePageParameters.GIF_WEB_TEMPLATE;
406: } else {
407: throw UnexpectedSystemException.unknownState();
408: }
409: //
410: sacDelGeneralFile.addAction(
411: ConsoleParameterContext.SECOND_INPUT,
412: singleQuotes(SubmitActionParameters.WEB_PAGE));
413: //
414: SubmitActionContext sacEditWebPage = SubmitActionContext
415: .newInstance(this );
416: //
417: initializeEditWebPage(sacEditWebPage, true,
418: singleQuotes(inAppName),
419: singleQuotes(fullDirName),
420: singleQuotes(nextFile.getName()));
421: //
422: //sacEditWebPage.setGoToPage(
423: // ConsolePageParameters.SERVLET_DEVELOP_WEB_PAGE);
424: //
425: //sacEditWebPage.addAction(
426: // sacEditWebPage.FIRST_INPUT,
427: // singleQuotes(SubmitActionParameters.OPEN));
428: //
429: //sacEditWebPage.addParameter(
430: // sacEditWebPage.FIRST_INPUT,
431: // singleQuotes(SubmitActionParameters.USER));
432: //sacEditWebPage.addParameter(
433: // sacEditWebPage.SECOND_INPUT,
434: // singleQuotes(inAppName));
435: //sacEditWebPage.addParameter(
436: // sacEditWebPage.THIRD_INPUT,
437: // singleQuotes(SubmitActionParameters.WEB_PAGE));
438: //sacEditWebPage.addParameter(
439: // sacEditWebPage.FOURTH_INPUT,
440: // singleQuotes(fullDirName));
441: //sacEditWebPage.addParameter(
442: // sacEditWebPage.FIFTH_INPUT,
443: // singleQuotes(nextFile.getName()));
444: //
445: editTextFile = padNbsp(1)
446: + createStaticImage(IMAGE__EDIT,
447: ConsolePageParameters.GIF_EDIT_BUTTON,
448: getImageAttrs(sacEditWebPage), null);
449: // "<img alt=\"Edit\" src=\""
450: // + ConsolePageParameters.GIF_EDIT_BUTTON
451: // + "\" onclick=\""
452: // + sacEditWebPage.submitActionCall()
453: // + "\" onmouseover=\"this.style.cursor = 'pointer';"
454: // + "\" onmouseout=\"this.style.cursor = 'default';"
455: // + "\"/>";
456: }
457: //else if (inMacrosDir.isFilePresent(nextFileUpperName)) {
458: // //
459: // sacDelGeneralFile.setSubAction(
460: // singleQuotes(SubmitActionParameters.WEB_MACRO));
461: //}
462: //else if (inTemplatesDir.isFilePresent(nextFileUpperName)) {
463: // //
464: // sacDelGeneralFile.setSubAction(
465: // singleQuotes(SubmitActionParameters.WEB_TEMPLATE));
466: //}
467: //else if (inServletsDir.isFilePresent(nextFileUpperName)) {
468: // //
469: // sacDelGeneralFile.setSubAction(
470: // singleQuotes(SubmitActionParameters.WEB_SERVLET));
471: //}
472: else {
473: throw UnexpectedSystemException.unknownState();
474: }
475: //
476: String textGif = "<img src=\"" + textGifImage + "\"/>";
477: String delFile = padNbsp(1)
478: + createStaticImage(IMAGE__DELETE,
479: ConsolePageParameters.GIF_DELETE,
480: getImageAttrs(sacDelGeneralFile), null);
481: // "<img src=\"" + ConsolePageParameters.GIF_DELETE
482: // + "\" onclick=\"" + sacDelGeneralFile.submitActionCall()
483: // + "\" onmouseover=\"this.style.cursor = 'pointer';"
484: // + "\" onmouseout=\"this.style.cursor = 'default';"
485: // + "\" alt=\"Delete"
486: // + "\"/>";
487: simpleAndPrint(padNbsp((2 * inCurrentDir.size()) + 2)
488: + textGif + padNbsp(1) + nextFile.getName()
489: + delFile + editTextFile + "<br/>");
490: //
491: //
492: //
493: localCps.popToggleLink();
494: }
495: //
496: //
497: //
498: endEnclosingTableAndRowAndCell();
499: }
500:
501: public final static void initializeEditWebPage(
502: SubmitActionContext inSac, boolean inUseQuotes,
503: String inAppName, String inDirName, String inFileName) {
504: //
505: inSac
506: .setGoToPage(ConsolePageParameters.SERVLET_DEVELOP_WEB_PAGE);
507: //
508: inSac.addAction(ConsoleParameterContext.FIRST_INPUT,
509: singleQuotes(SubmitActionParameters.OPEN, inUseQuotes));
510: //
511: inSac.addParameter(ConsoleParameterContext.FIRST_INPUT,
512: singleQuotes(SubmitActionParameters.USER, inUseQuotes));
513: inSac.addParameter(ConsoleParameterContext.SECOND_INPUT,
514: inAppName);
515: inSac.addParameter(ConsoleParameterContext.THIRD_INPUT,
516: singleQuotes(SubmitActionParameters.WEB_PAGE,
517: inUseQuotes));
518: inSac.addParameter(ConsoleParameterContext.FOURTH_INPUT,
519: inDirName);
520: inSac.addParameter(ConsoleParameterContext.FIFTH_INPUT,
521: inFileName);
522: }
523:
524: private final static void addDirNames(
525: VirtualFileSystemHolder inVsd, HashMap inMap) {
526:
527: if (inVsd != null) {
528: ArrayList localDirs = inVsd.getLocalDirectories();
529: for (int i = 0; i < localDirs.size(); i++) {
530: VirtualFileSystemDirectory nextDir = (VirtualFileSystemDirectory) localDirs
531: .get(i);
532: String nextUpperName = nextDir.getName().toUpperCase();
533: if (!inMap.containsKey(nextUpperName)) {
534: inMap.put(nextUpperName, nextDir.getName());
535: }
536: }
537: }
538: }
539:
540: private final static void addFiles(VirtualFileSystemHolder inVsd,
541: HashMap inMap) {
542:
543: if (inVsd != null) {
544: ArrayList localFiles = inVsd.getLocalFiles();
545: for (int i = 0; i < localFiles.size(); i++) {
546: VirtualFileSystemFile nextFile = (VirtualFileSystemFile) localFiles
547: .get(i);
548: if (!inMap
549: .containsKey(nextFile.getName().toUpperCase())) {
550: inMap.put(nextFile.getName().toUpperCase(),
551: nextFile);
552: } else {
553: throw new UnexpectedSystemException("File '"
554: + nextFile.getName() + "' Already Present");
555: }
556: }
557: }
558: }
559:
560: private final static VirtualFileSystemDirectory getDirOrNull(
561: VirtualFileSystemHolder inDir, String inName) {
562:
563: VirtualFileSystemDirectory outValue = null;
564:
565: if (inDir != null) {
566: if (inDir.isDirectoryPresent(inName)) {
567: outValue = inDir.getDirectory(inName);
568: }
569: }
570:
571: return outValue;
572: }
573: //private final static boolean isTextFile(String inName) {
574: //
575: // boolean outValue = false;
576: //
577: // int lastPeriod = inName.lastIndexOf(".");
578: //
579: // if (lastPeriod != -1) {
580: // String fileExtension = inName.substring(lastPeriod + 1);
581: // String textFileExtensions[] = new String[]{
582: // "bat", "html", "htm", "xml", "txt"};
583: // for (int i = 0; i < textFileExtensions.length; i++) {
584: // outValue |= fileExtension.equals(textFileExtensions[i]);
585: // }
586: // }
587: //
588: // return outValue;
589: //}
590:
591: }
|