Author |
Message |
11/11/2015 10:05:36
|
moebus
Power User
Joined: 21/11/2007 12:49:18
Messages: 93
Offline
|
We use textwithlinks, and in the html text have included some images. In some scenarios (applet) the base url of our page contains a .. path element.
In this situation we have problems displaying images in html text.
We like to specify them with relative url, i.e. <img src="images/cool.jpg">. This src specification makes its way through ExtImageView and comes to new URL(baseUrl,src). This JDK method normalizes the resulting URL, i.e. the ../ stuff is gone. This URL is then presented to TestPaneElement.HTMLImageCache.get() where it is checked if the url of the image starts with the page url. This page url however has not been normalized, just toExternalForm() is called. So the image is not displayed.
It would work if we did specify the correct url in absolute form (so in this case containing the xxx/../yyy stuff), but this is cumbersome especially since then the application code would have to include ifs reflecting the current mode in which the app is viewed, e.g. webstart, or applet.
Regards
Manfred
|
|
|
11/11/2015 10:27:41
|
CaptainCasa
Power User
Joined: 21/11/2007 12:23:06
Messages: 5535
Offline
|
If you say "relative URL" then you mean relative within the webcontent directory?
Regards, Björn
PS: to do some pre-parsing on my side etc. shouldn't be a a big problem...
|
Björn Müller, CaptainCasa GmbH |
|
|
11/11/2015 10:40:45
|
moebus
Power User
Joined: 21/11/2007 12:49:18
Messages: 93
Offline
|
Just another helpful idea:
In webstart case, we can explicitly set page root and start page, as the first two arguments of PageWebstart.
In applet case, we have only one argument available ("page") which then mangled together with applet's contextRoot to form the two parameters for the PageBrowser. It might be helpful to normalize the resulting URL here.
|
|
|
11/11/2015 10:46:14
|
moebus
Power User
Joined: 21/11/2007 12:49:18
Messages: 93
Offline
|
while composing my previous comment, did not see your last remark.
To answer this: relative url is such that it works in webstart, i.e. it is relative to the path where the faces servlet is situated.
|
|
|
13/11/2015 08:28:01
|
dkhanzhyiev
Active
Joined: 11/11/2015 10:21:27
Messages: 10
Offline
|
To illustrate the problem here is small sample:
http://pastebin.com/t8kSSijA
|
|
|
18/11/2015 08:25:06
|
CaptainCasa
Power User
Joined: 21/11/2007 12:23:06
Messages: 5535
Offline
|
THere is now an attribute TEXTWITHLINKS-BASEURL which you can set in the component. If you want to set it in general, then please use the style processing.
Hope, this matches you requirements.
Thanks + regards! Björn
|
Björn Müller, CaptainCasa GmbH |
|
|
18/11/2015 09:13:39
|
dkhanzhyiev
Active
Joined: 11/11/2015 10:21:27
Messages: 10
Offline
|
Why not just correctly check URL in
TEXTPANEElement.HTMLImageCache.get()
something like this
Code:
...
68: String str = localURL.toExternalForm();
69: if (m_baseUrl != null)
{
String normalized = (new URI(m_baseUrl )).normalize().toString();
71: if(str.startsWith(normalized)) {
...
but str probably should also be normalized.
|
|
|
23/11/2015 15:39:51
|
dkhanzhyiev
Active
Joined: 11/11/2015 10:21:27
Messages: 10
Offline
|
baseurl attribute does not solve our problem.
Again here is problematic code:
Code:
class HTMLImageCache extends Hashtable<URL,Image>
{
@Override
public synchronized Image get(Object key)
{
if (key instanceof URL)
{
URL url = (URL)key;
String urlString = url.toExternalForm();
if (m_webappBaseUrl != null)
{
if (urlString.startsWith(m_webappBaseUrl))
{
urlString = urlString.substring(m_webappBaseUrl.length());
if (urlString.startsWith("/") == false)
urlString = "/" + urlString;
ImageIcon icon = getPage().loadImageIcon(urlString);
return icon.getImage();
}
}
}
return super.get(key);
}
}
when
m_webappBaseUrl llooks like: "http://host.com/some1/../some2/"
key is URL constructed from base "http://host.com/some1/../some2" and "img/someImg.gif" - it is normalized by URL class and then
Code:
String urlString = url.toExternalForm(); // ="http://host.com/some2/img/someImg.gif"
So line
Code:
if (urlString.startsWith(m_webappBaseUrl)) {...
fails. And image is not displayed while URL is correct.
|
|
|
21/12/2015 07:59:00
|
dkhanzhyiev
Active
Joined: 11/11/2015 10:21:27
Messages: 10
Offline
|
UP!
|
|
|
21/12/2015 15:07:07
|
CaptainCasa
Power User
Joined: 21/11/2007 12:23:06
Messages: 5535
Offline
|
...ooops, did not see the activity on this item....
Will check...
Björn
|
Björn Müller, CaptainCasa GmbH |
|
|
22/12/2015 08:38:07
|
CaptainCasa
Power User
Joined: 21/11/2007 12:23:06
Messages: 5535
Offline
|
Hi,
thanks for your remark: up to now we only did read the image when feeling explicitly responsible, but it seems that the cache has to read all images. We now added the following implementation and read all images, also these ones not belonging to the scope of our web application.
When do you need the update on this? The regular availability would be next Monday (Dec 28th).
Regards, Björn
Code:
public synchronized Image get(Object key)
{
if (key instanceof URL)
{
URL url = (URL)key;
String urlString = url.toExternalForm();
if (m_webappBaseUrl != null)
{
if (urlString.startsWith(m_webappBaseUrl))
{
urlString = urlString.substring(m_webappBaseUrl.length());
if (urlString.startsWith("/") == false)
urlString = "/" + urlString;
ImageIcon icon = getPage().loadImageIcon(urlString);
return icon.getImage();
}
}
else
{
try
{
// first check in cache
if (contains(key))
return get(super.get(key));
// explicitly read image
DataTransfer dt = new DataTransfer(null,null,null);
dt.readBytesFromURL(urlString);
if (dt.getDataTransferException() != null)
{
CLog.L.log(CLog.LL_WAR,"Problem loading image: " + urlString,dt.getDataTransferException());
put((URL)key,null);
return null;
}
else
{
byte[] bytes = dt.getResponseBytes();
ImageIcon icon = new ImageIcon(bytes);
put((URL)key,icon.getImage());
return icon.getImage();
}
}
catch (Throwable t)
{
CLog.L.log(CLog.LL_WAR,"Problem loading image: " + urlString,t);
put((URL)key,null);
return null;
}
}
}
return super.get(key);
|
Björn Müller, CaptainCasa GmbH |
|
|
23/12/2015 07:33:46
|
dkhanzhyiev
Active
Joined: 11/11/2015 10:21:27
Messages: 10
Offline
|
Thanks! Next Monday is Ok.
But it still looks like it will not work.
In our case m_webappBaseUrl is not null and still is not normalized(or is it?) so this code will not work in our case.
|
|
|
23/12/2015 07:54:39
|
CaptainCasa
Power User
Joined: 21/11/2007 12:23:06
Messages: 5535
Offline
|
Hey, you are right!!!! - the else-processing belongs to the wrong if statement!
THANKS!!!
Björn
Code:
class HTMLImageCache extends Hashtable<URL,Image>
{
@Override
public synchronized Image get(Object key)
{
if (key instanceof URL)
{
URL url = (URL)key;
String urlString = url.toExternalForm();
// load via page processing if URL is pointing into the
// content of the web application
if (m_webappBaseUrl != null)
{
if (urlString.startsWith(m_webappBaseUrl))
{
urlString = urlString.substring(m_webappBaseUrl.length());
if (urlString.startsWith("/") == false)
urlString = "/" + urlString;
ImageIcon icon = getPage().loadImageIcon(urlString);
return icon.getImage();
}
}
// otherwise: load image through normal http access
try
{
// first check in cache
if (contains(key))
return get(super.get(key));
// explicitly read image
DataTransfer dt = new DataTransfer(null,null,null);
dt.readBytesFromURL(urlString);
if (dt.getDataTransferException() != null)
{
CLog.L.log(CLog.LL_WAR,"Problem loading image: " + urlString,dt.getDataTransferException());
put((URL)key,null);
return null;
}
else
{
byte[] bytes = dt.getResponseBytes();
ImageIcon icon = new ImageIcon(bytes);
put((URL)key,icon.getImage());
return icon.getImage();
}
}
catch (Throwable t)
{
CLog.L.log(CLog.LL_WAR,"Problem loading image: " + urlString,t);
put((URL)key,null);
return null;
}
}
return super.get(key);
}
}
|
Björn Müller, CaptainCasa GmbH |
|
|
|