Update of /cvsroot/webmacro/wiki/src/org/tcdi/opensource/wiki/servlet In directory sc8-pr-cvs1:/tmp/cvs-serv7466a/src/org/tcdi/opensource/wiki/servlet Modified Files: DiffPageAction.java EditPageAction.java SavePageAction.java WikiServlet.java Added Files: PreviewPageAction.java Log Message: - fixed rendering issues with DiffPage - add begin() and done() notifications to the page builder - add parser/renderer supported for numbered lists - fix rendering bug with: ~~ - fix bugs where one could create a page with all lower-case letters (also cleaned up filesystem of production webserver) - add ability to Preview before Saving a page edit - cleanup "thank you for registering" page a little bit - don't show the "Diff to Previous" link if we're not actually viewing a valid page - attempt to convince WMServlet to log my exception stack traces so I can hunt down the cause of a few NPE's I've seen in the error log on the production server --- NEW FILE: PreviewPageAction.java --- package org.tcdi.opensource.wiki.servlet; import org.tcdi.opensource.wiki.WikiSystem; import org.tcdi.opensource.wiki.WikiUser; import org.tcdi.opensource.wiki.WikiPage; import org.webmacro.servlet.WebContext; import java.util.ConcurrentModificationException; import java.util.List; import java.util.ArrayList; import java.util.StringTokenizer; /** * Created by IntelliJ IDEA. * User: e_ridge * Date: Jul 2, 2003 * Time: 11:34:53 PM * To change this template use Options | File Templates. */ public class PreviewPageAction implements PageAction { /** * can only save a page if the request is POST and "?save=<pagename>" is * in the request */ public boolean accept(WikiSystem wiki, WebContext wc, WikiUser user) { // and then only accept if this is a get request return wc.getRequest().getMethod().equalsIgnoreCase("POST") && wc.getForm ("preview") != null && wc.getForm("preview").equals("true"); } /** * do the saving of the page. When we're done, we redirect to the page * so the user can view his changes. */ public void perform(WikiSystem wiki, WebContext wc, WikiUser user, WikiPage page) throws PageAction.PageActionException { if (page != null && page.getIsModerated() && !user.getIsModerator()) throw new PageActionException ("This page can only be saved by moderators"); try { String text = wc.getForm ("TEXT"); String pageName = wc.getForm ("save"); page = wiki.createPage(pageName, user.getIdentifier(), text); wiki.parsePage(page); wc.put ("Page", page); } catch (Exception e) { e.printStackTrace(); throw new PageAction.PageActionException (e.toString()); } } /** * no template for saving */ public String getTemplateName(WikiSystem wiki, WikiPage page) { return "preview.wm"; } /** * the page name is whatever is behind the "?save=<pagename>" request * parameter. */ public String getWikiPageName(WikiSystem wiki, WebContext wc) { return null; } } Index: DiffPageAction.java =================================================================== RCS file: /cvsroot/webmacro/wiki/src/org/tcdi/opensource/wiki/servlet/DiffPageAction.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DiffPageAction.java 2 Jul 2003 06:55:13 -0000 1.1 --- DiffPageAction.java 3 Jul 2003 05:20:09 -0000 1.2 *************** *** 57,78 **** public static class DiffHelper { ! private List _changes; ! public DiffHelper (Diff.change changes) { ! _changes = new ArrayList(); while (changes != null) { ! _changes.add (changes); changes = changes.link; } } ! public List getChanges() { ! return _changes; } ! public boolean isModified (int line_no) { ! for (Iterator itr = _changes.iterator(); itr.hasNext();) { Diff.change ch = (Diff.change) itr.next(); ! if (line_no < ch.line0+ch.deleted && line_no <= ch.line1 + ch.inserted && line_no >= ch.line0 && line_no >=ch.line1 && ch.deleted > 0 && ch.inserted > 0) return true; } --- 57,123 ---- public static class DiffHelper { ! private List _changeList; ! private String[] _currentLines; ! private String[] _oldLines; ! ! public DiffHelper (WikiSystem wiki, WikiPage old, WikiPage current) throws Exception { ! _currentLines = WikiUtil.delimitedToArray(wiki.getPageRenderer().render(current), "\n"); ! _oldLines = WikiUtil.delimitedToArray(wiki.getPageRenderer().render(old), "\n"); ! ! Diff diff = new Diff (_oldLines, _currentLines); ! Diff.change changes = diff.diff(Diff.forwardScript); ! ! _changeList = new ArrayList(); while (changes != null) { ! _changeList.add (changes); changes = changes.link; } } ! public String[] getCurrentLines() { ! return _currentLines; } ! public String[] getOldLines() { ! return _oldLines; ! } ! ! public List getChangeList() { ! return _changeList; ! } ! ! public boolean isStartOfDiffLeft (int line_no) { ! for (Iterator itr = _changeList.iterator(); itr.hasNext();) { Diff.change ch = (Diff.change) itr.next(); ! if (line_no == ch.line0) ! return true; ! } ! return false; ! } ! ! public boolean isStartOfDiffRight (int line_no) { ! for (Iterator itr = _changeList.iterator(); itr.hasNext();) { ! Diff.change ch = (Diff.change) itr.next(); ! if (line_no == ch.line1) ! return true; ! } ! return false; ! } ! ! public boolean isModifiedLeft (int line_no) { ! for (Iterator itr = _changeList.iterator(); itr.hasNext();) { ! Diff.change ch = (Diff.change) itr.next(); ! if (line_no >= ch.line0 && line_no < ch.line0+Math.min(ch.inserted, ch.deleted) ! && ch.inserted > 0 && ch.deleted > 0) ! return true; ! } ! return false; ! } ! public boolean isModifiedRight (int line_no) { ! for (Iterator itr = _changeList.iterator(); itr.hasNext();) { ! Diff.change ch = (Diff.change) itr.next(); ! if (line_no >= ch.line1 && line_no < ch.line1+Math.min(ch.deleted, ch.inserted) ! && ch.inserted > 0 && ch.deleted > 0) return true; } *************** *** 81,88 **** public boolean isDeleted(int line_no) { ! if (isModified(line_no)) return false; ! for (Iterator itr = _changes.iterator(); itr.hasNext();) { Diff.change ch = (Diff.change) itr.next(); if (ch.line0 + ch.deleted > line_no && ch.line0 <= line_no) --- 126,133 ---- public boolean isDeleted(int line_no) { ! if (isModifiedLeft(line_no)) return false; ! for (Iterator itr = _changeList.iterator(); itr.hasNext();) { Diff.change ch = (Diff.change) itr.next(); if (ch.line0 + ch.deleted > line_no && ch.line0 <= line_no) *************** *** 93,100 **** public boolean isInserted(int line_no) { ! if (isModified(line_no)) return false; ! for (Iterator itr = _changes.iterator(); itr.hasNext();) { Diff.change ch = (Diff.change) itr.next(); if (line_no >= ch.line1 && line_no < ch.line1 + ch.inserted) --- 138,145 ---- public boolean isInserted(int line_no) { ! if (isModifiedLeft(line_no)) return false; ! for (Iterator itr = _changeList.iterator(); itr.hasNext();) { Diff.change ch = (Diff.change) itr.next(); if (line_no >= ch.line1 && line_no < ch.line1 + ch.inserted) *************** *** 105,112 **** public int getDeleteCount(int line_no) { ! if (isModified(line_no)) return 0; ! for (Iterator itr = _changes.iterator(); itr.hasNext();) { Diff.change ch = (Diff.change) itr.next(); if (line_no == ch.line1) --- 150,157 ---- public int getDeleteCount(int line_no) { ! if (isModifiedRight(line_no)) return 0; ! for (Iterator itr = _changeList.iterator(); itr.hasNext();) { Diff.change ch = (Diff.change) itr.next(); if (line_no == ch.line1) *************** *** 116,123 **** } public int getInsertCount(int line_no) { ! if (isModified(line_no)) return 0; ! for (Iterator itr = _changes.iterator(); itr.hasNext();) { Diff.change ch = (Diff.change) itr.next(); if (line_no == ch.line0) --- 161,168 ---- } public int getInsertCount(int line_no) { ! if (isModifiedRight(line_no)) return 0; ! for (Iterator itr = _changeList.iterator(); itr.hasNext();) { Diff.change ch = (Diff.change) itr.next(); if (line_no == ch.line0) *************** *** 156,171 **** boolean is_current = tmp.getVersion() == currentPage.getVersion(); ! String[] currentPageLines = WikiUtil.delimitedToArray(currentPage.getUnparsedData(), "\n"); ! String[] oldPageLines = WikiUtil.delimitedToArray(oldPage.getUnparsedData(), "\n"); ! ! Diff diff = new Diff(oldPageLines, currentPageLines); ! Diff.change changes = diff.diff(Diff.forwardScript); wc.put ("IsCurrent", is_current); wc.put ("CurrentPage", currentPage); wc.put ("OldPage", oldPage); ! wc.put ("CurrentPageLines", currentPageLines); ! wc.put ("OldPageLines", oldPageLines); ! wc.put ("DiffHelper", new DiffHelper (changes)); } catch (Exception e) { e.printStackTrace(); --- 201,210 ---- boolean is_current = tmp.getVersion() == currentPage.getVersion(); ! DiffHelper helper = new DiffHelper (wiki, oldPage, currentPage); wc.put ("IsCurrent", is_current); wc.put ("CurrentPage", currentPage); wc.put ("OldPage", oldPage); ! wc.put ("DiffHelper", helper); } catch (Exception e) { e.printStackTrace(); Index: EditPageAction.java =================================================================== RCS file: /cvsroot/webmacro/wiki/src/org/tcdi/opensource/wiki/servlet/EditPageAction.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** EditPageAction.java 5 Jan 2002 20:27:29 -0000 1.2 --- EditPageAction.java 3 Jul 2003 05:20:09 -0000 1.3 *************** *** 74,78 **** throw new PageAction.PageActionException ("This page can only be edited by moderators"); ! wc.put ("PageName", wc.getForm ("edit")); } --- 74,80 ---- throw new PageAction.PageActionException ("This page can only be edited by moderators"); ! String pageName = wc.getForm("edit"); ! pageName = WikiUtil.formatAsWikiTitle(pageName); ! wc.put ("PageName", pageName); } Index: SavePageAction.java =================================================================== RCS file: /cvsroot/webmacro/wiki/src/org/tcdi/opensource/wiki/servlet/SavePageAction.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** SavePageAction.java 27 Nov 2002 07:06:32 -0000 1.4 --- SavePageAction.java 3 Jul 2003 05:20:09 -0000 1.5 *************** *** 94,98 **** boolean moderated = wc.getForm ("MODERATED") != null && wc.getForm("MODERATED").equals ("true"); String keywords = wc.getForm ("RELATED_TITLES"); ! String pageName = wc.getForm ("save"); // create the page --- 94,98 ---- boolean moderated = wc.getForm ("MODERATED") != null && wc.getForm("MODERATED").equals ("true"); String keywords = wc.getForm ("RELATED_TITLES"); ! String pageName = getWikiPageName(wiki, wc); // create the page *************** *** 142,146 **** */ public String getWikiPageName(WikiSystem wiki, WebContext wc) { ! return wc.getForm ("save"); } --- 142,148 ---- */ public String getWikiPageName(WikiSystem wiki, WebContext wc) { ! String pageName = wc.getForm ("save"); ! pageName = WikiUtil.formatAsWikiTitle(pageName); ! return pageName; } Index: WikiServlet.java =================================================================== RCS file: /cvsroot/webmacro/wiki/src/org/tcdi/opensource/wiki/servlet/WikiServlet.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** WikiServlet.java 2 Jul 2003 06:55:13 -0000 1.5 --- WikiServlet.java 3 Jul 2003 05:20:09 -0000 1.6 *************** *** 135,139 **** // something bad happened while performing the action // TODO: Handle error and error template ourselves ! e.printStackTrace(); throw new HandlerException (e.toString()); } finally { --- 135,139 ---- // something bad happened while performing the action // TODO: Handle error and error template ourselves ! log("Error handling request", e); throw new HandlerException (e.toString()); } finally { |