Search in sources :

Example 1 with SpaceReference

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());
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 2 with SpaceReference

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());
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 3 with SpaceReference

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;
}
Also used : Query(org.xwiki.query.Query) SpaceReference(org.xwiki.model.reference.SpaceReference) ArrayList(java.util.ArrayList)

Example 4 with SpaceReference

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;
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) ArrayList(java.util.ArrayList) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 5 with SpaceReference

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

Aggregations

SpaceReference (org.xwiki.model.reference.SpaceReference)142 DocumentReference (org.xwiki.model.reference.DocumentReference)96 Test (org.junit.Test)83 WikiReference (org.xwiki.model.reference.WikiReference)58 EntityReference (org.xwiki.model.reference.EntityReference)24 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)21 ArrayList (java.util.ArrayList)11 ResourceReference (org.xwiki.rendering.listener.reference.ResourceReference)11 XWikiException (com.xpn.xwiki.XWikiException)9 QueryRestrictionGroup (com.celements.search.lucene.query.QueryRestrictionGroup)8 Expectations (org.jmock.Expectations)8 XWikiContext (com.xpn.xwiki.XWikiContext)7 DocumentAccessBridge (org.xwiki.bridge.DocumentAccessBridge)7 DefaultComponentDescriptor (org.xwiki.component.descriptor.DefaultComponentDescriptor)7 ComponentManager (org.xwiki.component.manager.ComponentManager)7 NamespacedComponentManager (org.xwiki.component.manager.NamespacedComponentManager)7 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)7 EntityReferenceResolver (org.xwiki.model.reference.EntityReferenceResolver)7 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)7 DocumentResourceReference (org.xwiki.rendering.listener.reference.DocumentResourceReference)7