First of all I have to apologize for not having a
perfect diff output. I happen to use Visual Age for
Java, and it imports the original source code in its
repositories and shuffles the relative locations of
methods according to its own logic. When I export the
code to a regular text file, it does not look like the
orginal one. Perhaps someone in the mailing list have
a better idea on how to import turbine sources to
Visual Age and then also submit the diffs properly.
Anyway, I am including some changes which will support
relative templates.
1)If a template contains a link such as
$link.setPage("a,b,foo.wm"), it will be evaluated from
the current directory (meaning the directory of the
referring template).
2) If the link starts with a comma, it will be
considered an absolute template name and referring
template's directory will be ignored. For example,
$link.setPage(",adm,index.wm") will mean /adm/index.wm
.
3) In order to use this features, one needs to put the
following entries in the Turbine Properties file:
use.relative.templates=true
Please note a new keyword is introduced. It will be
'rtemplate' suggesting referring template. It is a
keyword just like 'template'.
Ok. now lets look at the code.
I have modified/added code to the following classes:
WebMacroSitePage.java
TemplateInfo.java
WebMacroLink.java
It seems the diff may have worked on
WebMacroSite.java. Here is the diff:
130a131,135
> //If the template does not start with a comma, and
there is a referring template available,
> //evaluate the absolute template name and save it
as the template name
> if (
TurbineResources.getBoolean("use.relative.templates",
false))
> setAbsScreenTemplate(data);
>
262c268,285
< }
---
> /**
> * This method finds out if there is any referring
template information available. If it is available it
> * creates an absolute template name using the
referring template and the template information, and
saves that
> * absolute name as the template name. This method
should be called only once in WebMacroSitePage.
> *
> * If the template name starts with a comma, the
referring template is ignored.
> *
> * Creation date: (6/15/00 12:46:34 PM)
> * @author Moshiul Shovon <a
href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a>
> * @param data org.apache.turbine.util.RunData
> */
> public void setAbsScreenTemplate(RunData data)
> {
> String template =
data.getTemplateInfo().getScreenTemplate();
> if (null == template)
> return;
> String referringTemplate =
data.getTemplateInfo().getScreenRefTemplate();
> String name = null;
263a287,316
> //if template start with a slash ignore the
referringTemplate
> if (template.startsWith("/"))
> {
> name = template.substring(1);
> }
> else
> {
> if ((null == referringTemplate) || (0 ==
referringTemplate.length()))
> {
> name = template;
> }
> else
> {
> //referring template will be in the form
"a/b/c/d.wm", we need to ignore anyting after the last
slash(/)
> int indexOfLastSlash =
referringTemplate.lastIndexOf('/');
> if (-1 == indexOfLastSlash)
> {
> name = template;
> }
> else
> {
> String refDirectory =
referringTemplate.substring(0, indexOfLastSlash);
> name = refDirectory + "," + template;
> }
> }
> }
> name = name.replace('/', ',');
> data.getTemplateInfo().setScreenTemplate(name);
> }
> }
--- End of WebMacroSitePage.java diff ---
Diff for other two classes did not work properly. So,
here is the changes with descriptions:
TemplateInfo.java
Please add the following method:
public String getScreenRefTemplate()
{
String temp = data.getParameters().getString
("rtemplate",null);
if ( temp != null )
{
temp = temp.replace(',', '/');
}
return temp;
}
---
In file WebMacroLink.java,
Please add a member variable as follows:
public class WebMacroLink extends DynamicURI
{
String refTemplate = null;
}
ALSO, replate the toString() method with the following
code (just adds one line ):
public String toString()
{
//add the referring template as 'rtemplate'
if ((null != refTemplate) && ( refTemplate.length() >
0))
addPathInfo("rtemplate", refTemplate);
String output = super.toString();
// This was added to allow multilple $link variables
in one
// WebMacro template
removePathInfo();
removeQueryData();
return output;
}
--
Please let me know if you all think it is a good
feature. I believe it is. I developed few pages myself
in a directory and wanted to move them to a
sub-directory, and had a lot of problems.
Thanks ...
-shovon-
__________________________________________________
Do You Yahoo!?
Send instant messages with Yahoo! Messenger.
http://im.yahoo.com/
------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Search: <http://www.mail-archive.com/turbine%40list.working-dogs.com/>
Problems?: [EMAIL PROTECTED]