r954 - in xwiki/trunk/src: main/java/com/xpn/xwiki main/java/com/xpn/xwiki/api main/java/com/xpn/xwiki/doc main/java/com/xpn/xwiki/web main/resources main/web/WEB-INF main/web/templates test/cactus/com/xpn/xwiki/test

Nguyen Viet Chung chungnv at users.forge.objectweb.org
Thu Mar 2 08:40:00 CET 2006


Author: chungnv
Date: 2006-03-02 08:39:59 +0100 (Thu, 02 Mar 2006)
New Revision: 954

Modified:
   xwiki/trunk/src/main/java/com/xpn/xwiki/XWiki.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/api/XWiki.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/web/CommentAddAction.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/web/ViewrevAction.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/web/XWikiAction.java
   xwiki/trunk/src/main/resources/ApplicationResources.properties
   xwiki/trunk/src/main/web/WEB-INF/struts-config.xml
   xwiki/trunk/src/main/web/WEB-INF/xwiki.cfg
   xwiki/trunk/src/main/web/templates/exception.vm
   xwiki/trunk/src/test/cactus/com/xpn/xwiki/test/ViewEditTest.java
Log:
Added AddComment control on existance of page #XWIKI-211
Added redirection for the wiki that does not exist error
Added checking existance of revision of a document
Added getComments and parseMessage APIs

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/XWiki.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/XWiki.java	2006-03-01 16:23:18 UTC (rev 953)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/XWiki.java	2006-03-02 07:39:59 UTC (rev 954)
@@ -30,60 +30,6 @@
 
 package com.xpn.xwiki;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.io.UnsupportedEncodingException;
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLEncoder;
-import java.text.DateFormatSymbols;
-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 java.util.ResourceBundle;
-import java.util.Set;
-import java.util.Vector;
-import java.util.zip.ZipOutputStream;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.UsernamePasswordCredentials;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.commons.lang.RandomStringUtils;
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.commons.net.smtp.SMTPClient;
-import org.apache.commons.net.smtp.SMTPReply;
-import org.apache.ecs.Filter;
-import org.apache.ecs.filter.CharacterFilter;
-import org.apache.ecs.xhtml.textarea;
-import org.apache.velocity.VelocityContext;
-import org.exoplatform.container.PortalContainer;
-import org.exoplatform.container.RootContainer;
-import org.hibernate.HibernateException;
-import org.securityfilter.filter.URLPatternMatcher;
-
 import com.xpn.xwiki.api.Api;
 import com.xpn.xwiki.api.Document;
 import com.xpn.xwiki.api.User;
@@ -121,13 +67,46 @@
 import com.xpn.xwiki.user.impl.xwiki.XWikiAuthServiceImpl;
 import com.xpn.xwiki.user.impl.xwiki.XWikiGroupServiceImpl;
 import com.xpn.xwiki.user.impl.xwiki.XWikiRightServiceImpl;
-import com.xpn.xwiki.util.Util;
 import com.xpn.xwiki.util.MenuSubstitution;
+import com.xpn.xwiki.util.Util;
 import com.xpn.xwiki.web.*;
-import com.xpn.xwiki.web.XWikiURLFactoryService;
-import com.xpn.xwiki.web.XWikiURLFactoryServiceImpl;
 import com.xpn.xwiki.web.includeservletasstring.IncludeServletAsString;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.lang.RandomStringUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.net.smtp.SMTPClient;
+import org.apache.commons.net.smtp.SMTPReply;
+import org.apache.ecs.Filter;
+import org.apache.ecs.filter.CharacterFilter;
+import org.apache.ecs.xhtml.textarea;
+import org.apache.velocity.VelocityContext;
+import org.exoplatform.container.PortalContainer;
+import org.exoplatform.container.RootContainer;
+import org.hibernate.HibernateException;
+import org.securityfilter.filter.URLPatternMatcher;
 
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.*;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLEncoder;
+import java.text.DateFormatSymbols;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.util.zip.ZipOutputStream;
+
 public class XWiki implements XWikiDocChangeNotificationInterface, XWikiInterface {
     private static final Log log = LogFactory.getLog(XWiki.class);
 
@@ -165,7 +144,8 @@
        each request ...
     */
     private static String configPath = null;
-    private static String getConfigPath () throws NamingException {
+
+    private static String getConfigPath() throws NamingException {
         if (configPath == null) {
             try {
                 Context envContext = (Context) new InitialContext().lookup("java:comp/env");
@@ -173,15 +153,15 @@
             } catch (Exception e) {
                 // Allow a config path from WEB-INF
                 if (log.isInfoEnabled())
-                 log.info("xwiki.cfg taken from /WEB-INF/xwiki.cfg because the XWikiConfig variable is not set in the context");
+                    log.info("xwiki.cfg taken from /WEB-INF/xwiki.cfg because the XWikiConfig variable is not set in the context");
                 configPath = "/WEB-INF/xwiki.cfg";
             }
 
         }
         return configPath;
-   }
+    }
 
-   public static XWiki getMainXWiki(XWikiContext context) throws XWikiException {
+    public static XWiki getMainXWiki(XWikiContext context) throws XWikiException {
         String xwikicfg = null;
         String xwikiname = "xwiki";
         XWiki xwiki = null;
@@ -195,7 +175,7 @@
 
                 // first try to load the file pointed by the given path
                 // if it does not exist, look for it relative to the classpath
-                File f = new File (xwikicfg);
+                File f = new File(xwikicfg);
                 if (f.exists()) {
                     xwikicfgis = new FileInputStream(f);
                 } else {
@@ -232,9 +212,10 @@
     public synchronized void updateDatabase(String appname, XWikiContext context) throws HibernateException, XWikiException {
         updateDatabase(appname, false, context);
     }
+
     public synchronized void updateDatabase(String appname, boolean force, XWikiContext context) throws HibernateException, XWikiException {
         String database = context.getDatabase();
-        
+
         try {
             List wikilist = getVirtualWikiList();
             context.setDatabase(appname);
@@ -292,8 +273,8 @@
                 String servername = (i1 != -1) ? host.substring(0, i1) : host;
 
                 XWikiURLFactory urlf = context.getURLFactory();
-                if ((urlf!=null)&&(urlf instanceof XWikiServletURLFactory)
-                        &&("".equals(((XWikiServletURLFactory)urlf).getServletPath())))
+                if ((urlf != null) && (urlf instanceof XWikiServletURLFactory)
+                        && ("".equals(((XWikiServletURLFactory) urlf).getServletPath())))
                     appname = "xwiki";
                 else
                     appname = uri.substring(1, uri.indexOf("/", 2));
@@ -488,7 +469,7 @@
             getStatsService(context);
         }
 
-        String ro = Param ("xwiki.readonly", "no");
+        String ro = Param("xwiki.readonly", "no");
 
         isReadOnly = ("yes".equalsIgnoreCase(ro) || "true".equalsIgnoreCase(ro) || "1".equalsIgnoreCase(ro));
 
@@ -676,7 +657,7 @@
             if (revision.equals("1.1") || revision.equals("1.0"))
                 newdoc = new XWikiDocument(doc.getWeb(), doc.getName());
             else {
-                throw e;                
+                throw e;
             }
         }
         return newdoc;
@@ -721,14 +702,13 @@
         String web, name;
         int i1 = 0;
         int i2;
-        if (StringUtils.countMatches(path, "/")>2)
-         i1 = path.indexOf("/", 1);
+        if (StringUtils.countMatches(path, "/") > 2)
+            i1 = path.indexOf("/", 1);
 
-        if (StringUtils.countMatches(path, "/")>1) {
-         i2 = path.indexOf("/", i1 + 1);
-         web = path.substring(i1 + 1, i2);
-        }
-        else {
+        if (StringUtils.countMatches(path, "/") > 1) {
+            i2 = path.indexOf("/", i1 + 1);
+            web = path.substring(i1 + 1, i2);
+        } else {
             i2 = 0;
             web = context.getWiki().getDefaultWeb(context);
         }
@@ -877,7 +857,7 @@
 
     public String parseContent(String content, XWikiContext context) {
         if ((content != null) && (!content.equals("")))
-        // Let's use this template
+            // Let's use this template
             return XWikiVelocityRenderer.evaluate(content, context.getDoc().getFullName(), (VelocityContext) context.get("vcontext"), context);
         else
             return "";
@@ -957,17 +937,15 @@
         HttpServletRequest servletRequest = xwikiContext.getRequest();
         HttpServletResponse servletResponse = xwikiContext.getResponse();
 
-        try
-        {
+        try {
             return IncludeServletAsString.invokeServletAndReturnAsString(
                     url,
                     servletRequest,
                     servletResponse);
         }
-        catch(Exception e)
-        {
-            log.warn("Exception including url: "+url, e);
-            return "Exception including \""+url+"\", see logs for details.";
+        catch (Exception e) {
+            log.warn("Exception including url: " + url, e);
+            return "Exception including \"" + url + "\", see logs for details.";
         }
 
     }
@@ -1534,7 +1512,7 @@
         }
 
         String menu = doc.getStringValue("XWiki.XWikiPreferences", "menu");
-        if (menu.indexOf("../..")!=-1) {
+        if (menu.indexOf("../..") != -1) {
             MenuSubstitution msubst = new MenuSubstitution(context.getUtil());
             menu = msubst.substitute(menu);
             doc.setStringValue("XWiki.XWikiPreferences", "menu", menu);
@@ -1965,7 +1943,9 @@
     }
 
     public User getUser(XWikiContext context) {
-        return null;
+        XWikiUser xwikiUser = context.getXWikiUser();
+        User user = new User(xwikiUser, context);
+        return user;
     }
 
     public void prepareResources(XWikiContext context) {
@@ -1979,11 +1959,11 @@
             XWikiMessageTool msg = new XWikiMessageTool(bundle);
             context.put("msg", msg);
             VelocityContext vcontext = ((VelocityContext) context.get("vcontext"));
-            if (vcontext!=null)
+            if (vcontext != null)
                 vcontext.put("msg", msg);
             Map gcontext = (Map) context.get("gcontext");
             if (gcontext != null)
-            	gcontext.put("msg", msg);
+                gcontext.put("msg", msg);
         }
     }
 
@@ -2345,20 +2325,23 @@
 
             // User does not exist
             if (userdoc.isNew()) {
-                if (log.isErrorEnabled()) log.error("Wiki creation (" + wikiName + "," + wikiUrl + "," + wikiAdmin + ") failed: " + "user does not exist");
+                if (log.isErrorEnabled())
+                    log.error("Wiki creation (" + wikiName + "," + wikiUrl + "," + wikiAdmin + ") failed: " + "user does not exist");
                 return -2;
             }
 
             // User is not active
             if (!(userdoc.getIntValue("XWiki.XWikiUsers", "active") == 1)) {
-                if (log.isErrorEnabled()) log.error("Wiki creation (" + wikiName + "," + wikiUrl + "," + wikiAdmin + ") failed: " + "user is not active");
+                if (log.isErrorEnabled())
+                    log.error("Wiki creation (" + wikiName + "," + wikiUrl + "," + wikiAdmin + ") failed: " + "user is not active");
                 return -3;
             }
 
 
             String wikiForbiddenList = Param("xwiki.virtual.reserved_wikis");
             if (Util.contains(wikiName, wikiForbiddenList, ", ")) {
-                if (log.isErrorEnabled()) log.error("Wiki creation (" + wikiName + "," + wikiUrl + "," + wikiAdmin + ") failed: " + "wiki name is forbidden");
+                if (log.isErrorEnabled())
+                    log.error("Wiki creation (" + wikiName + "," + wikiUrl + "," + wikiAdmin + ") failed: " + "wiki name is forbidden");
                 return -4;
             }
 
@@ -2380,9 +2363,11 @@
                 // If we are not allowed to continue if server page already exists
 
                 if (failOnExist) {
-                    if (log.isErrorEnabled()) log.error("Wiki creation (" + wikiName + "," + wikiUrl + "," + wikiAdmin + ") failed: " + "wiki server page already exists");
+                    if (log.isErrorEnabled())
+                        log.error("Wiki creation (" + wikiName + "," + wikiUrl + "," + wikiAdmin + ") failed: " + "wiki server page already exists");
                     return -5;
-                } else if (log.isWarnEnabled()) log.warn("Wiki creation (" + wikiName + "," + wikiUrl + "," + wikiAdmin + ") failed: " + "wiki server page already exists");
+                } else if (log.isWarnEnabled())
+                    log.warn("Wiki creation (" + wikiName + "," + wikiUrl + "," + wikiAdmin + ") failed: " + "wiki server page already exists");
 
             }
 
@@ -2410,7 +2395,6 @@
                 return -6;
             }
 
-
             // Copy base wiki
             int nb = copyWiki(baseWikiName, wikiName, wikilanguage, context);
             // Save the number of docs copied in the context
@@ -2683,7 +2667,8 @@
                 else
                     authService = new XWikiAuthServiceImpl();
 
-                if (log.isDebugEnabled()) log.debug("Initialized AuthService " + authService.getClass().getName() + " using 'new'.");
+                if (log.isDebugEnabled())
+                    log.debug("Initialized AuthService " + authService.getClass().getName() + " using 'new'.");
 
             }
         }
@@ -2718,7 +2703,8 @@
 
                 rightService = new XWikiRightServiceImpl();
 
-                if (log.isDebugEnabled()) log.debug("Initialized RightService " + authService.getClass().getName() + " using 'new'.");
+                if (log.isDebugEnabled())
+                    log.debug("Initialized RightService " + authService.getClass().getName() + " using 'new'.");
 
             }
         }
