Search in sources :

Example 46 with LocalDocumentReference

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

the class XARInputFilterStreamTest method testSkipFirstDocument.

@Test
public void testSkipFirstDocument() throws FilterException, IOException, ComponentLookupException {
    XARInputProperties xarProperties = new XARInputProperties();
    xarProperties.setSource(new DefaultFileInputSource(extensionPackager.getExtensionFile(new ExtensionId("xar1", "1.0"))));
    EntityReferenceSet entities = new EntityReferenceSet();
    entities.includes(new LocalDocumentReference("space2", "page2"));
    xarProperties.setEntities(entities);
    assertXML("testSkipFirstDocument", xarProperties);
    assertTrue(this.allLogRule.getMarker(0).contains(WikiDocumentFilter.LOG_DOCUMENT_SKIPPED));
}
Also used : EntityReferenceSet(org.xwiki.model.reference.EntityReferenceSet) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) XARInputProperties(org.xwiki.filter.xar.input.XARInputProperties) DefaultFileInputSource(org.xwiki.filter.input.DefaultFileInputSource) ExtensionId(org.xwiki.extension.ExtensionId) Test(org.junit.Test)

Example 47 with LocalDocumentReference

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

the class DocumentLocaleReader method readDocument.

private void readDocument(XMLStreamReader xmlReader, Object filter, XARInputFilter proxyFilter) throws XMLStreamException, FilterException {
    xmlReader.require(XMLStreamReader.START_ELEMENT, null, XarDocumentModel.ELEMENT_DOCUMENT);
    this.currentSourceType = SourceType.DOCUMENT;
    // Initialize with a few defaults (thing that don't exist in old XAR format)
    this.currentDocumentRevisionParameters.put(XWikiWikiDocumentFilter.PARAMETER_SYNTAX, Syntax.XWIKI_1_0);
    this.currentDocumentRevisionParameters.put(XWikiWikiDocumentFilter.PARAMETER_HIDDEN, false);
    // Reference
    String referenceString = xmlReader.getAttributeValue(null, XARDocumentModel.ATTRIBUTE_DOCUMENT_REFERENCE);
    if (StringUtils.isNotEmpty(referenceString)) {
        this.currentDocumentReference = this.relativeResolver.resolve(referenceString, EntityType.DOCUMENT);
        this.currentSpaceReference = this.currentDocumentReference.getParent();
        // Send needed wiki spaces event if possible
        switchWikiSpace(proxyFilter, false);
    }
    // Locale
    String localeString = xmlReader.getAttributeValue(null, XARDocumentModel.ATTRIBUTE_DOCUMENT_LOCALE);
    if (localeString != null) {
        this.currentDocumentLocale = toLocale(localeString);
        this.localeFromLegacy = false;
    }
    for (xmlReader.nextTag(); xmlReader.isStartElement(); xmlReader.nextTag()) {
        String elementName = xmlReader.getLocalName();
        if (elementName.equals(XARAttachmentModel.ELEMENT_ATTACHMENT)) {
            readAttachment(xmlReader, filter, proxyFilter);
        } else if (elementName.equals(XARObjectModel.ELEMENT_OBJECT)) {
            readObject(xmlReader, filter, proxyFilter);
        } else if (elementName.equals(XARClassModel.ELEMENT_CLASS)) {
            readClass(xmlReader, filter, proxyFilter);
        } else {
            String value = xmlReader.getElementText();
            if (XarDocumentModel.ELEMENT_SPACE.equals(elementName)) {
                this.currentLegacySpace = value;
                if (this.currentDocumentReference == null) {
                    // Its an old thing
                    if (this.currentLegacyDocument == null) {
                        this.currentSpaceReference = new EntityReference(value, EntityType.SPACE);
                    } else {
                        this.currentDocumentReference = new LocalDocumentReference(this.currentLegacySpace, this.currentLegacyDocument);
                        this.currentSpaceReference = this.currentDocumentReference.getParent();
                    }
                    // Send needed wiki spaces event if possible
                    switchWikiSpace(proxyFilter, false);
                }
            } else if (XarDocumentModel.ELEMENT_NAME.equals(elementName)) {
                this.currentLegacyDocument = value;
                if (this.currentDocumentReference == null) {
                    // Its an old thing
                    if (this.currentLegacySpace != null) {
                        this.currentDocumentReference = new LocalDocumentReference(this.currentLegacySpace, this.currentLegacyDocument);
                        this.currentSpaceReference = this.currentDocumentReference.getParent();
                    }
                }
            } else if (XarDocumentModel.ELEMENT_LOCALE.equals(elementName)) {
                if (this.localeFromLegacy) {
                    this.currentDocumentLocale = toLocale(value);
                }
            } else if (XarDocumentModel.ELEMENT_REVISION.equals(elementName)) {
                this.currentDocumentRevision = value;
            } else {
                EventParameter parameter = XARDocumentModel.DOCUMENT_PARAMETERS.get(elementName);
                if (parameter != null) {
                    Object wsValue = convert(parameter.type, value);
                    if (wsValue != null) {
                        this.currentDocumentParameters.put(parameter.name, wsValue);
                    }
                } else {
                    parameter = XARDocumentModel.DOCUMENTLOCALE_PARAMETERS.get(elementName);
                    if (parameter != null) {
                        Object wsValue = convert(parameter.type, value);
                        if (wsValue != null) {
                            this.currentDocumentLocaleParameters.put(parameter.name, wsValue);
                        }
                    } else {
                        parameter = XARDocumentModel.DOCUMENTREVISION_PARAMETERS.get(elementName);
                        if (parameter != null) {
                            Object objectValue;
                            if (parameter.type == EntityReference.class) {
                                objectValue = this.relativeResolver.resolve(value, EntityType.DOCUMENT);
                            } else {
                                objectValue = convert(parameter.type, value);
                            }
                            if (objectValue != null) {
                                this.currentDocumentRevisionParameters.put(parameter.name, objectValue);
                            }
                        } else {
                        // Unknown property
                        // TODO: log something ?
                        }
                    }
                }
            }
        }
    }
    sendBeginWikiDocumentRevision(proxyFilter, true);
    sendWikiAttachments(proxyFilter);
    sendWikiClass(proxyFilter);
    sendWikiObjects(proxyFilter);
    sendEndWikiDocument(proxyFilter);
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) EventParameter(org.xwiki.filter.xar.internal.XARFilterUtils.EventParameter) EntityReference(org.xwiki.model.reference.EntityReference) WikiObject(org.xwiki.filter.xar.internal.input.WikiObjectReader.WikiObject)

Example 48 with LocalDocumentReference

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

the class DefaultContextualAuthorizationManagerTest method hasAccess.

@Test
public void hasAccess() throws Exception {
    LocalDocumentReference localReference = new LocalDocumentReference("space", "page");
    this.mocker.getComponentUnderTest().hasAccess(Right.VIEW, localReference);
    verify(this.authorizationManager).hasAccess(same(Right.VIEW), isNull(DocumentReference.class), eq(new DocumentReference(localReference, this.currentWikiReference)));
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) DocumentReference(org.xwiki.model.reference.DocumentReference) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) Test(org.junit.Test)

Example 49 with LocalDocumentReference

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

the class IconThemeListenerTest method onEvent.

@Test
public void onEvent() throws Exception {
    // Mocks
    XWikiDocument doc = mock(XWikiDocument.class);
    List<BaseObject> list = new ArrayList<BaseObject>();
    BaseObject obj = mock(BaseObject.class);
    list.add(obj);
    when(obj.getStringValue("name")).thenReturn("icontheme1");
    DocumentReference docRef = new DocumentReference("wikiA", "b", "c");
    when(doc.getDocumentReference()).thenReturn(docRef);
    LocalDocumentReference iconThemeClassRef = new LocalDocumentReference("IconThemesCode", "IconThemeClass");
    when(doc.getXObjects(eq(iconThemeClassRef))).thenReturn(list);
    // Tests
    mocker.getComponentUnderTest().onEvent(null, doc, null);
    // Verify
    verify(iconSetCache, atLeastOnce()).clear(docRef);
    verify(iconSetCache, atLeastOnce()).clear("icontheme1", "wikiA");
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) ArrayList(java.util.ArrayList) DocumentReference(org.xwiki.model.reference.DocumentReference) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject) Test(org.junit.Test)

Example 50 with LocalDocumentReference

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

the class UIExtensionTest method testUIExtension.

@Test
public void testUIExtension() throws Exception {
    // Test Java UI extensions
    getUtil().rest().savePage(new LocalDocumentReference(getTestClassName(), HELLOWORLD_UIX_PAGE), "{{velocity}}\n" + "\n" + "{{html}}\n" + "#foreach($uix in $services.uix.getExtensions('hello', {'sortByParameter' : 'HelloWorldKey'}))" + "$services.rendering.render($uix.execute(), " + "'xhtml/1.0')#end\n" + "{{/html}}\n" + "\n" + "#foreach($uix in $services.uix.getExtensions('hello', {'sortByParameter' : 'HelloWorldKey'}))\n" + "$uix.parameters\n" + "#end\n" + "{{/velocity}}\n", "");
    // Test Wiki UI extension
    Page extensionsPage = getUtil().rest().page(new LocalDocumentReference(getTestClassName(), HELLOWIKIWORLD_UIX_PAGE));
    Objects objects = new Objects();
    extensionsPage.setObjects(objects);
    Object object = RestTestUtils.object(WikiUIExtensionConstants.CLASS_REFERENCE_STRING);
    object.setNumber(0);
    object.withProperties(RestTestUtils.property("name", "helloWikiWorld2"));
    object.withProperties(RestTestUtils.property("extensionPointId", "hello"));
    object.withProperties(RestTestUtils.property("content", "HelloWikiWorld2"));
    object.withProperties(RestTestUtils.property("parameters", "HelloWorldKey=zz2_$xcontext.user"));
    objects.withObjectSummaries(object);
    object = RestTestUtils.object(WikiUIExtensionConstants.CLASS_REFERENCE_STRING);
    object.setNumber(1);
    object.withProperties(RestTestUtils.property("name", "helloWikiWorld1"));
    object.withProperties(RestTestUtils.property("extensionPointId", "hello"));
    object.withProperties(RestTestUtils.property("content", "HelloWikiWorld1"));
    object.withProperties(RestTestUtils.property("parameters", "HelloWorldKey=zz1_$xcontext.user"));
    objects.withObjectSummaries(object);
    getUtil().rest().save(extensionsPage);
    ViewPage page = getUtil().gotoPage(getTestClassName(), HELLOWORLD_UIX_PAGE);
    Assert.assertEquals("HelloWorld\n" + "HelloWikiWorld1\n" + "HelloWikiWorld2\n" + "{HelloWorldKey=HelloWorldValue}\n" + "{HelloWorldKey=zz1_XWiki.superadmin}\n" + "{HelloWorldKey=zz2_XWiki.superadmin}", page.getContent());
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) Objects(org.xwiki.rest.model.jaxb.Objects) Page(org.xwiki.rest.model.jaxb.Page) ViewPage(org.xwiki.test.ui.po.ViewPage) Object(org.xwiki.rest.model.jaxb.Object) ViewPage(org.xwiki.test.ui.po.ViewPage) Test(org.junit.Test) AbstractTest(org.xwiki.test.ui.AbstractTest)

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