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 org.slf4j.Logger; |
23 |
|
import org.slf4j.LoggerFactory; |
24 |
|
|
25 |
|
import com.xpn.xwiki.XWikiContext; |
26 |
|
import com.xpn.xwiki.XWikiException; |
27 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
28 |
|
|
|
|
| 33.1% |
Uncovered Elements: 81 (121) |
Complexity: 41 |
Complexity Density: 0.67 |
|
29 |
|
public class DocumentInfo |
30 |
|
{ |
31 |
|
private static final Logger LOGGER = LoggerFactory.getLogger(DocumentInfo.class); |
32 |
|
|
33 |
|
private XWikiDocument doc; |
34 |
|
|
35 |
|
private int installable = INSTALL_IMPOSSIBLE; |
36 |
|
|
37 |
|
private int action = ACTION_NOT_DEFINED; |
38 |
|
|
39 |
|
private int fileType; |
40 |
|
|
41 |
|
public final static int TYPE_SAMPLE = 0; |
42 |
|
|
43 |
|
public final static int TYPE_NORMAL = 1; |
44 |
|
|
45 |
|
public final static int ACTION_NOT_DEFINED = -1; |
46 |
|
|
47 |
|
public final static int ACTION_OVERWRITE = 0; |
48 |
|
|
49 |
|
public final static int ACTION_SKIP = 1; |
50 |
|
|
51 |
|
public final static int ACTION_MERGE = 2; |
52 |
|
|
53 |
|
public final static int INSTALL_IMPOSSIBLE = 0; |
54 |
|
|
55 |
|
public final static int INSTALL_ALREADY_EXIST = 1; |
56 |
|
|
57 |
|
public final static int INSTALL_OK = 2; |
58 |
|
|
59 |
|
public final static int INSTALL_ERROR = 4; |
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
61 |
2007 |
public DocumentInfo(XWikiDocument doc)... |
62 |
|
{ |
63 |
2007 |
this.doc = doc; |
64 |
|
} |
65 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
66 |
21745 |
public XWikiDocument getDoc()... |
67 |
|
{ |
68 |
21745 |
return this.doc; |
69 |
|
} |
70 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
71 |
0 |
public boolean isNew()... |
72 |
|
{ |
73 |
0 |
return this.doc.isNew(); |
74 |
|
} |
75 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
76 |
0 |
public void changeSpace(String Space)... |
77 |
|
{ |
78 |
0 |
if (this.doc.getSpace().compareTo("XWiki") != 0) { |
79 |
0 |
return; |
80 |
|
} |
81 |
0 |
this.doc.setSpace(Space); |
82 |
0 |
this.installable = INSTALL_IMPOSSIBLE; |
83 |
|
} |
84 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
85 |
0 |
public int getFileType()... |
86 |
|
{ |
87 |
0 |
return this.fileType; |
88 |
|
} |
89 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
90 |
0 |
public void setFileType(int fileType)... |
91 |
|
{ |
92 |
0 |
this.fileType = fileType; |
93 |
|
} |
94 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
95 |
64606 |
public String getFullName()... |
96 |
|
{ |
97 |
64606 |
return (this.doc.getFullName()); |
98 |
|
} |
99 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
100 |
8210 |
public String getLanguage()... |
101 |
|
{ |
102 |
8210 |
return (this.doc.getLanguage()); |
103 |
|
} |
104 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
105 |
0 |
public int isInstallable()... |
106 |
|
{ |
107 |
0 |
return this.installable; |
108 |
|
} |
109 |
|
|
|
|
| 60% |
Uncovered Elements: 18 (45) |
Complexity: 15 |
Complexity Density: 0.65 |
|
110 |
4126 |
public int testInstall(boolean isAdmin, XWikiContext context)... |
111 |
|
{ |
112 |
4126 |
if (LOGGER.isDebugEnabled()) { |
113 |
0 |
LOGGER.debug("Package test install document " + ((this.doc == null) ? "" : getFullName()) + " " |
114 |
0 |
+ ((this.doc == null) ? "" : getLanguage())); |
115 |
|
} |
116 |
|
|
117 |
4126 |
this.installable = INSTALL_IMPOSSIBLE; |
118 |
|
|
119 |
4126 |
try { |
120 |
4126 |
if (this.doc == null) { |
121 |
0 |
return this.installable; |
122 |
|
} |
123 |
4126 |
try { |
124 |
4126 |
if ((!isAdmin) && (!context.getWiki().checkAccess("edit", this.doc, context))) { |
125 |
0 |
return this.installable; |
126 |
|
} |
127 |
4126 |
XWikiDocument doc1 = context.getWiki().getDocument(this.doc.getFullName(), context); |
128 |
4126 |
boolean isNew = doc1.isNew(); |
129 |
4126 |
if (!isNew) { |
130 |
164 |
if ((this.doc.getLanguage() != null) && (!this.doc.getLanguage().equals(""))) { |
131 |
158 |
isNew = !doc1.getTranslationList(context).contains(this.doc.getLanguage()); |
132 |
|
} |
133 |
|
} |
134 |
|
|
135 |
4126 |
if (!isNew) { |
136 |
8 |
this.installable = INSTALL_ALREADY_EXIST; |
137 |
8 |
return this.installable; |
138 |
|
} |
139 |
|
} catch (XWikiException e) { |
140 |
0 |
this.installable = INSTALL_IMPOSSIBLE; |
141 |
0 |
return this.installable; |
142 |
|
} |
143 |
4118 |
this.installable = INSTALL_OK; |
144 |
4118 |
return this.installable; |
145 |
|
} finally { |
146 |
4126 |
if (LOGGER.isDebugEnabled()) { |
147 |
0 |
LOGGER.debug("Package test install document " + ((this.doc == null) ? "" : getFullName()) + " " |
148 |
0 |
+ ((this.doc == null) ? "" : getLanguage()) + " result " + this.installable); |
149 |
|
} |
150 |
|
} |
151 |
|
} |
152 |
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 5 |
Complexity Density: 0.56 |
|
153 |
0 |
public static String installStatusToString(int status)... |
154 |
|
{ |
155 |
0 |
if (status == INSTALL_IMPOSSIBLE) { |
156 |
0 |
return "Impossible"; |
157 |
0 |
} else if (status == INSTALL_ERROR) { |
158 |
0 |
return "Error"; |
159 |
0 |
} else if (status == INSTALL_OK) { |
160 |
0 |
return "Ok"; |
161 |
0 |
} else if (status == INSTALL_ALREADY_EXIST) { |
162 |
0 |
return "Already exist"; |
163 |
|
} |
164 |
0 |
return "Unknown Status"; |
165 |
|
} |
166 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 4 |
Complexity Density: 0.57 |
|
167 |
0 |
public static String actionToString(int status)... |
168 |
|
{ |
169 |
0 |
if (status == ACTION_MERGE) { |
170 |
0 |
return "merge"; |
171 |
0 |
} else if (status == ACTION_OVERWRITE) { |
172 |
0 |
return "overwrite"; |
173 |
0 |
} else if (status == ACTION_SKIP) { |
174 |
0 |
return "skip"; |
175 |
|
} |
176 |
0 |
return "Not defined"; |
177 |
|
} |
178 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 4 |
Complexity Density: 0.57 |
|
179 |
0 |
public static int actionToInt(String status)... |
180 |
|
{ |
181 |
0 |
if (status.compareTo("merge") == 0) { |
182 |
0 |
return ACTION_MERGE; |
183 |
0 |
} else if (status.compareTo("overwrite") == 0) { |
184 |
0 |
return ACTION_OVERWRITE; |
185 |
0 |
} else if (status.compareTo("skip") == 0) { |
186 |
0 |
return ACTION_SKIP; |
187 |
|
} |
188 |
0 |
return ACTION_NOT_DEFINED; |
189 |
|
} |
190 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
191 |
2006 |
public int getAction()... |
192 |
|
{ |
193 |
2006 |
return this.action; |
194 |
|
} |
195 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
196 |
3989 |
public void setAction(int action)... |
197 |
|
{ |
198 |
3989 |
this.action = action; |
199 |
|
} |
200 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
201 |
0 |
public void setDoc(XWikiDocument doc)... |
202 |
|
{ |
203 |
0 |
this.doc = doc; |
204 |
|
} |
205 |
|
} |