How to use an external decorator

thuss <[email protected]> Mon, 29 Aug 2005 14:45:57 CDT
Newsgroups gmane.comp.web.sitemesh.general,gmane.comp.lang.pnuts.user
Message-ID <32412750.1125344919413.JavaMail.os-j2ee@opensymphony01.contegix.com>
Well, I've come up with this rather ugly but functional JSP solution that pulls a page from our perl site and uses it as the decorator for java pages. On the perl side we have perlHeaderAndFooter.cgi which returns the page with $body where the main replacement should occur.

-Todd

decorators.xml:

<decorators defaultdir="/WEB-INF/decorator">
    <decorator name="perlwrapper" page="perlwrapper.jsp">
        <pattern>/*.jsp</pattern>
    </decorator>
</decorators>

perlwrapper.jsp:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ taglib
    uri="http://www.opensymphony.com/sitemesh/decorator"
    prefix="decorator" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>

<c:import url="http://mysite.com/perlHeaderAndFooter.cgi" var="ctmpl" />

<%
    String ctmpl = (String) pageContext.getAttribute("ctmpl");

    // Get the position markers
    int startmarker = ctmpl.indexOf("<html>");
    int bodymarker = ctmpl.indexOf("$body");
    int titlestartmarker = ctmpl.indexOf("<title>");
    int titlestopmarker = ctmpl.indexOf("</title>");
    int headmarker = ctmpl.indexOf("</head>");

    // Write out the head through the title
    out.write(ctmpl.substring(startmarker, titlestartmarker + 7));
%>

<decorator:title default="REPLACE THIS REPLACE THIS REPLACE THIS REPLACE THIS" />

<%
    // Write out the title through the head
    out.write(ctmpl.substring(titlestopmarker, headmarker));
%>

<decorator:head />

<%
    // Write out the head through the body start
    out.write(ctmpl.substring(headmarker, bodymarker));
%>

<decorator:body />

<%
    out.write(ctmpl.substring(bodymarker + 5, ctmpl.length() - 1));
%>

---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=6210&messageID=14075#14075


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]