Search in sources :

Example 66 with MediaResource

use of org.olat.core.gui.media.MediaResource in project OpenOLAT by OpenOLAT.

the class RepositoryEntryImportExport method exportDoExportContent.

/**
 * Export a repository entry referenced by a course node to the given export directory.
 * User importReferencedRepositoryEntry to import again.
 * @return True upon success, false otherwise.
 */
public boolean exportDoExportContent() {
    // export resource
    RepositoryHandler rh = RepositoryHandlerFactory.getInstance().getRepositoryHandler(re);
    MediaResource mr = rh.getAsMediaResource(re.getOlatResource(), false);
    FileOutputStream fOut = null;
    try {
        fOut = new FileOutputStream(new File(baseDirectory, CONTENT_FILE));
        InputStream in = mr.getInputStream();
        if (in == null) {
            HttpServletResponse hres = new HttpServletResponseOutputStream(fOut);
            mr.prepare(hres);
        } else {
            IOUtils.copy(mr.getInputStream(), fOut);
        }
        fOut.flush();
    } catch (IOException fnfe) {
        return false;
    } finally {
        IOUtils.closeQuietly(fOut);
        mr.release();
    }
    return true;
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) HttpServletResponse(javax.servlet.http.HttpServletResponse) MediaResource(org.olat.core.gui.media.MediaResource) RepositoryHandler(org.olat.repository.handlers.RepositoryHandler) HttpServletResponseOutputStream(org.olat.core.util.io.HttpServletResponseOutputStream) IOException(java.io.IOException) File(java.io.File)

Example 67 with MediaResource

use of org.olat.core.gui.media.MediaResource in project OpenOLAT by OpenOLAT.

the class AuthorListController method doDownload.

protected void doDownload(UserRequest ureq, AuthoringEntryRow row) {
    RepositoryHandler typeToDownload = repositoryHandlerFactory.getRepositoryHandler(row.getResourceType());
    if (typeToDownload == null) {
        StringBuilder sb = new StringBuilder(translate("error.download"));
        sb.append(": No download handler for repository entry: ").append(row.getKey());
        showError(sb.toString());
        return;
    }
    RepositoryEntry entry = repositoryService.loadByKey(row.getKey());
    OLATResourceable ores = entry.getOlatResource();
    if (ores == null) {
        showError("error.download");
        return;
    }
    boolean isAlreadyLocked = typeToDownload.isLocked(ores);
    try {
        lockResult = typeToDownload.acquireLock(ores, ureq.getIdentity());
        if (lockResult == null || (lockResult != null && lockResult.isSuccess() && !isAlreadyLocked)) {
            MediaResource mr = typeToDownload.getAsMediaResource(ores, false);
            if (mr != null) {
                repositoryService.incrementDownloadCounter(entry);
                ureq.getDispatchResult().setResultingMediaResource(mr);
            } else {
                showError("error.export");
                fireEvent(ureq, Event.FAILED_EVENT);
            }
        } else if (lockResult != null && lockResult.isSuccess() && isAlreadyLocked) {
            String fullName = userManager.getUserDisplayName(lockResult.getOwner());
            showInfo("warning.course.alreadylocked.bySameUser", fullName);
            // invalid lock, it was already locked
            lockResult = null;
        } else {
            String fullName = userManager.getUserDisplayName(lockResult.getOwner());
            showInfo("warning.course.alreadylocked", fullName);
        }
    } finally {
        if ((lockResult != null && lockResult.isSuccess() && !isAlreadyLocked)) {
            typeToDownload.releaseLock(lockResult);
            lockResult = null;
        }
    }
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) MediaResource(org.olat.core.gui.media.MediaResource) RepositoryHandler(org.olat.repository.handlers.RepositoryHandler) OrderedRepositoryHandler(org.olat.repository.handlers.RepositoryHandlerFactory.OrderedRepositoryHandler) RepositoryEntry(org.olat.repository.RepositoryEntry)

Example 68 with MediaResource

use of org.olat.core.gui.media.MediaResource in project OpenOLAT by OpenOLAT.

the class ShibbolethDispatcher method execute.

/**
 * Main method called by OpenOLATServlet.
 * This processess all shibboleth requests.
 *
 * @param req
 * @param resp
 * @param uriPrefix
 */
@Override
public void execute(HttpServletRequest req, HttpServletResponse resp) {
    if (translator == null) {
        translator = Util.createPackageTranslator(ShibbolethDispatcher.class, I18nModule.getDefaultLocale());
    }
    if (!shibbolethModule.isEnableShibbolethLogins()) {
        throw new OLATSecurityException("Got shibboleth request but shibboleth is not enabled");
    }
    String uriPrefix = DispatcherModule.getLegacyUriPrefix(req);
    Map<String, String> attributesMap = getShibbolethAttributesFromRequest(req);
    ShibbolethAttributes shibbolethAttriutes = CoreSpringFactory.getImpl(ShibbolethAttributes.class);
    shibbolethAttriutes.init(attributesMap);
    String uid = shibbolethAttriutes.getUID();
    if (uid == null) {
        handleException(new ShibbolethException(ShibbolethException.UNIQUE_ID_NOT_FOUND, "Unable to get unique identifier for subject. Make sure you are listed in the metadata.xml file and your resources your are trying to access are available and your are allowed to see them. (Resourceregistry). "), req, resp, translator);
        return;
    }
    if (!authorization(req, resp, shibbolethAttriutes)) {
        return;
    }
    UserRequest ureq = null;
    try {
        // upon creation URL is checked for
        ureq = new UserRequestImpl(uriPrefix, req, resp);
    } catch (NumberFormatException nfe) {
        // a 404 message must be shown -> e.g. robots correct their links.
        if (log.isDebug()) {
            log.debug("Bad Request " + req.getPathInfo());
        }
        DispatcherModule.sendBadRequest(req.getPathInfo(), resp);
        return;
    }
    Authentication auth = securityManager.findAuthenticationByAuthusername(uid, PROVIDER_SHIB);
    if (auth == null) {
        // no matching authentication...
        ShibbolethRegistrationController.putShibAttributes(req, shibbolethAttriutes);
        ShibbolethRegistrationController.putShibUniqueID(req, uid);
        redirectToShibbolethRegistration(resp);
        return;
    }
    if (ureq.getUserSession() != null) {
        // re-init the activity logger
        ThreadLocalUserActivityLoggerInstaller.initUserActivityLogger(req);
    }
    int loginStatus = AuthHelper.doLogin(auth.getIdentity(), ShibbolethDispatcher.PROVIDER_SHIB, ureq);
    if (loginStatus != AuthHelper.LOGIN_OK) {
        if (loginStatus == AuthHelper.LOGIN_NOTAVAILABLE) {
            DispatcherModule.redirectToServiceNotAvailable(resp);
        } else {
            // error, redirect to login screen
            DispatcherModule.redirectToDefaultDispatcher(resp);
        }
        return;
    }
    // Successful login
    Identity authenticationedIdentity = ureq.getIdentity();
    userDeletionManager.setIdentityAsActiv(authenticationedIdentity);
    shibbolethManager.syncUser(authenticationedIdentity, shibbolethAttriutes);
    ureq.getUserSession().getIdentityEnvironment().addAttributes(shibbolethModule.getAttributeTranslator().translateAttributesMap(shibbolethAttriutes.toMap()));
    MediaResource mr = ureq.getDispatchResult().getResultingMediaResource();
    if (mr instanceof RedirectMediaResource) {
        RedirectMediaResource rmr = (RedirectMediaResource) mr;
        rmr.prepare(resp);
    } else {
        // error, redirect to login screen
        DispatcherModule.redirectToDefaultDispatcher(resp);
    }
}
Also used : ShibbolethAttributes(org.olat.shibboleth.manager.ShibbolethAttributes) Authentication(org.olat.basesecurity.Authentication) OLATSecurityException(org.olat.core.logging.OLATSecurityException) RedirectMediaResource(org.olat.core.gui.media.RedirectMediaResource) MediaResource(org.olat.core.gui.media.MediaResource) RedirectMediaResource(org.olat.core.gui.media.RedirectMediaResource) Identity(org.olat.core.id.Identity) UserRequest(org.olat.core.gui.UserRequest) UserRequestImpl(org.olat.core.gui.UserRequestImpl)

Example 69 with MediaResource

use of org.olat.core.gui.media.MediaResource in project OpenOLAT by OpenOLAT.

the class CertificatesOptionsController method doPreviewTemplate.

private void doPreviewTemplate(UserRequest ureq) {
    selectedTemplate = certificatesManager.getTemplateById(selectedTemplate.getKey());
    File preview = certificatesManager.previewCertificate(selectedTemplate, entry, getLocale());
    MediaResource resource = new PreviewMediaResource(preview);
    ureq.getDispatchResult().setResultingMediaResource(resource);
}
Also used : MediaResource(org.olat.core.gui.media.MediaResource) StreamedMediaResource(org.olat.core.gui.media.StreamedMediaResource) ZippedDirectoryMediaResource(org.olat.fileresource.ZippedDirectoryMediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource) File(java.io.File)

Example 70 with MediaResource

use of org.olat.core.gui.media.MediaResource in project OpenOLAT by OpenOLAT.

the class CertificateController method event.

@Override
protected void event(UserRequest ureq, Component source, Event event) {
    if (downloadButton == source) {
        VFSLeaf certificateLeaf = certificatesManager.getCertificateLeaf(certificate);
        String name = DownloadCertificateCellRenderer.getName(certificate);
        MediaResource certificateResource = new CertificateMediaResource(name, certificateLeaf);
        ureq.getDispatchResult().setResultingMediaResource(certificateResource);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) MediaResource(org.olat.core.gui.media.MediaResource)

Aggregations

MediaResource (org.olat.core.gui.media.MediaResource)141 VFSMediaResource (org.olat.core.util.vfs.VFSMediaResource)36 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)32 NotFoundMediaResource (org.olat.core.gui.media.NotFoundMediaResource)30 Identity (org.olat.core.id.Identity)18 VFSItem (org.olat.core.util.vfs.VFSItem)18 File (java.io.File)16 ArrayList (java.util.ArrayList)16 RedirectMediaResource (org.olat.core.gui.media.RedirectMediaResource)16 IOException (java.io.IOException)13 FileMediaResource (org.olat.core.gui.media.FileMediaResource)12 List (java.util.List)10 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)10 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)10 StringMediaResource (org.olat.core.gui.media.StringMediaResource)8 AssertException (org.olat.core.logging.AssertException)8 RepositoryEntry (org.olat.repository.RepositoryEntry)8 RepositoryHandler (org.olat.repository.handlers.RepositoryHandler)8 InputStream (java.io.InputStream)6 OLATResourceable (org.olat.core.id.OLATResourceable)6