use of org.olat.core.util.vfs.JavaIOItem in project OpenOLAT by OpenOLAT.
the class WordOOXMLDocument method readContent.
@Override
public FileContent readContent(VFSLeaf leaf) throws IOException, DocumentException {
File file = ((JavaIOItem) leaf).getBasefile();
LimitedContentWriter writer = new LimitedContentWriter(100000, FileDocumentFactory.getMaxFileSize());
try (ZipFile wordFile = new ZipFile(file)) {
List<String> contents = new ArrayList<>();
for (Enumeration<? extends ZipEntry> entriesEnumeration = wordFile.entries(); entriesEnumeration.hasMoreElements(); ) {
ZipEntry entry = entriesEnumeration.nextElement();
String name = entry.getName();
if (name.endsWith("word/document.xml")) {
contents.add(name);
} else if (name.startsWith(HEADER) && name.endsWith(".xml")) {
contents.add(name);
} else if (name.startsWith(FOOTER) && name.endsWith(".xml")) {
contents.add(name);
}
}
if (contents.size() > 1) {
Collections.sort(contents, new WordDocumentComparator());
}
for (String content : contents) {
if (writer.accept()) {
ZipEntry entry = wordFile.getEntry(content);
InputStream zip = wordFile.getInputStream(entry);
OfficeDocumentHandler dh = new OfficeDocumentHandler(writer);
parse(new ShieldInputStream(zip), dh);
zip.close();
}
}
} catch (DocumentException e) {
throw e;
} catch (Exception e) {
throw new DocumentException(e.getMessage());
}
return new FileContent(writer.toString());
}
use of org.olat.core.util.vfs.JavaIOItem in project OpenOLAT by OpenOLAT.
the class CollectImageMediaController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
formLayout.setElementCssClass("o_sel_pf_collect_image_form");
String title = mediaReference == null ? null : mediaReference.getTitle();
titleEl = uifactory.addTextElement("artefact.title", "artefact.title", 255, title, formLayout);
titleEl.setElementCssClass("o_sel_pf_collect_title");
titleEl.setMandatory(true);
String desc = mediaReference == null ? null : mediaReference.getDescription();
descriptionEl = uifactory.addRichTextElementForStringDataMinimalistic("artefact.descr", "artefact.descr", desc, 8, 60, formLayout, getWindowControl());
descriptionEl.getEditorConfiguration().setPathInStatusBar(false);
fileEl = uifactory.addFileElement(getWindowControl(), "artefact.file", "artefact.file", formLayout);
fileEl.limitToMimeType(imageMimeTypes, null, null);
fileEl.addActionListener(FormEvent.ONCHANGE);
fileEl.setMaxUploadSizeKB(10000, null, null);
fileEl.setPreview(ureq.getUserSession(), true);
if (mediaReference != null) {
fileEl.setEnabled(false);
VFSItem item = fileHandler.getImage(mediaReference);
if (item instanceof JavaIOItem) {
fileEl.setInitialFile(((JavaIOItem) item).getBasefile());
}
}
categoriesEl = uifactory.addTextBoxListElement("categories", "categories", "categories.hint", categories, formLayout, getTranslator());
categoriesEl.setHelpText(translate("categories.hint"));
categoriesEl.setElementCssClass("o_sel_ep_tagsinput");
categoriesEl.setAllowDuplicates(false);
Date collectDate = mediaReference == null ? new Date() : mediaReference.getCollectionDate();
String date = Formatter.getInstance(getLocale()).formatDate(collectDate);
uifactory.addStaticTextElement("artefact.collect.date", "artefact.collect.date", date, formLayout);
if (StringHelper.containsNonWhitespace(businessPath)) {
String link = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
uifactory.addStaticTextElement("artefact.collect.link", "artefact.collect.link", link, formLayout);
}
FormLayoutContainer buttonsCont = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
formLayout.add(buttonsCont);
uifactory.addFormSubmitButton("save", "save", buttonsCont);
uifactory.addFormCancelButton("cancel", buttonsCont, ureq, getWindowControl());
}
use of org.olat.core.util.vfs.JavaIOItem in project openolat by klemens.
the class CollectFileMediaController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
formLayout.setElementCssClass("o_sel_pf_collect_document_form");
String title = mediaReference == null ? null : mediaReference.getTitle();
titleEl = uifactory.addTextElement("artefact.title", "artefact.title", 255, title, formLayout);
titleEl.setElementCssClass("o_sel_pf_collect_title");
titleEl.setMandatory(true);
String desc = mediaReference == null ? null : mediaReference.getTitle();
descriptionEl = uifactory.addRichTextElementForStringDataMinimalistic("artefact.descr", "artefact.descr", desc, 8, 60, formLayout, getWindowControl());
descriptionEl.getEditorConfiguration().setPathInStatusBar(false);
fileEl = uifactory.addFileElement(getWindowControl(), "artefact.file", "artefact.file", formLayout);
fileEl.addActionListener(FormEvent.ONCHANGE);
if (mediaReference != null) {
fileEl.setEnabled(false);
VFSItem item = fileHandler.getItem(mediaReference);
if (item instanceof JavaIOItem) {
fileEl.setInitialFile(((JavaIOItem) item).getBasefile());
}
}
categoriesEl = uifactory.addTextBoxListElement("categories", "categories", "categories.hint", categories, formLayout, getTranslator());
categoriesEl.setHelpText(translate("categories.hint"));
categoriesEl.setElementCssClass("o_sel_ep_tagsinput");
categoriesEl.setAllowDuplicates(false);
// String source = "Forum";
// uifactory.addStaticTextElement("artefact.source", "artefact.source", source, formLayout);
Date collectDate = mediaReference == null ? new Date() : mediaReference.getCollectionDate();
String date = Formatter.getInstance(getLocale()).formatDate(collectDate);
uifactory.addStaticTextElement("artefact.collect.date", "artefact.collect.date", date, formLayout);
if (StringHelper.containsNonWhitespace(businessPath)) {
String link = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
uifactory.addStaticTextElement("artefact.collect.link", "artefact.collect.link", link, formLayout);
}
FormLayoutContainer buttonsCont = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
formLayout.add(buttonsCont);
uifactory.addFormSubmitButton("save", "save", buttonsCont);
uifactory.addFormCancelButton("cancel", buttonsCont, ureq, getWindowControl());
}
use of org.olat.core.util.vfs.JavaIOItem in project openolat by klemens.
the class VFSResource method getCreation.
@Override
public long getCreation() {
try {
if (item instanceof JavaIOItem) {
JavaIOItem ioItem = (JavaIOItem) item;
BasicFileAttributes attrs = Files.readAttributes(ioItem.getBasefile().toPath(), BasicFileAttributes.class);
return attrs.creationTime().toMillis();
}
return 0;
} catch (IOException e) {
log.warn("getCreationFail" + item, e);
return 0;
}
}
use of org.olat.core.util.vfs.JavaIOItem in project OpenOLAT by OpenOLAT.
the class PowerPointOOXMLDocument method readContent.
@Override
public FileContent readContent(VFSLeaf leaf) throws IOException, DocumentException {
File file = ((JavaIOItem) leaf).getBasefile();
LimitedContentWriter writer = new LimitedContentWriter(100000, FileDocumentFactory.getMaxFileSize());
try (ZipFile wordFile = new ZipFile(file)) {
List<String> contents = new ArrayList<>();
for (Enumeration<? extends ZipEntry> entriesEnumeration = wordFile.entries(); entriesEnumeration.hasMoreElements(); ) {
ZipEntry entry = entriesEnumeration.nextElement();
String name = entry.getName();
if (name.startsWith(SLIDE) && name.endsWith(".xml")) {
contents.add(name);
}
}
if (contents.size() > 1) {
Collections.sort(contents, new PowerPointDocumentComparator());
}
for (String content : contents) {
if (writer.accept()) {
ZipEntry entry = wordFile.getEntry(content);
InputStream zip = wordFile.getInputStream(entry);
OfficeDocumentHandler dh = new OfficeDocumentHandler(writer);
parse(new ShieldInputStream(zip), dh);
zip.close();
}
}
} catch (DocumentException e) {
throw e;
} catch (Exception e) {
throw new DocumentException(e.getMessage());
}
return new FileContent(writer.toString());
}
Aggregations