1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.plugin.packaging; |
21 |
|
|
22 |
|
import java.io.IOException; |
23 |
|
import java.io.InputStream; |
24 |
|
import java.util.ArrayList; |
25 |
|
import java.util.List; |
26 |
|
|
27 |
|
import com.xpn.xwiki.XWikiContext; |
28 |
|
import com.xpn.xwiki.XWikiException; |
29 |
|
import com.xpn.xwiki.api.Api; |
30 |
|
import com.xpn.xwiki.util.Util; |
31 |
|
|
32 |
|
import net.sf.json.JSONObject; |
33 |
|
|
|
|
| 26.1% |
Uncovered Elements: 82 (111) |
Complexity: 47 |
Complexity Density: 0.75 |
|
34 |
|
public class PackageAPI extends Api |
35 |
|
{ |
36 |
|
Package pack; |
37 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
38 |
224 |
public PackageAPI(Package plugin, XWikiContext context) throws PackageException... |
39 |
|
{ |
40 |
224 |
super(context); |
41 |
|
|
42 |
224 |
if (!hasAdminRights()) { |
43 |
15 |
throw new PackageException(XWikiException.ERROR_XWIKI_ACCESS_DENIED, |
44 |
|
"Admin right is needed to use this plugin"); |
45 |
|
} |
46 |
|
|
47 |
209 |
setPlugin(plugin); |
48 |
|
} |
49 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
50 |
209 |
private void setPlugin(Package plugin)... |
51 |
|
{ |
52 |
209 |
this.pack = plugin; |
53 |
|
} |
54 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
55 |
0 |
public String getName()... |
56 |
|
{ |
57 |
0 |
return this.pack.getName(); |
58 |
|
} |
59 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
60 |
0 |
public void setName(String name)... |
61 |
|
{ |
62 |
0 |
this.pack.setName(name); |
63 |
|
} |
64 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
65 |
0 |
public Package getPackage()... |
66 |
|
{ |
67 |
0 |
if (hasProgrammingRights()) { |
68 |
0 |
return this.pack; |
69 |
|
} |
70 |
0 |
return null; |
71 |
|
} |
72 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
73 |
0 |
public String getDescription()... |
74 |
|
{ |
75 |
0 |
return this.pack.getDescription(); |
76 |
|
} |
77 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
78 |
0 |
public void setDescription(String description)... |
79 |
|
{ |
80 |
0 |
this.pack.setDescription(description); |
81 |
|
} |
82 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
83 |
0 |
public String getVersion()... |
84 |
|
{ |
85 |
0 |
return this.pack.getVersion(); |
86 |
|
} |
87 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
88 |
0 |
public void setVersion(String version)... |
89 |
|
{ |
90 |
0 |
this.pack.setVersion(version); |
91 |
|
} |
92 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
93 |
0 |
public String getLicence()... |
94 |
|
{ |
95 |
0 |
return this.pack.getLicence(); |
96 |
|
} |
97 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
98 |
0 |
public void setLicence(String licence)... |
99 |
|
{ |
100 |
0 |
this.pack.setLicence(licence); |
101 |
|
} |
102 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
103 |
0 |
public String getAuthorName()... |
104 |
|
{ |
105 |
0 |
return this.pack.getAuthorName(); |
106 |
|
} |
107 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
108 |
0 |
public void setAuthorName(String authorName)... |
109 |
|
{ |
110 |
0 |
this.pack.setAuthorName(authorName); |
111 |
|
} |
112 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
113 |
0 |
public boolean isBackupPack()... |
114 |
|
{ |
115 |
0 |
return this.pack.isBackupPack(); |
116 |
|
} |
117 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
118 |
2 |
public void setBackupPack(boolean backupPack)... |
119 |
|
{ |
120 |
2 |
this.pack.setBackupPack(backupPack); |
121 |
|
} |
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
@return |
130 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
131 |
88 |
public boolean hasBackupPackImportRights()... |
132 |
|
{ |
133 |
88 |
return this.pack.hasBackupPackImportRights(this.context); |
134 |
|
} |
135 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
136 |
0 |
public boolean isVersionPreserved()... |
137 |
|
{ |
138 |
0 |
return this.pack.isVersionPreserved(); |
139 |
|
} |
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
@link |
144 |
|
|
145 |
|
|
146 |
|
@param |
147 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
148 |
1 |
public void setPreserveVersion(boolean preserveVersion)... |
149 |
|
{ |
150 |
1 |
this.pack.setPreserveVersion(preserveVersion); |
151 |
|
} |
152 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
153 |
0 |
public boolean isWithVersions()... |
154 |
|
{ |
155 |
0 |
return this.pack.isWithVersions(); |
156 |
|
} |
157 |
|
|
158 |
|
|
159 |
|
|
160 |
|
@link@link |
161 |
|
|
162 |
|
|
163 |
|
|
164 |
|
@param |
165 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
166 |
1 |
public void setWithVersions(boolean withVersions)... |
167 |
|
{ |
168 |
1 |
this.pack.setWithVersions(withVersions); |
169 |
|
} |
170 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
171 |
0 |
public void addDocumentFilter(Object filter) throws PackageException... |
172 |
|
{ |
173 |
0 |
this.pack.addDocumentFilter(filter); |
174 |
|
} |
175 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
176 |
0 |
public List<DocumentInfoAPI> getFiles()... |
177 |
|
{ |
178 |
0 |
List<DocumentInfo> files = this.pack.getFiles(); |
179 |
0 |
ArrayList<DocumentInfoAPI> apiFiles = new ArrayList<DocumentInfoAPI>(files.size()); |
180 |
|
|
181 |
0 |
for (DocumentInfo docInfo : files) { |
182 |
0 |
apiFiles.add(new DocumentInfoAPI(docInfo, getXWikiContext())); |
183 |
|
} |
184 |
|
|
185 |
0 |
return apiFiles; |
186 |
|
} |
187 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
188 |
0 |
public boolean add(String docFullName, int DefaultAction) throws XWikiException... |
189 |
|
{ |
190 |
0 |
return this.pack.add(docFullName, DefaultAction, getXWikiContext()); |
191 |
|
} |
192 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
193 |
0 |
public boolean add(String docFullName) throws XWikiException... |
194 |
|
{ |
195 |
0 |
return this.pack.add(docFullName, getXWikiContext()); |
196 |
|
} |
197 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
198 |
0 |
public void setDocumentAction(String docFullName, int action)... |
199 |
|
{ |
200 |
0 |
for (DocumentInfo docInfo : this.pack.getFiles()) { |
201 |
0 |
if (docInfo.getFullName().compareTo(docFullName) == 0) { |
202 |
0 |
docInfo.setAction(action); |
203 |
|
} |
204 |
|
} |
205 |
|
} |
206 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
207 |
0 |
public void setDocumentAction(String docFullName, String language, int action)... |
208 |
|
{ |
209 |
0 |
for (DocumentInfo docInfo : this.pack.getFiles()) { |
210 |
0 |
if ((docInfo.getFullName().compareTo(docFullName) == 0) && (language.equals(docInfo.getLanguage()))) { |
211 |
0 |
docInfo.setAction(action); |
212 |
|
} |
213 |
|
} |
214 |
|
} |
215 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
216 |
0 |
public String export() throws IOException, XWikiException... |
217 |
|
{ |
218 |
0 |
getXWikiContext().getResponse().setContentType("application/zip"); |
219 |
0 |
getXWikiContext().getResponse().addHeader("Content-disposition", |
220 |
|
"attachment; filename=" + Util.encodeURI(this.pack.getName(), this.context) + ".xar"); |
221 |
0 |
getXWikiContext().setFinished(true); |
222 |
|
|
223 |
0 |
return this.pack.export(getXWikiContext().getResponse().getOutputStream(), getXWikiContext()); |
224 |
|
} |
225 |
|
|
226 |
|
|
227 |
|
@link |
228 |
|
|
229 |
|
|
230 |
|
|
231 |
|
@param |
232 |
|
@return |
233 |
|
|
234 |
|
@since |
235 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 3 |
Complexity Density: 0.43 |
|
236 |
0 |
public boolean importPackageFromByteArray(byte data[])... |
237 |
|
{ |
238 |
0 |
try { |
239 |
0 |
this.pack.Import(data, getXWikiContext()); |
240 |
0 |
return true; |
241 |
|
} catch (XWikiException e) { |
242 |
0 |
getXWikiContext().put("import_error", e.getMessage()); |
243 |
0 |
return false; |
244 |
|
} catch (IOException e) { |
245 |
0 |
getXWikiContext().put("import_error", e.getMessage()); |
246 |
0 |
return false; |
247 |
|
} |
248 |
|
} |
249 |
|
|
250 |
|
|
251 |
|
@link |
252 |
|
@link |
253 |
|
|
254 |
|
@param |
255 |
|
@return |
256 |
|
@throws |
257 |
|
@throws |
258 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
259 |
0 |
public String Import(byte file[]) throws IOException, XWikiException... |
260 |
|
{ |
261 |
0 |
return this.pack.Import(file, getXWikiContext()); |
262 |
|
} |
263 |
|
|
264 |
|
|
265 |
|
@link |
266 |
|
|
267 |
|
@param |
268 |
|
@return |
269 |
|
@throws |
270 |
|
@throws |
271 |
|
@since |
272 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
273 |
1 |
public String Import(InputStream file) throws IOException, XWikiException... |
274 |
|
{ |
275 |
1 |
return this.pack.Import(file, getXWikiContext()); |
276 |
|
} |
277 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
278 |
0 |
public int testInstall()... |
279 |
|
{ |
280 |
0 |
return this.pack.testInstall(false, getXWikiContext()); |
281 |
|
} |
282 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
283 |
0 |
public int testInstall(boolean isAdmin)... |
284 |
|
{ |
285 |
0 |
return this.pack.testInstall(isAdmin, getXWikiContext()); |
286 |
|
} |
287 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
288 |
0 |
public void backupWiki() throws XWikiException, IOException... |
289 |
|
{ |
290 |
0 |
this.pack.addAllWikiDocuments(getXWikiContext()); |
291 |
0 |
this.export(); |
292 |
|
} |
293 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
294 |
0 |
public String toXml()... |
295 |
|
{ |
296 |
0 |
return this.pack.toXml(getXWikiContext()); |
297 |
|
} |
298 |
|
|
299 |
|
|
300 |
|
@return |
301 |
|
@since |
302 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
303 |
0 |
public JSONObject toJSON()... |
304 |
|
{ |
305 |
0 |
return this.pack.toJSON(getXWikiContext()); |
306 |
|
} |
307 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
308 |
1 |
public int install() throws XWikiException... |
309 |
|
{ |
310 |
1 |
return this.pack.install(getXWikiContext()); |
311 |
|
} |
312 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
313 |
8 |
public List<String> getErrors()... |
314 |
|
{ |
315 |
8 |
return this.pack.getErrors(getXWikiContext()); |
316 |
|
} |
317 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
318 |
8 |
public List<String> getSkipped()... |
319 |
|
{ |
320 |
8 |
return this.pack.getSkipped(getXWikiContext()); |
321 |
|
} |
322 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
323 |
12 |
public List<String> getInstalled()... |
324 |
|
{ |
325 |
12 |
return this.pack.getInstalled(getXWikiContext()); |
326 |
|
} |
327 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
328 |
4 |
public int getStatus()... |
329 |
|
{ |
330 |
4 |
return this.pack.getStatus(getXWikiContext()); |
331 |
|
} |
332 |
|
|
333 |
|
} |