Search in sources :

Example 51 with LocalDocumentReference

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

the class AbstractXWikiPreferencesConfigurationSource method getBaseObject.

@Override
protected BaseObject getBaseObject() throws XWikiException {
    XWikiContext xcontext = this.xcontextProvider.get();
    if (xcontext != null && xcontext.getWiki() != null) {
        DocumentReference documentReference = getFailsafeDocumentReference();
        LocalDocumentReference classReference = getFailsafeClassReference();
        if (documentReference != null && classReference != null) {
            XWikiDocument document = xcontext.getWiki().getDocument(getDocumentReference(), xcontext);
            // First we try to get a translated preference object
            BaseObject object = getBaseObject(document, xcontext.getLanguage());
            if (object != null) {
                return object;
            }
            return document.getXObject(classReference);
        }
    }
    return null;
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiContext(com.xpn.xwiki.XWikiContext) DocumentReference(org.xwiki.model.reference.DocumentReference) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 52 with LocalDocumentReference

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

the class ColorThemeListenerTest method onEventWhenColorThemeChanged.

@Test
public void onEventWhenColorThemeChanged() throws Exception {
    // Mocks
    Event event = mock(Event.class);
    XWikiDocument doc = mock(XWikiDocument.class);
    Object data = new Object();
    EntityReference classReference = new LocalDocumentReference("ColorThemes", "ColorThemeClass");
    List<BaseObject> objects = new ArrayList<>();
    BaseObject object = mock(BaseObject.class);
    objects.add(object);
    when(doc.getXObjects(classReference)).thenReturn(objects);
    DocumentReference documentReference = new DocumentReference("wiki", "space", "page");
    when(doc.getDocumentReference()).thenReturn(documentReference);
    ColorThemeReference colorThemeReference = new DocumentColorThemeReference(documentReference, null);
    when(colorThemeReferenceFactory.createReference(eq(documentReference))).thenReturn(colorThemeReference);
    // Test
    mocker.getComponentUnderTest().onEvent(event, doc, data);
    // Verify
    verify(lessResourcesCache).clearFromColorTheme(colorThemeReference);
    verify(colorThemeCache).clearFromColorTheme(colorThemeReference);
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) DocumentColorThemeReference(org.xwiki.lesscss.internal.colortheme.DocumentColorThemeReference) ColorThemeReference(org.xwiki.lesscss.internal.colortheme.ColorThemeReference) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) DocumentColorThemeReference(org.xwiki.lesscss.internal.colortheme.DocumentColorThemeReference) EntityReference(org.xwiki.model.reference.EntityReference) ArrayList(java.util.ArrayList) DocumentCreatedEvent(org.xwiki.bridge.event.DocumentCreatedEvent) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) Event(org.xwiki.observation.event.Event) DocumentDeletedEvent(org.xwiki.bridge.event.DocumentDeletedEvent) BaseObject(com.xpn.xwiki.objects.BaseObject) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) DocumentReference(org.xwiki.model.reference.DocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject) Test(org.junit.Test)

Example 53 with LocalDocumentReference

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

the class ColorThemeListenerTest method onEventWhenFlamingoThemeChanged.

@Test
public void onEventWhenFlamingoThemeChanged() throws Exception {
    // Mocks
    Event event = mock(Event.class);
    XWikiDocument doc = mock(XWikiDocument.class);
    Object data = new Object();
    EntityReference classReference = new LocalDocumentReference("FlamingoThemesCode", "ThemeClass");
    List<BaseObject> objects = new ArrayList<>();
    BaseObject object = mock(BaseObject.class);
    objects.add(object);
    when(doc.getXObjects(classReference)).thenReturn(objects);
    DocumentReference documentReference = new DocumentReference("wiki", "space", "page");
    when(doc.getDocumentReference()).thenReturn(documentReference);
    ColorThemeReference colorThemeReference = new DocumentColorThemeReference(documentReference, null);
    when(colorThemeReferenceFactory.createReference(eq(documentReference))).thenReturn(colorThemeReference);
    // Test
    mocker.getComponentUnderTest().onEvent(event, doc, data);
    // Verify
    verify(lessResourcesCache).clearFromColorTheme(colorThemeReference);
    verify(colorThemeCache).clearFromColorTheme(colorThemeReference);
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) DocumentColorThemeReference(org.xwiki.lesscss.internal.colortheme.DocumentColorThemeReference) ColorThemeReference(org.xwiki.lesscss.internal.colortheme.ColorThemeReference) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) DocumentColorThemeReference(org.xwiki.lesscss.internal.colortheme.DocumentColorThemeReference) EntityReference(org.xwiki.model.reference.EntityReference) ArrayList(java.util.ArrayList) DocumentCreatedEvent(org.xwiki.bridge.event.DocumentCreatedEvent) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) Event(org.xwiki.observation.event.Event) DocumentDeletedEvent(org.xwiki.bridge.event.DocumentDeletedEvent) BaseObject(com.xpn.xwiki.objects.BaseObject) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) DocumentReference(org.xwiki.model.reference.DocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject) Test(org.junit.Test)

Example 54 with LocalDocumentReference

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

the class XWikiAuthServiceImplTest method testLoginWithWikiPrefix.

/**
 * Test that SomeUser is correctly authenticated as XWiki.SomeUser when xwiki:SomeUser is entered as username.
 */
@Test
public void testLoginWithWikiPrefix() throws Exception {
    // Setup a simple user profile document
    XWikiDocument userDoc = new XWikiDocument(new DocumentReference(this.oldcore.getXWikiContext().getWikiId(), "XWiki", "SomeUser"));
    BaseObject mockUserObj = userDoc.newXObject(new LocalDocumentReference("XWiki", "XWikiUsers"), this.oldcore.getXWikiContext());
    mockUserObj.setStringValue("password", "pass");
    // Save the user
    this.oldcore.getSpyXWiki().saveDocument(userDoc, this.oldcore.getXWikiContext());
    // Finally run the test: Using xwiki:Admin should correctly authenticate the Admin user
    Principal principal = this.authService.authenticate("xwiki:SomeUser", "pass", this.oldcore.getXWikiContext());
    assertNotNull(principal);
    assertEquals("xwiki:XWiki.SomeUser", principal.getName());
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) DocumentReference(org.xwiki.model.reference.DocumentReference) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) Principal(java.security.Principal) BaseObject(com.xpn.xwiki.objects.BaseObject) Test(org.junit.Test)

Example 55 with LocalDocumentReference

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

the class XWikiServletURLFactoryTest method createWiki.

/**
 * Creates a new sub-wiki with the given name.
 *
 * @param wikiName the wiki name
 * @throws Exception if creating the wiki fails
 */
private void createWiki(String wikiName) throws Exception {
    String wikiDocName = "XWikiServer" + wikiName.substring(0, 1).toUpperCase() + wikiName.substring(1);
    XWikiDocument wikiDoc = this.oldcore.getSpyXWiki().getDocument(new DocumentReference(MAIN_WIKI_NAME, "XWiki", wikiDocName), this.oldcore.getXWikiContext());
    BaseObject wikiObj = wikiDoc.newXObject(new LocalDocumentReference("XWiki", "XWikiServerClass"), this.oldcore.getXWikiContext());
    wikiObj.setStringValue("server", wikiName + "server");
    this.oldcore.getSpyXWiki().saveDocument(wikiDoc, this.oldcore.getXWikiContext());
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) DocumentReference(org.xwiki.model.reference.DocumentReference) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject)

Aggregations

LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)58 Test (org.junit.Test)28 DocumentReference (org.xwiki.model.reference.DocumentReference)25 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)23 BaseObject (com.xpn.xwiki.objects.BaseObject)19 XWikiContext (com.xpn.xwiki.XWikiContext)10 EntityReference (org.xwiki.model.reference.EntityReference)10 ArrayList (java.util.ArrayList)8 ViewPage (org.xwiki.test.ui.po.ViewPage)6 Page (org.xwiki.rest.model.jaxb.Page)5 DocumentCreatedEvent (org.xwiki.bridge.event.DocumentCreatedEvent)4 DocumentDeletedEvent (org.xwiki.bridge.event.DocumentDeletedEvent)4 DocumentUpdatedEvent (org.xwiki.bridge.event.DocumentUpdatedEvent)4 Event (org.xwiki.observation.event.Event)4 XWiki (com.xpn.xwiki.XWiki)3 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)2 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)2 Principal (java.security.Principal)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2