click-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "jozsef.gabor@bluewin.ch" <jozsef.ga...@bluewin.ch>
Subject AW: [jira] Created: (CLK-568) Add ability to use templates with custom extensions
Date Thu, 16 Jul 2009 17:08:27 GMT
Hello. This is my favorite issue.

Currently I use a small hack in order to generate stylesheet from velocity template.
Example: http://212.25.31.150/shop2/style.css


First I tell the ClickServlet to trigger for special extensions in the deployment descriptor.
(web.xml).

	<servlet-mapping>
		<servlet-name>SpringClickServlet</servlet-name>
		<url-pattern>*.htm</url-pattern>
		<url-pattern>/robots.txt</url-pattern>
		<url-pattern>/style.css</url-pattern>
	</servlet-mapping>





Small modification of performRender method in the ClickServlet is necessary.
It is not perfect solution because it prevents using jsp pages. (IMHO jsp is a nightmare)

    /**
     * Performs rendering of the specified page.
     *
     * @param page page to render
     * @param context the request context
     * @throws java.lang.Exception if error occurs
     */
    protected void performRender(Page page, Context context) throws Exception {

        final HttpServletRequest request = context.getRequest();
        final HttpServletResponse response = context.getResponse();

        if (StringUtils.isNotBlank(page.getRedirect())) {
            String url = page.getRedirect();

            url = response.encodeRedirectURL(url);

            if (logger.isTraceEnabled()) {
                logger.debug("   redirect: " + url);

            } else if (logger.isDebugEnabled()) {
                logger.debug("redirect: " + url);
            }

            response.sendRedirect(url);

        } else if (StringUtils.isNotBlank(page.getForward())) {
            // Indicates the request is forwarded
            request.setAttribute(CLICK_FORWARD, CLICK_FORWARD);

            if (logger.isTraceEnabled()) {
                logger.debug("   forward: " + page.getForward());

            } else if (logger.isDebugEnabled()) {
                logger.debug("forward: " + page.getForward());
            }

            if (page.getForward().endsWith(".jsp")) {
                renderJSP(page);

            } else {
                RequestDispatcher dispatcher =
                    request.getRequestDispatcher(page.getForward());

                dispatcher.forward(request, response);
            }

        } else if (page.getPath() != null) {
        	// MODIFICATION JGA ---------------------
        	/*
            String pagePath = page.getPath();

            // Check if request is a JSP page
            if (pagePath.endsWith(".jsp") || configService.isJspPage(pagePath)) {
                // CLK-141. Set pagePath as the forward value.
                page.setForward(StringUtils.replace(pagePath, ".htm", ".jsp"));

                // Indicates the request is forwarded
                request.setAttribute(CLICK_FORWARD, CLICK_FORWARD);
                renderJSP(page);

            } else {
                renderTemplate(page);
            }
            */
            renderTemplate(page);
            // MODIFICATION JGA ---------------------

        } else {
            if (logger.isTraceEnabled()) {
                logger.debug("   path not defined for " + page.getClass().getName());

            } else if (logger.isDebugEnabled()) {
                logger.debug("path not defined for " + page.getClass().getName());
            }
        }
    }



Mime
View raw message