use of org.xwiki.model.EntityType in project xwiki-platform by xwiki.
the class EntityResourceReferenceResolver method resolve.
@Override
public EntityResourceReference resolve(ExtendedURL extendedURL, ResourceType resourceType, Map<String, Object> parameters) throws CreateResourceReferenceException, UnsupportedResourceReferenceException {
EntityResourceReference entityURL;
// UC1: <action>/<entity reference type>/<entity reference>
// UC2: <action>/<entity reference> ==> type = page
// UC3: <entity reference> ==> type = page, action = view
List<String> pathSegments = extendedURL.getSegments();
String action = ACTION_VIEW;
EntityType entityType;
String entityReferenceAsString;
if (pathSegments.size() == 3) {
action = pathSegments.get(0);
entityType = computeEntityType(pathSegments.get(1));
entityReferenceAsString = pathSegments.get(2);
} else if (pathSegments.size() == 2) {
action = pathSegments.get(0);
entityType = computeDefaultEntityType(action);
entityReferenceAsString = pathSegments.get(1);
} else if (pathSegments.size() == 1) {
entityType = computeDefaultEntityType(action);
entityReferenceAsString = pathSegments.get(0);
} else {
throw new CreateResourceReferenceException(String.format("Invalid Entity URL [%s]", extendedURL.serialize()));
}
// Convert the string representation of the Entity reference into a proper EntityResourceReference.
entityURL = new EntityResourceReference(this.defaultEntityReferenceResolver.resolve(entityReferenceAsString, entityType), EntityResourceAction.fromString(action));
return entityURL;
}
Aggregations