Author: tmortagne
Date: 2008-01-24 11:01:26 +0100 (Thu, 24 Jan 2008)
New Revision: 7037

Modified:
   
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/wikimanager/WikiManagerPluginApi.java
Log:
XAWM-50: Trying to create a wiki without wiki name should return error

Modified: 
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/wikimanager/WikiManagerPluginApi.java
===================================================================
--- 
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/wikimanager/WikiManagerPluginApi.java
    2008-01-24 10:01:23 UTC (rev 7036)
+++ 
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/wikimanager/WikiManagerPluginApi.java
    2008-01-24 10:01:26 UTC (rev 7037)
@@ -66,7 +66,7 @@
      * The default WikiManager managed exception.
      */
     private XWikiExceptionApi defaultException;
-    
+
     /**
      * API tool to be able to make and merge multi wikis search queries.
      */
@@ -76,7 +76,7 @@
      * The plugin internationalization service.
      */
     private XWikiPluginMessageTool messageTool;
-   
+
     /**
      * Create an instance of the Wiki Manager plugin user api.
      * 
@@ -94,7 +94,7 @@
         Locale locale = (Locale) context.get("locale");
         this.messageTool = new WikiManagerMessageTool(locale, plugin, context);
         context.put(WikiManager.MESSAGETOOL_CONTEXT_KEY, this.messageTool);
-        
+
         searchApi = plugin.getGlobalSearchApiPlugin(context);
     }
 
@@ -113,7 +113,7 @@
     {
         return this.messageTool;
     }
-    
+
     /**
      * @return the GlobalSearch plugin api.
      */
@@ -168,29 +168,26 @@
 
         int returncode = XWikiExceptionApi.ERROR_NOERROR;
 
-        wikiXObjectDocument.setWikiName(wikiname);
+        try {
+            if (wikiname == null || wikiname.trim().equals("")) {
+                throw new 
WikiManagerException(WikiManagerException.ERROR_WM_WIKINAMEFORBIDDEN,
+                    
messageTool.get(WikiManagerMessageTool.ERROR_WIKINAMEFORBIDDEN, wikiname));
+            }
 
-        String realTemplateWikiName =
-            templateWiki == null || templateWiki.trim().length() == 0 ? null : 
templateWiki;
+            wikiXObjectDocument.setWikiName(wikiname);
 
-        String realPkgName = pkgName == null || pkgName.trim().length() == 0 ? 
null : pkgName;
+            String realTemplateWikiName =
+                templateWiki == null || templateWiki.trim().length() == 0 ? 
null : templateWiki;
 
-        try {
-            String comment;
+            String realPkgName = pkgName == null || pkgName.trim().length() == 
0 ? null : pkgName;
 
-            if (realTemplateWikiName != null) {
-                comment = 
WikiManagerMessageTool.COMMENT_CREATEWIKIFROMTEMPLATE;
-            } else if (realPkgName != null) {
-                comment = WikiManagerMessageTool.COMMENT_CREATEWIKIFROMPACKAGE;
-            } else {
-                comment = WikiManagerMessageTool.COMMENT_CREATEEMPTYWIKI;
-            }
+            String comment = WikiManagerMessageTool.COMMENT_CREATEEMPTYWIKI;
 
             WikiManager.getInstance().createNewWiki(wikiXObjectDocument, 
failOnExist,
                 realTemplateWikiName, realPkgName, comment, this.context);
         } catch (WikiManagerException e) {
-            LOG.error(messageTool.get(WikiManagerMessageTool.LOG_WIKICREATION, 
wikiXObjectDocument
-                .toString()), e);
+            LOG.error(messageTool.get(WikiManagerMessageTool.LOG_WIKICREATION,
+                wikiXObjectDocument.toString()), e);
 
             this.context.put(CONTEXT_LASTERRORCODE, new Integer(e.getCode()));
             this.context.put(CONTEXT_LASTEXCEPTION, new XWikiExceptionApi(e, 
this.context));
@@ -281,7 +278,7 @@
 
         return doc;
     }
-    
+
     /**
      * @return the list of all [EMAIL PROTECTED] Wiki}.
      * @throws XWikiException error when getting wiki documents descriptors.
@@ -558,8 +555,8 @@
                 
this.messageTool.get(WikiManagerMessageTool.COMMENT_CREATEWIKITEMPLATE,
                     new String[] {templateName, packageName}), this.context);
         } catch (WikiManagerException e) {
-            LOG.error(messageTool.get(WikiManagerMessageTool.LOG_WIKICREATION, 
wikiXObjectDocument
-                .toString()), e);
+            LOG.error(messageTool.get(WikiManagerMessageTool.LOG_WIKICREATION,
+                wikiXObjectDocument.toString()), e);
 
             this.context.put(CONTEXT_LASTERRORCODE, new Integer(e.getCode()));
             this.context.put(CONTEXT_LASTEXCEPTION, new XWikiExceptionApi(e, 
this.context));

_______________________________________________
notifications mailing list
notifications@xwiki.org
http://lists.xwiki.org/mailman/listinfo/notifications

Reply via email to