1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.wiki.internal.manager

File DefaultWikiCreator.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

0
16
2
1
103
56
5
0.31
8
2
2.5

Classes

Class Line # Actions
DefaultWikiCreator 45 16 0% 5 3
0.833333383.3%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.wiki.internal.manager;
21   
22    import javax.inject.Inject;
23    import javax.inject.Provider;
24    import javax.inject.Singleton;
25   
26    import org.xwiki.component.annotation.Component;
27    import org.xwiki.localization.ContextualLocalizationManager;
28    import org.xwiki.wiki.descriptor.WikiDescriptor;
29    import org.xwiki.wiki.descriptor.WikiDescriptorManager;
30    import org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor;
31    import org.xwiki.wiki.internal.descriptor.builder.WikiDescriptorBuilder;
32    import org.xwiki.wiki.internal.descriptor.builder.WikiDescriptorBuilderException;
33    import org.xwiki.wiki.manager.WikiManagerException;
34   
35    import com.xpn.xwiki.XWiki;
36    import com.xpn.xwiki.XWikiContext;
37   
38    /**
39    * Default implementation of {@link WikiCreator}.
40    *
41    * @version $Id: 6e1cb7beb73157a3d1301e6f003df292b706a2ef $
42    */
43    @Component
44    @Singleton
 
45    public class DefaultWikiCreator implements WikiCreator
46    {
47    @Inject
48    private Provider<XWikiContext> xcontextProvider;
49   
50    @Inject
51    private ContextualLocalizationManager localizationManager;
52   
53    @Inject
54    private WikiDescriptorBuilder wikiDescriptorBuilder;
55   
56    @Inject
57    private WikiDescriptorManager wikiDescriptorManager;
58   
 
59  5 toggle @Override
60    public WikiDescriptor create(String wikiId, String wikiAlias) throws WikiManagerException
61    {
62  5 XWikiContext context = xcontextProvider.get();
63  5 XWiki xwiki = context.getWiki();
64   
65    // Create database/schema
66  5 try {
67  5 xwiki.getStore().createWiki(wikiId, context);
68    } catch (Exception e) {
69  0 throw new WikiManagerException(localizationManager.getTranslationPlain("wiki.databasecreation", wikiId), e);
70    }
71   
72    // Create the descriptor
73    // Since XWiki#updateDatabase is generating documents it needs the wiki to actually exist
74    // from XWiki point of view as otherwise various codes are going to be lost
75  5 WikiDescriptor descriptor = createDescriptor(wikiId, wikiAlias);
76   
77    // Init database/schema
78  5 try {
79  5 xwiki.initializeWiki(wikiId, true, context);
80    } catch (Exception e) {
81  0 throw new WikiManagerException(localizationManager.getTranslationPlain("wiki.databaseupdate", wikiId), e);
82    }
83   
84  5 return descriptor;
85    }
86   
 
87  5 toggle private WikiDescriptor createDescriptor(String wikiId, String wikiAlias) throws WikiManagerException
88    {
89    // Create the descriptor
90  5 WikiDescriptor descriptor = new DefaultWikiDescriptor(wikiId, wikiAlias);
91   
92  5 try {
93    // Build the document
94  5 wikiDescriptorBuilder.save(descriptor);
95    // Reload the descriptor from the cache because it should have been seen by the DescriptorListener.
96  5 descriptor = wikiDescriptorManager.getById(wikiId);
97    } catch (WikiDescriptorBuilderException e) {
98  0 throw new WikiManagerException("Failed to build the descriptor document.", e);
99    }
100   
101  5 return descriptor;
102    }
103    }