Search in sources :

Example 1 with DocumentReference

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

the class DefaultIOTargetService method getObjectPropertyContent.

private String getObjectPropertyContent(ObjectPropertyReference reference) {
    BaseObjectReference objRef = new BaseObjectReference(reference.getParent());
    DocumentReference docRef = new DocumentReference(objRef.getParent());
    if (objRef.getObjectNumber() != null) {
        return dab.getProperty(docRef, objRef.getXClassReference(), objRef.getObjectNumber(), reference.getName()).toString();
    } else {
        return dab.getProperty(docRef, objRef.getXClassReference(), reference.getName()).toString();
    }
}
Also used : BaseObjectReference(com.xpn.xwiki.objects.BaseObjectReference) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 2 with DocumentReference

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

the class DefaultIOTargetService method getSourceSyntax.

@Override
public String getSourceSyntax(String reference) throws IOServiceException {
    try {
        EntityReference ref = referenceResolver.resolve(reference, EntityType.DOCUMENT);
        EntityReference docRef = ref.extractReference(EntityType.DOCUMENT);
        if (docRef != null) {
            // doc
            return dab.getTranslatedDocumentInstance(new DocumentReference(docRef)).getSyntax().toIdString();
        } else {
            return dab.getDocumentSyntaxId(reference);
        }
    } catch (Exception e) {
        throw new IOServiceException("An exception has occurred while getting the syntax of the source for " + reference, e);
    }
}
Also used : IOServiceException(org.xwiki.annotation.io.IOServiceException) EntityReference(org.xwiki.model.reference.EntityReference) DocumentReference(org.xwiki.model.reference.DocumentReference) ParseException(org.xwiki.rendering.parser.ParseException) IOServiceException(org.xwiki.annotation.io.IOServiceException) TransformationException(org.xwiki.rendering.transformation.TransformationException)

Example 3 with DocumentReference

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

the class DefaultIOTargetServiceTest method testGettersWhenTargetIsTypedRelativeDocument.

@Test
public void testGettersWhenTargetIsTypedRelativeDocument() throws Exception {
    final DocumentModelBridge dmb = getMockery().mock(DocumentModelBridge.class);
    getMockery().checking(new Expectations() {

        {
            // default resolver should be used
            allowing(dabMock).getTranslatedDocumentInstance(new DocumentReference("xwiki", "Space", "Page"));
            will(returnValue(dmb));
            oneOf(dmb).getContent();
            will(returnValue("defcontent"));
            oneOf(dmb).getSyntax();
            will(returnValue(new Syntax(SyntaxType.XWIKI, "2.0")));
        }
    });
    String reference = "DOCUMENT://Space.Page";
    assertEquals("defcontent", ioTargetService.getSource(reference));
    assertEquals("xwiki/2.0", ioTargetService.getSourceSyntax(reference));
}
Also used : Expectations(org.jmock.Expectations) DocumentModelBridge(org.xwiki.bridge.DocumentModelBridge) Syntax(org.xwiki.rendering.syntax.Syntax) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 4 with DocumentReference

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

the class DefaultIOTargetServiceTest method testGetterWhenTargetIsTypedIndexedRelativeObjectProperty.

@Test
public void testGetterWhenTargetIsTypedIndexedRelativeObjectProperty() throws Exception {
    final DocumentModelBridge dmb = getMockery().mock(DocumentModelBridge.class);
    getMockery().checking(new Expectations() {

        {
            // this will fail if defaults fail, not very well isolated
            allowing(classResolver).resolve("Classes.Class", new DocumentReference("xwiki", "Main", "WebHome"));
            will(returnValue(new DocumentReference("xwiki", "Classes", "Class")));
            oneOf(dabMock).getProperty(new DocumentReference("xwiki", "Main", "WebHome"), new DocumentReference("xwiki", "Classes", "Class"), 3, "property");
            will(returnValue("defcontent"));
            oneOf(dabMock).getTranslatedDocumentInstance(new DocumentReference("xwiki", "Main", "WebHome"));
            will(returnValue(dmb));
            oneOf(dmb).getSyntax();
            will(returnValue(new Syntax(SyntaxType.XWIKI, "2.0")));
        }
    });
    String reference = "OBJECT_PROPERTY://Classes.Class[3].property";
    assertEquals("defcontent", ioTargetService.getSource(reference));
    assertEquals("xwiki/2.0", ioTargetService.getSourceSyntax(reference));
}
Also used : Expectations(org.jmock.Expectations) DocumentModelBridge(org.xwiki.bridge.DocumentModelBridge) Syntax(org.xwiki.rendering.syntax.Syntax) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 5 with DocumentReference

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

the class DefaultIOTargetServiceTest method testGettersWhenTargetIsNonTypedDocument.

@Test
public void testGettersWhenTargetIsNonTypedDocument() throws Exception {
    final DocumentModelBridge dmb = getMockery().mock(DocumentModelBridge.class);
    getMockery().checking(new Expectations() {

        {
            allowing(dabMock).getTranslatedDocumentInstance(new DocumentReference("wiki", "Space", "Page"));
            will(returnValue(dmb));
            oneOf(dmb).getContent();
            will(returnValue("defcontent"));
            oneOf(dmb).getSyntax();
            will(returnValue(new Syntax(SyntaxType.XWIKI, "2.0")));
        }
    });
    String reference = "wiki:Space.Page";
    assertEquals("defcontent", ioTargetService.getSource(reference));
    assertEquals("xwiki/2.0", ioTargetService.getSourceSyntax(reference));
}
Also used : Expectations(org.jmock.Expectations) DocumentModelBridge(org.xwiki.bridge.DocumentModelBridge) Syntax(org.xwiki.rendering.syntax.Syntax) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Aggregations

DocumentReference (org.xwiki.model.reference.DocumentReference)1324 Test (org.junit.Test)711 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)482 BaseObject (com.xpn.xwiki.objects.BaseObject)250 XWikiContext (com.xpn.xwiki.XWikiContext)186 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)157 ArrayList (java.util.ArrayList)128 WikiReference (org.xwiki.model.reference.WikiReference)127 XWikiException (com.xpn.xwiki.XWikiException)121 EntityReference (org.xwiki.model.reference.EntityReference)113 SpaceReference (org.xwiki.model.reference.SpaceReference)96 XWiki (com.xpn.xwiki.XWiki)82 HashMap (java.util.HashMap)54 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)52 Expectations (org.jmock.Expectations)50 Before (org.junit.Before)50 DocumentModelBridge (org.xwiki.bridge.DocumentModelBridge)46 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)45 AttachmentReference (org.xwiki.model.reference.AttachmentReference)44 Date (java.util.Date)42