use of org.olat.core.util.vfs.LocalFolderImpl in project openolat by klemens.
the class VideoPosterUploadForm method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
remainingSpace = Quota.UNLIMITED;
videoResourceFileroot = new LocalFolderImpl(FileResourceManager.getInstance().getFileResourceRootImpl(videoResource).getBasefile());
metaDataFolder = VFSManager.getOrCreateContainer(videoResourceFileroot, "media");
posterField = uifactory.addFileElement(getWindowControl(), "poster", "video.config.poster", formLayout);
posterField.limitToMimeType(imageMimeTypes, "poster.error.filetype", null);
posterField.setMaxUploadSizeKB(picUploadlimitKB, null, null);
posterField.setPreview(ureq.getUserSession(), true);
posterField.addActionListener(FormEvent.ONCHANGE);
posterField.setHelpTextKey("poster.help", null);
FormLayoutContainer buttonGroupLayout = FormLayoutContainer.createButtonLayout("buttonGroupLayout", getTranslator());
formLayout.add(buttonGroupLayout);
buttonGroupLayout.setElementCssClass("o_sel_upload_buttons");
uifactory.addFormCancelButton("cancel", buttonGroupLayout, ureq, getWindowControl());
uifactory.addFormSubmitButton("track.upload", buttonGroupLayout);
}
use of org.olat.core.util.vfs.LocalFolderImpl in project openolat by klemens.
the class VideoModule method getTranscodingBaseContainer.
/**
* The base container where the transcoded videos are stored. This config can only be set in
* olat.localproperties, see "video.transcoding.dir"
* @return
*/
public VFSContainer getTranscodingBaseContainer() {
if (transcodingDir != null) {
File base = new File(transcodingDir);
if (base.exists() || base.mkdirs()) {
return new LocalFolderImpl(base);
}
}
if (transcodingEnabled) {
log.error("Error, no valid transcoding dir. Disabling transcoding. video.transcoding.dir=" + transcodingDir);
// only disable variable, don't store it in persisted properties
transcodingEnabled = false;
}
return null;
}
use of org.olat.core.util.vfs.LocalFolderImpl in project openolat by klemens.
the class GlossaryDefinitionMapper method handle.
/**
* @see org.olat.core.dispatcher.mapper.Mapper#handle(java.lang.String,
* javax.servlet.http.HttpServletRequest)
*/
public MediaResource handle(String relPath, HttpServletRequest request) {
GlossaryItemManager gIM = GlossaryItemManager.getInstance();
String[] parts = relPath.split("/");
String glossaryId = parts[1];
String glossaryFolderString = FolderConfig.getCanonicalRoot() + FolderConfig.getRepositoryHome() + "/" + glossaryId + "/" + GlossaryMarkupItemController.INTERNAL_FOLDER_NAME;
File glossaryFolderFile = new File(glossaryFolderString);
if (!glossaryFolderFile.isDirectory()) {
logWarn("GlossaryDefinition delivery failed; path to glossaryFolder not existing: " + relPath, null);
return new NotFoundMediaResource();
}
VFSContainer glossaryFolder = new LocalFolderImpl(glossaryFolderFile);
if (!gIM.isFolderContainingGlossary(glossaryFolder)) {
logWarn("GlossaryDefinition delivery failed; glossaryFolder doesn't contain a valid Glossary: " + glossaryFolder, null);
return new NotFoundMediaResource();
}
String glossaryMainTerm = parts[2];
if (parts.length > 2) {
// this handle / or \ in a term
for (int i = 3; i < parts.length; i++) {
glossaryMainTerm += "/" + parts[i];
}
}
// cut away ".html" if necessary
if (glossaryMainTerm.endsWith(".html")) {
glossaryMainTerm = glossaryMainTerm.substring(0, glossaryMainTerm.length() - 5);
}
glossaryMainTerm = glossaryMainTerm.toLowerCase();
Set<String> alternatives = new HashSet<>();
prepareAlternatives(glossaryMainTerm, alternatives);
// Create a media resource
StringMediaResource resource = new StringMediaResource() {
@Override
public void prepare(HttpServletResponse hres) {
// don't use normal string media headers which prevent caching,
// use standard browser caching based on last modified timestamp
}
};
resource.setLastModified(gIM.getGlossaryLastModifiedTime(glossaryFolder));
resource.setContentType("text/html");
List<GlossaryItem> glossItems = gIM.getGlossaryItemListByVFSItem(glossaryFolder);
GlossaryItem foundItem = null;
for (GlossaryItem glossaryItem : glossItems) {
String item = glossaryItem.getGlossTerm().toLowerCase();
if (alternatives.contains(item)) {
foundItem = glossaryItem;
break;
}
}
if (foundItem == null) {
return new NotFoundMediaResource();
}
StringBuilder sb = new StringBuilder();
sb.append("<dd><dt>").append(foundItem.getGlossTerm()).append("</dt><dl>").append(foundItem.getGlossDef()).append("</dl></dd>");
resource.setData(sb.toString());
resource.setEncoding("utf-8");
if (isLogDebugEnabled())
logDebug("loaded definition for " + glossaryMainTerm, null);
return resource;
}
use of org.olat.core.util.vfs.LocalFolderImpl in project openolat by klemens.
the class RichTextConfiguration method setDocumentMediaBase.
/**
* Set the documents media base that is used to deliver media files
* referenced by the content.
*
* @param documentBaseContainer
* the vfs container that contains the media files
* @param relFilePath
* The file path of the HTML file relative to the
* documentBaseContainer
* @param usess
* The user session
*/
private void setDocumentMediaBase(final VFSContainer documentBaseContainer, String relFilePath, UserSession usess) {
linkBrowserRelativeFilePath = relFilePath;
// get a usersession-local mapper for the file storage (and tinymce's references to images and such)
Mapper contentMapper = new VFSContainerMapper(documentBaseContainer);
// Register mapper for this user. This mapper is cleaned up in the
// dispose method (RichTextElementImpl will clean it up)
// Register mapper as cacheable
String mapperID = VFSManager.getRealPath(documentBaseContainer);
if (mapperID == null) {
// Can't cache mapper, no cacheable context available
contentMapperKey = CoreSpringFactory.getImpl(MapperService.class).register(usess, contentMapper);
} else {
// Add classname to the file path to remove conflicts with other
// usages of the same file path
mapperID = this.getClass().getSimpleName() + ":" + mapperID + ":" + CodeHelper.getRAMUniqueID();
contentMapperKey = CoreSpringFactory.getImpl(MapperService.class).register(usess, mapperID, contentMapper);
}
if (relFilePath != null) {
// remove filename, path must end with slash
int lastSlash = relFilePath.lastIndexOf("/");
if (lastSlash == -1) {
relFilePath = "";
} else if (lastSlash + 1 < relFilePath.length()) {
relFilePath = relFilePath.substring(0, lastSlash + 1);
} else {
String containerPath = documentBaseContainer.getName();
// try to get more information if it's a local folder impl
if (documentBaseContainer instanceof LocalFolderImpl) {
LocalFolderImpl folder = (LocalFolderImpl) documentBaseContainer;
containerPath = folder.getBasefile().getAbsolutePath();
}
log.warn("Could not parse relative file path::" + relFilePath + " in container::" + containerPath);
}
} else {
relFilePath = "";
// set empty relative file path to prevent nullpointers later on
linkBrowserRelativeFilePath = relFilePath;
}
mapperUri = contentMapperKey.getUrl() + "/" + relFilePath;
setQuotedConfigValue(DOCUMENT_BASE_URL, mapperUri);
}
use of org.olat.core.util.vfs.LocalFolderImpl in project openolat by klemens.
the class FileElementImpl method moveUploadFileTo.
@Override
public VFSLeaf moveUploadFileTo(VFSContainer destinationContainer, boolean crop) {
VFSLeaf targetLeaf = null;
if (tempUploadFile != null && tempUploadFile.exists()) {
// Check if such a file does already exist, if yes rename new file
VFSItem existsChild = destinationContainer.resolve(uploadFilename);
if (existsChild != null) {
// Use standard rename policy
uploadFilename = VFSManager.rename(destinationContainer, uploadFilename);
}
// Create target leaf file now and delete original temp file
if (destinationContainer instanceof LocalFolderImpl) {
// Optimize for local files (don't copy, move instead)
LocalFolderImpl folderContainer = (LocalFolderImpl) destinationContainer;
File destinationDir = folderContainer.getBasefile();
File targetFile = new File(destinationDir, uploadFilename);
Crop cropSelection = previewEl == null ? null : previewEl.getCropSelection();
if (crop && cropSelection != null) {
CoreSpringFactory.getImpl(ImageService.class).cropImage(tempUploadFile, targetFile, cropSelection);
targetLeaf = (VFSLeaf) destinationContainer.resolve(targetFile.getName());
} else if (FileUtils.copyFileToFile(tempUploadFile, targetFile, true)) {
targetLeaf = (VFSLeaf) destinationContainer.resolve(targetFile.getName());
} else {
log.error("Error after copying content from temp file, cannot copy file::" + (tempUploadFile == null ? "NULL" : tempUploadFile) + " - " + (targetFile == null ? "NULL" : targetFile), null);
}
if (targetLeaf == null) {
log.error("Error after copying content from temp file, cannot resolve copied file::" + (tempUploadFile == null ? "NULL" : tempUploadFile) + " - " + (targetFile == null ? "NULL" : targetFile), null);
}
} else {
// Copy stream in case the destination is a non-local container
VFSLeaf leaf = destinationContainer.createChildLeaf(uploadFilename);
boolean success = false;
try {
success = VFSManager.copyContent(new FileInputStream(tempUploadFile), leaf);
} catch (FileNotFoundException e) {
log.error("Error while copying content from temp file::" + (tempUploadFile == null ? "NULL" : tempUploadFile.getAbsolutePath()), e);
}
if (success) {
// Delete original temp file after copy to simulate move
// behavior
tempUploadFile.delete();
targetLeaf = leaf;
}
}
} else if (log.isDebug()) {
log.debug("Error while copying content from temp file, no temp file::" + (tempUploadFile == null ? "NULL" : tempUploadFile.getAbsolutePath()));
}
return targetLeaf;
}
Aggregations