Index: src/test/java/com/xpn/xwiki/plugin/multiwiki/WikiManagerTest.java
===================================================================
--- src/test/java/com/xpn/xwiki/plugin/multiwiki/WikiManagerTest.java	(révision 0)
+++ src/test/java/com/xpn/xwiki/plugin/multiwiki/WikiManagerTest.java	(révision 0)
@@ -0,0 +1,264 @@
+/*
+ * Copyright 2006-2007, XpertNet SARL, and individual contributors.
+ *
+ * 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.
+ */
+
+package com.xpn.xwiki.plugin.multiwiki;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jmock.Mock;
+import org.jmock.cglib.MockObjectTestCase;
+import org.jmock.core.Invocation;
+import org.jmock.core.stub.CustomStub;
+
+import com.xpn.xwiki.XWiki;
+import com.xpn.xwiki.XWikiConfig;
+import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.doc.XWikiDocument;
+import com.xpn.xwiki.store.XWikiHibernateStore;
+import com.xpn.xwiki.store.XWikiHibernateVersioningStore;
+import com.xpn.xwiki.store.XWikiStoreInterface;
+import com.xpn.xwiki.store.XWikiVersioningStoreInterface;
+
+/**
+ * Unit tests for {@link com.xpn.xwiki.plugin.multiwiki.WikiManager}.
+ * 
+ * @version $Id: $
+ */
+public class WikiManagerTest extends MockObjectTestCase
+{
+    private XWikiContext context;
+
+    private XWiki xwiki;
+
+    private Mock mockXWikiStore;
+
+    private Mock mockXWikiVersioningStore;
+
+    private Map databases = new HashMap();
+
+    private static final String WIKI_NAME = "xwiki";
+    private static final String TARGET_WIKI_NAME = "wikitosave";
+    
+    protected void setUp() throws XWikiException
+    {
+        this.context = new XWikiContext();
+        this.context.setVirtual(true);
+        this.xwiki = new XWiki(new XWikiConfig(), this.context);
+
+        databases.put(WIKI_NAME, new HashMap());
+        
+        this.mockXWikiStore =
+            mock(XWikiHibernateStore.class, new Class[] {XWiki.class, XWikiContext.class},
+                new Object[] {this.xwiki, this.context});
+        this.mockXWikiStore.stubs().method("loadXWikiDoc").will(
+            new CustomStub("Implements XWikiStoreInterface.loadXWikiDoc")
+            {
+                public Object invoke(Invocation invocation) throws Throwable
+                {
+                    XWikiDocument shallowDoc = (XWikiDocument) invocation.parameterValues.get(0);
+                    XWikiContext context = (XWikiContext) invocation.parameterValues.get(1);
+                    
+                    String database = context.getDatabase();
+                    
+                    if (database == null || database.length() == 0)
+                        database = WIKI_NAME;
+                    
+                    if (!databases.containsKey(database))
+                        throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_UNKNOWN,
+                            "Database " + database + " does not exists.");
+                    
+                    Map docs = (Map)databases.get(database);
+                    
+                    if (docs.containsKey(shallowDoc.getFullName())) {
+                        return docs.get(shallowDoc.getFullName());
+                    } else {
+                        return shallowDoc;
+                    }
+                }
+            });
+        this.mockXWikiStore.stubs().method("saveXWikiDoc").will(
+            new CustomStub("Implements XWikiStoreInterface.saveXWikiDoc")
+            {
+                public Object invoke(Invocation invocation) throws Throwable
+                {
+                    XWikiDocument document = (XWikiDocument) invocation.parameterValues.get(0);
+                    XWikiContext context = (XWikiContext) invocation.parameterValues.get(1);
+                    
+                    String database = context.getDatabase();
+                    
+                    if (database == null || database.length() == 0)
+                        database = WIKI_NAME;
+                    
+                    if (!databases.containsKey(database))
+                        throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_UNKNOWN,
+                            "Database " + database + " does not exists.");
+                    
+                    Map docs = (Map)databases.get(database);
+                    
+                    document.setNew(false);
+                    document.setStore((XWikiStoreInterface) mockXWikiStore.proxy());
+                    document.setDatabase(context.getDatabase());
+                    
+                    docs.put(document.getFullName(), document);
+                    
+                    return null;
+                }
+            });
+        this.mockXWikiStore.stubs().method("createWiki").will(
+            new CustomStub("Implements XWikiStoreInterface.createWiki")
+            {
+                public Object invoke(Invocation invocation) throws Throwable
+                {
+                    String wikiName = (String) invocation.parameterValues.get(0);
+                    
+                    if (databases.containsKey(wikiName))
+                        throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_CREATE_DATABASE,
+                            "Database " + wikiName + " already exists.");
+                    
+                    databases.put(wikiName, new HashMap());
+                    
+                    return null;
+                }
+            });
+        /*this.mockXWikiStore.stubs().method("deleteWiki").will(
+            new CustomStub("Implements XWikiStoreInterface.deleteWiki")
+            {
+                public Object invoke(Invocation invocation) throws Throwable
+                {
+                    String wikiName = (String) invocation.parameterValues.get(0);
+                    
+                    if (!databases.containsKey(wikiName))
+                        throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_DELETE_DATABASE,
+                            "Database " + wikiName + " does not exists.");
+                    
+                    databases.remove(wikiName);
+                    
+                    return null;
+                }
+            });*/
+        this.mockXWikiStore.stubs().method("getTranslationList").will(
+            returnValue(Collections.EMPTY_LIST));
+
+        this.mockXWikiVersioningStore =
+            mock(XWikiHibernateVersioningStore.class, new Class[] {XWiki.class,
+            XWikiContext.class}, new Object[] {this.xwiki, this.context});
+        this.mockXWikiVersioningStore.stubs().method("getXWikiDocumentArchive").will(
+            returnValue(null));
+        this.mockXWikiVersioningStore.stubs().method("resetRCSArchive").will(
+            returnValue(null));
+
+        this.xwiki.setStore((XWikiStoreInterface) mockXWikiStore.proxy());
+        this.xwiki.setVersioningStore((XWikiVersioningStoreInterface) mockXWikiVersioningStore
+            .proxy());
+    }
+
+    /////////////////////////////////////////////////////////////////////////////////////////:
+    // Tests
+    
+    private static final String DOCSPACE = "DocumentSpace";
+    private static final String DOCNAME = "DocumentName";
+    private static final String DOCFULLNAME = DOCSPACE + "." + DOCNAME;
+    
+    public void testSaveDocument() throws XWikiException
+    {
+        context.setDatabase(WIKI_NAME);
+
+        databases.clear();
+        databases.put(TARGET_WIKI_NAME, new HashMap());
+
+        /////
+        
+        XWikiDocument doc = new XWikiDocument("DocumentSpace", "DocumentName");
+        
+        WikiManager.getInstance().saveDocument(TARGET_WIKI_NAME, doc, context);
+        
+        assertEquals(WIKI_NAME, context.getDatabase());
+        assertTrue(databases.containsKey(TARGET_WIKI_NAME) && ((Map)databases.get(TARGET_WIKI_NAME)).containsKey(doc.getFullName()));
+    }
+    
+    public void testGetDocument() throws XWikiException
+    {
+        testSaveDocument();
+        
+        /////
+        
+        XWikiDocument doc = WikiManager.getInstance().getDocument(TARGET_WIKI_NAME, DOCFULLNAME, context);
+        
+        assertFalse(doc.isNew());
+        assertEquals(WIKI_NAME, context.getDatabase());
+    }
+    
+    public void testSearchDocuments()
+    {
+        
+    }
+    
+    public void testCreateNewWikiFromPackage()
+    {
+        
+    }
+    
+    public void testCreateNewWikiFromTemplate()
+    {
+        
+    }
+    
+    public void testCreateNewWiki()
+    {
+        
+    }
+    
+    public void testDeleteWiki()
+    {
+        
+    }
+    
+    public void testGetWiki()
+    {
+        
+    }
+    
+    public void testGetWikiDocumentList()
+    {
+        
+    }
+    
+    public void testIsWikiExist()
+    {
+        
+    }
+    
+    public void testGetWikiTemplate()
+    {
+        
+    }
+    
+    public void testGetWikiTemplateList()
+    {
+        
+    }
+    
+    public void testCreateWikiTemplate()
+    {
+        
+    }
+}
Index: src/main/java/com/xpn/xwiki/plugin/multiwiki/doc/XWikiServer.java
===================================================================
--- src/main/java/com/xpn/xwiki/plugin/multiwiki/doc/XWikiServer.java	(révision 0)
+++ src/main/java/com/xpn/xwiki/plugin/multiwiki/doc/XWikiServer.java	(révision 0)
@@ -0,0 +1,143 @@
+/*
+ * Copyright 2006-2007, XpertNet SARL, and individual contributors.
+ *
+ * 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.
+ */
+
+package com.xpn.xwiki.plugin.multiwiki.doc;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import com.xpn.xwiki.XWiki;
+import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.doc.XWikiDocument;
+import com.xpn.xwiki.doc.objects.classes.DefaultSuperDocument;
+
+public class XWikiServer extends DefaultSuperDocument
+{
+    protected static final Log LOG = LogFactory.getLog(XWikiServer.class);
+
+    // ///////////////////////////////////////////////////////////////////
+    // object section
+
+    public XWikiServer(XWikiDocument xdoc, XWikiContext context) throws XWikiException
+    {
+        super(XWikiServerClass.getInstance(context), xdoc, context);
+    }
+
+    public void delete() throws XWikiException
+    {
+        super.delete(context);
+
+        /*XWiki xwiki = context.getWiki();
+
+        try {
+            // delete database
+            xwiki.getStore().deleteWiki(getWikiName(), context);
+        } catch (XWikiException e) {
+            if (LOG.isWarnEnabled()) {
+                LOG.warn("Wiki delete \"" + getWikiName()
+                    + "\" failed: wiki database delete threw exception", e);
+            }
+        }*/
+    }
+
+    // ///
+
+    public String getWikiName()
+    {
+        return sclass.getItemDefaultName(getFullName(), context);
+    }
+
+    public void setWikiName(String wikiName)
+    {
+        getDoc().setFullName(sclass.getItemDocumentDefaultFullName(wikiName, context));
+    }
+
+    public String getOwner()
+    {
+        return getStringValue(XWikiServerClass.FIELD_owner);
+    }
+
+    public void setOwner(String owner)
+    {
+        setStringValue(XWikiServerClass.FIELD_owner, owner);
+    }
+
+    public String getDescription()
+    {
+        return getStringValue(XWikiServerClass.FIELD_description);
+    }
+
+    public void setDescription(String description)
+    {
+        setLargeStringValue(XWikiServerClass.FIELD_description, description);
+    }
+
+    public String getServer()
+    {
+        return getStringValue(XWikiServerClass.FIELD_server);
+    }
+
+    public void setServer(String server)
+    {
+        setStringValue(XWikiServerClass.FIELD_server, server);
+    }
+
+    public String getVisibility()
+    {
+        return getStringValue(XWikiServerClass.FIELD_visibility);
+    }
+
+    public void setVisibility(String visibility)
+    {
+        setStringValue(XWikiServerClass.FIELD_visibility, visibility);
+    }
+
+    public String getLanguage()
+    {
+        return getStringValue(XWikiServerClass.FIELD_language);
+    }
+
+    public void setLanguage(String language)
+    {
+        setStringValue(XWikiServerClass.FIELD_language, language);
+    }
+
+    public String getState()
+    {
+        return getStringValue(XWikiServerClass.FIELD_state);
+    }
+
+    public void setState(String state)
+    {
+        setStringValue(XWikiServerClass.FIELD_state, state);
+    }
+
+    // ///
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see java.lang.Object#toString()
+     */
+    public String toString()
+    {
+        return getFullName() + "," + getServer() + "," + getOwner();
+    }
+}

