r1355 - 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/plugin main/java/com/xpn/xwiki/plugin/fileupload main/java/com/xpn/xwiki/plugin/packaging main/java/com/xpn/xwiki/plugin/query main/java/com/xpn/xwiki/plugin/userdirectory main/java/com/xpn/xwiki/plugin/usertools main/java/com/xpn/xwiki/render main/java/com/xpn/xwiki/render/groovy main/java/com/xpn/xwiki/web main/resources main/web/templates test/java/com/xpn/xwiki/plugin/charts/tests test/java/com/xpn/xwiki/test test/java/com/xpn/xwiki/test/plugin/query

Jeremi Joslin jeremi at users.forge.objectweb.org
Tue Oct 3 15:53:25 CEST 2006


Author: jeremi
Date: 2006-10-03 15:53:24 +0200 (Tue, 03 Oct 2006)
New Revision: 1355

Added:
   xwiki/trunk/src/test/java/com/xpn/xwiki/test/CustomDocumentClass.java
   xwiki/trunk/src/test/java/com/xpn/xwiki/test/XWikiDocumentTest.java
Modified:
   xwiki/trunk/src/main/java/com/xpn/xwiki/XWiki.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/XWikiException.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/api/Document.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/plugin/XWikiPluginManager.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/fileupload/FileUploadPlugin.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/fileupload/FileUploadPluginApi.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/packaging/Package.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/query/SecHibernateQuery.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/userdirectory/Group.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/userdirectory/UserDirectoryPlugin.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/usertools/XWikiUserManagementToolsAPI.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/usertools/XWikiUserManagementToolsImpl.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/render/XWikiVelocityRenderer.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/render/groovy/XWikiGroovyRenderer.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/web/AdminAction.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/web/EditAction.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/web/InlineAction.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/web/PreviewAction.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/web/XWikiAction.java
   xwiki/trunk/src/main/resources/xwiki.hbm.xml
   xwiki/trunk/src/main/web/templates/macros.vm
   xwiki/trunk/src/test/java/com/xpn/xwiki/plugin/charts/tests/ChartingPluginTest.java
   xwiki/trunk/src/test/java/com/xpn/xwiki/test/AbstractRenderTest.java
   xwiki/trunk/src/test/java/com/xpn/xwiki/test/XWikiTest.java
   xwiki/trunk/src/test/java/com/xpn/xwiki/test/plugin/query/QueryPluginApiTest.java
Log:
[GELC]
* Add Custom class for Document
* Change all new Document() by XWikiDocument.newDocument()
* fix the UserManagementTools API (remove the context)

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/XWiki.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/XWiki.java	2006-09-28 17:32:49 UTC (rev 1354)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/XWiki.java	2006-10-03 13:53:24 UTC (rev 1355)
@@ -3087,7 +3087,7 @@
         try {
             doc = getDocument(getDocumentName(request, context), context);
             context.put("doc", doc);
-            vcontext.put("doc", new Document(doc, context));
+            vcontext.put("doc", doc.newDocument(context));
             vcontext.put("cdoc", vcontext.get("doc"));
         } catch (XWikiException e) {
             doc = context.getDoc();
@@ -3098,7 +3098,7 @@
                     doc.setElements(XWikiDocument.HAS_ATTACHMENTS | XWikiDocument.HAS_OBJECTS);
                     doc.setStore(getStore());
                     context.put("doc", doc);
-                    vcontext.put("doc", new Document(doc, context));
+                    vcontext.put("doc", doc.newDocument(context));
                     vcontext.put("cdoc", vcontext.get("doc"));
                 }
                 if (!checkAccess("admin", doc, context)) {
@@ -3123,7 +3123,7 @@
 
         XWikiDocument tdoc = doc.getTranslatedDocument(context);
         context.put("tdoc", tdoc);
-        vcontext.put("tdoc", new Document(tdoc, context));
+        vcontext.put("tdoc", tdoc.newDocument(context));
         return true;
     }
 
@@ -3975,8 +3975,9 @@
     }
 
     public String getConvertingUserNameType(XWikiContext context){
-        if (context.getWiki().getXWikiPreference("convertmail", context) != null)
-            return context.getWiki().getXWikiPreference("convertmail", context);
+        if (context.getWiki().getXWikiPreference("convertmail", context) != null
+                && context.getWiki().getXWikiPreference("convertmail", context).length() > 0)
+            return context.getWiki().getXWikiPreference("convertmail", "0", context);
         return context.getWiki().Param("xwiki.authentication.convertemail", "0");
     }
 

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/XWikiException.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/XWikiException.java	2006-09-28 17:32:49 UTC (rev 1354)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/XWikiException.java	2006-10-03 13:53:24 UTC (rev 1355)
@@ -75,6 +75,7 @@
     public static final int ERROR_XWIKI_DOES_NOT_EXIST = 2;
     public static final int ERROR_XWIKI_INIT_FAILED = 3;
     public static final int ERROR_XWIKI_MKDIR = 4;
+    public static final int ERROR_XWIKI_DOC_CUSTOMDOCINVOCATIONERROR = 5;
 
     // Config
     public static final int ERROR_XWIKI_CONFIG_FILENOTFOUND = 1001;

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/api/Document.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/api/Document.java	2006-09-28 17:32:49 UTC (rev 1354)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/api/Document.java	2006-10-03 13:53:24 UTC (rev 1355)
@@ -28,10 +28,9 @@
 
 package com.xpn.xwiki.api;
 
-import com.xpn.xwiki.*;
 import com.xpn.xwiki.XWiki;
-import com.xpn.xwiki.plugin.fileupload.FileUploadPluginApi;
-import com.xpn.xwiki.plugin.fileupload.FileUploadPlugin;
+import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.XWikiException;
 import com.xpn.xwiki.doc.XWikiAttachment;
 import com.xpn.xwiki.doc.XWikiDocument;
 import com.xpn.xwiki.doc.XWikiDocumentArchive;
@@ -39,14 +38,21 @@
 import com.xpn.xwiki.objects.BaseObject;
 import com.xpn.xwiki.objects.BaseProperty;
 import com.xpn.xwiki.objects.classes.BaseClass;
+import com.xpn.xwiki.plugin.fileupload.FileUploadPlugin;
 import com.xpn.xwiki.stats.impl.DocumentStats;
 import com.xpn.xwiki.util.TOCGenerator;
 import com.xpn.xwiki.util.Util;
+import org.apache.commons.fileupload.DefaultFileItem;
 import org.suigeneris.jrcs.diff.DifferentiationFailedException;
 import org.suigeneris.jrcs.rcs.Version;
