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
f1aba23d
Commit
f1aba23d
authored
5 years ago
by
srosse
Browse files
Options
Downloads
Patches
Plain Diff
OO-4401: add case insensitive file resolver as fallback in iframe mapper
parent
47825fb9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/org/olat/core/gui/control/generic/iframe/IFrameDeliveryMapper.java
+57
-11
57 additions, 11 deletions
...core/gui/control/generic/iframe/IFrameDeliveryMapper.java
with
57 additions
and
11 deletions
src/main/java/org/olat/core/gui/control/generic/iframe/IFrameDeliveryMapper.java
+
57
−
11
View file @
f1aba23d
...
...
@@ -22,11 +22,13 @@ package org.olat.core.gui.control.generic.iframe;
import
java.nio.charset.Charset
;
import
java.nio.charset.IllegalCharsetNameException
;
import
java.nio.charset.StandardCharsets
;
import
java.util.List
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
javax.servlet.http.HttpServletRequest
;
import
org.apache.logging.log4j.Logger
;
import
org.olat.core.dispatcher.impl.StaticMediaDispatcher
;
import
org.olat.core.dispatcher.mapper.Mapper
;
import
org.olat.core.gui.components.htmlheader.jscss.CustomCSSDelegate
;
...
...
@@ -34,15 +36,17 @@ import org.olat.core.gui.media.MediaResource;
import
org.olat.core.gui.media.NotFoundMediaResource
;
import
org.olat.core.gui.media.StringMediaResource
;
import
org.olat.core.gui.render.StringOutput
;
import
org.apache.logging.log4j.Logger
;
import
org.olat.core.logging.Tracing
;
import
org.olat.core.util.FileUtils
;
import
org.olat.core.util.SimpleHtmlParser
;
import
org.olat.core.util.StringHelper
;
import
org.olat.core.util.WebappHelper
;
import
org.olat.core.util.vfs.VFSContainer
;
import
org.olat.core.util.vfs.VFSItem
;
import
org.olat.core.util.vfs.VFSLeaf
;
import
org.olat.core.util.vfs.VFSManager
;
import
org.olat.core.util.vfs.VFSMediaResource
;
import
org.olat.core.util.vfs.filters.VFSItemFilter
;
/**
*
...
...
@@ -177,20 +181,14 @@ public class IFrameDeliveryMapper implements Mapper {
}
protected
MediaResource
deliverFile
(
HttpServletRequest
httpRequest
,
String
path
,
boolean
isPopUp
)
{
MediaResource
mr
;
VFSLeaf
vfsLeaf
=
null
;
VFSItem
vfsItem
=
null
;
//if directory gets renamed root becomes null
if
(
rootDir
==
null
)
{
return
new
NotFoundMediaResource
();
}
else
{
vfsItem
=
rootDir
.
resolve
(
path
);
}
//only files are allowed, but somehow it happened that folders showed up here
if
(
vfsItem
instanceof
VFSLeaf
)
{
vfsLeaf
=
(
VFSLeaf
)
rootDir
.
resolve
(
path
);
}
}
VFSLeaf
vfsLeaf
=
resolveFile
(
path
);
MediaResource
mr
;
if
(
vfsLeaf
==
null
)
{
mr
=
new
NotFoundMediaResource
();
}
else
{
...
...
@@ -214,6 +212,41 @@ public class IFrameDeliveryMapper implements Mapper {
return
mr
;
}
/**
* @param path The path
* @return A leaf
*/
private
final
VFSLeaf
resolveFile
(
String
path
)
{
VFSItem
vfsItem
=
rootDir
.
resolve
(
path
);
if
(
vfsItem
==
null
&&
rootDir
instanceof
VFSContainer
)
{
path
=
VFSManager
.
sanitizePath
(
path
);
List
<
VFSItem
>
items
=
null
;
int
lastSlash
=
path
.
lastIndexOf
(
'/'
);
if
(
lastSlash
==
0
)
{
String
filename
=
path
.
substring
(
1
);
items
=
((
VFSContainer
)
rootDir
).
getItems
(
new
ByNameCaseInsensitive
(
filename
));
}
else
if
(
lastSlash
>
0
)
{
String
containerPath
=
path
.
substring
(
0
,
lastSlash
);
String
filename
=
path
.
substring
(
lastSlash
+
1
);
VFSItem
parentItem
=
rootDir
.
resolve
(
containerPath
);
items
=
((
VFSContainer
)
parentItem
).
getItems
(
new
ByNameCaseInsensitive
(
filename
));
}
else
{
items
=
((
VFSContainer
)
rootDir
).
getItems
(
new
ByNameCaseInsensitive
(
path
));
}
if
(
items
!=
null
&&
items
.
size
()
==
1
)
{
vfsItem
=
items
.
get
(
0
);
}
}
VFSLeaf
vfsLeaf
=
null
;
//only files are allowed, but somehow it happened that folders showed up here
if
(
vfsItem
instanceof
VFSLeaf
)
{
vfsLeaf
=
(
VFSLeaf
)
vfsItem
;
}
return
vfsLeaf
;
}
private
MediaResource
deliverJavascriptFile
(
VFSLeaf
vfsLeaf
)
{
VFSMediaResource
vmr
=
new
VFSMediaResource
(
vfsLeaf
);
// set the encoding; could be null if this page starts with .js file
...
...
@@ -698,5 +731,18 @@ public class IFrameDeliveryMapper implements Mapper {
this
.
useLoadedPageString
=
useLoadedPageString
;
}
}
private
static
class
ByNameCaseInsensitive
implements
VFSItemFilter
{
private
final
String
filename
;
public
ByNameCaseInsensitive
(
String
filename
)
{
this
.
filename
=
filename
;
}
@Override
public
boolean
accept
(
VFSItem
vfsItem
)
{
return
vfsItem
!=
null
&&
filename
.
equalsIgnoreCase
(
vfsItem
.
getName
());
}
}
}
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