Search in sources :

Example 66 with ExtensionId

use of org.xwiki.extension.ExtensionId in project xwiki-platform by xwiki.

the class ExtensionVersionFileRESTResource method downloadRemoteExtension.

private ResponseBuilder downloadRemoteExtension(ExtensionResourceReference extensionResource) throws ResolveException, IOException {
    ExtensionRepository repository = null;
    if (extensionResource.getRepositoryId() != null) {
        repository = this.extensionRepositoryManager.getRepository(extensionResource.getRepositoryId());
    }
    if (repository == null && extensionResource.getRepositoryType() != null && extensionResource.getRepositoryURI() != null) {
        ExtensionRepositoryDescriptor repositoryDescriptor = new DefaultExtensionRepositoryDescriptor("tmp", extensionResource.getRepositoryType(), extensionResource.getRepositoryURI());
        try {
            ExtensionRepositoryFactory repositoryFactory = this.componentManager.getInstance(ExtensionRepositoryFactory.class, repositoryDescriptor.getType());
            repository = repositoryFactory.createRepository(repositoryDescriptor);
        } catch (Exception e) {
            // Ignore invalid repository
            getLogger().warn("Invalid repository in download link [{}]", extensionResource);
        }
    }
    // Resolve extension
    Extension downloadExtension;
    if (repository == null) {
        downloadExtension = this.extensionRepositoryManager.resolve(new ExtensionId(extensionResource.getExtensionId(), extensionResource.getExtensionVersion()));
    } else {
        downloadExtension = repository.resolve(new ExtensionId(extensionResource.getExtensionId(), extensionResource.getExtensionVersion()));
    }
    // Get file
    // TODO: find media type
    ExtensionFile extensionFile = downloadExtension.getFile();
    long length = extensionFile.getLength();
    // TODO: find a proper way to do a perfect proxy of the URL without directly using Restlet classes.
    // Should probably use javax.ws.rs.ext.MessageBodyWriter
    InputRepresentation content = new InputRepresentation(extensionFile.openStream(), MediaType.ALL, length);
    Disposition disposition = new Disposition(Disposition.TYPE_ATTACHMENT);
    disposition.setFilename(downloadExtension.getId().toString() + '.' + downloadExtension.getType());
    content.setDisposition(disposition);
    ResponseBuilder response = Response.ok();
    response.entity(content);
    return response;
}
Also used : Extension(org.xwiki.extension.Extension) InputRepresentation(org.restlet.representation.InputRepresentation) ExtensionRepository(org.xwiki.extension.repository.ExtensionRepository) ExtensionRepositoryFactory(org.xwiki.extension.repository.ExtensionRepositoryFactory) Disposition(org.restlet.data.Disposition) ExtensionId(org.xwiki.extension.ExtensionId) DefaultExtensionRepositoryDescriptor(org.xwiki.extension.repository.DefaultExtensionRepositoryDescriptor) ExtensionFile(org.xwiki.extension.ExtensionFile) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) XWikiException(com.xpn.xwiki.XWikiException) URISyntaxException(java.net.URISyntaxException) WebApplicationException(javax.ws.rs.WebApplicationException) QueryException(org.xwiki.query.QueryException) IOException(java.io.IOException) ResolveException(org.xwiki.extension.ResolveException) ExtensionRepositoryDescriptor(org.xwiki.extension.repository.ExtensionRepositoryDescriptor) DefaultExtensionRepositoryDescriptor(org.xwiki.extension.repository.DefaultExtensionRepositoryDescriptor)

Example 67 with ExtensionId

use of org.xwiki.extension.ExtensionId in project xwiki-platform by xwiki.

the class RepositoryTest method setUp.

@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    // base extension informations
    this.baseExtension = getRepositoryTestUtils().getTestExtension(new ExtensionId(IDPREFIX + "macro-jar-extension", "1.0"), "jar");
    this.baseExtension.setName("Macro JAR extension");
    this.baseExtension.setDescription("extension description");
    this.baseExtension.setSummary("extension summary, **not bold**");
    this.baseLicense = new ExtensionLicense("Do What The Fuck You Want To Public License 2", null);
    this.baseExtension.addLicense(this.baseLicense);
    this.baseAuthor = new DefaultExtensionAuthor("User Name", getUtil().getURL("XWiki", USER_CREDENTIALS.getUserName()));
    this.baseExtension.addAuthor(this.baseAuthor);
    this.baseExtension.addDependency(new DefaultExtensionDependency("dependencyid1", new DefaultVersionConstraint("1.0")));
    this.baseExtension.addDependency(new DefaultExtensionDependency("dependencyid2", new DefaultVersionConstraint("2.0")));
    this.sizeOfFile = FileUtils.sizeOf(this.baseExtension.getFile().getFile());
}
Also used : ExtensionLicense(org.xwiki.extension.ExtensionLicense) DefaultExtensionAuthor(org.xwiki.extension.DefaultExtensionAuthor) DefaultVersionConstraint(org.xwiki.extension.version.internal.DefaultVersionConstraint) ExtensionId(org.xwiki.extension.ExtensionId) DefaultExtensionDependency(org.xwiki.extension.DefaultExtensionDependency) Before(org.junit.Before)

Aggregations

ExtensionId (org.xwiki.extension.ExtensionId)67 Test (org.junit.Test)37 InstalledExtension (org.xwiki.extension.InstalledExtension)13 ExtensionAdministrationPage (org.xwiki.extension.test.po.ExtensionAdministrationPage)11 TestExtension (org.xwiki.repository.test.TestExtension)11 ExtensionPane (org.xwiki.extension.test.po.ExtensionPane)9 DocumentReference (org.xwiki.model.reference.DocumentReference)9 InstalledExtensionRepository (org.xwiki.extension.repository.InstalledExtensionRepository)8 Extension (org.xwiki.extension.Extension)7 InstallRequest (org.xwiki.extension.job.InstallRequest)6 DefaultVersionConstraint (org.xwiki.extension.version.internal.DefaultVersionConstraint)6 WikiDescriptorManager (org.xwiki.wiki.descriptor.WikiDescriptorManager)6 IOException (java.io.IOException)5 DefaultExtensionDependency (org.xwiki.extension.DefaultExtensionDependency)5 SearchResultsPane (org.xwiki.extension.test.po.SearchResultsPane)5 ViewPage (org.xwiki.test.ui.po.ViewPage)5 XWikiContext (com.xpn.xwiki.XWikiContext)4 ResolveException (org.xwiki.extension.ResolveException)4 DependencyPane (org.xwiki.extension.test.po.DependencyPane)4 LogItemPane (org.xwiki.extension.test.po.LogItemPane)4