-import org.apache.commons.fileupload.DefaultFileItem;
 
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Vector;
 
 
 public class Document extends Api {
@@ -308,7 +314,7 @@
      * @throws XWikiException
      */
     public Document getTranslatedDocument(String language) throws XWikiException {
-        return new Document(doc.getTranslatedDocument(language, context), context);
+        return doc.getTranslatedDocument(language, context).newDocument(context);
     }
 
     /**
@@ -319,7 +325,7 @@
      * @throws XWikiException
      */
     public Document getTranslatedDocument() throws XWikiException {
-        return new Document(doc.getTranslatedDocument(context), context);
+        return doc.getTranslatedDocument(context).newDocument(context);
     }
 
     /**
@@ -1083,6 +1089,10 @@
         getDoc().setTitle(title);
     }
 
+    public void setCustomClass(String customClass) {
+        getDoc().setCustomClass(customClass);
+    }
+
     public void setParent(String parent) {
         getDoc().setParent(parent);
     }
@@ -1181,6 +1191,7 @@
 
         XWiki xwiki = context.getWiki();
         FileUploadPlugin fileupload = (FileUploadPlugin) xwiki.getPlugin("fileupload", context);
+        fileupload.loadFileList(context);
         List fileuploadlist = fileupload.getFileItems(context);
         List attachments = new ArrayList();
         int nb = 0;

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/api/XWiki.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/api/XWiki.java	2006-09-28 17:32:49 UTC (rev 1354)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/api/XWiki.java	2006-10-03 13:53:24 UTC (rev 1355)
@@ -101,7 +101,7 @@
             return null;
         }
 
-        Document newdoc = new Document(doc, context);
+        Document newdoc = doc.newDocument(context);
         return newdoc;
     }
 
@@ -148,7 +148,7 @@
             return null;
         }
 
-        Document newdoc = new Document(doc, context);
+        Document newdoc = doc.newDocument(context);
         return newdoc;
     }
 
@@ -171,7 +171,7 @@
 
         try {
             XWikiDocument revdoc = xwiki.getDocument(doc.getDoc(), rev, context);
-            Document newdoc = new Document(revdoc, context);
+            Document newdoc = revdoc.newDocument(context);
             return newdoc;
         } catch (Exception e) {
             // Can't read versioned document
@@ -377,7 +377,7 @@
         if (docs != null) {
             for (Iterator iter = result.iterator(); iter.hasNext();) {
                 XWikiDocument doc = (XWikiDocument) iter.next();
-                Document wrappedDoc = new Document(doc, context);
+                Document wrappedDoc = doc.newDocument(context);
                 result.add(wrappedDoc);
             }
         }
@@ -1903,7 +1903,7 @@
      * @return an XWikiDocument wrapped in a Document
      */
     public Document createDocument() {
-        return new Document(new XWikiDocument(), context);
+        return new XWikiDocument().newDocument(context);
     }
 
     /**

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java	2006-09-28 17:32:49 UTC (rev 1354)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java	2006-10-03 13:53:24 UTC (rev 1355)
@@ -73,6 +73,7 @@
 import java.io.StringWriter;
 import java.lang.ref.SoftReference;
 import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
 import java.net.URL;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
@@ -96,6 +97,7 @@
     private String creator;
     private String author;
     private String contentAuthor;
+    private String customClass;
     private Date contentUpdateDate;
     private Date updateDate;
     private Date creationDate;
@@ -254,6 +256,7 @@
         this.language = "";
         this.defaultLanguage = "";
         this.attachmentList = new ArrayList();
+        this.customClass = "";
     }
 
     public XWikiDocument getParentDoc() {
@@ -593,6 +596,38 @@
         return getDocumentArchive();
     }
 
+    /**
+     * return a wrapped version of an XWikiDocument. Prefer this function instead of new Document(XWikiDocument, XWikiContext)
+     *
+     * @param context
+     * @return
+     */
+    public com.xpn.xwiki.api.Document newDocument(String className, XWikiContext context) {
+            if (!((className==null)||(className.equals(""))))
+                try {
+                    Class[] classes = new Class[]{XWikiDocument.class, XWikiContext.class};
+                    Object[] args = new Object[]{this, context};
+                    return (com.xpn.xwiki.api.Document) Class.forName(className).getConstructor(classes).newInstance(args);
+                } catch (InstantiationException e) {
+                    e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+                } catch (IllegalAccessException e) {
+                    e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+                } catch (ClassNotFoundException e) {
+                    e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+                } catch (NoSuchMethodException e) {
+                    e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+                } catch (InvocationTargetException e) {
+                    e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+                }
+        return new com.xpn.xwiki.api.Document(this, context);
+
+    }
+
+    public com.xpn.xwiki.api.Document newDocument(XWikiContext context) {
+        String customClass = getCustomClass();
+        return newDocument(customClass, context);
+    }
+
     public void loadArchive(XWikiContext context) throws XWikiException {
         if (archive==null) {
             XWikiDocumentArchive arch = getVersioningStore(context).getXWikiDocumentArchive(this, context);
@@ -1244,6 +1279,7 @@
         doc.setContentDirty(isContentDirty());
         doc.setCreationDate(getCreationDate());
         doc.setDate(getDate());
+        doc.setCustomClass(getCustomClass());
         doc.setContentUpdateDate(getContentUpdateDate());
         doc.setTitle(getTitle());
         doc.setFormat(getFormat());
@@ -1473,6 +1509,10 @@
         el.addText(getAuthor());
         docel.add(el);
 
+        el = new DOMElement("customClass");
+        el.addText(getCustomClass());
+        docel.add(el);
+
         el = new DOMElement("contentAuthor");
         el.addText(getContentAuthor());
         docel.add(el);
@@ -1644,6 +1684,7 @@
         setParent(getElement(docel, "parent"));
         setCreator(getElement(docel, "creator"));
         setAuthor(getElement(docel, "author"));
+        setCustomClass(getElement(docel, "customClass"));
         setContentAuthor(getElement(docel, "contentAuthor"));
         setVersion(getElement(docel, "version"));
         setContent(getElement(docel, "content"));
@@ -2827,4 +2868,11 @@
         }
     }
 
+    public String getCustomClass() {
+        return customClass;
+    }
+
+    public void setCustomClass(String customClass) {
+        this.customClass = customClass;
+    }
 }

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/XWikiPluginManager.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/XWikiPluginManager.java	2006-09-28 17:32:49 UTC (rev 1354)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/XWikiPluginManager.java	2006-10-03 13:53:24 UTC (rev 1355)
@@ -24,6 +24,7 @@
 package com.xpn.xwiki.plugin;
 
 import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.XWikiException;
 import com.xpn.xwiki.doc.XWikiAttachment;
 import org.apache.commons.lang.StringUtils;
 
@@ -67,7 +68,7 @@
             if (plugin!=null) {
                 plugins.add(plugin.getName());
                 plugins_classes.put(plugin.getName(), plugin);
-                initPlugin(plugin, pluginClass);
+                initPlugin(plugin, pluginClass, context);
             }
         } catch (Exception e) {
             // Log an error but do not fail..
@@ -119,7 +120,7 @@
         }
     }
     
