use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.
the class EventAndFactoryTest method testSpace.
@Test
public void testSpace() {
Assert.assertNull(this.defaultEvent.getSpace());
DocumentReference doc = new DocumentReference("wiki1", "Space1", "Page");
SpaceReference space = new SpaceReference("Space2", new WikiReference("wiki2"));
this.defaultEvent.setDocument(doc);
Assert.assertEquals(doc.getLastSpaceReference(), this.defaultEvent.getSpace());
Assert.assertEquals("Space1", this.defaultEvent.getSpace().getName());
this.defaultEvent.setSpace(space);
Assert.assertEquals(space, this.defaultEvent.getSpace());
Assert.assertEquals("Space2", this.defaultEvent.getSpace().getName());
this.defaultEvent.setSpace(null);
Assert.assertEquals(doc.getLastSpaceReference(), this.defaultEvent.getSpace());
this.defaultEvent.setDocument(null);
Assert.assertNull(this.defaultEvent.getSpace());
Assert.assertNull(this.rawEvent.getSpace());
}
use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.
the class EventAndFactoryTest method testWiki.
@Test
public void testWiki() {
Assert.assertNull(this.defaultEvent.getWiki());
DocumentReference doc = new DocumentReference("wiki1", "Space1", "Page");
SpaceReference space = new SpaceReference("Space2", new WikiReference("wiki2"));
WikiReference wiki = new WikiReference("wiki3");
this.defaultEvent.setDocument(doc);
Assert.assertEquals(doc.getWikiReference(), this.defaultEvent.getWiki());
Assert.assertEquals("wiki1", this.defaultEvent.getWiki().getName());
this.defaultEvent.setSpace(space);
Assert.assertEquals(space.getRoot(), this.defaultEvent.getWiki());
Assert.assertEquals("wiki2", this.defaultEvent.getWiki().getName());
this.defaultEvent.setWiki(wiki);
Assert.assertEquals(wiki, this.defaultEvent.getWiki());
Assert.assertEquals("wiki3", this.defaultEvent.getWiki().getName());
this.defaultEvent.setWiki(null);
Assert.assertEquals(space.getRoot(), this.defaultEvent.getWiki());
this.defaultEvent.setSpace(null);
Assert.assertEquals(doc.getWikiReference(), this.defaultEvent.getWiki());
this.defaultEvent.setDocument(null);
Assert.assertNull(this.defaultEvent.getWiki());
Assert.assertNull(this.rawEvent.getWiki());
}
use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.
the class WikiTreeNode method getChildren.
@Override
protected List<? extends EntityReference> getChildren(WikiReference wikiReference, int offset, int limit) throws QueryException {
List<String> constraints = new ArrayList<String>();
constraints.add("parent is null");
if (!areHiddenEntitiesShown()) {
constraints.add("hidden <> true");
}
String statement = StringUtils.join(Arrays.asList("select name from XWikiSpace", whereClause(constraints), "order by lower(name), name"), ' ');
Query query = this.queryManager.createQuery(statement, Query.HQL);
query.setWiki(wikiReference.getName());
query.setOffset(offset);
query.setLimit(limit);
List<SpaceReference> spaceReferences = new ArrayList<SpaceReference>();
for (Object result : query.execute()) {
String name = (String) result;
spaceReferences.add(new SpaceReference(name, wikiReference));
}
return spaceReferences;
}
use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.
the class DocumentReferenceResolverFilter method filterResults.
@Override
public List<?> filterResults(@SuppressWarnings("rawtypes") List results) {
String defaultDocumentName = this.defaultEntityReferenceProvider.getDefaultReference(EntityType.DOCUMENT).getName();
List<DocumentReference> documentReferences = new ArrayList<DocumentReference>();
for (Object result : results) {
String reference = (String) ((Object[]) result)[0];
boolean terminal = toBoolean(((Object[]) result)[1]);
if (terminal) {
documentReferences.add(this.currentDocumentReferenceResolver.resolve(reference));
} else {
SpaceReference spaceReference = this.currentSpaceReferenceResolver.resolve(reference);
documentReferences.add(new DocumentReference(defaultDocumentName, spaceReference));
}
}
return documentReferences;
}
use of org.xwiki.model.reference.SpaceReference 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