rendered paste body# This patch file was generated by NetBeans IDE# This patch can be applied using context Tools: Apply Diff Patch action on respective folder.# It uses platform neutral UTF-8 encoding.# Above lines and this line are ignored by the patching process.3,6c3,13< import java.util.Date;< import java.util.HashMap;< import java.util.Locale;< import java.util.Map;---> import ch.epfl.kis.polywiki.model.*;> import ch.epfl.kis.polywiki.security.*;> import ch.epfl.kis.polywiki.service.*;> import ch.epfl.kis.polywiki.util.*;> import ch.epfl.kis.polywiki.validator.*;> import com.baneo.core.jsp.taglib.*;> import com.baneo.core.util.*;> import com.baneo.core.validator.*;> import com.baneo.core.view.web.action.*;> import org.apache.struts.action.*;> import org.apache.struts.taglib.html.*;8,9c15,16< import javax.servlet.http.HttpServletRequest;< import javax.servlet.http.HttpServletResponse;---> import javax.servlet.http.*;> import java.util.*;11,35d17< import org.apache.struts.action.ActionForm;< import org.apache.struts.action.ActionForward;< import org.apache.struts.action.ActionMapping;< < import ch.epfl.kis.polywiki.model.Lock;< import ch.epfl.kis.polywiki.model.Page;< import ch.epfl.kis.polywiki.model.User;< import ch.epfl.kis.polywiki.model.Wiki;< import ch.epfl.kis.polywiki.security.SecurityService;< import ch.epfl.kis.polywiki.service.LockService;< import ch.epfl.kis.polywiki.service.PDFService;< import ch.epfl.kis.polywiki.service.PDFServiceException;< import ch.epfl.kis.polywiki.service.PageService;< import ch.epfl.kis.polywiki.service.UrlService;< import ch.epfl.kis.polywiki.util.Formater;< import ch.epfl.kis.polywiki.validator.PageValidator;< < import com.baneo.core.jsp.taglib.MessageTag;< import com.baneo.core.system.Message;< import com.baneo.core.util.ArrayUtil;< import com.baneo.core.util.BeanUtil;< import com.baneo.core.util.HttpUtil;< import com.baneo.core.validator.Validator;< import com.baneo.core.view.web.action.ObjectUpdateAction;< 41c23,24< public class PageUpdateAction extends ObjectUpdateAction {---> public class PageUpdateAction extends ObjectUpdateAction> {43d25< 46c28< private static final PDFService _pdfService = PDFService.instance();---> public static int _reloadCount = 0;48,49c30,31< public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,< HttpServletResponse response) throws Exception {---> public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception> {52,56d33< // preview< if (request.getParameter("preview") != null) {< return mapping.findForward("preview");< }< 59c36,37< if (page == null) {---> if (page == null)> {65c43,44< if (request.getParameter("cancel") != null) {---> if (request.getParameter("cancel") != null)> {79a59,65> // check if the form was reloaded> if (request.getParameter(Constants.TOKEN_KEY) != null && !isTokenValid(request))> {> _reloadCount++;> return mapping.findForward("reload");> }> 81c67,68< if (!isTokenValid(request)) {---> if (!isTokenValid(request))> {84c71,72< if (lock == null) {---> if (lock == null)> {86c74,76< } else {---> }> else> {89c79,80< if (!locker.equals(user)) {---> if (!locker.equals(user))> {101,105d91< // Latex page => try to compile it first< if ("2".equals(request.getParameter("type"))) {< return compileLatex(mapping, form, request, response);< }< 109c95,96< protected Map getValues(HttpServletRequest request, HttpServletResponse response) throws Exception {---> protected Map getValues(HttpServletRequest request, HttpServletResponse response) throws Exception> {110a98> 114c102,103< protected Validator getValidator(HttpServletRequest request, HttpServletResponse response) throws Exception {---> protected Validator getValidator(HttpServletRequest request, HttpServletResponse response) throws Exception> {115a105> 118a109> 122,123c113,114< protected void update(Object object, Validator validator, HttpServletRequest request, HttpServletResponse response)< throws Exception {---> protected void update(Object object, Validator validator, HttpServletRequest request, HttpServletResponse response) throws Exception> {138,143c129,131< * @param request< * the request.< * @param mode< * the mode, can be MODE_INIT or MODE_UPDATE.< * @throws Exception< * on error.---> * @param request the request.> * @param mode the mode, can be MODE_INIT or MODE_UPDATE.> * @throws Exception on error.145c133,134< private void prepareRequest(HttpServletRequest request, int mode) throws Exception {---> private void prepareRequest(HttpServletRequest request, int mode) throws Exception> {152c141,142< if (mode == MODE_INIT) {---> if (mode == MODE_INIT)> {154c144,146< } else {---> }> else> {156c148< attributes = ArrayUtil.removeFromArray(attributes, new String[] { "id", "numComment" });---> attributes = ArrayUtil.removeFromArray(attributes, new String[]{"id", "numComment"});167,168c159,160< protected ActionForward getSuccessActionForward(ActionMapping mapping, HttpServletRequest request,< HttpServletResponse response) throws Exception {---> protected ActionForward getSuccessActionForward(ActionMapping mapping, HttpServletRequest request, HttpServletResponse response) throws Exception> {171c163,164< if (request.getParameter("saveAndClose") != null) {---> if (request.getParameter("saveAndClose") != null)> {173,175d165< } else {< response.sendRedirect(UrlService.getPageUpdateUrl(page, UrlService.ABSOLUTE_CONTEXT_PATH)< + "&confirmation=common.page.save.confirmation.singular");176a167,170> else> {> response.sendRedirect(UrlService.getPageUpdateUrl(page, UrlService.ABSOLUTE_CONTEXT_PATH) + "&confirmation=common.page.save.confirmation.singular");> }180,193d173< < protected ActionForward compileLatex(ActionMapping mapping, ActionForm form, HttpServletRequest request,< HttpServletResponse response) throws Exception {< < if (!isTokenValid(request)) {< Map values = getValues(request, response);< < if (values != null) {< request.setAttribute("values", values);< // We have no errors, put an empty Map (null is not valid)< request.setAttribute("errors", new HashMap());< return mapping.findForward("init");< } else {< return mapping.findForward("generalError");195,275d174< }< < // The user is updating< Validator validator = getValidator(request, response);< validator.validate();< Map errors = validator.getErrors();< < // Ensure that what the user entered in the form is displayed< Map values = validator.getValues();< request.setAttribute("values", values);< < if (errors.size() > 0) {< request.setAttribute("errors", errors);< < return mapping.findForward("error");< } else {< < // try to compile the Latex document< Page tmpPage = (Page) validator.getObject();< < Page backup = new Page();< backup.setName(tmpPage.getName());< backup.setContent(tmpPage.getContent());< < // change name to trick PDFLatexWorker< tmpPage.setName("tmp_" + tmpPage.getName());< < // set date to force PDF compilation< tmpPage.setCreated(new Date());< < StringBuilder error = new StringBuilder();< String errorType = null;< < try {< _pdfService.getPDF(tmpPage, response, true);< < } catch (PDFServiceException e) {< errorType = e.getType();< error.append(e.getError());< < Locale locale = MessageTag.getLocale(request);< < StringBuilder ret = new StringBuilder();< ret.append("<div class=\"logError\">" + Message.get("pdfservice.compilation.error", locale) + "<br />");< < if (errorType.equals("latex-error")) {< String logUrl = e.getLogUrl();< < if (logUrl != null) {< ret.append("<br />" + Message.format("pdfservice.compilation.error.url", locale, logUrl) + "<br />");< < }< ret.append("<br /><textarea cols=\"120\" rows=\"10\">" + error.toString() + "</textarea>");< } else {< ret.append(Message.get("pdfservice.latex." + errorType, locale) + "<br />" + error.toString());< }< < ret.append("</div>");< < request.setAttribute("compileResult", ret.toString());< < // For the jsp< tmpPage.setName(tmpPage.getName().replace("tmp_", ""));< tmpPage.setContent(backup.getContent());< request.setAttribute("page", tmpPage);< < return mapping.findForward("error");< }< < // Persist the update< Page up = (Page) validator.getObject();< up.setName(backup.getName());< up.setContent(backup.getContent());< update(up, validator, request, response);< < resetToken(request);< < return getSuccessActionForward(mapping, request, response);< }< }< }