001: package com.ice.jcvsweb.action;
002:
003: import java.awt.Dimension;
004: import java.io.File;
005: import java.io.IOException;
006: import java.util.ArrayList;
007:
008: import javax.servlet.ServletConfig;
009: import javax.servlet.ServletContext;
010: import javax.servlet.ServletException;
011: import javax.servlet.http.HttpServlet;
012: import javax.servlet.http.HttpServletRequest;
013: import javax.servlet.http.HttpServletResponse;
014: import javax.servlet.http.HttpSession;
015:
016: import org.apache.struts.action.ActionError;
017: import org.apache.struts.action.ActionErrors;
018: import org.apache.struts.action.ActionForm;
019: import org.apache.struts.action.ActionForward;
020: import org.apache.struts.action.ActionMapping;
021:
022: import com.ice.jcvsweb.bean.JCVSUser;
023: import com.ice.jcvsweb.bean.JCVSError;
024: import com.ice.jcvsweb.bean.JCVSConfiguration;
025: import com.ice.jcvsweb.form.EditConfLocForm;
026: import com.ice.jcvsweb.helper.ContextHelper;
027: import com.ice.jcvsweb.manager.JCVSUserManager;
028: import com.ice.jcvsweb.manager.JCVSConfigManager;
029: import com.ice.jcvsweb.manager.JCVSPermManager;
030: import com.ice.jcvsweb.manager.JCVSProjectManager;
031:
032: public class SaveConfigLocation extends JCVSAction {
033: public ActionForward execute(ActionMapping mapping,
034: ActionForm form, HttpServletRequest request,
035: HttpServletResponse response) throws Exception {
036: ActionForward result = null;
037: String forwardName = "failure";
038: HttpSession session = request.getSession();
039: ServletContext ctx = session.getServletContext();
040: JCVSUser user = this .establishUser(request);
041: JCVSPermManager permMgr = this .getPermissionManager(ctx);
042: JCVSProjectManager projectMgr = this .getProjectManager(ctx);
043: JCVSUserManager userMgr = this .getUserManager(ctx);
044: JCVSConfigManager configMgr = this .getConfigManager(ctx);
045:
046: EditConfLocForm confLocForm = (EditConfLocForm) form;
047:
048: if (user == null || !user.getIsAdmin()) {
049: forwardName = "notallowed";
050: this .setReasonMessage(request,
051: "Only the site administrator has the authority to "
052: + "edit the site configuration.");
053: } else if (confLocForm != null) {
054: try {
055: String locStr = confLocForm.getConfigLocation();
056:
057: String locPath = ContextHelper.getRealAbsolutePath(ctx,
058: locStr);
059:
060: File locF = new File(locPath);
061: if (!locF.exists()) {
062: if (!locF.mkdirs())
063: throw new IOException("could not create path '"
064: + locPath + "'");
065: }
066:
067: configMgr.setConfigLocation(ctx, locStr);
068:
069: // Clear the cache to cause references to reload.
070: userMgr.clearCache();
071:
072: // If there is no existing user configuration, ensure
073: // the directories and the special user definitions.
074: userMgr.ensureInitialState();
075:
076: // Clear cache, causing all future references to projects
077: // to reload the projects anew.
078: projectMgr.clearCache();
079:
080: // If no permissions in new location, save current
081: // permissions there. Then reloads permissions file.
082: permMgr.ensureInitialState();
083:
084: request.setAttribute("jcvsConfig", configMgr
085: .getConfiguration());
086: this .setEditMode(request, true);
087: forwardName = "success";
088: } catch (IOException ex) {
089: JCVSError err = new JCVSError();
090: err.setException(ex);
091: err.setTitle("Error saving configuration location.");
092: err
093: .setShortMessage("An error occurred while saving the configuratoin location.");
094: this.postAndLogError(request, err);
095: }
096: }
097:
098: return mapping.findForward(forwardName);
099: }
100:
101: }
|