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

no-jira: close inputstream in QTI ParserManager and in ServletUtil

parent 08d3be74
No related branches found
No related tags found
No related merge requests found
......@@ -180,22 +180,23 @@ public class ServletUtil {
}
if (ranges != null && ranges.size() == 1) {
Range range = ranges.get(0);
httpResp.addHeader("Content-Range", "bytes " + range.start + "-" + range.end + "/" + range.length);
long length = range.end - range.start + 1;
if (length < Integer.MAX_VALUE) {
httpResp.setContentLength((int) length);
} else {
// Set the content-length as String to be able to use a long
httpResp.setHeader("content-length", "" + length);
}
httpResp.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
try {
httpResp.setBufferSize(2048);
} catch (IllegalStateException e) {
// Silent catch
}
copy(out, in, range);
Range range = ranges.get(0);
httpResp.addHeader("Content-Range", "bytes " + range.start + "-" + range.end + "/" + range.length);
long length = range.end - range.start + 1;
if (length < Integer.MAX_VALUE) {
httpResp.setContentLength((int) length);
} else {
// Set the content-length as String to be able to use a long
httpResp.setHeader("content-length", "" + length);
}
httpResp.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
try {
httpResp.setBufferSize(2048);
} catch (IllegalStateException e) {
// Silent catch
}
copy(out, in, range);
} else {
if (size != null) {
httpResp.setContentLength(size.intValue());
......@@ -211,8 +212,6 @@ public class ServletUtil {
}
}
} catch (IOException e) {
FileUtils.closeSafely(in);
FileUtils.closeSafely(bis);
FileUtils.closeSafely(out);
String className = e.getClass().getSimpleName();
if("ClientAbortException".equals(className)) {
......@@ -220,6 +219,9 @@ public class ServletUtil {
} else {
log.error("client browser probably abort when serving media resource", e);
}
} finally {
IOUtils.closeQuietly(bis);
IOUtils.closeQuietly(in);
}
}
......
......@@ -25,47 +25,50 @@
package org.olat.ims.qti.editor.beecom.parser;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.io.IOUtils;
import org.dom4j.Document;
import org.dom4j.Element;
import org.olat.core.logging.OLATRuntimeException;
import org.olat.core.logging.OLog;
import org.olat.core.logging.Tracing;
/**
* @author rkulow
*/
public class ParserManager implements IParser {
private static final OLog log = Tracing.createLoggerFor(ParserManager.class);
private static String PROPERTIES_FILENAME = "org/olat/ims/qti/editor/beecom/parser/qtiparser.properties";
private HashMap parserMap = null;
private static final Map<String,String> parserMap = new ConcurrentHashMap<>();
private static String PARSER_DEFAULT = "defaultparser";
/**
*
*/
public ParserManager() {
this.init();
init();
}
private void init() {
this.parserMap = new HashMap();
try {
Properties prop = new Properties();
prop.load(this.getClass().getClassLoader().getResourceAsStream(PROPERTIES_FILENAME));
Enumeration enumeration = prop.keys();
while (enumeration.hasMoreElements()) {
String key = (String) enumeration.nextElement();
String value = prop.getProperty(key);
this.parserMap.put(key, value);
if(parserMap.isEmpty()) {
InputStream in = null;
try {
in = this.getClass().getClassLoader().getResourceAsStream(PROPERTIES_FILENAME);
Properties prop = new Properties();
prop.load(in);
for(Enumeration<Object> enumeration = prop.keys(); enumeration.hasMoreElements(); ) {
String key = (String) enumeration.nextElement();
String value = prop.getProperty(key);
parserMap.put(key, value);
}
} catch (Exception e) {
log.error("Could not load qtiparser.properties", e);
} finally {
IOUtils.closeQuietly(in);
}
} catch (Exception e) {
//
}
}
/**
......@@ -74,7 +77,7 @@ public class ParserManager implements IParser {
*/
public Object parse(Document doc) {
Element rootElement = doc.getRootElement();
return this.parse(rootElement);
return parse(rootElement);
}
/**
......@@ -85,16 +88,16 @@ public class ParserManager implements IParser {
if (element == null) return null;
String name = element.getName();
String parserClassName = null;
Object tmpName = this.parserMap.get(name);
String tmpName = parserMap.get(name);
if (tmpName == null) {
parserClassName = (String) this.parserMap.get(PARSER_DEFAULT);
parserClassName = parserMap.get(PARSER_DEFAULT);
} else {
parserClassName = (String) tmpName;
parserClassName = tmpName;
}
if(Tracing.isDebugEnabled(ParserManager.class)){
Tracing.logDebug("ELEMENTNAME:" + name + "PARSERNAME" + parserClassName,ParserManager.class);
if(log.isDebug()){
log.debug("ELEMENTNAME:" + name + "PARSERNAME" + parserClassName);
}
Class parserClass = this.getClass().getClassLoader().loadClass(parserClassName);
Class<?> parserClass = this.getClass().getClassLoader().loadClass(parserClassName);
IParser parser = (IParser) parserClass.newInstance();
return parser.parse(element);
} catch (ClassNotFoundException e) {
......@@ -105,5 +108,4 @@ public class ParserManager implements IParser {
throw new OLATRuntimeException(this.getClass(), "Illegal Access in QTI editor", e);
}
}
}
\ No newline at end of file
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