Search in sources :

Example 11 with EntityReference

use of org.xwiki.model.reference.EntityReference in project xwiki-platform by xwiki.

the class DefaultLegacySpaceResolver method resolve.

@Override
public List<String> resolve(String spaceReferenceRepresentation) {
    List<String> spaceNames = new ArrayList<>();
    // Parse the spaces list into Space References
    EntityReference spaceReference = this.relativeEntityReferenceResolver.resolve(spaceReferenceRepresentation, EntityType.SPACE);
    for (EntityReference reference : spaceReference.getReversedReferenceChain()) {
        spaceNames.add(reference.getName());
    }
    return spaceNames;
}
Also used : ArrayList(java.util.ArrayList) EntityReference(org.xwiki.model.reference.EntityReference)

Example 12 with EntityReference

use of org.xwiki.model.reference.EntityReference in project xwiki-platform by xwiki.

the class CompactStringEntityReferenceSerializer method serializeEntityReferenceType.

/**
 * Serialize the last part of the reference (all the ending elements having the same entity type).
 *
 * @param reference the reference to serialize
 * @since 7.2M2
 */
protected void serializeEntityReferenceType(EntityReference reference, StringBuilder representation, boolean isLastReference) {
    EntityReference parent = reference.getParent();
    if (parent != null && parent.getType() == reference.getType()) {
        serializeEntityReferenceType(parent, representation, false);
    }
    super.serializeEntityReference(reference, representation, isLastReference);
}
Also used : EntityReference(org.xwiki.model.reference.EntityReference)

Example 13 with EntityReference

use of org.xwiki.model.reference.EntityReference 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();
}
Also used : EntityType(org.xwiki.model.EntityType) EntityReference(org.xwiki.model.reference.EntityReference)

Example 14 with EntityReference

use of org.xwiki.model.reference.EntityReference in project xwiki-platform by xwiki.

the class CompactStringEntityReferenceSerializer method equal.

protected boolean equal(EntityReference defaultReference, EntityReference currentReference) {
    EntityReference defaultReferenceIt = defaultReference;
    EntityReference currentReferenceIt = currentReference;
    for (; defaultReferenceIt != null; defaultReferenceIt = defaultReferenceIt.getParent(), currentReferenceIt = currentReferenceIt.getParent()) {
        if (currentReferenceIt == null || defaultReferenceIt.getType() != currentReferenceIt.getType() || !defaultReferenceIt.getName().equals(currentReferenceIt.getName())) {
            return false;
        }
    }
    return true;
}
Also used : EntityReference(org.xwiki.model.reference.EntityReference)

Example 15 with EntityReference

use of org.xwiki.model.reference.EntityReference in project xwiki-platform by xwiki.

the class CurrentSpaceReferenceProvider method get.

@Override
public SpaceReference get() {
    EntityReference currentWiki = this.wikiReferenceProvider.get();
    EntityReference currentSpace = this.provider.getDefaultReference(EntityType.SPACE);
    // The provided space entity has no wiki parent set. Re-create the space reference chain and set the current
    // wiki as the root.
    EntityReference result = currentWiki;
    for (EntityReference spaceReference : currentSpace.getReversedReferenceChain()) {
        result = new SpaceReference(spaceReference.getName(), result);
    }
    return (SpaceReference) result;
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) EntityReference(org.xwiki.model.reference.EntityReference)

Aggregations

EntityReference (org.xwiki.model.reference.EntityReference)338 Test (org.junit.Test)157 DocumentReference (org.xwiki.model.reference.DocumentReference)107 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)39 BaseObject (com.xpn.xwiki.objects.BaseObject)38 ArrayList (java.util.ArrayList)27 XWikiContext (com.xpn.xwiki.XWikiContext)24 WikiReference (org.xwiki.model.reference.WikiReference)24 SpaceReference (org.xwiki.model.reference.SpaceReference)23 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)18 XWikiException (com.xpn.xwiki.XWikiException)17 EntityType (org.xwiki.model.EntityType)11 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)10 EntityReferenceProvider (org.xwiki.model.reference.EntityReferenceProvider)9 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)8 XDOM (org.xwiki.rendering.block.XDOM)8 URL (java.net.URL)7 AttachmentReference (org.xwiki.model.reference.AttachmentReference)7 HashMap (java.util.HashMap)6 Before (org.junit.Before)6