Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
OLAT CI-CD Testing Project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lars Oliver Dam
OLAT CI-CD Testing Project
Commits
597ef5ba
Commit
597ef5ba
authored
10 years ago
by
srosse
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/org/olat/core/gui/media/ServletUtil.java
+20
-18
20 additions, 18 deletions
src/main/java/org/olat/core/gui/media/ServletUtil.java
src/main/java/org/olat/ims/qti/editor/beecom/parser/ParserManager.java
+30
-28
30 additions, 28 deletions
.../org/olat/ims/qti/editor/beecom/parser/ParserManager.java
with
50 additions
and
46 deletions
src/main/java/org/olat/core/gui/media/ServletUtil.java
+
20
−
18
View file @
597ef5ba
...
@@ -180,22 +180,23 @@ public class ServletUtil {
...
@@ -180,22 +180,23 @@ public class ServletUtil {
}
}
if
(
ranges
!=
null
&&
ranges
.
size
()
==
1
)
{
if
(
ranges
!=
null
&&
ranges
.
size
()
==
1
)
{
Range
range
=
ranges
.
get
(
0
);
httpResp
.
addHeader
(
"Content-Range"
,
"bytes "
+
range
.
start
+
"-"
+
range
.
end
+
"/"
+
range
.
length
);
Range
range
=
ranges
.
get
(
0
);
long
length
=
range
.
end
-
range
.
start
+
1
;
httpResp
.
addHeader
(
"Content-Range"
,
"bytes "
+
range
.
start
+
"-"
+
range
.
end
+
"/"
+
range
.
length
);
if
(
length
<
Integer
.
MAX_VALUE
)
{
long
length
=
range
.
end
-
range
.
start
+
1
;
httpResp
.
setContentLength
((
int
)
length
);
if
(
length
<
Integer
.
MAX_VALUE
)
{
}
else
{
httpResp
.
setContentLength
((
int
)
length
);
// Set the content-length as String to be able to use a long
}
else
{
httpResp
.
setHeader
(
"content-length"
,
""
+
length
);
// 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
.
setStatus
(
HttpServletResponse
.
SC_PARTIAL_CONTENT
);
httpResp
.
setBufferSize
(
2048
);
try
{
}
catch
(
IllegalStateException
e
)
{
httpResp
.
setBufferSize
(
2048
);
// Silent catch
}
catch
(
IllegalStateException
e
)
{
}
// Silent catch
copy
(
out
,
in
,
range
);
}
copy
(
out
,
in
,
range
);
}
else
{
}
else
{
if
(
size
!=
null
)
{
if
(
size
!=
null
)
{
httpResp
.
setContentLength
(
size
.
intValue
());
httpResp
.
setContentLength
(
size
.
intValue
());
...
@@ -211,8 +212,6 @@ public class ServletUtil {
...
@@ -211,8 +212,6 @@ public class ServletUtil {
}
}
}
}
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
FileUtils
.
closeSafely
(
in
);
FileUtils
.
closeSafely
(
bis
);
FileUtils
.
closeSafely
(
out
);
FileUtils
.
closeSafely
(
out
);
String
className
=
e
.
getClass
().
getSimpleName
();
String
className
=
e
.
getClass
().
getSimpleName
();
if
(
"ClientAbortException"
.
equals
(
className
))
{
if
(
"ClientAbortException"
.
equals
(
className
))
{
...
@@ -220,6 +219,9 @@ public class ServletUtil {
...
@@ -220,6 +219,9 @@ public class ServletUtil {
}
else
{
}
else
{
log
.
error
(
"client browser probably abort when serving media resource"
,
e
);
log
.
error
(
"client browser probably abort when serving media resource"
,
e
);
}
}
}
finally
{
IOUtils
.
closeQuietly
(
bis
);
IOUtils
.
closeQuietly
(
in
);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
src/main/java/org/olat/ims/qti/editor/beecom/parser/ParserManager.java
+
30
−
28
View file @
597ef5ba
...
@@ -25,47 +25,50 @@
...
@@ -25,47 +25,50 @@
package
org.olat.ims.qti.editor.beecom.parser
;
package
org.olat.ims.qti.editor.beecom.parser
;
import
java.io.InputStream
;
import
java.util.Enumeration
;
import
java.util.Enumeration
;
import
java.util.
Hash
Map
;
import
java.util.Map
;
import
java.util.Properties
;
import
java.util.Properties
;
import
java.util.concurrent.ConcurrentHashMap
;
import
org.apache.commons.io.IOUtils
;
import
org.dom4j.Document
;
import
org.dom4j.Document
;
import
org.dom4j.Element
;
import
org.dom4j.Element
;
import
org.olat.core.logging.OLATRuntimeException
;
import
org.olat.core.logging.OLATRuntimeException
;
import
org.olat.core.logging.OLog
;
import
org.olat.core.logging.Tracing
;
import
org.olat.core.logging.Tracing
;
/**
/**
* @author rkulow
* @author rkulow
*/
*/
public
class
ParserManager
implements
IParser
{
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
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"
;
private
static
String
PARSER_DEFAULT
=
"defaultparser"
;
/**
*
*/
public
ParserManager
()
{
public
ParserManager
()
{
this
.
init
();
init
();
}
}
private
void
init
()
{
private
void
init
()
{
this
.
parserMap
=
new
HashMap
();
if
(
parserMap
.
isEmpty
())
{
InputStream
in
=
null
;
try
{
try
{
Properties
prop
=
new
Properties
();
in
=
this
.
getClass
().
getClassLoader
().
getResourceAsStream
(
PROPERTIES_FILENAME
);
prop
.
load
(
this
.
getClass
().
getClassLoader
().
getResourceAsStream
(
PROPERTIES_FILENAME
));
Properties
prop
=
new
Properties
();
Enumeration
enumeration
=
prop
.
keys
();
prop
.
load
(
in
);
while
(
enumeration
.
hasMoreElements
())
{
for
(
Enumeration
<
Object
>
enumeration
=
prop
.
keys
();
enumeration
.
hasMoreElements
();
)
{
String
key
=
(
String
)
enumeration
.
nextElement
();
String
key
=
(
String
)
enumeration
.
nextElement
();
String
value
=
prop
.
getProperty
(
key
);
String
value
=
prop
.
getProperty
(
key
);
this
.
parserMap
.
put
(
key
,
value
);
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 {
...
@@ -74,7 +77,7 @@ public class ParserManager implements IParser {
*/
*/
public
Object
parse
(
Document
doc
)
{
public
Object
parse
(
Document
doc
)
{
Element
rootElement
=
doc
.
getRootElement
();
Element
rootElement
=
doc
.
getRootElement
();
return
this
.
parse
(
rootElement
);
return
parse
(
rootElement
);
}
}
/**
/**
...
@@ -85,16 +88,16 @@ public class ParserManager implements IParser {
...
@@ -85,16 +88,16 @@ public class ParserManager implements IParser {
if
(
element
==
null
)
return
null
;
if
(
element
==
null
)
return
null
;
String
name
=
element
.
getName
();
String
name
=
element
.
getName
();
String
parserClassName
=
null
;
String
parserClassName
=
null
;
Object
tmpName
=
this
.
parserMap
.
get
(
name
);
String
tmpName
=
parserMap
.
get
(
name
);
if
(
tmpName
==
null
)
{
if
(
tmpName
==
null
)
{
parserClassName
=
(
String
)
this
.
parserMap
.
get
(
PARSER_DEFAULT
);
parserClassName
=
parserMap
.
get
(
PARSER_DEFAULT
);
}
else
{
}
else
{
parserClassName
=
(
String
)
tmpName
;
parserClassName
=
tmpName
;
}
}
if
(
Tracin
g
.
isDebug
Enabled
(
ParserManager
.
class
)){
if
(
lo
g
.
isDebug
(
)){
Tracing
.
log
D
ebug
(
"ELEMENTNAME:"
+
name
+
"PARSERNAME"
+
parserClassName
,
ParserManager
.
class
);
log
.
d
ebug
(
"ELEMENTNAME:"
+
name
+
"PARSERNAME"
+
parserClassName
);
}
}
Class
parserClass
=
this
.
getClass
().
getClassLoader
().
loadClass
(
parserClassName
);
Class
<?>
parserClass
=
this
.
getClass
().
getClassLoader
().
loadClass
(
parserClassName
);
IParser
parser
=
(
IParser
)
parserClass
.
newInstance
();
IParser
parser
=
(
IParser
)
parserClass
.
newInstance
();
return
parser
.
parse
(
element
);
return
parser
.
parse
(
element
);
}
catch
(
ClassNotFoundException
e
)
{
}
catch
(
ClassNotFoundException
e
)
{
...
@@ -105,5 +108,4 @@ public class ParserManager implements IParser {
...
@@ -105,5 +108,4 @@ public class ParserManager implements IParser {
throw
new
OLATRuntimeException
(
this
.
getClass
(),
"Illegal Access in QTI editor"
,
e
);
throw
new
OLATRuntimeException
(
this
.
getClass
(),
"Illegal Access in QTI editor"
,
e
);
}
}
}
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment