r1273 - in xwiki/trunk/src: main/java/com/xpn/xwiki main/java/com/xpn/xwiki/render/filter main/java/com/xpn/xwiki/web main/resources main/web/WEB-INF main/web/templates test/cactus/com/xpn/xwiki/test test/resources

Phung Hai Nam namphunghai at users.forge.objectweb.org
Mon Sep 4 13:25:40 CEST 2006


Author: namphunghai
Date: 2006-09-04 13:25:39 +0200 (Mon, 04 Sep 2006)
New Revision: 1273

Modified:
   xwiki/trunk/src/main/java/com/xpn/xwiki/XWiki.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/render/filter/XWikiHeadingFilter.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/web/EditAction.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/web/PreviewAction.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/web/SaveAction.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/web/ViewAction.java
   xwiki/trunk/src/main/resources/ApplicationResources.properties
   xwiki/trunk/src/main/web/WEB-INF/xwiki.cfg
   xwiki/trunk/src/main/web/templates/edit.vm
   xwiki/trunk/src/main/web/templates/editactions.vm
   xwiki/trunk/src/main/web/templates/preview.vm
   xwiki/trunk/src/main/web/templates/previewfooter.vm
   xwiki/trunk/src/main/web/templates/previewheader.vm
   xwiki/trunk/src/main/web/templates/wysiwyg.vm
   xwiki/trunk/src/test/cactus/com/xpn/xwiki/test/ServletSectionEditTest.java
   xwiki/trunk/src/test/resources/xwiki.cfg
Log:
XWIKI-174 update the code that matching with ServletSectionEditTest.java , that implement sectional editing

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/XWiki.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/XWiki.java	2006-09-04 02:31:28 UTC (rev 1272)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/XWiki.java	2006-09-04 11:25:39 UTC (rev 1273)
@@ -1,3 +1,4 @@
+
 /*
  * Copyright 2006, XpertNet SARL, and individual contributors as indicated
  * by the contributors.txt.
@@ -3949,5 +3950,11 @@
         else
           return username;
     }
+
+    public boolean hasSectionEdit(XWikiContext context) {
+        if (context.getWiki().ParamAsLong("xwiki.section.edit", 0) == 1)
+            return true;
+         else
+            return false;
+    }
 }
-

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/render/filter/XWikiHeadingFilter.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/render/filter/XWikiHeadingFilter.java	2006-09-04 02:31:28 UTC (rev 1272)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/render/filter/XWikiHeadingFilter.java	2006-09-04 11:25:39 UTC (rev 1273)
@@ -38,6 +38,8 @@
 import org.radeox.regex.MatchResult;
 
 import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.doc.XWikiDocument;
 import com.xpn.xwiki.render.XWikiRadeoxRenderEngine;
 import com.xpn.xwiki.util.TOCGenerator;
 
@@ -52,6 +54,7 @@
 	private final String TOC_DATA = "tocData";
 
 	private MessageFormat formatter;
+    private int sectionNumber = 0;
 
 
 	protected String getLocaleKey() {
@@ -71,6 +74,7 @@
 
 	public String handleMatch(MatchResult result, FilterContext context) {
 		String id = null;
+        String title = result.group(0);
 		String level = result.group(1);
 		int level_i = (level.length()+3)/2;
 		String hlevel = (level_i <= 6 ? level_i : 6)+ "";
@@ -79,6 +83,7 @@
 
 		RenderContext rcontext = context.getRenderContext();
 		XWikiContext xcontext  = ((XWikiRadeoxRenderEngine) rcontext.getRenderEngine()).getContext();
+        XWikiDocument doc = xcontext.getDoc();
 
 		// generate unique ID of the heading
 		List processedHeadings = (List) rcontext.get("processedHeadings");
@@ -108,6 +113,40 @@
 			}
 		}
 
-		return formatter.format(new Object[]{id, level.replace('.', '-'), numbering, text, hlevel});
-	}
+        Object beforeAction = xcontext.get("action");
+        boolean showEditButton = false;
+        // only show sectional edit button for view action
+        if (xcontext.getAction().equals("view"))
+            showEditButton = true;
+        if (beforeAction != null) {
+            if(!beforeAction.toString().equals("HeadingFilter")) {
+                xcontext.put("action","HeadingFilter");
+                sectionNumber = 0;
+            }
+        }
+
+        boolean accessRight = false ;
+        try {
+            accessRight = xcontext.getWiki().checkAccess("edit", doc, xcontext);
+        } catch (XWikiException e){
+            e.printStackTrace();
+        }
+
+        if (level.equals("1") || level.equals("1.1") ) {
+            if(doc.getContent().indexOf(title) != -1 && accessRight && xcontext.getWiki().hasSectionEdit(xcontext) && showEditButton) {
+                sectionNumber++;
+                String url =xcontext.getDoc().getURL("edit",xcontext);
+                String textfomat = formatter.format(new Object[]{id, level.replace('.', '-'), numbering, text, hlevel});
+                if(xcontext.getWiki().getEditorPreference(xcontext).equals("wysiwyg")) {
+                    url += "?xpage=wysiwyg&section=" + sectionNumber;
+                } else {
+                    url +="?section=" + sectionNumber;
+                }
+                textfomat += "<span style='float:right;margin-left:5px;margin-right:5px;'>&#91;<a style='text-decoration: none;' title='Edit section: "+text+"' href='"+ url+"'>"+"edit"+"</a>&#93;</span>";
+                return textfomat;
+            }
+        }
+
+        return formatter.format(new Object[]{id, level.replace('.', '-'), numbering, text, hlevel});
+    }
 }

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/web/EditAction.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/web/EditAction.java	2006-09-04 02:31:28 UTC (rev 1272)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/web/EditAction.java	2006-09-04 11:25:39 UTC (rev 1273)
@@ -29,6 +29,7 @@
 
 import com.xpn.xwiki.XWikiContext;
 import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.XWiki;
 import com.xpn.xwiki.api.Document;
 import com.xpn.xwiki.doc.XWikiDocument;
 import com.xpn.xwiki.doc.XWikiLock;
@@ -40,9 +41,19 @@
         XWikiRequest request = context.getRequest();
         String content = request.getParameter("content");
         XWikiDocument doc = context.getDoc();
+        XWiki xwiki = context.getWiki();
         XWikiForm form = context.getForm();
         VelocityContext vcontext = (VelocityContext) context.get("vcontext");
 
+         // Check for edit section
+         String sectionContent = "";
+         int sectionNumber = 0;
+         if (request.getParameter("section") != null && xwiki.hasSectionEdit(context)) {
+            sectionNumber = Integer.parseInt(request.getParameter("section"));
+            sectionContent = doc.getContentOfSection(sectionNumber);
+         }
+         vcontext.put("sectionNumber",new Integer(sectionNumber));
+
         synchronized (doc) {
             XWikiDocument tdoc = (XWikiDocument) context.get("tdoc");
             EditForm peform = (EditForm) form;
@@ -97,6 +108,11 @@
             XWikiDocument tdoc2 = (XWikiDocument) tdoc.clone();
             if (content != null && !content.equals(""))
                 tdoc2.setContent(content);
+            if(sectionContent != null && !sectionContent.equals("")){
+                if(content != null && !content.equals("")) tdoc2.setContent(content);
+                else tdoc2.setContent(sectionContent);
+                tdoc2.setTitle(doc.getDocumentSection(sectionNumber).getSectionTitle());
+            }
             context.put("tdoc", tdoc2);
             vcontext.put("tdoc", new Document(tdoc2, context));
             try{

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/web/PreviewAction.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/web/PreviewAction.java	2006-09-04 02:31:28 UTC (rev 1272)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/web/PreviewAction.java	2006-09-04 11:25:39 UTC (rev 1273)
@@ -71,6 +71,12 @@
 			XWikiDocument doc2 = (XWikiDocument) doc.clone();
 			context.put("doc", doc2);
 
+           int sectionNumber = 0;
+           if (request.getParameter("section") != null && context.getWiki().hasSectionEdit(context)) {
+               sectionNumber = Integer.parseInt(request.getParameter("section"));
+            }
+            vcontext.put("sectionNumber",new Integer(sectionNumber));
+
 			if ((language == null) || (language.equals("")) || (language.equals("default")) || (language.equals(doc.getDefaultLanguage()))) {
 				tdoc = doc2;
 				context.put("tdoc", doc2);

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/web/SaveAction.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/web/SaveAction.java	2006-09-04 02:31:28 UTC (rev 1272)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/web/SaveAction.java	2006-09-04 11:25:39 UTC (rev 1273)
@@ -32,11 +32,18 @@
 public class SaveAction extends XWikiAction {
 	public boolean save(XWikiContext context) throws XWikiException {
 		XWiki xwiki = context.getWiki();
+        XWikiRequest request = context.getRequest();
 		XWikiDocument doc = context.getDoc();
 		XWikiForm form = context.getForm();
 
 		// This is pretty useless, since contexts aren't shared between threads.
 		// It just slows down execution.
+        String title = doc.getTitle();
+        // Check save session
+        int sectionNumber = 0;
+        if (request.getParameter("section") != null && xwiki.hasSectionEdit(context)) {
+           sectionNumber = Integer.parseInt(request.getParameter("section"));
+        }
 		synchronized (doc) {
 			String language = ((EditForm) form).getLanguage();
 			// FIXME Which one should be used: doc.getDefaultLanguage or
@@ -67,7 +74,16 @@
 				}
 			}
 
-			tdoc.readFromForm((EditForm) form, context);
+            if(sectionNumber != 0 ){
+                XWikiDocument sectionDoc = (XWikiDocument)tdoc.clone();
+                sectionDoc.readFromForm((EditForm)form, context);
+                String sectionContent = sectionDoc.getContent() +"\n";
+                String content = doc.updateDocumentSection(sectionNumber, sectionContent);
+                tdoc.setContent(content);
+                tdoc.setTitle(title);
+            }else{
+		    	tdoc.readFromForm((EditForm) form, context);
+            }
 
 			// TODO: handle Author
 			String username = context.getUser();

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/web/ViewAction.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/web/ViewAction.java	2006-09-04 02:31:28 UTC (rev 1272)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/web/ViewAction.java	2006-09-04 11:25:39 UTC (rev 1273)
@@ -1,26 +1,26 @@
-/*
- * Copyright 2006, XpertNet SARL, and individual contributors as indicated
- * by the contributors.txt.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- *
- * @author namphunghai
- * @author torcq
- * @author sdumitriu
- */
+/*
+ * Copyright 2006, XpertNet SARL, and individual contributors as indicated
+ * by the contributors.txt.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *
+ * @author namphunghai
+ * @author torcq
+ * @author sdumitriu
+ */
 package com.xpn.xwiki.web;
 
 import com.xpn.xwiki.XWikiContext;
