Dynamic path for Images with Java
I work in a project where I had to set a dynamic path for the images, as we where using Iplanet I choosed the Java Connector and this are the changes I made in order for FCKeditor to manage the images of the webpage being seen (the images in my project where hosted at the sema directory level as the web page), of course you can change a bit the whole procedure in order to point to the directory of your choice (I had to get rid of the Image directory )
1)
web.xml
There is nothing to change you use the default parameters anyway they will be overided
<servlet>
<servlet-name>Connector</servlet-name>
<servlet-class>com.fredck.FCKeditor.connector.ConnectorServlet</servlet-class>
<init-param>
<param-name>baseDir</param-name>
<param-value>/UserDir/</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- ==================================================================== -->
<!-- From rules.properties -->
<servlet-mapping>
<servlet-name>Connector</servlet-name>
<url-pattern>/FCKeditor/editor/filemanager/browser/default/connectors/jsp/connector</url-pattern>
</servlet-mapping>
2)
In the fckconfig.js of course you have to change the connectors (those 3 lines)
FCKConfig.LinkBrowserURL = FCKConfig.BasePath + "filemanager/browser/default/browser.html?Connector=connectors/jsp/connector" ;
FCKConfig.ImageBrowserURL = FCKConfig.BasePath + "filemanager/browser/default/browser.html?Type=Image&Connector=connectors/jsp/connector" ;
FCKConfig.FlashBrowserURL = FCKConfig.BasePath + "filemanager/browser/default/browser.html?Type=Flash&Connector=connectors/jsp/connector" ;
And I'm not gonna comment on the way to configurate the web server in order to work with the FCKeditor taglibs, it is already commented here somewhere. There is something about taking out the tld files from the jar file.
3)
My jsp page (editor.jsp):
<%
String basehref="";
String urlpasse = request.getParameter("urlpasse");
if (urlpasse==null || urlpasse.equals("")) urlpasse = "";
if (!(urlpasse.equals("")))
{
StringTokenizer token=new StringTokenizer(urlpasse,"/");
basehref=urlpasse.substring(0,urlpasse.lastIndexOf("/")+1);
urlpasse=urlpasse.substring(urlpasse.indexOf("/doc/"));
}
String imageBrowserURLS="/FCKeditor/editor/filemanager/browser/default/browser.html?Type=Image&Connector=connectors/jsp/connector&Basep="+urlpasse.substring(0,urlpasse.lastIndexOf("/"));
%>
<html> <head> <title>FCKeditor - Sample</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="robots" content="noindex, nofollow"> <link href="../sample.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="../../fckeditor.js"></script> </head> <body> <h1>EditionFCKeditor - JSP - Sample 7</h1> <hr> <form action="sampleposteddata.jsp" method="post" target="_blank"> <FCK:editor id="EditorDefault" basePath="/FCKeditor/" fullPage="true" height="80%" width="80%" baseHref="<%=basehref%>" imageBrowserURL="<%=imageBrowserURLS%>" linkBrowserURL="/FCKeditor/editor/filemanager/browser/default/browser.html?Connector=connectors/jsp/connector" flashBrowserURL="/FCKeditor/editor/filemanager/browser/default/browser.html?Type=Flash&Connector=connectors/jsp/connector" imageUploadURL="/FCKeditor/editor/filemanager/upload/simpleuploader?Type=Image" linkUploadURL="/FCKeditor/editor/filemanager/upload/simpleuploader?Type=File" flashUploadURL="/FCKeditor/editor/filemanager/upload/simpleuploader?Type=Flash"> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><jsp:include page="<%=urlpasse%>" /> </FCK:editor> <br> <input type="submit" value="Submit"> </form> </body> </html>
Two things are important here, first, as I wanted to point my image browser to the repertory I was working with,I set baseHref="<%=basehref%>"
This page is called by another jsp page like that myjsp.jsp?urlpasse=http://machine/doc/dom1/dom2/pageToBeEditedWithFCKeditor.html
in my project the doc directory exists always, so I use it to get the basehref and also the the basedirectory, in my case the basehref would be http://machine/doc/dom1/ , while the basedirectory would be /doc/dom1/dom2
The lines
String imageBrowserURLS="/FCKeditor/editor/filemanager/browser/default/browser.html?Type=Image&Connector=connectors/jsp/connector&Basep="+urlpasse.substring(0,urlpasse.lastIndexOf("/"));
and
ImageBrowserURL="<%=imageBrowserURLS%>"
do all the magic
then the following line includes the page to be edited:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><jsp:include page="<%=urlpasse%>" />
4)
In the browser.html file:
First we get the Basep parameter sent from the editor.jsp page
just after the lines:
oConnector.ResourceType = GetUrlParam( 'Type' ) ;
oConnector.ShowAllTypes = ( oConnector.ResourceType.length == 0 ) ;
we get the parameter:
var LaBase=GetUrlParam( 'Basep' ) ;
then after the SendCommand function we had 3 lines
oConnector.SendCommand = function( command, params, callBackFunction )
{
var sUrl = this.ConnectorUrl + 'Command=' + command ;
sUrl += '&Type=' + this.ResourceType ;
sUrl += '&CurrentFolder=' + escape( this.CurrentFolder ) ;
if ( params ) sUrl += '&' + params ;
var oXML = new FCKXml() ;
if ( callBackFunction )
oXML.LoadUrl( sUrl, callBackFunction ) ; // Asynchronous load.
else
return oXML.LoadUrl( sUrl ) ;
}
//these three lines set the basedir to whatever we choosed to send on the argument Basep on the jsp page
this.CurrentFolder=LaBase ;
oConnector.CurrentFolder = LaBase ;
oConnector.SendCommand( 'SetBase', '' , '') ;
5)
We modify the page frmresourceslist.html
In order to get rid of the Images folder I changed the following lines
line number 137
oListManager.AddFile( sFileName, sCurrentFolderUrl + sFileName, sFileSize ) ;
replaced by
oListManager.AddFile( sFileName, sFileName, sFileSize ) ;
6)
We modify the ConnectorServlet.java
we add this function:
/**
* Sets the the "baseDir" which is the root of the file repository:<br>
*
*/
public void setBaseDir(String basedirp) throws ServletException {
baseDir=basedirp+"/";
}
Then we add three lines to the doGet method:
just before
if(commandStr.equals("GetFolders")) {
getFolders(currentDir,root,document);
}
we add
if(commandStr.equals("SetBase")) {
this.setBaseDir(currentFolderStr);
}
7)
We recompile the jar file and that's it!!!!
We have FCKeditor working with dynamical directories
Of course there are some inconvinients in my project the html files are in the same directory as the image files, so when we ask to choose an image, all the html files are also showing (normally a web developer will be wise enough to not insert an html file as an image).
And there are also some other issues to be considered, but the main idea is here, I guess that depending on your project you'll have to adapt a bit the procedure showed here.