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