use of org.xwiki.rendering.listener.reference.ResourceReference in project xwiki-platform by xwiki.
the class XWikiWikiModel method getImageURL.
/**
* {@inheritDoc}
*
* @since 2.5RC1
*/
@Override
public String getImageURL(ResourceReference imageReference, Map<String, String> parameters) {
// Handle icon references
if (imageReference.getType().equals(ResourceType.ICON)) {
return this.skinAccessBridge.getIconURL(imageReference.getReference());
}
// Handle attachment references
if (this.extendedRenderingConfiguration.isImageDimensionsIncludedInImageURL()) {
Map<String, Object> urlParameters = getImageURLParameters(parameters);
if (!urlParameters.isEmpty()) {
// Handle scaled image attachments.
String queryString = imageReference.getParameter(AttachmentResourceReference.QUERY_STRING);
queryString = extendQueryString(queryString, urlParameters);
ResourceReference scaledImageReference = imageReference.clone();
scaledImageReference.setParameter(AttachmentResourceReference.QUERY_STRING, queryString);
return getLinkURL(scaledImageReference);
}
}
return getLinkURL(imageReference);
}
use of org.xwiki.rendering.listener.reference.ResourceReference in project xwiki-platform by xwiki.
the class DefaultLinkReferenceParserTest method parseWhenInWikiMode.
@Test
public void parseWhenInWikiMode() throws Exception {
// Create a Mock WikiModel implementation so that the link parser works in wiki mode
WikiModel mockWikiModel = this.componentManager.registerMockComponent(WikiModel.class);
ResourceReference reference = this.parser.parse("");
assertEquals("", reference.getReference());
assertFalse(reference.isTyped());
assertEquals(ResourceType.DOCUMENT, reference.getType());
assertEquals("Typed = [false] Type = [doc] Reference = []", reference.toString());
when(mockWikiModel.isDocumentAvailable(new DocumentResourceReference("existingpage"))).thenReturn(true);
reference = this.parser.parse("existingpage");
assertEquals("existingpage", reference.getReference());
assertFalse(reference.isTyped());
assertEquals(ResourceType.DOCUMENT, reference.getType());
assertEquals("Typed = [false] Type = [doc] Reference = [existingpage]", reference.toString());
reference = this.parser.parse("unexistingpage");
assertEquals("unexistingpage", reference.getReference());
assertFalse(reference.isTyped());
assertEquals(ResourceType.DOCUMENT, reference.getType());
assertEquals("Typed = [false] Type = [doc] Reference = [unexistingpage]", reference.toString());
reference = this.parser.parse("space.unexistingpage");
assertEquals("space.unexistingpage", reference.getReference());
assertFalse(reference.isTyped());
assertEquals(ResourceType.DOCUMENT, reference.getType());
assertEquals("Typed = [false] Type = [doc] Reference = [space.unexistingpage]", reference.toString());
reference = this.parser.parse("http://xwiki.org");
assertEquals("http://xwiki.org", reference.getReference());
assertFalse(reference.isTyped());
assertEquals(ResourceType.URL, reference.getType());
assertEquals("Typed = [false] Type = [url] Reference = [http://xwiki.org]", reference.toString());
// Verify mailto: URI is recognized
reference = this.parser.parse("mailto:john@smith.com?subject=test");
assertEquals("john@smith.com?subject=test", reference.getReference());
assertTrue(reference.isTyped());
assertEquals(ResourceType.MAILTO, reference.getType());
assertEquals("Typed = [true] Type = [mailto] Reference = [john@smith.com?subject=test]", reference.toString());
// Verify attach: URI is recognized
reference = this.parser.parse("attach:some:content");
assertEquals("some:content", reference.getReference());
assertTrue(reference.isTyped());
assertEquals(ResourceType.ATTACHMENT, reference.getType());
assertEquals("Typed = [true] Type = [attach] Reference = [some:content]", reference.toString());
// Verify that unknown URIs are ignored
// Note: In this example we point to a document and we consider that myxwiki is the wiki name and
// http://xwiki.org is the page name
reference = this.parser.parse("mywiki:http://xwiki.org");
assertEquals("mywiki:http://xwiki.org", reference.getReference());
assertFalse(reference.isTyped());
assertEquals(ResourceType.DOCUMENT, reference.getType());
assertEquals("Typed = [false] Type = [doc] Reference = [mywiki:http://xwiki.org]", reference.toString());
// Verify doc links work
reference = this.parser.parse("doc:wiki:space.page");
assertEquals(ResourceType.DOCUMENT, reference.getType());
assertEquals("wiki:space.page", reference.getReference());
assertEquals("Typed = [true] Type = [doc] Reference = [wiki:space.page]", reference.toString());
assertTrue(reference.isTyped());
// Verify space links work
reference = this.parser.parse("space:wiki:space");
assertEquals(ResourceType.SPACE, reference.getType());
assertEquals("wiki:space", reference.getReference());
assertEquals("Typed = [true] Type = [space] Reference = [wiki:space]", reference.toString());
assertTrue(reference.isTyped());
// Verify InterWiki links work
reference = this.parser.parse("interwiki:alias:content");
assertEquals(ResourceType.INTERWIKI, reference.getType());
assertEquals("content", reference.getReference());
assertTrue(reference.isTyped());
assertEquals("alias", ((InterWikiResourceReference) reference).getInterWikiAlias());
assertEquals("Typed = [true] Type = [interwiki] Reference = [content] " + "Parameters = [[interWikiAlias] = [alias]]", reference.toString());
// Verify that an invalid InterWiki link is considered as Document link
reference = this.parser.parse("interwiki:invalid_since_doesnt_have_colon");
assertEquals(ResourceType.DOCUMENT, reference.getType());
assertEquals("interwiki:invalid_since_doesnt_have_colon", reference.getReference());
assertFalse(reference.isTyped());
assertEquals("Typed = [false] Type = [doc] Reference = [interwiki:invalid_since_doesnt_have_colon]", reference.toString());
// Verify typed URLs
reference = this.parser.parse("url:http://xwiki.org");
assertEquals(ResourceType.URL, reference.getType());
assertTrue(reference.isTyped());
assertEquals("http://xwiki.org", reference.getReference());
assertEquals("Typed = [true] Type = [url] Reference = [http://xwiki.org]", reference.toString());
// Verify query string and anchors have no meaning in link reference to documents.
reference = this.parser.parse("Hello World?no=queryString#notAnAnchor");
assertEquals(ResourceType.DOCUMENT, reference.getType());
assertEquals("Hello World?no=queryString#notAnAnchor", reference.getReference());
assertFalse(reference.isTyped());
assertNull(((DocumentResourceReference) reference).getAnchor());
assertNull(((DocumentResourceReference) reference).getQueryString());
assertEquals("Typed = [false] Type = [doc] Reference = [Hello World?no=queryString#notAnAnchor]", reference.toString());
// Verify that the interwiki separator from XWiki Syntax 2.0 has not meaning in link references to documents
reference = this.parser.parse("page@alias");
assertEquals(ResourceType.DOCUMENT, reference.getType());
assertFalse(reference.isTyped());
assertEquals("page@alias", reference.getReference());
assertEquals("Typed = [false] Type = [doc] Reference = [page@alias]", reference.toString());
// Verify path link types
reference = this.parser.parse("path:/some/path");
assertEquals(ResourceType.PATH, reference.getType());
assertTrue(reference.isTyped());
assertEquals("/some/path", reference.getReference());
assertEquals("Typed = [true] Type = [path] Reference = [/some/path]", reference.toString());
// Verify UNC link types
reference = this.parser.parse("unc:\\\\myserver\\myshare\\mydoc.txt");
assertEquals(ResourceType.UNC, reference.getType());
assertTrue(reference.isTyped());
assertEquals("\\\\myserver\\myshare\\mydoc.txt", reference.getReference());
assertEquals("Typed = [true] Type = [unc] Reference = [\\\\myserver\\myshare\\mydoc.txt]", reference.toString());
// Verify that reference escapes are left as is by the link parser
reference = this.parser.parse("pa\\.ge");
assertEquals(ResourceType.DOCUMENT, reference.getType());
assertEquals("pa\\.ge", reference.getReference());
}
use of org.xwiki.rendering.listener.reference.ResourceReference in project xwiki-platform by xwiki.
the class DefaultLinkedResourceHelper method setResourceType.
@Override
public void setResourceType(Block block, ResourceType newResourceType) {
if (block instanceof LinkBlock) {
LinkBlock linkBlock = (LinkBlock) block;
ResourceReference linkReference = linkBlock.getReference();
linkReference.setType(newResourceType);
} else if (block instanceof MacroBlock) {
// N/A yet.
}
}
use of org.xwiki.rendering.listener.reference.ResourceReference in project xwiki-platform by xwiki.
the class DefaultLinkedResourceHelper method getResourceType.
@Override
public ResourceType getResourceType(Block block) {
// Determine the reference string and reference type for each block type.
ResourceType resourceType = null;
if (block instanceof LinkBlock) {
LinkBlock linkBlock = (LinkBlock) block;
ResourceReference linkReference = linkBlock.getReference();
resourceType = linkReference.getType();
} else if (block instanceof MacroBlock) {
// We still have to look at the reference string to see if it is a valid include (i.e. non-recursive).
String referenceString = block.getParameter(REFERENCE_MACRO_PARAMETER);
if (StringUtils.isBlank(referenceString)) {
referenceString = block.getParameter(DOCUMENT_MACRO_PARAMETER);
}
if (StringUtils.isBlank(referenceString)) {
// Skip it.
return null;
}
// FIXME: this may be SPACE once we start hiding "WebHome" from macro reference parameters.
resourceType = ResourceType.DOCUMENT;
}
return resourceType;
}
use of org.xwiki.rendering.listener.reference.ResourceReference in project xwiki-platform by xwiki.
the class DefaultLinkedResourceHelper method getResourceReferenceString.
@Override
public String getResourceReferenceString(Block block) {
// Determine the reference string and reference type for each block type.
String referenceString = null;
if (block instanceof LinkBlock) {
LinkBlock linkBlock = (LinkBlock) block;
ResourceReference linkReference = linkBlock.getReference();
referenceString = linkReference.getReference();
} else if (block instanceof MacroBlock) {
referenceString = block.getParameter(REFERENCE_MACRO_PARAMETER);
if (StringUtils.isBlank(referenceString)) {
referenceString = block.getParameter(DOCUMENT_MACRO_PARAMETER);
}
if (StringUtils.isBlank(referenceString)) {
// If the reference is not set or is empty, we have a recursive include which is not valid anyway.
// Skip it.
referenceString = null;
}
}
return referenceString;
}
Aggregations