Search in sources :

Example 11 with Extension

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

the class RepositoryManager method addExtensionVersionObjectToDocument.

/**
 * Call this method only, when it was check that given extension version xobject is ABSENT
 */
private void addExtensionVersionObjectToDocument(XWikiDocument extensionDocument, String extensionVersion) throws XWikiException, ResolveException {
    Extension extension = resolveExtensionVersion(extensionDocument, extensionVersion);
    if (extension == null) {
        return;
    }
    boolean needSave = updateExtensionVersion(extensionDocument, extension);
    if (needSave) {
        xcontextProvider.get().getWiki().saveDocument(extensionDocument, xcontextProvider.get());
    }
}
Also used : Extension(org.xwiki.extension.Extension)

Example 12 with Extension

use of org.xwiki.extension.Extension 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)

Aggregations

Extension (org.xwiki.extension.Extension)12 ExtensionId (org.xwiki.extension.ExtensionId)7 LocalExtension (org.xwiki.extension.LocalExtension)6 InstalledExtension (org.xwiki.extension.InstalledExtension)5 ResolveException (org.xwiki.extension.ResolveException)5 XWikiException (com.xpn.xwiki.XWikiException)3 IOException (java.io.IOException)3 CoreExtension (org.xwiki.extension.CoreExtension)3 SearchException (org.xwiki.extension.repository.search.SearchException)3 JobException (org.xwiki.job.JobException)3 QueryException (org.xwiki.query.QueryException)3 HashSet (java.util.HashSet)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 Version (org.xwiki.extension.version.Version)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 BaseObject (com.xpn.xwiki.objects.BaseObject)1 URISyntaxException (java.net.URISyntaxException)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1