Modification de propriétés sur src/main/java/com/xpn/xwiki/plugin/multiwiki/doc/XWikiServer.java
___________________________________________________________________
Nom : svn:executable
   + *

Index: src/main/java/com/xpn/xwiki/plugin/multiwiki/doc/XWikiServerClass.java
===================================================================
--- src/main/java/com/xpn/xwiki/plugin/multiwiki/doc/XWikiServerClass.java	(révision 0)
+++ src/main/java/com/xpn/xwiki/plugin/multiwiki/doc/XWikiServerClass.java	(révision 0)
@@ -0,0 +1,223 @@
+/*
+ * Copyright 2006-2007, XpertNet SARL, and individual contributors.
+ *
+ * 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.
+ */
+
+package com.xpn.xwiki.plugin.multiwiki.doc;
+
+import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.doc.XWikiDocument;
+import com.xpn.xwiki.doc.objects.classes.AbstractSuperClass;
+import com.xpn.xwiki.doc.objects.classes.ISuperDocument;
+import com.xpn.xwiki.objects.classes.BaseClass;
+import com.xpn.xwiki.objects.classes.UsersClass;
+import com.xpn.xwiki.plugin.multiwiki.WikiManagerException;
+
+public class XWikiServerClass extends AbstractSuperClass
+{
+    /**
+     * Space of class document.
+     */
+    private static final String CLASS_SPACE = "XWiki";
+    /**
+     * Prefix of class document.
+     */
+    private static final String CLASS_PREFIX = "XWikiServer";
+
+    // ///
+
+    /**
+     * Name of field <code>owner</code>.
+     */
+    public static final String FIELD_owner = "owner";
+    /**
+     * Pretty name of field <code>owner</code>.
+     */
+    public static final String FIELDPN_owner = "Owner";
+
+    /**
+     * Name of field <code>description</code>.
+     */
+    public static final String FIELD_description = "description";
+    /**
+     * Pretty name of field <code>description</code>.
+     */
+    public static final String FIELDPN_description = "Description";
+
+    /**
+     * Name of field <code>server</code>.
+     */
+    public static final String FIELD_server = "server";
+    /**
+     * Pretty name of field <code>server</code>.
+     */
+    public static final String FIELDPN_server = "Server";
+
+    /**
+     * Name of field <code>visibility</code>.
+     */
+    public static final String FIELD_visibility = "visibility";
+    public static final String FIELDL_visibility_public = "public";
+    public static final String FIELDL_visibility_private = "private";
+    public static final String FIELDL_visibility_template = "template";
+    /**
+     * List of possible values for <code>visibility</code>.
+     */
+    public static final String FIELDL_visibility =
+        FIELDL_visibility_public + "|" + FIELDL_visibility_private + "|"
+            + FIELDL_visibility_template;
+    /**
+     * Pretty name of field <code>visibility</code>.
+     */
+    public static final String FIELDPN_visibility = "Visibility";
+
+    /**
+     * Name of field <code>state</code>.
+     */
+    public static final String FIELD_state = "state";
+    public static final String FIELDL_state_active = "active";
+    public static final String FIELDL_state_inactive = "inactive";
+    public static final String FIELDL_state_locked = "locked";
+    /**
+     * List of possible values for <code>state</code>.
+     */
+    public static final String FIELDL_state =
+        FIELDL_state_active + "|" + FIELDL_state_inactive + "|" + FIELDL_state_locked;
+    /**
+     * Pretty name of field <code>state</code>.
+     */
+    public static final String FIELDPN_state = "State";
+
+    /**
+     * Name of field <code>language</code>.
+     */
+    public static final String FIELD_language = "language";
+    /**
+     * List of possible values for <code>language</code>.
+     */
+    public static final String FIELDL_language = "en|fr";
+    /**
+     * Pretty name of field <code>language</code>.
+     */
+    public static final String FIELDPN_language = "Language";
+
+    // ///
+
+    private static XWikiServerClass instance = null;
+
+    /**
+     * Return unique instance of XWikiServerClass and update documents for this context.
+     * 
+     * @param context Context.
+     * @return XWikiServerClass Instance of XWikiApplicationClass.
+     * @throws XWikiException
+     */
+    public static XWikiServerClass getInstance(XWikiContext context) throws XWikiException
+    {
+        synchronized (XWikiServerClass.class) {
+            if (instance == null)
+                instance = new XWikiServerClass();
+        }
+
+        instance.check(context);
+
+        return instance;
+    }
+
+    /**
+     * Default constructor for XWikiServerClass.
+     */
+    private XWikiServerClass()
+    {
+        super(CLASS_SPACE, CLASS_PREFIX, false);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see com.xpn.xwiki.util.AbstractSuperClass#updateBaseClass(com.xpn.xwiki.objects.classes.BaseClass)
+     */
+    protected boolean updateBaseClass(BaseClass baseClass)
+    {
+        boolean needsUpdate = super.updateBaseClass(baseClass);
+
+        baseClass.setName(getClassFullName());
+
+        needsUpdate |= baseClass.addUsersField(FIELD_owner, FIELDPN_owner);
+        // TODO : move into addUserField with "multiselect" parameter
+        UsersClass userclass = (UsersClass)baseClass.getField(FIELD_owner);
+        userclass.setMultiSelect(false);
+        
+        needsUpdate |= baseClass.addTextAreaField(FIELD_description, FIELDPN_description, 40, 5);
+        needsUpdate |= baseClass.addTextField(FIELD_server, FIELDPN_server, 30);
+        needsUpdate |=
+            baseClass.addStaticListField(FIELD_visibility, FIELDPN_visibility, FIELDL_visibility);
+        needsUpdate |= baseClass.addStaticListField(FIELD_state, FIELDPN_state, FIELDL_state);
+        needsUpdate |=
+            baseClass.addStaticListField(FIELD_language, FIELDPN_language, FIELDL_language);
+
+        return needsUpdate;
+    }
+
+    private XWikiDocument getWikiServerDocument(String wikiName, XWikiContext context,
+        boolean validate) throws XWikiException
+    {
+        XWikiDocument doc = getItemDocument(wikiName, context);
+
+        if (validate && doc.isNew())
+            throw new WikiManagerException(WikiManagerException.ERROR_MULTIWIKI_SERVER_DOES_NOT_EXIST,
+                wikiName + " wiki server does not exist");
+
+        return doc;
+    }
+
+    private XWikiDocument getWikiTemplateServerDocument(String wikiName, XWikiContext context,
+        boolean validate) throws XWikiException
+    {
+        XWikiDocument doc = getItemDocument(wikiName, context);
+
+        if (validate) {
+            if (doc.isNew())
+                throw new WikiManagerException(WikiManagerException.ERROR_MULTIWIKI_SERVER_DOES_NOT_EXIST,
+                    wikiName + " wiki server does not exist");
+            if (!doc.getStringValue(FIELD_visibility).equals(FIELDL_visibility_template))
+                throw new WikiManagerException(WikiManagerException.ERROR_MULTIWIKI_SERVER_DOES_NOT_EXIST,
+                    wikiName + " wiki server template does not exist");
+        }
+
+        return doc;
+    }
+
+    public XWikiServer getWikiServer(String wikiName, XWikiContext context, boolean validate)
+        throws XWikiException
+    {
+        return (XWikiServer)newSuperDocument(getWikiServerDocument(wikiName, context, validate), context);
+    }
+
+    public XWikiServer getWikiTemplateServer(String wikiName, XWikiContext context,
+        boolean validate) throws XWikiException
+    {
+        return (XWikiServer)newSuperDocument(getWikiTemplateServerDocument(wikiName, context, validate),
+            context);
+    }
+    
+    public ISuperDocument newSuperDocument(XWikiDocument doc, XWikiContext context)
+    {
+        return (ISuperDocument)doc.newDocument(XWikiServer.class.getName(), context);
+    }
+}

Modification de propriétés sur src/main/java/com/xpn/xwiki/plugin/multiwiki/doc/XWikiServerClass.java
___________________________________________________________________
Nom : svn:executable
   + *

Index: src/main/java/com/xpn/xwiki/plugin/multiwiki/MultiWikiPluginAPI.java
===================================================================
--- src/main/java/com/xpn/xwiki/plugin/multiwiki/MultiWikiPluginAPI.java	(révision 4867)
+++ src/main/java/com/xpn/xwiki/plugin/multiwiki/MultiWikiPluginAPI.java	(copie de travail)
@@ -1,167 +0,0 @@
-/*
- * Copyright 2007, 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 jvelociter
- */
-package com.xpn.xwiki.plugin.multiwiki;
-
-import com.xpn.xwiki.api.Api;
-import com.xpn.xwiki.XWikiContext;
-import com.xpn.xwiki.XWikiException;
-
-import java.util.Map;
-import java.util.List;
-
-/**
- * API for managing multiwikis
- *
- * @version $Id: $
- * @see com.xpn.xwiki.plugin.multiwiki.MultiWikiPlugin
- */
-public class MultiWikiPluginAPI extends Api
-{
-    /**
-     * The MultiWiki plugin hidden by this API class. This is to create a separation between the API
-     * used by users in XWiki documents and the actual implementations.
-     */
-    private MultiWikiPlugin plugin;
-
-    /**
-     * @param context the XWiki Context object
-     * @param plugin the MutliWikiPlugin plugin
-     * @see #getXWikiContext()
-     */
-    public MultiWikiPluginAPI(MultiWikiPlugin plugin, XWikiContext context)
-    {
-        super(context);
-        this.plugin = plugin;
-    }
-
-    /**
-     * Create an account on the top level wiki
-     *
-     * @param params A map that contains account parameters for creation
-     * @param username the username of the account to be created
-     * @param emailValidation true if the account creation needs validation by mail
-     * @param generateUsername true if the user name has to be generated
-     * @return true on success, false on failure. On failure the error log is pushed in the
-     *         context.
-     */
-    public void createAccount(Map params, String username, boolean emailValidation,
-        boolean generateUsername)
-    {
-        try {
-            plugin.createAccount(params, username, emailValidation, generateUsername, context);
-        } catch (MultiWikiPluginException e) {
-            context.put(
-                "error",
-                "Error while creation account : " + e.getMessage()
-            );
-        }
-    }
-
-    /**
-     *
-     * @param wikiName
-     * @param wikiUrl
-     * @param wikiAdmin
-     * @param baseWikiName
-     * @param description
-     * @param language
-     * @param failOnExist
-     * @param context
-     * @return
-     * @throws XWikiException
-     */
-    public int createNewWiki(String wikiName, String wikiUrl, String wikiAdmin,
-        String baseWikiName, String description, String language, boolean failOnExist,
-        XWikiContext context) throws XWikiException
-    {
-        return plugin.createWiki(wikiName, wikiUrl, wikiAdmin, baseWikiName, description, language,
-            failOnExist, context);
-    }
-
-    /**
-     * Get the list of wiki associated to a given username
-     *
-     * @param username the name of the user that own the wikis to be retrieved
-     * @return the list of wikis owned by the user
-     */
-    public List getWikiList(String username)
-    {
-        return plugin.getWikiList(username);
-    }
-
-    /**
-     * Get all wikis
-     *
-     * @return a list of all the wikis
-     */
-    public List getWikiList()
-    {
-        return plugin.getWikiList();
-    }
-
-    /**
-     * Validate an account from email
-     *
-     * @param username the username of the account to be validated
-     * @param validKey the validation key the user received by mail
-     * @param withConfirmation indicates if the user shall receive a confirmation email of his
-     * account validation
-     * @return true on success, false on failure
-     */
-    public int validateAccount(String username, String validKey, boolean withConfirmation)
-    {
-        try {
-            if (plugin.validateAccount(username, validKey, withConfirmation, context)) {
-                return 0;
-            } else {
-                return -1;
-            }
-        } catch (MultiWikiPluginException e) {
-            context.put("error", "Error occured while validating account with username \"" +
-                username + "\". Caused by : " + e.getMessage());
-            return -2;
-        }
-    }
-
-    /**
-     * Check if a given username is actually an account
-     *
-     * @return true if the account exists for the given username, false otherwise
-     */
-    public boolean isAccount(String username)
-    {
-        return plugin.isAccount(username, context);
-    }
-
-    /**
-     * Check if a Server of the given name exists in the master Wiki by checking if the
-     * "XWiki.XWikiServer{serverName}" document is new
-     *
-     * @param serverName the name of the server to be checked
-     * @param context the context
-     * @return true if server exists, false otherwise
-     */
-    public boolean isServer(String serverName, XWikiContext context)
-    {
-        return plugin.isServer(serverName, context);
-    }
-}
Index: src/main/java/com/xpn/xwiki/plugin/multiwiki/WikiManagerPluginApi.java
===================================================================
--- src/main/java/com/xpn/xwiki/plugin/multiwiki/WikiManagerPluginApi.java	(révision 4867)
+++ src/main/java/com/xpn/xwiki/plugin/multiwiki/WikiManagerPluginApi.java	(copie de travail)
@@ -1,6 +1,5 @@
 /*
- * Copyright 2007, XpertNet SARL, and individual contributors as indicated
- * by the contributors.txt.
+ * Copyright 2006-2007, XpertNet SARL, and individual contributors.
  *
  * This is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as
@@ -16,152 +15,298 @@
  * 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 jvelociter
  */
+
 package com.xpn.xwiki.plugin.multiwiki;
 
-import com.xpn.xwiki.api.Api;
+import com.xpn.xwiki.api.XWikiExceptionApi;
+import com.xpn.xwiki.doc.XWikiDocument;
+import com.xpn.xwiki.plugin.PluginApi;
+import com.xpn.xwiki.plugin.multiwiki.doc.XWikiServer;
+import com.xpn.xwiki.plugin.multiwiki.doc.XWikiServerClass;
 import com.xpn.xwiki.XWikiContext;
 import com.xpn.xwiki.XWikiException;
 
-import java.util.Map;
+import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 /**
  * API for managing multiwikis
- *
+ * 
  * @version $Id: $
- * @see com.xpn.xwiki.plugin.multiwiki.MultiWikiPlugin
+ * @see com.xpn.xwiki.plugin.multiwiki.WikiManagerPlugin
  */
-public class MultiWikiPluginAPI extends Api
+public class WikiManagerPluginApi extends PluginApi
 {
-    /**
-     * The MultiWiki plugin hidden by this API class. This is to create a separation between the API
-     * used by users in XWiki documents and the actual implementations.
-     */
-    private MultiWikiPlugin plugin;
+    protected static final Log LOG = LogFactory.getLog(WikiManagerPluginApi.class);
 
-    /**
-     * @param context the XWiki Context object
-     * @param plugin the MutliWikiPlugin plugin
-     * @see #getXWikiContext()
-     */
-    public MultiWikiPluginAPI(MultiWikiPlugin plugin, XWikiContext context)
+    private XWikiExceptionApi defaultException;
+
+    public WikiManagerPluginApi(WikiManagerPlugin plugin, XWikiContext context)
     {
-        super(context);
-        this.plugin = plugin;
+        super(plugin, context);
+
+        this.defaultException =
+            new XWikiExceptionApi(WikiManagerException.getDefaultException(), this.context);
     }
 
-    /**
-     * Create an account on the top level wiki
-     *
-     * @param params A map that contains account parameters for creation
-     * @param username the username of the account to be created
-     * @param emailValidation true if the account creation needs validation by mail
-     * @param generateUsername true if the user name has to be generated
-     * @return true on success, false on failure. On failure the error log is pushed in the
-     *         context.
-     */
-    public void createAccount(Map params, String username, boolean emailValidation,
-        boolean generateUsername)
+    public XWikiExceptionApi getDefaultException()
     {
+        return this.defaultException;
+    }
+
+    // ////////////////////////////////////////////////////////////////////////////
+    // Wikis management
+
+    public int createNewWiki(String wikiname, String templateWiki, XWikiServer wikiSuperDocument,
+        boolean failOnExist) throws XWikiException
+    {
+        return createNewWiki(wikiname, templateWiki, null, wikiSuperDocument, failOnExist);
+    }
+
+    public int createNewWiki(String wikiname, String templateWiki, String pkg,
+        XWikiServer wikiSuperDocument, boolean failOnExist) throws XWikiException
+    {
+        if (!hasAdminRights())
+            return XWikiException.ERROR_XWIKI_ACCESS_DENIED;
+
+        int returncode = XWikiExceptionApi.ERROR_NOERROR;
+
+        wikiSuperDocument.setWikiName(wikiname);
+
+        // Some initializations dues to Velocity
+        if ("".equals(templateWiki))
+            templateWiki = null;
+
         try {
-            plugin.createAccount(params, username, emailValidation, generateUsername, context);
-        } catch (MultiWikiPluginException e) {
-            context.put(
-                "error",
-                "Error while creation account : " + e.getMessage()
-            );
+            if (templateWiki != null)
+                WikiManager.getInstance().createNewWikiFromTemplate(wikiSuperDocument, templateWiki, failOnExist, this.context);
+            else if (pkg != null)
+                WikiManager.getInstance().createNewWikiFromPackage(wikiSuperDocument, pkg, failOnExist, this.context);
+            else
+                WikiManager.getInstance().createNewWiki(wikiSuperDocument, failOnExist, this.context);
+        } catch (WikiManagerException e) {
+            LOG.error("Try to create wiki \"" + wikiSuperDocument + "\"", e);
+
+            this.context.put("lasterrorcode", new Integer(e.getCode()));
+            this.context.put("lastexception", new XWikiExceptionApi(e, this.context));
+
+            returncode = e.getCode();
         }
+
+        return returncode;
     }
 
-    /**
-     *
-     * @param wikiName
-     * @param wikiUrl
-     * @param wikiAdmin
-     * @param baseWikiName
-     * @param description
-     * @param language
-     * @param failOnExist
-     * @param context
-     * @return
-     * @throws XWikiException
-     */
-    public int createNewWiki(String wikiName, String wikiUrl, String wikiAdmin,
-        String baseWikiName, String description, String language, boolean failOnExist,
-        XWikiContext context) throws XWikiException
+    public int deleteWiki(String wikiName) throws XWikiException
     {
-        return plugin.createWiki(wikiName, wikiUrl, wikiAdmin, baseWikiName, description, language,
-            failOnExist, context);
+        if (!hasAdminRights())
+            return XWikiException.ERROR_XWIKI_ACCESS_DENIED;
+
+        int returncode = XWikiExceptionApi.ERROR_NOERROR;
+
+        try {
+            WikiManager.getInstance().deleteWiki(wikiName, this.context);
+        } catch (WikiManagerException e) {
+            LOG.error("Try to delete wiki \"" + wikiName + "\"", e);
+
+            this.context.put("lasterrorcode", new Integer(e.getCode()));
+            this.context.put("lastexception", new XWikiExceptionApi(e, this.context));
+
+            returncode = e.getCode();
+        }
+
+        return returncode;
     }
 
+    public XWikiServer getWikiDocument(String wikiName) throws XWikiException
+    {
+        XWikiServer doc = null;
+
+        try {
+            doc =
+                WikiManager.getInstance().getWiki(wikiName, this.context, true);
+        } catch (WikiManagerException e) {
+            LOG.error("Try to get wiki \"" + wikiName + "\" document", e);
+
+            this.context.put("lasterrorcode", new Integer(e.getCode()));
+            this.context.put("lastexception", new XWikiExceptionApi(e, this.context));
+        }
+
+        return doc;
+    }
+
     /**
      * Get the list of wiki associated to a given username
-     *
+     * 
      * @param username the name of the user that own the wikis to be retrieved
      * @return the list of wikis owned by the user
+     * @throws XWikiException
      */
-    public List getWikiList(String username)
+    public List getWikiDocumentList(String username) throws XWikiException
     {
-        return plugin.getWikiList(username);
+        List listDocument = new ArrayList();
+
+        try {
+            listDocument = WikiManager.getInstance().getWikiList(/*username, */this.context);
+        } catch (WikiManagerException e) {
+            if (username != null)
+                LOG.error("Try to get wikis documents for user \"" + username + "\"", e);
+            else
+                LOG.error("Try to get all wikis documents", e);
+
+            this.context.put("lasterrorcode", new Integer(e.getCode()));
+            this.context.put("lastexception", new XWikiExceptionApi(e, this.context));
+        }
+
+        return listDocument;
     }
 
     /**
      * Get all wikis
-     *
+     * 
      * @return a list of all the wikis
+     * @throws XWikiException
      */
-    public List getWikiList()
+    public List getWikiDocumentList() throws XWikiException
     {
-        return plugin.getWikiList();
+        return getWikiDocumentList(null);
     }
 
     /**
-     * Validate an account from email
-     *
-     * @param username the username of the account to be validated
-     * @param validKey the validation key the user received by mail
-     * @param withConfirmation indicates if the user shall receive a confirmation email of his
-     * account validation
-     * @return true on success, false on failure
+     * Create empty wiki document
+     * 
+     * @return Document Empty wiki document
+     * @throws XWikiException
      */
-    public int validateAccount(String username, String validKey, boolean withConfirmation)
+    public XWikiServer createWikiDocument() throws XWikiException
     {
-        try {
-            if (plugin.validateAccount(username, validKey, withConfirmation, context)) {
-                return 0;
-            } else {
-                return -1;
-            }
-        } catch (MultiWikiPluginException e) {
-            context.put("error", "Error occured while validating account with username \"" +
-                username + "\". Caused by : " + e.getMessage());
-            return -2;
-        }
+        return (XWikiServer)XWikiServerClass.getInstance(context).newSuperDocument(context);
     }
 
     /**
-     * Check if a given username is actually an account
-     *
-     * @return true if the account exists for the given username, false otherwise
-     */
-    public boolean isAccount(String username)
-    {
-        return plugin.isAccount(username, context);
-    }
-
-    /**
      * Check if a Server of the given name exists in the master Wiki by checking if the
      * "XWiki.XWikiServer{serverName}" document is new
-     *
-     * @param serverName the name of the server to be checked
-     * @param context the context
+     * 
+     * @param wikiName the name of the server to be checked
      * @return true if server exists, false otherwise
      */
-    public boolean isServer(String serverName, XWikiContext context)
+    public boolean isWikiExist(String wikiName)
     {
-        return plugin.isServer(serverName, context);
+        return WikiManager.getInstance().isWikiExist(wikiName, this.context);
     }
+
+    public int setWikiVisibility(String wikiName, String visibility) throws XWikiException
+    {
+        int returncode = XWikiExceptionApi.ERROR_NOERROR;
+
+        try {
+            XWikiServer wikiDoc = WikiManager.getInstance().getWiki(wikiName, this.context, true);
+            wikiDoc.setVisibility(visibility);
+            wikiDoc.save();
+        } catch (WikiManagerException e) {
+            LOG.error("Try to set wiki visibility \"" + wikiName + "\"", e);
+
+            this.context.put("lasterrorcode", new Integer(e.getCode()));
+            this.context.put("lastexception", new XWikiExceptionApi(e, this.context));
+
+            returncode = e.getCode();
+        }
+
+        return returncode;
+    }
+
+    public String getWikiName(XWikiServer document) throws XWikiException
+    {
+        String wikiName = null;
+
+        try {
+            wikiName =
+                XWikiServerClass.getInstance(this.context).getItemDefaultName(
+                    document.getFullName(), this.context);
+        } catch (WikiManagerException e) {
+            LOG.error("Try to get wiki name \"" + document.getFullName() + "\"", e);
+
+            this.context.put("lasterrorcode", new Integer(e.getCode()));
+            this.context.put("lastexception", new XWikiExceptionApi(e, this.context));
+        }
+
+        return wikiName;
+    }
+
+    // ////////////////////////////////////////////////////////////////////////////
+    // Template management
+
+    public int createWikiTemplate(String templateName, String templateDescription,
+        String packageName) throws XWikiException
+    {
+        if (!hasAdminRights())
+            return XWikiException.ERROR_XWIKI_ACCESS_DENIED;
+
+        int returncode = XWikiExceptionApi.ERROR_NOERROR;
+
+        XWikiServer wikiSuperDocument = (XWikiServer)XWikiServerClass.getInstance(context).newSuperDocument(context);
+        wikiSuperDocument.setWikiName(templateName);
+        wikiSuperDocument.setDescription(templateDescription);
+
+        wikiSuperDocument.setServer(templateName + ".template.local");
+
+        wikiSuperDocument.setState(XWikiServerClass.FIELDL_state_active);
+        wikiSuperDocument.setOwner(this.context.getUser());
+
+        try {
+            WikiManager.getInstance().createWikiTemplate(wikiSuperDocument, packageName,
+                this.context);
+        } catch (WikiManagerException e) {
+            LOG.error("Try to create wiki template \"" + wikiSuperDocument + "\"", e);
+
+            this.context.put("lasterrorcode", new Integer(e.getCode()));
+            this.context.put("lastexception", new XWikiExceptionApi(e, this.context));
+
+            returncode = e.getCode();
+        }
+
+        return returncode;
+    }
+
+    public XWikiServer getWikiTemplateDocument(String wikiName) throws XWikiException
+    {
+        XWikiServer doc = null;
+
+        try {
+            doc =
+                WikiManager.getInstance().getWikiTemplate(wikiName, this.context, true);
+        } catch (WikiManagerException e) {
+            LOG.error("Try to get wiki \"" + wikiName + "\" document", e);
+
+            this.context.put("lasterrorcode", new Integer(e.getCode()));
+            this.context.put("lastexception", new XWikiExceptionApi(e, this.context));
+        }
+
+        return doc;
+    }
+
+    public List getWikiTemplateList() throws XWikiException
+    {
+        List listDocument = new ArrayList();
+
+        try {
+            List listXWikiDocument = WikiManager.getInstance().getWikiTemplateList(this.context);
+            
+            for (Iterator it = listXWikiDocument.iterator(); it.hasNext();) {
+                XWikiDocument doc = (XWikiDocument) it.next();
+                listDocument.add(doc.newDocument(this.context));
+            }
+        } catch (WikiManagerException e) {
+            LOG.error("Try to get wikis templates", e);
+
+            this.context.put("lasterrorcode", new Integer(e.getCode()));
+            this.context.put("lastexception", new XWikiExceptionApi(e, this.context));
+        }
+
+        return listDocument;
+    }
 }
Index: src/main/java/com/xpn/xwiki/plugin/multiwiki/MultiWikiPluginException.java
===================================================================
--- src/main/java/com/xpn/xwiki/plugin/multiwiki/MultiWikiPluginException.java	(révision 4867)
+++ src/main/java/com/xpn/xwiki/plugin/multiwiki/MultiWikiPluginException.java	(copie de travail)
@@ -1,39 +0,0 @@
-package com.xpn.xwiki.plugin.multiwiki;
-
-import com.xpn.xwiki.plugin.PluginException;
-
-public class MultiWikiPluginException extends PluginException
-{
-    public static final int ERROR_MULTIWIKI_ACCOUNT_ALREADY_EXISTS = 50010;
-
-    public static final int ERROR_MULTIWIKI_CANNOT_CREATE_ACCOUNT = 50011;
-
-    public static final int ERROR_MULTIWIKI_SERVER_ALREADY_EXISTS = 50020;
-
-    public static final int ERROR_MULTIWIKI_CANNOT_CREATE_SERVER = 50021;
-
-    public static final int ERROR_MULTIWIKI_CANNOT_CREATE_SERVER_ADMIN = 50022;
-
-    public static final int ERROR_MULTIWIKI_CANNOT_CREATE_USER_SPACE = 50003;
-
-    public static final int ERROR_MULTIWIKI_CANNOT_USER_ALREADY_EXISTS = 50030;
-
-    public static final int ERROR_MULTIWIKI_CANNOT_CANNOT_VALIDATE_ACCOUNT= 50031;
-
-    public static final int ERROR_MULTIWIKI_CANNOT_CREATE_WIKI = 50032;
-
-    public MultiWikiPluginException(int code, String message)
-    {
-        super(com.xpn.xwiki.plugin.multiwiki.MultiWikiPlugin.class, code, message);
-    }
-
-    public MultiWikiPluginException(int code, String message, Throwable e, Object[] args)
-    {
-        super(com.xpn.xwiki.plugin.multiwiki.MultiWikiPlugin.class, code, message, e, args);
-    }
-
-    public MultiWikiPluginException(int code, String message, Throwable e)
-    {
-        super(com.xpn.xwiki.plugin.multiwiki.MultiWikiPlugin.class, code, message, e);
-    }
-}
Index: src/main/java/com/xpn/xwiki/plugin/multiwiki/MultiWikiPlugin.java
===================================================================
--- src/main/java/com/xpn/xwiki/plugin/multiwiki/MultiWikiPlugin.java	(révision 4867)
+++ src/main/java/com/xpn/xwiki/plugin/multiwiki/MultiWikiPlugin.java	(copie de travail)
@@ -1,215 +0,0 @@
-/*
- * Copyright 2007, 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 jvelociter
- */
-package com.xpn.xwiki.plugin.multiwiki;
-
-import com.xpn.xwiki.plugin.XWikiDefaultPlugin;
-import com.xpn.xwiki.plugin.XWikiPluginInterface;
-import com.xpn.xwiki.XWikiContext;
-import com.xpn.xwiki.XWikiException;
-import com.xpn.xwiki.doc.XWikiDocument;
-import com.xpn.xwiki.objects.BaseObject;
-import com.xpn.xwiki.api.*;
-
-import java.util.Map;
-import java.util.List;
-import java.lang.Object;
-
-import org.apache.log4j.Logger;
-
-/**
- * {@inheritDoc}
- */
-public class MultiWikiPlugin extends XWikiDefaultPlugin implements MultiWikiPluginInterface
-{
-    /**
-     * Log4J logger object to log messages in this class.
-     */
-    private static final Logger LOG = Logger.getLogger(MultiWikiPlugin.class);
-
-    /**
-     * {@inheritDoc}
-     *
-     * @see XWikiDefaultPlugin#XWikiDefaultPlugin(String,String,com.xpn.xwiki.XWikiContext)
-     */
-    public MultiWikiPlugin(String name, String className, XWikiContext context)
-    {
-        super(name, className, context);
-    }
-
-    /**
-     * {@inheritDoc}
-     *
-     * @see com.xpn.xwiki.plugin.XWikiDefaultPlugin#getName()
-     */
-    public String getName()
-    {
-        return "multiwiki";
-    }
-
-    /**
-     * {@inheritDoc}
-     *
-     * @see com.xpn.xwiki.plugin.XWikiDefaultPlugin#getPluginApi
-     */
-    public Api getPluginApi(XWikiPluginInterface plugin, XWikiContext context)
-    {
-        return new MultiWikiPluginAPI((MultiWikiPlugin) plugin, context);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public void createAccount(Map params, String username, boolean emailValidation,
-        boolean generateUsername, XWikiContext context) throws MultiWikiPluginException
-    {
-        if (isAccount(username, context)) {
-            throw new MultiWikiPluginException(
-                MultiWikiPluginException.ERROR_MULTIWIKI_ACCOUNT_ALREADY_EXISTS,
-                "Account with user name " + username + "already exists"
-            );
-        }
-        try {
-            String validKey = "";
-            if (emailValidation) {
-                validKey = context.getWiki().generateValidationKey(16);
-                params.put("validkey", validKey);
-                params.put("active", "0");
-            } else {
-                params.put("active", "1");
-            }
-
-            context.getWiki()
-                .createUser(username, params, "", getUserTemplate(context), "view, edit", context);
-
-            if (emailValidation) {
-                context.getWiki().sendValidationEmail("XWiki." + username,
-                    (String) params.get("password"), (String) params.get("email"), validKey,
-                    "validation_email_content", context);
-            }
-        }
-        catch (XWikiException e) {
-            Object[] args = {username};
-            throw new MultiWikiPluginException(
-                MultiWikiPluginException.ERROR_MULTIWIKI_CANNOT_CREATE_ACCOUNT,
-                "Cannot create account with username {0}",
-                e,
-                args
-            );
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public boolean validateAccount(String xwikiname, String validkey, boolean withConfirmationEmail,
-        XWikiContext context) throws MultiWikiPluginException
-    {
-        //I do not use xwiki.validateAccount() since it depends on request parameters
-        try {
-            boolean result = false;
-            if (xwikiname.indexOf(".") == -1) {
-                xwikiname = "XWiki." + xwikiname;
-            }
-
-            XWikiDocument docuser = context.getWiki().getDocument(xwikiname, context);
-            BaseObject userobj = docuser.getObject("XWiki.XWikiUsers", 0);
-            String validkey2 = userobj.getStringValue("validkey");
-            String email = userobj.getStringValue("email");
-            String password = userobj.getStringValue("password");
-
-            if ((!validkey2.equals("") && (validkey2.equals(validkey)))) {
-                userobj.setIntValue("active", 1);
-                context.getWiki().saveDocument(docuser, context);
-
-                result = true;
-
-                if (withConfirmationEmail) {
-                    context.getWiki().sendValidationEmail(xwikiname, password, email, validkey,
-                        "confirmation_email_content", context);
-                }
-            }
-            return result;
-        }
-        catch (XWikiException e) {
-            Object[] args = {xwikiname};
-            throw new MultiWikiPluginException(
-                MultiWikiPluginException.ERROR_MULTIWIKI_CANNOT_CANNOT_VALIDATE_ACCOUNT,
-                "Could not validate user with name {0}",
-                e,
-                args);
-        }
-    }
-
-    public int createWiki(String wikiName, String wikiUrl, String wikiAdmin,
-        String baseWikiName, String description, String language, boolean failOnExist,
-        XWikiContext context) throws MultiWikiPluginException
-    {
-        try {
-            return context.getWiki().createNewWiki(wikiName, wikiUrl, wikiAdmin, baseWikiName,
-                description, language, failOnExist, context);
-        } catch (XWikiException e) {
-            Object args[] = {wikiName};
-            throw new MultiWikiPluginException(
-                MultiWikiPluginException.ERROR_MULTIWIKI_CANNOT_CREATE_WIKI,
-                "Could not create wiki with wiki name {0}",
-                e,
-                args);
-        }
-    }
-
-    public List getWikiList(String username)
-    {
-        //todo
-        return null;
-    }
-
-    public List getWikiList()
-    {
-        //todo
-        return null;
-    }
-
-    public boolean isAccount(String username, XWikiContext context)
-    {
-        try {
-            return !context.getWiki().getDocument("XWiki." + username, context).isNew();
-        } catch (XWikiException e) {
-            return true;
-        }
-    }
-
-    public boolean isServer(String serverName, XWikiContext context)
-    {
-        try {
-            return !context.getWiki().getDocument("XWiki.XWikiServer" + serverName, context)
-                .isNew();
-        }
-        catch (XWikiException e) {
-            return true;
-        }
-    }
-
-    private String getUserTemplate(XWikiContext context) throws XWikiException
-    {
-        return context.getWiki().getDocument("XWiki.XWikiUserTemplate", context).getContent();
-    }
-}
Index: src/main/java/com/xpn/xwiki/plugin/multiwiki/WikiManagerPlugin.java
===================================================================
--- src/main/java/com/xpn/xwiki/plugin/multiwiki/WikiManagerPlugin.java	(révision 4867)
+++ src/main/java/com/xpn/xwiki/plugin/multiwiki/WikiManagerPlugin.java	(copie de travail)
@@ -1,6 +1,5 @@
 /*
- * Copyright 2007, XpertNet SARL, and individual contributors as indicated
- * by the contributors.txt.
+ * Copyright 2006-2007, XpertNet SARL, and individual contributors.
  *
  * This is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as
@@ -16,200 +15,61 @@
  * 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 jvelociter
  */
+
 package com.xpn.xwiki.plugin.multiwiki;
 
 import com.xpn.xwiki.plugin.XWikiDefaultPlugin;
 import com.xpn.xwiki.plugin.XWikiPluginInterface;
 import com.xpn.xwiki.XWikiContext;
-import com.xpn.xwiki.XWikiException;
-import com.xpn.xwiki.doc.XWikiDocument;
-import com.xpn.xwiki.objects.BaseObject;
-import com.xpn.xwiki.api.*;
 
-import java.util.Map;
-import java.util.List;
-import java.lang.Object;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
-import org.apache.log4j.Logger;
-
-/**
- * {@inheritDoc}
- */
-public class MultiWikiPlugin extends XWikiDefaultPlugin implements MultiWikiPluginInterface
+public class WikiManagerPlugin extends XWikiDefaultPlugin
 {
-    /**
-     * Log4J logger object to log messages in this class.
-     */
-    private static final Logger LOG = Logger.getLogger(MultiWikiPlugin.class);
+    protected static final Log LOG = LogFactory.getLog(WikiManagerPlugin.class);
 
-    /**
-     * {@inheritDoc}
-     *
-     * @see XWikiDefaultPlugin#XWikiDefaultPlugin(String,String,com.xpn.xwiki.XWikiContext)
-     */
-    public MultiWikiPlugin(String name, String className, XWikiContext context)
+    // ////////////////////////////////////////////////////////////////////////////
+
+    private static final String PLUGIN_NAME = "multiwiki";
+
+    // ////////////////////////////////////////////////////////////////////////////
+
+    public WikiManagerPlugin(String name, String className, XWikiContext context)
     {
         super(name, className, context);
+        init(context);
     }
 
-    /**
-     * {@inheritDoc}
-     *
+    /*
+     * (non-Javadoc)
+     * 
      * @see com.xpn.xwiki.plugin.XWikiDefaultPlugin#getName()
      */
     public String getName()
     {
-        return "multiwiki";
+        return PLUGIN_NAME;
     }
 
-    /**
-     * {@inheritDoc}
-     *
-     * @see com.xpn.xwiki.plugin.XWikiDefaultPlugin#getPluginApi
+    /*
+     * (non-Javadoc)
+     * 
+     * @see com.xpn.xwiki.plugin.XWikiDefaultPlugin#getPluginApi(com.xpn.xwiki.plugin.XWikiPluginInterface,
+     *      com.xpn.xwiki.XWikiContext)
      */
-    public Api getPluginApi(XWikiPluginInterface plugin, XWikiContext context)
+    public com.xpn.xwiki.api.Api getPluginApi(XWikiPluginInterface plugin, XWikiContext context)
     {
-        return new MultiWikiPluginAPI((MultiWikiPlugin) plugin, context);
+        return new WikiManagerPluginApi((WikiManagerPlugin) plugin, context);
     }
 
-    /**
-     * {@inheritDoc}
+    /*
+     * (non-Javadoc)
+     * 
+     * @see com.xpn.xwiki.plugin.XWikiDefaultPlugin#init(com.xpn.xwiki.XWikiContext)
      */
-    public void createAccount(Map params, String username, boolean emailValidation,
-        boolean generateUsername, XWikiContext context) throws MultiWikiPluginException
+    public void init(XWikiContext context)
     {
-        if (isAccount(username, context)) {
-            throw new MultiWikiPluginException(
-                MultiWikiPluginException.ERROR_MULTIWIKI_ACCOUNT_ALREADY_EXISTS,
-                "Account with user name " + username + "already exists"
-            );
-        }
-        try {
-            String validKey = "";
-            if (emailValidation) {
-                validKey = context.getWiki().generateValidationKey(16);
-                params.put("validkey", validKey);
-                params.put("active", "0");
-            } else {
-                params.put("active", "1");
-            }
-
-            context.getWiki()
-                .createUser(username, params, "", getUserTemplate(context), "view, edit", context);
-
-            if (emailValidation) {
-                context.getWiki().sendValidationEmail("XWiki." + username,
-                    (String) params.get("password"), (String) params.get("email"), validKey,
-                    "validation_email_content", context);
-            }
-        }
-        catch (XWikiException e) {
-            Object[] args = {username};
-            throw new MultiWikiPluginException(
-                MultiWikiPluginException.ERROR_MULTIWIKI_CANNOT_CREATE_ACCOUNT,
-                "Cannot create account with username {0}",
-                e,
-                args
-            );
-        }
+        super.init(context);
     }
-
-    /**
-     * {@inheritDoc}
-     */
-    public boolean validateAccount(String xwikiname, String validkey, boolean withConfirmationEmail,
-        XWikiContext context) throws MultiWikiPluginException
-    {
-        //I do not use xwiki.validateAccount() since it depends on request parameters
-        try {
-            boolean result = false;
-            if (xwikiname.indexOf(".") == -1) {
-                xwikiname = "XWiki." + xwikiname;
-            }
-
-            XWikiDocument docuser = context.getWiki().getDocument(xwikiname, context);
-            BaseObject userobj = docuser.getObject("XWiki.XWikiUsers", 0);
-            String validkey2 = userobj.getStringValue("validkey");
-            String email = userobj.getStringValue("email");
-            String password = userobj.getStringValue("password");
-
-            if ((!validkey2.equals("") && (validkey2.equals(validkey)))) {
-                userobj.setIntValue("active", 1);
-                context.getWiki().saveDocument(docuser, context);
-
-                result = true;
-
-                if (withConfirmationEmail) {
-                    context.getWiki().sendValidationEmail(xwikiname, password, email, validkey,
-                        "confirmation_email_content", context);
-                }
-            }
-            return result;
-        }
-        catch (XWikiException e) {
-            Object[] args = {xwikiname};
-            throw new MultiWikiPluginException(
-                MultiWikiPluginException.ERROR_MULTIWIKI_CANNOT_CANNOT_VALIDATE_ACCOUNT,
-                "Could not validate user with name {0}",
-                e,
-                args);
-        }
-    }
-
-    public int createWiki(String wikiName, String wikiUrl, String wikiAdmin,
-        String baseWikiName, String description, String language, boolean failOnExist,
-        XWikiContext context) throws MultiWikiPluginException
-    {
-        try {
-            return context.getWiki().createNewWiki(wikiName, wikiUrl, wikiAdmin, baseWikiName,
-                description, language, failOnExist, context);
-        } catch (XWikiException e) {
-            Object args[] = {wikiName};
-            throw new MultiWikiPluginException(
-                MultiWikiPluginException.ERROR_MULTIWIKI_CANNOT_CREATE_WIKI,
-                "Could not create wiki with wiki name {0}",
-                e,
-                args);
-        }
-    }
-
-    public List getWikiList(String username)
-    {
-        //todo
-        return null;
-    }
-
-    public List getWikiList()
-    {
-        //todo
-        return null;
-    }
-
-    public boolean isAccount(String username, XWikiContext context)
-    {
-        try {
-            return !context.getWiki().getDocument("XWiki." + username, context).isNew();
-        } catch (XWikiException e) {
-            return true;
-        }
-    }
-
-    public boolean isServer(String serverName, XWikiContext context)
-    {
-        try {
-            return !context.getWiki().getDocument("XWiki.XWikiServer" + serverName, context)
-                .isNew();
-        }
-        catch (XWikiException e) {
-            return true;
-        }
-    }
-
-    private String getUserTemplate(XWikiContext context) throws XWikiException
-    {
-        return context.getWiki().getDocument("XWiki.XWikiUserTemplate", context).getContent();
-    }
 }
Index: src/main/java/com/xpn/xwiki/plugin/multiwiki/WikiManagerException.java
===================================================================
--- src/main/java/com/xpn/xwiki/plugin/multiwiki/WikiManagerException.java	(révision 4867)
+++ src/main/java/com/xpn/xwiki/plugin/multiwiki/WikiManagerException.java	(copie de travail)
@@ -1,3 +1,22 @@
+/*
+ * Copyright 2006-2007, XpertNet SARL, and individual contributors.
+ *
+ * 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.
+ */
+
 package com.xpn.xwiki.plugin.multiwiki;
 
 import com.xpn.xwiki.plugin.PluginException;
@@ -2,36 +21,48 @@
 
-public class MultiWikiPluginException extends PluginException
+public class WikiManagerException extends PluginException
 {
-    public static final int ERROR_MULTIWIKI_ACCOUNT_ALREADY_EXISTS = 50010;
+    // TODO : move in XWikiException
+    public static final int ERROR_XWIKI_USER_DOES_NOT_EXIST = 50091;
+    
+    ////////
 
-    public static final int ERROR_MULTIWIKI_CANNOT_CREATE_ACCOUNT = 50011;
-
-    public static final int ERROR_MULTIWIKI_SERVER_ALREADY_EXISTS = 50020;
-
-    public static final int ERROR_MULTIWIKI_CANNOT_CREATE_SERVER = 50021;
-
-    public static final int ERROR_MULTIWIKI_CANNOT_CREATE_SERVER_ADMIN = 50022;
-
-    public static final int ERROR_MULTIWIKI_CANNOT_CREATE_USER_SPACE = 50003;
-
-    public static final int ERROR_MULTIWIKI_CANNOT_USER_ALREADY_EXISTS = 50030;
-
-    public static final int ERROR_MULTIWIKI_CANNOT_CANNOT_VALIDATE_ACCOUNT= 50031;
-
+    public static final int MODULE_PLUGIN_MULTIWIKI = 50;
+    
     public static final int ERROR_MULTIWIKI_CANNOT_CREATE_WIKI = 50032;
-
-    public MultiWikiPluginException(int code, String message)
+    
+    public static final int ERROR_MULTIWIKI_SERVER_DOES_NOT_EXIST = 50034;
+    public static final int ERROR_MULTIWIKI_WIKISERVER_ALREADY_EXISTS = 50020;
+    
+    public static final int ERROR_MULTIWIKI_WIKI_NAME_FORBIDDEN = 50035;
+    
+    ////////
+    
+    public WikiManagerException(int code, String message)
     {
-        super(com.xpn.xwiki.plugin.multiwiki.MultiWikiPlugin.class, code, message);
+        super(WikiManagerPlugin.class, code, message);
     }
 
-    public MultiWikiPluginException(int code, String message, Throwable e, Object[] args)
+    public WikiManagerException(int code, String message, Throwable e, Object[] args)
     {
-        super(com.xpn.xwiki.plugin.multiwiki.MultiWikiPlugin.class, code, message, e, args);
+        super(WikiManagerPlugin.class, code, message, e, args);
     }
 
-    public MultiWikiPluginException(int code, String message, Throwable e)
+    public WikiManagerException(int code, String message, Throwable e)
     {
-        super(com.xpn.xwiki.plugin.multiwiki.MultiWikiPlugin.class, code, message, e);
+        super(WikiManagerPlugin.class, code, message, e);
     }
+    
+    ////////
+    
+    private WikiManagerException()
+    {
+        super(WikiManagerPlugin.class, 0, "No error");
+    }
+    
+    private static final WikiManagerException _defaultException = new WikiManagerException();
+    
+    public static WikiManagerException getDefaultException()
+    {
+        return _defaultException;
+    }
 }
Index: src/main/java/com/xpn/xwiki/plugin/multiwiki/MultiWikiPluginInterface.java
===================================================================
--- src/main/java/com/xpn/xwiki/plugin/multiwiki/MultiWikiPluginInterface.java	(révision 4867)
+++ src/main/java/com/xpn/xwiki/plugin/multiwiki/MultiWikiPluginInterface.java	(copie de travail)
@@ -1,44 +0,0 @@
-package com.xpn.xwiki.plugin.multiwiki;
-
-import com.xpn.xwiki.plugin.XWikiPluginInterface;
-import com.xpn.xwiki.XWikiContext;
-import com.xpn.xwiki.XWikiException;
-
-import java.util.Map;
-
-/**
- * Plugin interface for multiwiki operations
- */
-public interface MultiWikiPluginInterface extends XWikiPluginInterface
-{
-    /**
-     * Create a user account with the given params. Allow email validation and username generation
-     *
-     * @parmam context
-     */
-    public void createAccount(Map params, String username, boolean emailValidation,
-        boolean generateUsername, XWikiContext context) throws MultiWikiPluginException;
-
-    /**
-     * Validate the Account with the given username. If the key match, XWikiUsers's parameter active
-     * is set to 1.
-     *
-     * @param xwikiname the username of the account to validate
-     * @param validkey the key to validate the account against
-     * @param withConfirmationEmail indicates if an confirmation email must be sent after
-     * validation
-     * @return true on success (key match), false otherwise
-     */
-    public boolean validateAccount(String xwikiname, String validkey, boolean withConfirmationEmail,
-        XWikiContext context) throws MultiWikiPluginException;
-
-    //public int createServerAdmin(String serverName, String owner, String language, XWikiContext context) throws MultiWikiPluginException;
-
-    public int createWiki(String wikiName, String wikiUrl, String wikiAdmin,
-        String baseWikiName, String description, String language, boolean failOnExist,
-        XWikiContext context) throws MultiWikiPluginException;
-
-    public boolean isAccount(String username, XWikiContext context);
-
-    public boolean isServer(String serverName, XWikiContext context);
-}
Index: src/main/java/com/xpn/xwiki/plugin/multiwiki/WikiManager.java
===================================================================
--- src/main/java/com/xpn/xwiki/plugin/multiwiki/WikiManager.java	(révision 0)
+++ src/main/java/com/xpn/xwiki/plugin/multiwiki/WikiManager.java	(révision 0)
@@ -0,0 +1,419 @@
+/*
+ * Copyright 2006-2007, XpertNet SARL, and individual contributors.
+ *
+ * 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.
+ */
+
+package com.xpn.xwiki.plugin.multiwiki;
+
+import com.xpn.xwiki.XWiki;
+import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.plugin.applicationmanager.ApplicationManagerPlugin;
+import com.xpn.xwiki.plugin.applicationmanager.ApplicationManagerPluginApi;
+import com.xpn.xwiki.plugin.applicationmanager.doc.XWikiApplication;
+import com.xpn.xwiki.plugin.multiwiki.doc.XWikiServer;
+import com.xpn.xwiki.plugin.multiwiki.doc.XWikiServerClass;
+import com.xpn.xwiki.plugin.packaging.DocumentInfo;
+import com.xpn.xwiki.plugin.packaging.PackageAPI;
+import com.xpn.xwiki.util.Util;
+import com.xpn.xwiki.doc.XWikiAttachment;
+import com.xpn.xwiki.doc.XWikiDocument;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class WikiManager
+{
+    protected static final Log LOG = LogFactory.getLog(WikiManager.class);
+
+    // ////////////////////////////////////////////////////////////////////////////
+
+    private WikiManager()
+    {
+    }
+
+    private static WikiManager _instance = null;
+
+    public static WikiManager getInstance()
+    {
+        synchronized (WikiManager.class) {
+            if (_instance == null)
+                _instance = new WikiManager();
+        }
+
+        return _instance;
+    }
+
+    // ////////////////////////////////////////////////////////////////////////////
+    // Utils
+
+    public void saveDocument(String wiki, XWikiDocument doc, XWikiContext context)
+        throws XWikiException
+    {
+        String database = context.getDatabase();
+
+        try {
+            context.setDatabase(wiki);
+            context.getWiki().saveDocument(doc, context);
+        } finally {
+            context.setDatabase(database);
+        }
+    }
+
+    public XWikiDocument getDocument(String wiki, String fullname, XWikiContext context)
+        throws XWikiException
+    {
+        String database = context.getDatabase();
+
+        try {
+            context.setDatabase(wiki);
+            return context.getWiki().getDocument(fullname, context);
+        } finally {
+            context.setDatabase(database);
+        }
+    }
+
+    public List searchDocuments(String wiki, String wheresql, XWikiContext context)
+        throws XWikiException
+    {
+        String database = context.getDatabase();
+
+        try {
+            context.setDatabase(wiki);
+            return context.getWiki().getStore().searchDocuments(wheresql, context);
+        } finally {
+            context.setDatabase(database);
+        }
+    }
+
+    // ////////////////////////////////////////////////////////////////////////////
+    // Wikis management
+
+    private Collection getDocsNameToInclude(String wiki, XWikiContext context)
+        throws XWikiException
+    {
+        // Get applications manger
+        ApplicationManagerPluginApi appmanager = (ApplicationManagerPluginApi) context.getWiki().getPluginApi(ApplicationManagerPlugin.PLUGIN_NAME, context);
+        
+        if (appmanager == null)
+            return null;
+
+        ////////////////////////////////////
+        // Get documents to include
+        
+        String database = context.getDatabase();
+
+        Collection docsToInclude = null;
+
+        try {
+            context.setDatabase(wiki);
+            
+            XWikiApplication rootApp = appmanager.getRootApplication(context);
+
+            if (rootApp != null)
+                docsToInclude = rootApp.getDocsNameToInclude(true, context);
+            else
+                docsToInclude =
+                    XWikiApplication.getDocsNameToInclude(appmanager.getApplicationDocumentList(), true, context);
+        } finally {
+            context.setDatabase(database);
+        }
+
+        return docsToInclude;
+    }
+
+    private void copyWiki(String sourceWiki, String targetWiki, String language,
+        XWikiContext context) throws XWikiException
+    {
+        /* TODO : add included copy support to xwiki-core and use this code
+         * context.getWiki().copyWikiWeb(null, sourceWiki,
+            getDocsNameToInclude(sourceWiki, context), targetWiki, language, true, context);*/
+    	
+    	XWiki xwiki = context.getWiki();
+    	
+    	// Copy all the wiki
+    	xwiki.copyWikiWeb(null, sourceWiki, targetWiki, language, true, context);
+    	
+    	// Replace documents contents to include
+    	String database = context.getDatabase();
+    	try {
+    		context.setDatabase(targetWiki);
+    		
+    		Collection docsNameToInclude = getDocsNameToInclude(sourceWiki, context);
+    		for (Iterator it = docsNameToInclude.iterator(); it.hasNext();) {
+    			String docFullName = (String)it.next();
+    			XWikiDocument targetDoc = xwiki.getDocument(docFullName, context);
+    			
+    			targetDoc.setContent("#includeInContext(\"" + sourceWiki + ":" + docFullName + "\")");
+    		}
+    	} finally {
+    		context.setDatabase(database);
+    	}
+    }
+
+    public XWikiServer createNewWikiFromPackage(XWikiServer userWikiSuperDoc, String packageName,
+        boolean failOnExist, XWikiContext context) throws XWikiException
+    {
+        return createNewWiki(userWikiSuperDoc, failOnExist, null, packageName, context);
+    }
+
+    public XWikiServer createNewWikiFromTemplate(XWikiServer userWikiSuperDoc, String templateWikiName,
+        boolean failOnExist, XWikiContext context) throws XWikiException
+    {
+        return createNewWiki(userWikiSuperDoc, failOnExist, templateWikiName, null, context);
+    }
+    
+    public XWikiServer createNewWiki(XWikiServer userWikiSuperDoc, boolean failOnExist, XWikiContext context) throws XWikiException
+    {
+        return createNewWiki(userWikiSuperDoc, failOnExist, null, null, context);
+    }
+
+    private XWikiServer createNewWiki(XWikiServer userWikiSuperDoc, boolean failOnExist,
+        String templateWikiName, String packageName, XWikiContext context) throws XWikiException
+    {
+        if (userWikiSuperDoc.getOwner().length() == 0)
+        throw new WikiManagerException(WikiManagerException.ERROR_XWIKI_USER_INACTIVE,
+            "Invalid user \"" + userWikiSuperDoc.getOwner() + "\"");
+        
+        XWiki xwiki = context.getWiki();
+        XWikiServerClass wikiClass = XWikiServerClass.getInstance(context);
+
+        String newWikiName = userWikiSuperDoc.getWikiName();
+        
+        String database = context.getDatabase();
+        
+        try {
+            // Return to root database
+            context.setDatabase(context.getMainXWiki());
+
+            XWikiDocument userdoc =
+                getDocument(xwiki.getDatabase(), userWikiSuperDoc.getOwner(), context);
+
+            // User does not exist
+            if (userdoc.isNew()) {
+                if (LOG.isErrorEnabled())
+                    LOG.error("Wiki creation (" + userWikiSuperDoc + ") failed: "
+                        + "user does not exist");
+                throw new WikiManagerException(WikiManagerException.ERROR_XWIKI_USER_DOES_NOT_EXIST,
+                    "User \"" + userWikiSuperDoc.getOwner() + "\" does not exist");
+            }
+
+            // User is not active
+            if (!(userdoc.getIntValue("XWiki.XWikiUsers", "active") == 1)) {
+                if (LOG.isErrorEnabled())
+                    LOG.error("Wiki creation (" + userWikiSuperDoc + ") failed: "
+                        + "user is not active");
+                throw new WikiManagerException(WikiManagerException.ERROR_XWIKI_USER_INACTIVE,
+                    "User \"" + userWikiSuperDoc.getOwner() + "\" is not active");
+            }
+
+            // Wiki name forbidden
+            String wikiForbiddenList = xwiki.Param("xwiki.virtual.reserved_wikis");
+            if (Util.contains(newWikiName, wikiForbiddenList, ", ")) {
+                if (LOG.isErrorEnabled())
+                    LOG.error("Wiki creation (" + userWikiSuperDoc + ") failed: "
+                        + "wiki name is forbidden");
+                throw new WikiManagerException(WikiManagerException.ERROR_MULTIWIKI_WIKI_NAME_FORBIDDEN,
+                    "Wiki name \"" + newWikiName + "\" forbidden");
+            }
+
+            XWikiServer wikiSuperDocToSave;
+
+            // If modify existing document
+            if (!userWikiSuperDoc.isFromCache()) {
+                // Verify is server page already exist
+                XWikiDocument docToSave =
+                    getDocument(context.getMainXWiki(), userWikiSuperDoc.getFullName(), context);
+
+                if (!docToSave.isNew() && wikiClass.isInstance(docToSave, context)) {
+                    // If we are not allowed to continue if server page already exists
+                    if (failOnExist) {
+                        if (LOG.isErrorEnabled())
+                            LOG.error("Wiki creation (" + userWikiSuperDoc + ") failed: "
+                                + "wiki server page already exists");
+                        throw new WikiManagerException(WikiManagerException.ERROR_MULTIWIKI_WIKISERVER_ALREADY_EXISTS,
+                            "Wiki \"" + userWikiSuperDoc.getFullName() + "\" document already exist");
+                    } else if (LOG.isWarnEnabled())
+                        LOG.warn("Wiki creation (" + userWikiSuperDoc + ") failed: "
+                            + "wiki server page already exists");
+
+                }
+
+                wikiSuperDocToSave = (XWikiServer)XWikiServerClass.getInstance(context).newSuperDocument(docToSave, context);
+
+                // clear entry in virtual wiki cache
+                if (!wikiSuperDocToSave.getServer().equals(userWikiSuperDoc.getServer()))
+                    xwiki.getVirtualWikiMap().flushEntry(userWikiSuperDoc.getServer());
+
+                wikiSuperDocToSave.mergeBaseObject(userWikiSuperDoc);
+            } else
+                wikiSuperDocToSave = userWikiSuperDoc;
+
+            // Create wiki database
+            try {
+                xwiki.getStore().createWiki(newWikiName, context);
+            } catch (XWikiException e) {
+                if (LOG.isErrorEnabled()) {
+                    if (e.getCode() == 10010)
+                        LOG.error("Wiki creation (" + userWikiSuperDoc + ") failed: "
+                            + "wiki database already exists");
+                    else if (e.getCode() == 10011)
+                        LOG.error("Wiki creation (" + userWikiSuperDoc + ") failed: "
+                            + "wiki database creation failed");
+                    else
+                        LOG.error("Wiki creation (" + userWikiSuperDoc + ") failed: "
+                            + "wiki database creation threw exception", e);
+                }
+            } catch (Exception e) {
+                LOG.error("Wiki creation (" + userWikiSuperDoc + ") failed: "
+                    + "wiki database creation threw exception", e);
+            }
+
+            try {
+                xwiki.updateDatabase(newWikiName, true, false, context);
+            } catch (Exception e) {
+                throw new WikiManagerException(WikiManagerException.ERROR_MULTIWIKI_WIKISERVER_ALREADY_EXISTS,
+                    "Wiki \"" + newWikiName + "\" database update failed",
+                    e);
+            }
+
+            String language = userWikiSuperDoc.getLanguage();
+            if (language.length() == 0)
+                language = null;
+
+            // Copy base wiki
+            if (templateWikiName != null) {
+                copyWiki(templateWikiName, newWikiName, language, context);
+            }
+            if (packageName != null) {
+                // Prepare to import
+                XWikiDocument doc = context.getDoc();
+
+                XWikiAttachment packFile = doc.getAttachment(packageName);
+
+                if (packFile == null)
+                    throw new WikiManagerException(XWikiException.ERROR_XWIKI_UNKNOWN,
+                        "Package " + packageName + " does not exists.");
+
+                // Change database
+                context.setDatabase(newWikiName);
+
+                // Import
+                PackageAPI importer =
+                    ((PackageAPI) context.getWiki().getPluginApi("package", context));
+
+                try {
+                    importer.Import(packFile.getContent(context));
+                } catch (IOException e) {
+                    throw new WikiManagerException(XWikiException.ERROR_XWIKI_UNKNOWN,
+                        "Fail to import package " + packageName,
+                        e);
+                }
+
+                if (importer.install() == DocumentInfo.INSTALL_IMPOSSIBLE)
+                    throw new WikiManagerException(XWikiException.ERROR_XWIKI_UNKNOWN,
+                        "Fail to import package " + packageName);
+            }
+
+            // Create user page in his wiki
+            // Let's not create it anymore.. this makes the creator loose super admin rights on
+            // his wiki
+            //xwiki.copyDocument(userWikiSuperDoc.getOwner(), database, newWikiName, language, context);
+
+            // Return to root database
+            context.setDatabase(context.getMainXWiki());
+
+            wikiSuperDocToSave.save();
+            
+            return wikiSuperDocToSave;
+        } finally {
+            context.setDatabase(database);
+        }
+    }
+
+    public void deleteWiki(String wikiNameToDelete, XWikiContext context) throws XWikiException
+    {
+        XWikiServer doc = getWiki(wikiNameToDelete, context, true);
+
+        doc.delete(context);
+    }
+
+    public XWikiServer getWiki(String wikiName, XWikiContext context, boolean validate)
+        throws XWikiException
+    {
+        return XWikiServerClass.getInstance(context).getWikiServer(wikiName, context, validate);
+    }
+
+    public List getWikiDocumentList(XWikiContext context) throws XWikiException
+    {
+        return XWikiServerClass.getInstance(context).searchItemDocuments(context);
+    }
+    
+    public List getWikiList(XWikiContext context) throws XWikiException
+    {
+        List documentList = getWikiDocumentList(context);
+
+        List applicationList = new ArrayList(documentList.size());
+
+        for (Iterator it = documentList.iterator(); it.hasNext();) {
+            applicationList.add(XWikiServerClass.getInstance(context).newSuperDocument((XWikiDocument) it.next(), context));
+        }
+
+        return applicationList;
+    }
+
+    public boolean isWikiExist(String wikiName, XWikiContext context)
+    {
+        try {
+            return getWiki(wikiName, context, true) != null;
+        } catch (XWikiException e) {
+            return false;
+        }
+    }
+
+    // ////////////////////////////////////////////////////////////////////////////
+    // Template management
+
+    public XWikiServer getWikiTemplate(String wikiName, XWikiContext context, boolean validate)
+        throws XWikiException
+    {
+        return XWikiServerClass.getInstance(context).getWikiTemplateServer(wikiName, context, validate);
+    }
+
+    public List getWikiTemplateList(XWikiContext context) throws XWikiException
+    {
+        return XWikiServerClass.getInstance(context).searchItemDocumentsByField(
+            XWikiServerClass.FIELD_visibility, XWikiServerClass.FIELDL_visibility_template,
+            "StringProperty", context);
+    }
+
+    public void createWikiTemplate(XWikiServer wikiSuperDocument, String packageName,
+        XWikiContext context) throws XWikiException
+    {
+        wikiSuperDocument.setVisibility(XWikiServerClass.FIELDL_visibility_template);
+
+        // Create empty wiki
+        WikiManager.getInstance().createNewWikiFromPackage(wikiSuperDocument, packageName, false,
+            context);
+    }
+}

Modification de propriétés sur src/main/java/com/xpn/xwiki/plugin/multiwiki/WikiManager.java
___________________________________________________________________
Nom : svn:executable
   + *

Index: pom.xml
===================================================================
--- pom.xml	(révision 4867)
+++ pom.xml	(copie de travail)
@@ -2,8 +2,7 @@
 
 <!--
  *
- * Copyright 2006-2007, XpertNet SARL, and individual contributors as indicated
- * by the contributors.txt.
+ * Copyright 2006-2007, XpertNet SARL, and individual contributors.
  *
  * This is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as
@@ -22,30 +21,34 @@
  *
 -->
 
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-  <modelVersion>4.0.0</modelVersion>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
   <parent>
+    <artifactId>xwiki-plugins</artifactId>
     <groupId>com.xpn.xwiki.platform.plugins</groupId>
-    <artifactId>xwiki-plugins</artifactId>
     <version>1-SNAPSHOT</version>
   </parent>
+  <modelVersion>4.0.0</modelVersion>
   <artifactId>xwiki-plugin-multiwiki</artifactId>
-  <version>1.0-SNAPSHOT</version>
   <name>XWiki Platform - Plugins - Multiwiki</name>
-  <packaging>jar</packaging>
+  <version>0.1-SNAPSHOT</version>
   <description>XWiki Platform - Plugins - Multiwiki</description>
   <dependencies>
-
-    <!-- Standard dependencies found in the main Maven remote repository -->
-
     <dependency>
       <groupId>com.xpn.xwiki.platform</groupId>
       <artifactId>xwiki-core</artifactId>
-      <version>1.2-SNAPSHOT</version>
+      <version>1.1-SNAPSHOT</version>
     </dependency>
-
+     <dependency>
+      <groupId>com.xpn.xwiki.platform.plugins</groupId>
+      <artifactId>xwiki-plugin-applicationmanager</artifactId>
+      <version>0.1-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>jmock</groupId>
+      <artifactId>jmock-cglib</artifactId>
+      <version>1.1.0</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
+</project>
 
-</project>
-        
