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