Search in sources :

Example 26 with ExtendedURL

use of org.xwiki.url.ExtendedURL in project xwiki-platform by xwiki.

the class VfsResourceReferenceSerializer method serialize.

@Override
public ExtendedURL serialize(VfsResourceReference resourceReference) throws SerializeResourceReferenceException, UnsupportedResourceReferenceException {
    ExtendedURL extendedURL;
    // We need to ensure that the URI contains absolute references since the VFS handler that will handle
    // the generated URL won't have any base reference to resolve any relative refeence.
    // 
    // Look for a scheme-specific serializer to convert from a relative URI into an absolute URI and if not found
    // then don't perform any transformation of the URI.
    URI uri = resourceReference.getURI();
    try {
        ResourceReferenceSerializer<VfsResourceReference, ExtendedURL> schemeSpecificSerializer = this.componentManagerProvider.get().getInstance(TYPE, uri.getScheme());
        extendedURL = schemeSpecificSerializer.serialize(resourceReference);
    } catch (ComponentLookupException e) {
        extendedURL = super.serialize(resourceReference);
    }
    return extendedURL;
}
Also used : VfsResourceReference(org.xwiki.vfs.VfsResourceReference) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) ExtendedURL(org.xwiki.url.ExtendedURL) URI(java.net.URI)

Example 27 with ExtendedURL

use of org.xwiki.url.ExtendedURL in project xwiki-platform by xwiki.

the class WebJarsScriptServiceTest method computeURLWithoutVersion.

@Test
public void computeURLWithoutVersion() throws Exception {
    WikiDescriptorManager wikiDescriptorManager = this.mocker.getInstance(WikiDescriptorManager.class);
    when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("math");
    InstalledExtensionRepository installedExtensionRepository = this.mocker.getInstance(InstalledExtensionRepository.class);
    InstalledExtension extension = mock(InstalledExtension.class);
    when(installedExtensionRepository.getInstalledExtension("org.webjars:angular", "wiki:math")).thenReturn(extension);
    when(extension.getId()).thenReturn(new ExtensionId("bar", "2.1.11"));
    WebJarsResourceReference resourceReference = new WebJarsResourceReference("wiki:math", Arrays.asList("angular", "2.1.11", "angular.css"));
    when(this.serializer.serialize(resourceReference)).thenReturn(new ExtendedURL(Arrays.asList("xwiki", "angular", "2.1.11", "angular.css")));
    assertEquals("/xwiki/angular/2.1.11/angular.css", this.mocker.getComponentUnderTest().url("angular", "angular.css"));
}
Also used : InstalledExtension(org.xwiki.extension.InstalledExtension) WebJarsResourceReference(org.xwiki.webjars.internal.WebJarsResourceReference) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) ExtensionId(org.xwiki.extension.ExtensionId) ExtendedURL(org.xwiki.url.ExtendedURL) InstalledExtensionRepository(org.xwiki.extension.repository.InstalledExtensionRepository) Test(org.junit.Test)

Example 28 with ExtendedURL

use of org.xwiki.url.ExtendedURL in project xwiki-platform by xwiki.

the class WebJarsScriptServiceTest method computeURLWithParametersAndWikiIsNotSpecifiedInParameter.

@Test
public void computeURLWithParametersAndWikiIsNotSpecifiedInParameter() throws Exception {
    WikiDescriptorManager wikiDescriptorManager = this.mocker.getInstance(WikiDescriptorManager.class);
    when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("math");
    InstalledExtensionRepository installedExtensionRepository = this.mocker.getInstance(InstalledExtensionRepository.class);
    InstalledExtension extension = mock(InstalledExtension.class);
    when(installedExtensionRepository.getInstalledExtension("org.webjars:angular", "wiki:math")).thenReturn(extension);
    when(extension.getId()).thenReturn(new ExtensionId("bar", "2.1.11"));
    WebJarsResourceReference resourceReference = new WebJarsResourceReference("wiki:math", Arrays.asList("angular", "2.1.11", "angular.css"));
    when(this.serializer.serialize(resourceReference)).thenReturn(new ExtendedURL(Arrays.asList("xwiki", "angular", "2.1.11", "angular.css")));
    assertEquals("/xwiki/angular/2.1.11/angular.css", this.mocker.getComponentUnderTest().url("angular", "angular.css", Collections.<String, Object>emptyMap()));
}
Also used : InstalledExtension(org.xwiki.extension.InstalledExtension) WebJarsResourceReference(org.xwiki.webjars.internal.WebJarsResourceReference) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) ExtensionId(org.xwiki.extension.ExtensionId) ExtendedURL(org.xwiki.url.ExtendedURL) InstalledExtensionRepository(org.xwiki.extension.repository.InstalledExtensionRepository) Test(org.junit.Test)

