Skip to content
Snippets Groups Projects
Commit 3ff141a7 authored by uhensler's avatar uhensler
Browse files

OO-4536: Edit XML files with the internal document editor

parent 386f4d2a
No related branches found
No related tags found
No related merge requests found
......@@ -50,7 +50,7 @@ import org.springframework.stereotype.Service;
public class FileEditor implements DocEditor {
private static final List<String> HTML_EDITOR_SUFFIX = Arrays.asList("html", "htm");
private static final List<String> TEXT_EDITOR_SUFFIX = Arrays.asList("txt", "css", "csv");
private static final List<String> TEXT_EDITOR_SUFFIX = Arrays.asList("txt", "css", "csv", "xml");
@Autowired
private VFSLockManager lockManager;
......
......@@ -26,6 +26,7 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Locale;
import java.util.zip.ZipOutputStream;
......@@ -46,6 +47,7 @@ public class ContentProviderFactory {
private static final Logger log = Tracing.createLoggerFor(ContentProviderFactory.class);
private static final ContentProvider EMPTY = new EmptyContentProvider();
private static final ContentProvider XML = new XmlContentProvider();
private static final ContentProvider DOCX = new DocxContentProvider();
private static final ContentProvider XLSX = new XlsxContentProvider();
private static final ContentProvider PPTX = new PptxContentProvider();
......@@ -54,6 +56,11 @@ public class ContentProviderFactory {
return EMPTY;
}
public static ContentProvider emptyXml() {
return XML;
}
public static ContentProvider emptyDocx() {
return DOCX;
}
......@@ -76,6 +83,16 @@ public class ContentProviderFactory {
}
}
private static final class XmlContentProvider implements ContentProvider {
private static final String XML_CONTENT = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>";
@Override
public InputStream getContent(Locale locale) {
return new ByteArrayInputStream(XML_CONTENT.getBytes(StandardCharsets.UTF_8));
}
}
private static final class DocxContentProvider implements ContentProvider {
@Override
......
......@@ -23,6 +23,7 @@ import static org.olat.core.commons.services.doceditor.ContentProviderFactory.em
import static org.olat.core.commons.services.doceditor.ContentProviderFactory.emptyDocx;
import static org.olat.core.commons.services.doceditor.ContentProviderFactory.emptyPptx;
import static org.olat.core.commons.services.doceditor.ContentProviderFactory.emptyXlsx;
import static org.olat.core.commons.services.doceditor.ContentProviderFactory.emptyXml;
import static org.olat.core.commons.services.doceditor.DocEditor.Mode.EDIT;
import java.util.ArrayList;
......@@ -72,6 +73,9 @@ public class DocTemplates {
if (docEditorService.hasEditor(identity, roles, "css", EDIT, hasMeta)) {
builder.addCss();
}
if (docEditorService.hasEditor(identity, roles, "xml", EDIT, hasMeta)) {
builder.addXml();
}
if (docEditorService.hasEditor(identity, roles, "docx", EDIT, hasMeta)) {
builder.addDocx();
}
......@@ -97,23 +101,28 @@ public class DocTemplates {
this.translator = Util.createPackageTranslator(CreateDocumentController.class, locale);
}
public Builder addCss() {
docTemplates.add(DocTemplate.of("css", translate("doc.type.css"), empty()));
public Builder addTxt() {
docTemplates.add(DocTemplate.of("txt", translate("doc.type.txt"), empty()));
return this;
}
public Builder addDocx() {
docTemplates.add(DocTemplate.of("docx", translate("doc.type.docx"), emptyDocx()));
public Builder addHtml() {
docTemplates.add(DocTemplate.of("html", translate("doc.type.html"), empty()));
return this;
}
public Builder addHtml() {
docTemplates.add(DocTemplate.of("html", translate("doc.type.html"), empty()));
public Builder addCss() {
docTemplates.add(DocTemplate.of("css", translate("doc.type.css"), empty()));
return this;
}
public Builder addTxt() {
docTemplates.add(DocTemplate.of("txt", translate("doc.type.txt"), empty()));
public Builder addXml() {
docTemplates.add(DocTemplate.of("xml", translate("doc.type.xml"), emptyXml()));
return this;
}
public Builder addDocx() {
docTemplates.add(DocTemplate.of("docx", translate("doc.type.docx"), emptyDocx()));
return this;
}
......
......@@ -23,4 +23,5 @@ doc.type.html=HTML-Dokument
doc.type.pptx=PowerPoint
doc.type.txt=Text
doc.type.xlsx=Excel
doc.type.xml=Extensible Markup Language
error.no.editor=Die Datei kann nicht angezeigt werden.
......@@ -23,4 +23,5 @@ doc.type.html=HTML Document
doc.type.pptx=PowerPoint
doc.type.txt=Text
doc.type.xlsx=Excel
doc.type.xml=Extensible Markup Language
error.no.editor=The content of the document cannot be displayed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment