Search in sources :

Example 56 with WikiReference

use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.

the class DefaultSignatureStoreTest method testRetrievingExistingSignature.

@Test
public void testRetrievingExistingSignature() throws Exception {
    XWikiDocument sourceDocument = mock(XWikiDocument.class);
    when(this.xwiki.getDocument(new DocumentReference("wiki", "space", "document"), this.xcontext)).thenReturn(sourceDocument);
    BaseObject signatureObject = mock(BaseObject.class);
    when(sourceDocument.getXObject(new DocumentReference(DefaultSignatureStore.SIGNATURECLASS, new WikiReference("wiki")), DefaultSignatureStore.SIGNATURECLASS_PROP_REFERENCE, "block")).thenReturn(signatureObject);
    when(signatureObject.getLargeStringValue(DefaultSignatureStore.SIGNATURECLASS_PROP_SIGNATURE)).thenReturn(ENCODED_SIGNATURE);
    assertThat(this.store.retrieve(new BlockReference("block", new DocumentReference("wiki", "space", "document"))), equalTo(SIGNATURE));
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) BlockReference(org.xwiki.model.reference.BlockReference) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject) Test(org.junit.Test)

Example 57 with WikiReference

use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.

the class DefaultSignatureStoreTest method testUpdatingSignature.

@Test
public void testUpdatingSignature() throws Exception {
    XWikiDocument sourceDocument = mock(XWikiDocument.class);
    when(this.xwiki.getDocument(new DocumentReference("wiki", "space", "document"), this.xcontext)).thenReturn(sourceDocument);
    BaseObject signatureObject = mock(BaseObject.class);
    when(sourceDocument.getXObject(new DocumentReference(DefaultSignatureStore.SIGNATURECLASS, new WikiReference("wiki")), DefaultSignatureStore.SIGNATURECLASS_PROP_REFERENCE, "block")).thenReturn(signatureObject);
    this.store.store(new BlockReference("block", new DocumentReference("wiki", "space", "document")), SIGNATURE);
    verify(signatureObject, never()).setStringValue(eq(DefaultSignatureStore.SIGNATURECLASS_PROP_REFERENCE), any(String.class));
    verify(signatureObject).setLargeStringValue(DefaultSignatureStore.SIGNATURECLASS_PROP_SIGNATURE, ENCODED_SIGNATURE);
    verify(this.xwiki).saveDocument(sourceDocument, this.xcontext);
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) BlockReference(org.xwiki.model.reference.BlockReference) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject) Test(org.junit.Test)

Example 58 with WikiReference

use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.

the class DefaultModelContext method getCurrentEntityReference.

@Override
public EntityReference getCurrentEntityReference() {
    WikiReference result = null;
    // TODO: This is bridge to the old XWiki Context since we currently don't store the current entity in the
    // new Execution Context yet. Remove when we do so.
    ExecutionContext econtext = this.execution.getContext();
    if (econtext != null) {
        Map<String, Object> xcontext = (Map<String, Object>) econtext.getProperty(XCONTEXT_KEY);
        if (xcontext != null) {
            String wikiName = (String) xcontext.get(WIKINAME_KEY);
            if (wikiName != null) {
                result = new WikiReference(wikiName);
            }
        }
    }
    return result;
}
Also used : ExecutionContext(org.xwiki.context.ExecutionContext) WikiReference(org.xwiki.model.reference.WikiReference) Map(java.util.Map)

Example 59 with WikiReference

use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.

the class XWikiDocument method setDatabase.

/**
 * Note that this method cannot be removed for now since it's used by Hibernate for loading a XWikiDocument.
 *
 * @deprecated since 2.2M1 use {@link #setDocumentReference(DocumentReference)} instead
 */
@Deprecated
public void setDatabase(String database) {
    if (database != null) {
        DocumentReference reference = getDocumentReference();
        WikiReference wiki = reference.getWikiReference();
        WikiReference newWiki = new WikiReference(database);
        if (!newWiki.equals(wiki)) {
            setDocumentReferenceInternal(reference.replaceParent(wiki, newWiki));
        }
    }
}
Also used : WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference)