Example 29 with ExtendedURL

use of org.xwiki.url.ExtendedURL in project xwiki-platform by xwiki.

the class WebJarsScriptServiceTest method computeURLForBackwardCompatibilityWhenWikiIsSpecifiedAsParameter.

@Test
public void computeURLForBackwardCompatibilityWhenWikiIsSpecifiedAsParameter() throws Exception {
    InstalledExtensionRepository installedExtensionRepository = this.mocker.getInstance(InstalledExtensionRepository.class);
    InstalledExtension extension = mock(InstalledExtension.class);
    when(installedExtensionRepository.getInstalledExtension("org.webjars:angular", "wiki:math")).thenReturn(extension);
    when(extension.getId()).thenReturn(new ExtensionId("bar", "2.1.11"));
    WebJarsResourceReference resourceReference = new WebJarsResourceReference("wiki:math", Arrays.asList("angular", "2.1.11", "angular.css"));
    when(this.serializer.serialize(resourceReference)).thenReturn(new ExtendedURL(Arrays.asList("xwiki", "angular", "2.1.11", "angular.css")));
    assertEquals("/xwiki/angular/2.1.11/angular.css", this.mocker.getComponentUnderTest().url("angular", "angular.css", Collections.singletonMap("wiki", "math")));
}
Also used : InstalledExtension(org.xwiki.extension.InstalledExtension) WebJarsResourceReference(org.xwiki.webjars.internal.WebJarsResourceReference) ExtensionId(org.xwiki.extension.ExtensionId) ExtendedURL(org.xwiki.url.ExtendedURL) InstalledExtensionRepository(org.xwiki.extension.repository.InstalledExtensionRepository) Test(org.junit.Test)

Example 30 with ExtendedURL

use of org.xwiki.url.ExtendedURL in project xwiki-platform by xwiki.

the class WebJarsScriptServiceTest method computeJavaScriptURLWithSuffixAndNoParameters.

@Test
public void computeJavaScriptURLWithSuffixAndNoParameters() throws Exception {
    WikiDescriptorManager wikiDescriptorManager = this.mocker.getInstance(WikiDescriptorManager.class);
    when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("math");
    WebJarsResourceReference resourceReference = new WebJarsResourceReference("wiki:math", Arrays.asList("angular", "angular.js"));
    resourceReference.addParameter("r", "1");
    when(this.serializer.serialize(resourceReference)).thenReturn(new ExtendedURL(Arrays.asList("xwiki", "angular", "angular.js"), resourceReference.getParameters()));
    assertEquals("/xwiki/angular/angular.js?r=1", this.mocker.getComponentUnderTest().url("angular", "angular.js"));
}
Also used : WebJarsResourceReference(org.xwiki.webjars.internal.WebJarsResourceReference) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) ExtendedURL(org.xwiki.url.ExtendedURL) Test(org.junit.Test)

Aggregations

ExtendedURL (org.xwiki.url.ExtendedURL)46 Test (org.junit.Test)26 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)13 ResourceType (org.xwiki.resource.ResourceType)10 URL (java.net.URL)9 WebJarsResourceReference (org.xwiki.webjars.internal.WebJarsResourceReference)8 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)7 VfsResourceReference (org.xwiki.vfs.VfsResourceReference)7 HashMap (java.util.HashMap)6 List (java.util.List)6 EntityResourceReference (org.xwiki.resource.entity.EntityResourceReference)6 ServletException (javax.servlet.ServletException)5 WikiDescriptorManager (org.xwiki.wiki.descriptor.WikiDescriptorManager)5 IOException (java.io.IOException)4 Type (java.lang.reflect.Type)3 ExtensionId (org.xwiki.extension.ExtensionId)3 InstalledExtension (org.xwiki.extension.InstalledExtension)3 InstalledExtensionRepository (org.xwiki.extension.repository.InstalledExtensionRepository)3 DocumentReference (org.xwiki.model.reference.DocumentReference)3 ResourceReference (org.xwiki.resource.ResourceReference)3