@@ -32,6 +32,7 @@
 public class ViewAction extends XWikiAction {
     public boolean action(XWikiContext context) throws XWikiException {
         XWikiRequest request = context.getRequest();
+        context.put("action","view");
         String rev = request.getParameter("rev");
         if (rev!=null) {
             String url = context.getDoc().getURL("viewrev", request.getQueryString(), context);
@@ -46,13 +47,13 @@
     }
 
     public String render(XWikiContext context) throws XWikiException {
-        handleRevision(context);
-        XWikiDocument doc = (XWikiDocument) context.get("doc");
-        String defaultTemplate = doc.getDefaultTemplate();
-        if ((defaultTemplate !=null) && (!defaultTemplate.equals(""))) {
-        	return defaultTemplate;
-        }
-        else
-        	return "view";
+        handleRevision(context);
+        XWikiDocument doc = (XWikiDocument) context.get("doc");
+        String defaultTemplate = doc.getDefaultTemplate();
+        if ((defaultTemplate !=null) && (!defaultTemplate.equals(""))) {
+        	return defaultTemplate;
+        }
+        else
+        	return "view";
     }
 }

Modified: xwiki/trunk/src/main/resources/ApplicationResources.properties
===================================================================
--- xwiki/trunk/src/main/resources/ApplicationResources.properties	2006-09-04 02:31:28 UTC (rev 1272)
+++ xwiki/trunk/src/main/resources/ApplicationResources.properties	2006-09-04 11:25:39 UTC (rev 1273)
@@ -475,4 +475,7 @@
 editObject=Objects
 editClass=Class
 editRights=Access Rights
-editHistory=History
\ No newline at end of file
+editHistory=History
+
+switchto=Switch to
+sectionEdit=Sectional Editing
\ No newline at end of file

Modified: xwiki/trunk/src/main/web/WEB-INF/xwiki.cfg
===================================================================
--- xwiki/trunk/src/main/web/WEB-INF/xwiki.cfg	2006-09-04 02:31:28 UTC (rev 1272)
+++ xwiki/trunk/src/main/web/WEB-INF/xwiki.cfg	2006-09-04 11:25:39 UTC (rev 1273)
@@ -68,4 +68,7 @@
 xwiki.authentication.ldap.UID_attr=sAMAccountName
 xwiki.authentication.ldap.fields_mapping=name=sAMAccountName,last_name=sn,first_name=givenName,fullname=displayName,email=mail,ldap_dn=dn
 
-xwiki.authentication.unauthorized_code=200
\ No newline at end of file
+xwiki.authentication.unauthorized_code=200
+
+# This parameter will activate the sectional editing
+xwiki.section.edit=1

Modified: xwiki/trunk/src/main/web/templates/edit.vm
===================================================================
--- xwiki/trunk/src/main/web/templates/edit.vm	2006-09-04 02:31:28 UTC (rev 1272)
+++ xwiki/trunk/src/main/web/templates/edit.vm	2006-09-04 11:25:39 UTC (rev 1273)
@@ -18,6 +18,12 @@
 #else
 #set($colsclass = "hide-both")
 #end
+
+#set($switchParam = "xpage=wysiwyg")
+#if ($sectionNumber != 0)
+   #set($switchParam = "xpage=wysiwyg&section=$sectionNumber")
+#end
+
 <script language="javascript" type="text/javascript" src="${request.contextPath}/tiny_mce/tiny_mce.js"></script>
 <script language="javascript" type="text/javascript" src="${request.contextPath}/wiki_editor/wiki_editor.js"></script>
 
@@ -58,7 +64,7 @@
 #end
 $msg.get("titlefield"):&nbsp;<input type="text" name="title" value="$!tdoc.title" size="60" />
 <br /><br />
-Switch to &nbsp; <span style="color: blue; cursor:pointer;" onclick="document.forms.edit.action='$doc.getURL("edit","xpage=wysiwyg")'; if (document.forms.edit.onsubmit) document.forms.edit.onsubmit(); document.forms.edit.submit(); return false;"><u>$msg.get("wysiwygeditor")</u></span>
+$msg.get("switchto") &nbsp; <span style="color: blue; cursor:pointer;" onclick="document.forms.edit.action='$doc.getURL("edit","$switchParam")'; if (document.forms.edit.onsubmit) document.forms.edit.onsubmit(); document.forms.edit.submit(); return false;"><u>$msg.get("wysiwygeditor")</u></span>
 <br />
 #includeHelp("EditWikiToolbar")
 $xwiki.getTextArea($tdoc.content)

Modified: xwiki/trunk/src/main/web/templates/editactions.vm
===================================================================
--- xwiki/trunk/src/main/web/templates/editactions.vm	2006-09-04 02:31:28 UTC (rev 1272)
+++ xwiki/trunk/src/main/web/templates/editactions.vm	2006-09-04 11:25:39 UTC (rev 1273)
@@ -10,10 +10,14 @@
        return true;
    }
 </script>
