Author: ssmiweve
Date: 2008-02-17 19:36:10 +0100 (Sun, 17 Feb 2008)
New Revision: 6130
Removed:
branches/2.16/war/src/main/webapp/WEB-INF/jsp/decorators/httpDecorator.jsp
Modified:
branches/2.16/war/src/main/java/no/sesat/search/http/filters/SiteJspLoaderFilter.java
branches/2.16/war/src/main/java/no/sesat/search/view/taglib/AbstractVelocityTemplateTag.java
branches/2.16/war/src/main/java/no/sesat/search/view/taglib/PublishingPageTag.java
branches/2.16/war/src/main/java/no/sesat/search/view/taglib/SearchTabIncludeTag.java
branches/2.16/war/src/main/java/no/sesat/search/view/taglib/SearchTabMainTag.java
branches/2.16/war/src/main/java/no/sesat/search/view/taglib/VelocityTemplateTag.java
branches/2.16/war/src/main/webapp/WEB-INF/jsp/decorators/webDecorator.jsp
Log:
SEARCH-4294 - Enable sesat templating system to accept JSP templates
Modified:
branches/2.16/war/src/main/java/no/sesat/search/http/filters/SiteJspLoaderFilter.java
===================================================================
---
branches/2.16/war/src/main/java/no/sesat/search/http/filters/SiteJspLoaderFilter.java
2008-02-17 17:01:01 UTC (rev 6129)
+++
branches/2.16/war/src/main/java/no/sesat/search/http/filters/SiteJspLoaderFilter.java
2008-02-17 18:36:10 UTC (rev 6130)
@@ -66,12 +66,6 @@
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
* </pre> so to avoid the skin's JspServlet and to serve the jsp files are
resources back to sesat,</li>
- * <li>in the skin's pom.xml add to the
<pre><directory>src/main/templates</directory></pre>
- * the following to ensure jsps and bundled into the war file:
- * <pre>
- <include>*.jsp</include>
- <include>**/*.jsp</include>
- * </pre></li>
* </ul>
* This have already been done in the base skin sesat-kernel/generic.sesam and
can be used as an example.<br/><br/>
*
Modified:
branches/2.16/war/src/main/java/no/sesat/search/view/taglib/AbstractVelocityTemplateTag.java
===================================================================
---
branches/2.16/war/src/main/java/no/sesat/search/view/taglib/AbstractVelocityTemplateTag.java
2008-02-17 17:01:01 UTC (rev 6129)
+++
branches/2.16/war/src/main/java/no/sesat/search/view/taglib/AbstractVelocityTemplateTag.java
2008-02-17 18:36:10 UTC (rev 6130)
@@ -24,9 +24,11 @@
import com.opensymphony.module.sitemesh.Page;
import com.opensymphony.module.sitemesh.RequestConstants;
import com.opensymphony.module.sitemesh.util.OutputConverter;
+import java.io.IOException;
import java.io.StringWriter;
import java.util.Enumeration;
import java.util.Map;
+import javax.servlet.ServletException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
@@ -110,15 +112,32 @@
}
return site;
}
+
+ /** Imports the specified jsp.
+ *
+ * @param include must contain ".jsp" suffix.
+ * @throws java.io.IOException
+ * @throws javax.servlet.ServletException
+ */
+ protected final void importJsp(final String include) throws JspException{
+
+ try{
+ ((PageContext)getJspContext()).include(include);
+
+ }catch(IOException ioe){
+ throw new JspException(ioe);
+ }catch(ServletException ioe){
+ throw new JspException(ioe);
+ }
+ }
- /**Called by the container to invoke this tag.
- * The implementation of this method is provided by the tag library
developer,
- * and handles all tag processing, body iteration, etc.
- * @param templateName
- * @param map
+ /** Imports the specified velocity template.
+ *
+ * @param templateName may or may not contain ".vm" extension.
+ * @param map key-value pairs to put into the velocity's context.
* @throws javax.servlet.jsp.JspException
*/
- protected final void importTemplate(final String templateName, final
Map<String,Object> map) throws JspException {
+ protected final void importVelocity(final String templateName, final
Map<String,Object> map) throws JspException {
final String missing = "Missing_" + templateName.replaceAll("/","") +
"_Template";
@@ -151,7 +170,10 @@
final VelocityEngine engine =
VelocityEngineFactory.valueOf(site).getEngine();
- final Template template =
VelocityEngineFactory.getTemplate(engine, site, templateName);
+ final Template template = VelocityEngineFactory.getTemplate(
+ engine,
+ site,
+ templateName.replaceAll(".vm$", ""));
final VelocityContext context =
VelocityEngineFactory.newContextInstance(engine);
Modified:
branches/2.16/war/src/main/java/no/sesat/search/view/taglib/PublishingPageTag.java
===================================================================
---
branches/2.16/war/src/main/java/no/sesat/search/view/taglib/PublishingPageTag.java
2008-02-17 17:01:01 UTC (rev 6129)
+++
branches/2.16/war/src/main/java/no/sesat/search/view/taglib/PublishingPageTag.java
2008-02-17 18:36:10 UTC (rev 6130)
@@ -77,7 +77,7 @@
final Map<String,Object> map = new
HashMap<String,Object>();
map.put("document", ImportPublish.importXml(page,
datamodel));
- importTemplate(template, map);
+ importVelocity(template, map);
} catch (ParserConfigurationException e) {
LOG.error("Failed to import " + page + ".html");
Modified:
branches/2.16/war/src/main/java/no/sesat/search/view/taglib/SearchTabIncludeTag.java
===================================================================
---
branches/2.16/war/src/main/java/no/sesat/search/view/taglib/SearchTabIncludeTag.java
2008-02-17 17:01:01 UTC (rev 6129)
+++
branches/2.16/war/src/main/java/no/sesat/search/view/taglib/SearchTabIncludeTag.java
2008-02-17 18:36:10 UTC (rev 6130)
@@ -34,8 +34,13 @@
import org.apache.log4j.Logger;
-/** Imports (and merges) a velocity template from a site-config into the jsp
according to the SearchTab's includes.
+/** Imports a template into the jsp according to the SearchTab's includes.
*
+ * The template may be either a velocity template or a JavaServer page.
+ * If the extension is not specified it defaults to ".vm".
+ *
+ * A relative path is relative to templates/fragments/layout/
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Michael Semb Wever</a>
* @version $Id$
*/
@@ -72,7 +77,7 @@
this.include = include;
}
- /**Called by the container to invoke this tag.
+ /** Called by the container to invoke this tag.
* The implementation of this method is provided by the tag library
developer,
* and handles all tag processing, body iteration, etc.
* @throws javax.servlet.jsp.JspException
@@ -86,22 +91,35 @@
if(null != layout.getInclude(include) &&
layout.getInclude(include).length() > 0 ){
- final String template = LAYOUT_DIRECTORY +
layout.getInclude(include);
try{
cxt.getOut().println("<!-- " + include + " -->");
}catch(IOException ioe){
LOG.warn("Failed to write include comment", ioe);
}
+
+ String template = layout.getInclude(include);
+ template = include.startsWith("/")
+ ? template
+ : LAYOUT_DIRECTORY + template;
final Map<String,Object> map = new HashMap<String,Object>();
+ map.put("layout", layout);
+ map.put("commandName", layout.getOrigin());
- map.put("layout", layout);
- // HACK the pager until the datamodel provides methods to access
"paging" commands in the current mode.
- map.put("commandName", layout.getOrigin());
- // end-HACK
+ if(template.endsWith(".jsp")){
- importTemplate(template, map);
+ importJsp(template);
+ }else if(template.endsWith(".vm")){
+
+ importVelocity(template, map);
+
+ }else{
+ // legacy
+ importVelocity(template, map);
+ }
+
+
}else{
// could not find include
cxt.getOut().write("<!-- " + include + " not found -->");
Modified:
branches/2.16/war/src/main/java/no/sesat/search/view/taglib/SearchTabMainTag.java
===================================================================
---
branches/2.16/war/src/main/java/no/sesat/search/view/taglib/SearchTabMainTag.java
2008-02-17 17:01:01 UTC (rev 6129)
+++
branches/2.16/war/src/main/java/no/sesat/search/view/taglib/SearchTabMainTag.java
2008-02-17 18:36:10 UTC (rev 6130)
@@ -21,9 +21,11 @@
package no.sesat.search.view.taglib;
+import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
+import javax.servlet.ServletException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
@@ -39,6 +41,11 @@
/** Import's the SearchTab's main template from the appropriate layout.
* Will use the "front" template if the layout defines it and the query is
empty.
*
+ * The template may be either a velocity template or a JavaServer page.
+ * If the extension is not specified it defaults to ".vm".
+ *
+ * A relative path is relative to templates/pages/
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Michael Semb Wever</a>
* @version $Id$
*/
@@ -83,23 +90,40 @@
? layout.getFront()
: null;
- final String include = datamodel.getQuery().getQuery().isBlank() &&
null != front
+ String include = datamodel.getQuery().getQuery().isBlank() && null !=
front
? front
: layout.getMain();
+ include = include.startsWith("/")
+ ? include
+ : PAGES_DIRECTORY + include;
- if(null != include){
+ try{
+ if(null != include){
- final Map<String,Object> map = new HashMap<String,Object>();
+ final Map<String,Object> map = new HashMap<String,Object>();
+ map.put("layout", layout);
- map.put("layout", layout);
+ if(include.endsWith(".jsp")){
- importTemplate(include.startsWith("/") ? include : PAGES_DIRECTORY
+ include, map);
+ importJsp(include);
- }else{
- // use the default httpDecorator.jsp
- cxt.setAttribute(MISSING, Boolean.TRUE);
+ }else if(include.endsWith(".vm")){
+
+ importVelocity(include, map);
+
+ }else{
+ // legacy
+ importVelocity(include, map);
+ }
+
+ }else{
+ LOG.error(MISSING);
+ cxt.getOut().println(MISSING);
+ cxt.setAttribute(MISSING, Boolean.TRUE);
+ }
+ }catch(IOException ioe){
+ throw new JspException(ioe);
}
-
}
// Package protected ---------------------------------------------
Modified:
branches/2.16/war/src/main/java/no/sesat/search/view/taglib/VelocityTemplateTag.java
===================================================================
---
branches/2.16/war/src/main/java/no/sesat/search/view/taglib/VelocityTemplateTag.java
2008-02-17 17:01:01 UTC (rev 6129)
+++
branches/2.16/war/src/main/java/no/sesat/search/view/taglib/VelocityTemplateTag.java
2008-02-17 18:36:10 UTC (rev 6130)
@@ -75,7 +75,7 @@
final Map<String,Object> map = new HashMap<String,Object>();
map.put("layout", layout);
map.put("commandName", command != null ? command : this.template);
- importTemplate(this.template, map);
+ importVelocity(this.template, map);
}
Deleted:
branches/2.16/war/src/main/webapp/WEB-INF/jsp/decorators/httpDecorator.jsp
===================================================================
--- branches/2.16/war/src/main/webapp/WEB-INF/jsp/decorators/httpDecorator.jsp
2008-02-17 17:01:01 UTC (rev 6129)
+++ branches/2.16/war/src/main/webapp/WEB-INF/jsp/decorators/httpDecorator.jsp
2008-02-17 18:36:10 UTC (rev 6130)
@@ -1,71 +0,0 @@
-<%-- Copyright (2006-2007) Schibsted Søk AS
- * This file is part of SESAT.
- *
- * SESAT is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published
by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * SESAT is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with SESAT. If not, see <http://www.gnu.org/licenses/>.
- -- The Homegrown Templating System.
- -- @author <a href="mailto:[EMAIL PROTECTED]">Michael Semb Wever</a>
- -- @version $Id$
---%>
-<%@ page language="java" pageEncoding="UTF-8"
contentType="text/html;charset=utf-8" %>
-<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
-<%@ taglib uri="/WEB-INF/SearchPortal.tld" prefix="search" %>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
-"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
-<head>
- <search:include include="head-element"/>
-</head>
-<body>
- <search:include include="topBar"/>
- <search:include include="header"/>
- <table cellspacing="0" cellpadding="0" id="body_table">
- <tr>
- <c:choose>
- <c:when test="${layout.properties['left-column-hide'] == 'true'}">
- <td valign="top" colspan="3">
- </c:when>
- <c:otherwise>
- <td class="cell_one" valign="top">
- <search:include include="left-col-one"/>
- <search:include include="left-col-two"/>
- <search:include include="left-col-three"/>
- <search:include include="left-col-four"/>
- <search:include include="left-col-five"/>
- </td>
- <td class="cell_three" valign="top" colspan="2">
- </c:otherwise>
- </c:choose>
- <search:include include="error-msg"/>
- <search:include include="middle-col-one"/>
- <search:include include="middle-col-two"/>
- <search:include include="middle-col-three"/>
- <search:include include="middle-col-four"/>
- <search:include include="middle-col-five"/>
- </td>
- <td class="cell_four">
- <search:include include="right-col-one"/>
- <search:include include="right-col-two"/>
- </td>
- </tr>
- </table>
- <search:include include="bottom-one"/>
- <search:include include="bottom-two"/>
- <search:include include="bottom-three"/>
- <search:include include="bottom-four"/>
- <search:include include="bottom-five"/>
- <search:include include="bottom-six"/>
- <search:include include="bottom-seven"/>
- <search:include include="bottom-eight"/>
-</body>
-</html>
Modified:
branches/2.16/war/src/main/webapp/WEB-INF/jsp/decorators/webDecorator.jsp
===================================================================
--- branches/2.16/war/src/main/webapp/WEB-INF/jsp/decorators/webDecorator.jsp
2008-02-17 17:01:01 UTC (rev 6129)
+++ branches/2.16/war/src/main/webapp/WEB-INF/jsp/decorators/webDecorator.jsp
2008-02-17 18:36:10 UTC (rev 6130)
@@ -19,10 +19,5 @@
-- @author <a href="mailto:[EMAIL PROTECTED]">Michael Semb Wever</a>
-- @version $Id$
--%>
-<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="/WEB-INF/SearchPortal.tld" prefix="search" %>
-
-<search:main/>
-<c:if test="${!empty Missing_SearchTabMain_Template}">
- <%@ include file="httpDecorator.jsp" %>
-</c:if>
\ No newline at end of file
+<search:main/>
\ No newline at end of file
_______________________________________________
Kernel-commits mailing list
[email protected]
http://sesat.no/mailman/listinfo/kernel-commits