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));
}
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);
}
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)));
}
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");
}
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());
}
Aggregations