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.web.file;
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.files.VirtualFileSystemFile;
017: import org.jfolder.common.files.VirtualFileSystemHolder;
018: import org.jfolder.common.utils.misc.MiscHelper;
019: import org.jfolder.common.utils.web.ParameterSet;
020: import org.jfolder.common.web.template.ConsoleParameterContext;
021: import org.jfolder.common.web.template.SubmitActionContext;
022: import org.jfolder.common.web.template.SubmitActionParameters;
023: import org.jfolder.console.base.BaseConsoleServlet;
024: import org.jfolder.console.base.ConsolePageContext;
025: import org.jfolder.console.base.ConsolePageSession;
026: import org.jfolder.project.model.ProjectSystem;
027: import org.jfolder.security.model.UserHolder;
028: import org.jfolder.security.model.UserIdentity;
029:
030: //other classes
031:
032: public class EditTextFilePageServlet extends BaseConsoleServlet {
033:
034: public EditTextFilePageServlet() {
035: }
036:
037: protected boolean checkAccess(ConsolePageSession inCps)
038: throws IOException, ServletException {
039:
040: boolean outValue = false;
041:
042: outValue = (inCps.isDeveloper());
043:
044: return outValue;
045: }
046:
047: public ConsolePageContext process(ConsolePageSession inCps,
048: UserHolder inUser, ParameterSet inPs,
049: SubmitActionContext inSac) throws IOException,
050: ServletException {
051:
052: //
053: ConsolePageContext outValue = null;
054:
055: if (inSac.isAction(SubmitActionParameters.OPEN)) {
056: String appType = inSac
057: .getParameter(ConsoleParameterContext.FIRST_INPUT);
058: String appName = inSac
059: .getParameter(ConsoleParameterContext.SECOND_INPUT);
060: String fileType = inSac
061: .getParameter(ConsoleParameterContext.THIRD_INPUT);
062: String directory = inSac
063: .getParameter(ConsoleParameterContext.FOURTH_INPUT);
064: String fileName = inSac
065: .getParameter(ConsoleParameterContext.FIFTH_INPUT);
066: inCps.setCurrentApplication(appType, appName, fileType,
067: directory, fileName, null, null, null);
068: } else if (inSac.isAction(SubmitActionParameters.DO_NOTHING)) {
069: } else if (inSac.isAction(SubmitActionParameters.SAVE)) {
070: //
071: String content = inSac
072: .getParameter(ConsoleParameterContext.FIRST_INPUT);
073: //
074: String appType = inCps.getCurrentApplicationType();
075: String appName = inCps.getCurrentApplicationName();
076: String fileType = inCps.getCurrentApplicationWebDocType();
077: String directory = inCps
078: .getCurrentApplicationWebDocDirectory();
079: String fileName = inCps.getCurrentApplicationWebDocFile();
080: //
081: ProjectSystem projectSystem = inCps
082: .getCurrentApplicationProjectSystem();
083: //
084: VirtualFileSystemHolder fileVsh = projectSystem
085: .getWebDocs();
086: //
087: VirtualFileSystemHolder localVsh = fileVsh
088: .getOrCreateAbsoluteDirectory(directory);
089: //
090: //MiscHelper.println("EditTextFilePageServlet beforeLength = "
091: // + localVsh.getFile(fileName).getContent().length);
092: localVsh.updateFile(fileName, MiscHelper
093: .fromStringToBytes(content));
094: //MiscHelper.println("EditTextFilePageServlet afterLength = "
095: // + localVsh.getFile(fileName).getContent().length);
096: //
097: UserIdentity ui = inCps.getUserHolder().getUserIdentity();
098: saveProjectSystem(projectSystem, ui);
099: } else {
100: throw UnexpectedSystemException.unknownState();
101: }
102:
103: outValue = EditTextFilePageContext.newInstance(inCps);
104:
105: return outValue;
106:
107: }
108:
109: }
|