+#set($param = "")
+#if ($sectionNumber != 0)
+   #set($param = "section=$sectionNumber")
+#end
 #if ($showactions == 1)
     <a href="$doc.getURL("cancel")" onclick="document.forms.edit.action=this.href; if (document.forms.edit.onsubmit) document.forms.edit.onsubmit(); document.forms.edit.submit(); return false;" >$msg.get("cancel")</a>
     <span> | </span>
-    <a style="cursor:pointer;" onclick="document.forms.edit.action='$doc.getURL("preview")'; if (document.forms.edit.onsubmit) document.forms.edit.onsubmit();if (checkDocumentContent()) document.forms.edit.submit(); return false;" >$msg.get("preview")</a>
+    <a style="cursor:pointer;" onclick="document.forms.edit.action='$doc.getURL("preview",$param)'; if (document.forms.edit.onsubmit) document.forms.edit.onsubmit();if (checkDocumentContent()) document.forms.edit.submit(); return false;" >$msg.get("preview")</a>
     <span> | </span>
-    <a href="$doc.getURL("save")" onclick="document.forms.edit.action=this.href; if (document.forms.edit.onsubmit) document.forms.edit.onsubmit();if (checkDocumentContent()) document.forms.edit.submit(); return false;" >$msg.get("save")</a>
+    <a href="$doc.getURL("save",$param)" onclick="document.forms.edit.action=this.href; if (document.forms.edit.onsubmit) document.forms.edit.onsubmit();if (checkDocumentContent()) document.forms.edit.submit(); return false;" >$msg.get("save")</a>
 #end
\ No newline at end of file

Modified: xwiki/trunk/src/main/web/templates/preview.vm
===================================================================
--- xwiki/trunk/src/main/web/templates/preview.vm	2006-09-04 02:31:28 UTC (rev 1272)
+++ xwiki/trunk/src/main/web/templates/preview.vm	2006-09-04 11:25:39 UTC (rev 1273)
@@ -2,7 +2,7 @@
 #template("httpheader.vm")
 #template("header.vm")
 #template("previewheader.vm")
-<div id="xwikicontent">
+&nbsp;<div id="xwikicontent">
 $tdoc.getRenderedContent($tdoc.content)
 <form id="edit" method="post" action="$doc.getURL("save")">
 <p>
@@ -15,7 +15,6 @@
 <input type="hidden" name="xredirect" value="$!request.getParameter("xredirect")" />
 <input type="hidden" name="xnotification" value="$!request.getParameter("xnotification")" />
 <input type="hidden" name="language" value="$!request.getParameter("language")" />
-
 </p>
 <div id="xwikiobject">
 #template("hiddenobject.vm")

Modified: xwiki/trunk/src/main/web/templates/previewfooter.vm
===================================================================
--- xwiki/trunk/src/main/web/templates/previewfooter.vm	2006-09-04 02:31:28 UTC (rev 1272)
+++ xwiki/trunk/src/main/web/templates/previewfooter.vm	2006-09-04 11:25:39 UTC (rev 1273)
@@ -3,18 +3,22 @@
     <a href="$doc.getURL("cancel")" onclick="document.forms.edit.action=this.href; if (document.forms.edit.onsubmit) document.forms.edit.onsubmit(); document.forms.edit.submit(); return false;" >$msg.get("cancel")</a>
     <span> | </span>
     #if($doc.content.indexOf("includeForm(")!=-1)
-        #set($editaction = "inline")
+      #set($editaction = "inline")
+      #set($editparams="")
     #else
-        #set($editaction = "edit")
+      #set($editaction = "edit")
     ## Check WYSISYG editing option
-        #if($xwiki.getUserPreference("editor")=="Wysiwyg")
-            #set($editparams="xpage=wysiwyg")
-        #else
-            #set($editparams="")
-        #end
+      #if($xwiki.getUserPreference("editor")=="Wysiwyg")
+        #set($editparams="xpage=wysiwyg")
+      #else
+        #set($editparams="")
+      #end
+      #if ($sectionNumber != 0)
+        #set($editparams = "$editparams&section=$sectionNumber")
+      #end
     #end
