1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.internal.filter.input; |
21 |
|
|
22 |
|
import java.util.List; |
23 |
|
import java.util.Locale; |
24 |
|
|
25 |
|
import javax.inject.Inject; |
26 |
|
import javax.inject.Named; |
27 |
|
import javax.inject.Provider; |
28 |
|
|
29 |
|
import org.xwiki.component.annotation.Component; |
30 |
|
import org.xwiki.component.annotation.InstantiationStrategy; |
31 |
|
import org.xwiki.component.descriptor.ComponentInstantiationStrategy; |
32 |
|
import org.xwiki.filter.FilterEventParameters; |
33 |
|
import org.xwiki.filter.FilterException; |
34 |
|
import org.xwiki.filter.descriptor.FilterStreamDescriptor; |
35 |
|
import org.xwiki.filter.event.model.WikiDocumentFilter; |
36 |
|
import org.xwiki.filter.instance.input.AbstractInstanceInputEventGenerator; |
37 |
|
import org.xwiki.filter.instance.input.EntityEventGenerator; |
38 |
|
import org.xwiki.model.reference.DocumentReference; |
39 |
|
import org.xwiki.model.reference.SpaceReference; |
40 |
|
import org.xwiki.properties.BeanManager; |
41 |
|
|
42 |
|
import com.xpn.xwiki.XWikiContext; |
43 |
|
import com.xpn.xwiki.XWikiException; |
44 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
45 |
|
import com.xpn.xwiki.internal.filter.XWikiDocumentFilter; |
46 |
|
|
47 |
|
@Component |
48 |
|
@Named("documents") |
49 |
|
@InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP) |
|
|
| 75% |
Uncovered Elements: 7 (28) |
Complexity: 7 |
Complexity Density: 0.28 |
|
50 |
|
public class DocumentInstanceInputEventGenerator extends AbstractInstanceInputEventGenerator<XWikiDocumentFilter> |
51 |
|
{ |
52 |
|
|
53 |
|
@link |
54 |
|
|
55 |
|
@Inject |
56 |
|
protected BeanManager beanManager; |
57 |
|
|
58 |
|
@Inject |
59 |
|
private EntityEventGenerator<XWikiDocument> documentLocaleParser; |
60 |
|
|
61 |
|
@Inject |
62 |
|
private Provider<XWikiContext> xcontextProvider; |
63 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
64 |
2 |
@Override... |
65 |
|
public FilterStreamDescriptor getDescriptor() |
66 |
|
{ |
67 |
2 |
return this.documentLocaleParser.getDescriptor(); |
68 |
|
} |
69 |
|
|
|
|
| 85.7% |
Uncovered Elements: 1 (7) |
Complexity: 2 |
Complexity Density: 0.29 |
|
70 |
3 |
@Override... |
71 |
|
public void setWikiDocumentParameters(String name, FilterEventParameters documentParameters) throws FilterException |
72 |
|
{ |
73 |
3 |
DocumentReference reference = new DocumentReference(name, new SpaceReference(this.currentReference)); |
74 |
|
|
75 |
3 |
XWikiContext xcontext = this.xcontextProvider.get(); |
76 |
|
|
77 |
3 |
XWikiDocument defaultDocument; |
78 |
3 |
try { |
79 |
3 |
defaultDocument = xcontext.getWiki().getDocument(reference, xcontext); |
80 |
|
} catch (XWikiException e) { |
81 |
0 |
throw new FilterException("Failed to get document [" + reference + "]", e); |
82 |
|
} |
83 |
|
|
84 |
3 |
documentParameters.put(WikiDocumentFilter.PARAMETER_LOCALE, defaultDocument.getDefaultLocale()); |
85 |
|
} |
86 |
|
|
|
|
| 64.7% |
Uncovered Elements: 6 (17) |
Complexity: 4 |
Complexity Density: 0.24 |
|
87 |
3 |
@Override... |
88 |
|
public void beginWikiDocument(String name, FilterEventParameters parameters) throws FilterException |
89 |
|
{ |
90 |
3 |
super.beginWikiDocument(name, parameters); |
91 |
|
|
92 |
3 |
DocumentReference reference = new DocumentReference(this.currentReference); |
93 |
|
|
94 |
3 |
XWikiContext xcontext = this.xcontextProvider.get(); |
95 |
|
|
96 |
3 |
XWikiDocument defaultDocument; |
97 |
3 |
try { |
98 |
3 |
defaultDocument = xcontext.getWiki().getDocument(reference, xcontext); |
99 |
|
} catch (XWikiException e) { |
100 |
0 |
throw new FilterException("Failed to get document [" + reference + "]", e); |
101 |
|
} |
102 |
|
|
103 |
|
|
104 |
3 |
this.documentLocaleParser.write(defaultDocument, this.filter, this.properties); |
105 |
|
|
106 |
3 |
List<Locale> locales; |
107 |
3 |
try { |
108 |
3 |
locales = defaultDocument.getTranslationLocales(xcontext); |
109 |
|
} catch (XWikiException e) { |
110 |
0 |
throw new FilterException("Failed to get translations of document [" + reference + "]", e); |
111 |
|
} |
112 |
|
|
113 |
|
|
114 |
3 |
for (Locale locale : locales) { |
115 |
0 |
try { |
116 |
0 |
XWikiDocument translationDocument = defaultDocument.getTranslatedDocument(locale, xcontext); |
117 |
0 |
this.documentLocaleParser.write(translationDocument, this.filter, this.properties); |
118 |
|
} catch (XWikiException e) { |
119 |
0 |
throw new FilterException("Failed to get document [" + reference + "] for locale [" + locale + "]", e); |
120 |
|
} |
121 |
|
} |
122 |
|
} |
123 |
|
} |