@Override public SpaceReference getSpace() { SpaceReference result = null; if (this.space != null) { result = this.space; } else if (this.document != null) { result = this.document.getLastSpaceReference(); } return result; }
/** * Note that this method cannot be removed for now since it's used by Hibernate for saving a XWikiDocument. * * @return the name of the space of the document * @deprecated since 2.2M1 used {@link #getDocumentReference()} instead */ @Deprecated public String getSpace() { return getDocumentReference().getLastSpaceReference().getName(); }
@Override public Iterator<ConfigurationSource> iterator() { XWikiContext xcontext = this.xcontextProvider.get(); if (xcontext != null) { XWikiDocument currentDocument = xcontext.getDoc(); if (currentDocument != null) { return new SpaceIterator(currentDocument.getDocumentReference().getLastSpaceReference()); } } return Collections.<ConfigurationSource>emptyList().iterator(); }
/** * Note that this method cannot be removed for now since it's used by Hibernate for loading a XWikiDocument. * * @deprecated since 2.2M1 used {@link #setDocumentReference(DocumentReference)} instead */ @Deprecated public void setSpace(String space) { if (space != null) { getDocumentReference().getLastSpaceReference().setName(space); // Clean the absolute parent reference cache to rebuild it next time getParentReference is called. this.parentReferenceCache = null; } }
/** * return the name of the space of the document for example if the fullName of a document is "MySpace.Mydoc", the * name is MySpace. * * @return the name of the space of the document */ public String getSpace() { return this.doc.getDocumentReference().getLastSpaceReference().getName(); }
protected void process(DocumentReference source, DocumentReference destination) { if (this.request.isDeep() && isSpaceHomeReference(source)) { if (isSpaceHomeReference(destination)) { // Rename an entire space. process(source.getLastSpaceReference(), destination.getLastSpaceReference()); } else { this.logger.error("You cannot transform a non-terminal document [{}] into a terminal document [{}]" + " and preserve its child documents at the same time.", source, destination); } } else { maybeMove(source, destination); } }
@Override public ExtendedURL serialize(TemporaryResourceReference resource) throws SerializeResourceReferenceException, UnsupportedResourceReferenceException { DocumentReference owningReference = (DocumentReference) resource.getOwningEntityReference(); List<String> segments = new LinkedList<>(); segments.add("temp"); segments.add(owningReference.getLastSpaceReference().getName()); segments.add(owningReference.getName()); segments.add(resource.getModuleId()); segments.add(resource.getResourceName()); ExtendedURL result = new ExtendedURL(segments, new HashMap<String, List<String>>()); return this.extendedURLNormalizer.normalize(result); } }
/** * @return The space in which the event happened. */ public String getSpace() { SpaceReference spaceReference = getDocumentReference().getLastSpaceReference(); return getLocalSerializer().serialize(spaceReference); }
/** * @return The space, prefixed with the wiki name, in which the event happened (example: "xwiki:Main"). */ public String getPrefixedSpace() { SpaceReference spaceReference = getDocumentReference().getLastSpaceReference(); return getSerializer().serialize(spaceReference); }
private void getEntities(DocumentReference documentReference) { if (this.request.isDeep() && isSpaceHomeReference(documentReference)) { getEntities(documentReference.getLastSpaceReference()); } else { this.concernedEntities.put(documentReference, new EntitySelection(documentReference)); } }
private String getEmail(DocumentReference userDocument) { String email = ""; try { XWikiDocument doc = (XWikiDocument) this.bridge.getDocument(userDocument); // TODO after projects is merged: UsersAndGroups.getType(userDocument).equals(UsersAndGroups.GROUP) if ("Groups".equals(userDocument.getLastSpaceReference().getName())) { email = doc.getStringValue(GROUP_EMAIL); } else { email = doc.getStringValue(EMAIL); } } catch (Exception e) { } return email; }
private void process(DocumentReference documentReference) { if (this.request.isDeep() && isSpaceHomeReference(documentReference)) { process(documentReference.getLastSpaceReference()); } else { maybeDelete(documentReference); } }
/** * {@inheritDoc} * * @see DocumentAccessBridge#getDocumentName(String) */ @Deprecated public org.xwiki.bridge.DocumentName getDocumentName(String documentReference) { DocumentReference docReference = this.currentMixedDocumentReferenceResolver.resolve(documentReference); return new org.xwiki.bridge.DocumentName(docReference.getWikiReference().getName(), docReference.getLastSpaceReference().getName(), docReference.getName()); }
/** * @return the serialized space for display, taking into account Nested Pages, i.e. not displaying WebHome for a * nicer user experience * @since 8.3M2 */ public String getDisplaySpace() { if (getDefaultEntityReferenceProvider().getDefaultReference(EntityType.DOCUMENT).getName().equals( getDocumentReference().getName()) && getDocumentReference().getLastSpaceReference().getParent() != null) { return getLocalSerializer().serialize(getDocumentReference().getLastSpaceReference().getParent()); } else { return getSpace(); } }
/** * Check if a document is the original context document. This is needed when generating attachment revision URLs, * since only attachments of the context document should also be versioned. * * @param wiki the wiki name of the document to check * @param space the space name of the document to check * @param name the document name of the document to check * @param context the current request context * @return {@code true} if the provided document is the same as the current context document, {@code false} * otherwise */ protected boolean isContextDoc(String wiki, String space, String name, XWikiContext context) { if (context == null || context.getDoc() == null) { return false; } XWikiDocument doc = context.getDoc(); return doc.getDocumentReference().getLastSpaceReference().getName().equals(space) && doc.getDocumentReference().getName().equals(name) && (wiki == null || doc.getDocumentReference().getWikiReference().getName().equals(wiki)); }
@Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = ((XWikiDocument) source).getOriginalDocument(); if (doc == null || doc.getXObject(Group.CLASS_REFERENCE) == null) { return; } XWikiContext context = this.xcontextProvider.get(); DocumentReference docReference = doc.getDocumentReference(); DocumentReference adminsReference = new DocumentReference(docReference.getName() + " Administrators", docReference.getLastSpaceReference()); XWiki xwiki = context.getWiki(); try { // Delete the administrative group XWikiDocument adminsDoc = xwiki.getDocument(adminsReference, context); xwiki.deleteDocument(adminsDoc, context); } catch (XWikiException ex) { this.logger.error("Failed to delete administrative group for [{}]: {}", docReference, ex.getMessage(), ex); } } }
private DocumentReference getHierarchicalParent(DocumentReference documentReference) { final String spaceHomePage = entityReferenceProvider.getDefaultReference(EntityType.DOCUMENT).getName(); EntityReference parentOfTheSpace = documentReference.getLastSpaceReference().getParent(); boolean pageIsNotTerminal = documentReference.getName().equals(spaceHomePage); // Case 1: The document has the location A.B.C.WebHome // The parent should be A.B.WebHome if (pageIsNotTerminal && parentOfTheSpace.getType() == EntityType.SPACE) { return new DocumentReference(spaceHomePage, new SpaceReference(parentOfTheSpace)); } // Case 2: The document has the location A.WebHome // The parent should be Main.WebHome if (pageIsNotTerminal && parentOfTheSpace.getType() == EntityType.WIKI) { return new DocumentReference(spaceHomePage, new SpaceReference(entityReferenceProvider.getDefaultReference(EntityType.SPACE).getName(), documentReference.getWikiReference())); } // Case 3: The document has the location A.B // The parent should be A.WebHome return new DocumentReference(spaceHomePage, documentReference.getLastSpaceReference()); }
/** * Generate a {@link Link} object from {@link DocumentReference} to be used in * {@link DocumentParser#parseLinksAndReplace(String, Link, Link, com.xpn.xwiki.content.parsers.ReplaceLinkHandler, String)} * * @param documentReference the full document reference * @return a {@link Link} */ private Link createLink(DocumentReference documentReference) { Link link = new Link(); link.setVirtualWikiAlias(documentReference.getWikiReference().getName()); link.setSpace(documentReference.getLastSpaceReference().getName()); link.setPage(documentReference.getName()); return link; }
/** * Note: BaseElement.setName() does not support setting reference anymore since 2.4M2. * * {@inheritDoc} * * @deprecated since 2.2M2 use {@link #setDocumentReference(org.xwiki.model.reference.DocumentReference)} */ @Deprecated @Override public void setName(String name) { DocumentReference reference = getDocumentReference(); if (reference != null) { // Make sure to not modify a reference that could comes from somewhere else reference = new DocumentReference(reference); EntityReference relativeReference = this.relativeEntityReferenceResolver.resolve(name, EntityType.DOCUMENT); reference.getLastSpaceReference().setName(relativeReference.extractReference(EntityType.SPACE).getName()); reference.setName(relativeReference.extractReference(EntityType.DOCUMENT).getName()); } else { reference = this.currentMixedDocumentReferenceResolver.resolve(name); } setDocumentReference(reference); }
protected void process(DocumentReference source, EntityReference destination) { if (processOnlySameSourceDestinationTypes()) { // We know the destination is a document (see above). DocumentReference destinationDocumentReference = new DocumentReference(destination); this.process(source, destinationDocumentReference); } else { if (this.request.isDeep() && isSpaceHomeReference(source)) { process(source.getLastSpaceReference(), destination); } else if (destination.getType() == EntityType.SPACE) { maybeMove(source, new DocumentReference(source.getName(), new SpaceReference(destination))); } else if (destination.getType() == EntityType.DOCUMENT && isSpaceHomeReference(new DocumentReference(destination))) { maybeMove(source, new DocumentReference(source.getName(), new SpaceReference(destination.getParent()))); } else { this.logger.error("Unsupported destination entity type [{}] for a document.", destination.getType()); } } }