Author |
Message |
![[Post New]](/forum/templates/default/images/icon_minipost_new.gif) 18/05/2010 15:55:42
|
mreich
Power User
![[Avatar]](/forum/images/avatar/093f65e080a295f8076b1c5722a46aa2.jpg)
Joined: 30/01/2009 08:34:23
Messages: 750
Offline
|
Would it make sense to add an attribute to the <onlinehelp> tag, for specifying a default language, if no directory for this certain language exists?
Markus
|
|
![](/forum/templates/default/images/spacer.gif) |
![[Post New]](/forum/templates/default/images/icon_minipost_new.gif) 18/05/2010 19:27:56
|
CaptainCasa
Power User
![[Avatar]](/forum/images/avatar/eccbc87e4b5ce2fe28308fd9f2a7baf3.jpg)
Joined: 21/11/2007 12:23:06
Messages: 5542
Offline
|
Hi,
because there are many possibilities how to deal with online help, this is left open by providing interfaces:
This is the default implementation of IOnlineHelpProcessor2 interface:
Code:
package org.eclnt.jsfserver.onlinehelp.defaultimpl;
import org.eclnt.jsfserver.defaultscreens.ModelessPopup;
import org.eclnt.jsfserver.defaultscreens.OnlineHelp;
import org.eclnt.jsfserver.defaultscreens.ModelessPopup.IModelessPopupListener;
import org.eclnt.jsfserver.onlinehelp.IOnlineHelpProcessor2;
import org.eclnt.jsfserver.onlinehelp.OnlineHelpConfiguration;
import org.eclnt.jsfserver.onlinehelp.OnlineHelpFactory;
import org.eclnt.jsfserver.onlinehelp.IOnlineHelpReader.OnlineHelpText;
import org.eclnt.util.log.CLog;
/**
* Online help processor that opens up a modal dialog in which a JBrowser
* Component is loaded with a URL of the online help page.
*/
public class OnlineHelpProcessorJBrowser implements IOnlineHelpProcessor2
{
ModelessPopup m_popup;
public void processOnlineHelp(String helpId, String language, boolean refersToComponent)
{
OnlineHelpText oht = OnlineHelpFactory.getReader().readOnlineHelpText(helpId,language);
// calculate URL
String url = OnlineHelpConfiguration.getContentDirectory();
if (url == null)
{
throw new Error("Online help is not configured yet: /eclntjsfserver/onlinehelp.xml, content directory not defined");
}
if (!url.startsWith("/")) url = "/" + url;
if (!url.endsWith("/")) url = url + "/";
url = url + language + "/" + helpId + ".html";
OnlineHelp.setOnlineHelpJBrowser(url);
m_popup = ModelessPopup.createInstance();
IModelessPopupListener mpl = new ModelessPopup.IModelessPopupListener()
{
public void reactOnPopupClosedByUser()
{
m_popup.close();
}
};
m_popup.open("/eclntjsfserver/popups/onlinehelpjbrowser.jsp","Online Help",400,300, mpl);
m_popup.setUndecorated(true);
m_popup.setCloseonclickoutside(true);
m_popup.setStartfromrootwindow(false);
if (refersToComponent == false)
m_popup.setLeftTopReferenceCentered();
CLog.L.log(CLog.LL_INF,"Showing online help: " + url);
}
}
You can add "if's and then's" to this implementation and the register the interface in "eclntjsfserver/config/onlinehelp.xml".
Regards, Björn
|
Björn Müller, CaptainCasa GmbH |
|
![](/forum/templates/default/images/spacer.gif) |
![[Post New]](/forum/templates/default/images/icon_minipost_new.gif) 18/05/2010 19:29:18
|
CaptainCasa
Power User
![[Avatar]](/forum/images/avatar/eccbc87e4b5ce2fe28308fd9f2a7baf3.jpg)
Joined: 21/11/2007 12:23:06
Messages: 5542
Offline
|
...forgot to add the code of OnlineHelpReader, fyi:
Code:
package org.eclnt.jsfserver.onlinehelp.defaultimpl;
import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import org.eclnt.jsfserver.onlinehelp.IOnlineHelpReader;
import org.eclnt.jsfserver.onlinehelp.OnlineHelpConfiguration;
import org.eclnt.jsfserver.util.WebResourceReader;
public class OnlineHelpReader implements IOnlineHelpReader
{
public OnlineHelpText readOnlineHelpText(String helpId, String language)
{
String contentdirectory = OnlineHelpConfiguration.getContentDirectory();
String fileName = contentdirectory + language + "/" + helpId + ".txt";
String content = WebResourceReader.readUTF8FileIntoString(fileName,false);
if (content != null)
return new OnlineHelpText("text/plain",content);
fileName = contentdirectory + language + "/" + helpId + ".html";
content = WebResourceReader.readUTF8FileIntoString(fileName,false);
if (content != null)
{
content = updateImageReferences(content);
return new OnlineHelpText("text/html",content);
}
fileName = contentdirectory + language + "/" + helpId + ".rtf";
content = WebResourceReader.readUTF8FileIntoString(fileName,false);
if (content != null)
return new OnlineHelpText("text/rtf",content);
return new OnlineHelpText("text/plain","No online help available for " + helpId + "/" + language);
}
private String updateImageReferences(String html)
{
// determine current host and current web app
HttpServletRequest request = (HttpServletRequest) FacesContext
.getCurrentInstance().getExternalContext().getRequest();
String url = request.getRequestURL().toString();
// <a href="http://yyy:yyy/yyy/" target="_blank" rel="nofollow">http://yyy:yyy/yyy/</a>
int indexFourthSlash = -1;
indexFourthSlash = url.indexOf('/', indexFourthSlash+1);
indexFourthSlash = url.indexOf('/', indexFourthSlash+1);
indexFourthSlash = url.indexOf('/', indexFourthSlash+1);
indexFourthSlash = url.indexOf('/', indexFourthSlash+1);
String urlBase = url.substring(0,indexFourthSlash);
html = html.replace("<img src=\"","<img src=\""+urlBase+OnlineHelpConfiguration.getContentDirectory());
html = html.replace("<a href=\"","<a href=\""+urlBase+OnlineHelpConfiguration.getContentDirectory());
html = html.replace("<IMG SRC=\"","<IMG SRC=\""+urlBase+OnlineHelpConfiguration.getContentDirectory());
html = html.replace("<A HREF=\"","<A HREF=\""+urlBase+OnlineHelpConfiguration.getContentDirectory());
return html;
}
}
Björn
|
Björn Müller, CaptainCasa GmbH |
|
![](/forum/templates/default/images/spacer.gif) |
|
|
|