You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by sn...@apache.org on 2006/05/02 00:23:34 UTC
svn commit: r398712 [23/32] - in /incubator/roller/trunk/src/org/apache: ./
roller/ roller/business/ roller/business/hibernate/
roller/business/referrers/ roller/business/runnable/
roller/business/search/ roller/business/search/operations/ roller/busin...
Added: incubator/roller/trunk/src/org/apache/roller/presentation/weblog/actions/CategoryDeleteAction.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/apache/roller/presentation/weblog/actions/CategoryDeleteAction.java?rev=398712&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/presentation/weblog/actions/CategoryDeleteAction.java (added)
+++ incubator/roller/trunk/src/org/apache/roller/presentation/weblog/actions/CategoryDeleteAction.java Mon May 1 15:23:02 2006
@@ -0,0 +1,143 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+/*
+ * Created on Oct 21, 2003
+ */
+package org.apache.roller.presentation.weblog.actions;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.struts.action.Action;
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionForward;
+import org.apache.struts.action.ActionMapping;
+import org.apache.roller.RollerException;
+import org.apache.roller.model.RollerFactory;
+import org.apache.roller.model.WeblogManager;
+import org.apache.roller.pojos.WeblogCategoryData;
+import org.apache.roller.presentation.RollerRequest;
+import org.apache.roller.presentation.RollerSession;
+import org.apache.roller.presentation.cache.CacheManager;
+import org.apache.roller.presentation.weblog.formbeans.CategoryDeleteForm;
+
+/**
+ * @struts.action path="/editor/categoryDelete" name="categoryDeleteForm"
+ * @struts.action-forward name="CategoryDeleteOK" path=".CategoryDeleteOK"
+ *
+ * @author Dave Johnson
+ */
+public class CategoryDeleteAction extends Action
+{
+ public ActionForward execute(
+ ActionMapping mapping,
+ ActionForm actionForm,
+ HttpServletRequest request,
+ HttpServletResponse response)
+ throws Exception
+ {
+ ActionForward forward = mapping.findForward("categories");
+ CategoryDeleteForm form = (CategoryDeleteForm)actionForm;
+ WeblogManager wmgr = RollerFactory.getRoller().getWeblogManager();
+
+ String catid = request.getParameter(RollerRequest.WEBLOGCATEGORYID_KEY);
+ WeblogCategoryData catToDelete =
+ wmgr.getWeblogCategory(catid);
+ RollerSession rses = RollerSession.getRollerSession(request);
+ if (rses.isUserAuthorizedToAuthor(catToDelete.getWebsite()))
+ {
+ String returnId = null;
+ if (catToDelete.getParent() != null)
+ {
+ returnId = catToDelete.getParent().getId();
+ }
+ if (form.isDelete() == null)
+ {
+ // Present CategoryDeleteOK? page to user
+ RollerRequest rreq = RollerRequest.getRollerRequest(request);
+ WeblogCategoryData theCat = wmgr.getWeblogCategory(catid);
+ Iterator allCats =
+ wmgr.getWeblogCategories(theCat.getWebsite()).iterator();
+ List destCats = new LinkedList();
+ while (allCats.hasNext())
+ {
+ WeblogCategoryData cat = (WeblogCategoryData)allCats.next();
+ // Allow entries to be moved to any other category except
+ // root and the sub-cats of the category being deleted.
+ if (!cat.getId().equals(catid)
+ && cat.getParent()!=null
+ && !cat.descendentOf(catToDelete)
+ && cat.retrieveWeblogEntries(true).size() < 1)
+ {
+ destCats.add(cat);
+ }
+ }
+ if (destCats.size() > 0)
+ {
+ form.setName(theCat.getName());
+ form.setCategoryId(catid);
+ form.setCats(destCats);
+ form.setInUse(Boolean.valueOf(catToDelete.isInUse()));
+ forward = mapping.findForward("CategoryDeleteOK");
+ }
+ else
+ {
+ // Can't delete last category, send 'em back!
+ if (null != returnId)
+ {
+ request.setAttribute(
+ RollerRequest.WEBLOGCATEGORYID_KEY, returnId);
+ }
+ }
+ }
+ else if (form.isDelete().booleanValue()) {
+
+ // User clicked YES to delete
+ // remove cat to delete
+ wmgr.removeWeblogCategory(catToDelete);
+ RollerFactory.getRoller().flush();
+
+ // notify caches of invalidated object
+ CacheManager.invalidate(catToDelete);
+
+ if (null != returnId) {
+ request.setAttribute(RollerRequest.WEBLOGCATEGORYID_KEY, returnId);
+ }
+ }
+ else
+ {
+ // User clicked NO to delete, do back to categories form
+ if (null != returnId)
+ {
+ request.setAttribute(
+ RollerRequest.WEBLOGCATEGORYID_KEY, returnId);
+ }
+ }
+ }
+ else
+ {
+ forward = mapping.findForward("access-denied");
+ }
+ return forward;
+ }
+
+}
Added: incubator/roller/trunk/src/org/apache/roller/presentation/weblog/actions/CategoryEditAction.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/apache/roller/presentation/weblog/actions/CategoryEditAction.java?rev=398712&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/presentation/weblog/actions/CategoryEditAction.java (added)
+++ incubator/roller/trunk/src/org/apache/roller/presentation/weblog/actions/CategoryEditAction.java Mon May 1 15:23:02 2006
@@ -0,0 +1,120 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+/*
+ * Created on Oct 21, 2003
+ */
+package org.apache.roller.presentation.weblog.actions;
+
+import java.util.LinkedList;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.struts.action.Action;
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionForward;
+import org.apache.struts.action.ActionMapping;
+import org.apache.roller.model.RollerFactory;
+import org.apache.roller.model.WeblogManager;
+import org.apache.roller.pojos.WeblogCategoryData;
+import org.apache.roller.pojos.WebsiteData;
+import org.apache.roller.presentation.BasePageModel;
+import org.apache.roller.presentation.RollerRequest;
+import org.apache.roller.presentation.RollerSession;
+import org.apache.roller.presentation.weblog.formbeans.WeblogCategoryFormEx;
+
+/**
+ * @struts.action path="/editor/categoryEdit" name="weblogCategoryFormEx" validate="false"
+ * @struts.action-forward name="CategoryForm" path=".CategoryForm"
+ *
+ * @author Dave Johnson
+ */
+public class CategoryEditAction extends Action
+{
+ public ActionForward execute(
+ ActionMapping mapping,
+ ActionForm actionForm,
+ HttpServletRequest request,
+ HttpServletResponse response)
+ throws Exception
+ {
+ RollerRequest rreq = RollerRequest.getRollerRequest(request);
+ WeblogManager wmgr = RollerFactory.getRoller().getWeblogManager();
+ WeblogCategoryFormEx form = (WeblogCategoryFormEx)actionForm;
+
+ BasePageModel pageModel = null;
+ WeblogCategoryData parentCat = null;
+ if (null!=rreq.getWeblogCategory() && null==request.getParameter("correct"))
+ {
+ // If request specifies Category and we are not correcting an
+ // already submitted form then load that Category into the form.
+ WeblogCategoryData cd = rreq.getWeblogCategory();
+ form.copyFrom(cd, request.getLocale());
+ request.setAttribute("state","edit");
+
+ parentCat = cd.getParent();
+ pageModel = new BasePageModel(
+ "categoryForm.edit.title", request, response, mapping);
+ pageModel.setWebsite(cd.getWebsite());
+ }
+ else if (null != request.getParameter("correct"))
+ {
+ // We are correcting a previously submtted form.
+ // already submitted form then load that Category into the form.
+ WeblogCategoryData cd = rreq.getWeblogCategory();
+ request.setAttribute("state","correcting");
+
+ parentCat = wmgr.getWeblogCategory(cd.getId());
+ pageModel = new BasePageModel(
+ "categoryForm.correct.title", request, response, mapping);
+ pageModel.setWebsite(cd.getWebsite());
+ }
+ else
+ {
+ // We are adding a new Category
+ request.setAttribute("state","add");
+
+ String pid = request.getParameter(RollerRequest.PARENTID_KEY);
+ parentCat = wmgr.getWeblogCategory(pid);
+ form.setParentId(parentCat.getId());
+
+ pageModel = new BasePageModel(
+ "categoryForm.add.title", request, response, mapping);
+ pageModel.setWebsite(parentCat.getWebsite());
+ }
+
+ // Build cat path for display on page
+ if (null != parentCat)
+ {
+ LinkedList categoryPath = new LinkedList();
+ categoryPath.add(0, parentCat);
+ WeblogCategoryData parent = parentCat.getParent();
+ while (parent != null)
+ {
+ categoryPath.add(0, parent);
+ parent = parent.getParent();
+ }
+ request.setAttribute("parentCategory", parentCat);
+ request.setAttribute("categoryPath", categoryPath);
+ }
+
+ request.setAttribute("model", pageModel);
+ return mapping.findForward("CategoryForm");
+ }
+
+}
Added: incubator/roller/trunk/src/org/apache/roller/presentation/weblog/actions/CategorySaveAction.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/apache/roller/presentation/weblog/actions/CategorySaveAction.java?rev=398712&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/presentation/weblog/actions/CategorySaveAction.java (added)
+++ incubator/roller/trunk/src/org/apache/roller/presentation/weblog/actions/CategorySaveAction.java Mon May 1 15:23:02 2006
@@ -0,0 +1,97 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+/*
+ * Created on Oct 21, 2003
+ */
+package org.apache.roller.presentation.weblog.actions;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.struts.action.Action;
+import org.apache.struts.action.ActionError;
+import org.apache.struts.action.ActionErrors;
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionForward;
+import org.apache.struts.action.ActionMapping;
+import org.apache.roller.model.RollerFactory;
+import org.apache.roller.model.WeblogManager;
+import org.apache.roller.pojos.PermissionsData;
+import org.apache.roller.pojos.WeblogCategoryData;
+import org.apache.roller.presentation.RollerRequest;
+import org.apache.roller.presentation.RollerSession;
+import org.apache.roller.presentation.cache.CacheManager;
+import org.apache.roller.presentation.weblog.formbeans.WeblogCategoryFormEx;
+
+/**
+ * @struts.action path="/editor/categorySave" name="weblogCategoryFormEx"
+ * validate="true" input="/editor/categoryEdit.do"
+ *
+ * @author Dave Johnson
+ */
+public class CategorySaveAction extends Action
+{
+ public ActionForward execute(
+ ActionMapping mapping,
+ ActionForm actionForm,
+ HttpServletRequest request,
+ HttpServletResponse response)
+ throws Exception
+ {
+ ActionForward forward = mapping.findForward("categories");
+ WeblogCategoryFormEx form = (WeblogCategoryFormEx)actionForm;
+ RollerRequest rreq = RollerRequest.getRollerRequest(request);
+ WeblogManager wmgr = RollerFactory.getRoller().getWeblogManager();
+
+ WeblogCategoryData cd = null;
+ if (null != form.getId() && !form.getId().trim().equals(""))
+ {
+ cd = wmgr.getWeblogCategory(form.getId());
+ }
+ else
+ {
+ cd = new WeblogCategoryData();
+ String pid = form.getParentId();
+ WeblogCategoryData parentCat = wmgr.getWeblogCategory(pid);
+ cd.setWebsite(parentCat.getWebsite());
+ cd.setParent(parentCat);
+ }
+
+ RollerSession rses = RollerSession.getRollerSession(request);
+ if (cd.getWebsite().hasUserPermissions(
+ rses.getAuthenticatedUser(), PermissionsData.AUTHOR))
+ {
+ form.copyTo(cd, request.getLocale());
+ wmgr.saveWeblogCategory(cd);
+ RollerFactory.getRoller().flush();
+
+ // notify caches of object invalidation
+ CacheManager.invalidate(cd);
+ }
+ else
+ {
+ ActionErrors errors = new ActionErrors();
+ errors.add(null, new ActionError("error.permissions.deniedSave"));
+ saveErrors(request, errors);
+ forward = mapping.findForward("access-denied");
+ }
+ request.setAttribute(
+ RollerRequest.WEBLOGCATEGORYID_KEY, cd.getParent().getId());
+ return forward;
+ }
+}
Added: incubator/roller/trunk/src/org/apache/roller/presentation/weblog/actions/CommentManagementAction.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/apache/roller/presentation/weblog/actions/CommentManagementAction.java?rev=398712&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/presentation/weblog/actions/CommentManagementAction.java (added)
+++ incubator/roller/trunk/src/org/apache/roller/presentation/weblog/actions/CommentManagementAction.java Mon May 1 15:23:02 2006
@@ -0,0 +1,390 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.roller.presentation.weblog.actions;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.struts.action.ActionErrors;
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionForward;
+import org.apache.struts.action.ActionMapping;
+import org.apache.struts.action.ActionMessage;
+import org.apache.struts.action.ActionMessages;
+import org.apache.struts.actions.DispatchAction;
+import org.apache.struts.util.RequestUtils;
+import org.apache.roller.RollerException;
+import org.apache.roller.model.Roller;
+import org.apache.roller.model.RollerFactory;
+import org.apache.roller.model.WeblogManager;
+import org.apache.roller.pojos.CommentData;
+import org.apache.roller.pojos.WeblogEntryData;
+import org.apache.roller.presentation.BasePageModel;
+import org.apache.roller.presentation.RollerContext;
+import org.apache.roller.presentation.RollerRequest;
+import org.apache.roller.presentation.RollerSession;
+import org.apache.roller.presentation.cache.CacheManager;
+import org.apache.roller.presentation.servlets.CommentServlet;
+import org.apache.roller.presentation.weblog.formbeans.CommentManagementForm;
+import org.apache.roller.util.Utilities;
+
+/**
+ * Action for quering, approving, marking as spam and deleting comments.
+ *
+ * @struts.action path="/editor/commentManagement" name="commentManagementForm"
+ * scope="request" parameter="method"
+ *
+ * @struts.action path="/editor/commentQuery" name="commentQueryForm"
+ * scope="request" parameter="method"
+ *
+ * @struts.action path="/admin/commentManagement" name="commentManagementForm"
+ * scope="request" parameter="method"
+ *
+ * @struts.action path="/admin/commentQuery" name="commentQueryForm"
+ * scope="request" parameter="method"
+ *
+ * @struts.action-forward name="commentManagement.page" path=".CommentManagement"
+ * @struts.action-forward name="commentManagementGlobal.page" path=".CommentManagementGlobal"
+ */
+public final class CommentManagementAction extends DispatchAction {
+
+ private static Log logger =
+ LogFactory.getFactory().getInstance(CommentManagementAction.class);
+
+ public ActionForward query(
+ ActionMapping mapping,
+ ActionForm actionForm,
+ HttpServletRequest request,
+ HttpServletResponse response)
+ throws IOException, ServletException, RollerException {
+
+ CommentManagementForm queryForm = (CommentManagementForm)actionForm;
+ RollerRequest rreq = RollerRequest.getRollerRequest(request);
+ RollerSession rses = RollerSession.getRollerSession(request);
+
+ if (rreq.getWeblogEntry() != null) {
+ queryForm.setEntryid(rreq.getWeblogEntry().getId());
+ queryForm.setWeblog(rreq.getWeblogEntry().getWebsite().getHandle());
+ }
+ else if (rreq.getWebsite() != null) {
+ queryForm.setWeblog(rreq.getWebsite().getHandle());
+ }
+ request.setAttribute("model", new CommentManagementPageModel(
+ "commentManagement.title", request, response, mapping, queryForm));
+ if (request.getAttribute("commentManagementForm") == null) {
+ request.setAttribute("commentManagementForm", actionForm);
+ }
+
+ // Ensure user is authorized to view comments in weblog
+ if (rreq.getWebsite() != null && rses.isUserAuthorized(rreq.getWebsite())) {
+ return mapping.findForward("commentManagement.page");
+ }
+ // And ensure only global admins can see all comments
+ else if (rses.isGlobalAdminUser()) {
+ return mapping.findForward("commentManagementGlobal.page");
+ }
+ else {
+ return mapping.findForward("access-denied");
+ }
+ }
+
+ public ActionForward update(
+ ActionMapping mapping,
+ ActionForm actionForm,
+ HttpServletRequest request,
+ HttpServletResponse response)
+ throws IOException, ServletException, RollerException {
+
+ CommentManagementForm queryForm = (CommentManagementForm)actionForm;
+ RollerRequest rreq = RollerRequest.getRollerRequest(request);
+ if (rreq.getWeblogEntry() != null) {
+ queryForm.setEntryid(rreq.getWeblogEntry().getId());
+ queryForm.setWeblog(rreq.getWeblogEntry().getWebsite().getHandle());
+ }
+ else if (rreq.getWebsite() != null) {
+ queryForm.setWeblog(rreq.getWebsite().getHandle());
+ }
+ RollerSession rses = RollerSession.getRollerSession(request);
+ try {
+ if (rses.isGlobalAdminUser()
+ || (rreq.getWebsite()!=null && rses.isUserAuthorizedToAuthor(rreq.getWebsite())) ) {
+ WeblogManager mgr= RollerFactory.getRoller().getWeblogManager();
+
+ // delete all comments with delete box checked
+ CommentData deleteComment = null;
+ String[] deleteIds = queryForm.getDeleteComments();
+ List deletedList = Arrays.asList(deleteIds);
+ if (deleteIds != null && deleteIds.length > 0) {
+ for(int j=0; j < deleteIds.length; j++) {
+ deleteComment = mgr.getComment(deleteIds[j]);
+
+ mgr.removeComment(deleteComment);
+ }
+ }
+
+ // Collect comments approved for first time, so we can send
+ // out comment approved notifications later
+ List approvedComments = new ArrayList();
+
+ // loop through IDs of all comments displayed on page
+ String[] ids = Utilities.stringToStringArray(queryForm.getIds(),",");
+ List flushList = new ArrayList();
+ for (int i=0; i<ids.length; i++) {
+ if (deletedList.contains(ids[i])) continue;
+ CommentData comment = mgr.getComment(ids[i]);
+
+ // apply spam checkbox
+ List spamIds = Arrays.asList(queryForm.getSpamComments());
+ if (spamIds.contains(ids[i])) {
+ comment.setSpam(Boolean.TRUE);
+ } else {
+ comment.setSpam(Boolean.FALSE);
+ }
+
+ // Only participate in comment review workflow if we're
+ // working within one specfic weblog. Global admins should
+ // be able to mark-as-spam and delete comments without
+ // interfering with moderation by bloggers.
+ if (rreq.getWebsite() != null) {
+
+ // all comments reviewed, so they're no longer pending
+ if (comment.getPending() != null && comment.getPending().booleanValue()) {
+ comment.setPending(Boolean.FALSE);
+ approvedComments.add(comment);
+ }
+
+ // apply pending checkbox
+ List approvedIds =
+ Arrays.asList(queryForm.getApprovedComments());
+ if (approvedIds.contains(ids[i])) {
+ comment.setApproved(Boolean.TRUE);
+
+ } else {
+ comment.setApproved(Boolean.FALSE);
+ }
+ }
+ mgr.saveComment(comment);
+ flushList.add(comment);
+ }
+
+ RollerFactory.getRoller().flush();
+ for (Iterator comments=flushList.iterator(); comments.hasNext();) {
+ CacheManager.invalidate((CommentData)comments.next());
+ }
+
+ sendCommentNotifications(request, approvedComments);
+
+ ActionMessages msgs = new ActionMessages();
+ msgs.add(ActionMessages.GLOBAL_MESSAGE,
+ new ActionMessage("commentManagement.updateSuccess"));
+ saveMessages(request, msgs);
+ }
+ } catch (Exception e) {
+ ActionMessages errors = new ActionMessages();
+ errors.add(ActionErrors.GLOBAL_MESSAGE,
+ new ActionMessage("commentManagement.updateError",e.toString()));
+ saveErrors(request, errors);
+ logger.error("ERROR updating comments", e);
+ }
+ CommentManagementPageModel model = new CommentManagementPageModel(
+ "commentManagement.title", request, response, mapping, queryForm);
+ request.setAttribute("model", model);
+ if (request.getAttribute("commentManagementForm") == null) {
+ request.setAttribute("commentManagementForm", actionForm);
+ }
+
+ if (rreq.getWebsite() != null) {
+ return mapping.findForward("commentManagement.page");
+ }
+ return mapping.findForward("commentManagementGlobal.page");
+ }
+
+ private void sendCommentNotifications(
+ HttpServletRequest req, List comments) throws RollerException {
+
+ RollerContext rc = RollerContext.getRollerContext();
+ String rootURL = rc.getAbsoluteContextUrl(req);
+ try {
+ if (rootURL == null || rootURL.trim().length()==0) {
+ rootURL = RequestUtils.serverURL(req) + req.getContextPath();
+ }
+ } catch (MalformedURLException e) {
+ logger.error("ERROR: determining URL of site");
+ return;
+ }
+
+ Iterator iter = comments.iterator();
+ while (iter.hasNext()) {
+ CommentData comment = (CommentData)iter.next();
+
+ // Send email notifications because a new comment has been approved
+ CommentServlet.sendEmailNotification(comment, rootURL);
+
+ // Send approval notification to author of approved comment
+ CommentServlet.sendEmailApprovalNotification(comment, rootURL);
+ }
+ }
+
+ public class CommentManagementPageModel extends BasePageModel {
+ private List comments = new ArrayList();
+ private WeblogEntryData weblogEntry = null;
+ private CommentManagementForm queryForm = null;
+ private boolean more = false;
+
+ public CommentManagementPageModel(
+ String titleKey,
+ HttpServletRequest request,
+ HttpServletResponse response,
+ ActionMapping mapping,
+ CommentManagementForm queryForm) throws RollerException {
+
+ super(titleKey, request, response, mapping);
+ this.queryForm = queryForm;
+
+ Roller roller = RollerFactory.getRoller();
+ RollerRequest rreq = RollerRequest.getRollerRequest(request);
+ if (rreq.getWeblogEntry() != null) {
+ website = rreq.getWeblogEntry().getWebsite();
+ weblogEntry = rreq.getWeblogEntry();
+ }
+ else if (rreq.getWebsite() != null) {
+ website = rreq.getWebsite();
+ }
+ WeblogManager blogmgr = roller.getWeblogManager();
+
+ int offset = queryForm.getOffset();
+ comments = blogmgr.getComments(
+ website,
+ weblogEntry,
+ queryForm.getSearchString(),
+ queryForm.getStartDate(request.getLocale()),
+ queryForm.getEndDate(request.getLocale()),
+ queryForm.getPending(),
+ queryForm.getApproved(),
+ queryForm.getSpam(),
+ true, // reverse chrono order
+ queryForm.getOffset(),
+ queryForm.getCount() + 1);
+ if (comments.size() > queryForm.getCount()) {
+ more = true;
+ comments.remove(comments.size()-1);
+ }
+ this.queryForm.loadCheckboxes(comments);
+ }
+
+ public List getComments() {
+ return comments;
+ }
+
+ public int getCommentCount() {
+ int ret = comments.size();
+ return ret > queryForm.getCount() ? queryForm.getCount() : ret;
+ }
+
+ /**
+ * Number of pending entries on current page of results.
+ * Returns zero when managing comments across entire site, because
+ * we don't want global admins to change pending status of posts.
+ */
+ public int getPendingCommentCount() {
+ int count = 0;
+ if (getWebsite() != null) {
+ for (Iterator iter = comments.iterator(); iter.hasNext();) {
+ CommentData cd = (CommentData)iter.next();
+ if (cd.getPending().booleanValue()) count++;
+ }
+ }
+ return count;
+ }
+
+ public Date getEarliestDate() {
+ Date date = null;
+ if (comments.size() > 0) {
+ CommentData earliest = (CommentData)comments.get(comments.size()-1);
+ date = earliest.getPostTime();
+ }
+ return date;
+ }
+
+ public Date getLatestDate() {
+ Date date = null;
+ if (comments.size() > 0) {
+ CommentData latest = (CommentData)comments.get(0);
+ date = latest.getPostTime();
+ }
+ return date;
+ }
+
+ public WeblogEntryData getWeblogEntry() {
+ return weblogEntry;
+ }
+
+ public String getLink() {
+ return getQueryLink() + "&offset=" + queryForm.getOffset();
+ }
+
+ public String getNextLink() {
+ if (more) {
+ int offset = queryForm.getOffset() + queryForm.getCount();
+ offset = (offset < 0) ? 0 : offset;
+ return getQueryLink() + "&offset=" + offset;
+ } else {
+ return null;
+ }
+ }
+
+ public String getPrevLink() {
+ if (queryForm.getOffset() > 0) {
+ int offset = queryForm.getOffset() - queryForm.getCount();
+ offset = (offset < 0) ? 0 : offset;
+ return getQueryLink() + "&offset=" + offset;
+ } else {
+ return null;
+ }
+ }
+
+ private String getQueryLink() {
+ StringBuffer sb = new StringBuffer();
+ sb.append(request.getContextPath());
+ if (getWebsite() != null) {
+ sb.append("/editor/commentManagement.do"); // TODO: get path from Struts
+ sb.append("?method=query");
+ sb.append("&weblog=");
+ sb.append(getWebsite().getHandle());
+ } else {
+ sb.append("/admin/commentManagement.do"); // TODO: get path from Struts
+ sb.append("?method=query");
+ }
+ sb.append("&count=");
+ sb.append(queryForm.getCount());
+ return sb.toString();
+ }
+ }
+}
+
+
+
Added: incubator/roller/trunk/src/org/apache/roller/presentation/weblog/actions/CustomPingTargetsAction.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/apache/roller/presentation/weblog/actions/CustomPingTargetsAction.java?rev=398712&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/presentation/weblog/actions/CustomPingTargetsAction.java (added)
+++ incubator/roller/trunk/src/org/apache/roller/presentation/weblog/actions/CustomPingTargetsAction.java Mon May 1 15:23:02 2006
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.roller.presentation.weblog.actions;
+
+import java.util.Collections;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionForward;
+import org.apache.struts.action.ActionMapping;
+import org.apache.roller.RollerException;
+import org.apache.roller.config.PingConfig;
+import org.apache.roller.model.PingTargetManager;
+import org.apache.roller.model.RollerFactory;
+import org.apache.roller.pojos.PingTargetData;
+import org.apache.roller.pojos.WebsiteData;
+import org.apache.roller.presentation.forms.PingTargetForm;
+import org.apache.roller.presentation.RollerRequest;
+import org.apache.roller.presentation.RollerSession;
+
+
+/**
+ * Administer custom ping targets.
+ *
+ * @author <a href="mailto:anil@busybuddha.org">Anil Gangolli</a>
+ * @struts.action name="pingTargetForm" path="/editor/customPingTargets" scope="request" parameter="method"
+ * @struts.action-forward name="pingTargets.page" path=".CustomPingTargets"
+ * @struts.action-forward name="pingTargetEdit.page" path=".CustomPingTargetEdit"
+ * @struts.action-forward name="pingTargetDeleteOK.page" path=".CustomPingTargetDeleteOK"
+ */
+public class CustomPingTargetsAction
+ extends BasePingTargetsAction
+{
+ private static Log mLogger =
+ LogFactory.getFactory().getInstance(CustomPingTargetsAction.class);
+
+ public String getPingTargetsTitle()
+ {
+ return "customPingTargets.customPingTargets";
+ }
+ public String getPingTargetEditTitle()
+ {
+ return "pingTarget.pingTarget";
+ }
+ public String getPingTargetDeleteOKTitle()
+ {
+ return "pingTarget.confirmRemoveTitle";
+ }
+
+ public CustomPingTargetsAction() {
+ super();
+ }
+
+ protected Log getLogger() {
+ return mLogger;
+ }
+
+ /*
+ * Get the ping targets for the view. Here we return the custom ping targets for the
+ * website and set the value of attribute <code>allowCustomTargets</code> in the request.
+ * If custom ping targets have been disallowed, we just return the empty list.
+ */
+ protected List getPingTargets(RollerRequest rreq) throws RollerException
+ {
+ HttpServletRequest req = rreq.getRequest();
+ PingTargetManager pingTargetMgr = RollerFactory.getRoller().getPingTargetManager();
+
+ Boolean allowCustomTargets = new Boolean(!PingConfig.getDisallowCustomTargets());
+ req.setAttribute("allowCustomTargets", allowCustomTargets);
+
+ List customPingTargets = allowCustomTargets.booleanValue() ?
+ pingTargetMgr.getCustomPingTargets(rreq.getWebsite()) : Collections.EMPTY_LIST;
+
+ return customPingTargets;
+ }
+
+ /*
+ * Create a new ping target (blank). Here we create a custom ping target for the website.
+ */
+ protected PingTargetData createPingTarget(RollerRequest rreq, PingTargetForm pingTargetForm)
+ throws RollerException
+ {
+ return new PingTargetData(null, pingTargetForm.getName(),
+ pingTargetForm.getPingUrl(), rreq.getWebsite());
+ }
+
+
+ /*
+ * Check if the user has editing rights.
+ */
+ protected boolean hasRequiredRights(RollerRequest rreq, WebsiteData website)
+ throws RollerException
+ {
+ RollerSession rses = RollerSession.getRollerSession(rreq.getRequest());
+ return (rses.isUserAuthorizedToAdmin(website)
+ && !PingConfig.getDisallowCustomTargets());
+ }
+
+ public ActionForward cancel(
+ ActionMapping mapping,
+ ActionForm actionForm,
+ HttpServletRequest request,
+ HttpServletResponse response)
+ throws Exception
+ {
+ return view(mapping, actionForm, request, response);
+ }
+}
Added: incubator/roller/trunk/src/org/apache/roller/presentation/weblog/actions/ExportEntriesAction.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/apache/roller/presentation/weblog/actions/ExportEntriesAction.java?rev=398712&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/presentation/weblog/actions/ExportEntriesAction.java (added)
+++ incubator/roller/trunk/src/org/apache/roller/presentation/weblog/actions/ExportEntriesAction.java Mon May 1 15:23:02 2006
@@ -0,0 +1,318 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+/*
+ * Created on Mar 25, 2004
+ */
+package org.apache.roller.presentation.weblog.actions;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.jsp.JspFactory;
+import javax.servlet.jsp.PageContext;
+
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionForward;
+import org.apache.struts.action.ActionMapping;
+import org.apache.struts.action.ActionMessage;
+import org.apache.struts.action.ActionMessages;
+import org.apache.struts.actions.DispatchAction;
+import org.apache.struts.util.RequestUtils;
+import org.apache.roller.RollerException;
+import org.apache.roller.model.RollerFactory;
+import org.apache.roller.model.WeblogManager;
+import org.apache.roller.pojos.WeblogEntryData;
+import org.apache.roller.presentation.BasePageModel;
+import org.apache.roller.presentation.RollerRequest;
+import org.apache.roller.presentation.RollerSession;
+import org.apache.roller.presentation.velocity.ExportRss;
+import org.apache.roller.presentation.weblog.formbeans.WeblogEntryManagementForm;
+import org.apache.roller.util.DateUtil;
+
+/**
+ * @struts.action path="/editor/exportEntries" name="weblogQueryForm"
+ * scope="request" parameter="method"
+ *
+ * @struts.action-forward name="exportEntries.page" path=".export-entries"
+ *
+ * @author lance.lavandowska
+ */
+public class ExportEntriesAction extends DispatchAction
+{
+ private SimpleDateFormat dayFormat = new SimpleDateFormat("yyyyMMdd");
+ private SimpleDateFormat monthFormat = new SimpleDateFormat("yyyyMM");
+ private SimpleDateFormat yearFormat = new SimpleDateFormat("yyyy");
+
+ public ActionForward unspecified(
+ ActionMapping mapping,
+ ActionForm actionForm,
+ HttpServletRequest request,
+ HttpServletResponse response)
+ throws IOException, ServletException
+ {
+ return edit(mapping, actionForm, request, response);
+ }
+
+ /**
+ * Prepare the form for selecting date-range to export.
+ *
+ * @param mapping
+ * @param actionForm
+ * @param request
+ * @param response
+ * @return
+ * @throws IOException
+ * @throws ServletException
+ */
+ public ActionForward edit(
+ ActionMapping mapping,
+ ActionForm actionForm,
+ HttpServletRequest request,
+ HttpServletResponse response)
+ throws IOException, ServletException
+ {
+ ActionForward forward = mapping.findForward("exportEntries.page");
+ try
+ {
+ RollerRequest rreq = RollerRequest.getRollerRequest(request);
+ RollerSession rses =
+ RollerSession.getRollerSession(rreq.getRequest());
+ if ( rreq.getWebsite() == null
+ || !rses.isUserAuthorizedToAdmin(rreq.getWebsite()))
+ {
+ forward = mapping.findForward("access-denied");
+ }
+ else
+ {
+ request.setAttribute("model",
+ new BasePageModel("", request, response, mapping));
+ }
+ }
+ catch (Exception e)
+ {
+ request.getSession().getServletContext().log("ERROR",e);
+ throw new ServletException(e);
+ }
+ return forward;
+ }
+
+ /**
+ * Export entries from the requested date-range to XML.
+ *
+ * @param mapping
+ * @param actionForm
+ * @param request
+ * @param response
+ * @return
+ * @throws IOException
+ * @throws ServletException
+ */
+ public ActionForward export(
+ ActionMapping mapping,
+ ActionForm actionForm,
+ HttpServletRequest request,
+ HttpServletResponse response)
+ throws IOException, ServletException
+ {
+ ActionForward forward = mapping.findForward("exportEntries.page");
+ try
+ {
+ RollerRequest rreq = RollerRequest.getRollerRequest(request);
+ RollerSession rses = RollerSession.getRollerSession(rreq.getRequest());
+ WeblogEntryManagementForm form = (WeblogEntryManagementForm)actionForm;
+ if ( rreq.getWebsite() != null
+ && rses.isUserAuthorizedToAdmin(rreq.getWebsite()) )
+ {
+ request.setAttribute("model",
+ new BasePageModel("", request, response, mapping));
+
+ Locale locale = Locale.getDefault();//rreq.getWebsite().getLocaleInstance();
+ final DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
+ Date startDate;
+ Date endDate;
+ try
+ {
+ startDate = DateUtil.getStartOfDay(df.parse(form.getStartDateString()));
+ endDate = DateUtil.getEndOfDay(df.parse(form.getEndDateString()));
+ }
+ catch (ParseException e)
+ {
+ throw new RollerException("ERROR parsing date:" + e.getMessage());
+ }
+
+ if (startDate != null && endDate != null)
+ {
+ // this work should go into a Thread!
+ WeblogManager weblogMgr =
+ RollerFactory.getRoller().getWeblogManager();
+
+ //List entries = weblogMgr.getWeblogEntriesInDateRange(
+ //rreq.getUser().getUserName(), null, startDate, endDate, false);
+ //System.out.println("Export: got " + entries.size() + " entries.");
+
+ List entries = weblogMgr.getWeblogEntries(
+ rreq.getWebsite(), // userName
+ startDate, // startDate
+ endDate, // endDate
+ null, // catName
+ null, // status
+ null, // sortby (null for pubtime)
+ null); // maxEntries
+
+ ActionMessages messages = writeSuccessMessage(request, response, rreq, form);
+
+ // seperate the entries as specified: day, month, year
+ Map entryMap = seperateByPeriod(entries, form.getFileBy());
+
+ // now export each List in the entryMap
+ ExportRss exporter = new ExportRss(rreq.getWebsite());
+ String exportTo = form.getExportFormat().toLowerCase();
+ if ("atom".equals(exportTo))
+ {
+ exporter.setExportAtom(true);
+ }
+ ArrayList fileNames = new ArrayList();
+ Iterator it = entryMap.keySet().iterator();
+ while(it.hasNext())
+ {
+ String key = (String)it.next();
+ ArrayList list = (ArrayList)entryMap.get(key);
+ exporter.exportEntries(list, key+"_"+exportTo+".xml");
+ fileNames.add("Exported " + list.size() + " entry(s) to " + key+"_"+exportTo+".xml<br />");
+ //System.out.println("Exported: " + list.size() + " entries for " + key);
+ }
+
+ StringBuffer fileMessage = new StringBuffer();
+ it = fileNames.iterator();
+ while (it.hasNext())
+ {
+ fileMessage.append((String)it.next());
+ }
+ if (fileMessage.length() > 0)
+ {
+ messages.add(ActionMessages.GLOBAL_MESSAGE,
+ new ActionMessage("weblogEntryExport.exportFiles",
+ fileMessage.toString()));
+ }
+ saveMessages(request, messages);
+ }
+ else
+ {
+ form.reset(mapping, (ServletRequest)request);
+ return edit(mapping, actionForm, request, response);
+ }
+
+ //forward = mapping.findForward("exportEntries.done");
+ }
+ else
+ {
+ forward = mapping.findForward("access-denied");
+ }
+ }
+ catch (Exception e)
+ {
+ request.getSession().getServletContext().log("ERROR",e);
+ throw new ServletException(e);
+ }
+ return forward;
+ }
+
+ /**
+ * Place entries into Lists, placed into date-related
+ * buckets. The individual buckets may represent a
+ * day, month, or year, depending on which the user specified.
+ *
+ * @param entries
+ * @return
+ */
+ private Map seperateByPeriod(List entries, String period)
+ {
+ HashMap map = new HashMap();
+ WeblogEntryData entry = null;
+ String key = null;
+ ArrayList list = null;
+ SimpleDateFormat formatter = monthFormat;
+ if ("year".equals(period))
+ {
+ formatter = yearFormat;
+ }
+ else if ("day".equals(period))
+ {
+ formatter = dayFormat;
+ }
+
+ Iterator it = entries.iterator();
+ while (it.hasNext())
+ {
+ entry = (WeblogEntryData)it.next();
+ key = formatter.format(entry.getPubTime());
+ list = (ArrayList)map.get(key);
+ if (list == null)
+ {
+ list = new ArrayList();
+ map.put(key, list);
+ }
+ list.add(entry);
+ }
+ return map;
+ }
+
+ private ActionMessages writeSuccessMessage(
+ HttpServletRequest request,
+ HttpServletResponse response,
+ RollerRequest rreq,
+ WeblogEntryManagementForm form) throws MalformedURLException
+ {
+ PageContext pageContext =
+ JspFactory.getDefaultFactory().getPageContext(
+ this.getServlet(), request, response, "", true, 8192, true);
+ Map params = new HashMap();
+ params.put( RollerRequest.WEBLOG_KEY,
+ rreq.getWebsite().getHandle());
+ params.put("rmik", "Files");
+ String filesLink = RequestUtils.computeURL(
+ pageContext, (String)null, (String)null, (String)null,
+ "uploadFiles", params, (String)null, false);
+
+ String message =
+ "Exporting Entries from " +
+ form.getStartDateString() + " to " +
+ form.getEndDateString() + ".<br />" +
+ "Check your <a href=\"" + filesLink + "\">Files</a>.";
+
+ ActionMessages messages = new ActionMessages();
+ messages.add(ActionMessages.GLOBAL_MESSAGE,
+ new ActionMessage("weblogEntryExport.exportSuccess", message));
+
+ return messages;
+ }
+}
Added: incubator/roller/trunk/src/org/apache/roller/presentation/weblog/actions/ImportEntriesAction.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/apache/roller/presentation/weblog/actions/ImportEntriesAction.java?rev=398712&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/presentation/weblog/actions/ImportEntriesAction.java (added)
+++ incubator/roller/trunk/src/org/apache/roller/presentation/weblog/actions/ImportEntriesAction.java Mon May 1 15:23:02 2006
@@ -0,0 +1,190 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+/*
+ * Created on Mar 31, 2004
+ */
+package org.apache.roller.presentation.weblog.actions;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.struts.action.ActionError;
+import org.apache.struts.action.ActionErrors;
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionForward;
+import org.apache.struts.action.ActionMapping;
+import org.apache.struts.action.ActionMessage;
+import org.apache.struts.action.ActionMessages;
+import org.apache.struts.actions.DispatchAction;
+import org.apache.roller.RollerException;
+import org.apache.roller.model.RollerFactory;
+import org.apache.roller.pojos.WebsiteData;
+import org.apache.roller.presentation.RollerRequest;
+import org.apache.roller.presentation.RollerSession;
+import org.apache.roller.presentation.cache.CacheManager;
+import org.apache.roller.presentation.weblog.formbeans.ImportEntriesForm;
+import org.apache.roller.util.StringUtils;
+/**
+ * TODO: revisit this class once Atom 1.0 support comes to Rome
+ * @struts.action name="importEntries" path="/editor/importEntries"
+ * scope="request" parameter="method"
+ *
+ * @struts.action-forward name="importEntries.page" path=".import-entries"
+ *
+ * @author lance.lavandowska
+ */
+public class ImportEntriesAction extends DispatchAction
+{
+ public ActionForward importEntries(
+ ActionMapping mapping,
+ ActionForm actionForm,
+ HttpServletRequest request,
+ HttpServletResponse response)
+ throws IOException, ServletException
+ {
+ ActionForward forward = mapping.findForward("importEntries.page");
+ try
+ {
+ RollerRequest rreq = RollerRequest.getRollerRequest(request);
+ RollerSession rollerSession = RollerSession.getRollerSession(rreq.getRequest());
+ if ( rreq.getWebsite() == null
+ || !rollerSession.isUserAuthorizedToAdmin(rreq.getWebsite()))
+ {
+ forward = mapping.findForward("access-denied");
+ }
+ else
+ {
+ getXmlFiles(actionForm, rreq);
+ ImportEntriesForm form = (ImportEntriesForm)actionForm;
+ if (StringUtils.isNotEmpty(form.getImportFileName()))
+ {
+ // "default" values
+ WebsiteData website = rreq.getWebsite();
+
+ // load selected file
+ String dir = RollerFactory.getRoller().getFileManager().getUploadDir();
+ File f = new File(dir + website.getHandle() +
+ "/" + form.getImportFileName());
+
+ //ArchiveParser archiveParser =
+ //new ArchiveParser(RollerFactory.getRoller(), rreq.getWebsite(), f);
+ String parseMessages = null; // archiveParser.parse();
+
+ // buf will be non-zero if Entries were imported
+ if (parseMessages.length() > 0)
+ {
+ ActionMessages notices = new ActionMessages();
+ notices.add(ActionMessages.GLOBAL_MESSAGE,
+ new ActionMessage("weblogEntryImport.importFiles",
+ parseMessages));
+ saveMessages(request, notices);
+
+ // Flush the page cache
+ //PageCacheFilter.removeFromCache(request, website);
+ CacheManager.invalidate(website);
+ }
+ else
+ {
+ ActionErrors errors = new ActionErrors();
+ errors.add(ActionErrors.GLOBAL_ERROR,
+ new ActionError("error.importing.entries", ""));
+ saveErrors(request,errors);
+ }
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ request.getSession().getServletContext().log("ERROR",e);
+ throw new ServletException(e);
+ }
+ return forward;
+ }
+
+ /**
+ * Load list of XML files available for import.
+ * @param mapping
+ * @param actionForm
+ * @param request
+ * @param response
+ * @return
+ * @throws IOException
+ * @throws ServletException
+ */
+ public ActionForward edit(
+ ActionMapping mapping,
+ ActionForm actionForm,
+ HttpServletRequest request,
+ HttpServletResponse response)
+ throws IOException, ServletException
+ {
+ ActionForward forward = mapping.findForward("importEntries.page");
+ try
+ {
+ RollerRequest rreq = RollerRequest.getRollerRequest(request);
+ RollerSession rses = RollerSession.getRollerSession(request);
+ if ( rreq.getWebsite() == null
+ || !rses.isUserAuthorizedToAdmin(rreq.getWebsite()) )
+ {
+ forward = mapping.findForward("access-denied");
+ }
+ else
+ {
+ getXmlFiles(actionForm, rreq);
+ }
+ }
+ catch (Exception e)
+ {
+ request.getSession().getServletContext().log("ERROR",e);
+ throw new ServletException(e);
+ }
+ return forward;
+ }
+
+ private void getXmlFiles(ActionForm actionForm, RollerRequest rreq)
+ {
+ String dir = null;
+ try {
+ RollerFactory.getRoller().getFileManager().getUploadDir();
+ } catch(RollerException re) {
+ // shouldn't happen
+ }
+
+ File d = new File(dir + rreq.getWebsite().getHandle());
+ ArrayList xmlFiles = new ArrayList();
+ if (d.mkdirs() || d.exists())
+ {
+ File[] files = d.listFiles();
+ for (int i=0; i<files.length; i++)
+ {
+ if (!files[i].isDirectory() &&
+ files[i].getName().toLowerCase().endsWith(".xml"))
+ // TODO : later change detection to use FileInfo
+ {
+ xmlFiles.add(files[i].getName());
+ }
+ }
+ }
+ ImportEntriesForm form = (ImportEntriesForm)actionForm;
+ form.setXmlFiles(xmlFiles);
+ }
+}
Added: incubator/roller/trunk/src/org/apache/roller/presentation/weblog/actions/PingSetupAction.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/apache/roller/presentation/weblog/actions/PingSetupAction.java?rev=398712&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/presentation/weblog/actions/PingSetupAction.java (added)
+++ incubator/roller/trunk/src/org/apache/roller/presentation/weblog/actions/PingSetupAction.java Mon May 1 15:23:02 2006
@@ -0,0 +1,355 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.roller.presentation.weblog.actions;
+
+import java.io.IOException;
+import java.net.SocketException;
+import java.net.UnknownHostException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionForward;
+import org.apache.struts.action.ActionMapping;
+import org.apache.struts.action.ActionMessage;
+import org.apache.struts.action.ActionMessages;
+import org.apache.struts.actions.DispatchAction;
+import org.apache.xmlrpc.XmlRpcException;
+import org.apache.roller.RollerException;
+import org.apache.roller.config.PingConfig;
+import org.apache.roller.model.AutoPingManager;
+import org.apache.roller.model.PingTargetManager;
+import org.apache.roller.model.RollerFactory;
+import org.apache.roller.pojos.AutoPingData;
+import org.apache.roller.pojos.PingTargetData;
+import org.apache.roller.pojos.WebsiteData;
+import org.apache.roller.presentation.BasePageModel;
+import org.apache.roller.presentation.RollerContext;
+import org.apache.roller.presentation.RollerRequest;
+import org.apache.roller.presentation.RollerSession;
+import org.apache.roller.presentation.pings.WeblogUpdatePinger;
+
+
+/**
+ * Actions for setting up automatic ping configuration for a weblog.
+ *
+ * @author <a href="mailto:anil@busybuddha.org">Anil Gangolli</a>
+ * @struts.action name="pingSetupForm" path="/editor/pingSetup" scope="request" parameter="method"
+ * @struts.action-forward name="pingSetup.page" path=".Pings"
+ * @struts.action-forward name="pingResult.page" path=".PingResult"
+ */
+public class PingSetupAction extends DispatchAction
+{
+ private static Log mLogger =
+ LogFactory.getFactory().getInstance(PingSetupAction.class);
+
+ private static final String PING_SETUP_PAGE = "pingSetup.page";
+
+ // Changing this to take your back to the pings setup page instead of
+ // ping result page, no need for extra page.
+ private static final String PING_RESULT_PAGE = "pingSetup.page"; // "pingResult.page";
+
+ /* (non-Javadoc)
+ * @see org.apache.struts.actions.DispatchAction#unspecified(
+ * org.apache.struts.action.ActionMapping,
+ * org.apache.struts.action.ActionForm,
+ * javax.servlet.http.HttpServletRequest,
+ * javax.servlet.http.HttpServletResponse)
+ */
+ protected ActionForward unspecified(ActionMapping mapping,
+ ActionForm actionForm,
+ HttpServletRequest request,
+ HttpServletResponse response)
+ throws Exception
+ {
+ return view(mapping, actionForm, request, response);
+ }
+
+ /*
+ * Display the common ping targets with page
+ */
+ public ActionForward view(ActionMapping mapping, ActionForm form,
+ HttpServletRequest req, HttpServletResponse res)
+ throws Exception
+ {
+ ActionForward forward = mapping.findForward(PING_SETUP_PAGE);
+ RollerRequest rreq = RollerRequest.getRollerRequest(req);
+ PingTargetManager pingTargetMgr = RollerFactory.getRoller().getPingTargetManager();
+ WebsiteData website = rreq.getWebsite();
+ try
+ {
+ if (!isAuthorized(rreq, website))
+ {
+ return mapping.findForward("access-denied");
+ }
+
+ BasePageModel pageModel =
+ new BasePageModel("pings.title", req, res, mapping);
+ req.setAttribute("model",pageModel);
+
+ List commonPingTargets = pingTargetMgr.getCommonPingTargets();
+ req.setAttribute("commonPingTargets", commonPingTargets);
+
+ Boolean allowCustomTargets = new Boolean(!PingConfig.getDisallowCustomTargets());
+ req.setAttribute("allowCustomTargets", allowCustomTargets);
+
+ List customPingTargets = allowCustomTargets.booleanValue() ?
+ pingTargetMgr.getCustomPingTargets(website) : Collections.EMPTY_LIST;
+ req.setAttribute("customPingTargets", customPingTargets);
+
+ // Build isEnabled map (keyed by ping target id and values Boolean.TRUE/Boolean.FALSE)
+ Map isEnabled = buildIsEnabledMap(rreq, commonPingTargets, customPingTargets);
+ req.setAttribute("isEnabled", isEnabled);
+
+ return forward;
+ }
+ catch (Exception e)
+ {
+ mLogger.error("ERROR in action", e);
+ throw new ServletException(e);
+ }
+ }
+
+ /*
+ * Private helper to build a map indexed by ping target id with values Boolean.TRUE and Boolean.FALSE
+ * based on whether the ping target is enabled (has a corresponding auto ping configuration).
+ */
+ private Map buildIsEnabledMap(RollerRequest rreq, List commonPingTargets, List customPingTargets)
+ throws RollerException
+ {
+ AutoPingManager autoPingMgr = RollerFactory.getRoller().getAutopingManager();
+ WebsiteData website = rreq.getWebsite();
+
+ // Build isEnabled map (keyed by ping target id and values Boolean.TRUE/Boolean.FALSE)
+ Map isEnabled = new HashMap();
+ List autopings = autoPingMgr.getAutoPingsByWebsite(website);
+ // Add the enabled auto ping configs with TRUE
+ for (Iterator i = autopings.iterator(); i.hasNext();)
+ {
+ AutoPingData autoPing = (AutoPingData) i.next();
+ isEnabled.put(autoPing.getPingTarget().getId(), Boolean.TRUE);
+ }
+ // Somewhat awkward, but the two loops save building a separate combined list.
+ // Add disabled common ones with FALSE
+ for (Iterator i = commonPingTargets.iterator(); i.hasNext();)
+ {
+ PingTargetData pingTarget = (PingTargetData) i.next();
+ if (isEnabled.get(pingTarget.getId()) == null)
+ {
+ isEnabled.put(pingTarget.getId(), Boolean.FALSE);
+ }
+ }
+ // Add disabled custom ones with FALSE
+ for (Iterator i = customPingTargets.iterator(); i.hasNext();)
+ {
+ PingTargetData pingTarget = (PingTargetData) i.next();
+ if (isEnabled.get(pingTarget.getId()) == null)
+ {
+ isEnabled.put(pingTarget.getId(), Boolean.FALSE);
+ }
+ }
+ return isEnabled;
+ }
+
+ /*
+ * Enable a ping target.
+ */
+ public ActionForward enableSelected(ActionMapping mapping, ActionForm form,
+ HttpServletRequest req, HttpServletResponse res)
+ throws Exception
+ {
+ RollerRequest rreq = RollerRequest.getRollerRequest(req);
+ AutoPingManager autoPingMgr = RollerFactory.getRoller().getAutopingManager();
+ PingTargetData pingTarget = select(rreq);
+ try
+ {
+ if (!isAuthorized(rreq, rreq.getWebsite()))
+ {
+ return mapping.findForward("access-denied");
+ }
+ AutoPingData autoPing = new AutoPingData(null, pingTarget, rreq.getWebsite());
+ autoPingMgr.saveAutoPing(autoPing);
+ RollerFactory.getRoller().flush();
+
+ return view(mapping, form, req, res);
+ }
+ catch (Exception e)
+ {
+ mLogger.error("ERROR in action", e);
+ throw new ServletException(e);
+ }
+ }
+
+ /*
+ * Load delete confirmation view.
+ */
+ public ActionForward disableSelected(ActionMapping mapping, ActionForm form,
+ HttpServletRequest req, HttpServletResponse res)
+ throws Exception
+ {
+ RollerRequest rreq = RollerRequest.getRollerRequest(req);
+ AutoPingManager autoPingMgr = RollerFactory.getRoller().getAutopingManager();
+ PingTargetData pingTarget = select(rreq);
+ try
+ {
+ if (!isAuthorized(rreq, rreq.getWebsite()))
+ {
+ return mapping.findForward("access-denied");
+ }
+ autoPingMgr.removeAutoPing(pingTarget, rreq.getWebsite());
+ RollerFactory.getRoller().flush();
+
+ return view(mapping, form, req, res);
+ }
+ catch (Exception e)
+ {
+ mLogger.error("ERROR in action", e);
+ throw new ServletException(e);
+ }
+ }
+
+ /*
+ * Ping the selected target now.
+ */
+ public ActionForward pingSelectedNow(ActionMapping mapping, ActionForm form,
+ HttpServletRequest req, HttpServletResponse res)
+ throws Exception
+ {
+ try
+ {
+ RollerRequest rreq = RollerRequest.getRollerRequest(req);
+ String absoluteUrl = RollerContext.getRollerContext().getAbsoluteContextUrl(req);
+ PingTargetData pingTarget = select(rreq);
+ WebsiteData website = rreq.getWebsite();
+ try
+ {
+ if (!isAuthorized(rreq, website))
+ {
+ return mapping.findForward("access-denied");
+ }
+ if (PingConfig.getSuspendPingProcessing())
+ {
+ if (mLogger.isDebugEnabled()) mLogger.debug("Ping processing is disabled.");
+ ActionMessages errors = new ActionMessages();
+ errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("ping.pingProcessingIsSuspended"));
+ saveErrors(req, errors);
+ }
+ else
+ {
+ WeblogUpdatePinger.PingResult pingResult =
+ WeblogUpdatePinger.sendPing(absoluteUrl, pingTarget, website);
+ if (pingResult.isError())
+ {
+ if (mLogger.isDebugEnabled()) mLogger.debug("Ping Result: " + pingResult);
+ ActionMessages errors = new ActionMessages();
+ if (pingResult.getMessage() != null && pingResult.getMessage().trim().length() > 0)
+ {
+ errors.add(ActionMessages.GLOBAL_MESSAGE,
+ new ActionMessage("ping.transmittedButError"));
+ errors.add(ActionMessages.GLOBAL_MESSAGE,
+ new ActionMessage(pingResult.getMessage()));
+ }
+ else
+ {
+ errors.add(ActionMessages.GLOBAL_MESSAGE,
+ new ActionMessage("ping.transmissionFailed"));
+ }
+ saveErrors(req, errors);
+ }
+ else
+ {
+ ActionMessages messages = new ActionMessages();
+ messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("ping.successful"));
+ saveMessages(req, messages);
+ }
+ }
+ }
+ catch (IOException ex)
+ {
+ mLogger.debug(ex);
+ ActionMessages errors = new ActionMessages();
+ errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("ping.transmissionFailed"));
+ addSpecificMessages(ex, errors);
+ saveErrors(req, errors);
+ }
+ catch (XmlRpcException ex)
+ {
+ mLogger.debug(ex);
+ ActionMessages errors = new ActionMessages();
+ errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("ping.transmissionFailed"));
+ addSpecificMessages(ex, errors);
+ saveErrors(req, errors);
+ }
+ return view(mapping, form , req, res);
+ }
+ catch (Exception ex)
+ {
+ mLogger.error("ERROR in action", ex);
+ throw new ServletException(ex);
+ }
+ }
+
+ // TODO: Consider unifying with other RollerRequest methods
+ // Private helper to get ping target specified by request
+ private PingTargetData select(RollerRequest rreq) throws RollerException
+ {
+ String pingTargetId = rreq.getRequest().getParameter(RollerRequest.PINGTARGETID_KEY);
+ PingTargetManager pingTargetMgr = RollerFactory.getRoller().getPingTargetManager();
+ if (pingTargetId == null || pingTargetId.length() == 0)
+ {
+ throw new RollerException("Missing ping target id: " + pingTargetId);
+ }
+
+ PingTargetData pingTarget = pingTargetMgr.getPingTarget(pingTargetId);
+ if (pingTarget == null)
+ {
+ throw new RollerException("No such ping target id: " + pingTargetId);
+ }
+ return pingTarget;
+ }
+
+ private void addSpecificMessages(Exception ex, ActionMessages errors)
+ {
+ if (ex instanceof UnknownHostException)
+ {
+ errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("ping.unknownHost"));
+ }
+ else if (ex instanceof SocketException)
+ {
+ errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("ping.networkConnectionFailed"));
+ }
+ }
+
+ private boolean isAuthorized(RollerRequest rreq, WebsiteData website)
+ throws RollerException
+ {
+ RollerSession rses = RollerSession.getRollerSession(rreq.getRequest());
+ return rses.isUserAuthorizedToAdmin(website)
+ && !PingConfig.getDisablePingUsage();
+ }
+}
Added: incubator/roller/trunk/src/org/apache/roller/presentation/weblog/actions/ReferersAction.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/apache/roller/presentation/weblog/actions/ReferersAction.java?rev=398712&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/presentation/weblog/actions/ReferersAction.java (added)
+++ incubator/roller/trunk/src/org/apache/roller/presentation/weblog/actions/ReferersAction.java Mon May 1 15:23:02 2006
@@ -0,0 +1,186 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+
+package org.apache.roller.presentation.weblog.actions;
+
+import java.util.List;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.struts.action.ActionError;
+import org.apache.struts.action.ActionErrors;
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionForward;
+import org.apache.struts.action.ActionMapping;
+import org.apache.struts.action.ActionMessage;
+import org.apache.struts.action.ActionMessages;
+import org.apache.struts.actions.DispatchAction;
+import org.apache.roller.model.RefererManager;
+import org.apache.roller.model.RollerFactory;
+import org.apache.roller.pojos.RefererData;
+import org.apache.roller.pojos.WebsiteData;
+import org.apache.roller.presentation.BasePageModel;
+import org.apache.roller.presentation.RollerRequest;
+import org.apache.roller.presentation.RollerSession;
+import org.apache.roller.presentation.cache.CacheManager;
+
+/**
+ * Display today's referers.
+ * @struts.action name="refererForm" path="/editor/referers"
+ * scope="session" parameter="method"
+ *
+ * @struts.action-forward name="referers.page" path=".referers"
+ */
+public class ReferersAction extends DispatchAction
+{
+ private static Log mLogger =
+ LogFactory.getFactory().getInstance(ReferersAction.class);
+
+ public ActionForward unspecified(
+ ActionMapping mapping,
+ ActionForm actionForm,
+ HttpServletRequest request,
+ HttpServletResponse response)
+ throws Exception
+ {
+ return view(mapping, actionForm, request, response);
+ }
+
+ /**
+ * execute
+ */
+ public ActionForward view(
+ ActionMapping mapping, ActionForm form,
+ HttpServletRequest req, HttpServletResponse res)
+ throws Exception
+ {
+ ActionForward forward = mapping.findForward("referers.page");
+ RollerRequest rreq = RollerRequest.getRollerRequest(req);
+ RollerSession rollerSession = RollerSession.getRollerSession(req);
+ RefererManager refmgr = RollerFactory.getRoller().getRefererManager();
+ try
+ {
+ if (rreq.getWebsite() != null
+ && rollerSession.isUserAuthorizedToAuthor(rreq.getWebsite()) )
+ {
+ BasePageModel pageModel = new BasePageModel(
+ "referers.todaysReferers", req, res, mapping);
+ req.setAttribute("model", pageModel);
+ req.setAttribute("pageHits",
+ new Integer(refmgr.getDayHits(rreq.getWebsite())));
+
+ req.setAttribute("totalHits",
+ new Integer(refmgr.getTotalHits(rreq.getWebsite())));
+
+ List refs = refmgr.getTodaysReferers(rreq.getWebsite());
+ req.setAttribute("referers",refs);
+ }
+ }
+ catch (Exception e)
+ {
+ mLogger.error("ERROR in action",e);
+ throw new ServletException(e);
+ }
+
+ return forward;
+ }
+
+ public ActionForward reset(
+ ActionMapping mapping, ActionForm form,
+ HttpServletRequest req, HttpServletResponse res)
+ throws Exception
+ {
+ this.servlet.log("ReferersAction.reset()");
+ RollerRequest rreq = RollerRequest.getRollerRequest(req);
+ RollerSession rollerSession = RollerSession.getRollerSession(req);
+ try
+ {
+ if (rreq.getWebsite() != null
+ && rollerSession.isUserAuthorizedToAuthor(rreq.getWebsite()) )
+ {
+ RefererManager refmgr = RollerFactory.getRoller().getRefererManager();
+ WebsiteData website = rreq.getWebsite();
+ refmgr.clearReferrers(website);
+ RollerFactory.getRoller().flush();
+
+ CacheManager.invalidate(website);
+ }
+ this.servlet.log("ReferersAction.reset(): don't have permission");
+ }
+ catch (Exception e)
+ {
+ mLogger.error("ERROR in action",e);
+ throw new ServletException(e);
+ }
+ return view(mapping, form, req, res);
+ }
+
+ public ActionForward delete(
+ ActionMapping mapping, ActionForm form,
+ HttpServletRequest req, HttpServletResponse res)
+ throws Exception
+ {
+ //this.servlet.log("ReferersAction.delete()");
+ RollerRequest rreq = RollerRequest.getRollerRequest(req);
+ RollerSession rollerSession = RollerSession.getRollerSession(req);
+ try
+ {
+ if (rreq.getWebsite() != null
+ && rollerSession.isUserAuthorizedToAuthor(rreq.getWebsite()) )
+ {
+ RefererManager refmgr = RollerFactory.getRoller().getRefererManager();
+ WebsiteData website = rreq.getWebsite();
+
+ RefererData referer = null;
+ String[] deleteIds = req.getParameterValues("id");
+ if (deleteIds != null)
+ {
+ for (int i=0; i<deleteIds.length; i++)
+ {
+ referer = refmgr.getReferer(deleteIds[i]);
+ refmgr.removeReferer(referer);
+ }
+ RollerFactory.getRoller().flush();
+
+ CacheManager.invalidate(website);
+
+ ActionMessages messages = new ActionMessages();
+ messages.add(null, new ActionMessage("referers.deletedReferers"));
+ saveMessages(req, messages);
+ }
+ else
+ {
+ ActionErrors errors = new ActionErrors();
+ errors.add(null, new ActionError("referers.noReferersSpecified"));
+ saveErrors(req, errors);
+ }
+ }
+ //this.servlet.log("ReferersAction.delete(): don't have permission");
+ }
+ catch (Exception e)
+ {
+ mLogger.error("ERROR in action",e);
+ throw new ServletException(e);
+ }
+ return view(mapping, form, req, res);
+ }
+}
Added: incubator/roller/trunk/src/org/apache/roller/presentation/weblog/actions/ToggleLinkbackDisplayAction.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/apache/roller/presentation/weblog/actions/ToggleLinkbackDisplayAction.java?rev=398712&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/presentation/weblog/actions/ToggleLinkbackDisplayAction.java (added)
+++ incubator/roller/trunk/src/org/apache/roller/presentation/weblog/actions/ToggleLinkbackDisplayAction.java Mon May 1 15:23:02 2006
@@ -0,0 +1,109 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.roller.presentation.weblog.actions;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.struts.action.Action;
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionForward;
+import org.apache.struts.action.ActionMapping;
+import org.apache.roller.model.RefererManager;
+import org.apache.roller.model.RollerFactory;
+import org.apache.roller.pojos.RefererData;
+import org.apache.roller.pojos.WeblogEntryData;
+import org.apache.roller.presentation.RollerContext;
+import org.apache.roller.presentation.RollerRequest;
+import org.apache.roller.presentation.RollerSession;
+import org.apache.roller.presentation.cache.CacheManager;
+
+/**
+ * Toggle display of a linkback.
+ * @struts.action path="/editor/toggleLinkback" name="toggleLinkback"
+ */
+public class ToggleLinkbackDisplayAction extends Action
+{
+ private static Log mLogger = LogFactory.getFactory().getInstance(
+ ToggleLinkbackDisplayAction.class);
+
+ /**
+ * execute
+ */
+ public ActionForward execute(
+ ActionMapping mapping, ActionForm form,
+ HttpServletRequest req, HttpServletResponse res)
+ throws Exception
+ {
+ WeblogEntryData entry = null;
+ RollerRequest rreq = RollerRequest.getRollerRequest(req);
+ RollerSession rollerSession = RollerSession.getRollerSession(req);
+ try
+ {
+ if (rreq.getWebsite() != null
+ && rollerSession.isUserAuthorizedToAuthor(rreq.getWebsite()) )
+ {
+ String refid = req.getParameter(RollerRequest.REFERERID_KEY);
+ if ( refid != null )
+ {
+ RefererManager refmgr =
+ RollerFactory.getRoller().getRefererManager();
+ RefererData ref = refmgr.getReferer(refid);
+ entry = ref.getWeblogEntry();
+ boolean was = ref.getVisible()==null ?
+ false : ref.getVisible().booleanValue();
+ ref.setVisible(Boolean.valueOf( !was )); // what up, dog?
+ refmgr.saveReferer(ref);
+
+ RollerFactory.getRoller().flush();
+
+ //PageCacheFilter.removeFromCache( req, rreq.getWebsite() );
+ CacheManager.invalidate(rreq.getWebsite());
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ mLogger.error("Toggling linkback display",e);
+ throw new ServletException(e);
+ }
+
+ // forward back to entry or to blog if we have no entry
+ String url = null;
+ try
+ {
+ RollerContext rctx = RollerContext.getRollerContext();
+ if (entry != null) {
+ url = rctx.createEntryPermalink(entry, req, true);
+ } else {
+ url = rctx.getContextUrl(req, rreq.getWebsite());
+ }
+ res.sendRedirect(url);
+ }
+ catch (Exception e)
+ {
+ mLogger.error("Unexpected exception",e);
+ }
+
+ return null;
+ }
+}
+