-<a href="$doc.getURL($editaction,$editparams)"  onclick="document.forms.edit.action=this.href; document.forms.edit.submit(); return false;"> $msg.get("backtoedit")</a>
-<span> | </span>
-<a href="$doc.getURL("save")" onclick="document.forms.edit.action=this.href; document.forms.edit.submit(); return false;" >$msg.get("save")</a>
-</div>
+    <a href="$doc.getURL($editaction,$editparams)"  onclick="document.forms.edit.action=this.href; document.forms.edit.submit(); return false;"> $msg.get("backtoedit")</a>
+    <span> | </span>
+    <a href="$doc.getURL("save",$editparams)" onclick="document.forms.edit.action=this.href; document.forms.edit.submit(); return false;" >$msg.get("save")</a>
+  </div>
 </div>
\ No newline at end of file

Modified: xwiki/trunk/src/main/web/templates/previewheader.vm
===================================================================
--- xwiki/trunk/src/main/web/templates/previewheader.vm	2006-09-04 02:31:28 UTC (rev 1272)
+++ xwiki/trunk/src/main/web/templates/previewheader.vm	2006-09-04 11:25:39 UTC (rev 1273)
@@ -1,21 +1,24 @@
-<div class="xwiki${xwikimode}b" id="xwikinav_footer">
+<div class="xwiki${xwikimode}b" id="xwikinav_header">
   <div class="xwikiactions">
     <a href="$doc.getURL("cancel")" onclick="document.forms.edit.action=this.href; if (document.forms.edit.onsubmit) document.forms.edit.onsubmit(); document.forms.edit.submit(); return false;" >$msg.get("cancel")</a>
     <span> | </span>
     #if($doc.content.indexOf("includeForm(")!=-1)
-        #set($editaction = "inline")
-        #set($editparams="")
+      #set($editaction = "inline")
+      #set($editparams="")
     #else
-        #set($editaction = "edit")
+      #set($editaction = "edit")
     ## Check WYSISYG editing option
-        #if($xwiki.getUserPreference("editor")=="Wysiwyg")
-            #set($editparams="xpage=wysiwyg")
-        #else
-            #set($editparams="")
-        #end
+      #if($xwiki.getUserPreference("editor")=="Wysiwyg")
+        #set($editparams="xpage=wysiwyg")
+      #else
+        #set($editparams="")
+      #end
+      #if ($sectionNumber != 0)
+        #set($editparams = "$editparams&section=$sectionNumber")
+      #end
     #end
     <a href="$doc.getURL($editaction,$editparams)"  onclick="document.forms.edit.action=this.href; document.forms.edit.submit(); return false;"> $msg.get("backtoedit")</a>
     <span> | </span>
-    <a href="$doc.getURL("save")" onclick="document.forms.edit.action=this.href; document.forms.edit.submit(); return false;" >$msg.get("save")</a>
+    <a href="$doc.getURL("save",$editparams)" onclick="document.forms.edit.action=this.href; document.forms.edit.submit(); return false;" >$msg.get("save")</a>
   </div>
 </div>
\ No newline at end of file

Modified: xwiki/trunk/src/main/web/templates/wysiwyg.vm
===================================================================
--- xwiki/trunk/src/main/web/templates/wysiwyg.vm	2006-09-04 02:31:28 UTC (rev 1272)
+++ xwiki/trunk/src/main/web/templates/wysiwyg.vm	2006-09-04 11:25:39 UTC (rev 1273)
@@ -16,6 +16,10 @@
 #else
 #set($colsclass = "hide-both")
 #end
+#set($switchParam = "")
+#if ($sectionNumber != 0)
+   #set($switchParam = "section=$sectionNumber")
+#end
 <script language="javascript" type="text/javascript" src="${request.contextPath}/tiny_mce/tiny_mce.js"></script>
 <script language="javascript" type="text/javascript" src="${request.contextPath}/wiki_editor/wiki_editor.js"></script>
 <script language="javascript" type="text/javascript">
@@ -65,7 +69,7 @@
 #end
 $msg.get("titlefield"):&nbsp;<input type="text" name="title" value="$!tdoc.title" size="60" />
 <br /><br />
-   Switch to &nbsp; <span style="color: blue; cursor:pointer;" onclick="document.forms.edit.action='$doc.getURL("edit")';if (document.forms.edit.onsubmit) document.forms.edit.onsubmit(); document.forms.edit.submit(); return false;"><u>$msg.get("wikieditor")</u></span>
+   $msg.get("switchto") &nbsp; <span style="color: blue; cursor:pointer;" onclick="document.forms.edit.action='$doc.getURL("edit","$switchParam")';if (document.forms.edit.onsubmit) document.forms.edit.onsubmit(); document.forms.edit.submit(); return false;"><u>$msg.get("wikieditor")</u></span>
 <br />
 $xwiki.getTextArea($tdoc.content)
 <br/>

