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