/** * Creates a new {@link DocumentReference} from a given page name and the reference of the parent space. * * @param pageName the page name * @param parent the parent space reference * @return the typed {@link DocumentReference} object * @since 7.3M2 */ public DocumentReference createDocumentReference(String pageName, SpaceReference parent) { return new DocumentReference(pageName, parent); }
/** * Transforms a XClass reference relative to this document into an absolute reference. */ private DocumentReference resolveClassReference(EntityReference reference) { DocumentReference defaultReference = new DocumentReference(getDocumentReference().getWikiReference().getName(), XWiki.SYSTEM_SPACE, getDocumentReference().getName()); return this.explicitReferenceDocumentReferenceResolver.resolve(reference, defaultReference); }
@Override public boolean equals(Object o) { if (o instanceof DocumentSkinReference) { DocumentSkinReference documentSkinReference = (DocumentSkinReference) o; return skinDocument.equals(documentSkinReference.skinDocument); } return false; }
/** * Convert a username to an XWikiUser object, taking care of proper escapes. * * @param username the username to process * @return an XWikiUser object holding the specified username */ private XWikiUser toXWikiUser(String username, XWikiContext context) { DocumentReference ref = new DocumentReference(context.getDatabase(), XWiki.SYSTEM_SPACE, username); return new XWikiUser(ref.toString()); } }
/** * {@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()); }
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()); }
@Override public boolean updateDocument(XWikiDocument document) { boolean needsUpdate = super.updateDocument(document); // Use PanelSheet to display documents having PanelClass objects if no other class sheet is specified. if (this.classSheetBinder.getSheets(document).isEmpty()) { String wikiName = document.getDocumentReference().getWikiReference().getName(); DocumentReference sheet = new DocumentReference(wikiName, CLASS_SPACE, "PanelSheet"); needsUpdate |= this.classSheetBinder.bind(document, sheet); } return needsUpdate; } }
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()); } } }
@Override public String getWikiIdFromDocumentReference(DocumentReference descriptorDocumentReference) { String docName = descriptorDocumentReference.getName(); return StringUtils.removeStart(docName, "XWikiServer").toLowerCase(); }
/** * @param documentReference the full document reference * @since 5.2M2 */ public LocalDocumentReference(DocumentReference documentReference) { super(documentReference, documentReference.getWikiReference(), null); }
@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); } }
@Override public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException { if (Patient.class.isInstance(value)) { st.setString(index, ((Patient) value).getDocument().toString()); } else { st.setNull(index, Types.VARCHAR); } }
@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; }
@Override public boolean updateDocument(XWikiDocument document) { super.updateDocument(document); // Use SchedulerJobSheet to display documents having SchedulerJobClass objects if no other class sheet is // specified. if (this.classSheetBinder.getSheets(document).isEmpty()) { String wikiName = document.getDocumentReference().getWikiReference().getName(); DocumentReference sheet = new DocumentReference(wikiName, XWiki.SYSTEM_SPACE, SHEET_NAME); return this.classSheetBinder.bind(document, sheet); } return false; } }
/** * 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; }
/** * return the name of a document. for exemple if the fullName of a document is "MySpace.Mydoc", the name is MyDoc. * * @return the name of the document */ public String getName() { return this.doc.getDocumentReference().getName(); }
private XWikiDocument getMembersGroupDocument(String wikiId) throws WikiUserManagerException { // Reference to the document DocumentReference memberGroupReference = new DocumentReference(wikiId, XWiki.SYSTEM_SPACE, "XWikiAllGroup"); // Get the document try { XWikiContext xcontext = xcontextProvider.get(); XWiki xwiki = xcontext.getWiki(); return xwiki.getDocument(memberGroupReference, xcontext); } catch (XWikiException e) { throw new WikiUserManagerException(String.format("Fail to load the member group document [%s].", memberGroupReference.toString()), e); } }
@Override public WikiReference getWiki() { WikiReference result = null; if (this.wiki != null) { result = this.wiki; } else if (this.space != null) { result = (WikiReference) this.space.getRoot(); } else if (this.document != null) { result = this.document.getWikiReference(); } return result; }
/** * @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(); } }