@@ -2741,33 +2727,29 @@
         return statsService;
     }
 
-    public XWikiURLFactoryService getURLFactoryService()
-    {
-        if (urlFactoryService == null)
-        {
+    public XWikiURLFactoryService getURLFactoryService() {
+        if (urlFactoryService == null) {
 
             log.info("Initializing URLFactory Service...");
 
             String urlFactoryServiceClass = Param("xwiki.urlfactory.serviceclass");
 
-            if (urlFactoryServiceClass != null)
-            {
-                try
-                {
-                    if (log.isDebugEnabled()) log.debug("Using custom URLFactory Service Class " + urlFactoryServiceClass + ".");
+            if (urlFactoryServiceClass != null) {
+                try {
+                    if (log.isDebugEnabled())
+                        log.debug("Using custom URLFactory Service Class " + urlFactoryServiceClass + ".");
                     urlFactoryService = (XWikiURLFactoryService) Class.forName(urlFactoryServiceClass).newInstance();
                     urlFactoryService.init(this);
                     log.debug("Initialized URLFactory Service using Reflection.");
                 }
-                catch (Exception e)
-                {
+                catch (Exception e) {
                     urlFactoryService = null;
                     log.warn("Failed to initialize URLFactory Service  " + urlFactoryServiceClass + " using Reflection, trying default implementation using 'new'.", e);
                 }
             }
-            if (urlFactoryService == null)
-            {
-                if (log.isDebugEnabled()) log.debug("Using default URLFactory Service Class " + urlFactoryServiceClass + ".");
+            if (urlFactoryService == null) {
+                if (log.isDebugEnabled())
+                    log.debug("Using default URLFactory Service Class " + urlFactoryServiceClass + ".");
                 urlFactoryService = new XWikiURLFactoryServiceImpl();
                 urlFactoryService.init(this);
             }
@@ -2857,7 +2839,7 @@
         if (newFullName)
             return "doc.fullName";
 
-        if (fullNameSQL==null) {
+        if (fullNameSQL == null) {
             if (isMySQL())
                 fullNameSQL = "CONCAT(doc.web,'.',doc.name)";
             else
@@ -3054,7 +3036,6 @@
         XWiki.threadMap = threadMap;
     }
 
-
     /*  public XWikiExecutionInfo getExecutionInfo(XWikiContext context) {
         Thread thread = Thread.currentThread();
         XWikiExecutionInfo info = getThreadMap().get(thread);
@@ -3238,20 +3219,19 @@
      * accessor for the isReadOnly instance var.
      *
      * @see #isReadOnly
-     *
      */
-    public boolean isReadOnly () {
+    public boolean isReadOnly() {
         return isReadOnly;
     }
 
-    public void setReadOnly (boolean readOnly) {
+    public void setReadOnly(boolean readOnly) {
         isReadOnly = readOnly;
     }
 
     public void deleteAllDocuments(XWikiDocument doc, XWikiContext context) throws XWikiException {
         // Delete all documents
         List list = doc.getTranslationList(context);
-        for (int i=0;i<list.size();i++) {
+        for (int i = 0; i < list.size(); i++) {
             String lang = (String) list.get(i);
             XWikiDocument tdoc = doc.getTranslatedDocument(lang, context);
             deleteDocument(tdoc, context);
@@ -3259,11 +3239,11 @@
         deleteDocument(doc, context);
     }
 
-    public void refreshLinks(XWikiContext context)throws XWikiException{
-       // refreshes all Links of each doc of the wiki
+    public void refreshLinks(XWikiContext context) throws XWikiException {
+        // refreshes all Links of each doc of the wiki
         List docs = this.search("select doc.fullName from XWikiDocument as doc", context);
-        for (int i=0;i<docs.size();i++){
-            XWikiDocument myDoc = this.getDocument((String)docs.get(i), context);
+        for (int i = 0; i < docs.size(); i++) {
+            XWikiDocument myDoc = this.getDocument((String) docs.get(i), context);
             myDoc.getStore().saveLinks(myDoc, context, true);
         }
     }
@@ -3319,7 +3299,7 @@
             return dweb;
     }
 
-    public XWikiDocument renamePage (XWikiDocument doc, XWikiContext context, String newFullName) throws XWikiException {
+    public XWikiDocument renamePage(XWikiDocument doc, XWikiContext context, String newFullName) throws XWikiException {
         XWikiDocument renamedDoc = doc.renameDocument(newFullName, context);
         saveDocument(renamedDoc, context);
         deleteDocument(doc, context);
@@ -3334,7 +3314,7 @@
     public String getEditorPreference(XWikiContext context) {
         String pref = getUserPreference("editor", context);
         if (pref.equals(""))
-         pref = Param("xwiki.editor", "");
+            pref = Param("xwiki.editor", "");
         return pref.toLowerCase();
     }
 }

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/api/XWiki.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/api/XWiki.java	2006-03-01 16:23:18 UTC (rev 953)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/api/XWiki.java	2006-03-02 07:39:59 UTC (rev 954)
@@ -28,13 +28,6 @@
 
 package com.xpn.xwiki.api;
 
-import java.awt.image.BufferedImage;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.*;
-
-import org.apache.commons.jrcs.diff.Chunk;
-
 import com.sun.image.codec.jpeg.JPEGCodec;
 import com.sun.image.codec.jpeg.JPEGImageEncoder;
 import com.xpn.xwiki.XWikiContext;
@@ -44,13 +37,20 @@
 import com.xpn.xwiki.stats.api.XWikiStatsService;
 import com.xpn.xwiki.stats.impl.DocumentStats;
 import com.xpn.xwiki.web.Utils;
+import com.xpn.xwiki.web.XWikiMessageTool;
+import org.apache.commons.jrcs.diff.Chunk;
 
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.*;
+
 public class XWiki extends Api {
     private com.xpn.xwiki.XWiki xwiki;
 
     public XWiki(com.xpn.xwiki.XWiki xwiki, XWikiContext context) {
-       super(context);
-       this.xwiki = xwiki;
+        super(context);
+        this.xwiki = xwiki;
     }
 
     public com.xpn.xwiki.XWiki getXWiki() {
@@ -60,32 +60,34 @@
             return null;
     }
 
-     public String getVersion() {
-          return xwiki.getVersion();
-     }
+    public String getVersion() {
+        return xwiki.getVersion();
+    }
 
-     public String getRequestURL() throws XWikiException {
-         return context.getURLFactory().getRequestURL(context).toString();
-     }
+    public String getRequestURL() throws XWikiException {
+        return context.getURLFactory().getRequestURL(context).toString();
+    }
 
-     /**
-      * Loads an Document from the database. Rights are checked before sending back the document.
-      * @param fullname Fullname of the XWiki document to be loaded
-      * @return a Document object or null if it is not accessible
-      * @throws XWikiException
-      */
-     public Document getDocument(String fullname) throws XWikiException {
-         XWikiDocument doc = xwiki.getDocument(fullname, context);
-         if (xwiki.getRightService().hasAccessLevel("view", context.getUser(), doc.getFullName(), context)==false) {
-                    return null;
-                }
+    /**
+     * Loads an Document from the database. Rights are checked before sending back the document.
+     *
+     * @param fullname Fullname of the XWiki document to be loaded
+     * @return a Document object or null if it is not accessible
+     * @throws XWikiException
+     */
+    public Document getDocument(String fullname) throws XWikiException {
+        XWikiDocument doc = xwiki.getDocument(fullname, context);
+        if (xwiki.getRightService().hasAccessLevel("view", context.getUser(), doc.getFullName(), context) == false) {
+            return null;
+        }
 
-         Document newdoc = new Document(doc, context);
-         return newdoc;
-     }
+        Document newdoc = new Document(doc, context);
+        return newdoc;
+    }
 
     /**
      * Returns wether a document exists or not
+     *
      * @param fullname Fullname of the XWiki document to be loaded
      * @return true if the document exists, false if not
      * @throws XWikiException
@@ -96,13 +98,14 @@
 
     /**
      * Verify the rights the current user has on a document
+     *
      * @param docname fullname of the document
-     * @param right right to check ("view", "edit", "admin", "delete")
+     * @param right   right to check ("view", "edit", "admin", "delete")
      * @return true if it exists
      */
     public boolean checkAccess(String docname, String right) {
         try {
-            XWikiDocument doc =new XWikiDocument();
+            XWikiDocument doc = new XWikiDocument();
             doc.setFullName(docname, context);
             return context.getWiki().checkAccess(right, doc, context);
         } catch (XWikiException e) {
@@ -114,36 +117,37 @@
     /**
      * Loads an Document from the database. Rights are checked before sending back the document.
      *
-     * @param web  Space to use in case no space is defined in the fullname
+     * @param web      Space to use in case no space is defined in the fullname
      * @param fullname Fullname or relative name of the document to load
      * @return a Document object or null if it is not accessible
      * @throws XWikiException
      */
-     public Document getDocument(String web, String fullname) throws XWikiException {
-         XWikiDocument doc = xwiki.getDocument(web, fullname, context);
-         if (xwiki.getRightService().hasAccessLevel("view", context.getUser(), doc.getFullName(), context)==false) {
-                    return null;
-                }
+    public Document getDocument(String web, String fullname) throws XWikiException {
+        XWikiDocument doc = xwiki.getDocument(web, fullname, context);
+        if (xwiki.getRightService().hasAccessLevel("view", context.getUser(), doc.getFullName(), context) == false) {
+            return null;
+        }
 
-         Document newdoc = new Document(doc, context);
-         return newdoc;
-     }
+        Document newdoc = new Document(doc, context);
+        return newdoc;
+    }
 
     /**
      * Load a specific revision of a document
+     *
      * @param doc Document for which to load a specific revision
      * @param rev Revision number
-     * @return  Specific revision of a document
+     * @return Specific revision of a document
      * @throws XWikiException
      */
     public Document getDocument(Document doc, String rev) throws XWikiException {
-        if ((doc==null)||(doc.getDoc()==null))
+        if ((doc == null) || (doc.getDoc() == null))
             return null;
 
-        if (xwiki.getRightService().hasAccessLevel("view", context.getUser(), doc.getFullName(), context)==false) {
-                    // Finally we return null, otherwise showing search result is a real pain
-                   return null;
-               }
+        if (xwiki.getRightService().hasAccessLevel("view", context.getUser(), doc.getFullName(), context) == false) {
+            // Finally we return null, otherwise showing search result is a real pain
+            return null;
+        }
 
         try {
             XWikiDocument revdoc = xwiki.getDocument(doc.getDoc(), rev, context);
@@ -158,43 +162,48 @@
 
     /**
      * Transform a text in a form compatible text
+     *
      * @param content text to transform
-     * @return  encoded result
+     * @return encoded result
      */
-     public String getFormEncoded(String content) {
+    public String getFormEncoded(String content) {
         return com.xpn.xwiki.XWiki.getFormEncoded(content);
-     }
+    }
 
     /**
      * Transform a text in a URL compatible text
+     *
      * @param content text to transform
-     * @return  encoded result
+     * @return encoded result
      */
 
     public String getURLEncoded(String content) {
-       return com.xpn.xwiki.XWiki.getURLEncoded(content);
+        return com.xpn.xwiki.XWiki.getURLEncoded(content);
     }
 
     /**
      * Transform a text in a XML compatible text
+     *
      * @param content text to transform
-     * @return  encoded result
+     * @return encoded result
      */
-     public String getXMLEncoded(String content) {
+    public String getXMLEncoded(String content) {
         return com.xpn.xwiki.XWiki.getXMLEncoded(content);
-     }
+    }
 
     /**
      * Output content in the edit content textarea
+     *
      * @param content content to output
      * @return the textarea text content
      */
-     public String getTextArea(String content) {
+    public String getTextArea(String content) {
         return com.xpn.xwiki.XWiki.getTextArea(content, context);
-     }
+    }
 
     /**
      * Output content in the edit content htmlarea
+     *
      * @param content content to output
      * @return the htmlarea text content
      */
@@ -204,6 +213,7 @@
 
     /**
      * Get the list of available classes in the wiki
+     *
      * @return list of classes names
      * @throws XWikiException
      */
@@ -213,6 +223,7 @@
 
     /**
      * Get the global MetaClass object
+     *
      * @return MetaClass object
      */
     public MetaClass getMetaclass() {
@@ -221,16 +232,16 @@
 
     public List search(String wheresql) throws XWikiException {
         if (checkProgrammingRights())
-         return xwiki.search(wheresql, context);
+            return xwiki.search(wheresql, context);
         else
-         return null;
+            return null;
     }
 
     public List search(String wheresql, int nb, int start) throws XWikiException {
         if (checkProgrammingRights())
-         return xwiki.search(wheresql, nb, start, context);
+            return xwiki.search(wheresql, nb, start, context);
         else
-         return null;
+            return null;
     }
 
     public List searchDocuments(String wheresql) throws XWikiException {
@@ -243,9 +254,9 @@
 
     public List searchDocuments(String wheresql, int nb, int start, String selectColumns) throws XWikiException {
         if (checkProgrammingRights())
-         return xwiki.getStore().searchDocumentsNames(wheresql, nb, start, selectColumns, context);
+            return xwiki.getStore().searchDocumentsNames(wheresql, nb, start, selectColumns, context);
         else
-         return null;
+            return null;
     }
 
     public List searchDocuments(String wheresql, boolean distinctbylanguage) throws XWikiException {
@@ -256,13 +267,10 @@
         return wrapDocs(xwiki.getStore().searchDocuments(wheresql, nb, start, context));
     }
 
-    private List wrapDocs(List docs)
-    {
+    private List wrapDocs(List docs) {
         List result = new ArrayList();
-        if (docs != null)
-        {
-            for (Iterator iter = result.iterator(); iter.hasNext();)
-            {
+        if (docs != null) {
+            for (Iterator iter = result.iterator(); iter.hasNext();) {
                 XWikiDocument doc = (XWikiDocument) iter.next();
                 Document wrappedDoc = new Document(doc, context);
                 result.add(wrappedDoc);
@@ -275,10 +283,25 @@
         return xwiki.parseContent(content, context);
     }
 
-    public String parseTemplate(String template) {
-            return xwiki.parseTemplate(template, context);
+    public String parseMessage() {
+        String message = (String) context.get("message");
+        if (message == null)
+            return null;
+        else {
+            return parseMessage(message);
         }
 
+    }
+
+    public String parseMessage(String id) {
+        XWikiMessageTool msg = (XWikiMessageTool) context.get("msg");
+        return parseContent(msg.get(id));
+    }
+
+    public String parseTemplate(String template) {
+        return xwiki.parseTemplate(template, context);
+    }
+
     /**
      * Designed to include dynamic content, such as Servlets or JSPs, inside Velocity
      * templates; works by creating a RequestDispatcher, buffering the output,
@@ -376,7 +399,7 @@
 
     public void flushCache() {
         if (hasProgrammingRights())
-         xwiki.flushCache();
+            xwiki.flushCache();
     }
 
     public void resetRenderingEngine() {
@@ -419,12 +442,12 @@
 
     public int createNewWiki(String wikiName, String wikiUrl, String wikiAdmin,
                              String baseWikiName, boolean failOnExist) throws XWikiException {
-                return createNewWiki(wikiName, wikiUrl, wikiAdmin, baseWikiName, "", null, failOnExist);
+        return createNewWiki(wikiName, wikiUrl, wikiAdmin, baseWikiName, "", null, failOnExist);
     }
 
     public int createNewWiki(String wikiName, String wikiUrl, String wikiAdmin,
                              String baseWikiName, String description, boolean failOnExist) throws XWikiException {
-                return createNewWiki(wikiName, wikiUrl, wikiAdmin, baseWikiName, description, null, failOnExist);
+        return createNewWiki(wikiName, wikiUrl, wikiAdmin, baseWikiName, description, null, failOnExist);
     }
 
     public int createNewWiki(String wikiName, String wikiUrl, String wikiAdmin,
@@ -500,19 +523,19 @@
     }
 
     public boolean hasAccessLevel(String level) {
-       try {
-           return xwiki.getRightService().hasAccessLevel(level, context.getUser(), context.getDoc().getFullName(), context);
-       } catch (Exception e) {
-           return false;
-       }
+        try {
+            return xwiki.getRightService().hasAccessLevel(level, context.getUser(), context.getDoc().getFullName(), context);
+        } catch (Exception e) {
+            return false;
+        }
     }
 
     public boolean hasAccessLevel(String level, String user, String docname) {
-       try {
-           return xwiki.getRightService().hasAccessLevel(level, user, docname, context);
-       } catch (Exception e) {
-           return false;
-       }
+        try {
+            return xwiki.getRightService().hasAccessLevel(level, user, docname, context);
+        } catch (Exception e) {
+            return false;
+        }
     }
 
     public String renderText(String text, Document doc) {
@@ -526,7 +549,7 @@
     public String renderChunk(Chunk chunk, boolean source, Document doc) {
         StringBuffer buf = new StringBuffer();
         chunk.toString(buf, "", "\n");
-        if (source==true)
+        if (source == true)
             return buf.toString();
 
         try {
@@ -599,16 +622,16 @@
 
     public java.lang.Object getService(String className) throws XWikiException {
         if (hasProgrammingRights())
-         return xwiki.getService(className);
+            return xwiki.getService(className);
         else
-         return null;
+            return null;
     }
 
     public java.lang.Object getPortalService(String className) throws XWikiException {
         if (hasProgrammingRights())
-         return xwiki.getPortalService(className);
+            return xwiki.getPortalService(className);
         else
-         return null;
+            return null;
     }
 
     public List getArrayList() {
@@ -620,8 +643,8 @@
     }
 
     public List sort(List list) {
-            Collections.sort(list);
-            return list;
+        Collections.sort(list);
+        return list;
     }
 
     public void outputImage(BufferedImage image) throws IOException {
@@ -633,12 +656,12 @@
     }
 
     public DocumentStats getCurrentMonthXWikiStats(String action) {
-       return context.getWiki().getStatsService(context).getDocMonthStats("", action, new Date(), context);
+        return context.getWiki().getStatsService(context).getDocMonthStats("", action, new Date(), context);
     }
 
     public String getRefererText(String referer) {
         try {
-         return xwiki.getRefererText(referer, context);
+            return xwiki.getRefererText(referer, context);
         } catch (Exception e) {
             return "";
         }
@@ -646,7 +669,7 @@
 
     public String getShortRefererText(String referer, int length) {
         try {
-         return xwiki.getRefererText(referer, context).substring(0, length);
+            return xwiki.getRefererText(referer, context).substring(0, length);
         } catch (Exception e) {
             return xwiki.getRefererText(referer, context);
         }
@@ -691,6 +714,7 @@
 
     /**
      * Returns a plugin from the plugin API. Plugin Rights can be verified.
+     *
      * @param name Name of the plugin to retrieve (either short of full class name)
      * @return a plugin object
      */
@@ -700,6 +724,7 @@
 
     /**
      * Returns a plugin from the plugin API. Plugin Rights can be verified.
+     *
      * @param name Name of the plugin to retrieve (either short of full class name)
      * @return a plugin object
      */
@@ -709,13 +734,14 @@
 
     /**
      * Returns the recently visited pages for a specific action
+     *
      * @param action ("view" or "edit")
-     * @param size how many recent actions to retrieve
+     * @param size   how many recent actions to retrieve
      * @return a ArrayList of document names
      */
     public java.util.Collection getRecentActions(String action, int size) {
         XWikiStatsService stats = context.getWiki().getStatsService(context);
-        if (stats==null)
+        if (stats == null)
             return new ArrayList();
         else
             return stats.getRecentActions(action, size, context);
@@ -723,6 +749,7 @@
 
     /**
      * Returns the Advertisement system from the preferences
+     *
      * @return "google" or "none"
      */
     public String getAdType() {
@@ -731,6 +758,7 @@
 
     /**
      * Returns the Advertisement client ID from the preferences
+     *
      * @return an Ad affiliate ID
      */
     public String getAdClientId() {
@@ -739,8 +767,9 @@
 
     /**
      * Retrieves a int from a String
+     *
      * @param str String to convert to int
-     * @return  the int or zero in case of exception
+     * @return the int or zero in case of exception
      */
     public int parseInt(String str) {
         try {
@@ -752,8 +781,9 @@
 
     /**
      * Retrieves a int from a String
+     *
      * @param str String to convert to int
-     * @return  the int or zero in case of exception
+     * @return the int or zero in case of exception
      */
     public Integer parseInteger(String str) {
         return new Integer(parseInt(str));
@@ -761,8 +791,9 @@
 
     /**
      * Retrieves a long from a String
+     *
      * @param str String to convert to long
-     * @return  the long or zero in case of exception
+     * @return the long or zero in case of exception
      */
     public long parseLong(String str) {
         try {
@@ -774,8 +805,9 @@
 
     /**
      * Retrieves a float from a String
+     *
      * @param str String to convert to float
-     * @return  the float or zero in case of exception
+     * @return the float or zero in case of exception
      */
     public float parseFloat(String str) {
         try {
@@ -787,8 +819,9 @@
 
     /**
      * Retrieves a double from a String
+     *
      * @param str String to convert to double
-     * @return  the double or zero in case of exception
+     * @return the double or zero in case of exception
      */
     public double parseDouble(String str) {
         try {
@@ -800,7 +833,8 @@
 
     /**
      * Returns the content of an HTTP/HTTPS URL protected using Basic Authentication
-     * @param surl url to retrieve
+     *
+     * @param surl     url to retrieve
      * @param username username for the basic authentication
      * @param password password for the basic authentication
      * @return Content of the specified URL
@@ -816,6 +850,7 @@
 
     /**
      * Returns the content of an HTTP/HTTPS URL
+     *
      * @param surl url to retrieve
      * @return Content of the specified URL
      * @throws IOException
@@ -830,7 +865,8 @@
 
     /**
      * Returns the content of an HTTP/HTTPS URL protected using Basic Authentication as Bytes
-     * @param surl url to retrieve
+     *
+     * @param surl     url to retrieve
      * @param username username for the basic authentication
      * @param password password for the basic authentication
      * @return Content of the specified URL
@@ -846,6 +882,7 @@
 
     /**
      * Returns the content of an HTTP/HTTPS URL as Bytes
+     *
      * @param surl url to retrieve
      * @return Content of the specified URL
      * @throws IOException
@@ -860,6 +897,7 @@
 
     /**
      * Filters text to be include in = or like clause in SQL
+     *
      * @param text text to filter
      * @return filtered text
      */
@@ -869,8 +907,9 @@
 
     /**
      * Returns the list of Macros documents in the specified content
+     *
      * @param defaultweb Default Web to use for relative path names
-     * @param content Content to parse
+     * @param content    Content to parse
      * @return ArrayList of document names
      */
     public List getIncludedMacros(String defaultweb, String content) {
@@ -882,33 +921,31 @@
      * returns true if xwiki.readonly is set in the configuration file
      *
      * @return the value of xwiki.isReadOnly()
-     *
      * @see #com.xpn.xwiki.XWiki
-     *
      */
-    public boolean isReadOnly () {
+    public boolean isReadOnly() {
         return xwiki.isReadOnly();
     }
 
-    public void setReadOnly (boolean ro) {
+    public void setReadOnly(boolean ro) {
         if (hasAdminRights()) {
             xwiki.setReadOnly(ro);
         }
     }
 
-    public void refreshLinks() throws XWikiException{
-        if (hasAdminRights()){
+    public void refreshLinks() throws XWikiException {
+        if (hasAdminRights()) {
             xwiki.refreshLinks(context);
         }
     }
 
     public boolean hasBacklinks() throws XWikiException {
-            return xwiki.hasBacklinks(context);
+        return xwiki.hasBacklinks(context);
     }
 
-    public void renamePage (XWikiDocument doc, String newFullName) throws XWikiException {
-       if (xwiki.getRightService().hasAccessLevel("edit", context.getUser(), doc.getFullName(), context)){
-            xwiki.renamePage(doc, context, newFullName) ;
+    public void renamePage(XWikiDocument doc, String newFullName) throws XWikiException {
+        if (xwiki.getRightService().hasAccessLevel("edit", context.getUser(), doc.getFullName(), context)) {
+            xwiki.renamePage(doc, context, newFullName);
         }
     }
 

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java	2006-03-01 16:23:18 UTC (rev 953)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java	2006-03-02 07:39:59 UTC (rev 954)
@@ -1,28 +1,28 @@
-/*
- * 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 ludovic
- * @author torcq
- * @author jeremi
- * @author sdumitriu
- * @author thomas
- */
+/*
+ * 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 ludovic
+ * @author torcq
+ * @author jeremi
+ * @author sdumitriu
+ * @author thomas
+ */
 
 package com.xpn.xwiki.doc;
 
@@ -128,7 +128,7 @@
 
     // Template by default assign to a view
     private String defaultTemplate;
-    
+
     private Object wikiNode;
 
     private XWikiStoreInterface store;
@@ -143,7 +143,7 @@
 
 
     public long getId() {
-        if ((language==null)||language.trim().equals(""))
+        if ((language == null) || language.trim().equals(""))
             id = getFullName().hashCode();
         else
             id = (getFullName() + ":" + language).hashCode();
@@ -191,12 +191,12 @@
     public XWikiDocument(String web, String name) {
         this.web = web;
 
-        int i1 =name.indexOf(".");
-        if (i1==-1) {
+        int i1 = name.indexOf(".");
+        if (i1 == -1) {
             this.name = name;
         } else {
-            this.web = name.substring(0,i1);
-            this.name = name.substring(i1+1);
+            this.web = name.substring(0, i1);
+            this.name = name.substring(i1 + 1);
         }
         this.updateDate = new Date();
         this.creationDate = new Date();
@@ -272,7 +272,7 @@
     }
 
     public String getTitle() {
-        if (title==null)
+        if (title == null)
             return "";
         else
             return title;
@@ -281,12 +281,12 @@
     public String getDisplayTitle() {
         String title = getTitle();
         if (title.equals("")) {
-         title = extractTitle();
+            title = extractTitle();
         }
         if (title.equals(""))
-         return getName();
+            return getName();
         else
-         return title;
+            return title;
     }
 
     public String extractTitle() {
@@ -298,22 +298,23 @@
             while (true) {
                 i2 = content.indexOf("\n", i1);
                 String title = "";
-                if (i2!=-1)
+                if (i2 != -1)
                     title = content.substring(i1, i2).trim();
                 else
                     title = content.substring(i1).trim();
-                if ((!title.equals(""))&&(title.matches("1(\\.1)?\\s+.+")))
+                if ((!title.equals("")) && (title.matches("1(\\.1)?\\s+.+")))
                     return title.substring(title.indexOf(" ")).trim();
-                if (i2==-1)
+                if (i2 == -1)
                     break;
                 i1 = i2 + 1;
             }
-        } catch (Exception e) {}
+        } catch (Exception e) {
+        }
         return "";
     }
 
     public void setTitle(String title) {
-        if (title==null)
+        if (title == null)
             title = "";
         this.title = title;
         if (!title.equals(this.title)) {
@@ -322,7 +323,7 @@
     }
 
     public String getFormat() {
-        if (format==null)
+        if (format == null)
             return "";
         else
             return format;
@@ -336,14 +337,14 @@
     }
 
     public String getAuthor() {
-        if (author==null)
+        if (author == null)
             return "";
         else
             return author.trim();
     }
 
     public String getContentAuthor() {
-        if (contentAuthor==null)
+        if (contentAuthor == null)
             return "";
         else
             return contentAuthor.trim();
@@ -364,7 +365,7 @@
     }
 
     public String getCreator() {
-        if (creator==null)
+        if (creator == null)
             return "";
         else
             return creator.trim();
@@ -378,14 +379,14 @@
     }
 
     public Date getDate() {
-        if (updateDate==null)
+        if (updateDate == null)
             return new Date();
         else
             return updateDate;
     }
 
     public void setDate(Date date) {
-        if ((date!=null)&&(!date.equals(this.updateDate))) {
+        if ((date != null) && (!date.equals(this.updateDate))) {
             setMetaDataDirty(true);
         }
         this.updateDate = date;
@@ -399,21 +400,21 @@
     }
 
     public void setCreationDate(Date date) {
-        if ((date!=null)&&(!creationDate.equals(this.creationDate))) {
+        if ((date != null) && (!creationDate.equals(this.creationDate))) {
             setMetaDataDirty(true);
         }
         this.creationDate = date;
     }
 
     public Date getContentUpdateDate() {
-        if (contentUpdateDate==null)
+        if (contentUpdateDate == null)
             return new Date();
         else
             return contentUpdateDate;
     }
 
     public void setContentUpdateDate(Date date) {
-        if ((date!=null)&&(!date.equals(this.contentUpdateDate))) {
+        if ((date != null) && (!date.equals(this.contentUpdateDate))) {
             setMetaDataDirty(true);
         }
         this.contentUpdateDate = date;
@@ -424,8 +425,8 @@
     }
 
     public void setMeta(String meta) {
-        if (meta==null) {
-            if (this.meta!=null)
+        if (meta == null) {
+            if (this.meta != null)
                 setMetaDataDirty(true);
         } else if (!meta.equals(this.meta)) {
             setMetaDataDirty(true);
@@ -446,7 +447,7 @@
     }
 
     public void incrementVersion() {
-        if (version==null)
+        if (version == null)
             version = new Version("1.1");
         else {
             version = version.next();
@@ -477,12 +478,11 @@
     public String getURL(String action, boolean redirect, XWikiContext context) {
         URL url = context.getURLFactory().createURL(getWeb(), getName(), action, redirect, context);
         if (redirect) {
-            if (url==null)
+            if (url == null)
                 return null;
             else
                 return url.toString();
-        }
-        else
+        } else
             return context.getURLFactory().getURL(url, context);
     }
 
@@ -498,7 +498,7 @@
 
     public String getExternalURL(String action, XWikiContext context) {
         URL url = context.getURLFactory().createExternalURL(getWeb(), getName(), action,
-                null , null, context);
+                null, null, context);
         return url.toString();
     }
 
@@ -526,16 +526,16 @@
             int length = nb;
 
             // 0 means all revisions
-            if (nb==0)
+            if (nb == 0)
                 length = revisions.length;
 
-            if (revisions.length<length)
+            if (revisions.length < length)
                 length = revisions.length;
 
             String[] recentrevs = new String[length];
             for (int i = 1; i <= length; i++)
-                recentrevs[i-1
-                        ] = revisions[revisions.length-i].toString();
+                recentrevs[i - 1
+                        ] = revisions[revisions.length - i].toString();
             return recentrevs;
         } catch (Exception e) {
             return new String[0];
@@ -555,11 +555,11 @@
     }
 
     public String getArchive(XWikiContext context) throws XWikiException {
-        if ((content==null)||(content.equals("")))
+        if ((content == null) || (content.equals("")))
             setContent("\n");
-        if (archive==null)
+        if (archive == null)
             updateArchive(toXML(context));
-        if (archive==null)
+        if (archive == null)
             return "";
         else {
             StringBuffer buffer = new StringBuffer();
@@ -574,8 +574,8 @@
             archive = new Archive(getFullName(), is);
         }
         catch (Exception e) {
-            Object[] args = { getFullName() };
-            throw new XWikiException( XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_ARCHIVEFORMAT,
+            Object[] args = {getFullName()};
+            throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_ARCHIVEFORMAT,
                     "Exception while manipulating the archive for doc {0}", e, args);
         }
     }
@@ -583,14 +583,14 @@
     public void updateArchive(String text) throws XWikiException {
         try {
             Lines lines = new Lines(text);
-            if (archive!=null)
-                archive.addRevision(lines.toArray(),"");
+            if (archive != null)
+                archive.addRevision(lines.toArray(), "");
             else
-                archive = new Archive(lines.toArray(),getFullName(),getVersion());
+                archive = new Archive(lines.toArray(), getFullName(), getVersion());
         }
         catch (Exception e) {
-            Object[] args = { getFullName() };
-            throw new XWikiException( XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_ARCHIVEFORMAT,
+            Object[] args = {getFullName()};
+            throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_ARCHIVEFORMAT,
                     "Exception while manipulating the archive for doc {0}", e, args);
         }
     }
@@ -604,7 +604,7 @@
     }
 
     public BaseClass getxWikiClass() {
-        if (xWikiClass==null) {
+        if (xWikiClass == null) {
             xWikiClass = new BaseClass();
             xWikiClass.setName(getFullName());
         }
@@ -629,19 +629,19 @@
 
     public List getxWikiClasses(XWikiContext context) {
         List list = new ArrayList();
-        for (Iterator it=getxWikiObjects().keySet().iterator();it.hasNext();) {
+        for (Iterator it = getxWikiObjects().keySet().iterator(); it.hasNext();) {
             String classname = (String) it.next();
             BaseClass bclass = null;
             Vector objects = getObjects(classname);
-            for (int i=0;i<objects.size();i++) {
+            for (int i = 0; i < objects.size(); i++) {
                 BaseObject obj = (BaseObject) objects.get(i);
-                if (obj!=null) {
+                if (obj != null) {
                     bclass = obj.getxWikiClass(context);
-                    if (bclass!=null)
+                    if (bclass != null)
                         break;
                 }
             }
-            if (bclass!=null)
+            if (bclass != null)
                 list.add(bclass);
         }
         return list;
@@ -652,19 +652,19 @@
         object.setName(getFullName());
         object.setClassName(classname);
         Vector objects = getObjects(classname);
-        if (objects==null) {
+        if (objects == null) {
             objects = new Vector();
             setObjects(classname, objects);
         }
         objects.add(object);
-        int nb = objects.size()-1;
+        int nb = objects.size() - 1;
         object.setNumber(nb);
         return nb;
     }
 
     public int getObjectNumbers(String classname) {
         try {
-            return ((Vector)getxWikiObjects().get(classname)).size();
+            return ((Vector) getxWikiObjects().get(classname)).size();
         } catch (Exception e) {
             return 0;
         }
@@ -679,12 +679,12 @@
     }
 
     public BaseObject getObject(String classname) {
-        Vector objects = (Vector)getxWikiObjects().get(classname);
-        if (objects==null)
+        Vector objects = (Vector) getxWikiObjects().get(classname);
+        if (objects == null)
             return null;
-        for (int i=0;i<objects.size();i++) {
+        for (int i = 0; i < objects.size(); i++) {
             BaseObject obj = (BaseObject) objects.get(i);
-            if (obj!=null)
+            if (obj != null)
                 return obj;
         }
         return null;
@@ -692,7 +692,7 @@
 
     public BaseObject getObject(String classname, int nb) {
         try {
-            return (BaseObject) ((Vector)getxWikiObjects().get(classname)).get(nb);
+            return (BaseObject) ((Vector) getxWikiObjects().get(classname)).get(nb);
         } catch (Exception e) {
             return null;
         }
@@ -704,19 +704,19 @@
 
     public BaseObject getObject(String classname, String key, String value, boolean failover) {
         try {
-            if (value==null) {
+            if (value == null) {
                 if (failover)
                     return getObject(classname);
                 else
                     return null;
             }
 
-            Vector objects = (Vector)getxWikiObjects().get(classname);
-            if ((objects==null)||(objects.size()==0))
+            Vector objects = (Vector) getxWikiObjects().get(classname);
+            if ((objects == null) || (objects.size() == 0))
                 return null;
-            for (int i=0;i<objects.size();i++) {
+            for (int i = 0; i < objects.size(); i++) {
                 BaseObject obj = (BaseObject) objects.get(i);
-                if (obj!=null) {
+                if (obj != null) {
                     if (value.equals(obj.getStringValue(key)))
                         return obj;
                 }
@@ -738,7 +738,7 @@
 
     public void addObject(String classname, BaseObject object) {
         Vector vobj = getObjects(classname);
-        if (vobj==null)
+        if (vobj == null)
             setObject(classname, 0, object);
         else
             setObject(classname, vobj.size(), object);
@@ -747,12 +747,12 @@
     public void setObject(String classname, int nb, BaseObject object) {
         Vector objects = null;
         objects = getObjects(classname);
-        if (objects==null) {
+        if (objects == null) {
             objects = new Vector();
             setObjects(classname, objects);
         }
         if (nb >= objects.size()) {
-            objects.setSize(nb+1);
+            objects.setSize(nb + 1);
         }
         objects.set(nb, object);
         object.setNumber(nb);
@@ -769,11 +769,11 @@
     public void mergexWikiClass(XWikiDocument templatedoc) {
         BaseClass bclass = getxWikiClass();
         BaseClass tbclass = templatedoc.getxWikiClass();
-        if (tbclass!=null) {
-            if (bclass==null) {
-                setxWikiClass((BaseClass)tbclass.clone());
+        if (tbclass != null) {
+            if (bclass == null) {
+                setxWikiClass((BaseClass) tbclass.clone());
             } else {
-                getxWikiClass().merge((BaseClass)tbclass.clone());
+                getxWikiClass().merge((BaseClass) tbclass.clone());
             }
         }
     }
@@ -785,25 +785,24 @@
             String name = (String) itobjects.next();
             Vector objects = (Vector) getxWikiObjects().get(name);
 
-            if (objects!=null) {
+            if (objects != null) {
                 Vector tobjects = (Vector) templatedoc.getxWikiObjects().get(name);
-                for (int i=0;i<tobjects.size();i++) {
+                for (int i = 0; i < tobjects.size(); i++) {
                     {
                         BaseObject bobj = (BaseObject) ((BaseObject) tobjects.get(i)).clone();
                         objects.add(bobj);
-                        bobj.setNumber(objects.size()-1);
+                        bobj.setNumber(objects.size() - 1);
                     }
                 }
             } else {
                 Vector tobjects = (Vector) templatedoc.getObjects(name);
                 objects = new Vector();
-                for (int i=0;i<tobjects.size();i++)
-                {
+                for (int i = 0; i < tobjects.size(); i++) {
                     BaseObject bobj1 = (BaseObject) tobjects.get(i);
-                    if (bobj1!=null) {
-                        BaseObject bobj = (BaseObject)bobj1.clone();
+                    if (bobj1 != null) {
+                        BaseObject bobj = (BaseObject) bobj1.clone();
                         objects.add(bobj);
-                        bobj.setNumber(objects.size()-1);
+                        bobj.setNumber(objects.size() - 1);
                     }
                 }
                 getxWikiObjects().put(name, objects);
@@ -828,27 +827,22 @@
 
             if (type.equals("view")) {
                 pclass.displayView(result, fieldname, prefix, obj, context);
-            }
-            else if (type.equals("rendered")) {
+            } else if (type.equals("rendered")) {
                 String fcontent = pclass.displayView(fieldname, prefix, obj, context);
                 result.append(getRenderedContent(fcontent, context));
-            }
-            else if (type.equals("edit")) {
+            } else if (type.equals("edit")) {
                 result.append("{pre}");
                 pclass.displayEdit(result, fieldname, prefix, obj, context);
                 result.append("{/pre}");
-            }
-            else if (type.equals("hidden")) {
+            } else if (type.equals("hidden")) {
                 result.append("{pre}");
                 pclass.displayHidden(result, fieldname, prefix, obj, context);
                 result.append("{/pre}");
-            }
-            else if (type.equals("search")) {
+            } else if (type.equals("search")) {
                 result.append("{pre}");
                 pclass.displaySearch(result, fieldname, prefix, obj, context);
                 result.append("{/pre}");
-            }
-            else {
+            } else {
                 pclass.displayView(result, fieldname, prefix, obj, context);
             }
             return result.toString();
@@ -861,10 +855,13 @@
 
     public String display(String fieldname, BaseObject obj, XWikiContext context) {
         String type = null;
-        try { type = (String) context.get("display"); }
+        try {
+            type = (String) context.get("display");
+        }
         catch (Exception e) {
-        };
-        if (type==null)
+        }
+        ;
+        if (type == null)
             type = "view";
         return display(fieldname, type, obj, context);
     }
@@ -872,7 +869,7 @@
     public String display(String fieldname, XWikiContext context) {
         try {
             BaseObject object = getxWikiObject();
-            if (object==null)
+            if (object == null)
                 object = getFirstObject(fieldname);
             return display(fieldname, object, context);
         } catch (Exception e) {
@@ -883,9 +880,9 @@
     public String display(String fieldname, String mode, XWikiContext context) {
         try {
             BaseObject object = getxWikiObject();
-            if (object==null)
+            if (object == null)
                 object = getFirstObject(fieldname);
-            if (object==null)
+            if (object == null)
                 return "";
             else
                 return display(fieldname, mode, object, context);
@@ -894,34 +891,34 @@
         }
     }
 
-    public String displayForm(String className,String header, String format, XWikiContext context) {
+    public String displayForm(String className, String header, String format, XWikiContext context) {
         return displayForm(className, header, format, true, context);
     }
 
-    public String displayForm(String className,String header, String format, boolean linebreak, XWikiContext context) {
+    public String displayForm(String className, String header, String format, boolean linebreak, XWikiContext context) {
         Vector objects = getObjects(className);
         if (format.endsWith("\\n"))
             linebreak = true;
 
         BaseObject firstobject = null;
         Iterator foit = objects.iterator();
-        while ((firstobject==null)&&foit.hasNext()) {
+        while ((firstobject == null) && foit.hasNext()) {
             firstobject = (BaseObject) foit.next();
         }
 
-        if (firstobject==null)
+        if (firstobject == null)
             return "";
 
         BaseClass bclass = firstobject.getxWikiClass(context);
         Collection fields = bclass.getFieldList();
-        if (fields.size()==0)
+        if (fields.size() == 0)
             return "";
 
         StringBuffer result = new StringBuffer();
         XWikiVelocityRenderer renderer = new XWikiVelocityRenderer();
         VelocityContext vcontext = new VelocityContext();
         vcontext.put("formatter", new VelocityFormatter(vcontext));
-        for (Iterator it = fields.iterator();it.hasNext();) {
+        for (Iterator it = fields.iterator(); it.hasNext();) {
             PropertyClass pclass = (PropertyClass) it.next();
             vcontext.put(pclass.getName(), pclass.getPrettyName());
         }
@@ -930,11 +927,11 @@
             result.append("\n");
 
         // display each line
-        for (int i=0;i<objects.size();i++) {
-            vcontext.put("id", new Integer(i+1));
+        for (int i = 0; i < objects.size(); i++) {
+            vcontext.put("id", new Integer(i + 1));
             BaseObject object = (BaseObject) objects.get(i);
-            if (object!=null) {
-                for (Iterator it = bclass.getPropertyList().iterator();it.hasNext();) {
+            if (object != null) {
+                for (Iterator it = bclass.getPropertyList().iterator(); it.hasNext();) {
                     String name = (String) it.next();
                     vcontext.put(name, display(name, object, context));
                 }
@@ -948,28 +945,28 @@
 
     public String displayForm(String className, XWikiContext context) {
         Vector objects = getObjects(className);
-        if (objects==null)
+        if (objects == null)
             return "";
 
         BaseObject firstobject = null;
         Iterator foit = objects.iterator();
-        while ((firstobject==null)&&foit.hasNext()) {
+        while ((firstobject == null) && foit.hasNext()) {
             firstobject = (BaseObject) foit.next();
         }
 
-        if (firstobject==null)
+        if (firstobject == null)
             return "";
 
         BaseClass bclass = firstobject.getxWikiClass(context);
         Collection fields = bclass.getFieldList();
-        if (fields.size()==0)
+        if (fields.size() == 0)
             return "";
 
         StringBuffer result = new StringBuffer();
         result.append("{table}\n");
         boolean first = true;
-        for (Iterator it = fields.iterator();it.hasNext();) {
-            if (first==true)
+        for (Iterator it = fields.iterator(); it.hasNext();) {
+            if (first == true)
                 first = false;
             else
                 result.append("|");
@@ -977,16 +974,16 @@
             result.append(pclass.getPrettyName());
         }
         result.append("\n");
-        for (int i=0;i<objects.size();i++) {
+        for (int i = 0; i < objects.size(); i++) {
             BaseObject object = (BaseObject) objects.get(i);
-            if (object!=null) {
+            if (object != null) {
                 first = true;
-                for (Iterator it = bclass.getPropertyList().iterator();it.hasNext();) {
-                    if (first==true)
+                for (Iterator it = bclass.getPropertyList().iterator(); it.hasNext();) {
+                    if (first == true)
                         first = false;
                     else
                         result.append("|");
-                    String data = display((String)it.next(), object, context);
+                    String data = display((String) it.next(), object, context);
                     if (data.trim().equals(""))
                         result.append("&nbsp;");
                     else
@@ -1010,34 +1007,34 @@
 
     public void readFromForm(EditForm eform, XWikiContext context) throws XWikiException {
         String content = eform.getContent();
-        if ((content!=null)&&(!content.equals(""))) {
+        if ((content != null) && (!content.equals(""))) {
             // Cleanup in case we use HTMLAREA
             // content = context.getUtil().substitute("s/<br class=\\\"htmlarea\\\"\\/>/\\r\\n/g", content);
             content = context.getUtil().substitute("s/<br class=\"htmlarea\" \\/>/\r\n/g", content);
             setContent(content);
         }
         String parent = eform.getParent();
-        if (parent!=null)
+        if (parent != null)
             setParent(parent);
 
         String title = eform.getTitle();
-        if (title!=null)
+        if (title != null)
             setTitle(title);
 
         String creator = eform.getCreator();
-        if ((creator!=null)&&(!creator.equals(getCreator()))) {
+        if ((creator != null) && (!creator.equals(getCreator()))) {
             if ((getCreator().equals(context.getUser()))
-                    ||(context.getWiki().getRightService().hasAdminRights(context)))
+                    || (context.getWiki().getRightService().hasAdminRights(context)))
                 setCreator(creator);
         }
 
         String defaultLanguage = eform.getDefaultLanguage();
-        if (defaultLanguage!=null)
+        if (defaultLanguage != null)
             setDefaultLanguage(defaultLanguage);
-        
+
         String defaultTemplate = eform.getDefaultTemplate();
-        if (defaultTemplate!=null)
-            setDefaultTemplate(defaultTemplate);        
+        if (defaultTemplate != null)
+            setDefaultTemplate(defaultTemplate);
 
         // This is now done before
         // readFromTemplate(eform, context);
@@ -1048,10 +1045,9 @@
             Vector bobjects = getObjects(name);
             Vector newobjects = new Vector();
             newobjects.setSize(bobjects.size());
-            for (int i=0;i<bobjects.size();i++) {
+            for (int i = 0; i < bobjects.size(); i++) {
                 BaseObject oldobject = (BaseObject) getObject(name, i);
-                if (oldobject!=null)
-                {
+                if (oldobject != null) {
                     BaseClass baseclass = oldobject.getxWikiClass(context);
                     BaseObject newobject = (BaseObject) baseclass.fromMap(eform.getObject(baseclass.getName() + "_" + i), oldobject);
                     newobject.setNumber(oldobject.getNumber());
@@ -1091,29 +1087,29 @@
     }
 
     public void readFromTemplate(String template, XWikiContext context) throws XWikiException {
-        if ((template!=null)&&(!template.equals(""))) {
+        if ((template != null) && (!template.equals(""))) {
             String content = getContent();
-            if ((!content.equals("\n"))&&(!content.equals(""))&&!isNew()) {
-                Object[] args = { getFullName() };
-                throw new XWikiException( XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_APP_DOCUMENT_NOT_EMPTY,
+            if ((!content.equals("\n")) && (!content.equals("")) && !isNew()) {
+                Object[] args = {getFullName()};
+                throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_APP_DOCUMENT_NOT_EMPTY,
                         "Cannot add a template to document {0} because it already has content", null, args);
             } else {
 
-                if (template.indexOf('.')==-1) {
+                if (template.indexOf('.') == -1) {
                     template = getWeb() + "." + template;
                 }
                 XWiki xwiki = context.getWiki();
                 XWikiDocument templatedoc = xwiki.getDocument(template, context);
                 if (templatedoc.isNew()) {
-                    Object[] args = { template, getFullName() };
-                    throw new XWikiException( XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_APP_TEMPLATE_DOES_NOT_EXIST,
+                    Object[] args = {template, getFullName()};
+                    throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_APP_TEMPLATE_DOES_NOT_EXIST,
                             "Template document {0} does not exist when adding to document {1}", null, args);
                 } else {
                     setTemplate(template);
                     setContent(templatedoc.getContent());
-                    if ((getParent()==null)||(getParent().equals(""))) {
+                    if ((getParent() == null) || (getParent().equals(""))) {
                         String tparent = templatedoc.getParent();
-                        if (tparent!=null)
+                        if (tparent != null)
                             setParent(tparent);
                     }
 
@@ -1174,7 +1170,7 @@
         doc.setDefaultTemplate(getDefaultTemplate());
         doc.setLanguage(getLanguage());
         doc.setTranslation(getTranslation());
-        doc.setxWikiClass((BaseClass)getxWikiClass().clone());
+        doc.setxWikiClass((BaseClass) getxWikiClass().clone());
         doc.setxWikiClassXML(getxWikiClassXML());
         doc.mergexWikiObjects(this);
         doc.copyAttachments(this);
@@ -1226,7 +1222,7 @@
         if (!getLanguage().equals(doc.getLanguage()))
             return false;
 
-        if (getTranslation()!=doc.getTranslation())
+        if (getTranslation() != doc.getTranslation())
             return false;
 
         if (getDate().getTime() != doc.getDate().getTime())
@@ -1265,31 +1261,31 @@
         if (!list1.equals(list2))
             return false;
 
-        for (Iterator it = list1.iterator();it.hasNext();) {
+        for (Iterator it = list1.iterator(); it.hasNext();) {
             String name = (String) it.next();
             Vector v1 = getObjects(name);
             Vector v2 = doc.getObjects(name);
-            if (v1.size()!=v2.size())
+            if (v1.size() != v2.size())
                 return false;
-            for (int i=0;i<v1.size();i++) {
-                if ((v1.get(i)==null)&&(v2.get(i)!=null))
+            for (int i = 0; i < v1.size(); i++) {
+                if ((v1.get(i) == null) && (v2.get(i) != null))
                     return false;
                 if (!v1.get(i).equals(v2.get(i)))
                     return false;
             }
         }
 
-       return true;
+        return true;
     }
 
     public String toXML(Document doc, XWikiContext context) {
         OutputFormat outputFormat = new OutputFormat("", true);
-        if ((context==null)||(context.getWiki()==null))
+        if ((context == null) || (context.getWiki() == null))
             outputFormat.setEncoding("UTF-8");
         else
             outputFormat.setEncoding(context.getWiki().getEncoding());
         StringWriter out = new StringWriter();
-        XMLWriter writer = new XMLWriter( out, outputFormat );
+        XMLWriter writer = new XMLWriter(out, outputFormat);
         try {
             writer.write(doc);
             return out.toString();
@@ -1301,7 +1297,7 @@
 
     public String getXMLContent(XWikiContext context) throws XWikiException {
         XWikiDocument tdoc = getTranslatedDocument(context);
-        Document doc =  tdoc.toXMLDocument(true, true, false, false, context);
+        Document doc = tdoc.toXMLDocument(true, true, false, false, context);
         return toXML(doc, context);
     }
 
@@ -1315,10 +1311,10 @@
     }
 
     public void addToZip(ZipOutputStream zos, boolean withVersions, XWikiContext context) throws IOException {
-        try  {
+        try {
             String zipname = getWeb() + "/" + getName();
             String language = getLanguage();
-            if ((language!=null)&&(!language.equals("")))
+            if ((language != null) && (!language.equals("")))
                 zipname += "." + language;
             ZipEntry zipentry = new ZipEntry(zipname);
             zos.putNextEntry(zipentry);
@@ -1339,7 +1335,7 @@
                         boolean bWithVersions,
                         XWikiContext context) throws XWikiException {
         Document doc = toXMLDocument(bWithObjects, bWithRendering,
-                bWithAttachmentContent, bWithVersions ,context);
+                bWithAttachmentContent, bWithVersions, context);
         return toXML(doc, context);
     }
 
@@ -1398,7 +1394,7 @@
         docel.add(el);
 
         List alist = getAttachmentList();
-        for (int ai=0;ai<alist.size();ai++) {
+        for (int ai = 0; ai < alist.size(); ai++) {
             XWikiAttachment attach = (XWikiAttachment) alist.get(ai);
             docel.add(attach.toXML(bWithAttachmentContent, bWithVersions, context));
         }
@@ -1406,7 +1402,7 @@
         if (bWithObjects) {
             // Add Class
             BaseClass bclass = getxWikiClass();
-            if (bclass.getFieldList().size()>0) {
+            if (bclass.getFieldList().size() > 0) {
                 docel.add(bclass.toXML(null));
             }
 
@@ -1414,9 +1410,9 @@
             Iterator it = getxWikiObjects().values().iterator();
             while (it.hasNext()) {
                 Vector objects = (Vector) it.next();
-                for (int i=0;i<objects.size();i++) {
-                    BaseObject obj = (BaseObject)objects.get(i);
-                    if (obj!=null) {
+                for (int i = 0; i < objects.size(); i++) {
+                    BaseObject obj = (BaseObject) objects.get(i);
+                    if (obj != null) {
                         BaseClass objclass = null;
                         if (obj.getName().equals(obj.getClassName()))
                             objclass = bclass;
@@ -1469,7 +1465,7 @@
         char character;
         StringBuffer result = new StringBuffer();
         for (int i = 0; i < length; i++) {
-            character = xmlString.charAt( i );
+            character = xmlString.charAt(i);
             switch (character) {
                 case '&':
                     result.append("&amp;");
@@ -1509,13 +1505,13 @@
 
     protected String getElement(Element docel, String name) {
         Element el = docel.element(name);
-        if (el==null)
+        if (el == null)
             return "";
         else
             return el.getText();
     }
 
-    public void fromXML(String xml)throws XWikiException {
+    public void fromXML(String xml) throws XWikiException {
         fromXML(xml, false);
     }
 
@@ -1533,42 +1529,41 @@
 
         Element docel = domdoc.getRootElement();
         setName(getElement(docel, "name"));
-        setWeb(getElement(docel,"web"));
-        setParent(getElement(docel,"parent"));
-        setCreator(getElement(docel,"creator"));
-        setAuthor(getElement(docel,"author"));
-        setVersion(getElement(docel,"version"));
-        setContent(getElement(docel,"content"));
-        setLanguage(getElement(docel,"language"));
-        setDefaultLanguage(getElement(docel,"defaultLanguage"));
+        setWeb(getElement(docel, "web"));
+        setParent(getElement(docel, "parent"));
+        setCreator(getElement(docel, "creator"));
+        setAuthor(getElement(docel, "author"));
+        setVersion(getElement(docel, "version"));
+        setContent(getElement(docel, "content"));
+        setLanguage(getElement(docel, "language"));
+        setDefaultLanguage(getElement(docel, "defaultLanguage"));
 
-        String strans = getElement(docel,"translation");
-        if ((strans==null)||strans.equals(""))
+        String strans = getElement(docel, "translation");
+        if ((strans == null) || strans.equals(""))
             setTranslation(0);
         else
             setTranslation(Integer.parseInt(strans));
 
-        String archive = getElement(docel,"versions");
-        if (withArchive && archive != null && archive.length() > 0)
-        {
+        String archive = getElement(docel, "versions");
+        if (withArchive && archive != null && archive.length() > 0) {
             setArchive(archive);
         }
 
 
-        String sdate = getElement(docel,"date");
+        String sdate = getElement(docel, "date");
         if (!sdate.equals("")) {
             Date date = new Date(Long.parseLong(sdate));
             setDate(date);
         }
 
-        String scdate = getElement(docel,"creationDate");
+        String scdate = getElement(docel, "creationDate");
         if (!scdate.equals("")) {
             Date cdate = new Date(Long.parseLong(scdate));
             setCreationDate(cdate);
         }
 
         List atels = docel.elements("attachment");
-        for (int i=0;i<atels.size();i++) {
+        for (int i = 0; i < atels.size(); i++) {
             Element atel = (Element) atels.get(i);
             XWikiAttachment attach = new XWikiAttachment();
             attach.setDoc(this);
@@ -1578,13 +1573,13 @@
 
         Element cel = docel.element("class");
         BaseClass bclass = new BaseClass();
-        if (cel!=null) {
+        if (cel != null) {
             bclass.fromXML(cel);
             setxWikiClass(bclass);
         }
 
         List objels = docel.elements("object");
-        for (int i=0;i<objels.size();i++) {
+        for (int i = 0; i < objels.size(); i++) {
             Element objel = (Element) objels.get(i);
             BaseObject bobject = new BaseObject();
             bobject.fromXML(objel);
@@ -1601,22 +1596,22 @@
     }
 
     public void saveAllAttachments(XWikiContext context) throws XWikiException {
-        for (int i=0;i<attachmentList.size();i++) {
+        for (int i = 0; i < attachmentList.size(); i++) {
             saveAttachmentContent((XWikiAttachment) attachmentList.get(i), context);
         }
     }
-    
+
     public void saveAttachmentContent(XWikiAttachment attachment, XWikiContext context) throws XWikiException {
         String database = context.getDatabase();
         try {
             // We might need to switch database to
             // get the translated content
-            if (getDatabase()!=null)
+            if (getDatabase() != null)
                 context.setDatabase(getDatabase());
 
             getStore().saveAttachmentContent(attachment, context, true);
         } finally {
-            if (database!=null)
+            if (database != null)
                 context.setDatabase(database);
         }
     }
@@ -1626,12 +1621,12 @@
         try {
             // We might need to switch database to
             // get the translated content
-            if (getDatabase()!=null)
+            if (getDatabase() != null)
                 context.setDatabase(getDatabase());
 
             getStore().loadAttachmentContent(attachment, context, true);
         } finally {
-            if (database!=null)
+            if (database != null)
                 context.setDatabase(database);
         }
     }
@@ -1641,37 +1636,37 @@
         try {
             // We might need to switch database to
             // get the translated content
-            if (getDatabase()!=null)
+            if (getDatabase() != null)
                 context.setDatabase(getDatabase());
 
             getStore().deleteXWikiAttachment(attachment, context, true);
         } finally {
-            if (database!=null)
+            if (database != null)
                 context.setDatabase(database);
         }
     }
 
     public List getBacklinks(XWikiContext context) throws XWikiException {
-         return getStore().loadBacklinks(getFullName(),context ,true);
-     }
+        return getStore().loadBacklinks(getFullName(), context, true);
+    }
 
     public List getLinks(XWikiContext context) throws XWikiException {
-         return getStore().loadLinks(getId(), context, true);
-     }
+        return getStore().loadLinks(getId(), context, true);
+    }
 
-      public void renameProperties(String className, Map fieldsToRename) {
+    public void renameProperties(String className, Map fieldsToRename) {
         Vector objects = getObjects(className);
-        if (objects==null)
+        if (objects == null)
             return;
-        for (int j=0;j<objects.size();j++) {
+        for (int j = 0; j < objects.size(); j++) {
             BaseObject bobject = (BaseObject) objects.get(j);
-            if (bobject==null)
+            if (bobject == null)
                 continue;
-            for (Iterator renameit = fieldsToRename.keySet().iterator();renameit.hasNext();) {
-                String origname = (String)renameit.next();
+            for (Iterator renameit = fieldsToRename.keySet().iterator(); renameit.hasNext();) {
+                String origname = (String) renameit.next();
                 String newname = (String) fieldsToRename.get(origname);
                 BaseProperty origprop = (BaseProperty) bobject.safeget(origname);
-                if (origprop!=null) {
+                if (origprop != null) {
                     BaseProperty prop = (BaseProperty) origprop.clone();
                     bobject.removeField(origname);
                     prop.setName(newname);
@@ -1697,10 +1692,10 @@
         try {
             String pattern = "#include(Topic|Form|Macros)\\(\"(.*?)\"\\)";
             List list = context.getUtil().getMatches(getContent(), pattern, 2);
-            for (int i=0;i<list.size();i++) {
+            for (int i = 0; i < list.size(); i++) {
                 try {
-                    String name = (String)list.get(i);
-                    if (name.indexOf(".")==-1) {
+                    String name = (String) list.get(i);
+                    if (name.indexOf(".") == -1) {
                         list.set(i, getWeb() + "." + name);
                     }
                 } catch (Exception e) {
@@ -1727,45 +1722,45 @@
             String pattern = "\\[(.*?)\\]";
             List newlist = new ArrayList();
             List list = context.getUtil().getMatches(getContent(), pattern, 1);
-            for (int i=0;i<list.size();i++) {
+            for (int i = 0; i < list.size(); i++) {
                 try {
-                    String name = (String)list.get(i);
+                    String name = (String) list.get(i);
                     int i1 = name.indexOf(">");
-                    if (i1!=-1) {
-                        name = name.substring(i1+1);
+                    if (i1 != -1) {
+                        name = name.substring(i1 + 1);
                     }
                     i1 = name.indexOf("&gt;");
-                    if (i1!=-1) {
-                        name = name.substring(i1+4);
+                    if (i1 != -1) {
+                        name = name.substring(i1 + 4);
                     }
                     i1 = name.indexOf("#");
-                    if (i1!=-1) {
-                        name = name.substring(0,i1);
+                    if (i1 != -1) {
+                        name = name.substring(0, i1);
                     }
                     i1 = name.indexOf("?");
-                    if (i1!=-1) {
-                        name = name.substring(0,i1);
+                    if (i1 != -1) {
+                        name = name.substring(0, i1);
                     }
 
                     // Let's get rid of anything that's not a real link
-                    if (name.trim().equals("")||(name.indexOf("$")!=-1)||(name.indexOf("://")!=-1)
-                            ||(name.indexOf("\"")!=-1)||(name.indexOf("\'")!=-1)
-                            ||(name.indexOf("..")!=-1)||(name.indexOf(":")!=-1)||(name.indexOf("=")!=-1))
+                    if (name.trim().equals("") || (name.indexOf("$") != -1) || (name.indexOf("://") != -1)
+                            || (name.indexOf("\"") != -1) || (name.indexOf("\'") != -1)
+                            || (name.indexOf("..") != -1) || (name.indexOf(":") != -1) || (name.indexOf("=") != -1))
                         continue;
 
                     // generate the link
                     Util util = context.getUtil();
-                    String newname = StringUtils.replace( util.noaccents(name), " ", "");
+                    String newname = StringUtils.replace(util.noaccents(name), " ", "");
 
                     // If it is a local link let's add the space
-                    if (newname.indexOf(".")==-1) {
+                    if (newname.indexOf(".") == -1) {
                         newname = getWeb() + "." + name;
                     }
                     if (context.getWiki().exists(newname, context)) {
                         name = newname;
                     } else {
                         // If it is a local link let's add the space
-                        if (name.indexOf(".")==-1) {
+                        if (name.indexOf(".") == -1) {
                             name = getWeb() + "." + name;
                         }
                     }
@@ -1795,30 +1790,30 @@
     }
 
     public String displayView(PropertyClass pclass, String prefix, BaseCollection object, XWikiContext context) {
-        return (pclass==null) ? "" : pclass.displayView(pclass.getName(), prefix, object, context);
+        return (pclass == null) ? "" : pclass.displayView(pclass.getName(), prefix, object, context);
     }
 
     public String displayEdit(PropertyClass pclass, String prefix, BaseCollection object, XWikiContext context) {
-        return (pclass==null) ? "" : pclass.displayEdit(pclass.getName(), prefix, object, context);
+        return (pclass == null) ? "" : pclass.displayEdit(pclass.getName(), prefix, object, context);
     }
 
     public String displayHidden(PropertyClass pclass, String prefix, BaseCollection object, XWikiContext context) {
-        return (pclass==null) ? "" : pclass.displayHidden(pclass.getName(), prefix, object, context);
+        return (pclass == null) ? "" : pclass.displayHidden(pclass.getName(), prefix, object, context);
     }
 
     public String displaySearch(PropertyClass pclass, String prefix, BaseCollection object, XWikiContext context) {
-        return (pclass==null) ? "" : pclass.displaySearch(pclass.getName(), prefix, object, context);
+        return (pclass == null) ? "" : pclass.displaySearch(pclass.getName(), prefix, object, context);
     }
 
     public XWikiAttachment getAttachment(String filename) {
         List list = getAttachmentList();
-        for (int i=0;i<list.size();i++) {
+        for (int i = 0; i < list.size(); i++) {
             XWikiAttachment attach = (XWikiAttachment) list.get(i);
             if (attach.getFilename().equals(filename)) {
                 return attach;
             }
         }
-        for (int i=0;i<list.size();i++) {
+        for (int i = 0; i < list.size(); i++) {
             XWikiAttachment attach = (XWikiAttachment) list.get(i);
             if (attach.getFilename().startsWith(filename + ".")) {
                 return attach;
@@ -1829,16 +1824,16 @@
 
     public BaseObject getFirstObject(String fieldname) {
         Collection objectscoll = getxWikiObjects().values();
-        if (objectscoll==null)
+        if (objectscoll == null)
             return null;
 
-        for (Iterator itobjs = objectscoll.iterator();itobjs.hasNext();) {
-            Vector objects = (Vector)itobjs.next();
-            for (Iterator itobjs2 = objects.iterator();itobjs2.hasNext();) {
+        for (Iterator itobjs = objectscoll.iterator(); itobjs.hasNext();) {
+            Vector objects = (Vector) itobjs.next();
+            for (Iterator itobjs2 = objects.iterator(); itobjs2.hasNext();) {
                 BaseObject obj = (BaseObject) itobjs2.next();
-                if (obj!=null) {
+                if (obj != null) {
                     Set set = obj.getPropertyList();
-                    if ((set!=null)&&set.contains(fieldname))
+                    if ((set != null) && set.contains(fieldname))
                         return obj;
                 }
             }
@@ -1848,21 +1843,21 @@
 
     public int getIntValue(String className, String fieldName) {
         BaseObject obj = getObject(className, 0);
-        if (obj==null)
+        if (obj == null)
             return 0;
         return obj.getIntValue(fieldName);
     }
 
     public long getLongValue(String className, String fieldName) {
         BaseObject obj = getObject(className, 0);
-        if (obj==null)
+        if (obj == null)
             return 0;
         return obj.getLongValue(fieldName);
     }
 
     public String getStringValue(String className, String fieldName) {
         BaseObject obj = getObject(className);
-        if (obj==null)
+        if (obj == null)
             return "";
         String result = obj.getStringValue(fieldName);
         if (result.equals(" "))
@@ -1873,7 +1868,7 @@
 
     public int getIntValue(String fieldName) {
         BaseObject object = getFirstObject(fieldName);
-        if (object==null)
+        if (object == null)
             return 0;
         else
             return object.getIntValue(fieldName);
@@ -1881,7 +1876,7 @@
 
     public long getLongValue(String fieldName) {
         BaseObject object = getFirstObject(fieldName);
-        if (object==null)
+        if (object == null)
             return 0;
         else
             return object.getLongValue(fieldName);
@@ -1889,7 +1884,7 @@
 
     public String getStringValue(String fieldName) {
         BaseObject object = getFirstObject(fieldName);
-        if (object==null)
+        if (object == null)
             return "";
 
         String result = object.getStringValue(fieldName);
@@ -1902,7 +1897,7 @@
 
     public void setStringValue(String className, String fieldName, String value) {
         BaseObject bobject = getObject(className);
-        if (bobject==null) {
+        if (bobject == null) {
             bobject = new BaseObject();
             addObject(className, bobject);
         }
@@ -1913,7 +1908,7 @@
 
     public void setLargeStringValue(String className, String fieldName, String value) {
         BaseObject bobject = getObject(className);
-        if (bobject==null) {
+        if (bobject == null) {
             bobject = new BaseObject();
             addObject(className, bobject);
         }
@@ -1924,7 +1919,7 @@
 
     public void setIntValue(String className, String fieldName, int value) {
         BaseObject bobject = getObject(className);
-        if (bobject==null) {
+        if (bobject == null) {
             bobject = new BaseObject();
             addObject(className, bobject);
         }
@@ -1944,18 +1939,18 @@
 
 
     public void setFullName(String fullname, XWikiContext context) {
-        if (fullname==null)
+        if (fullname == null)
             return;
 
         int i0 = fullname.lastIndexOf(":");
         int i1 = fullname.lastIndexOf(".");
 
-        if (i0!=-1) {
-            database = fullname.substring(0,i0);
-            web = fullname.substring(i0+1,i1);
-            name = fullname.substring(i1+1);
+        if (i0 != -1) {
+            database = fullname.substring(0, i0);
+            web = fullname.substring(i0 + 1, i1);
+            name = fullname.substring(i1 + 1);
         } else {
-            if (i1==-1) {
+            if (i1 == -1) {
                 try {
                     web = context.getDoc().getWeb();
                 } catch (Exception e) {
@@ -1963,8 +1958,8 @@
                 }
                 name = fullname;
             } else {
-                web = fullname.substring(0,i1);
-                name = fullname.substring(i1+1);
+                web = fullname.substring(0, i1);
+                name = fullname.substring(i1 + 1);
             }
         }
 
@@ -1973,7 +1968,7 @@
     }
 
     public String getLanguage() {
-        if (language==null)
+        if (language == null)
             return "";
         else
             return language.trim();
@@ -1984,7 +1979,7 @@
     }
 
     public String getDefaultLanguage() {
-        if (defaultLanguage==null)
+        if (defaultLanguage == null)
             return "";
         else
             return defaultLanguage.trim();
@@ -2009,8 +2004,8 @@
 
     public String getTranslatedContent(String language, XWikiContext context) throws XWikiException {
         XWikiDocument tdoc = getTranslatedDocument(language, context);
-        String rev = (String)context.get("rev");
-        if ((rev==null)||(rev.length()==0))
+        String rev = (String) context.get("rev");
+        if ((rev == null) || (rev.length() == 0))
             return tdoc.getContent();
 
         XWikiDocument cdoc = context.getWiki().getDocument(tdoc, rev, context);
@@ -2025,14 +2020,14 @@
     public XWikiDocument getTranslatedDocument(String language, XWikiContext context) throws XWikiException {
         XWikiDocument tdoc = this;
 
-        if (!((language==null)||(language.equals(""))||language.equals(defaultLanguage))) {
+        if (!((language == null) || (language.equals("")) || language.equals(defaultLanguage))) {
             tdoc = new XWikiDocument(getWeb(), getName());
             tdoc.setLanguage(language);
             String database = context.getDatabase();
             try {
                 // We might need to switch database to
                 // get the translated content
-                if (getDatabase()!=null)
+                if (getDatabase() != null)
                     context.setDatabase(getDatabase());
 
                 tdoc = context.getWiki().getStore().loadXWikiDoc(tdoc, context);
@@ -2051,7 +2046,7 @@
 
     public String getRealLanguage(XWikiContext context) throws XWikiException {
         String lang = getLanguage();
-        if ((lang.equals("")||lang.equals("default")))
+        if ((lang.equals("") || lang.equals("default")))
             return getDefaultLanguage();
         else
             return lang;
@@ -2063,11 +2058,11 @@
                 + Utils.SQLFilter(getWeb()) + "' and doc.name = '" + Utils.SQLFilter(getName()) + "' and doc.language <> ''";
 
         List list = context.getWiki().search(hql, context);
-        if ((list==null)||(list.size()==0)) {
+        if ((list == null) || (list.size() == 0)) {
             return result;
         }
 
-        for (int i=0;i<list.size();i++) {
+        for (int i = 0; i < list.size(); i++) {
             result.add(list.get(i));
         }
         return result;
@@ -2094,7 +2089,7 @@
 
     public List getLastChanges(XWikiContext context) throws XWikiException, DifferentiationFailedException {
         Version version = getRCSVersion();
-        String prev = "1." + (version.last()-1);
+        String prev = "1." + (version.last() - 1);
         XWikiDocument prevdoc = context.getWiki().getDocument(this, prev, context);
 
         return getDeltas(Diff.diff(ToString.stringToArray(getContent()),
@@ -2125,7 +2120,7 @@
 
     protected List getDeltas(Revision rev) {
         ArrayList list = new ArrayList();
-        for (int i=0;i<rev.size();i++) {
+        for (int i = 0; i < rev.size(); i++) {
             list.add(rev.getDelta(i));
         }
         return list;
@@ -2145,7 +2140,7 @@
     public List getMetaDataDiff(XWikiDocument origdoc, XWikiDocument newdoc, XWikiContext context) throws XWikiException {
         List list = new ArrayList();
 
-        if ((origdoc==null)||(newdoc==null))
+        if ((origdoc == null) || (newdoc == null))
             return list;
 
         if (!origdoc.getParent().equals(newdoc.getParent()))
@@ -2176,33 +2171,33 @@
 
     public List getObjectDiff(XWikiDocument origdoc, XWikiDocument newdoc, XWikiContext context) throws XWikiException {
         ArrayList difflist = new ArrayList();
-        for (Iterator itobjs = origdoc.getxWikiObjects().values().iterator();itobjs.hasNext();) {
-            Vector objects = (Vector)itobjs.next();
-            for (Iterator itobjs2 = objects.iterator();itobjs2.hasNext();) {
+        for (Iterator itobjs = origdoc.getxWikiObjects().values().iterator(); itobjs.hasNext();) {
+            Vector objects = (Vector) itobjs.next();
+            for (Iterator itobjs2 = objects.iterator(); itobjs2.hasNext();) {
                 BaseObject origobj = (BaseObject) itobjs2.next();
                 BaseObject newobj = newdoc.getObject(origobj.getClassName(), origobj.getNumber());
 
                 List dlist;
-                if (newobj==null)
-                    dlist = origobj.getDiff(new BaseObject(),context);
+                if (newobj == null)
+                    dlist = origobj.getDiff(new BaseObject(), context);
                 else
-                    dlist = origobj.getDiff(newobj,context);
-                if (dlist.size()>0)
+                    dlist = origobj.getDiff(newobj, context);
+                if (dlist.size() > 0)
                     difflist.add(dlist);
             }
         }
-        for (Iterator itobjs = newdoc.getxWikiObjects().values().iterator();itobjs.hasNext();) {
-            Vector objects = (Vector)itobjs.next();
-            for (Iterator itobjs2 = objects.iterator();itobjs2.hasNext();) {
+        for (Iterator itobjs = newdoc.getxWikiObjects().values().iterator(); itobjs.hasNext();) {
+            Vector objects = (Vector) itobjs.next();
+            for (Iterator itobjs2 = objects.iterator(); itobjs2.hasNext();) {
                 BaseObject newobj = (BaseObject) itobjs2.next();
                 BaseObject origobj = origdoc.getObject(newobj.getClassName(), newobj.getNumber());
 
-                if (origobj==null) {
+                if (origobj == null) {
                     origobj = new BaseObject();
                     origobj.setClassName(newobj.getClassName());
                     origobj.setNumber(newobj.getNumber());
-                    List dlist = origobj.getDiff(newobj,context);
-                    if (dlist.size()>0)
+                    List dlist = origobj.getDiff(newobj, context);
+                    if (dlist.size() > 0)
                         difflist.add(dlist);
                 }
             }
@@ -2215,11 +2210,11 @@
         BaseClass origclass = origdoc.getxWikiClass();
         BaseClass newclass = newdoc.getxWikiClass();
 
-        if ((newclass==null)&&(origclass==null))
+        if ((newclass == null) && (origclass == null))
             return difflist;
 
-        List dlist = origclass.getDiff(newclass,context);
-        if (dlist.size()>0)
+        List dlist = origclass.getDiff(newclass, context);
+        if (dlist.size() > 0)
             difflist.add(dlist);
         return difflist;
     }
@@ -2229,14 +2224,14 @@
         if (oldname.equals(docname))
             return this;
 
-        XWikiDocument newdoc = (XWikiDocument)clone();
+        XWikiDocument newdoc = (XWikiDocument) clone();
         newdoc.setFullName(docname, context);
         newdoc.getxWikiClass().setName(docname);
         Vector objects = newdoc.getObjects(oldname);
-        if (objects!=null) {
+        if (objects != null) {
             Iterator it = objects.iterator();
             while (it.hasNext()) {
-                BaseObject object = (BaseObject)it.next();
+                BaseObject object = (BaseObject) it.next();
                 object.setName(docname);
             }
         }
@@ -2245,11 +2240,9 @@
 
     public XWikiLock getLock(XWikiContext context) throws XWikiException {
         XWikiLock theLock = getStore().loadLock(getId(), context, true);
-        if (theLock != null)
-        {
-            int timeout = context.getWiki().getXWikiPreferenceAsInt("lock_Timeout", 30*60, context);
-            if (theLock.getDate().getTime() + timeout*1000 < new Date().getTime())
-            {
+        if (theLock != null) {
+            int timeout = context.getWiki().getXWikiPreferenceAsInt("lock_Timeout", 30 * 60, context);
+            if (theLock.getDate().getTime() + timeout * 1000 < new Date().getTime()) {
                 getStore().deleteLock(theLock, context, true);
                 theLock = null;
             }
@@ -2264,8 +2257,7 @@
 
     public void removeLock(XWikiContext context) throws XWikiException {
         XWikiLock lock = getStore().loadLock(getId(), context, true);
-        if (lock != null)
-        {
+        if (lock != null) {
             getStore().deleteLock(lock, context, true);
         }
     }
@@ -2274,7 +2266,7 @@
     public BaseObject addObjectFromRequest(XWikiContext context) throws XWikiException {
         // Read info in object
         ObjectAddForm form = new ObjectAddForm();
-        form.setRequest((HttpServletRequest)context.getRequest());
+        form.setRequest((HttpServletRequest) context.getRequest());
         form.readRequest();
 
         XWikiDocument newdoc = (XWikiDocument) clone();
@@ -2332,7 +2324,7 @@
 
     public String getDefaultEditURL(XWikiContext context) throws XWikiException {
         com.xpn.xwiki.XWiki xwiki = context.getWiki();
-        if (getContent().indexOf("includeForm(")!=-1) {
+        if (getContent().indexOf("includeForm(") != -1) {
             return getEditURL("inline", "", context);
         } else {
             String editor = xwiki.getEditorPreference(context);
@@ -2345,7 +2337,7 @@
         String language = "";
         XWikiDocument tdoc = (XWikiDocument) context.get("tdoc");
         String realLang = tdoc.getRealLanguage(context);
-        if ((xwiki.isMultiLingual(context)==true)&&(!realLang.equals(""))) {
+        if ((xwiki.isMultiLingual(context) == true) && (!realLang.equals(""))) {
             language = realLang;
         }
         return getEditURL(action, mode, language, context);
@@ -2353,12 +2345,12 @@
 
     public String getEditURL(String action, String mode, String language, XWikiContext context) {
         StringBuffer editparams = new StringBuffer();
-        if (!mode.equals(""))  {
+        if (!mode.equals("")) {
             editparams.append("xpage=");
             editparams.append(mode);
         }
 
-        if (!language.equals(""))  {
+        if (!language.equals("")) {
             if (!mode.equals(""))
                 editparams.append("&");
             editparams.append("language=");
@@ -2367,12 +2359,31 @@
         return getURL(action, editparams.toString(), context);
     }
 
-	public String getDefaultTemplate() {
-		return defaultTemplate;
-	}
+    public String getDefaultTemplate() {
+        return defaultTemplate;
+    }
 
-	public void setDefaultTemplate(String defaultTemplate) {
-		this.defaultTemplate = defaultTemplate;
-	}
+    public void setDefaultTemplate(String defaultTemplate) {
+        this.defaultTemplate = defaultTemplate;
+    }
 
+    public Vector getComments() {
+        return getComments(true);
+    }
+
+    public Vector getComments(boolean asc) {
+        if (asc)
+            return getObjects("XWiki.XWikiComments");
+        else {
+            Vector list = getObjects("XWiki.XWikiComments");
+            if (list == null)
+                return list;
+            Vector newlist = new Vector();
+            for (int i = list.size() - 1; i >= 0; i--) {
+                newlist.add(list.get(i));
+            }
+            return newlist;
+        }
+    }
+
 }

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/web/CommentAddAction.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/web/CommentAddAction.java	2006-03-01 16:23:18 UTC (rev 953)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/web/CommentAddAction.java	2006-03-02 07:39:59 UTC (rev 954)
@@ -1,24 +1,24 @@
-/*
- * 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 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 sdumitriu
+ */
 package com.xpn.xwiki.web;
 
 import com.xpn.xwiki.XWiki;
@@ -29,28 +29,37 @@
 import com.xpn.xwiki.objects.classes.BaseClass;
 
 public class CommentAddAction extends XWikiAction {
-	public boolean action(XWikiContext context) throws XWikiException {
+    public boolean action(XWikiContext context) throws XWikiException {
         XWiki xwiki = context.getWiki();
         XWikiRequest request = context.getRequest();
         XWikiResponse response = context.getResponse();
         XWikiDocument doc = context.getDoc();
         ObjectAddForm oform = (ObjectAddForm) context.getForm();
 
-        XWikiDocument olddoc = (XWikiDocument) doc.clone();
-        String className = "XWiki.XWikiComments";
-        int nb = doc.createNewObject(className, context);
+        // Make sure this class exists
+        BaseClass baseclass = xwiki.getCommentsClass(context);
 
-        BaseObject oldobject = doc.getObject(className, nb);
-        BaseClass baseclass = oldobject.getxWikiClass(context);
-        BaseObject newobject = (BaseObject) baseclass.fromMap(oform.getObject(className), oldobject);
-        newobject.setNumber(oldobject.getNumber());
-        newobject.setName(doc.getFullName());
-        doc.setObject(className, nb, newobject);
-        xwiki.saveDocument(doc, olddoc, context);
-
+        if (doc.isNew()) {
+            return true;
+        } else {
+            XWikiDocument olddoc = (XWikiDocument) doc.clone();
+            String className = "XWiki.XWikiComments";
+            int nb = doc.createNewObject(className, context);
+            BaseObject oldobject = doc.getObject(className, nb);
+            BaseObject newobject = (BaseObject) baseclass.fromMap(oform.getObject(className), oldobject);
+            newobject.setNumber(oldobject.getNumber());
+            newobject.setName(doc.getFullName());
+            doc.setObject(className, nb, newobject);
+            xwiki.saveDocument(doc, olddoc, context);
+        }
         // forward to edit
         String redirect = Utils.getRedirect("edit", context);
         sendRedirect(response, redirect);
         return false;
-	}
+    }
+
+    public String render(XWikiContext context) throws XWikiException {
+        context.put("message", "nocommentwithnewdoc");
+        return "docnotexist";
+    }
 }

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/web/ViewrevAction.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/web/ViewrevAction.java	2006-03-01 16:23:18 UTC (rev 953)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/web/ViewrevAction.java	2006-03-02 07:39:59 UTC (rev 954)
@@ -25,14 +25,16 @@
 import com.xpn.xwiki.XWikiException;
 
 public class ViewrevAction extends XWikiAction {
-	public String render(XWikiContext context) throws XWikiException {
+    public String render(XWikiContext context) throws XWikiException {
         try {
-        handleRevision(context);
+            handleRevision(context);
         } catch (XWikiException e) {
-           if (e.getCode()==XWikiException.ERROR_XWIKI_STORE_HIBERNATE_UNEXISTANT_VERSION)
-              return "notexist";
-           else
-             throw e;
+            if (e.getCode() == XWikiException.ERROR_XWIKI_STORE_HIBERNATE_UNEXISTANT_VERSION) {
+                context.put("message", "revisiondoesnotexist");
+                return "notexist";
+
+            } else
+                throw e;
         }
         return "view";
     }

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/web/XWikiAction.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/web/XWikiAction.java	2006-03-01 16:23:18 UTC (rev 953)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/web/XWikiAction.java	2006-03-02 07:39:59 UTC (rev 954)
@@ -22,17 +22,16 @@
  */
 
 
-
 package com.xpn.xwiki.web;
 
-import java.io.IOException;
-import java.util.Iterator;
-import java.util.List;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
+import com.xpn.xwiki.XWiki;
+import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.api.Document;
+import com.xpn.xwiki.doc.XWikiDocument;
+import com.xpn.xwiki.monitor.api.MonitorPlugin;
+import com.xpn.xwiki.plugin.fileupload.FileUploadPlugin;
+import com.xpn.xwiki.render.XWikiVelocityRenderer;
 import org.apache.commons.fileupload.FileItem;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -44,65 +43,72 @@
 import org.apache.struts.upload.MultipartRequestWrapper;
 import org.apache.velocity.VelocityContext;
 
-import com.xpn.xwiki.XWiki;
-import com.xpn.xwiki.XWikiContext;
-import com.xpn.xwiki.XWikiException;
-import com.xpn.xwiki.api.Document;
-import com.xpn.xwiki.doc.XWikiDocument;
-import com.xpn.xwiki.monitor.api.MonitorPlugin;
-import com.xpn.xwiki.plugin.fileupload.FileUploadPlugin;
-import com.xpn.xwiki.render.XWikiVelocityRenderer;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
 
 /**
  * <p>A simple action that handles the display and editing of an
  * wiki page.. </p>
- *
+ * <p/>
  * <p>The action support an <i>action</i> URL. The action in the URL
  * controls what this action class does. The following values are supported:</p>
  * <ul>
- *    <li>view - view the Wiki Document
- *   <li>edit - edit the Wiki Document
- *   <li>preview - preview the Wiki Document
- *   <li>save - save the Wiki Document
+ * <li>view - view the Wiki Document
+ * <li>edit - edit the Wiki Document
+ * <li>preview - preview the Wiki Document
+ * <li>save - save the Wiki Document
  * </ul>
- * 
  */
-public abstract class XWikiAction extends Action
-{
+public abstract class XWikiAction extends Action {
 
     // --------------------------------------------------------- Public Methods
+
     /**
      * Handle server requests.
      *
      * @param mapping The ActionMapping used to select this instance
-     * @param form The optional ActionForm bean for this request (if any)
-     * @param req The HTTP request we are processing
-     * @param resp The HTTP response we are creating
-     *
-     * @exception IOException if an input/output error occurs
-     * @exception ServletException if a servlet exception occurs
+     * @param form    The optional ActionForm bean for this request (if any)
+     * @param req     The HTTP request we are processing
+     * @param resp    The HTTP response we are creating
+     * @throws IOException      if an input/output error occurs
+     * @throws ServletException if a servlet exception occurs
      */
     public ActionForward execute(ActionMapping mapping,
                                  ActionForm form,
                                  HttpServletRequest req,
                                  HttpServletResponse resp)
-            throws Exception, ServletException
-    {
+            throws Exception, ServletException {
 //        String action = mapping.getName();
 
         MonitorPlugin monitor = null;
         FileUploadPlugin fileupload = null;
         XWikiContext context = null;
+        boolean wikidoesnotexist = false;
+
         try {
             XWikiRequest request = new XWikiServletRequest(req);
             XWikiResponse response = new XWikiServletResponse(resp);
             context = Utils.prepareContext(mapping.getName(), request, response,
-            		new XWikiServletContext(servlet.getServletContext()));
+                    new XWikiServletContext(servlet.getServletContext()));
 
             // Add the form to the context
             context.setForm((XWikiForm) form);
-            XWiki xwiki = XWiki.getXWiki(context);
-            
+            XWiki xwiki = null;
+            try {
+                xwiki = XWiki.getXWiki(context);
+            } catch (XWikiException e) {
+                if (e.getCode() == XWikiException.ERROR_XWIKI_DOES_NOT_EXIST) {
+                    // redirect
+                    String redirect = context.getWiki().Param("xwiki.virtual.redirect");
+                    response.sendRedirect(redirect);
+                    return null;
+                }
+            }
+
             // Parses multipart so that parms in multipart are available for all actions
             fileupload = handleMultipart(req, context);
 
@@ -113,10 +119,10 @@
 
             // Start monitoring timer
             monitor = (MonitorPlugin) xwiki.getPlugin("monitor", context);
-            if (monitor!=null)
-              monitor.startRequest("", mapping.getName(), context.getURL());
-            if (monitor!=null)
-             monitor.startTimer("request");
+            if (monitor != null)
+                monitor.startRequest("", mapping.getName(), context.getURL());
+            if (monitor != null)
+                monitor.startTimer("request");
 
             VelocityContext vcontext = null;
             // Prepare velocity context
@@ -124,19 +130,19 @@
 
             try {
                 // Prepare documents and put them in the context
-                if (xwiki.prepareDocuments(request, context, vcontext)==false)
+                if (xwiki.prepareDocuments(request, context, vcontext) == false)
                     return null;
 
-                if (monitor!=null)
-                 monitor.setWikiPage(context.getDoc().getFullName());
+                if (monitor != null)
+                    monitor.setWikiPage(context.getDoc().getFullName());
 
                 String renderResult = null;
 
                 if (action(context)) {
-                	renderResult = render(context);
+                    renderResult = render(context);
                 }
-                
-                if (renderResult!=null) {
+
+                if (renderResult != null) {
                     String page = Utils.getPage(request, renderResult);
                     Utils.parseTemplate(page, !page.equals("direct"), context);
                 }
@@ -150,11 +156,11 @@
                 vcontext.put("exp", e);
                 try {
                     XWikiException xex = (XWikiException) e;
-                    if (xex.getCode()==XWikiException.ERROR_XWIKI_ACCESS_DENIED) {
+                    if (xex.getCode() == XWikiException.ERROR_XWIKI_ACCESS_DENIED) {
                         String page = Utils.getPage(request, "accessdenied");
                         Utils.parseTemplate(page, context);
                         return null;
-                    } else if (xex.getCode()==XWikiException.ERROR_XWIKI_USER_INACTIVE) {
+                    } else if (xex.getCode() == XWikiException.ERROR_XWIKI_USER_INACTIVE) {
                         String page = Utils.getPage(request, "userinactive");
                         Utils.parseTemplate(page, context);
                         return null;
@@ -162,7 +168,7 @@
 
                     Log log = LogFactory.getLog(XWikiAction.class);
                     if (log.isWarnEnabled()) {
-                           log.warn("Uncaught exception: " + e.getMessage(), e);
+                        log.warn("Uncaught exception: " + e.getMessage(), e);
                     }
                     Utils.parseTemplate(Utils.getPage(request, "exception"), context);
                     return null;
@@ -172,19 +178,20 @@
                     e2.printStackTrace();
                     return null;
                 }
-            } finally {
+            }
+            finally {
 
                 // Let's make sure we have flushed content and closed
                 try {
-                     response.getWriter().flush();
+                    response.getWriter().flush();
                 } catch (Throwable e) {
                 }
 
-                if (monitor!=null)
-                 monitor.endTimer("request");
+                if (monitor != null)
+                    monitor.endTimer("request");
 
-                if (monitor!=null)
-                 monitor.startTimer("notify");
+                if (monitor != null)
+                    monitor.startTimer("notify");
 
                 // Let's handle the notification and make sure it never fails
                 try {
@@ -193,43 +200,39 @@
                     e.printStackTrace();
                 }
 
-                if (monitor!=null)
-                 monitor.endTimer("notify");
+                if (monitor != null)
+                    monitor.endTimer("notify");
 
                 // Make sure we cleanup database connections
                 // There could be cases where we have some
-                if ((context!=null)&&(xwiki!=null)) {
+                if ((context != null) && (xwiki != null)) {
                     xwiki.getStore().cleanUp(context);
                 }
             }
-        } finally {
+        }
+        finally {
             // End request
-            if (monitor!=null)
+            if (monitor != null)
                 monitor.endRequest();
-            if (fileupload!=null)
+            if (fileupload != null)
                 fileupload.cleanFileList(context);
- 
+
             MDC.remove("url");
         }
     }
-    
-    private FileUploadPlugin handleMultipart(HttpServletRequest request, XWikiContext context)
-    {
+
+    private FileUploadPlugin handleMultipart(HttpServletRequest request, XWikiContext context) {
         FileUploadPlugin fileupload = null;
-        try
-        {
-            if (request instanceof MultipartRequestWrapper)
-            {
+        try {
+            if (request instanceof MultipartRequestWrapper) {
                 fileupload = new FileUploadPlugin("fileupload", "fileupload", context);
                 fileupload.loadFileList(context);
                 context.put("fileuploadplugin", fileupload);
                 MultipartRequestWrapper mpreq = (MultipartRequestWrapper) request;
                 List fileItems = fileupload.getFileItems(context);
-                for (Iterator iter = fileItems.iterator(); iter.hasNext();)
-                {
+                for (Iterator iter = fileItems.iterator(); iter.hasNext();) {
                     FileItem item = (FileItem) iter.next();
-                    if (item.isFormField())
-                    {
+                    if (item.isFormField()) {
                         String sName = item.getFieldName();
                         String sValue = item.getString();
                         mpreq.setParameter(sName, sVa