Using variable in decorators

View: New views
2 Messages — Rating Filter:   Alert me  

Using variable in decorators

by Mauriff :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all,
I want to use to a dynamic variable, such as ${template}, in my decorators.xml. Can I do it?
example:

<decorators defaultdir="/decorators">
<decorator name="default" page="${template}/default.jsp">
<pattern>/*</pattern>
</decorator>
</decorators>


Regards!

Mauri.

Re: Using variable in decorators

by Joe Walnes :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Maurif

The decorators.xml configuration loader does not support variables. However you can extends SiteMesh by adding your own DecoratorMapper to the stack that will do the variable substitution.

Here is a really crude implementation - but enough to get the point over.

  public class MyVariableSubstitutingDecoratorMapper extends AbstractDecoratorMapper {
    public Decorator getNamedDecorator(HttpServletRequest request, String name) {
      Decorator decorator = super.getNamedDecorator(request, name));
      if (decorator.getPage().contains("${template}")) {
        // replace decorator with a new page location.
        String newPage = decorator.getPage().replace("${template}", "something");
        decorator new DefaultDecorator(original.getName(), newPage, new HashMap());
      }
      return decorator;
    }
  }

To get SiteMesh to use this, you need to add it to WEB-INF/sitemesh.xml. (If you do not have this file, you can extract it from sitemesh.jar, named sitemesh-default.xml, or grab it here: http://fisheye5.cenqua.com/browse/~raw,r=1.5/sitemesh/src/java/com/opensymphony/module/sitemesh/factory/sitemesh-default.xml).

It should be inserted just before the ConfigDecoratorMapper.

  <sitemesh>
    ...
    <decorator-mappers>
      ... the other mappers ...
      <mapper class="com.yourpackage.MyVariableSubstitutingDecoratorMapper"/>
      <mapper class="com.opensymphony.module.sitemesh.mapper.ConfigDecoratorMapper">
        ...
      </mapper>
    </decorator-mappers>
  </sitemesh>

Hope that helps.
-Joe

On Tue, May 12, 2009 at 3:16 PM, Mauriff <mauriff@...> wrote:

Hi all,
I want to use to a dynamic variable, such as ${template}, in my
decorators.xml. Can I do it?
example:

<decorators defaultdir="/decorators">
<decorator name="default" page="${template}/default.jsp">
<pattern>/*</pattern>
</decorator>
</decorators>


Regards!

Mauri.
--
View this message in context: http://www.nabble.com/Using-variable-in-decorators-tp23503450p23503450.html
Sent from the OpenSymphony - SiteMesh mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...