diff --git a/xwiki-platform-core/xwiki-platform-wiki-manager/xwiki-platform-wiki-manager-api/src/main/java/com/xpn/xwiki/plugin/wikimanager/WikiManager.java b/xwiki-platform-core/xwiki-platform-wiki-manager/xwiki-platform-wiki-manager-api/src/main/java/com/xpn/xwiki/plugin/wikimanager/WikiManager.java index 4be0c4b..54d3902 100644 --- a/xwiki-platform-core/xwiki-platform-wiki-manager/xwiki-platform-wiki-manager-api/src/main/java/com/xpn/xwiki/plugin/wikimanager/WikiManager.java +++ b/xwiki-platform-core/xwiki-platform-wiki-manager/xwiki-platform-wiki-manager-api/src/main/java/com/xpn/xwiki/plugin/wikimanager/WikiManager.java @@ -49,7 +49,7 @@ /** * Hidden toolkit use by the plugin API that make all the plugins actions. - * + * * @version $Id$ */ public final class WikiManager @@ -82,7 +82,7 @@ public WikiManager(XWikiPluginMessageTool messageTool) /** * Get the {@link XWikiPluginMessageTool} to use with WikiManager. - * + * * @param context the XWiki context. * @return a translated strings manager. */ @@ -96,7 +96,7 @@ public XWikiPluginMessageTool getMessageTool(XWikiContext context) /** * Encapsulate {@link com.xpn.xwiki.XWiki#getDocument(String, XWikiContext)} adding wiki switch. - * + * * @param wikiName the name of the wiki where to get the document. * @param fullname the full name of the document to get. * @param context the XWiki context. @@ -120,7 +120,7 @@ public XWikiDocument getDocument(String wikiName, String fullname, XWikiContext /** * Encapsulate {@link com.xpn.xwiki.store.XWikiStoreInterface#searchDocuments(String, XWikiContext)} adding wiki * switch. - * + * * @param wikiName the name of the wiki where to search for documents. * @param wheresql the conditions to add to HQL request. * @param context the XWiki context. @@ -182,7 +182,7 @@ public boolean canDeleteWiki(XWikiContext context) /** * Get {@link Wiki} described by provided document. - * + * * @param document the wiki document descriptor. * @param context the XWiki context. * @return the {@link Wiki} object. @@ -195,7 +195,7 @@ public Wiki getWikiFromDocument(XWikiDocument document, XWikiContext context) th /** * Get {@link Wiki} with provided name. - * + * * @param wikiName the name of the wiki. * @param context the XWiki context. * @return the {@link Wiki} object. @@ -209,7 +209,7 @@ public Wiki getWikiFromName(String wikiName, XWikiContext context) throws XWikiE /** * Get {@link Wiki} described by document with provided full name. - * + * * @param documentFullName the full name of the wiki document descriptor. * @param context the XWiki context. * @return the {@link Wiki} object. @@ -222,7 +222,7 @@ public Wiki getWikiFromDocumentName(String documentFullName, XWikiContext contex /** * Get all {@link Wiki}. - * + * * @param context the XWiki context. * @return the list of all {@link Wiki}. * @throws XWikiException error when getting wikis documents descriptors. @@ -255,7 +255,7 @@ public Wiki getWikiFromDocumentName(String documentFullName, XWikiContext contex /** * Get the documents for which copied document content will be replace by an #includeInContext(SourceDocument) or * #includeTopic(SourceDocument) macro call. - * + * * @param wiki the name of the wiki where to find the list of documents. * @param context the XWiki context. * @return a pair of list of documents names to include and list of documents names to link. @@ -300,7 +300,7 @@ public Wiki getWikiFromDocumentName(String documentFullName, XWikiContext contex /** * Create a new virtual wiki. The new wiki is initialized with provided xar package. - * + * * @param userWikiSuperDoc a wiki descriptor document from which the new wiki descriptor document will be created. * @param packageName the name of the attached XAR file to import in the new wiki. * @param failOnExist if true throw exception when wiki already exist. If false overwrite existing wiki. @@ -330,9 +330,9 @@ public XWikiServer createNewWikiFromPackage(XWikiServer userWikiSuperDoc, String /** * Create a new virtual wiki. The new wiki is a copy of provided existing wiki. - * + * * @param userWikiSuperDoc a wiki descriptor document from which the new wiki descriptor document will be created. - * @param templateWikiName the of the wiki from where to copy document to the new wiki. + * @param templateWikiName the name of the wiki from where to copy document to the new wiki. * @param failOnExist if true throw exception when wiki already exist. If false overwrite existing wiki. * @param comment the comment to use when saving descriptor document. * @param context the XWiki context. @@ -360,7 +360,7 @@ public XWikiServer createNewWikiFromTemplate(XWikiServer userWikiSuperDoc, Strin /** * Create a new empty virtual wiki. - * + * * @param userWikiSuperDoc a wiki descriptor document from which the new wiki descriptor document will be created. * @param failOnExist if true throw exception when wiki already exist. If false overwrite existing wiki. * @param comment the comment to use when saving descriptor document. @@ -387,7 +387,7 @@ public XWikiServer createNewWiki(XWikiServer userWikiSuperDoc, boolean failOnExi /** * Create new wiki. - * + * * @param userWikiSuperDoc a wiki descriptor document from which the new wiki descriptor document will be created. * @param failOnExist if true throw exception when wiki already exist. If false overwrite existing wiki. * @param templateWikiName the name of the wiki from where to copy document to the new wiki. @@ -492,7 +492,7 @@ public XWikiServer createNewWiki(XWikiServer userWikiSuperDoc, boolean failOnExi /** * Update or create new wiki description document without saving it. - * + * * @param userWikiSuperDoc a wiki descriptor document from which the new wiki descriptor document will be created. * @param failOnExist if true throw exception when wiki already exist. If false overwrite existing wiki. * @param context the XWiki context. @@ -546,7 +546,7 @@ private XWikiServer getWikiDescriptorToSave(XWikiServer userWikiSuperDoc, boolea /** * Create and init new database/schema. - * + * * @param targetWiki the name of the new database/schema. * @param context the Xwiki context. * @param initClasses indicate if standard classes should be initalized @@ -585,7 +585,7 @@ private void createWikiDatabase(String targetWiki, XWikiContext context, boolean /** * Delete an existing wiki. - * + * * @param wikiNameToDelete the name of the wiki to delete. * @param deleteDatabase if true wiki's database is also removed. * @param context the XWiki context. @@ -610,7 +610,7 @@ public void deleteWiki(String wikiNameToDelete, boolean deleteDatabase, XWikiCon /** * Delete an existing wiki alias. If it's the last alias it delete the wiki. - * + * * @param wikiNameToDelete the name of the wiki to delete. * @param objectId the id of the XWiki object included in the document to manage. * @param context the XWiki context. @@ -635,7 +635,7 @@ public void deleteWikiAlias(String wikiNameToDelete, int objectId, XWikiContext /** * Get the wiki descriptor document. - * + * * @param wikiName the name of the wiki. * @param objectId the id of the XWiki object included in the document to manage. * @param validate when wiki descriptor document does not exist : @@ -655,7 +655,7 @@ public XWikiServer getWikiAlias(String wikiName, int objectId, boolean validate, /** * Get all the wikis descriptors documents. - * + * * @param context the XWiki context. * @return a list of XWikiServer. * @throws XWikiException error when: @@ -671,7 +671,7 @@ public XWikiServer getWikiAlias(String wikiName, int objectId, boolean validate, /** * Indicate of wiki descriptor document exist. - * + * * @param wikiName the name of the wiki. * @param objectId the id of the XWiki object included in the document to manage. * @param context the XWiki context. @@ -693,13 +693,13 @@ public boolean isWikiAliasExist(String wikiName, int objectId, XWikiContext cont * Get template wiki descriptor document. *

* A template wiki is a wiki which the XWiki.XWikiServerClass "visibility" field is set to "template". - * + * * @param wikiName the name of the template wiki. * @param objectId the id of the XWiki object included in the document to manage. * @param context the XWiki context. * @param validate when wiki descriptor document does not exist : *

* @return a wiki descriptor document. @@ -719,7 +719,7 @@ public XWikiServer getWikiTemplateAlias(String wikiName, int objectId, XWikiCont * Get all the templates wikis descriptors documents. *

* A template wiki is a wiki which the XWiki.XWikiServerClass "visibility" field is set to "template". - * + * * @param context the XWiki context. * @return a list of {@link XWikiServer}. * @throws XWikiException eeor when: @@ -738,7 +738,7 @@ public XWikiServer getWikiTemplateAlias(String wikiName, int objectId, XWikiCont * Create a template wiki. The new template wiki is initialized with provided xar package. *

* A template wiki is a wiki which the XWiki.XWikiServerClass "visibility" field is set to "template". - * + * * @param wikiXObjectDocument a wiki descriptor document from which the new template wiki descriptor document will * be created. * @param packageName the name of the attached XAR file to import in the new template wiki. diff --git a/xwiki-platform-core/xwiki-platform-workspace/pom.xml b/xwiki-platform-core/xwiki-platform-workspace/pom.xml index c78ecce..9b99263 100644 --- a/xwiki-platform-core/xwiki-platform-workspace/pom.xml +++ b/xwiki-platform-core/xwiki-platform-workspace/pom.xml @@ -110,4 +110,4 @@ - \ No newline at end of file + diff --git a/xwiki-platform-core/xwiki-platform-workspace/xwiki-platform-workspace-api/pom.xml b/xwiki-platform-core/xwiki-platform-workspace/xwiki-platform-workspace-api/pom.xml index ccbdbb1..5ef5348 100644 --- a/xwiki-platform-core/xwiki-platform-workspace/xwiki-platform-workspace-api/pom.xml +++ b/xwiki-platform-core/xwiki-platform-workspace/xwiki-platform-workspace-api/pom.xml @@ -59,6 +59,17 @@ + + + org.codehaus.mojo + clirr-maven-plugin + + + ** + + + + diff --git a/xwiki-platform-core/xwiki-platform-workspace/xwiki-platform-workspace-api/src/main/java/org/xwiki/workspace/WorkspaceManager.java b/xwiki-platform-core/xwiki-platform-workspace/xwiki-platform-workspace-api/src/main/java/org/xwiki/workspace/WorkspaceManager.java index bf03790..616382a 100644 --- a/xwiki-platform-core/xwiki-platform-workspace/xwiki-platform-workspace-api/src/main/java/org/xwiki/workspace/WorkspaceManager.java +++ b/xwiki-platform-core/xwiki-platform-workspace/xwiki-platform-workspace-api/src/main/java/org/xwiki/workspace/WorkspaceManager.java @@ -27,7 +27,7 @@ /** * Component in charge of creating and managing workspaces. - * + * * @version $Id$ */ @ComponentRole @@ -56,7 +56,7 @@ /** * Creates a new workspace from a wiki descriptor. - * + * * @param workspaceName name of the new workspace * @param newWikiXObjectDocument a new (in-memory) wiki descriptor document from which the new wiki descriptor * document will be created. This method will take care of saving the document. @@ -67,6 +67,19 @@ XWikiServer createWorkspace(String workspaceName, XWikiServer newWikiXObjectDocu throws WorkspaceException; /** + * Creates a new workspace from a wiki descriptor. + * + * @param workspaceName name of the new workspace + * @param newWikiXObjectDocument a new (in-memory) wiki descriptor document from which the new wiki descriptor + * document will be created. This method will take care of saving the document. + * @param templateWikiName the name of the wiki from where to copy document to the new wiki. + * @return {@link XWikiServer} descriptor for the newly created workspace + * @throws WorkspaceException if problems occur + */ + XWikiServer createWorkspace(String workspaceName, XWikiServer newWikiXObjectDocument, String templateWikiName) + throws WorkspaceException; + + /** * @param workspaceName name of the workspace to delete * @throws WorkspaceException if problems occur */ @@ -82,7 +95,7 @@ XWikiServer createWorkspace(String workspaceName, XWikiServer newWikiXObjectDocu /** * Retrieves a workspace by name. - * + * * @param workspaceName name (ID) of the workspace * @return the requested workspace or null if it does not exist * @throws WorkspaceException if problems occur @@ -92,7 +105,7 @@ XWikiServer createWorkspace(String workspaceName, XWikiServer newWikiXObjectDocu /** * Get the list of all workspaces. It basically gets all wikis that have a {@code WorkspaceManager.WorkspaceClass} * object in their {@code XWikiServer} page. - * + * * @return list of available workspaces * @throws WorkspaceException if problems occur */ diff --git a/xwiki-platform-core/xwiki-platform-workspace/xwiki-platform-workspace-api/src/main/java/org/xwiki/workspace/internal/DefaultWorkspaceManager.java b/xwiki-platform-core/xwiki-platform-workspace/xwiki-platform-workspace-api/src/main/java/org/xwiki/workspace/internal/DefaultWorkspaceManager.java index 4e9ccbe..96d2ff0 100644 --- a/xwiki-platform-core/xwiki-platform-workspace/xwiki-platform-workspace-api/src/main/java/org/xwiki/workspace/internal/DefaultWorkspaceManager.java +++ b/xwiki-platform-core/xwiki-platform-workspace/xwiki-platform-workspace-api/src/main/java/org/xwiki/workspace/internal/DefaultWorkspaceManager.java @@ -56,7 +56,7 @@ /** * Implementation of a WorkspaceManager component. - * + * * @version $Id$ */ @Component @@ -124,7 +124,7 @@ public void initialize() throws InitializationException * Note: This is a method instead of a cached field because the wiki manager plugin API is initialized, at every * usage, with the current context. Caching the plugin API instance would mean caching the context and that caused * problems. - * + * * @return the wrapped wiki manager plugin */ private WikiManagerPluginApi getWikiManager() @@ -239,6 +239,13 @@ private XWikiContext getXWikiContext() public XWikiServer createWorkspace(String workspaceName, XWikiServer newWikiXObjectDocument) throws WorkspaceException { + return this.createWorkspace(workspaceName, newWikiXObjectDocument, "workspacetemplate"); + } + + @Override + public XWikiServer createWorkspace(String workspaceName, XWikiServer newWikiXObjectDocument, String templateWikiName) + throws WorkspaceException + { XWikiContext deprecatedContext = getXWikiContext(); String comment = String.format("Created new workspace '%s'", workspaceName); @@ -249,7 +256,7 @@ public XWikiServer createWorkspace(String workspaceName, XWikiServer newWikiXObj newWikiXObjectDocument.setWikiName(workspaceName); result = - this.wikiManagerInternal.createNewWikiFromTemplate(newWikiXObjectDocument, "workspacetemplate", true, + this.wikiManagerInternal.createNewWikiFromTemplate(newWikiXObjectDocument, templateWikiName, true, comment, deprecatedContext); } catch (Exception e) { logAndThrowException(String.format("Failed to create workspace [%s]", workspaceName), e); @@ -284,7 +291,7 @@ public XWikiServer createWorkspace(String workspaceName, XWikiServer newWikiXObj /** * Initialize a newly created workspace by explicitly adding its owner in the XWikiAllGroup and XWikiAdminGroup * local groups. - * + * * @param workspaceName the workspace to initialize * @param workspaceOwner the owner user name to be used in the process * @param comment the comment used when saving the group documents @@ -444,7 +451,7 @@ public void editWorkspace(String workspaceName, XWikiServer modifiedWikiXObjectD /** * Update the contents of an object using the contents of another. Objects must be of the same class. - * + * * @param source object that provides the new contents to update with * @param destination object that is to be updated * @throws WorkspaceException if objects' classes differ @@ -562,7 +569,7 @@ private BaseObject getWorkspaceObject(Wiki wikiDocument) throws Exception /** * Utility method to log and throw a {@link WorkspaceException} wrapping a given exception. - * + * * @param message the error message to log * @param e the exception to log and wrap in the thrown {@link WorkspaceException} * @throws WorkspaceException when called diff --git a/xwiki-platform-core/xwiki-platform-workspace/xwiki-platform-workspace-api/src/main/java/org/xwiki/workspace/internal/WorkspaceManagerScriptService.java b/xwiki-platform-core/xwiki-platform-workspace/xwiki-platform-workspace-api/src/main/java/org/xwiki/workspace/internal/WorkspaceManagerScriptService.java index eae0349..ed35ee2 100644 --- a/xwiki-platform-core/xwiki-platform-workspace/xwiki-platform-workspace-api/src/main/java/org/xwiki/workspace/internal/WorkspaceManagerScriptService.java +++ b/xwiki-platform-core/xwiki-platform-workspace/xwiki-platform-workspace-api/src/main/java/org/xwiki/workspace/internal/WorkspaceManagerScriptService.java @@ -41,7 +41,7 @@ /** * Makes the WorkspaceManager API available to scripting. - * + * * @version $Id$ */ @Component @@ -107,7 +107,7 @@ public boolean canDeleteWorkspace(String userName, String workspaceName) /** * Creates a new workspace from a wiki descriptor. - * + * * @param workspaceName name of the new workspace * @param newWikiXObjectDocument a new (in-memory) wiki descriptor document from which the new wiki descriptor * document will be created. This method will take care of saving the document. @@ -115,6 +115,20 @@ public boolean canDeleteWorkspace(String userName, String workspaceName) */ public void createWorkspace(String workspaceName, XWikiServer newWikiXObjectDocument) { + createWorkspace(workspaceName, newWikiXObjectDocument, "workspacetemplate"); + } + + /** + * Creates a new workspace from a wiki descriptor. + * + * @param workspaceName name of the new workspace + * @param newWikiXObjectDocument a new (in-memory) wiki descriptor document from which the new wiki descriptor + * document will be created. This method will take care of saving the document. + * @param templateWikiName the name of the wiki from where to copy document to the new wiki. + * @see {@link #getLastException()} to check for abnormal method termination + */ + public void createWorkspace(String workspaceName, XWikiServer newWikiXObjectDocument, String templateWikiName) + { clearException(); try { @@ -133,7 +147,7 @@ public void createWorkspace(String workspaceName, XWikiServer newWikiXObjectDocu throw new WorkspaceException(String.format("Workspace name [%s] is invalid", workspaceName)); } - this.workspaceManager.createWorkspace(workspaceName, newWikiXObjectDocument); + this.workspaceManager.createWorkspace(workspaceName, newWikiXObjectDocument, templateWikiName); } catch (Exception e) { error(String.format("Failed to create workspace [%s]", workspaceName), e); } @@ -227,7 +241,7 @@ private XWikiContext getXWikiContext() /** * Log exception and store it in the context. - * + * * @param errorMessage error message * @param e the caught exception * @see #CONTEXT_LASTEXCEPTION @@ -249,7 +263,7 @@ private void error(String errorMessage, Exception e) /** * Log exception and store it in the context. The logged message is the exception's message. This allows the * underlying component to define it's messages and removes duplication. - * + * * @param e the caught exception * @see #CONTEXT_LASTEXCEPTION */ @@ -276,7 +290,7 @@ public Exception getLastException() /** * Retrieves a workspace by name. - * + * * @param workspaceId name (ID) of the workspace * @return the requested workspace or null if it does not exist * @see {@link #getLastException()} to check for abnormal method termination @@ -296,7 +310,7 @@ public Workspace getWorkspace(String workspaceId) /** * Get the list of all workspaces. It basically gets all wikis that have a {@code WorkspaceManager.WorkspaceClass} * object in their {@code XWikiServer} page. - * + * * @return list of available workspaces * @see #CONTEXT_LASTEXCEPTION to check for abnormal method termination */ diff --git a/xwiki-platform-core/xwiki-platform-workspace/xwiki-platform-workspace-ui/src/main/resources/WorkspaceManager/CreateNewWorkspace.xml b/xwiki-platform-core/xwiki-platform-workspace/xwiki-platform-workspace-ui/src/main/resources/WorkspaceManager/CreateNewWorkspace.xml index 8242bb5..8206aa3 100644 --- a/xwiki-platform-core/xwiki-platform-workspace/xwiki-platform-workspace-ui/src/main/resources/WorkspaceManager/CreateNewWorkspace.xml +++ b/xwiki-platform-core/xwiki-platform-workspace/xwiki-platform-workspace-ui/src/main/resources/WorkspaceManager/CreateNewWorkspace.xml @@ -348,7 +348,10 @@ ############################################################################# ## #if ($action && $action == 'create') - #set ($discard = $WorkspaceManager.createWorkspace($wikiname, $wikidocument)) + ########## JIRA http://jira.xwikisas.com/browse/AFPMIG-6 ############# + #set ($templateName = "$!request.template") + #set ($discard = $WorkspaceManager.createWorkspace($wikiname, $wikidocument, $templateName)) + ########## END JIRA http://jira.xwikisas.com/browse/AFPMIG-6 ############# ## #if ("$!WorkspaceManager.lastException" == '') ## Add members. @@ -401,6 +404,28 @@ </dt> <dd><input size='60' id='XWiki.XWikiServerClass_0_wikiprettyname' name='XWiki.XWikiServerClass_0_wikiprettyname' type='text' onchange='prettyNameChanged();' onkeyup='prettyNameChanged();' #if(!$isInstallComplete)disabled='disabled'#{end} /></dd> </dl> + + ########### JIRA http://jira.xwikisas.com/browse/AFPMIG-6 ############# + <dl> + <dt> + <label for='template'>Template</label> + <span class='xHint'>$msg.get('workspacemanager.doc.createwiki.desc.template')</span> + </dt> + <dd> + <select name='template'> + #set($wikiList = $WikiManager.getAllWikis()) + #foreach($wiki in $wikiList) + #set($wikiAliasList = $wiki.wikiAliasList) + #set($firstalias = $wikiAliasList.get(0)) + #if($firstalias.isWikiTemplate()) + #set($name = "#if($firstalias.wikiPrettyName && $firstalias.wikiPrettyName.trim().length() > 0) $firstalias.wikiPrettyName ($wiki.wikiName) #else $wiki.wikiName #end") + <option value="$wiki.getWikiName()" #if($docName=='XWiki.XWikiServerWorkspacetemplate') selected="selected" #end >$name</option> + #end + #end + </select> + </dd> + </dl> + ########### END JIRA http://jira.xwikisas.com/browse/AFPMIG-6 ######### <dl> <dt> diff --git a/xwiki-platform-core/xwiki-platform-workspace/xwiki-platform-workspace-ui/src/main/resources/WorkspaceManager/Translations.xml b/xwiki-platform-core/xwiki-platform-workspace/xwiki-platform-workspace-ui/src/main/resources/WorkspaceManager/Translations.xml index 493886d..7c4192e 100644 --- a/xwiki-platform-core/xwiki-platform-workspace/xwiki-platform-workspace-ui/src/main/resources/WorkspaceManager/Translations.xml +++ b/xwiki-platform-core/xwiki-platform-workspace/xwiki-platform-workspace-ui/src/main/resources/WorkspaceManager/Translations.xml @@ -94,6 +94,7 @@ # DOCUMENTATION workspacemanager.doc.createwiki.wikiname=The unique identifier of the new workspace. workspacemanager.doc.createwiki.desc.wikiprettyname=The display name of the workspace. +workspacemanager.doc.createwiki.desc.template=Template to use for this new workspace (all documents will be cloned). workspacemanager.doc.createwiki.desc.description=A brief description of the workspace and its purpose. workspacemanager.doc.createwiki.desc.owner=A user who will have all the rights on the workspace. workspacemanager.doc.createwiki.members=The users that can participate in the workspace.\n\