use of org.xwiki.extension.repository.ExtensionRepository in project xwiki-platform by xwiki.
the class ExtensionRatingScriptService method getRating.
/**
* @param extensionId the extension id
* @param extensionVersion the extension version
* @return the rating of an extension
*/
public ExtensionRating getRating(String extensionId, String extensionVersion) {
setError(null);
Collection<ExtensionRepository> repositories = getRepositories();
for (ExtensionRepository repository : repositories) {
if (repository instanceof Ratable) {
try {
setError(null);
return ((Ratable) repository).getRating(extensionId, extensionVersion);
} catch (ResolveException e) {
setError(e);
// Keep looking. Maybe there's another repository with the same extension.
continue;
}
}
}
return null;
}
use of org.xwiki.extension.repository.ExtensionRepository in project xwiki-platform by xwiki.
the class RepositoryManager method resolveExtensionVersion.
/**
* This method factually resolves extension from remote source (when it's possible). Call it only when the data that
* is going to be obtained cannot be got from extension document xobject
*
* @since 9.5RC1
*/
public Extension resolveExtensionVersion(XWikiDocument extensionDocument, String extensionVersion) throws ResolveException {
BaseObject extensionObject = extensionDocument.getXObject(XWikiRepositoryModel.EXTENSION_CLASSREFERENCE);
if (extensionObject == null) {
return null;
}
String extensionId = getValue(extensionObject, XWikiRepositoryModel.PROP_EXTENSION_ID, (String) null);
BaseObject extensionProxyObject = extensionDocument.getXObject(XWikiRepositoryModel.EXTENSIONPROXY_CLASSREFERENCE);
if (extensionProxyObject == null) {
return null;
}
String repositoryId = getValue(extensionProxyObject, XWikiRepositoryModel.PROP_PROXY_REPOSITORYID, (String) null);
if (extensionId == null || repositoryId == null) {
return null;
}
ExtensionRepository repository = this.extensionRepositoryManager.getRepository(repositoryId);
if (isGivenVersionOneOfExtensionVersions(repository, extensionId, extensionVersion)) {
return repository.resolve(new ExtensionId(extensionId, extensionVersion));
} else {
return tryToResolveExtensionFromExtensionFeatures(repository, extensionObject, extensionVersion);
}
}
use of org.xwiki.extension.repository.ExtensionRepository 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;
}
Aggregations