use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.
the class GlossaryItemManager method upgradeAndDeleteOldGlossary.
/**
* upgrades the old textmarker-format into the new DocBook-glossary-format
*
* @param folderContainingGlossary
* @param textMarkerFile
*/
protected void upgradeAndDeleteOldGlossary(VFSContainer folderContainingGlossary, VFSLeaf textMarkerFile) {
// check if a new glossary exists, warn
if (folderContainingGlossary.resolve(GLOSSARY_FILENAME) != null) {
logError("Upgrading Glossary in " + folderContainingGlossary.toString() + ": There is already a new glossary-file. There can't be an old and a new version in the same directory!", null);
} else {
// upgrade it
TextMarkerManager textMarkerManager = TextMarkerManagerImpl.getInstance();
List<TextMarker> textMarkerList = textMarkerManager.loadTextMarkerList(textMarkerFile);
Collections.sort(textMarkerList);
ArrayList<GlossaryItem> glossaryItemArr = new ArrayList<GlossaryItem>();
for (TextMarker tm : textMarkerList) {
String glossTerm = tm.getMarkedMainText();
String glossDef = tm.getHooverText();
GlossaryItem glossItem = new GlossaryItem(glossTerm, glossDef);
// handle alias -> save as synonyms
String aliasString = tm.getMarkedAliasText();
if (StringHelper.containsNonWhitespace(aliasString)) {
String[] aliasArr = aliasString.split(";");
ArrayList<String> glossSynonyms = new ArrayList<String>();
glossSynonyms.addAll(Arrays.asList(aliasArr));
glossItem.setGlossSynonyms(glossSynonyms);
}
glossaryItemArr.add(glossItem);
}
VFSLeaf glossaryFile = folderContainingGlossary.createChildLeaf(GLOSSARY_FILENAME);
saveToFile(glossaryFile, glossaryItemArr);
// keep a backup in debug mode:
if (Settings.isDebuging()) {
File tmFile = ((LocalFileImpl) textMarkerFile).getBasefile();
File tmCont = ((LocalFolderImpl) folderContainingGlossary).getBasefile();
FileUtils.copyFileToDir(tmFile, new File(tmCont + "/bkp"), "backup old glossary");
}
textMarkerFile.delete();
}
}
use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.
the class FileElementImpl method setInitialFile.
@Override
public void setInitialFile(File initialFile) {
this.initialFile = initialFile;
if (initialFile != null && previewEl != null) {
VFSLeaf media = new LocalFileImpl(initialFile);
previewEl.setMedia(media);
previewEl.setMaxWithAndHeightToFitWithin(300, 200);
previewEl.setVisible(true);
} else if (previewEl != null) {
previewEl.setVisible(false);
}
}
use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.
the class SendDocumentsByEMailController method setFiles.
protected void setFiles(VFSContainer rootContainer, List<VFSLeaf> leafs) {
this.files = leafs;
StringBuilder subjectSb = new StringBuilder();
if (StringHelper.containsNonWhitespace(subjectElement.getValue())) {
subjectSb.append(subjectElement.getValue()).append('\n').append('\n');
}
StringBuilder bodySb = new StringBuilder();
if (StringHelper.containsNonWhitespace(bodyElement.getValue())) {
bodySb.append(bodyElement.getValue()).append('\n').append('\n');
}
attachments = new ArrayList<File>();
long fileSize = 0l;
for (VFSLeaf file : files) {
MetaInfo infos = null;
if (file instanceof MetaTagged) {
infos = ((MetaTagged) file).getMetaInfo();
}
// subject
appendToSubject(file, infos, subjectSb);
// body
appendMetadatas(file, infos, bodySb);
appendBusinessPath(rootContainer, file, bodySb);
bodySb.append('\n').append('\n');
fileSize += file.getSize();
if (allowAttachments && file instanceof LocalFileImpl) {
File f = ((LocalFileImpl) file).getBasefile();
attachments.add(f);
}
}
int mailQuota = CoreSpringFactory.getImpl(MailModule.class).getMaxSizeForAttachement();
long fileSizeInMB = fileSize / (1024l * 1024l);
if (allowAttachments) {
if (fileSizeInMB > mailQuota) {
attachments.clear();
setFormWarning("send.mail.fileToBigForAttachments", new String[] { String.valueOf(mailQuota), String.valueOf(fileSizeInMB) });
} else {
List<FileInfo> infos = new ArrayList<FileInfo>(files.size());
for (VFSLeaf file : files) {
final String name = file.getName();
final double size = file.getSize() / (1024.0 * 1024.0);
final String sizeStr = formatMb.format(size);
final String cssClass = CSSHelper.createFiletypeIconCssClassFor(file.getName());
infos.add(new FileInfo(name, sizeStr, cssClass));
}
attachmentsLayout.contextPut("attachments", infos);
}
}
subjectElement.setValue(subjectSb.toString());
bodyElement.setValue(bodySb.toString());
}
use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.
the class ExportManager method saveFile.
private void saveFile(String targetDir, String fileName, VFSContainer tmpDir, List<VFSItem> files, String email, String emailI18nSubkey, Locale locale) {
File file = new File(targetDir, fileName);
VFSLeaf exportFile = new LocalFileImpl(file);
if (!ZipUtil.zip(files, exportFile, true)) {
// cleanup zip file
exportFile.delete();
} else {
// success
sendEMail(email, locale, emailI18nSubkey);
}
removeTemporaryFolder(tmpDir);
}
use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.
the class ForumOpenXMLFormatter method processAttachments.
private void processAttachments(VFSContainer attachmentsContainer) {
List<VFSItem> attachments = new ArrayList<VFSItem>(attachmentsContainer.getItems(filter));
for (VFSItem attachment : attachments) {
if (attachment instanceof LocalFileImpl) {
// add the text
document.appendText(translator.translate("attachments"), true, Style.bold);
}
}
for (VFSItem attachment : attachments) {
if (attachment instanceof LocalFileImpl) {
File file = ((LocalFileImpl) attachment).getBasefile();
String filename = file.getName();
int lastDot = filename.lastIndexOf('.');
boolean attach = true;
if (lastDot > 0) {
String extension = filename.substring(lastDot + 1).toLowerCase();
if ("jpeg".equals(extension) || "jpg".equals(extension) || "gif".equals(extension) || "png".equals(extension)) {
document.appendImage(file);
attach = false;
}
}
if (attach) {
StringBuilder attachSb = new StringBuilder(64);
String uniqueFilename = getUniqueFilename(file);
fileToAttachmentsMap.put(file, new DocReference("", uniqueFilename, null, file));
attachSb.append(filename).append(": /attachments/").append(uniqueFilename);
document.appendText(attachSb.toString(), true);
}
}
}
}
Aggregations