01: /*
02: * JFolder, Copyright 2001-2006 Gary Steinmetz
03: *
04: * Distributable under LGPL license.
05: * See terms of license at gnu.org.
06: */
07:
08: package org.jfolder.console.web.admin.macro.execute;
09:
10: //base classes
11: import java.io.IOException;
12: import java.io.OutputStream;
13: import javax.servlet.ServletException;
14:
15: //project specific classes
16: import org.jfolder.common.tagging.ConceptRollupTag;
17: import org.jfolder.common.tagging.RootConceptTagHolder;
18: import org.jfolder.common.utils.misc.MiscHelper;
19: import org.jfolder.common.utils.web.ParameterSet;
20: import org.jfolder.common.web.template.ConsoleParameterContext;
21: import org.jfolder.common.web.template.SubmitActionContext;
22: import org.jfolder.common.web.template.SubmitActionParameters;
23: import org.jfolder.console.base.BaseConsoleServlet;
24: import org.jfolder.console.base.ConsolePageContext;
25: import org.jfolder.console.base.ConsolePageSession;
26: import org.jfolder.security.model.UserHolder;
27:
28: //other classes
29:
30: public class ConsoleMacroExecuteServlet extends BaseConsoleServlet {
31:
32: public ConsoleMacroExecuteServlet() {
33: }
34:
35: protected boolean checkAccess(ConsolePageSession inCps)
36: throws IOException, ServletException {
37:
38: boolean outValue = false;
39:
40: outValue = (inCps.isAdministrator());
41:
42: return outValue;
43: }
44:
45: public ConsolePageContext process(ConsolePageSession inCps,
46: UserHolder inUser, ParameterSet inPs,
47: SubmitActionContext inSac) throws IOException,
48: ServletException {
49:
50: //
51: ConsolePageContext outValue = null;
52:
53: outValue = ConsoleMacroExecuteContext.newInstance(inCps);
54:
55: if (inSac.isAction(SubmitActionParameters.OPEN)) {
56: //
57: inCps.setCurrentMacro(null);
58: inCps.setMacroStateAsInactive();
59: } else if (inSac.isAction(SubmitActionParameters.LOAD)) {
60: //
61: String uploadParameter = inSac
62: .getParameter(ConsoleParameterContext.FIRST_INPUT);
63: byte uploadContent[] = inPs
64: .getParameterAsUpload(uploadParameter);
65: RootConceptTagHolder macroRcth = ConceptRollupTag
66: .getRootHolderFromList(uploadContent);
67: //
68: inCps.setCurrentMacro(macroRcth);
69: } else if (inSac
70: .isAction(SubmitActionParameters.CREATE_PET_STORE)) {
71: //
72: String database = inSac
73: .getParameter(ConsoleParameterContext.FIRST_INPUT);
74: //
75: RootConceptTagHolder petStoreMacro = PetStoreCreator
76: .getPetStoreMacro(database);
77: //
78: //
79: byte macroContent[] = ConceptRollupTag.getRollupFromList(
80: petStoreMacro, null);
81: OutputStream os = outValue.getOutputStream();
82: os.write(macroContent, 0, macroContent.length);
83: os.flush();
84: os.close();
85: //String appName = inSac.getFirstParameter();
86: outValue.setOutputText(false);
87: outValue.setOutputFileName(MiscHelper.literalReplace(
88: "PetStoreMacro.zip", "/", "_"));
89: outValue.setMimeType("application/download");
90: } else {
91: inSac.unknownAction();
92: }
93:
94: return outValue;
95: }
96: }
|