| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package com.xpn.xwiki.web; |
| 21 |
|
|
| 22 |
|
import java.lang.reflect.Type; |
| 23 |
|
import java.util.ArrayList; |
| 24 |
|
import java.util.List; |
| 25 |
|
import java.util.Map; |
| 26 |
|
|
| 27 |
|
import javax.script.ScriptContext; |
| 28 |
|
|
| 29 |
|
import org.apache.commons.lang3.StringUtils; |
| 30 |
|
import org.apache.velocity.VelocityContext; |
| 31 |
|
import org.slf4j.Logger; |
| 32 |
|
import org.slf4j.LoggerFactory; |
| 33 |
|
import org.xwiki.model.EntityType; |
| 34 |
|
import org.xwiki.model.reference.DocumentReference; |
| 35 |
|
import org.xwiki.model.reference.DocumentReferenceResolver; |
| 36 |
|
import org.xwiki.model.reference.EntityReference; |
| 37 |
|
import org.xwiki.model.reference.EntityReferenceResolver; |
| 38 |
|
import org.xwiki.model.reference.EntityReferenceSerializer; |
| 39 |
|
import org.xwiki.model.reference.SpaceReference; |
| 40 |
|
import org.xwiki.query.Query; |
| 41 |
|
import org.xwiki.query.QueryManager; |
| 42 |
|
import org.xwiki.script.ScriptContextManager; |
| 43 |
|
import org.xwiki.velocity.VelocityManager; |
| 44 |
|
|
| 45 |
|
import com.xpn.xwiki.XWiki; |
| 46 |
|
import com.xpn.xwiki.XWikiContext; |
| 47 |
|
import com.xpn.xwiki.XWikiException; |
| 48 |
|
import com.xpn.xwiki.api.Document; |
| 49 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
| 50 |
|
import com.xpn.xwiki.objects.BaseObject; |
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
|
@version |
| 56 |
|
|
| |
|
| 93.6% |
Uncovered Elements: 15 (234) |
Complexity: 63 |
Complexity Density: 0.42 |
|
| 57 |
|
public class CreateActionRequestHandler |
| 58 |
|
{ |
| 59 |
|
|
| 60 |
|
|
| 61 |
|
|
| 62 |
|
private static final Logger LOGGER = LoggerFactory.getLogger(CreateActionRequestHandler.class); |
| 63 |
|
|
| 64 |
|
|
| 65 |
|
|
| 66 |
|
|
| 67 |
|
private static final String SPACE_REFERENCE = "spaceReference"; |
| 68 |
|
|
| 69 |
|
|
| 70 |
|
|
| 71 |
|
|
| 72 |
|
private static final String NAME = "name"; |
| 73 |
|
|
| 74 |
|
|
| 75 |
|
|
| 76 |
|
@link |
| 77 |
|
|
| 78 |
|
|
| 79 |
|
@deprecated@value |
| 80 |
|
|
| 81 |
|
@Deprecated |
| 82 |
|
private static final String SPACE = "space"; |
| 83 |
|
|
| 84 |
|
|
| 85 |
|
|
| 86 |
|
|
| 87 |
|
@deprecated@value |
| 88 |
|
|
| 89 |
|
@Deprecated |
| 90 |
|
private static final String PAGE = "page"; |
| 91 |
|
|
| 92 |
|
|
| 93 |
|
|
| 94 |
|
|
| 95 |
|
|
| 96 |
|
private static final String TOCREATE_SPACE = SPACE; |
| 97 |
|
|
| 98 |
|
|
| 99 |
|
|
| 100 |
|
|
| 101 |
|
private static final String TYPE = "type"; |
| 102 |
|
|
| 103 |
|
|
| 104 |
|
|
| 105 |
|
|
| 106 |
|
private static final String TOCREATE_TERMINAL = "terminal"; |
| 107 |
|
|
| 108 |
|
|
| 109 |
|
|
| 110 |
|
|
| 111 |
|
private static final String TOCREATE_NONTERMINAL = "nonterminal"; |
| 112 |
|
|
| 113 |
|
|
| 114 |
|
|
| 115 |
|
|
| 116 |
|
|
| 117 |
|
private static final String TEMPLATE = "template"; |
| 118 |
|
|
| 119 |
|
|
| 120 |
|
|
| 121 |
|
|
| 122 |
|
private static final String TEMPLATE_PROVIDER = "templateprovider"; |
| 123 |
|
|
| 124 |
|
|
| 125 |
|
|
| 126 |
|
|
| 127 |
|
private static final EntityReference TEMPLATE_PROVIDER_CLASS = new EntityReference("TemplateProviderClass", |
| 128 |
|
EntityType.DOCUMENT, new EntityReference(XWiki.SYSTEM_SPACE, EntityType.SPACE)); |
| 129 |
|
|
| 130 |
|
|
| 131 |
|
|
| 132 |
|
|
| 133 |
|
|
| 134 |
|
private static final EntityReference REDIRECT_CLASS = new EntityReference("RedirectClass", EntityType.DOCUMENT, |
| 135 |
|
new EntityReference(XWiki.SYSTEM_SPACE, EntityType.SPACE)); |
| 136 |
|
|
| 137 |
|
|
| 138 |
|
|
| 139 |
|
|
| 140 |
|
@deprecated@link |
| 141 |
|
@value |
| 142 |
|
|
| 143 |
|
@Deprecated |
| 144 |
|
private static final String SPACES_PROPERTY = "spaces"; |
| 145 |
|
|
| 146 |
|
|
| 147 |
|
|
| 148 |
|
|
| 149 |
|
private static final String EXCEPTION = "createException"; |
| 150 |
|
|
| 151 |
|
|
| 152 |
|
|
| 153 |
|
|
| 154 |
|
private static final String CURRENT_RESOLVER_HINT = "current"; |
| 155 |
|
|
| 156 |
|
|
| 157 |
|
|
| 158 |
|
|
| 159 |
|
private static final String CURRENT_MIXED_RESOLVER_HINT = "currentmixed"; |
| 160 |
|
|
| 161 |
|
|
| 162 |
|
|
| 163 |
|
|
| 164 |
|
private static final String LOCAL_SERIALIZER_HINT = "local"; |
| 165 |
|
|
| 166 |
|
private static final String TP_TERMINAL_PROPERTY = TOCREATE_TERMINAL; |
| 167 |
|
|
| 168 |
|
private static final String TP_TYPE_PROPERTY = TYPE; |
| 169 |
|
|
| 170 |
|
private static final String TP_TYPE_PROPERTY_SPACE_VALUE = SPACE; |
| 171 |
|
|
| 172 |
|
private static final String TP_CREATION_RESTRICTIONS_PROPERTY = "creationRestrictions"; |
| 173 |
|
|
| 174 |
|
private static final String TP_VISIBILITY_RESTRICTIONS_PROPERTY = "visibilityRestrictions"; |
| 175 |
|
|
| 176 |
|
private static final String TP_CREATION_RESTRICTIONS_ARE_SUGGESTIONS_PROPERTY = |
| 177 |
|
"creationRestrictionsAreSuggestions"; |
| 178 |
|
|
| 179 |
|
|
| 180 |
|
|
| 181 |
|
|
| 182 |
|
private static final String WEBHOME = "WebHome"; |
| 183 |
|
|
| 184 |
|
private ScriptContextManager scriptContextManager; |
| 185 |
|
|
| 186 |
|
private SpaceReference spaceReference; |
| 187 |
|
|
| 188 |
|
private String name; |
| 189 |
|
|
| 190 |
|
private boolean isSpace; |
| 191 |
|
|
| 192 |
|
private XWikiContext context; |
| 193 |
|
|
| 194 |
|
private XWikiDocument document; |
| 195 |
|
|
| 196 |
|
private XWikiRequest request; |
| 197 |
|
|
| 198 |
|
private BaseObject templateProvider; |
| 199 |
|
|
| 200 |
|
private List<Document> availableTemplateProviders; |
| 201 |
|
|
| 202 |
|
private String type; |
| 203 |
|
|
| 204 |
|
|
| 205 |
|
@param |
| 206 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 207 |
98 |
public CreateActionRequestHandler(XWikiContext context)... |
| 208 |
|
{ |
| 209 |
98 |
this.context = context; |
| 210 |
98 |
this.document = context.getDoc(); |
| 211 |
98 |
this.request = context.getRequest(); |
| 212 |
|
} |
| 213 |
|
|
| 214 |
|
|
| 215 |
|
|
| 216 |
|
|
| 217 |
|
@throws |
| 218 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (32) |
Complexity: 8 |
Complexity Density: 0.36 |
|
| 219 |
98 |
public void processRequest() throws XWikiException... |
| 220 |
|
{ |
| 221 |
|
|
| 222 |
98 |
DocumentReferenceResolver<EntityReference> referenceResolver = |
| 223 |
|
Utils.getComponent(DocumentReferenceResolver.TYPE_REFERENCE, CURRENT_RESOLVER_HINT); |
| 224 |
98 |
DocumentReference templateProviderClassReference = referenceResolver.resolve(TEMPLATE_PROVIDER_CLASS); |
| 225 |
98 |
templateProvider = getTemplateProvider(templateProviderClassReference); |
| 226 |
|
|
| 227 |
|
|
| 228 |
|
|
| 229 |
98 |
availableTemplateProviders = |
| 230 |
|
loadAvailableTemplateProviders(document.getDocumentReference().getLastSpaceReference(), |
| 231 |
|
templateProviderClassReference, context); |
| 232 |
|
|
| 233 |
|
|
| 234 |
98 |
type = request.get(TYPE); |
| 235 |
|
|
| 236 |
|
|
| 237 |
|
|
| 238 |
98 |
String toCreate = request.getParameter("tocreate"); |
| 239 |
|
|
| 240 |
98 |
if (document.isNew()) { |
| 241 |
34 |
processNewDocument(toCreate); |
| 242 |
|
} else { |
| 243 |
|
|
| 244 |
|
|
| 245 |
64 |
if (request.getParameter(SPACE) != null || request.getParameter(PAGE) != null) { |
| 246 |
|
|
| 247 |
7 |
processDeprecatedParameters(toCreate); |
| 248 |
|
} else { |
| 249 |
|
|
| 250 |
|
|
| 251 |
57 |
String spaceReferenceParameter = request.getParameter(SPACE_REFERENCE); |
| 252 |
|
|
| 253 |
|
|
| 254 |
57 |
if (StringUtils.isNotEmpty(spaceReferenceParameter)) { |
| 255 |
34 |
EntityReferenceResolver<String> genericResolver = |
| 256 |
|
Utils.getComponent(EntityReferenceResolver.TYPE_STRING, CURRENT_RESOLVER_HINT); |
| 257 |
|
|
| 258 |
34 |
EntityReference resolvedEntityReference = |
| 259 |
|
genericResolver.resolve(spaceReferenceParameter, EntityType.SPACE); |
| 260 |
34 |
spaceReference = new SpaceReference(resolvedEntityReference); |
| 261 |
|
} |
| 262 |
|
|
| 263 |
|
|
| 264 |
|
|
| 265 |
|
|
| 266 |
57 |
name = request.getParameter(NAME); |
| 267 |
|
|
| 268 |
|
|
| 269 |
|
|
| 270 |
57 |
if (TOCREATE_TERMINAL.equals(toCreate) || TOCREATE_NONTERMINAL.equals(toCreate)) { |
| 271 |
|
|
| 272 |
|
|
| 273 |
26 |
isSpace = !TOCREATE_TERMINAL.equals(toCreate); |
| 274 |
31 |
} else if (templateProvider != null) { |
| 275 |
|
|
| 276 |
|
|
| 277 |
7 |
boolean providerTerminal = getTemplateProviderTerminalValue(); |
| 278 |
7 |
isSpace = !providerTerminal; |
| 279 |
|
} else { |
| 280 |
|
|
| 281 |
24 |
isSpace = true; |
| 282 |
|
} |
| 283 |
|
} |
| 284 |
|
} |
| 285 |
|
} |
| 286 |
|
|
| 287 |
|
|
| 288 |
|
@param |
| 289 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (24) |
Complexity: 6 |
Complexity Density: 0.38 |
|
| 290 |
34 |
private void processNewDocument(String toCreate)... |
| 291 |
|
{ |
| 292 |
|
|
| 293 |
34 |
spaceReference = document.getDocumentReference().getLastSpaceReference(); |
| 294 |
34 |
name = document.getDocumentReference().getName(); |
| 295 |
|
|
| 296 |
|
|
| 297 |
34 |
EntityReference parentSpaceReference = spaceReference.getParent(); |
| 298 |
34 |
boolean isTopLevelSpace = parentSpaceReference.extractReference(EntityType.SPACE) == null; |
| 299 |
|
|
| 300 |
|
|
| 301 |
34 |
String originalName = name; |
| 302 |
|
|
| 303 |
|
|
| 304 |
34 |
if (WEBHOME.equals(name)) { |
| 305 |
|
|
| 306 |
24 |
name = spaceReference.getName(); |
| 307 |
|
|
| 308 |
|
|
| 309 |
24 |
if (!isTopLevelSpace) { |
| 310 |
|
|
| 311 |
19 |
spaceReference = new SpaceReference(parentSpaceReference); |
| 312 |
|
} else { |
| 313 |
|
|
| 314 |
|
|
| 315 |
|
|
| 316 |
5 |
spaceReference = null; |
| 317 |
|
} |
| 318 |
|
} |
| 319 |
|
|
| 320 |
|
|
| 321 |
|
|
| 322 |
34 |
if (TOCREATE_TERMINAL.equals(toCreate) || TOCREATE_NONTERMINAL.equals(toCreate)) { |
| 323 |
|
|
| 324 |
|
|
| 325 |
14 |
isSpace = !TOCREATE_TERMINAL.equals(toCreate); |
| 326 |
20 |
} else if (templateProvider != null) { |
| 327 |
|
|
| 328 |
|
|
| 329 |
5 |
boolean providerTerminal = getTemplateProviderTerminalValue(); |
| 330 |
5 |
isSpace = !providerTerminal; |
| 331 |
|
} else { |
| 332 |
|
|
| 333 |
15 |
isSpace = WEBHOME.equals(originalName); |
| 334 |
|
} |
| 335 |
|
} |
| 336 |
|
|
| 337 |
|
|
| 338 |
|
@return |
| 339 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
| 340 |
12 |
private boolean getTemplateProviderTerminalValue()... |
| 341 |
|
{ |
| 342 |
12 |
boolean providerTerminal; |
| 343 |
12 |
int providerTerminalValue = templateProvider.getIntValue(TP_TERMINAL_PROPERTY, -1); |
| 344 |
12 |
if (providerTerminalValue == -1) { |
| 345 |
|
|
| 346 |
|
|
| 347 |
2 |
String providerType = templateProvider.getStringValue(TP_TYPE_PROPERTY); |
| 348 |
2 |
if (TP_TYPE_PROPERTY_SPACE_VALUE.equals(providerType)) { |
| 349 |
1 |
providerTerminal = false; |
| 350 |
|
} else { |
| 351 |
|
|
| 352 |
1 |
providerTerminal = true; |
| 353 |
|
} |
| 354 |
|
} else { |
| 355 |
|
|
| 356 |
10 |
providerTerminal = (1 == providerTerminalValue); |
| 357 |
|
} |
| 358 |
12 |
return providerTerminal; |
| 359 |
|
} |
| 360 |
|
|
| 361 |
|
|
| 362 |
|
@param |
| 363 |
|
|
| |
|
| 91.7% |
Uncovered Elements: 1 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
| 364 |
7 |
private void processDeprecatedParameters(String toCreate)... |
| 365 |
|
{ |
| 366 |
|
|
| 367 |
|
|
| 368 |
7 |
String spaceParameter = request.getParameter(SPACE); |
| 369 |
|
|
| 370 |
7 |
isSpace = TOCREATE_SPACE.equals(toCreate); |
| 371 |
7 |
if (isSpace) { |
| 372 |
|
|
| 373 |
4 |
spaceReference = null; |
| 374 |
4 |
name = spaceParameter; |
| 375 |
|
} else { |
| 376 |
3 |
if (StringUtils.isNotEmpty(spaceParameter)) { |
| 377 |
|
|
| 378 |
3 |
spaceReference = new SpaceReference(spaceParameter, document.getDocumentReference().getWikiReference()); |
| 379 |
|
} |
| 380 |
|
|
| 381 |
3 |
name = request.getParameter(PAGE); |
| 382 |
|
} |
| 383 |
|
} |
| 384 |
|
|
| 385 |
|
|
| 386 |
|
@param |
| 387 |
|
@return |
| 388 |
|
@throws |
| 389 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
| 390 |
98 |
private BaseObject getTemplateProvider(DocumentReference templateProviderClass) throws XWikiException... |
| 391 |
|
{ |
| 392 |
98 |
BaseObject result = null; |
| 393 |
|
|
| 394 |
|
|
| 395 |
98 |
DocumentReferenceResolver<String> referenceResolver = |
| 396 |
|
Utils.getComponent(DocumentReferenceResolver.TYPE_STRING, CURRENT_MIXED_RESOLVER_HINT); |
| 397 |
|
|
| 398 |
|
|
| 399 |
98 |
String templateProviderDocReferenceString = request.getParameter(TEMPLATE_PROVIDER); |
| 400 |
|
|
| 401 |
98 |
if (!StringUtils.isEmpty(templateProviderDocReferenceString)) { |
| 402 |
|
|
| 403 |
22 |
DocumentReference templateProviderRef = referenceResolver.resolve(templateProviderDocReferenceString); |
| 404 |
|
|
| 405 |
22 |
XWikiDocument templateProviderDoc = context.getWiki().getDocument(templateProviderRef, context); |
| 406 |
22 |
result = templateProviderDoc.getXObject(templateProviderClass); |
| 407 |
|
} |
| 408 |
|
|
| 409 |
98 |
return result; |
| 410 |
|
} |
| 411 |
|
|
| 412 |
|
|
| 413 |
|
@param |
| 414 |
|
@param |
| 415 |
|
@param |
| 416 |
|
@return@link |
| 417 |
|
|
| |
|
| 94.1% |
Uncovered Elements: 1 (17) |
Complexity: 3 |
Complexity Density: 0.2 |
|
| 418 |
98 |
private List<Document> loadAvailableTemplateProviders(SpaceReference spaceReference,... |
| 419 |
|
DocumentReference templateClassReference, XWikiContext context) |
| 420 |
|
{ |
| 421 |
98 |
XWiki wiki = context.getWiki(); |
| 422 |
98 |
List<Document> templates = new ArrayList<Document>(); |
| 423 |
98 |
try { |
| 424 |
|
|
| 425 |
98 |
DocumentReferenceResolver<String> resolver = |
| 426 |
|
Utils.getComponent(DocumentReferenceResolver.TYPE_STRING, CURRENT_MIXED_RESOLVER_HINT); |
| 427 |
|
|
| 428 |
98 |
QueryManager queryManager = Utils.getComponent((Type) QueryManager.class, "secure"); |
| 429 |
98 |
Query query = |
| 430 |
|
queryManager.createQuery("from doc.object(XWiki.TemplateProviderClass) as template " |
| 431 |
|
+ "where doc.fullName not like 'XWiki.TemplateProviderTemplate' " + "order by template.name", |
| 432 |
|
Query.XWQL); |
| 433 |
|
|
| 434 |
|
|
| 435 |
|
|
| 436 |
|
|
| 437 |
|
|
| 438 |
98 |
List<String> templateProviderDocNames = query.execute(); |
| 439 |
98 |
for (String templateProviderName : templateProviderDocNames) { |
| 440 |
|
|
| 441 |
36 |
DocumentReference reference = resolver.resolve(templateProviderName); |
| 442 |
36 |
XWikiDocument templateDoc = wiki.getDocument(reference, context); |
| 443 |
36 |
BaseObject templateObject = templateDoc.getXObject(templateClassReference); |
| 444 |
|
|
| 445 |
|
|
| 446 |
36 |
if (isTemplateProviderAllowedInSpace(templateObject, spaceReference, |
| 447 |
|
TP_VISIBILITY_RESTRICTIONS_PROPERTY)) { |
| 448 |
|
|
| 449 |
35 |
templates.add(new Document(templateDoc, context)); |
| 450 |
|
} |
| 451 |
|
} |
| 452 |
|
} catch (Exception e) { |
| 453 |
0 |
LOGGER.warn("There was an error getting the available templates for space {0}", spaceReference, e); |
| 454 |
|
} |
| 455 |
|
|
| 456 |
98 |
return templates; |
| 457 |
|
} |
| 458 |
|
|
| |
|
| 88.2% |
Uncovered Elements: 2 (17) |
Complexity: 6 |
Complexity Density: 0.55 |
|
| 459 |
58 |
private boolean isTemplateProviderAllowedInSpace(BaseObject templateObject, SpaceReference spaceReference,... |
| 460 |
|
String restrictionsProperty) |
| 461 |
|
{ |
| 462 |
|
|
| 463 |
58 |
if (TP_CREATION_RESTRICTIONS_PROPERTY.equals(restrictionsProperty) |
| 464 |
|
&& templateObject.getIntValue(TP_CREATION_RESTRICTIONS_ARE_SUGGESTIONS_PROPERTY, 0) == 1) { |
| 465 |
0 |
return true; |
| 466 |
|
} |
| 467 |
|
|
| 468 |
|
|
| 469 |
58 |
List<String> restrictions = getTemplateProviderRestrictions(templateObject, restrictionsProperty); |
| 470 |
58 |
if (restrictions.size() > 0) { |
| 471 |
7 |
EntityReferenceSerializer<String> localSerializer = |
| 472 |
|
Utils.getComponent(EntityReferenceSerializer.TYPE_STRING, LOCAL_SERIALIZER_HINT); |
| 473 |
7 |
String spaceStringReference = localSerializer.serialize(spaceReference); |
| 474 |
|
|
| 475 |
7 |
for (String allowedSpace : restrictions) { |
| 476 |
|
|
| 477 |
7 |
if (allowedSpace.equals(spaceStringReference) |
| 478 |
|
|| StringUtils.startsWith(spaceStringReference, String.format("%s.", allowedSpace))) { |
| 479 |
3 |
return true; |
| 480 |
|
} |
| 481 |
|
} |
| 482 |
|
|
| 483 |
|
|
| 484 |
4 |
return false; |
| 485 |
|
} |
| 486 |
|
|
| 487 |
|
|
| 488 |
51 |
return true; |
| 489 |
|
} |
| 490 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 491 |
61 |
private List<String> getTemplateProviderRestrictions(BaseObject templateObject, String restrictionsProperty)... |
| 492 |
|
{ |
| 493 |
61 |
List<String> creationRestrictions = templateObject.getListValue(restrictionsProperty); |
| 494 |
61 |
if (creationRestrictions.size() == 0) { |
| 495 |
|
|
| 496 |
|
|
| 497 |
51 |
creationRestrictions = templateObject.getListValue(SPACES_PROPERTY); |
| 498 |
|
} |
| 499 |
61 |
return creationRestrictions; |
| 500 |
|
} |
| 501 |
|
|
| 502 |
|
|
| 503 |
|
@return |
| 504 |
|
|
| 505 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (26) |
Complexity: 7 |
Complexity Density: 0.44 |
|
| 506 |
98 |
public DocumentReference getNewDocumentReference()... |
| 507 |
|
{ |
| 508 |
98 |
DocumentReference result = null; |
| 509 |
|
|
| 510 |
98 |
if (StringUtils.isEmpty(name)) { |
| 511 |
|
|
| 512 |
18 |
return null; |
| 513 |
|
} |
| 514 |
|
|
| 515 |
|
|
| 516 |
80 |
SpaceReference newSpaceReference = spaceReference; |
| 517 |
80 |
String newName = name; |
| 518 |
|
|
| 519 |
|
|
| 520 |
80 |
if (isSpace) { |
| 521 |
56 |
EntityReference parentSpaceReference = spaceReference; |
| 522 |
56 |
if (parentSpaceReference == null) { |
| 523 |
13 |
parentSpaceReference = context.getDoc().getDocumentReference().getWikiReference(); |
| 524 |
|
} |
| 525 |
|
|
| 526 |
|
|
| 527 |
56 |
newSpaceReference = new SpaceReference(name, parentSpaceReference); |
| 528 |
|
|
| 529 |
|
|
| 530 |
|
|
| 531 |
56 |
newName = WEBHOME; |
| 532 |
|
} |
| 533 |
|
|
| 534 |
|
|
| 535 |
|
|
| 536 |
80 |
if (newSpaceReference == null) { |
| 537 |
|
|
| 538 |
|
|
| 539 |
1 |
return null; |
| 540 |
|
} |
| 541 |
|
|
| 542 |
|
|
| 543 |
|
|
| 544 |
|
|
| 545 |
|
|
| 546 |
|
|
| 547 |
79 |
if (hasTemplate() || availableTemplateProviders.isEmpty()) { |
| 548 |
76 |
result = new DocumentReference(newName, newSpaceReference); |
| 549 |
|
} |
| 550 |
|
|
| 551 |
79 |
return result; |
| 552 |
|
} |
| 553 |
|
|
| 554 |
|
|
| 555 |
|
@return |
| 556 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 557 |
94 |
public boolean hasTemplate()... |
| 558 |
|
{ |
| 559 |
94 |
return request.getParameter(TEMPLATE_PROVIDER) != null || request.getParameter(TEMPLATE) != null; |
| 560 |
|
} |
| 561 |
|
|
| 562 |
|
|
| 563 |
|
|
| 564 |
|
|
| 565 |
|
|
| 566 |
|
@return |
| 567 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
| 568 |
76 |
public boolean isTemplateProviderAllowedToCreateInCurrentSpace()... |
| 569 |
|
{ |
| 570 |
|
|
| 571 |
|
|
| 572 |
|
|
| 573 |
76 |
if (templateProvider != null) { |
| 574 |
|
|
| 575 |
22 |
if (!isTemplateProviderAllowedInSpace(templateProvider, spaceReference, |
| 576 |
|
TP_CREATION_RESTRICTIONS_PROPERTY)) { |
| 577 |
|
|
| 578 |
3 |
Object[] args = {templateProvider.getStringValue(TEMPLATE), spaceReference, name}; |
| 579 |
3 |
XWikiException exception = |
| 580 |
|
new XWikiException(XWikiException.MODULE_XWIKI_STORE, |
| 581 |
|
XWikiException.ERROR_XWIKI_APP_TEMPLATE_NOT_AVAILABLE, |
| 582 |
|
"Template {0} cannot be used in space {1} when creating page {2}", null, args); |
| 583 |
|
|
| 584 |
3 |
ScriptContext scontext = getCurrentScriptContext(); |
| 585 |
3 |
scontext.setAttribute(EXCEPTION, exception, ScriptContext.ENGINE_SCOPE); |
| 586 |
3 |
scontext.setAttribute("createAllowedSpaces", |
| 587 |
|
getTemplateProviderRestrictions(templateProvider, TP_CREATION_RESTRICTIONS_PROPERTY), |
| 588 |
|
ScriptContext.ENGINE_SCOPE); |
| 589 |
|
|
| 590 |
3 |
return false; |
| 591 |
|
} |
| 592 |
|
} |
| 593 |
|
|
| 594 |
|
|
| 595 |
73 |
return true; |
| 596 |
|
} |
| 597 |
|
|
| 598 |
|
|
| 599 |
|
@param |
| 600 |
|
@return |
| 601 |
|
|
| 602 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
| 603 |
73 |
public boolean isDocumentAlreadyExisting(XWikiDocument newDocument)... |
| 604 |
|
{ |
| 605 |
|
|
| 606 |
|
|
| 607 |
73 |
if (!isEmptyDocument(newDocument)) { |
| 608 |
4 |
ScriptContext scontext = getCurrentScriptContext(); |
| 609 |
|
|
| 610 |
|
|
| 611 |
|
|
| 612 |
4 |
scontext.setAttribute("existingDocumentReference", newDocument.getDocumentReference(), |
| 613 |
|
ScriptContext.ENGINE_SCOPE); |
| 614 |
|
|
| 615 |
|
|
| 616 |
4 |
Object[] args = {newDocument.getDocumentReference()}; |
| 617 |
4 |
XWikiException documentAlreadyExists = |
| 618 |
|
new XWikiException(XWikiException.MODULE_XWIKI_STORE, |
| 619 |
|
XWikiException.ERROR_XWIKI_APP_DOCUMENT_NOT_EMPTY, |
| 620 |
|
"Cannot create document {0} because it already has content", null, args); |
| 621 |
4 |
scontext.setAttribute(EXCEPTION, documentAlreadyExists, ScriptContext.ENGINE_SCOPE); |
| 622 |
|
|
| 623 |
4 |
return true; |
| 624 |
|
} |
| 625 |
|
|
| 626 |
69 |
return false; |
| 627 |
|
} |
| 628 |
|
|
| 629 |
|
|
| 630 |
|
|
| 631 |
|
|
| 632 |
|
|
| 633 |
|
|
| 634 |
|
@param |
| 635 |
|
@return |
| 636 |
|
|
| 637 |
|
|
| |
|
| 50% |
Uncovered Elements: 8 (16) |
Complexity: 7 |
Complexity Density: 0.7 |
|
| 638 |
73 |
private boolean isEmptyDocument(XWikiDocument document)... |
| 639 |
|
{ |
| 640 |
|
|
| 641 |
73 |
if (document.isNew() || document.getXObject(REDIRECT_CLASS) != null) { |
| 642 |
69 |
return true; |
| 643 |
|
} |
| 644 |
|
|
| 645 |
|
|
| 646 |
|
|
| 647 |
|
|
| 648 |
|
|
| 649 |
4 |
String content = document.getContent(); |
| 650 |
4 |
if (!content.equals("\n") && !content.equals("") && !content.equals("\\\\")) { |
| 651 |
4 |
return false; |
| 652 |
|
} |
| 653 |
|
|
| 654 |
|
|
| 655 |
|
|
| 656 |
0 |
for (Map.Entry<DocumentReference, List<BaseObject>> objList : document.getXObjects().entrySet()) { |
| 657 |
0 |
for (BaseObject obj : objList.getValue()) { |
| 658 |
0 |
if (obj != null) { |
| 659 |
0 |
return false; |
| 660 |
|
} |
| 661 |
|
} |
| 662 |
|
} |
| 663 |
|
|
| 664 |
0 |
return true; |
| 665 |
|
} |
| 666 |
|
|
| 667 |
|
|
| 668 |
|
@return@link |
| 669 |
|
@deprecated@link |
| 670 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 671 |
0 |
@Deprecated... |
| 672 |
|
public VelocityContext getVelocityContext() |
| 673 |
|
{ |
| 674 |
0 |
return Utils.getComponent(VelocityManager.class).getVelocityContext(); |
| 675 |
|
} |
| 676 |
|
|
| 677 |
|
|
| 678 |
|
@return |
| 679 |
|
@since |
| 680 |
|
|
| |
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 681 |
7 |
protected ScriptContext getCurrentScriptContext()... |
| 682 |
|
{ |
| 683 |
7 |
if (this.scriptContextManager == null) { |
| 684 |
7 |
this.scriptContextManager = Utils.getComponent(ScriptContextManager.class); |
| 685 |
|
} |
| 686 |
|
|
| 687 |
7 |
return this.scriptContextManager.getCurrentScriptContext(); |
| 688 |
|
} |
| 689 |
|
|
| 690 |
|
|
| 691 |
|
@return |
| 692 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 693 |
98 |
public SpaceReference getSpaceReference()... |
| 694 |
|
{ |
| 695 |
98 |
return spaceReference; |
| 696 |
|
} |
| 697 |
|
|
| 698 |
|
|
| 699 |
|
@return@link |
| 700 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 701 |
98 |
public String getName()... |
| 702 |
|
{ |
| 703 |
98 |
return name; |
| 704 |
|
} |
| 705 |
|
|
| 706 |
|
|
| 707 |
|
@return |
| 708 |
|
|
| 709 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 710 |
156 |
public boolean isSpace()... |
| 711 |
|
{ |
| 712 |
156 |
return isSpace; |
| 713 |
|
} |
| 714 |
|
|
| 715 |
|
|
| 716 |
|
@return |
| 717 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 718 |
98 |
public List<Document> getAvailableTemplateProviders()... |
| 719 |
|
{ |
| 720 |
98 |
return availableTemplateProviders; |
| 721 |
|
} |
| 722 |
|
|
| 723 |
|
|
| 724 |
|
@return |
| 725 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 726 |
58 |
public BaseObject getTemplateProvider()... |
| 727 |
|
{ |
| 728 |
58 |
return templateProvider; |
| 729 |
|
} |
| 730 |
|
|
| 731 |
|
|
| 732 |
|
@return |
| 733 |
|
@since |
| 734 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 735 |
69 |
public String getType()... |
| 736 |
|
{ |
| 737 |
69 |
return type; |
| 738 |
|
} |
| 739 |
|
} |