@Override public SpaceReference replaceParent(EntityReference oldParent, EntityReference newParent) { if (newParent == oldParent) { return this; } return new SpaceReference(this, oldParent, newParent); }
/** * Generate a relative path based on provided document for the directory where the document should be stored. * * @param doc the document to export * @return the corresponding path */ public String getDirectoryForDocument(XWikiDocument doc) { StringBuilder path = new StringBuilder(); for (SpaceReference space : doc.getDocumentReference().getSpaceReferences()) { path.append(space.getName()).append('/'); } return path.toString(); }
@Override public SpaceReference replaceParent(EntityReference newParent) { if (newParent == getParent()) { return this; } return new SpaceReference(this, newParent); }
protected void process(SpaceReference source, EntityReference destination) { if (processOnlySameSourceDestinationTypes()) { // We know the destination is a space (see above). process(source, new SpaceReference(destination)); } else { if (destination.getType() == EntityType.SPACE || destination.getType() == EntityType.WIKI) { process(source, new SpaceReference(source.getName(), destination)); } else if (destination.getType() == EntityType.DOCUMENT && isSpaceHomeReference(new DocumentReference(destination))) { process(source, new SpaceReference(source.getName(), destination.getParent())); } else { this.logger.error("Unsupported destination entity type [{}] for a space.", destination.getType()); } } }
@Override public ConfigurationSource next() { SpaceReference next = this.reference; if (this.reference != null) { // Move reference to parent if (this.reference.getParent() instanceof SpaceReference) { this.reference = (SpaceReference) this.reference.getParent(); } else { this.reference = null; } // Return wrapped space configuration associated to the space reference return new SpaceConfigurationSource(next); } return null; }
/** * @return the reference of the wiki containing this space * @since 7.1M2 */ @Transient public WikiReference getWikiReference() { return (WikiReference) extractReference(EntityType.WIKI); } }
/** * @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(); } }
/** * Creates a {@link SpaceReference} from a string representing the space name and the reference of the parent space. * * @param spaceName the space name (e.g. "Main") * @param parent the reference of the parent space * @return the reference to the space * @since 7.3RC1 */ public SpaceReference createSpaceReference(String spaceName, SpaceReference parent) { return new SpaceReference(spaceName, parent); }
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()); }
/** * 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(); }
/** * Creates a {@link SpaceReference} from a string representing the space name. * * @param spaceName the space name (eg "Main") * @param parent the wiki reference in which the space is located * @return the reference to the space * @since 5.0M1 */ public SpaceReference createSpaceReference(String spaceName, WikiReference parent) { return new SpaceReference(spaceName, parent); }
/** * 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(); }
/** * Create a new Document reference from wiki name, spaces names and page name. * * @param wikiName the name of the wiki containing the document, must not be null * @param spaceNames an ordered list of the names of the spaces containing the document from root space to last one, * must not be null * @param pageName the name of the document */ public DocumentReference(String wikiName, List<String> spaceNames, String pageName) { super(pageName, EntityType.DOCUMENT, new SpaceReference(wikiName, spaceNames)); }
@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); } }
/** * Create a new Document reference from wiki name, spaces names, page name and locale. * * @param wikiName the name of the wiki containing the document, must not be null * @param spaceNames an ordered list of the names of the spaces containing the document from root space to last one, * must not be null * @param pageName the name of the document reference * @param locale the locale of the document reference, may be null */ public DocumentReference(String wikiName, List<String> spaceNames, String pageName, Locale locale) { super(pageName, EntityType.DOCUMENT, new SpaceReference(wikiName, spaceNames), locale); }
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; }
/** * Creates a {@link SpaceReference} from a list of string representing the space name and the name of its parents. * * @param spaces the list of the spaces name (eg ["A", "B", "C"]) * @param parent the wiki reference in which the space is located * @return the reference to the space * @since 7.2M2 */ public SpaceReference createSpaceReference(List<String> spaces, WikiReference parent) { SpaceReference spaceReference = null; EntityReference parentReference = parent; for (String space : spaces) { spaceReference = new SpaceReference(space, parentReference); parentReference = spaceReference; } return spaceReference; }
/** * {@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()); }
@Override public SpaceReference resolve(String documentReferenceRepresentation, Object... parameters) { return new SpaceReference(this.entityReferenceResolver.resolve(documentReferenceRepresentation, EntityType.SPACE, parameters)); } }
generator.setWikiSpaceParameters(spaceReference.getName(), parameters); proxyFilter.beginWikiSpace(spaceReference.getName(), parameters); generator.beginWikiSpace(spaceReference.getName(), parameters); generator.endWikiSpace(spaceReference.getName(), parameters); proxyFilter.endWikiSpace(spaceReference.getName(), parameters);