@Override public DocumentReference replaceParent(EntityReference newParent) { if (newParent == getParent()) { return this; } return new DocumentReference(this, newParent); }
@Override protected DocumentReference getDocumentReference() { DocumentReference currentDocumentReference = this.documentAccessBridge.getCurrentDocumentReference(); if (currentDocumentReference != null) { return new DocumentReference("WebPreferences", (SpaceReference) currentDocumentReference.getParent()); } return null; } }
@Override protected String getCacheKeyPrefix() { DocumentReference currentDocumentReference = this.documentAccessBridge.getCurrentDocumentReference(); if (currentDocumentReference != null) { return this.referenceSerializer.serialize(currentDocumentReference.getParent()); } return null; }
@Override protected String getCacheKeyPrefix() { DocumentReference currentDocumentReference = getDocumentReference(); if (currentDocumentReference != null) { return this.referenceSerializer.serialize(currentDocumentReference.getParent()); } return null; }
@Override protected String getCacheKeyPrefix() { DocumentReference currentDocumentReference = this.documentAccessBridge.getCurrentDocumentReference(); if (currentDocumentReference != null) { return this.referenceSerializer.serialize(currentDocumentReference.getParent()); } return null; }
/** * Check if the entity reference refers to a document that may contain global rights objects. In other words * '*:XWiki.XWikiPreferences' or '*:*.WebPreferences'. * * @param documentReference the document reference to check. * @return true if the document is scanned for global rights objects during authorization. */ private boolean isGlobalRightsReference(DocumentReference documentReference) { return (XWikiConstants.SPACE_DOC.equals(documentReference.getName()) || (XWikiConstants.WIKI_DOC.equals(documentReference.getName()) && XWikiConstants.XWIKI_SPACE.equals(documentReference.getParent().getName()))); } }
@Override protected DocumentReference getDocumentReference() { // Note: We would normally use a Reference Resolver here but since the Model module uses the Configuration // module we cannot use one as otherwise we would create a cyclic build dependency... // Get the current document reference to extract the wiki and space names. DocumentReference currentDocumentReference = this.documentAccessBridge.getCurrentDocumentReference(); if (currentDocumentReference != null) { // Add the current spaces and current wiki references to the Web Preferences document reference to form // an absolute reference. return new DocumentReference(DOCUMENT_NAME, (SpaceReference) currentDocumentReference.getParent()); } return null; } }
@Override public AuditEvent process(AuditEvent event) { DocumentReference originalEntity = event.getEntity(); XWikiRequest request = this.xcontextProvider.get().getRequest(); if ("PushPatientService".equals(originalEntity.getName()) && "PhenoTips".equals(originalEntity.getParent().getName()) && "push".equals(request.getParameter("do"))) { String pushedEntityName = request.getParameter("patientid"); DocumentReference pushedEntity = this.resolver.resolve(pushedEntityName, Patient.DEFAULT_DATA_SPACE); JSONObject extraInfo = new JSONObject(); String serverId = request.getParameter("serverid"); extraInfo.put("server", serverId); extraInfo.put("group", request.getParameter("groupname")); extraInfo.put("fields", request.getParameter("fields")); String remoteUser = request.getParameter("usr"); if (StringUtils.isEmpty(remoteUser)) { remoteUser = this.pushService.getRemoteUsername(serverId); } extraInfo.put("remoteUser", remoteUser); return new AuditEvent(event.getUser(), event.getIp(), "push", extraInfo.toString(), pushedEntity, event.getTime()); } return event; } }
/** * @param document an XWiki document * @return the title used as a fall-back when the dynamic title cannot be evaluated */ private XDOM getStaticTitle(DocumentModelBridge document) { String documentName = document.getDocumentReference().getName(); if (defaultEntityReferenceProvider.getDefaultReference(EntityType.DOCUMENT).getName().equals(documentName)) { // This document represents a space (it is the home page of a space). Use the space name instead. documentName = document.getDocumentReference().getParent().getName(); } return parseTitle(documentName); }
/** * Schedules an asynchronous job to convert the specified terminal document to a nested document (that can have * child documents). E.g. the document {@code Space1.Space2.Name} is converted to {@code Space1.Space2.Name.WebHome} * . * * @param documentReference the terminal document to convert to a nested document (that can have child documents) * @return the job that has been scheduled and that can be used to monitor the progress of the operation, * {@code null} in case of failure */ public Job convertToNestedDocument(DocumentReference documentReference) { String defaultDocName = this.defaultEntityReferenceProvider.getDefaultReference(EntityType.DOCUMENT).getName(); if (!documentReference.getName().equals(defaultDocName)) { SpaceReference spaceReference = new SpaceReference(documentReference.getName(), documentReference.getParent()); return rename(documentReference, new DocumentReference(defaultDocName, spaceReference)); } // The specified document is already a nested document. return null; }
/** * Describe {@code deliverUpdateEvent} method here. * * @param ref Reference to the document that should be invalidated. */ private void deliverUpdateEvent(DocumentReference ref) { if (XWikiConstants.WIKI_DOC_REFERENCE.equals(ref, EntityType.SPACE)) { // For XWiki.XWikiPreferences, remove the whole wiki. securityCache.remove(securityReferenceFactory.newEntityReference(ref.getWikiReference())); } else if (ref.getName().equals(XWikiConstants.SPACE_DOC)) { // For WebPreferences, remove the whole space. securityCache.remove(securityReferenceFactory.newEntityReference(ref.getParent())); } else { // For any other documents, remove that document cache. securityCache.remove(securityReferenceFactory.newEntityReference(ref)); // If it's a wiki descriptor remove the wiki reference from the cache if (ref.getName().startsWith(XWikiConstants.WIKI_DESCRIPTOR_PREFIX) && XWikiConstants.XWIKI_SPACE_REFERENCE.equals(ref.getLastSpaceReference(), EntityType.SPACE) && ref.getWikiReference().getName().equals(this.xcontextProvider.get().getMainXWiki())) { // For xwiki:XWiki.XWikiServer... documents, also remove the whole corresponding wiki. securityCache.remove(securityReferenceFactory.newEntityReference(new WikiReference( ref.getName().substring(XWikiConstants.WIKI_DESCRIPTOR_PREFIX.length()).toLowerCase()))); } } } }
/** * Adds to a Solr document the fields that are specific to the XWiki document that contains the entity to be * indexed. These fields required to identify the owning document and to also reflect some properties of the owning * document towards the indexed entity (like locale and hidden flag). * * @param documentReference reference to document. * @param solrDocument the Solr document to which to add the fields. * @return false if the document does not exist, true otherwise * @throws Exception if problems occur. */ protected boolean setDocumentFields(DocumentReference documentReference, SolrInputDocument solrDocument) throws Exception { XWikiDocument originalDocument = getDocument(documentReference); if (originalDocument.isNew()) { return false; } solrDocument.setField(FieldUtils.HIDDEN, originalDocument.isHidden()); solrDocument.setField(FieldUtils.WIKI, documentReference.getWikiReference().getName()); solrDocument.setField(FieldUtils.NAME, documentReference.getName()); // Set the fields that are used to query / filter the document hierarchy. setHierarchyFields(solrDocument, documentReference.getParent()); Locale locale = getLocale(documentReference); solrDocument.setField(FieldUtils.LOCALE, locale.toString()); solrDocument.setField(FieldUtils.LANGUAGE, locale.getLanguage()); return true; }
/** * Schedules an asynchronous job to convert the specified nested document to a terminal document (that can't have * child documents). E.g. the document {@code One.Two.WebHome} is converted to {@code One.Two} . * * @param documentReference the nested document to convert to a terminal document (that can't have child documents) * @return the job that has been scheduled and that can be used to monitor the progress of the operation, * {@code null} in case of failure */ public Job convertToTerminalDocument(DocumentReference documentReference) { if (documentReference.getName().equals( this.defaultEntityReferenceProvider.getDefaultReference(documentReference.getType()).getName())) { EntityReference parentReference = documentReference.getParent(); if (parentReference.getParent().getType() == EntityType.SPACE) { // There has to be at least 2 levels of nested spaces in order to be able to convert a nested document // into a terminal document. We cannot convert a root document like Main.WebHome into a terminal // document. DocumentReference terminalDocumentReference = new DocumentReference(parentReference.getName(), new SpaceReference(parentReference.getParent())); return rename(documentReference, terminalDocumentReference); } } // The specified document is already a terminal document or cannot be converted to a terminal document. return null; }