-    public void initPlugin(Object plugin, Class pluginClass){
+    public void initPlugin(Object plugin, Class pluginClass, XWikiContext context) throws XWikiException {
         Method[] methods = pluginClass.getDeclaredMethods();
         for (int i = 0; i < methods.length; i++)
         {
@@ -128,6 +129,7 @@
             if (functionList.containsKey(name))
                 ((Vector)functionList.get(name)).add(plugin);
         }
+        ((XWikiPluginInterface)plugin).init(context);
     }
 
     public Vector getPlugins(String functionName){

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/fileupload/FileUploadPlugin.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/fileupload/FileUploadPlugin.java	2006-09-28 17:32:49 UTC (rev 1354)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/fileupload/FileUploadPlugin.java	2006-10-03 13:53:24 UTC (rev 1355)
@@ -1,297 +1,297 @@
-/*
- * 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 sdumitriu
- */
-
-package com.xpn.xwiki.plugin.fileupload;
-
-import com.xpn.xwiki.XWiki;
-import com.xpn.xwiki.XWikiContext;
-import com.xpn.xwiki.XWikiException;
-import com.xpn.xwiki.api.Api;
-import com.xpn.xwiki.plugin.XWikiDefaultPlugin;
-import com.xpn.xwiki.plugin.XWikiPluginInterface;
-import com.xpn.xwiki.web.XWikiRequest;
-import org.apache.commons.fileupload.*;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-
-public class FileUploadPlugin extends XWikiDefaultPlugin implements XWikiPluginInterface {
-    private static Log mLogger =
-            LogFactory.getFactory().getInstance(FileUploadPlugin.class);
-
-    private static final long UPLOAD_DEFAULT_MAXSIZE = 10000000L;
-    private static final long UPLOAD_DEFAULT_SIZETHRESHOLD = 100000L;
-
-    public FileUploadPlugin(String name, String className, XWikiContext context) {
-        super(name, className, context);
-    }
-
-    /**
-     *  Allow to get the plugin name
-     * @return plugin name
-     */
-    public String getName() {
-        return "fileupload";
-    }
-
-    public void init(XWikiContext context) {
-    }
-
-    public void virtualInit(XWikiContext context) {
-    }
-
-    public Api getPluginApi(XWikiPluginInterface plugin, XWikiContext context) {
-        return new FileUploadPluginApi((FileUploadPlugin) plugin, context);
-    }
-
-    /**
-     *  endRendering to make sure we don't leave files in temp directories
-     * @param context Context of the request
-    */
-    public void endRendering(XWikiContext context) {
-        cleanFileList(context);
-    }
-
-    /**
-     *  Deletes all temporary files of the upload
-     * @param context Context of the request
-     */
-    public void cleanFileList(XWikiContext context) {
-        List fileuploadlist = (List) context.get("fileuploadlist");
-        if (fileuploadlist!=null) {
-             for (int i=0;i<fileuploadlist.size();i++) {
-                 try {
-                     FileItem item = (FileItem) fileuploadlist.get(i);
-                     item.delete();
-                 } catch (Exception e) {
-                 }
-             }
-            context.remove("fileuploadlist");
-        }
-    }
-
-    /**
-     * Allows to load the file list in the context if there is a file upload
-     * Default uploadMaxSize, uploadSizeThreashold and temporary directory are used
-     * @param context Context of the request
-     * @throws XWikiException An XWikiException is thrown if the request could not be parser
-     */
-    public void loadFileList(XWikiContext context) throws XWikiException {
-        XWiki xwiki = context.getWiki();
-        loadFileList(xwiki.getXWikiPreferenceAsLong("upload_maxsize", UPLOAD_DEFAULT_MAXSIZE, context),
-                (int)xwiki.getXWikiPreferenceAsLong("upload_sizethreshold", UPLOAD_DEFAULT_SIZETHRESHOLD, context),
-                xwiki.Param("xwiki.upload.tempdir"), context);
-    }
-
-    /**
-     * Allows to load the file list in the context if there is a file upload
-     *
-     * @param uploadMaxSize Maximum size of the request
-     * @param uploadSizeThreashold  Threashold over which the data should be on disk and not in memory
-     * @param tempdir Temporary Directory to store temp data
-     * @param context Context of the request
-     * @throws XWikiException An XWikiException is thrown if the request could not be parser
-     */
-    public void loadFileList(long uploadMaxSize, int uploadSizeThreashold, String tempdir, XWikiContext context) throws XWikiException {
-        // Get the FileUpload Data
-        DiskFileUpload fileupload = new DiskFileUpload();
-        fileupload.setSizeMax(uploadMaxSize);
-        fileupload.setSizeThreshold(uploadSizeThreashold);
-        context.put("fileupload", fileupload);
-        XWikiRequest request = context.getRequest() ;
-
-        if (tempdir != null) {
-            fileupload.setRepositoryPath(tempdir);
-            (new File(tempdir)).mkdirs();
-        }
-        else {
-            fileupload.setRepositoryPath(".");
-        }
-
-        try {
-            List list = fileupload.parseRequest(request.getHttpServletRequest());
-            // We store the file list in the context, throw Exception ERROR_XWIKI_APP_FILE_EXCEPTION_MAXSIZE
-            context.put("fileuploadlist", list);
-        }catch (FileUploadBase.SizeLimitExceededException  e) {
-              throw new XWikiException(XWikiException.MODULE_XWIKI_APP,
-                    XWikiException.ERROR_XWIKI_APP_FILE_EXCEPTION_MAXSIZE,
-                    "Exception uploaded file");
-        }catch(FileUploadException e){
-            throw new XWikiException(XWikiException.MODULE_XWIKI_APP,
-                    XWikiException.ERROR_XWIKI_APP_UPLOAD_PARSE_EXCEPTION,
-                    "Exception while parsing uploaded file", e);
-        }
-    }
-
-    /**
-     * Allows to retrieve the current FileItem list
-     * loadFileList needs to be called beforehand
-     * @param context Context of the request
-     * @return a list of FileItem elements
-     */
-    public List getFileItems(XWikiContext context) {
-        return (List) context.get("fileuploadlist");
-    }
-
-    /**
-     * Allows to retrieve the data of FileItem named name
-     * loadFileList needs to be called beforehand
-
-     * @param name Name of the item
-     * @param context Context of the request
-     * @return byte[] of the data
-     * @throws XWikiException Exception is thrown if the data could not be read
-     */
-    public byte[] getFileItemData(String name, XWikiContext context) throws XWikiException {
-        List fileuploadlist = getFileItems(context);
-        if (fileuploadlist==null) {
-            return null;
-        }
-
-        DefaultFileItem  fileitem = null;
-        for (int i=0;i<fileuploadlist.size();i++) {
-            DefaultFileItem item = (DefaultFileItem) fileuploadlist.get(i);
-            if (name.equals(item.getFieldName())) {
-                fileitem = item;
-                break;
-            }
-        }
-
-        if (fileitem==null)
-            return null;
-
-        byte[] data = new byte[(int)fileitem.getSize()];
-        try{
-            InputStream fileis = fileitem.getInputStream();
-            if(fileis != null){
-                fileis.read(data);
-                fileis.close();
-            }
-
-        } catch (java.lang.OutOfMemoryError e) {
-            throw new XWikiException(XWikiException.MODULE_XWIKI_APP,
-                   XWikiException.ERROR_XWIKI_APP_JAVA_HEAP_SPACE,"Java Heap Space, Out of memory exception",e);
-        }catch(IOException ie){
-            throw new XWikiException(XWikiException.MODULE_XWIKI_APP,
-                    XWikiException.ERROR_XWIKI_APP_UPLOAD_FILE_EXCEPTION,"Exception while reading uploaded parsed file",ie) ;
-        }
-        return data;
-    }
-
-
-    /**
-     * Allows to retrieve the data of FileItem named name
-     * loadFileList needs to be called beforehand
-
-     * @param name Name of the item
-     * @param context Context of the request
-     * @return String of the data
-     * @throws XWikiException Exception is thrown if the data could not be read
-     * @param name
-     * @param context
-     * @return
-     * @throws XWikiException
-     */
-    public String getFileItemAsString(String name, XWikiContext context) throws XWikiException {
-        byte[] data = getFileItemData(name, context);
-        if (data==null)
-            return null;
-        else
-            return new String(data);
-    }
-
-    /**
-     * Allows to retrieve the data of FileItem named name
-     * loadFileList needs to be called beforehand
-     * @deprecated not well named, use {@link #getFileItemAsString(String, com.xpn.xwiki.XWikiContext)}
-     * @param name Name of the item
-     * @param context Context of the request
-     * @return String of the data
-     * @throws XWikiException Exception is thrown if the data could not be read
-     * @param name
-     * @param context
-     * @return
-     * @throws XWikiException
-     */
-    public String getFileItem(String name, XWikiContext context) throws XWikiException {
-        byte[] data = getFileItemData(name, context);
-        if (data==null)
-            return null;
-        else
-            return new String(data);
-    }
-
-    /**
-     * Allows to retrieve the list of FileItem names
-     * loadFileList needs to be called beforehand
-
-     * @param context Context of the request
-     * @return List of strings of the item names
-     */
-    public List getFileItemNames(XWikiContext context) {
-        List itemnames = new ArrayList();
-        List fileuploadlist = getFileItems(context);
-        if (fileuploadlist==null) {
-            return itemnames;
-        }
-
-        for (int i=0;i<fileuploadlist.size();i++) {
-            DefaultFileItem item = (DefaultFileItem) fileuploadlist.get(i);
-            itemnames.add(item.getFieldName());
-        }
-        return itemnames;
-    }
-
-    /**
-     * Get file name from FileItem
-     * @param name of the field
-     * @param context Context of the request
-     * @return  The file name
-     */
-    public String getFileName(String name, XWikiContext context) {
-        List fileuploadlist = getFileItems(context);
-        if (fileuploadlist==null) {
-            return null;
-        }
-
-        DefaultFileItem  fileitem = null;
-        for (int i=0;i<fileuploadlist.size();i++) {
-            DefaultFileItem item = (DefaultFileItem) fileuploadlist.get(i);
-            if (name.equals(item.getFieldName())) {
-                fileitem = item;
-                break;
-            }
-        }
-
-        if (fileitem==null)
-            return null;
-
-        return fileitem.getName();
-    }
-
-}
+/*
+ * 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 sdumitriu
+ */
+
+package com.xpn.xwiki.plugin.fileupload;
+
+import com.xpn.xwiki.XWiki;
+import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.api.Api;
+import com.xpn.xwiki.plugin.XWikiDefaultPlugin;
+import com.xpn.xwiki.plugin.XWikiPluginInterface;
+import com.xpn.xwiki.web.XWikiRequest;
+import org.apache.commons.fileupload.*;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+public class FileUploadPlugin extends XWikiDefaultPlugin implements XWikiPluginInterface {
+    private static Log mLogger =
+            LogFactory.getFactory().getInstance(FileUploadPlugin.class);
+
+    private static final long UPLOAD_DEFAULT_MAXSIZE = 10000000L;
+    private static final long UPLOAD_DEFAULT_SIZETHRESHOLD = 100000L;
+
+    public FileUploadPlugin(String name, String className, XWikiContext context) {
+        super(name, className, context);
+    }
+
+    /**
+     *  Allow to get the plugin name
+     * @return plugin name
+     */
+    public String getName() {
+        return "fileupload";
+    }
+
+    public void init(XWikiContext context) {
+    }
+
+    public void virtualInit(XWikiContext context) {
+    }
+
+    public Api getPluginApi(XWikiPluginInterface plugin, XWikiContext context) {
+        return new FileUploadPluginApi((FileUploadPlugin) plugin, context);
+    }
+
+    /**
+     *  endRendering to make sure we don't leave files in temp directories
+     * @param context Context of the request
+    */
+    public void endRendering(XWikiContext context) {
+        cleanFileList(context);
+    }
+
+    /**
+     *  Deletes all temporary files of the upload
+     * @param context Context of the request
+     */
+    public void cleanFileList(XWikiContext context) {
+        List fileuploadlist = (List) context.get("fileuploadlist");
+        if (fileuploadlist!=null) {
+             for (int i=0;i<fileuploadlist.size();i++) {
+                 try {
+                     FileItem item = (FileItem) fileuploadlist.get(i);
+                     item.delete();
+                 } catch (Exception e) {
+                 }
+             }
+            context.remove("fileuploadlist");
+        }
+    }
+
+    /**
+     * Allows to load the file list in the context if there is a file upload
+     * Default uploadMaxSize, uploadSizeThreashold and temporary directory are used
+     * @param context Context of the request
+     * @throws XWikiException An XWikiException is thrown if the request could not be parser
+     */
+    public void loadFileList(XWikiContext context) throws XWikiException {
+        XWiki xwiki = context.getWiki();
+        loadFileList(xwiki.getXWikiPreferenceAsLong("upload_maxsize", UPLOAD_DEFAULT_MAXSIZE, context),
+                (int)xwiki.getXWikiPreferenceAsLong("upload_sizethreshold", UPLOAD_DEFAULT_SIZETHRESHOLD, context),
+                xwiki.Param("xwiki.upload.tempdir"), context);
+    }
+
+    /**
+     * Allows to load the file list in the context if there is a file upload
+     *
+     * @param uploadMaxSize Maximum size of the request
+     * @param uploadSizeThreashold  Threashold over which the data should be on disk and not in memory
+     * @param tempdir Temporary Directory to store temp data
+     * @param context Context of the request
+     * @throws XWikiException An XWikiException is thrown if the request could not be parser
+     */
+    public void loadFileList(long uploadMaxSize, int uploadSizeThreashold, String tempdir, XWikiContext context) throws XWikiException {
+        // Get the FileUpload Data
+        DiskFileUpload fileupload = new DiskFileUpload();
+        fileupload.setSizeMax(uploadMaxSize);
+        fileupload.setSizeThreshold(uploadSizeThreashold);
+        context.put("fileupload", fileupload);
+        XWikiRequest request = context.getRequest() ;
+
+        if (tempdir != null) {
+            fileupload.setRepositoryPath(tempdir);
+            (new File(tempdir)).mkdirs();
+        }
+        else {
+            fileupload.setRepositoryPath(".");
+        }
+
+        try {
+            List list = fileupload.parseRequest(request.getHttpServletRequest());
+            // We store the file list in the context, throw Exception ERROR_XWIKI_APP_FILE_EXCEPTION_MAXSIZE
+            context.put("fileuploadlist", list);
+        }catch (FileUploadBase.SizeLimitExceededException  e) {
+              throw new XWikiException(XWikiException.MODULE_XWIKI_APP,
+                    XWikiException.ERROR_XWIKI_APP_FILE_EXCEPTION_MAXSIZE,
+                    "Exception uploaded file");
+        }catch(FileUploadException e){
+            throw new XWikiException(XWikiException.MODULE_XWIKI_APP,
+                    XWikiException.ERROR_XWIKI_APP_UPLOAD_PARSE_EXCEPTION,
+                    "Exception while parsing uploaded file", e);
+        }
+    }
+
+    /**
+     * Allows to retrieve the current FileItem list
+     * loadFileList needs to be called beforehand
+     * @param context Context of the request
+     * @return a list of FileItem elements
+     */
+    public List getFileItems(XWikiContext context) {
+        return (List) context.get("fileuploadlist");
+    }
+
+    /**
+     * Allows to retrieve the data of FileItem named name
+     * loadFileList needs to be called beforehand
+
+     * @param name Name of the item
+     * @param context Context of the request
+     * @return byte[] of the data
+     * @throws XWikiException Exception is thrown if the data could not be read
+     */
+    public byte[] getFileItemData(String name, XWikiContext context) throws XWikiException {
+        List fileuploadlist = getFileItems(context);
+        if (fileuploadlist==null) {
+            return null;
+        }
+
+        DefaultFileItem  fileitem = null;
+        for (int i=0;i<fileuploadlist.size();i++) {
+            DefaultFileItem item = (DefaultFileItem) fileuploadlist.get(i);
+            if (name.equals(item.getFieldName())) {
+                fileitem = item;
+                break;
+            }
+        }
+
+        if (fileitem==null)
+            return null;
+
+        byte[] data = new byte[(int)fileitem.getSize()];
+        try{
+            InputStream fileis = fileitem.getInputStream();
+            if(fileis != null){
+                fileis.read(data);
+                fileis.close();
+            }
+
+        } catch (java.lang.OutOfMemoryError e) {
+            throw new XWikiException(XWikiException.MODULE_XWIKI_APP,
+                   XWikiException.ERROR_XWIKI_APP_JAVA_HEAP_SPACE,"Java Heap Space, Out of memory exception",e);
+        }catch(IOException ie){
+            throw new XWikiException(XWikiException.MODULE_XWIKI_APP,
+                    XWikiException.ERROR_XWIKI_APP_UPLOAD_FILE_EXCEPTION,"Exception while reading uploaded parsed file",ie) ;
+        }
+        return data;
+    }
+
+
+    /**
+     * Allows to retrieve the data of FileItem named name
+     * loadFileList needs to be called beforehand
+
+     * @param name Name of the item
+     * @param context Context of the request
+     * @return String of the data
+     * @throws XWikiException Exception is thrown if the data could not be read
+     * @param name
+     * @param context
+     * @return
+     * @throws XWikiException
+     */
+    public String getFileItemAsString(String name, XWikiContext context) throws XWikiException {
+        byte[] data = getFileItemData(name, context);
+        if (data==null)
+            return null;
+        else
+            return new String(data);
+    }
+
+    /**
+     * Allows to retrieve the data of FileItem named name
+     * loadFileList needs to be called beforehand
+     * @deprecated not well named, use {@link #getFileItemAsString(String, com.xpn.xwiki.XWikiContext)}
+     * @param name Name of the item
+     * @param context Context of the request
+     * @return String of the data
+     * @throws XWikiException Exception is thrown if the data could not be read
+     * @param name
+     * @param context
+     * @return
+     * @throws XWikiException
+     */
+    public String getFileItem(String name, XWikiContext context) throws XWikiException {
+        byte[] data = getFileItemData(name, context);
+        if (data==null)
+            return null;
+        else
+            return new String(data);
+    }
+
+    /**
+     * Allows to retrieve the list of FileItem names
+     * loadFileList needs to be called beforehand
+
+     * @param context Context of the request
+     * @return List of strings of the item names
+     */
+    public List getFileItemNames(XWikiContext context) {
+        List itemnames = new ArrayList();
+        List fileuploadlist = getFileItems(context);
+        if (fileuploadlist==null) {
+            return itemnames;
+        }
+
+        for (int i=0;i<fileuploadlist.size();i++) {
+            DefaultFileItem item = (DefaultFileItem) fileuploadlist.get(i);
+            itemnames.add(item.getFieldName());
+        }
+        return itemnames;
+    }
+
+    /**
+     * Get file name from FileItem
+     * @param name of the field
+     * @param context Context of the request
+     * @return  The file name
+     */
+    public String getFileName(String name, XWikiContext context) {
+        List fileuploadlist = getFileItems(context);
+        if (fileuploadlist==null) {
+            return null;
+        }
+
+        DefaultFileItem  fileitem = null;
+        for (int i=0;i<fileuploadlist.size();i++) {
+            DefaultFileItem item = (DefaultFileItem) fileuploadlist.get(i);
+            if (name.equals(item.getFieldName())) {
+                fileitem = item;
+                break;
+            }
+        }
+
+        if (fileitem==null)
+            return null;
+
+        return fileitem.getName();
+    }
+
+}

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/fileupload/FileUploadPluginApi.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/fileupload/FileUploadPluginApi.java	2006-09-28 17:32:49 UTC (rev 1354)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/fileupload/FileUploadPluginApi.java	2006-10-03 13:53:24 UTC (rev 1355)
@@ -1,121 +1,121 @@
-/*
- * 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 sdumitriu
- */
-
-package com.xpn.xwiki.plugin.fileupload;
-
-import com.xpn.xwiki.XWikiContext;
-import com.xpn.xwiki.XWikiException;
-import com.xpn.xwiki.plugin.PluginApi;
-
-import java.util.List;
-
-public class FileUploadPluginApi extends PluginApi {
-
-    public FileUploadPluginApi(FileUploadPlugin plugin, XWikiContext context) {
-        super(plugin, context);
-    }
-
-    public FileUploadPlugin getFileUploadPlugin() {
-        return (FileUploadPlugin) getPlugin();
-    }
-
-    /**
-     *  Deletes all temporary files of the upload
-     */
-    public void cleanFileList() {
-        getFileUploadPlugin().cleanFileList(context);
-    }
-
-    /**
-     * Allows to load the file list in the context if there is a file upload
-     * Default uploadMaxSize, uploadSizeThreashold and temporary directory are used
-     * @throws XWikiException An XWikiException is thrown if the request could not be parser
-     */
-    public void loadFileList() throws XWikiException {
-        getFileUploadPlugin().loadFileList(context);
-    }
-
-    /**
-     * Allows to load the file list in the context if there is a file upload
-     *
-     * @param uploadMaxSize Maximum size of the request
-     * @param uploadSizeThreashold  Threashold over which the data should be on disk and not in memory
-     * @param tempdir Temporary Directory to store temp data
-     * @throws XWikiException An XWikiException is thrown if the request could not be parser
-     */
-    public void loadFileList(long uploadMaxSize, int uploadSizeThreashold, String tempdir) throws XWikiException {
-        getFileUploadPlugin().loadFileList(uploadMaxSize, uploadSizeThreashold, tempdir, context);
-    }
-
-    /**
-     * Allows to retrieve the current FileItem list
-     * loadFileList needs to be called beforehand
-     * @return a list of FileItem elements
-     */
-    public List getFileItems() {
-        return getFileUploadPlugin().getFileItems(context);
-    }
-
-    /**
-     * Allows to retrieve the data of FileItem named name
-     * loadFileList needs to be called beforehand
-
-     * @param name Name of the item
-     * @return byte[] of the data
-     * @throws XWikiException Exception is thrown if the data could not be read
-     */
-    public byte[] getFileItemData(String name) throws XWikiException {
-        return getFileUploadPlugin().getFileItemData(name, context);
-    }
-
-    /**
-     * Allows to retrieve the data of FileItem named name
-     * loadFileList needs to be called beforehand
-
-     * @param name Name of the item
-     * @return String of the data
-     * @throws XWikiException Exception is thrown if the data could not be read
-     */
-    public String getFileItem(String name) throws XWikiException {
-        return getFileUploadPlugin().getFileItem(name, context);
-    }
-
-    /**
-     * Allows to retrieve the list of FileItem names
-     * loadFileList needs to be called beforehand
-
-     * @return List of strings of the item names
-     */
-    public List getFileItemNames() {
-        return getFileUploadPlugin().getFileItemNames(context);
-    }
-
-    /**
-     * Get file name from FileItem
-     * @param name of the field
-     * @return  The file name
-     */
-    public String getFileName(String name) {
-        return getFileUploadPlugin().getFileName(name, context);
-    }
-}
+/*
+ * 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 sdumitriu
+ */
+
+package com.xpn.xwiki.plugin.fileupload;
+
+import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.plugin.PluginApi;
+
+import java.util.List;
+
+public class FileUploadPluginApi extends PluginApi {
+
+    public FileUploadPluginApi(FileUploadPlugin plugin, XWikiContext context) {
+        super(plugin, context);
+    }
+
+    public FileUploadPlugin getFileUploadPlugin() {
+        return (FileUploadPlugin) getPlugin();
+    }
+
+    /**
+     *  Deletes all temporary files of the upload
+     */
+    public void cleanFileList() {
+        getFileUploadPlugin().cleanFileList(context);
+    }
+
+    /**
+     * Allows to load the file list in the context if there is a file upload
+     * Default uploadMaxSize, uploadSizeThreashold and temporary directory are used
+     * @throws XWikiException An XWikiException is thrown if the request could not be parser
+     */
+    public void loadFileList() throws XWikiException {
+        getFileUploadPlugin().loadFileList(context);
+    }
+
+    /**
+     * Allows to load the file list in the context if there is a file upload
+     *
+     * @param uploadMaxSize Maximum size of the request
+     * @param uploadSizeThreashold  Threashold over which the data should be on disk and not in memory
+     * @param tempdir Temporary Directory to store temp data
+     * @throws XWikiException An XWikiException is thrown if the request could not be parser
+     */
+    public void loadFileList(long uploadMaxSize, int uploadSizeThreashold, String tempdir) throws XWikiException {
+        getFileUploadPlugin().loadFileList(uploadMaxSize, uploadSizeThreashold, tempdir, context);
+    }
+
+    /**
+     * Allows to retrieve the current FileItem list
+     * loadFileList needs to be called beforehand
+     * @return a list of FileItem elements
+     */
+    public List getFileItems() {
+        return getFileUploadPlugin().getFileItems(context);
+    }
+
+    /**
+     * Allows to retrieve the data of FileItem named name
+     * loadFileList needs to be called beforehand
+
+     * @param name Name of the item
+     * @return byte[] of the data
+     * @throws XWikiException Exception is thrown if the data could not be read
+     */
+    public byte[] getFileItemData(String name) throws XWikiException {
+        return getFileUploadPlugin().getFileItemData(name, context);
+    }
+
+    /**
+     * Allows to retrieve the data of FileItem named name
+     * loadFileList needs to be called beforehand
+
+     * @param name Name of the item
+     * @return String of the data
+     * @throws XWikiException Exception is thrown if the data could not be read
+     */
+    public String getFileItem(String name) throws XWikiException {
+        return getFileUploadPlugin().getFileItem(name, context);
+    }
+
+    /**
+     * Allows to retrieve the list of FileItem names
+     * loadFileList needs to be called beforehand
+
+     * @return List of strings of the item names
+     */
+    public List getFileItemNames() {
+        return getFileUploadPlugin().getFileItemNames(context);
+    }
+
+    /**
+     * Get file name from FileItem
+     * @param name of the field
+     * @return  The file name
+     */
+    public String getFileName(String name) {
+        return getFileUploadPlugin().getFileName(name, context);
+    }
+}

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/packaging/Package.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/packaging/Package.java	2006-09-28 17:32:49 UTC (rev 1354)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/packaging/Package.java	2006-10-03 13:53:24 UTC (rev 1355)
@@ -437,6 +437,7 @@
 
                 // We don't want date and version to change
                 // So we need to cancel the dirty status
+                // TODO check pb with version
                 doc.getDoc().setContentDirty(false);
                 doc.getDoc().setMetaDataDirty(false);
 

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/query/SecHibernateQuery.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/query/SecHibernateQuery.java	2006-09-28 17:32:49 UTC (rev 1354)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/query/SecHibernateQuery.java	2006-10-03 13:53:24 UTC (rev 1355)
@@ -155,7 +155,7 @@
 			if (element instanceof XWikiDocument) {
 				XWikiDocument doc = (XWikiDocument) element;
 				doc = getStore().loadXWikiDoc(doc, getContext());
-				result.add(new Document(doc, getContext()));
+				result.add(doc.newDocument(getContext()));
 			} else if (element instanceof BaseObject) {
 				getHibernateStore().loadXWikiObject((BaseObject) element, getContext(), true);
 				result.add(new com.xpn.xwiki.api.Object((BaseObject) element, getContext()));

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/userdirectory/Group.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/userdirectory/Group.java	2006-09-28 17:32:49 UTC (rev 1354)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/userdirectory/Group.java	2006-10-03 13:53:24 UTC (rev 1355)
@@ -30,7 +30,7 @@
     public static final int ERROR_USERDIRECTORYPLUGIN_GROUP_DOESNT_EXIST = 1;
 
     public Group(XWikiDocument doc, XWikiContext context) throws XWikiException {
-        this(new Document(doc, context), context);
+        this(doc.newDocument(context), context);
     }
 
     public Group(Document doc, XWikiContext context) throws XWikiException {
@@ -43,7 +43,7 @@
 
     public void reload(Document doc, XWikiContext context) throws XWikiException {
         if (doc == null)
-            doc = new Document(context.getWiki().getDocument(this.doc.getFullName(), context), context);
+            doc = context.getWiki().getDocument(this.doc.getFullName(), context).newDocument(context);
         this.doc = doc;
 
         BaseClass dirGrpClass = getXWikiDirectoryGroupClass(context);
@@ -214,7 +214,7 @@
         Iterator it = members.iterator();
         while(it.hasNext()){
             String userPage = (String) it.next();
-            Document doc = new Document(context.getWiki().getDocument(userPage, context), context);
+            Document doc = context.getWiki().getDocument(userPage, context).newDocument(context);
             doc.use("XWiki.XWikiUsers");
             Integer active = (Integer) doc.getValue("active");
             if (active.intValue() == 0){
@@ -230,7 +230,7 @@
         Iterator it = members.iterator();
         while(it.hasNext()){
             String userPage = (String) it.next();
-            Document doc = new Document(context.getWiki().getDocument(userPage, context), context);
+            Document doc = context.getWiki().getDocument(userPage, context).newDocument(context);
             doc.use("XWiki.XWikiUsers");
             String active = (String) doc.getValue("active");
             if (active.equals("0")){
@@ -376,7 +376,7 @@
 
 
     public static boolean isValidGroup(String grpName, XWikiContext context) throws XWikiException {
-        Document doc = new Document(context.getWiki().getDocument(grpName, context), context);
+        Document doc = context.getWiki().getDocument(grpName, context).newDocument(context);
         if (doc.isNew())
             return false;
         return (doc.getObjects(getXWikiDirectoryGroupClass(context).getName()).size() > 0);

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/userdirectory/UserDirectoryPlugin.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/userdirectory/UserDirectoryPlugin.java	2006-09-28 17:32:49 UTC (rev 1354)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/userdirectory/UserDirectoryPlugin.java	2006-10-03 13:53:24 UTC (rev 1355)
@@ -80,7 +80,7 @@
         XWikiDocument tmpDoc = context.getWiki().getDocument(DEFAULT_PLUGIN_SPACE, name, context);
         if (!tmpDoc.isNew())
             throw new PluginException(UserDirectoryPlugin.class, ERROR_USERDIRECTORYPLUGIN_ALREADYEXIST, "This document already exist, try another name");
-        Document doc = new Document(tmpDoc, context);
+        Document doc = tmpDoc.newDocument(context);
         doc.addObjectFromRequest("XWiki.DirectoryGroupClass");
         doc.setContent(getTemplate(context));
         doc.saveWithProgrammingRights();
@@ -95,7 +95,7 @@
         XWikiRequest req = context.getRequest();
         String pageName = req.get("pageName");
         XWikiDocument tmpDoc = context.getWiki().getDocument(pageName, context);
-        Document doc = new Document(tmpDoc, context);
+        Document doc = tmpDoc.newDocument(context);
         doc.updateObjectFromRequest("XWiki.DirectoryGroupClass");
         doc.save();
     }
@@ -184,7 +184,7 @@
         XWikiDocument doc = context.getWiki().getDocument(userTools.getUserSpace(context) + "." + pageName, context);
         if (doc.isNew()) {
             String userDocName = userTools.inviteUser(name, email, context);
-            Document userDoc = new Document(context.getWiki().getDocument(userDocName,context), context);
+            Document userDoc = context.getWiki().getDocument(userDocName, context).newDocument(context);
             userDoc.use("XWiki.XWikiUsers");
             userDoc.set("first_name", firstName);
             userDoc.saveWithProgrammingRights();
@@ -221,7 +221,7 @@
         List usersDoc = new ArrayList();
         Iterator it = users.iterator();
         while(it.hasNext()){
-            usersDoc.add(new Document(context.getWiki().getDocument((String) it.next(), context), context));
+            usersDoc.add(context.getWiki().getDocument((String) it.next(), context).newDocument(context));
         }
         return usersDoc;
     }
@@ -287,7 +287,7 @@
     }
 
     public boolean deactivateAccount(String userPage, XWikiContext context) throws XWikiException {
-        Document doc = new Document(context.getWiki().getDocument(userPage, context), context);
+        Document doc = context.getWiki().getDocument(userPage, context).newDocument(context);
         doc.use("XWiki.XWikiUsers");
         doc.set("active", "0");
         String validkey = context.getWiki().generateValidationKey(16);

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/usertools/XWikiUserManagementToolsAPI.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/usertools/XWikiUserManagementToolsAPI.java	2006-09-28 17:32:49 UTC (rev 1354)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/usertools/XWikiUserManagementToolsAPI.java	2006-10-03 13:53:24 UTC (rev 1355)
@@ -26,7 +26,7 @@
 import com.xpn.xwiki.api.Api;
 
 
-public class XWikiUserManagementToolsAPI extends Api implements XWikiUserManagementTools {
+public class XWikiUserManagementToolsAPI extends Api{
     private XWikiUserManagementTools userMngtTools;
 
     public XWikiUserManagementToolsAPI(XWikiContext context) {
@@ -38,19 +38,19 @@
         this.userMngtTools = xWikiUserManagementTools;
     }
 
-    public String inviteUser(String name, String email, XWikiContext context) throws XWikiException {
+    public String inviteUser(String name, String email) throws XWikiException {
         return userMngtTools.inviteUser(name, email, context);
     }
 
-    public boolean resendInvitation(String email, XWikiContext context) throws XWikiException {
+    public boolean resendInvitation(String email) throws XWikiException {
         return userMngtTools.resendInvitation(email, context);
     }
 
-    public String getUserSpace(XWikiContext context) {
+    public String getUserSpace() {
         return userMngtTools.getUserSpace(context);
     }
 
-    public String getUserPage(String email, XWikiContext context) {
+    public String getUserPage(String email) {
         return userMngtTools.getUserPage(email, context);
     }
 
@@ -58,11 +58,11 @@
         return userMngtTools.isValidEmail(email);
     }
 
-    public String getUserName(String userPage, XWikiContext context) throws XWikiException {
+    public String getUserName(String userPage) throws XWikiException {
         return userMngtTools.getUserName(userPage, context);
     }
 
-    public String getEmail(String userPage, XWikiContext context) throws XWikiException {
+    public String getEmail(String userPage) throws XWikiException {
         return userMngtTools.getEmail(userPage, context);
     }
 }

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/usertools/XWikiUserManagementToolsImpl.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/usertools/XWikiUserManagementToolsImpl.java	2006-09-28 17:32:49 UTC (rev 1354)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/usertools/XWikiUserManagementToolsImpl.java	2006-10-03 13:53:24 UTC (rev 1355)
@@ -62,7 +62,7 @@
         if (!isValidEmail(email))
            throw new PluginException(getName(), ERROR_XWIKI_EMAIL_INVALID_EMAIL, "The email is not valid");
 
-        Document userdoc = createUserDocument(email, context);
+        Document userdoc = createUserDocument(name, email, context);
         userdoc.use(DEFAULT_USER_CLASS);
         userdoc.set("last_name", name);
         userdoc.set("email", email);
@@ -93,13 +93,17 @@
        return true;
      }
 
-    protected Document createUserDocument(String email, XWikiContext context) throws XWikiException {
-        String pageName = getUserPage(email, context);
+    protected Document createUserDocument(String name, String email, XWikiContext context) throws XWikiException {
+        String pageName;
+        if (context.getWiki().getConvertingUserNameType(context).equals("0"))
+            pageName = getUserPage(name, context);
+        else
+            pageName = getUserPage(email, context);
         XWikiDocument userDoc = context.getWiki().getDocument(pageName, context);
         if (!userDoc.isNew()) {
             throw new PluginException(getName(), ERROR_XWIKI_USER_PAGE_ALREADY_EXIST, "This document already exist, try another name");
         }
-        Document userApiDoc = new Document(userDoc, context);
+        Document userApiDoc = userDoc.newDocument(context);
 
         String template = DEFAULT_USERTEMPLATE_CLASS;
         if ((template != null) && (!template.equals(""))) {
@@ -131,13 +135,13 @@
     }
 
     public String getUserName(String userPage, XWikiContext context) throws XWikiException {
-        Document doc = new Document(context.getWiki().getDocument(userPage, context), context);
+        Document doc = context.getWiki().getDocument(userPage, context).newDocument(context);
         doc.use(DEFAULT_USER_CLASS);
         return doc.get("first_name") + " " + doc.get("last_name");
     }
 
     public String getEmail(String userPage, XWikiContext context) throws XWikiException {
-        Document doc = new Document(context.getWiki().getDocument(userPage, context), context);
+        Document doc = context.getWiki().getDocument(userPage, context).newDocument(context);
         doc.use(DEFAULT_USER_CLASS);
         return (String) doc.get("email");
     }

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/render/XWikiVelocityRenderer.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/render/XWikiVelocityRenderer.java	2006-09-28 17:32:49 UTC (rev 1354)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/render/XWikiVelocityRenderer.java	2006-10-03 13:53:24 UTC (rev 1355)
@@ -78,7 +78,7 @@
             Document previousdoc = (Document) vcontext.get("doc");
 
             try {
-                vcontext.put("doc", new Document(doc, context));
+                vcontext.put("doc", doc.newDocument(context));
 
                 try {
                     // We need to do this in case there are any macros in the content

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/render/groovy/XWikiGroovyRenderer.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/render/groovy/XWikiGroovyRenderer.java	2006-09-28 17:32:49 UTC (rev 1354)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/render/groovy/XWikiGroovyRenderer.java	2006-10-03 13:53:24 UTC (rev 1355)
@@ -191,7 +191,7 @@
             Writer previouswriter  = (Writer) gcontext.get("out");
 
             try {
-                gcontext.put("doc", new Document(contextdoc, context));
+                gcontext.put("doc", contextdoc.newDocument(context));
                 return evaluate(content, name, gcontext);
             } finally {
                 if (previousdoc!=null)

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/web/AdminAction.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/web/AdminAction.java	2006-09-28 17:32:49 UTC (rev 1354)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/web/AdminAction.java	2006-10-03 13:53:24 UTC (rev 1355)
@@ -88,7 +88,7 @@
                     tdoc.setAuthor(context.getUser());
                     tdoc.setStore(doc.getStore());
                     context.put("tdoc", tdoc);
-                    vcontext.put("tdoc", new Document(tdoc, context));
+                    vcontext.put("tdoc", tdoc.newDocument(context));
                 }
             }
 
@@ -96,7 +96,7 @@
             if (content != null && !content.equals(""))
                 tdoc2.setContent(content);
             context.put("tdoc", tdoc2);
-            vcontext.put("tdoc", new Document(tdoc2, context));
+            vcontext.put("tdoc", tdoc2.newDocument(context));
             try{
             	tdoc2.readFromTemplate(peform, context);
             }

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/web/EditAction.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/web/EditAction.java	2006-09-28 17:32:49 UTC (rev 1354)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/web/EditAction.java	2006-10-03 13:53:24 UTC (rev 1355)
@@ -111,7 +111,7 @@
                     tdoc.setAuthor(context.getUser());
                     tdoc.setStore(doc.getStore());
                     context.put("tdoc", tdoc);
-                    vcontext.put("tdoc", new Document(tdoc, context));
+                    vcontext.put("tdoc", tdoc.newDocument(context));
                 }
             }
 
@@ -124,7 +124,7 @@
                 tdoc2.setTitle(doc.getDocumentSection(sectionNumber).getSectionTitle());
             }
             context.put("tdoc", tdoc2);
-            vcontext.put("tdoc", new Document(tdoc2, context));
+            vcontext.put("tdoc", tdoc2.newDocument(context));
             try{
             tdoc2.readFromTemplate(peform, context);
             }

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/web/InlineAction.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/web/InlineAction.java	2006-09-28 17:32:49 UTC (rev 1354)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/web/InlineAction.java	2006-10-03 13:53:24 UTC (rev 1355)
@@ -47,7 +47,7 @@
             EditForm peform = (EditForm) form;
 
             XWikiDocument doc2 = (XWikiDocument) doc.clone();
-            Document vdoc2 = new Document(doc2, context);
+            Document vdoc2 = doc2.newDocument(context);
             context.put("doc", doc2);
             vcontext.put("doc", vdoc2);
 
@@ -75,7 +75,7 @@
             } else {
                 XWikiDocument cdoc = vcdoc.getDocument();
                 XWikiDocument cdoc2 = (XWikiDocument) cdoc.clone();
-                vcontext.put("cdoc", new Document(cdoc2, context));
+                vcontext.put("cdoc", cdoc2.newDocument(context));
                 cdoc2.readFromTemplate(peform, context);
             }
 

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/web/PreviewAction.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/web/PreviewAction.java	2006-09-28 17:32:49 UTC (rev 1354)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/web/PreviewAction.java	2006-10-03 13:53:24 UTC (rev 1355)
@@ -90,7 +90,7 @@
 			if ((language == null) || (language.equals("")) || (language.equals("default")) || (language.equals(doc.getDefaultLanguage()))) {
 				tdoc = doc2;
 				context.put("tdoc", doc2);
-				vcontext.put("doc", new Document(doc2, context));
+				vcontext.put("doc", doc2.newDocument(context));
 				vcontext.put("tdoc", vcontext.get("doc"));
 				vcontext.put("cdoc", vcontext.get("doc"));
 				doc2.readFromTemplate(((EditForm) form).getTemplate(), context);
@@ -102,7 +102,7 @@
 				tdoc.setTranslation(1);
 				XWikiDocument tdoc2 = (XWikiDocument) tdoc.clone();
 				context.put("tdoc", tdoc2);
-				vcontext.put("tdoc", new Document(tdoc2, context));
+				vcontext.put("tdoc", tdoc2.newDocument(context));
 				vcontext.put("cdoc", vcontext.get("tdoc"));
 				tdoc2.readFromTemplate(((EditForm) form).getTemplate(), context);
 				tdoc2.readFromForm((EditForm) form, context);

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/web/XWikiAction.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/web/XWikiAction.java	2006-09-28 17:32:49 UTC (rev 1354)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/web/XWikiAction.java	2006-10-03 13:53:24 UTC (rev 1355)
@@ -261,9 +261,9 @@
             context.put("cdoc", rdoc);
             context.put("doc", rdoc);
             VelocityContext vcontext = (VelocityContext) context.get("vcontext");
-            vcontext.put("doc", new Document(rdoc, context));
+            vcontext.put("doc", rdoc.newDocument(context));
             vcontext.put("cdoc", vcontext.get("doc"));
-            vcontext.put("tdoc", new Document(rtdoc, context));
+            vcontext.put("tdoc", rtdoc.newDocument(context));
         }
     }
 

Modified: xwiki/trunk/src/main/resources/xwiki.hbm.xml
===================================================================
--- xwiki/trunk/src/main/resources/xwiki.hbm.xml	2006-09-28 17:32:49 UTC (rev 1354)
+++ xwiki/trunk/src/main/resources/xwiki.hbm.xml	2006-10-03 13:53:24 UTC (rev 1355)
@@ -70,6 +70,11 @@
             <column name="XWD_VERSION" length="255" not-null="true"/>
         </property>
 
+        <property name="customClass" type="string">
+            <column name="XWD_CUSTOM_CLASS" length="255" not-null="true"/>
+        </property>
+
+
         <property name="parent" type="string">
             <column name="XWD_PARENT" length="511" not-null="true"/>
         </property>

Modified: xwiki/trunk/src/main/web/templates/macros.vm
===================================================================
--- xwiki/trunk/src/main/web/templates/macros.vm	2006-09-28 17:32:49 UTC (rev 1354)
+++ xwiki/trunk/src/main/web/templates/macros.vm	2006-10-03 13:53:24 UTC (rev 1355)
@@ -413,4 +413,13 @@
 $html
 #end
 </div>
+#end
+
+#macro(xwikiobjectfield $fielddoc $fieldname $fieldtext $action)
+<div class="xmblabel">$fieldtext</div>
+<div class="xmbfield">
+#if($fieldname!="")
+$fielddoc.display($fieldname, $action)
+#end
+</div>
 #end
\ No newline at end of file

Modified: xwiki/trunk/src/test/java/com/xpn/xwiki/plugin/charts/tests/ChartingPluginTest.java
===================================================================
--- xwiki/trunk/src/test/java/com/xpn/xwiki/plugin/charts/tests/ChartingPluginTest.java	2006-09-28 17:32:49 UTC (rev 1354)
+++ xwiki/trunk/src/test/java/com/xpn/xwiki/plugin/charts/tests/ChartingPluginTest.java	2006-10-03 13:53:24 UTC (rev 1355)
@@ -22,13 +22,6 @@
  */
 package com.xpn.xwiki.plugin.charts.tests;
 
-import java.io.File;
-import java.net.URL;
-
-import javax.servlet.ServletContext;
-
-import junit.framework.TestCase;
-
 import com.xpn.xwiki.XWiki;
 import com.xpn.xwiki.XWikiConfig;
 import com.xpn.xwiki.XWikiContext;
@@ -45,7 +38,12 @@
 import com.xpn.xwiki.web.XWikiServletContext;
 import com.xpn.xwiki.web.XWikiServletRequest;
 import com.xpn.xwiki.web.XWikiServletURLFactory;
+import junit.framework.TestCase;
 
+import javax.servlet.ServletContext;
+import java.io.File;
+import java.net.URL;
+
 public class ChartingPluginTest extends TestCase {
 
 	public static void main(String[] args) {

Modified: xwiki/trunk/src/test/java/com/xpn/xwiki/test/AbstractRenderTest.java
===================================================================
--- xwiki/trunk/src/test/java/com/xpn/xwiki/test/AbstractRenderTest.java	2006-09-28 17:32:49 UTC (rev 1354)
+++ xwiki/trunk/src/test/java/com/xpn/xwiki/test/AbstractRenderTest.java	2006-10-03 13:53:24 UTC (rev 1355)
@@ -1,39 +1,38 @@
-/*
- * 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 vmassol
- * @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 vmassol
+ * @author sdumitriu
+ */
 
 package com.xpn.xwiki.test;
 
-import java.net.URL;
-
-import org.hibernate.HibernateException;
-
 import com.xpn.xwiki.XWikiContext;
 import com.xpn.xwiki.XWikiException;
 import com.xpn.xwiki.doc.XWikiDocument;
 import com.xpn.xwiki.render.XWikiRenderer;
 import com.xpn.xwiki.render.XWikiRenderingEngine;
 import com.xpn.xwiki.web.XWikiServletURLFactory;
+import org.hibernate.HibernateException;
 
+import java.net.URL;
+
 public abstract class AbstractRenderTest extends HibernateTestCase {
 
     public abstract XWikiRenderer getXWikiRenderer();

Added: xwiki/trunk/src/test/java/com/xpn/xwiki/test/CustomDocumentClass.java
===================================================================
--- xwiki/trunk/src/test/java/com/xpn/xwiki/test/CustomDocumentClass.java	2006-09-28 17:32:49 UTC (rev 1354)
+++ xwiki/trunk/src/test/java/com/xpn/xwiki/test/CustomDocumentClass.java	2006-10-03 13:53:24 UTC (rev 1355)
@@ -0,0 +1,40 @@
+/*
+ * 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 jeremi
+ */
+package com.xpn.xwiki.test;
+
+import com.xpn.xwiki.api.Document;
+import com.xpn.xwiki.doc.XWikiDocument;
+import com.xpn.xwiki.XWikiContext;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: jeremi
+ * Date: Sep 26, 2006
+ * Time: 10:14:58 PM
+ * To change this template use File | Settings | File Templates.
+ */
+    public class CustomDocumentClass extends Document {
+
+        public CustomDocumentClass(XWikiDocument doc, XWikiContext context) {
+            super(doc, context);
+        }
+    }


Property changes on: xwiki/trunk/src/test/java/com/xpn/xwiki/test/CustomDocumentClass.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: xwiki/trunk/src/test/java/com/xpn/xwiki/test/XWikiDocumentTest.java
===================================================================
--- xwiki/trunk/src/test/java/com/xpn/xwiki/test/XWikiDocumentTest.java	2006-09-28 17:32:49 UTC (rev 1354)
+++ xwiki/trunk/src/test/java/com/xpn/xwiki/test/XWikiDocumentTest.java	2006-10-03 13:53:24 UTC (rev 1355)
@@ -0,0 +1,56 @@
+/*
+ * 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 jeremi
+ */
+package com.xpn.xwiki.test;
+
+import com.xpn.xwiki.doc.XWikiDocument;
+import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.api.Document;
+
+public class XWikiDocumentTest  extends HibernateTestCase {
+
+
+    public void testCustomClass() throws XWikiException {
+        XWikiDocument doc  = xwiki.getDocument("Test.CustomTest", context);
+        doc.setCustomClass(CustomDocumentClass.class.getName());
+        xwiki.saveDocument(doc, context);
+
+
+        doc  = xwiki.getDocument("Test.NotCustomTest", context);
+        xwiki.saveDocument(doc, context);
+
+        doc  = xwiki.getDocument("Test.CustomTest", context);
+        assertEquals(CustomDocumentClass.class.getName(), doc.getCustomClass());
+        assertTrue(doc.newDocument(context) instanceof CustomDocumentClass);
+
+        doc  = xwiki.getDocument("Test.NotCustomTest", context);
+        assertNotNull(doc);
+        assertTrue(doc.newDocument(context) instanceof Document);        
+        assertFalse(doc.newDocument(context) instanceof CustomDocumentClass);
+
+        doc  = xwiki.getDocument("Test.CustomTest", context);
+        doc.setContent("plop");
+        xwiki.saveDocument(doc, context);
+
+        assertEquals(CustomDocumentClass.class.getName(), doc.getCustomClass());
+        assertTrue(doc.newDocument(context) instanceof CustomDocumentClass);
+    }
+}


Property changes on: xwiki/trunk/src/test/java/com/xpn/xwiki/test/XWikiDocumentTest.java
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: xwiki/trunk/src/test/java/com/xpn/xwiki/test/XWikiTest.java
===================================================================
--- xwiki/trunk/src/test/java/com/xpn/xwiki/test/XWikiTest.java	2006-09-28 17:32:49 UTC (rev 1354)
+++ xwiki/trunk/src/test/java/com/xpn/xwiki/test/XWikiTest.java	2006-10-03 13:53:24 UTC (rev 1355)
@@ -77,7 +77,7 @@
         String xml = doc.getXMLContent(getXWikiContext());
         assertTrue("XML should should contain password field", xml.indexOf("<password>")!=-1);
         assertTrue("XML should contain password", xml.indexOf("toto")!=-1);
-        Document ddoc = new Document(doc, getXWikiContext());
+        Document ddoc = doc.newDocument(getXWikiContext());
         xml = ddoc.getXMLContent();
         assertTrue("XML should should contain password field", xml.indexOf("<password>")!=-1);
         assertTrue("XML should not contain password", xml.indexOf("toto")==-1);

Modified: xwiki/trunk/src/test/java/com/xpn/xwiki/test/plugin/query/QueryPluginApiTest.java
===================================================================
--- xwiki/trunk/src/test/java/com/xpn/xwiki/test/plugin/query/QueryPluginApiTest.java	2006-09-28 17:32:49 UTC (rev 1354)
+++ xwiki/trunk/src/test/java/com/xpn/xwiki/test/plugin/query/QueryPluginApiTest.java	2006-10-03 13:53:24 UTC (rev 1355)
@@ -121,7 +121,7 @@
         getXWiki().flushCache();
         //hb.beginTransaction(true, getXWikiContext());
         doc = getXWiki().getStore().loadXWikiDoc(new XWikiDocument("Test", "Test0"), getXWikiContext());
-        Document secdoc1 = new Document(doc, getXWikiContext());
+        Document secdoc1 = doc.newDocument(getXWikiContext());
         //object = (BaseObject) hb.getSession(getXWikiContext()).load(BaseObject.class, new Integer(object1.getId()));
         Object secobj1	 = new com.xpn.xwiki.api.Object(object1, getXWikiContext());
         getXWiki().flushCache();
@@ -189,7 +189,7 @@
         Utils.updateRight(getXWiki(), getXWikiContext(), "Test.Test0", "XWiki.XWikiGuest", "", "view", false, false);
         getXWiki().flushCache();
         doc1 = getXWiki().getStore().loadXWikiDoc(doc1, getXWikiContext());
-        secdoc1 = new Document(doc1, getXWikiContext());
+        secdoc1 = doc1.newDocument(getXWikiContext());
         testSearchXP("//Test/Test0",									new Object[]{secdoc1});
         testSearchXP("//Test/Test0/@name",							EMPTY);
         testSearchXP("//Test/Test0/@web",								new Object[]{"Test"});





More information about the Xwiki-notifications mailing list