# 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. 9,12c9,18 < 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.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.*; 14,15c20,21 < import javax.servlet.http.HttpServletRequest; < import javax.servlet.http.HttpServletResponse; --- > import javax.servlet.http.*; > import java.util.*; 17,36d22 < import org.apache.struts.action.ActionForm; < import org.apache.struts.action.ActionForward; < import org.apache.struts.action.ActionMapping; < < import ch.epfl.kis.polywiki.model.Page; < import ch.epfl.kis.polywiki.model.Wiki; < import ch.epfl.kis.polywiki.security.SecurityService; < 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.service.WikiService; < 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.HttpUtil; < import com.baneo.core.validator.Validator; < import com.baneo.core.view.web.action.ObjectInsertAction; < 46c32,33 < public class PageInsertAction extends ObjectInsertAction { --- > public class PageInsertAction extends ObjectInsertAction > { 48d34 < 51c37 < private static final PDFService _pdfService = PDFService.instance(); --- > public static int _reloadCount = 0; 53,55c39,40 < 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 > { 58c43,44 < if (wiki == null) { --- > if (wiki == null) > { 64,66c50,54 < // Latex page => try to compile it first < if ("2".equals(request.getParameter("type"))) { < return compileLatex(mapping, form, request, response); --- > // check if the form was reloaded > if (request.getParameter(Constants.TOKEN_KEY) != null && !isTokenValid(request)) > { > _reloadCount++; > return mapping.findForward("reload"); 72c60,62 < protected void onInit(HttpServletRequest request, HttpServletResponse response) throws Exception { --- > protected void onInit(HttpServletRequest request, HttpServletResponse response) throws Exception > { > Map values = new HashMap(); 74,75d63 < Map values = new HashMap(); < 87c75,76 < protected Validator getValidator(HttpServletRequest request, HttpServletResponse response) throws Exception { --- > protected Validator getValidator(HttpServletRequest request, HttpServletResponse response) throws Exception > { 88a78 > 94,96c84,85 < protected void insert(Object object, Validator validator, HttpServletRequest request, HttpServletResponse response) < throws Exception { < --- > protected void insert(Object object, Validator validator, HttpServletRequest request, HttpServletResponse response) throws Exception > { 97a87 > 101,102c91,92 < protected ActionForward getSuccessActionForward(ActionMapping mapping, HttpServletRequest request, < HttpServletResponse response) throws Exception { --- > protected ActionForward getSuccessActionForward(ActionMapping mapping, HttpServletRequest request, HttpServletResponse response) throws Exception > { 105c95,96 < if (request.getParameter("saveAndClose") != null) { --- > if (request.getParameter("saveAndClose") != null) > { 107,109d97 < } else { < response.sendRedirect(UrlService.getPageUpdateUrl(page, UrlService.ABSOLUTE_CONTEXT_PATH) < + "&confirmation=common.page.save.confirmation.singular"); 110a99,102 > else > { > response.sendRedirect(UrlService.getPageUpdateUrl(page, UrlService.ABSOLUTE_CONTEXT_PATH) + "&confirmation=common.page.save.confirmation.singular"); > } 114,121d105 < < protected ActionForward compileLatex(ActionMapping mapping, ActionForm form, HttpServletRequest request, < HttpServletResponse response) throws Exception { < < if (!isTokenValid(request)) { < saveToken(request); < onInit(request, response); < return mapping.findForward(MAPPING_INIT); 123,203d106 < < // Validate the values < Validator validator = getValidator(request, response); < validator.validate(); < Map values = validator.getValues(); < Map errors = validator.getErrors(); < < // Ensure that what the user entered in the form is displayed < request.setAttribute(ATTRIBUTE_VALUES, values); < < // If there is errors, prints them back to user. < if (errors.size() > 0) { < request.setAttribute(ATTRIBUTE_ERRORS, errors); < return mapping.findForward(MAPPING_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("
" + Message.get("pdfservice.compilation.error", locale) + "
"); < < if (errorType.equals("latex-error")) { < String logUrl = e.getLogUrl(); < < if (logUrl != null) { < ret.append("
" + Message.format("pdfservice.compilation.error.url", locale, logUrl) + "
"); < < } < ret.append("
"); < } else { < ret.append(Message.get("pdfservice.latex." + errorType, locale) + "
" + error.toString()); < } < < ret.append("
"); < < 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(MAPPING_ERROR); < } < < // Insert the object < Object toInsert = validator.getObject(); < ((Page) toInsert).setName(backup.getName()); < ((Page) toInsert).setContent(backup.getContent()); < insert(toInsert, validator, request, response); < request.setAttribute(ATTRIBUTE_INSERTED_OBJECT, toInsert); < < resetToken(request); < < return getSuccessActionForward(mapping, request, response); < } < } < }