Modified: xwiki/trunk/src/test/cactus/com/xpn/xwiki/test/ServletSectionEditTest.java
===================================================================
--- xwiki/trunk/src/test/cactus/com/xpn/xwiki/test/ServletSectionEditTest.java	2006-09-04 02:31:28 UTC (rev 1272)
+++ xwiki/trunk/src/test/cactus/com/xpn/xwiki/test/ServletSectionEditTest.java	2006-09-04 11:25:39 UTC (rev 1273)
@@ -20,6 +20,7 @@
 package com.xpn.xwiki.test;
 
 import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.XWiki;
 import com.xpn.xwiki.store.XWikiHibernateStore;
 import com.xpn.xwiki.doc.XWikiDocument;
 import com.xpn.xwiki.objects.BaseObject;
@@ -42,6 +43,39 @@
         super.cleanUp();
     }
 
+    // Check if the "Edit" button for a section is present
+    public void beginPresentEdit(WebRequest webRequest) throws HibernateException, XWikiException {
+        XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
+        StoreHibernateTest.cleanUp(hibstore, context);
+        clientSetUp(hibstore);
+
+        XWikiDocument doc = new XWikiDocument();
+        Utils.prepareObject(doc, "Main.PresentSectionEditTest");
+        BaseClass bclass = doc.getxWikiClass();
+        BaseObject bobject = doc.getObject(bclass.getName(), 0);
+
+        String content = "1 This is title 1\nThis is content of title 1\n1.1 This is the subtitle 1\nThis is content of subtitle 1\n1.1 This is the subtitle 2\nThis is content of subtitle 2\n1 This is the title 2\nThis is the content of title 2";
+        Utils.createDoc(xwiki.getStore(), "Main", "PresentSectionEditTest", content, bobject, bclass, context);
+
+        setUrl(webRequest, "view", "Main", "PresentSectionEditTest", "");
+    }
+
+    public void endPresentEdit(WebResponse webResponse) throws HibernateException {
+        try {
+            String result = webResponse.getText();
+            assertTrue("Content should have edit button for title 1 : " + result, result.indexOf("<a style='text-decoration: none;' title='Edit section: This is title 1' href='/xwiki/testbin/edit/Main/PresentSectionEditTest?section=1'>edit</a>") != -1);
+            assertTrue("Content should have edit button for subtitle 1 : " + result, result.indexOf("<a style='text-decoration: none;' title='Edit section: This is the subtitle 1' href='/xwiki/testbin/edit/Main/PresentSectionEditTest?section=2'>edit</a>") != -1);
+            assertTrue("Content should have edit button for subtitle 2 : " + result, result.indexOf("<a style='text-decoration: none;' title='Edit section: This is the subtitle 2' href='/xwiki/testbin/edit/Main/PresentSectionEditTest?section=3'>edit</a>") != -1);
+            assertTrue("Content should have edit button for title2 : " + result, result.indexOf("<a style='text-decoration: none;' title='Edit section: This is the title 2' href='/xwiki/testbin/edit/Main/PresentSectionEditTest?section=4'>edit</a>") != -1);
+        } finally {
+            clientTearDown();
+        }
+    }
+
+    public void testPresentEdit() throws Throwable {
+        launchTest();
+    }
+
     /** Test edit section for title 1 */
     public void beginSectionEditTitle1(WebRequest webRequest) throws HibernateException, XWikiException {
         XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
@@ -54,7 +88,7 @@
 
         String content = "1 This is title 1\nThis is content of title 1\n1.1 This is the subtitle 1\nThis is content of subtitle 1\n1 This is the title 2\nThis is the content of title 2";
         Utils.createDoc(xwiki.getStore(), "Main", "SectionEditTest", content, bobject, bclass, context);
-        setUrl(webRequest, "edit", "SectionEditTest", "section=1");
+        setUrl(webRequest, "edit", "Main", "SectionEditTest", "section=1");
     }
 
     public void endSectionEditTitle1(WebResponse webResponse) throws HibernateException {
@@ -64,7 +98,7 @@
             assertTrue("Find out the contents of title 2 :" + result, result.indexOf("1 This is the title 2\nThis is the content of title 2") == -1);
        } finally {
             clientTearDown();
-        }
+       }
     }
 
     public void testSectionEditTitle1() throws Throwable {
@@ -83,13 +117,13 @@
 
         String content = "1 This is title 1\nThis is content of title 1\n1.1 This is the subtitle 1\nThis is content of subtitle 1\n1.1 This is the subtitle 2\nThis is content of subtitle 2\n1 This is the title 2\nThis is the content of title 2";
         Utils.createDoc(xwiki.getStore(), "Main", "SectionEditTest", content, bobject, bclass, context);
-        setUrl(webRequest, "edit", "SectionEditTest", "section=2");
+        setUrl(webRequest, "edit", "Main", "SectionEditTest", "section=2");
     }
 
     public void endSectionEditSubtitle1(WebResponse webResponse) throws HibernateException {
         try {
             String result = webResponse.getText();
-            assertTrue("Could not find the contents of title 1 : " + result, result.indexOf("1.1 This is the subtitle 1\nThis is content of subtitle 1") != -1);
+            assertTrue("Could not find the contents of subtitle 1 : " + result, result.indexOf("1.1 This is the subtitle 1\nThis is content of subtitle 1") != -1);
             assertTrue("Find out the contents of title 1 :" + result, result.indexOf("1 This is title 1\nThis is content of title 1") == -1);
             assertTrue("Find out the contents of subtitle 2 :" + result, result.indexOf("1.1 This is the subtitle 2\nThis is content of subtitle 2") == -1);
             assertTrue("Find out the contents of title 2 :" + result, result.indexOf("1 This is title 2\nThis is content of title 2") == -1);
@@ -98,7 +132,7 @@
         }
     }
 
