001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. The ASF licenses this file to You
004: * under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License. For additional information regarding
015: * copyright in this work, please see the NOTICE file in the top level
016: * directory of this distribution.
017: */
018: /*
019: * Created on Oct 21, 2003
020: */
021: package org.apache.roller.ui.authoring.struts.actions;
022:
023: import javax.servlet.http.HttpServletRequest;
024: import javax.servlet.http.HttpServletResponse;
025:
026: import org.apache.struts.action.Action;
027: import org.apache.struts.action.ActionForm;
028: import org.apache.struts.action.ActionForward;
029: import org.apache.struts.action.ActionMapping;
030: import org.apache.roller.business.BookmarkManager;
031: import org.apache.roller.business.RollerFactory;
032: import org.apache.roller.pojos.FolderData;
033: import org.apache.roller.ui.core.BasePageModel;
034: import org.apache.roller.ui.core.RollerRequest;
035: import org.apache.roller.ui.authoring.struts.formbeans.FolderFormEx;
036: import org.apache.roller.ui.core.RequestConstants;
037:
038: /**
039: * @struts.action path="/roller-ui/authoring/folderEdit" name="folderFormEx" validate="false"
040: * @struts.action-forward name="FolderForm" path=".FolderForm"
041: *
042: * @author Dave Johnson
043: */
044: public class FolderEditAction extends Action {
045: public ActionForward execute(ActionMapping mapping,
046: ActionForm actionForm, HttpServletRequest request,
047: HttpServletResponse response) throws Exception {
048: RollerRequest rreq = RollerRequest.getRollerRequest(request);
049: BookmarkManager bmgr = RollerFactory.getRoller()
050: .getBookmarkManager();
051: FolderFormEx form = (FolderFormEx) actionForm;
052:
053: FolderData parentFolder = null;
054: if (null != rreq.getFolder()
055: && null == request.getParameter("correct")) {
056: // If request specifies folder and we are not correcting an
057: // already submitted form then load that folder into the form.
058: request.setAttribute("state", "edit");
059:
060: FolderData fd = rreq.getFolder();
061: form.copyFrom(fd, request.getLocale());
062: parentFolder = fd.getParent();
063:
064: BasePageModel pageModel = new BasePageModel(
065: "folderForm.add.title", request, response, mapping);
066: pageModel.setWebsite(parentFolder.getWebsite());
067: request.setAttribute("model", pageModel);
068: } else if (null != request.getParameter("correct")) {
069: // We are correcting a previously submtted form.
070: request.setAttribute("state", "correcting");
071:
072: String parentId = request
073: .getParameter(RequestConstants.PARENT_ID);
074: parentFolder = bmgr.getFolder(parentId);
075:
076: BasePageModel pageModel = new BasePageModel(
077: "folderForm.correct.title", request, response,
078: mapping);
079: pageModel.setWebsite(parentFolder.getWebsite());
080: request.setAttribute("model", pageModel);
081: } else {
082: // We are adding a new bookmark
083: request.setAttribute("state", "add");
084:
085: String parentId = request
086: .getParameter(RequestConstants.PARENT_ID);
087: parentFolder = bmgr.getFolder(parentId);
088:
089: BasePageModel pageModel = new BasePageModel(
090: "folderForm.add.title", request, response, mapping);
091: pageModel.setWebsite(parentFolder.getWebsite());
092: request.setAttribute("model", pageModel);
093: }
094:
095: request.setAttribute(RequestConstants.PARENT_ID, parentFolder
096: .getId());
097: request.setAttribute("parentFolder", parentFolder);
098:
099: return mapping.findForward("FolderForm");
100: }
101:
102: }
|