1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.wiki.template.internal; |
21 |
|
|
22 |
|
import javax.inject.Inject; |
23 |
|
import javax.inject.Named; |
24 |
|
import javax.inject.Provider; |
25 |
|
import javax.inject.Singleton; |
26 |
|
|
27 |
|
import org.xwiki.component.annotation.Component; |
28 |
|
import org.xwiki.wiki.internal.descriptor.document.WikiDescriptorDocumentHelper; |
29 |
|
import org.xwiki.wiki.manager.WikiManagerException; |
30 |
|
import org.xwiki.wiki.properties.WikiPropertyGroup; |
31 |
|
import org.xwiki.wiki.properties.WikiPropertyGroupException; |
32 |
|
import org.xwiki.wiki.properties.WikiPropertyGroupProvider; |
33 |
|
import org.xwiki.wiki.template.WikiTemplatePropertyGroup; |
34 |
|
|
35 |
|
import com.xpn.xwiki.XWiki; |
36 |
|
import com.xpn.xwiki.XWikiContext; |
37 |
|
import com.xpn.xwiki.XWikiException; |
38 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
39 |
|
import com.xpn.xwiki.objects.BaseObject; |
40 |
|
|
41 |
|
|
42 |
|
@link |
43 |
|
|
44 |
|
@since |
45 |
|
@version |
46 |
|
|
47 |
|
@Component |
48 |
|
@Named(WikiTemplatePropertyGroupProvider.GROUP_NAME) |
49 |
|
@Singleton |
|
|
| 81.2% |
Uncovered Elements: 6 (32) |
Complexity: 9 |
Complexity Density: 0.41 |
|
50 |
|
public class WikiTemplatePropertyGroupProvider implements WikiPropertyGroupProvider |
51 |
|
{ |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
public static final String GROUP_NAME = "template"; |
56 |
|
|
57 |
|
private static final String ERROR_MESSAGE_NO_DESCRIPTOR_DOCUMENT = "Unable to load descriptor " |
58 |
|
+ "document for wiki [%s]."; |
59 |
|
|
60 |
|
@Inject |
61 |
|
private Provider<XWikiContext> xcontextProvider; |
62 |
|
|
63 |
|
@Inject |
64 |
|
private WikiDescriptorDocumentHelper wikiDescriptorDocumentHelper; |
65 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 3 |
Complexity Density: 0.38 |
|
66 |
20 |
@Override... |
67 |
|
public WikiPropertyGroup get(String wikiId) throws WikiPropertyGroupException |
68 |
|
{ |
69 |
20 |
WikiTemplatePropertyGroup group = new WikiTemplatePropertyGroup(GROUP_NAME); |
70 |
|
|
71 |
20 |
try { |
72 |
20 |
XWikiDocument descriptorDocument = wikiDescriptorDocumentHelper.getDocumentFromWikiId(wikiId); |
73 |
|
|
74 |
19 |
BaseObject object = descriptorDocument.getXObject(WikiTemplateClassDocumentInitializer.SERVER_CLASS); |
75 |
19 |
if (object != null) { |
76 |
9 |
group.setTemplate( |
77 |
|
object.getIntValue(WikiTemplateClassDocumentInitializer.FIELD_ISWIKITEMPLATE, 0) != 0); |
78 |
|
} |
79 |
|
} catch (WikiManagerException e) { |
80 |
1 |
throw new WikiPropertyGroupException(String.format(ERROR_MESSAGE_NO_DESCRIPTOR_DOCUMENT, wikiId), e); |
81 |
|
} |
82 |
|
|
83 |
19 |
return group; |
84 |
|
} |
85 |
|
|
|
|
| 70% |
Uncovered Elements: 6 (20) |
Complexity: 6 |
Complexity Density: 0.43 |
|
86 |
7 |
@Override... |
87 |
|
public void save(WikiPropertyGroup group, String wikiId) throws WikiPropertyGroupException |
88 |
|
{ |
89 |
7 |
XWikiContext context = xcontextProvider.get(); |
90 |
7 |
XWiki xwiki = context.getWiki(); |
91 |
|
|
92 |
7 |
WikiTemplatePropertyGroup templateGroup = (WikiTemplatePropertyGroup) group; |
93 |
|
|
94 |
7 |
try { |
95 |
7 |
XWikiDocument descriptorDocument = wikiDescriptorDocumentHelper.getDocumentFromWikiId(wikiId); |
96 |
7 |
BaseObject object = descriptorDocument.getXObject(WikiTemplateClassDocumentInitializer.SERVER_CLASS, |
97 |
|
true, context); |
98 |
7 |
object.setIntValue(WikiTemplateClassDocumentInitializer.FIELD_ISWIKITEMPLATE, |
99 |
7 |
templateGroup.isTemplate() ? 1 : 0); |
100 |
|
|
101 |
7 |
if (descriptorDocument.getCreatorReference() == null) { |
102 |
0 |
descriptorDocument.setCreatorReference(context.getUserReference()); |
103 |
|
} |
104 |
|
|
105 |
7 |
if (descriptorDocument.getAuthorReference() == null) { |
106 |
0 |
descriptorDocument.setAuthorReference(context.getUserReference()); |
107 |
|
} |
108 |
7 |
xwiki.saveDocument(descriptorDocument, String.format("Changed property group [%s].", GROUP_NAME), context); |
109 |
|
} catch (WikiManagerException e) { |
110 |
0 |
throw new WikiPropertyGroupException(String.format(ERROR_MESSAGE_NO_DESCRIPTOR_DOCUMENT, wikiId), e); |
111 |
|
} catch (XWikiException e) { |
112 |
0 |
throw new WikiPropertyGroupException("Unable to save descriptor document.", e); |
113 |
|
} |
114 |
|
} |
115 |
|
|
116 |
|
} |