-    public void testSectionEditSubtitle11() throws Throwable {
+    public void testSectionEditSubtitle1() throws Throwable {
         launchTest();
     }
 
@@ -112,24 +146,24 @@
         BaseClass bclass = doc.getxWikiClass();
         BaseObject bobject = doc.getObject(bclass.getName(), 0);
 
-        String content = "1 This is title 1\nThis is content of title 1\n1.1 This is the subtitle 1\nThis is content of subtitle 1\n1.1 This is subtitle2\nThis is the content of subtitle 2\n1 This is the title 2\nThis is the content of title 2";
+        String content = "1 This is title 1\nThis is content of title 1\n1.1 This is the subtitle 1\nThis is content of subtitle 1\n1.1 This is subtitle 2\nThis is the content of subtitle 2\n1 This is the title 2\nThis is the content of title 2";
         Utils.createDoc(xwiki.getStore(), "Main", "SectionEditTest", content, bobject, bclass, context);
-        setUrl(webRequest, "edit", "SectionEditTest", "section=3");
+        setUrl(webRequest, "edit", "Main", "SectionEditTest", "section=3");
     }
 
     public void endSectionEditSubtitle2(WebResponse webResponse) throws HibernateException {
         try {
             String result = webResponse.getText();
-            assertTrue("Could not find the contents of title 1 : " + result, result.indexOf("1.1 This is the subtitle 2\nThis is content of subtitle 2") != -1);
-            assertTrue("Find out the contents of title 1 :" + result, result.indexOf("1 This is title 1\nThis is content of title 1") == -1);
-            assertTrue("Find out the contents of subtile 1:" + result, result.indexOf("1.1 This is the subtitle 1\nThis is content of subtitle 1") == -1);
-            assertTrue("Find out the contents of title 2 :" + result, result.indexOf("1 This is title 2\nThis is content of title 2") == -1);
+            assertTrue("Could not find the contents of sub title 2 : " + result, result.indexOf("1.1 This is subtitle 2\nThis is the content of subtitle 2") != -1);
+            assertFalse("Find out the contents of title 1 :" + result, result.indexOf("1 This is title 1\nThis is content of title 1") != -1);
+            assertFalse("Find out the contents of subtile 1:" + result, result.indexOf("1.1 This is the subtitle 1\nThis is content of subtitle 1") != -1);
+            assertFalse("Find out the contents of title 2 :" + result, result.indexOf("1 This is title 2\nThis is content of title 2") != -1);
         } finally {
             clientTearDown();
         }
     }
 
-    public void testSectionEditSubtitle12() throws Throwable {
+    public void testSectionEditSubtitle2() throws Throwable {
         launchTest();
     }
 
@@ -143,15 +177,15 @@
         BaseClass bclass = doc.getxWikiClass();
         BaseObject bobject = doc.getObject(bclass.getName(), 0);
 
-        String content = "1 This is title 1\nThis is content of title 1\n1.1 This is the subtitle 1\nThis is content of subtitle 1\n1.1 This is subtitle2\nThis is the content of subtitle 2\n1 This is the title 2\nThis is the content of title 2";
+        String content = "1 This is title 1\nThis is content of title 1\n1.1 This is the subtitle 1\nThis is content of subtitle 1\n1.1 This is subtitle 2\nThis is the content of subtitle 2\n1 This is the title 2\nThis is the content of title 2";
         Utils.createDoc(xwiki.getStore(), "Main", "SectionEditTest", content, bobject, bclass, context);
-        setUrl(webRequest, "edit", "SectionEditTest", "section=4");
+        setUrl(webRequest, "edit", "Main", "SectionEditTest", "section=4");
     }
 