Example 60 with WikiReference

use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.

the class XWikiDocument method getChildrenReferences.

/**
 * Returns a list of references of all documents which list this document as their parent, in the current wiki.
 *
 * @param nb The number of results to return.
 * @param start The number of results to skip before we begin returning results.
 * @param context The {@link com.xpn.xwiki.XWikiContext context}.
 * @return the list of document references
 * @throws XWikiException If there's an error querying the database.
 * @since 2.2M2
 */
public List<DocumentReference> getChildrenReferences(int nb, int start, XWikiContext context) throws XWikiException {
    // Use cases:
    // - the parent document reference saved in the database matches the reference of this document, in its fully
    // serialized form (eg "wiki:space.page"). Note that this is normally not required since the wiki part
    // isn't saved in the database when it matches the current wiki.
    // - the parent document reference saved in the database matches the reference of this document, in its
    // serialized form without the wiki part (eg "space.page"). The reason we don't need to specify the wiki
    // part is because document parents saved in the database don't have the wiki part specified when it matches
    // the current wiki.
    // - the parent document reference saved in the database matches the page name part of this document's
    // reference (eg "page") and the parent document's space is the same as this document's space.
    List<DocumentReference> children = new ArrayList<DocumentReference>();
    try {
        Query query = getStore().getQueryManager().createQuery("select distinct doc.fullName from XWikiDocument doc where " + "doc.parent=:prefixedFullName or doc.parent=:fullName or (doc.parent=:name and doc.space=:space)", Query.XWQL);
        query.addFilter(Utils.getComponent(QueryFilter.class, "hidden"));
        query.bindValue("prefixedFullName", getDefaultEntityReferenceSerializer().serialize(getDocumentReference()));
        query.bindValue("fullName", LOCAL_REFERENCE_SERIALIZER.serialize(getDocumentReference()));
        query.bindValue("name", getDocumentReference().getName());
        query.bindValue("space", LOCAL_REFERENCE_SERIALIZER.serialize(getDocumentReference().getLastSpaceReference()));
        query.setLimit(nb).setOffset(start);
        List<String> queryResults = query.execute();
        WikiReference wikiReference = this.getDocumentReference().getWikiReference();
        for (String fullName : queryResults) {
            children.add(getCurrentDocumentReferenceResolver().resolve(fullName, wikiReference));
        }
    } catch (QueryException e) {
        throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_UNKNOWN, String.format("Failed to retrieve children for document [%s]", this.getDocumentReference()), e);
    }
    return children;
}
Also used : QueryFilter(org.xwiki.query.QueryFilter) QueryException(org.xwiki.query.QueryException) Query(org.xwiki.query.Query) ArrayList(java.util.ArrayList) ToString(org.suigeneris.jrcs.util.ToString) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) XWikiException(com.xpn.xwiki.XWikiException)

Aggregations

WikiReference (org.xwiki.model.reference.WikiReference)220 DocumentReference (org.xwiki.model.reference.DocumentReference)127 Test (org.junit.Test)106 SpaceReference (org.xwiki.model.reference.SpaceReference)58 XWikiContext (com.xpn.xwiki.XWikiContext)33 XWikiException (com.xpn.xwiki.XWikiException)24 EntityReference (org.xwiki.model.reference.EntityReference)24 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)23 ArrayList (java.util.ArrayList)19 AccessDeniedException (org.xwiki.security.authorization.AccessDeniedException)18 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)15 WikiDescriptor (org.xwiki.wiki.descriptor.WikiDescriptor)11 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)10 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)10 XWiki (com.xpn.xwiki.XWiki)9 BaseObject (com.xpn.xwiki.objects.BaseObject)9 ComponentManager (org.xwiki.component.manager.ComponentManager)9 Expectations (org.jmock.Expectations)8 Before (org.junit.Before)8 DefaultComponentDescriptor (org.xwiki.component.descriptor.DefaultComponentDescriptor)8