Search in sources :

Example 6 with SpaceReference

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

the class CreateActionRequestHandler method processNewDocument.

/**
 * @param toCreate the value of the "tocreate" request parameter
 */
private void processNewDocument(String toCreate) {
    // Current space and page name.
    spaceReference = document.getDocumentReference().getLastSpaceReference();
    name = document.getDocumentReference().getName();
    // Determine if the current document is in a top-level space.
    EntityReference parentSpaceReference = spaceReference.getParent();
    boolean isTopLevelSpace = parentSpaceReference.extractReference(EntityType.SPACE) == null;
    // Remember this since we might update it below.
    String originalName = name;
    // Since WebHome is a convention, determine the real name and parent of our document.
    if (WEBHOME.equals(name)) {
        // Determine its name from the space name.
        name = spaceReference.getName();
        // Determine its space reference by looking at the space's parent.
        if (!isTopLevelSpace) {
            // The parent reference is a space reference. Use it.
            spaceReference = new SpaceReference(parentSpaceReference);
        } else {
            // Top level document, i.e. the parent reference is a wiki reference. Clear the spaceReference variable
            // so that this case is properly handled later on (as if an empty value was passed as parameter in the
            // request).
            spaceReference = null;
        }
    }
    if (TOCREATE_TERMINAL.equals(toCreate) || TOCREATE_NONTERMINAL.equals(toCreate)) {
        // Look at the request to see what the user wanted to create (terminal or non-terminal).
        isSpace = !TOCREATE_TERMINAL.equals(toCreate);
    } else if (templateProvider != null) {
        // A template provider is specified. Use it and extract the type of document.
        boolean providerTerminal = getTemplateProviderTerminalValue();
        isSpace = !providerTerminal;
    } else {
        // Last option is to check the document's original name and see if it was "WebHome".
        isSpace = WEBHOME.equals(originalName);
    }
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) EntityReference(org.xwiki.model.reference.EntityReference)

Example 7 with SpaceReference

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

the class CreateActionRequestHandler method getNewDocumentReference.

/**
 * @return the document reference of the new document to be created, {@code null} if a no document can be created
 *         (because the conditions are not met)
 */
public DocumentReference getNewDocumentReference() {
    DocumentReference result = null;
    if (StringUtils.isEmpty(name)) {
        // Can`t do anything without a name.
        return null;
    }
    // The new values, after the processing needed for ND below, to be used when creating the document reference.
    SpaceReference newSpaceReference = spaceReference;
    String newName = name;
    // Special handling for old spaces or new Nested Documents.
    if (isSpace) {
        EntityReference parentSpaceReference = spaceReference;
        if (parentSpaceReference == null) {
            parentSpaceReference = context.getDoc().getDocumentReference().getWikiReference();
        }
        // The new space's reference.
        newSpaceReference = new SpaceReference(name, parentSpaceReference);
        // The new document's name set to the new space's homepage. In Nested Documents, this leads to the new ND's
        // reference name.
        newName = WEBHOME;
    }
    if (newSpaceReference == null) {
        // documents can be top-level.
        return null;
    }
    // that there is no template is ok.
    if (hasTemplate() || availableTemplateProviders.isEmpty()) {
        result = new DocumentReference(newName, newSpaceReference);
    }
    return result;
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) EntityReference(org.xwiki.model.reference.EntityReference) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 8 with SpaceReference

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

the class R72001XWIKI12228DataMigration method createSpaces.

private void createSpaces(Collection<SpaceReference> spaces, boolean hidden, Session session) {
    // Create spaces in the xwikispace table
    for (SpaceReference spaceReference : spaces) {
        XWikiSpace space = new XWikiSpace(spaceReference);
        space.setHidden(hidden);
        session.save(space);
    }
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) XWikiSpace(com.xpn.xwiki.doc.XWikiSpace)

Example 9 with SpaceReference

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

the class R72001XWIKI12228DataMigration method getVisibleSpaces.

private Collection<SpaceReference> getVisibleSpaces(Session session) {
    Query query = session.createQuery(createSpaceQuery(false));
    Collection<SpaceReference> databaseSpaces = new ArrayList<>();
    for (String space : (List<String>) query.list()) {
        databaseSpaces.add(this.spaceResolver.resolve(space, WIKI));
    }
    // Resolve nested spaces
    Set<SpaceReference> spaces = new HashSet<>(databaseSpaces);
    for (SpaceReference space : databaseSpaces) {
        for (EntityReference parent = space.getParent(); parent instanceof SpaceReference; parent = parent.getParent()) {
            spaces.add((SpaceReference) parent);
        }
    }
    return spaces;
}
Also used : Query(org.hibernate.Query) SpaceReference(org.xwiki.model.reference.SpaceReference) ArrayList(java.util.ArrayList) EntityReference(org.xwiki.model.reference.EntityReference) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet)

Example 10 with SpaceReference

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

the class MoveJobTest method moveMissingDocument.

@Test
public void moveMissingDocument() throws Throwable {
    DocumentReference sourceReference = new DocumentReference("foo", "A", "Page");
    run(createRequest(sourceReference, new SpaceReference("B", new WikiReference("bar"))));
    verify(this.mocker.getMockedLogger()).warn("Skipping [{}] because it doesn't exist.", sourceReference);
    verifyNoMove();
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

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