Skip to content
Snippets Groups Projects
Commit e487692a authored by srosse's avatar srosse
Browse files

OO-1406: export of course need to use the streamed implementation of SCORM export media resource

parent 0b340e11
No related branches found
No related tags found
No related merge requests found
Showing
with 344 additions and 12 deletions
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.core.util.io;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Collection;
import java.util.Collections;
import java.util.Locale;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
/**
*
* Initial date: 27.01.2015<br>
* @author srosse, stephane.rosse@frentix.com, http://www.frentix.com
*
*/
public class HttpServletResponseOutputStream implements HttpServletResponse {
private final ServletOutputStream out;
public HttpServletResponseOutputStream(OutputStream out) {
this.out = new DelegateServletOutputStream(out);
}
@Override
public String getCharacterEncoding() {
return null;
}
@Override
public String getContentType() {
return null;
}
@Override
public ServletOutputStream getOutputStream() throws IOException {
return out;
}
@Override
public PrintWriter getWriter() throws IOException {
return null;
}
@Override
public void setCharacterEncoding(String charset) {
//
}
@Override
public void setContentLength(int len) {
//
}
@Override
public void setContentType(String type) {
//
}
@Override
public void setBufferSize(int size) {
//
}
@Override
public int getBufferSize() {
return 0;
}
@Override
public void flushBuffer() throws IOException {
//
}
@Override
public void resetBuffer() {
//
}
@Override
public boolean isCommitted() {
return false;
}
@Override
public void reset() {
//
}
@Override
public void setLocale(Locale loc) {
//
}
@Override
public Locale getLocale() {
return null;
}
@Override
public void addCookie(Cookie cookie) {
//
}
@Override
public boolean containsHeader(String name) {
return false;
}
@Override
public String encodeURL(String url) {
return null;
}
@Override
public String encodeRedirectURL(String url) {
return null;
}
@Override
public String encodeUrl(String url) {
return null;
}
@Override
public String encodeRedirectUrl(String url) {
return null;
}
@Override
public void sendError(int sc, String msg) throws IOException {
//
}
@Override
public void sendError(int sc) throws IOException {
//
}
@Override
public void sendRedirect(String location) throws IOException {
//
}
@Override
public void setDateHeader(String name, long date) {
//
}
@Override
public void addDateHeader(String name, long date) {
//
}
@Override
public void setHeader(String name, String value) {
//
}
@Override
public void addHeader(String name, String value) {
//
}
@Override
public void setIntHeader(String name, int value) {
//
}
@Override
public void addIntHeader(String name, int value) {
//
}
@Override
public void setStatus(int sc) {
//
}
@Override
public void setStatus(int sc, String sm) {
//
}
@Override
public int getStatus() {
return 0;
}
@Override
public String getHeader(String name) {
return null;
}
@Override
public Collection<String> getHeaders(String name) {
return Collections.emptyList();
}
@Override
public Collection<String> getHeaderNames() {
return Collections.emptyList();
}
public static class DelegateServletOutputStream extends ServletOutputStream {
private final OutputStream out;
public DelegateServletOutputStream(OutputStream out) {
this.out = out;
}
@Override
public void write(int b) throws IOException {
out.write(b);
}
@Override
public void write(byte[] b) throws IOException {
out.write(b);
}
@Override
public void write(byte[] b, int off, int len) throws IOException {
out.write(b, off, len);
}
@Override
public void flush() throws IOException {
out.flush();
}
@Override
public void close() throws IOException {
out.close();
}
}
}
......@@ -17,7 +17,7 @@
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.search.service.document.file.utils;
package org.olat.core.util.io;
import java.io.IOException;
import java.io.InputStream;
......
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.core.util.io;
import java.io.IOException;
import java.io.OutputStream;
import java.util.zip.ZipOutputStream;
/**
*
* Initial date: 27.01.2015<br>
* @author srosse, stephane.rosse@frentix.com, http://www.frentix.com
*
*/
public class ShieldOutputStream extends OutputStream {
private final ZipOutputStream out;
public ShieldOutputStream(ZipOutputStream out) {
this.out = out;
}
@Override
public void write(int b) throws IOException {
out.write(b);
}
@Override
public void write(byte[] b) throws IOException {
out.write(b);
}
@Override
public void write(byte[] b, int off, int len) throws IOException {
out.write(b, off, len);
}
@Override
public void close() throws IOException {
//
}
@Override
public void flush() throws IOException {
out.flush();
}
}
......@@ -48,10 +48,10 @@ import org.olat.core.commons.services.image.Size;
import org.olat.core.logging.OLog;
import org.olat.core.logging.Tracing;
import org.olat.core.util.StringHelper;
import org.olat.core.util.io.ShieldInputStream;
import org.olat.core.util.vfs.LocalFileImpl;
import org.olat.core.util.vfs.VFSContainer;
import org.olat.core.util.vfs.VFSItem;
import org.olat.search.service.document.file.utils.ShieldInputStream;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
......
......@@ -37,9 +37,9 @@ import org.dom4j.io.SAXReader;
import org.dom4j.io.SAXValidator;
import org.olat.core.logging.OLog;
import org.olat.core.logging.Tracing;
import org.olat.core.util.io.ShieldInputStream;
import org.olat.core.util.vfs.VFSLeaf;
import org.olat.ims.resources.IMSEntityResolver;
import org.olat.search.service.document.file.utils.ShieldInputStream;
import org.xml.sax.Attributes;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
......
......@@ -35,6 +35,8 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.olat.core.CoreSpringFactory;
import org.olat.core.gui.media.MediaResource;
......@@ -43,6 +45,7 @@ import org.olat.core.logging.OLog;
import org.olat.core.logging.Tracing;
import org.olat.core.util.FileUtils;
import org.olat.core.util.StringHelper;
import org.olat.core.util.io.HttpServletResponseOutputStream;
import org.olat.core.util.vfs.LocalFileImpl;
import org.olat.core.util.vfs.VFSContainer;
import org.olat.core.util.vfs.VFSLeaf;
......@@ -161,14 +164,19 @@ public class RepositoryEntryImportExport {
// export resource
RepositoryHandler rh = RepositoryHandlerFactory.getInstance().getRepositoryHandler(re);
MediaResource mr = rh.getAsMediaResource(re.getOlatResource(), false);
FileOutputStream fOut = null;
try {
fOut = new FileOutputStream(new File(baseDirectory, CONTENT_FILE));
IOUtils.copy(mr.getInputStream(), fOut);
try(FileOutputStream fOut = new FileOutputStream(new File(baseDirectory, CONTENT_FILE))) {
InputStream in = mr.getInputStream();
if(in == null) {
HttpServletResponse hres = new HttpServletResponseOutputStream(fOut);
mr.prepare(hres);
} else {
IOUtils.copy(mr.getInputStream(), fOut);
}
fOut.flush();
} catch (IOException fnfe) {
return false;
} finally {
FileUtils.closeSafely(fOut);
mr.release();
}
return true;
......
......@@ -31,9 +31,9 @@ import org.olat.core.gui.util.CSSHelper;
import org.olat.core.logging.OLog;
import org.olat.core.logging.Tracing;
import org.olat.core.util.FileUtils;
import org.olat.core.util.io.ShieldInputStream;
import org.olat.core.util.vfs.VFSLeaf;
import org.olat.search.service.SearchResourceContext;
import org.olat.search.service.document.file.utils.ShieldInputStream;
import org.olat.search.service.document.file.utils.SlicedDocument;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
......
......@@ -30,9 +30,9 @@ import org.olat.core.gui.util.CSSHelper;
import org.olat.core.logging.OLog;
import org.olat.core.logging.Tracing;
import org.olat.core.util.FileUtils;
import org.olat.core.util.io.ShieldInputStream;
import org.olat.core.util.vfs.VFSLeaf;
import org.olat.search.service.SearchResourceContext;
import org.olat.search.service.document.file.utils.ShieldInputStream;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;
......
......@@ -29,9 +29,9 @@ import org.olat.core.gui.util.CSSHelper;
import org.olat.core.logging.OLog;
import org.olat.core.logging.Tracing;
import org.olat.core.util.FileUtils;
import org.olat.core.util.io.ShieldInputStream;
import org.olat.core.util.vfs.VFSLeaf;
import org.olat.search.service.SearchResourceContext;
import org.olat.search.service.document.file.utils.ShieldInputStream;
import org.olat.search.service.document.file.utils.SlicedDocument;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
......
......@@ -29,9 +29,9 @@ import org.olat.core.gui.util.CSSHelper;
import org.olat.core.logging.OLog;
import org.olat.core.logging.Tracing;
import org.olat.core.util.FileUtils;
import org.olat.core.util.io.ShieldInputStream;
import org.olat.core.util.vfs.VFSLeaf;
import org.olat.search.service.SearchResourceContext;
import org.olat.search.service.document.file.utils.ShieldInputStream;
import org.olat.search.service.document.file.utils.SlicedDocument;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
......
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