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