Skip to content
Snippets Groups Projects
Commit 8979371d authored by gnaegi's avatar gnaegi
Browse files

OO-1162 create sp nodes in directory also when added by course wizard

parent 2622efeb
No related branches found
No related tags found
No related merge requests found
...@@ -35,33 +35,55 @@ package de.tuchemnitz.wizard.helper.course; ...@@ -35,33 +35,55 @@ package de.tuchemnitz.wizard.helper.course;
import java.io.BufferedOutputStream; import java.io.BufferedOutputStream;
import java.io.IOException; import java.io.IOException;
import org.olat.core.logging.OLog;
import org.olat.core.logging.Tracing; import org.olat.core.logging.Tracing;
import org.olat.core.util.FileUtils; import org.olat.core.util.FileUtils;
import org.olat.core.util.StringHelper;
import org.olat.core.util.vfs.VFSContainer;
import org.olat.core.util.vfs.VFSLeaf; import org.olat.core.util.vfs.VFSLeaf;
import org.olat.course.ICourse; import org.olat.course.ICourse;
public final class HTMLDocumentHelper { public final class HTMLDocumentHelper {
private static final OLog log = Tracing.createLoggerFor(HTMLDocumentHelper.class);
public static String ENCODING = "utf-8"; public static String ENCODING = "utf-8";
/** /**
* Create a HTML file and put it into the course folder container. * Create a HTML file and put it into the course folder container.
* *
* @param course the corresponding course object * @param course the corresponding course object
* @param htmlFileName HTML file name * @param relFilePath HTML file name
* @param htmlText the full html site content with head and body * @param htmlText the full html site content with head and body
* @return the created folder leaf * @return the created folder leaf
*/ */
public static final VFSLeaf createHtmlDocument(final ICourse course, final String htmlFileName, final String htmlText) { public static final VFSLeaf createHtmlDocument(final ICourse course, final String relFilePath, final String htmlText) {
// create the HTML file inside the course base folder container // Create the HTML file inside the course base folder container
final VFSLeaf leaf = course.getCourseFolderContainer().createChildLeaf(htmlFileName);
final BufferedOutputStream bos = new BufferedOutputStream(leaf.getOutputStream(false)); VFSContainer parent = course.getCourseFolderContainer();
FileUtils.save(bos, htmlText, ENCODING); VFSLeaf file = (VFSLeaf) parent.resolve(relFilePath);
try { if (file == null) {
bos.close(); // Expected: file does not exist, create it now.
} catch (IOException e) { String[] pathSegments = relFilePath.split("/");
Tracing.createLoggerFor(HTMLDocumentHelper.class).error("Error writing the HTML file: " + e.getLocalizedMessage()); for (int i = 0; i < pathSegments.length; i++) {
String segment = pathSegments[i];
if (StringHelper.containsNonWhitespace(segment)) {
if (i == pathSegments.length -1) {
// last one is leaf
file = parent.createChildLeaf(segment);
} else {
parent = parent.createChildContainer(segment);
}
}
}
final BufferedOutputStream bos = new BufferedOutputStream(file.getOutputStream(false));
FileUtils.save(bos, htmlText, ENCODING);
try {
bos.close();
} catch (IOException e) {
log.error("Error writing the HTML file::" + relFilePath, e);
}
} else {
log.error("Can not create file::" + relFilePath + ", does already exist");
} }
return leaf; return file;
} }
} }
...@@ -46,13 +46,13 @@ import org.olat.core.id.UserConstants; ...@@ -46,13 +46,13 @@ import org.olat.core.id.UserConstants;
import org.olat.core.logging.OLog; import org.olat.core.logging.OLog;
import org.olat.core.logging.Tracing; import org.olat.core.logging.Tracing;
import org.olat.core.util.Util; import org.olat.core.util.Util;
import org.olat.core.util.vfs.VFSLeaf;
import org.olat.course.CourseFactory; import org.olat.course.CourseFactory;
import org.olat.course.ICourse; import org.olat.course.ICourse;
import org.olat.course.condition.Condition; import org.olat.course.condition.Condition;
import org.olat.course.editor.CourseEditorHelper;
import org.olat.course.editor.PublishProcess; import org.olat.course.editor.PublishProcess;
import org.olat.course.editor.StatusDescription;
import org.olat.course.editor.PublishSetInformations; import org.olat.course.editor.PublishSetInformations;
import org.olat.course.editor.StatusDescription;
import org.olat.course.nodes.AbstractAccessableCourseNode; import org.olat.course.nodes.AbstractAccessableCourseNode;
import org.olat.course.nodes.BCCourseNode; import org.olat.course.nodes.BCCourseNode;
import org.olat.course.nodes.COCourseNode; import org.olat.course.nodes.COCourseNode;
...@@ -142,8 +142,9 @@ public class CourseCreationHelper { ...@@ -142,8 +142,9 @@ public class CourseCreationHelper {
singlePageNode = CourseExtensionHelper.createSinglePageNode(course, translator.translate("cce.informationpage"), translator singlePageNode = CourseExtensionHelper.createSinglePageNode(course, translator.translate("cce.informationpage"), translator
.translate("cce.informationpage.descr")); .translate("cce.informationpage.descr"));
if (singlePageNode instanceof SPCourseNode) { if (singlePageNode instanceof SPCourseNode) {
final VFSLeaf htmlLeaf = HTMLDocumentHelper.createHtmlDocument(course, "start.html", courseConfig.getSinglePageText(translator)); final String relPath = CourseEditorHelper.createUniqueRelFilePathFromShortTitle(singlePageNode, course.getCourseFolderContainer());
((SPCourseNode) singlePageNode).getModuleConfiguration().set(SPEditController.CONFIG_KEY_FILE, "/" + htmlLeaf.getName()); HTMLDocumentHelper.createHtmlDocument(course, relPath, courseConfig.getSinglePageText(translator));
((SPCourseNode) singlePageNode).getModuleConfiguration().set(SPEditController.CONFIG_KEY_FILE, relPath);
} }
} }
// enrollment node // enrollment node
......
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