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;
}
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);
}
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();
}
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;
}
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;
}
Aggregations