1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.xar.script; |
21 |
|
|
22 |
|
import java.io.File; |
23 |
|
import java.io.IOException; |
24 |
|
import java.io.InputStream; |
25 |
|
|
26 |
|
import javax.inject.Inject; |
27 |
|
import javax.inject.Named; |
28 |
|
import javax.inject.Provider; |
29 |
|
import javax.inject.Singleton; |
30 |
|
|
31 |
|
import org.xwiki.component.annotation.Component; |
32 |
|
import org.xwiki.component.manager.ComponentManager; |
33 |
|
import org.xwiki.configuration.ConfigurationSource; |
34 |
|
import org.xwiki.context.Execution; |
35 |
|
import org.xwiki.filter.input.InputFilterStreamFactory; |
36 |
|
import org.xwiki.filter.output.OutputFilterStreamFactory; |
37 |
|
import org.xwiki.filter.type.FilterStreamType; |
38 |
|
import org.xwiki.script.service.ScriptService; |
39 |
|
import org.xwiki.stability.Unstable; |
40 |
|
import org.xwiki.xar.XarPackage; |
41 |
|
|
42 |
|
import com.xpn.xwiki.XWikiContext; |
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
@version |
48 |
|
@since |
49 |
|
|
50 |
|
@Component |
51 |
|
@Named("xar") |
52 |
|
@Singleton |
|
|
| 47.2% |
Uncovered Elements: 19 (36) |
Complexity: 14 |
Complexity Density: 0.61 |
|
53 |
|
public class XarScriptService implements ScriptService |
54 |
|
{ |
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
public static final String ERROR_KEY = "scriptservice.xar.error"; |
59 |
|
|
60 |
|
private static final String EXPORT_USEFILTER_KEY = "xwiki.action.export.xar.usefilter"; |
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
@Inject |
66 |
|
protected Execution execution; |
67 |
|
|
68 |
|
@Inject |
69 |
|
@Named("xwikicfg") |
70 |
|
private ConfigurationSource xwikiCfgConfigurationSource; |
71 |
|
|
72 |
|
@Inject |
73 |
|
@Named("context") |
74 |
|
private Provider<ComponentManager> contextComponentManagerProvider; |
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
@return |
82 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
83 |
0 |
public Exception getLastError()... |
84 |
|
{ |
85 |
0 |
return (Exception) this.execution.getContext().getProperty(ERROR_KEY); |
86 |
|
} |
87 |
|
|
88 |
|
|
89 |
|
@link |
90 |
|
|
91 |
|
@param |
92 |
|
@see |
93 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
94 |
0 |
protected void setError(Exception e)... |
95 |
|
{ |
96 |
0 |
this.execution.getContext().setProperty(ERROR_KEY, e); |
97 |
|
} |
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
@link |
103 |
|
|
104 |
|
@param |
105 |
|
@return |
106 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
107 |
0 |
public XarPackage getXarPackage(File file)... |
108 |
|
{ |
109 |
0 |
try { |
110 |
0 |
return new XarPackage(file); |
111 |
|
} catch (Exception e) { |
112 |
0 |
setError(e); |
113 |
|
} |
114 |
|
|
115 |
0 |
return null; |
116 |
|
} |
117 |
|
|
118 |
|
|
119 |
|
@link |
120 |
|
|
121 |
|
@param |
122 |
|
@param |
123 |
|
@return |
124 |
|
|
|
|
| 66.7% |
Uncovered Elements: 3 (9) |
Complexity: 4 |
Complexity Density: 0.57 |
|
125 |
4 |
public XarPackage getXarPackage(InputStream stream, boolean close)... |
126 |
|
{ |
127 |
4 |
try { |
128 |
4 |
return new XarPackage(stream); |
129 |
|
} catch (Exception e) { |
130 |
0 |
setError(e); |
131 |
|
} finally { |
132 |
4 |
if (close) { |
133 |
4 |
try { |
134 |
4 |
stream.close(); |
135 |
|
} catch (IOException e) { |
136 |
|
|
137 |
|
} |
138 |
|
} |
139 |
|
} |
140 |
|
|
141 |
0 |
return null; |
142 |
|
} |
143 |
|
|
144 |
|
|
145 |
|
@return |
146 |
|
@since |
147 |
|
|
|
|
| 56.2% |
Uncovered Elements: 7 (16) |
Complexity: 6 |
Complexity Density: 0.6 |
|
148 |
271 |
@Unstable... |
149 |
|
public boolean isXARExportAvailable() |
150 |
|
{ |
151 |
271 |
boolean available = false; |
152 |
|
|
153 |
|
|
154 |
271 |
int useFilter = this.xwikiCfgConfigurationSource.getProperty(EXPORT_USEFILTER_KEY, (Integer) 1); |
155 |
271 |
if (useFilter == 1) { |
156 |
|
|
157 |
271 |
ComponentManager cm = this.contextComponentManagerProvider.get(); |
158 |
271 |
if (cm.hasComponent(InputFilterStreamFactory.class, FilterStreamType.XWIKI_INSTANCE.serialize()) |
159 |
|
&& cm.hasComponent(OutputFilterStreamFactory.class, FilterStreamType.XWIKI_XAR_CURRENT.serialize())) |
160 |
|
{ |
161 |
271 |
available = true; |
162 |
|
} |
163 |
|
} else { |
164 |
|
|
165 |
0 |
XWikiContext xcontext = |
166 |
|
(XWikiContext) this.execution.getContext().getProperty(XWikiContext.EXECUTIONCONTEXT_KEY); |
167 |
0 |
if (xcontext != null && xcontext.getWiki().getPlugin("package", xcontext) != null) { |
168 |
0 |
available = true; |
169 |
|
} |
170 |
|
} |
171 |
|
|
172 |
271 |
return available; |
173 |
|
} |
174 |
|
} |