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.page;
009:
010: //base classes
011: import java.io.ByteArrayInputStream;
012: import java.io.IOException;
013: import java.io.OutputStream;
014: import java.util.ArrayList;
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.SimpleVirtualFileSystemProperties;
022: import org.jfolder.common.files.VirtualFileSystemFile;
023: import org.jfolder.common.files.VirtualFileSystemHolder;
024: import org.jfolder.common.tagging.ConceptRollupTag;
025: import org.jfolder.common.tagging.ConceptTag;
026: import org.jfolder.common.tagging.ConceptTagCharacteristic;
027: import org.jfolder.common.tagging.ConceptTagCharacteristicHolder;
028: import org.jfolder.common.tagging.ConceptTagConstraintHolder;
029: import org.jfolder.common.tagging.ConceptTagPreferences;
030: import org.jfolder.common.tagging.ConceptTagSetContext;
031: import org.jfolder.common.tagging.ConceptTagSetHolder;
032: import org.jfolder.common.tagging.RootConceptTagHolder;
033: import org.jfolder.common.utils.misc.MiscHelper;
034: import org.jfolder.common.utils.web.ParameterSet;
035: import org.jfolder.common.utils.xml.XMLHelper;
036: import org.jfolder.common.web.template.ConsoleParameterContext;
037: import org.jfolder.common.web.template.PageSetupContext;
038: import org.jfolder.common.web.template.SubmitActionContext;
039: import org.jfolder.common.web.template.SubmitActionParameters;
040: import org.jfolder.console.base.BaseRcthStudioServlet;
041: import org.jfolder.console.base.BaseRcthStudioSettings;
042: import org.jfolder.console.base.ConsolePageContext;
043: import org.jfolder.console.base.ConsolePageSession;
044: import org.jfolder.project.model.ProjectSystem;
045: import org.jfolder.security.model.UserHolder;
046: import org.jfolder.security.model.UserIdentity;
047: import org.jfolder.web.page.RootWebPageTag;
048:
049: //other classes
050:
051: public class DevelopWebPageServlet extends BaseRcthStudioServlet {
052:
053: public DevelopWebPageServlet() {
054: }
055:
056: //protected boolean checkAccess(UserHolder inUser) {
057: //
058: // boolean outValue = false;
059: //
060: // UserAuthorizationAndAccessControl uaaac =
061: // UserHelper.getUserAuthorizationAndAccessControl();
062: //
063: // outValue = isDeveloper(uaaac, inUser);
064: //
065: // return outValue;
066: //}
067:
068: public ConsolePageContext subProcess(ConsolePageSession inCps,
069: UserHolder inUser, ParameterSet inPs,
070: SubmitActionContext inSac, BaseRcthStudioSettings inBrss)
071: throws IOException {
072:
073: DevelopWebPageContext outValue = null;
074:
075: //String currentHighlightHandle = null;
076: //
077: //Boolean currentTreeDeleteNotAdd = null;
078: //String currentTreeHandle = null;
079:
080: if (inSac.isAction(SubmitActionParameters.OPEN)) {
081: String appType = inSac
082: .getParameter(ConsoleParameterContext.FIRST_INPUT);
083: String appName = inSac
084: .getParameter(ConsoleParameterContext.SECOND_INPUT);
085: String fileType = inSac
086: .getParameter(ConsoleParameterContext.THIRD_INPUT);
087: String directory = inSac
088: .getParameter(ConsoleParameterContext.FOURTH_INPUT);
089: String fileName = inSac
090: .getParameter(ConsoleParameterContext.FIFTH_INPUT);
091: //
092: inCps.getMessageHolder().setInformationHeader("Welcome");
093: //
094: ProjectSystem projectSystem = inCps.getProjectSystem(
095: appType, appName);
096: //
097: VirtualFileSystemHolder pageVsh = projectSystem
098: .getWebDocs();
099: //
100: VirtualFileSystemHolder localVsh = pageVsh
101: .getOrCreateAbsoluteDirectory(directory);
102: //
103: VirtualFileSystemFile localPage = localVsh
104: .getFile(fileName);
105: byte pageContent[] = localPage.getContent();
106: //
107: RootConceptTagHolder webPageRcth = ConceptRollupTag
108: .getRootHolderFromList(pageContent);
109: //
110: inCps.setCurrentApplication(appType, appName, fileType,
111: directory, fileName, webPageRcth, null, null);
112: //
113: inCps.validateCurrentApplicationRootHolder();
114: //
115: }
116: //else if (inSac.isAction(SubmitActionParameters.DO_NOTHING)) {
117: //}
118: else if (inSac.isAction(SubmitActionParameters.SAVE)) {
119: //
120: //
121: accountForRcthTextChanges(inCps, inPs);
122: //
123: inCps.validateCurrentApplicationRootHolder();
124: //
125: //
126: //
127: RootConceptTagHolder localRcth = inCps
128: .getCurrentApplicationRootHolder();
129: //
130: byte localRcthContent[] = ConceptRollupTag
131: .getRollupFromList(localRcth, null);
132:
133: ProjectSystem ps = inCps
134: .getCurrentApplicationProjectSystem();
135: //
136: //VirtualFileSystemHolder pageVsh = projectSystem.getWebDocs();
137: //
138: VirtualFileSystemHolder localWebDocsVsh = ps
139: .getWebDocs()
140: .getOrCreateAbsoluteDirectory(
141: inCps
142: .getCurrentApplicationWebDocDirectory());
143: localWebDocsVsh.updateFile(inCps
144: .getCurrentApplicationWebDocFile(),
145: localRcthContent);
146: //
147:
148: VirtualFileSystemHolder localWebDocsPropertiesVsh = ps
149: .getWebDocsProperties()
150: .getOrCreateAbsoluteDirectory(
151: inCps
152: .getCurrentApplicationWebDocDirectory());
153: //
154: RootWebPageTag rwpt = ((RootWebPageTag) localRcth
155: .getFirstChildConceptTag());
156:
157: //
158: SimpleVirtualFileSystemProperties svfsp = null;
159: if (rwpt.isBinaryOutput()) {
160: svfsp = ps.getWebDocProperty(false, true, false, false,
161: false, null);
162: } else if (rwpt.isMacroGroup()) {
163: svfsp = ps.getWebDocProperty(false, false, false, true,
164: false, rwpt.getWebPageTagMacroGroup());
165: } else if (rwpt.isTemplate()) {
166: svfsp = ps.getWebDocProperty(false, false, false,
167: false, true, null);
168: } else {
169: svfsp = ps.getWebDocProperty(true, false, false, false,
170: false, null);
171: }
172: //
173: localWebDocsPropertiesVsh.updateFile(inCps
174: .getCurrentApplicationWebDocFile(), svfsp
175: .toByteArray());
176: //MiscHelper.println(
177: // "DevWebPageServ Macro/Template Save Not Impl");
178: //
179: //byte localOrigContent[] =
180: // localVsh.getFile(
181: // inCs.getCurrentApplicationWebDocFile()).getContent();
182: //RootConceptTagHolder localOrigRcth =
183: // ConceptRollupTag.getRootHolderFromList(localOrigContent);
184: //MiscHelper.println("DevWebPagSer dir = "
185: // + inCs.getCurrentApplicationWebDocDirectory());
186: //MiscHelper.println("DevWebPagSer file = "
187: // + inCs.getCurrentApplicationWebDocFile());
188: //MiscHelper.println("DevWebPagSer origContentLength = "
189: // + localOrigContent.length);
190: //MiscHelper.println("DevWebPagSer currContentLength = "
191: // + localRcthContent.length);
192: //MiscHelper.println("DevWebPagSer origContent = "
193: // + localOrigRcth.getXMLRepresentation());
194: //MiscHelper.println("DevWebPagSer currContent = "
195: //+ inCs.getCurrentApplicationRootHolder().getXMLRepresentation());
196: //
197: //
198:
199: //
200: UserIdentity ui = inCps.getUserHolder().getUserIdentity();
201: saveProjectSystem(ps, ui);
202: } else if (commonActions(inCps, inUser, inPs, inSac, inBrss)) {
203: //
204: } else {
205: inSac.unknownAction();
206: }
207:
208: //
209: outValue = DevelopWebPageContext.newInstance(inCps);
210: //
211: if (inBrss.isRcthBinaryOutputPresent()) {
212: //byte candidateContent[] = ConceptRollupTag.getRollupFromList(
213: // candidateRcth, null);
214: byte content[] = inBrss.getRcthBinaryOutputContent();
215: OutputStream os = outValue.getOutputStream();
216: os.write(content, 0, content.length);
217: os.flush();
218: os.close();
219: //String appName = inSac.getFirstParameter();
220: outValue.setOutputText(false);
221: outValue.setOutputFileName(inBrss
222: .getRcthBinaryOutputFileName());
223: outValue.setMimeType(inBrss.getRcthBinaryOutputMimeType());
224: }
225:
226: return outValue;
227: }
228:
229: }
|