-    public void endSectionEditTitle12(WebResponse webResponse) throws HibernateException {
+    public void endSectionEditTitle2(WebResponse webResponse) throws HibernateException {
         try {
             String result = webResponse.getText();
-            assertTrue("Could not find the contents of title 1 : " + result, result.indexOf("1 This is the title 2\nThis is the content of title 2") != -1);
+            assertTrue("Could not find the contents of title 2 : " + result, result.indexOf("1 This is the title 2\nThis is the content of title 2") != -1);
             assertTrue("Find out the contents of title 1 :" + result, result.indexOf("1 This is title 1\nThis is content of title 1") == -1);
             assertTrue("Find out the contents of subtile 1:" + result, result.indexOf("1.1 This is the subtitle 1\nThis is content of subtitle 1") == -1);
             assertTrue("Find out the contents of subtitle 2 :" + result, result.indexOf("1.1 This is subtitle 2\nThis is content of subtitle 2") == -1);
@@ -218,7 +252,7 @@
         Utils.createDoc(xwiki.getStore(), "Main", "SaveSectionTest", content, bobject, bclass, context);
 
         // Save section 1 with new content.
-        setUrl(webRequest, "save", "SaveSectionTest", "section=2");
+        setUrl(webRequest, "save", "Main", "SaveSectionTest", "section=2");
         webRequest.addParameter("content", "This is modification");
         webRequest.addParameter("parent", "Main.WebHome");
     }
@@ -263,51 +297,16 @@
     }
 
     public void endPreviewSection(WebResponse webResponse) throws HibernateException, XWikiException {
-         try {
-            String result = webResponse.getText();
-            assertTrue("Could not find PreviewSectionTest's Content: " + result, result.indexOf("This is modification\n1 This is the title 2\nThis is the content of title 2") != -1);
-            assertTrue("Could not find object hidden form value: " + result, result.indexOf("Main.PreviewSectionTest_0_first_name") != -1);
-        } finally {
-            clientTearDown();
-        }
-    }
-
-    public void testPreviewSectionOk() throws Throwable {
-        launchTest();
-    }
-
-    // Check if the "Edit" button for a section is present
-    public void beginPresentEdit(WebRequest webRequest) throws HibernateException, XWikiException {
-        XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
-        context.setDatabase("xwikitest");
-        StoreHibernateTest.cleanUp(hibstore, context);
-        clientSetUp(hibstore);
-
-        XWikiDocument doc = new XWikiDocument();
-        Utils.prepareObject(doc, "Main.PreviewSectionTest");
-        BaseClass bclass = doc.getxWikiClass();
-        BaseObject bobject = doc.getObject(bclass.getName(), 0);
-
-        String content = "1 This is title 1\nThis is content of title 1\n1.1 This is the subtitle 1\nThis is content of subtitle 1\n1.1 This is the subtitle 2\nThis is content of subtitle 2\n1 This is the title 2\nThis is the content of title 2";
-        Utils.createDoc(xwiki.getStore(), "Main", "PresentSectionEditTest", content, bobject, bclass, context);
-
-        Utils.updateRight(xwiki, context, "XWiki.PresentSectionEditTest", "XWiki.LudovicDubost","","edit", true, true);
-        setUrl(webRequest, "view", "Main", "PresentSectionEditTest", "");
-    }
-
-    public void endPresentEdit(WebResponse webResponse) throws HibernateException {
         try {
             String result = webResponse.getText();
-            assertTrue("Content should have edit button for title 1 : " + result, result.indexOf("<a style='text-decoration: none;' title='Edit section: This is title 1' href='/xwiki/testbin/edit/Main/PresentSectionEditTest?section=1'>edit</a>") != -1);
-            assertTrue("Content should have edit button for subtitle 1 : " + result, result.indexOf("<a style='text-decoration: none;' title='Edit section: This is the subtitle 1' href='/xwiki/testbin/edit/Main/PresentSectionEditTest?section=2'>edit</a>") != -1);
-            assertTrue("Content should have edit button for subtitle 2 : " + result, result.indexOf("<a style='text-decoration: none;' title='Edit section: This is the subtitle 2' href='/xwiki/testbin/edit/Main/PresentSectionEditTest?section=3'>edit</a>") != -1);
-            assertTrue("Content should have edit button for title2 : " + result, result.indexOf("<a style='text-decoration: none;' title='Edit section: This is the title 2' href='/xwiki/testbin/edit/Main/PresentSectionEditTest?section=4'>edit</a>") != -1);
+            assertTrue("Could not find link back to edit with valid section : " + result, result.indexOf("<a href=\"/xwiki/testbin/edit/Main/PreviewSectionTest?&section=1") != -1);
+            assertTrue("Could not find content hidden form value: " + result, result.indexOf("<input type=\"hidden\" name=\"content\" value=\"This is modification\" />") != -1);
         } finally {
             clientTearDown();
         }
     }
 
-    public void testPresentEdit() throws Throwable {
+    public void testPreviewSection() throws Throwable {
         launchTest();
     }
 }

Modified: xwiki/trunk/src/test/resources/xwiki.cfg
===================================================================
--- xwiki/trunk/src/test/resources/xwiki.cfg	2006-09-04 02:31:28 UTC (rev 1272)
+++ xwiki/trunk/src/test/resources/xwiki.cfg	2006-09-04 11:25:39 UTC (rev 1273)
@@ -26,3 +26,5 @@
 xwiki.authentication.encryptionKey=titititititititititititititititi
 xwiki.authentication.cookiedomains=xwiki.com,wiki.fr
 
+# This parameter will activate the sectional editing
+xwiki.section.edit=1





More information about the Xwiki-notifications mailing list