⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filter-vary.xtp

📁 解压在c盘
💻 XTP
字号:
<s1 title="Servlet Filter with XTP -- Vary"><p>The Servlet 2.3 specification creates a new way to controlservlets: filters.  Filters can inspect and modify the request orresponse before and after passing the request to the servlet.</p><p>This example uses a servlet filter to select a stylesheet Serif(XTP) pages.  If the user adds the style=plain query, the page willuse a plain stylesheet.  Otherwise the page will use a fancystylesheet.</p><p>The filter itself just looks at the "style" parameter.  If it's"plain", then the filter will set the <var/caucho.xsl.stylesheet/>parameter to <var/plain.xsl/>.  Serif uses<var/caucho.xsl.stylesheet/> to transform the page to HTML.</p><example title="test.VaryFilter.java">package test;import java.io.*;import javax.servlet.*;import javax.servlet.http.*;public class VaryFilter implements Filter {  private FilterConfig config;  public void init(FilterConfig config)  {    this.config = config;  }  public void doFilter(ServletRequest request,                       ServletResponse response,                       FilterChain next)    throws IOException, ServletException  {    HttpServletRequest req = (HttpServletRequest) request;    String style = req.getParameter("style");    if ("plain".equals(style))      req.setAttribute("caucho.xsl.stylesheet", "plain.xsl");    else      req.setAttribute("caucho.xsl.stylesheet", "default.xsl");    next.doFilter(request, response);  }  public void destroy()  {  }}</example><example title="web.xml">&lt;web-app>  &lt;filter-mapping url-pattern='*.xtp'                  filter-name='test.VaryFilter'/>&lt;/web-app></example><p>The sample Serif page has a small section and some content.  It'sparsed as HTML before using the stylesheets.  The default stylesheetwill color the section header red.  The plain stylesheet leaves it asblack.</p><example title="test.xtp">&lt;title>A Sample Title&lt;/title>&lt;s1 title="A Sample Section">Some content in the sample section.&lt;/s1></example><p>Unknown tags are copied from the Serif page to the generated HTMLpage unchanged.  So you can just add rules for tags you want tochange.  The example forces the background of the body to white andformats a section with an H3 header colored red.</p><example title="default.xsl">&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"                version="1.0">  &lt;!-- make sure '&lt;' is not printed as '&amp;lt;' -->  &lt;xsl:output disable-output-escaping='true'/>  &lt;!-- copy input to output -->  &lt;xsl:template match='*|@*'>    &lt;xsl:copy>      &lt;xsl:apply-templates select='node()|@*'/>    &lt;/xsl:copy>  &lt;/xsl:template>  &lt;xsl:template match="body">    &lt;body bgcolor=white>      &lt;xsl:apply-templates/>    &lt;/body>  &lt;/xsl:template>  &lt;xsl:template match="s1">    &lt;h3>&lt;font color=red>&lt;xsl:value-of select="@title"/>&lt;/font>&lt;/h3>    &lt;xsl:apply-templates/>  &lt;/xsl:template>&lt;/xsl:stylesheet></example><p>The plain stylesheet leaves the Serif page untouched except forconverting the section title to use plain H3.</p><example title="plain.xsl">&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"                version="1.0">  &lt;!-- make sure '&lt;' is not printed as '&amp;lt;' -->  &lt;xsl:output disable-output-escaping='true'/>  &lt;!-- copy input to output -->  &lt;xsl:template match='*|@*'>    &lt;xsl:copy>      &lt;xsl:apply-templates select='node()|@*'/>    &lt;/xsl:copy>  &lt;/xsl:template>  &lt;xsl:template match="s1">    &lt;h3>&lt;xsl:value-of select="@title"/>&lt;/h3>    &lt;xsl:apply-templates/>  &lt;/xsl:template>&lt;/xsl:stylesheet></example></s1>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -