use of org.olat.core.util.vfs.LocalFolderImpl in project OpenOLAT by OpenOLAT.
the class IframePortletRunController method initEditButton.
/**
* Helper to build the editor button and initialize some variables needed by
* the editor
*
* @param ureq
* @param editFilePath
*/
private boolean initEditButton(String editFilePath) {
if (editFilePath == null) {
log.warn("initEditButton: editFilePath was null");
return false;
}
File editFile = new File(editFilePath);
File parent = editFile.getParentFile();
if (parent == null) {
log.warn("initEditButton: no parent folder for " + editFilePath);
return false;
}
if (!editFile.getParentFile().exists()) {
log.warn("editFilePath is wrong, not even parent dir exists::" + editFile.getParentFile().getAbsolutePath());
return false;
}
if (!editFile.canWrite()) {
log.warn("Can not write to file::" + editFile.getAbsolutePath());
return false;
}
if (!editFile.exists()) {
try {
editFile.createNewFile();
} catch (IOException e) {
log.error("Cannot create file::" + editFile.getAbsolutePath());
return false;
}
}
// now as we have a writable file we initialize the path to this file
// and the edit button
fileName = editFile.getName();
rootDir = new LocalFolderImpl(editFile.getParentFile());
return true;
}
use of org.olat.core.util.vfs.LocalFolderImpl in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class GlossaryTermMapper 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();
// security checks are done by MapperRegistry
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("GlossaryTerms delivery failed; path to glossaryFolder not existing: " + relPath, null);
return new NotFoundMediaResource();
}
VFSContainer glossaryFolder = new LocalFolderImpl(glossaryFolderFile);
if (!gIM.isFolderContainingGlossary(glossaryFolder)) {
logWarn("GlossaryTerms delivery failed; glossaryFolder doesn't contain a valid Glossary: " + glossaryFolder, null);
return new NotFoundMediaResource();
}
// 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/javascript");
// Get data
String glossaryArrayData = TextMarkerJsGenerator.loadGlossaryItemListAsJSArray(glossaryFolder);
resource.setData(glossaryArrayData);
// UTF-8 encoding used in this js file since explicitly set in the ajax
// call (usually js files are 8859-1)
resource.setEncoding("utf-8");
return resource;
}
use of org.olat.core.util.vfs.LocalFolderImpl in project OpenOLAT by OpenOLAT.
the class ZipUtil method unzipStrict.
/**
* Unzip a file in the target dir with the restricted version
* @param zipFile
* @param targetDir
* @return
*/
public static boolean unzipStrict(File zipFile, VFSContainer targetDir) {
if (targetDir instanceof LocalFolderImpl) {
String outdir = ((LocalFolderImpl) targetDir).getBasefile().getAbsolutePath();
InputStream in = null;
try {
long s = System.currentTimeMillis();
in = new FileInputStream(zipFile);
xxunzip(in, outdir);
log.info("unzip file=" + zipFile.getName() + " to=" + outdir + " t=" + Long.toString(System.currentTimeMillis() - s));
return true;
} catch (IOException e) {
log.error("I/O failure while unzipping " + zipFile.getName() + " to " + outdir);
return false;
} finally {
IOUtils.closeQuietly(in);
}
}
return false;
}
use of org.olat.core.util.vfs.LocalFolderImpl in project OpenOLAT by OpenOLAT.
the class MailModule method getRootForAttachments.
public VFSContainer getRootForAttachments() {
String root = folderModule.getCanonicalRoot() + attachmentsRoot;
File rootFile = new File(root);
if (!rootFile.exists()) {
rootFile.mkdirs();
}
VFSContainer rootContainer = new LocalFolderImpl(rootFile);
return rootContainer;
}
Aggregations