use of org.xwiki.model.EntityType in project xwiki-platform by xwiki.
the class AbstractExtensionValidator method checkAccess.
protected void checkAccess(Right entityRight, String namespaceString, Request request) throws AccessDeniedException {
Namespace namespace = NamespaceUtils.toNamespace(namespaceString);
// Root namespace
if (namespace == null) {
checkRootRight(entityRight, request);
return;
}
if (namespace.getType() != null) {
// User
if (namespace.getType().equals("user")) {
EntityReference reference = this.resolver.resolve(namespace.getValue(), EntityType.DOCUMENT);
checkUserRight(reference, request);
return;
}
// Entity
EntityType entityType = EnumUtils.getEnum(EntityType.class, namespace.getType().toUpperCase());
if (entityType != null) {
EntityReference reference = this.resolver.resolve(namespace.getValue(), entityType);
checkAccess(reference, entityRight, request);
return;
}
}
// Unknown namespace
checkNamespaceRight(namespace, Right.PROGRAM, request);
}
use of org.xwiki.model.EntityType in project xwiki-platform by xwiki.
the class CompactStringEntityReferenceSerializer method serialize.
@Override
public String serialize(EntityReference reference, Object... parameters) {
if (reference == null) {
return null;
}
StringBuilder representation = new StringBuilder();
List<EntityReference> references = reference.getReversedReferenceChain();
for (int i = 0; i < references.size(); ) {
EntityReference currentReference = references.get(i);
EntityType currentType = currentReference.getType();
// Move to last element of the same type
while (++i < references.size() && references.get(i).getType() == currentType) {
currentReference = references.get(i);
}
if (shouldSerialize(currentReference, representation, currentReference == reference, parameters)) {
serializeEntityReferenceType(currentReference, representation, currentReference == reference);
}
}
return representation.toString();
}
use of org.xwiki.model.EntityType in project xwiki-platform by xwiki.
the class AbstractEntityJob method visitDocumentNodes.
private void visitDocumentNodes(EntityReferenceTreeNode node, Visitor<DocumentReference> visitor) {
if (node != null) {
EntityReference nodeReference = node.getReference();
EntityType nodeType = nodeReference != null ? nodeReference.getType() : null;
if (nodeType == EntityType.SPACE || nodeType == EntityType.WIKI || nodeType == null) {
// A node that corresponds to an entity that can contain documents.
visitDocumentAncestor(node, visitor);
} else if (nodeType == EntityType.DOCUMENT) {
visitor.visit((DocumentReference) node.getReference());
}
}
}
use of org.xwiki.model.EntityType in project xwiki-platform by xwiki.
the class TestAccessRuleFactory method getNewInstance.
@Override
TestAccessRule getNewInstance(ElementParser parser, String name, TestEntity parent, Attributes attributes) {
EntityReference userRef = parser.getResolver().resolve(attributes.getValue("name"), DefaultTestDocument.TYPE, new EntityReference(XWikiConstants.XWIKI_SPACE, EntityType.SPACE, parent.getReference().getRoot()));
Boolean allow = name.startsWith("allow");
String type = attributes.getValue("type");
String user = parser.getSerializer().serialize(userRef);
Boolean isUser = name.endsWith("User");
if (type != null) {
Right right = Right.toRight(type);
new DefaultTestAccessRule(user, userRef, right, allow, isUser, parent);
} else {
EntityType parentType = parent.getType();
if (parentType == EntityType.WIKI && ((TestWiki) parent).isMainWiki()) {
// Null here means root (or farm)
parentType = null;
}
for (Right right : Right.getEnabledRights(parentType)) {
if (right != Right.CREATOR) {
new DefaultTestAccessRule(user, userRef, right, allow, isUser, parent);
}
}
}
return null;
}
use of org.xwiki.model.EntityType in project xwiki-platform by xwiki.
the class AbstractEntityResourceReferenceResolver method buildEntityReference.
/**
* Normalize the extracted space/page to resolve empty/null values and replace them with default values.
*
* @param wikiReference the wiki reference as extracted from the URL
* @param spaceNames the space names as extracted from the URL (can be empty or null)
* @param pageName the page name as extracted from the URL (can be empty or null)
* @param attachmentName the attachment name as extracted from the URL (can be empty or null)
* @return the absolute Entity Reference
*/
private EntityReference buildEntityReference(WikiReference wikiReference, List<String> spaceNames, String pageName, String attachmentName) {
EntityReference reference = wikiReference;
EntityType entityType = EntityType.DOCUMENT;
if (spaceNames != null && !spaceNames.isEmpty()) {
EntityReference parent = reference;
for (String spaceName : spaceNames) {
if (!StringUtils.isEmpty(spaceName)) {
reference = new EntityReference(spaceName, EntityType.SPACE, parent);
parent = reference;
}
}
}
if (!StringUtils.isEmpty(pageName)) {
reference = new EntityReference(pageName, EntityType.DOCUMENT, reference);
}
if (!StringUtils.isEmpty(attachmentName)) {
reference = new EntityReference(attachmentName, EntityType.ATTACHMENT, reference);
entityType = EntityType.ATTACHMENT;
}
return this.defaultReferenceEntityReferenceResolver.resolve(reference, entityType);
}
Aggregations