锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲精品永久www忘忧草,亚洲欧洲精品无码AV,激情无码亚洲一区二区三区http://www.tkk7.com/libin2722/category/36802.html铏氬叾蹇冿紝鍙В澶╀笅涔嬮棶錛涗笓鍏跺績錛屽彲娌誨ぉ涓嬩箣瀛︼紱闈欏叾蹇冿紝鍙偀澶╀笅涔嬬悊錛涙亽鍏跺績錛屽彲鎴愬ぉ涓嬩箣涓氥?/description>zh-cnWed, 11 Aug 2010 02:38:08 GMTWed, 11 Aug 2010 02:38:08 GMT60 FreeMarker 鑷畾涔夋爣絳?/title><link>http://www.tkk7.com/libin2722/articles/328209.html</link><dc:creator>紺肩墿</dc:creator><author>紺肩墿</author><pubDate>Sat, 07 Aug 2010 10:11:00 GMT</pubDate><guid>http://www.tkk7.com/libin2722/articles/328209.html</guid><wfw:comment>http://www.tkk7.com/libin2722/comments/328209.html</wfw:comment><comments>http://www.tkk7.com/libin2722/articles/328209.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/libin2722/comments/commentRss/328209.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/libin2722/services/trackbacks/328209.html</trackback:ping><description><![CDATA[ <h1 class="title_txt"> FreeMarker 鑷畾涔夋爣絳? <cite class="fav_csdnstylebykimi"><a href="javascript:d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(saveit=window.open('http://wz.csdn.net/storeit.aspx?t='+escape(d.title)+'&u='+escape(d.location.href)+'&c='+escape(t),'saveit','scrollbars=no,width=590,height=300,left=75,top=20,status=no,resizable=yes'));saveit.focus();" class="fav_csdnstylebykimi" title="鏀惰棌鍒版垜鐨勭綉鎽樹腑錛屽茍鍒嗕韓緇欐垜鐨勬湅鍙?>鏀惰棌</a></cite></h1> <div id="xzxdjth" class="blogstory"> <script type="text/javascript"><![CDATA[ document.body.oncopy = function () { if (window.clipboardData) { setTimeout(function () { var text = clipboardData.getData("text"); if (text && text.length > 300) { text = text + "\r\n\n鏈枃鏉ヨ嚜CSDN鍗氬錛岃漿杞借鏍囨槑鍑哄錛? + location.href; clipboardData.setData("text", text); } }, 100); } } ]]></script> <script type="text/javascript"><![CDATA[ function StorePage() { d = document; t = d.selection ? (d.selection.type != 'None' ? d.selection.createRange().text : '') : (d.getSelection ? d.getSelection() : ''); void (keyit = window.open('http://www.365key.com/storeit.aspx?t=' + escape(d.title) + '&u=' + escape(d.location.href) + '&c=' + escape(t), 'keyit', 'scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes')); keyit.focus(); }]]></script> <div id="npplxpv" class="sect1"> <div id="xnbftlt" class="titlepage"> <div> <h2> <a name="pgui_datamodel_directive"> </a>Directives</h2> </div> </div> <p>Java programmers can implement user-defined directives in Java using the <tt style="color: rgb(160, 61, 16);">TemplateDirectiveModel</tt> interface. See in the API documentation.</p> <div style="margin-left: 0.5in; margin-right: 0.5in;"> <h3>Note</h3> <p> <tt style="color: rgb(160, 61, 16);">TemplateDirectiveModel</tt> was introduced in FreeMarker 2.3.11, replacing the soon to be depreciated <tt style="color: rgb(160, 61, 16);">TemplateTransformModel</tt>.</p> </div> <div id="xjzfrpx" class="titlepage"> <div> <h3> <a name="autoid_35"> </a>Example 1</h3> </div> </div> <p>We will implement a directive which converts all output between its start-tag and end-tag to upper case. Like, this template:</p> <div> <table bgcolor="#d8d8d8" border="0" cellpadding="0" cellspacing="0"> <tbody> <tr valign="top"> <td bgcolor="#000000" height="1" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> <td bgcolor="#000000" height="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> <td bgcolor="#000000" height="1" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> </tr> <tr> <td bgcolor="#000000" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> <td> <table style="margin: 0px; width: 100%;" bgcolor="#d8d8d8" border="0" cellpadding="4" cellspacing="0"> <tbody> <tr> <td> <pre style="margin: 0px;">foo<br /><strong><@upper></strong><br /> bar<br /> <#-- All kind of FTL is allowed here --><br /> <#list ["red", "green", "blue"] as color><br /> ${color}<br /> </#list><br /> baaz<br /><strong></@upper></strong><br />wombat聽<span style="font-size: 1pt;"></span></pre> </td> </tr> </tbody> </table> </td> <td bgcolor="#000000" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> </tr> <tr valign="top"> <td bgcolor="#000000" height="1" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> <td bgcolor="#000000" height="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> <td bgcolor="#000000" height="1" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> </tr> </tbody> </table> </div> <p>will output this:</p> <div> <table bgcolor="#ccffcc" border="0" cellpadding="0" cellspacing="0"> <tbody> <tr valign="top"> <td bgcolor="#000000" height="1" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> <td bgcolor="#000000" height="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> <td bgcolor="#000000" height="1" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> </tr> <tr> <td bgcolor="#000000" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> <td> <table style="margin: 0px; width: 100%;" bgcolor="#ccffcc" border="0" cellpadding="4" cellspacing="0"> <tbody> <tr> <td> <pre style="margin: 0px;">foo<br /> BAR<br /> RED<br /> GREEN<br /> BLUE<br /> BAAZ<br />wombat聽<span style="font-size: 1pt;"></span></pre> </td> </tr> </tbody> </table> </td> <td bgcolor="#000000" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> </tr> <tr valign="top"> <td bgcolor="#000000" height="1" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> <td bgcolor="#000000" height="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> <td bgcolor="#000000" height="1" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> </tr> </tbody> </table> </div> <p>This is the source code of the directive class:</p> <div> <table bgcolor="#f8f8f8" border="0" cellpadding="0" cellspacing="0"> <tbody> <tr valign="top"> <td bgcolor="#000000" height="1" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> <td bgcolor="#000000" height="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> <td bgcolor="#000000" height="1" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> </tr> <tr> <td bgcolor="#000000" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> <td> <table style="margin: 0px; width: 100%;" bgcolor="#f8f8f8" border="0" cellpadding="4" cellspacing="0"> <tbody> <tr> <td> <pre style="margin: 0px;">package com.example;<br />import java.io.IOException;<br />import java.io.Writer;<br />import java.util.Map;<br /><br />import freemarker.core.Environment;<br />import freemarker.template.TemplateDirectiveBody;<br />import freemarker.template.TemplateDirectiveModel;<br />import freemarker.template.TemplateException;<br />import freemarker.template.TemplateModel;<br />import freemarker.template.TemplateModelException;<br /><br />/**<br /> * FreeMarker user-defined directive that progressively transforms<br /> * the output of its nested content to upper-case.<br /> * <br /> * <br /> * <p><b>Directive info</b></p><br /> * <br /> * <p>Directive parameters: None<br /> * <p>Loop variables: None<br /> * <p>Directive nested content: Yes<br /> */<br />public class UpperDirective implements TemplateDirectiveModel {<br /><br /> public void execute(Environment env,<br /> Map params, TemplateModel[] loopVars,<br /> TemplateDirectiveBody body)<br /> throws TemplateException, IOException {<br /> // Check if no parameters were given:<br /> if (!params.isEmpty()) {<br /> throw new TemplateModelException(<br /> "This directive doesn't allow parameters.");<br /> }<br /> if (loopVars.length != 0) {<br /> throw new TemplateModelException(<br /> "This directive doesn't allow loop variables.");<br /> }<br /><br /> // If there is non-empty nested content:<br /> if (body != null) {<br /> // Executes the nested body. Same as <#nested> in FTL, except<br /> // that we use our own writer instead of the current output writer.<br /> body.render(new UpperCaseFilterWriter(env.getOut()));<br /> } else {<br /> throw new RuntimeException("missing body");<br /> }<br /> }<br /><br /> /**<br /> * A {@link Writer} that transforms the character stream to upper case<br /> * and forwards it to another {@link Writer}.<br /> */ <br /> private static class UpperCaseFilterWriter extends Writer {<br /><br /> private final Writer out;<br /><br /> UpperCaseFilterWriter (Writer out) {<br /> this.out = out;<br /> }<br /><br /> public void write(char[] cbuf, int off, int len)<br /> throws IOException {<br /> char[] transformedCbuf = new char[len];<br /> for (int i = 0; i < len; i++) {<br /> transformedCbuf[i] = Character.toUpperCase(cbuf[i + off]);<br /> }<br /> out.write(transformedCbuf);<br /> }<br /><br /> public void flush() throws IOException {<br /> out.flush();<br /> }<br /><br /> public void close() throws IOException {<br /> out.close();<br /> }<br /> }<br /><br />}聽<span style="font-size: 1pt;"></span></pre> </td> </tr> </tbody> </table> </td> <td bgcolor="#000000" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> </tr> <tr valign="top"> <td bgcolor="#000000" height="1" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> <td bgcolor="#000000" height="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> <td bgcolor="#000000" height="1" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> </tr> </tbody> </table> </div> <p>Now we still need to create an instance of this class, and make this directive available to the template with the name "upper" (or with whatever name we want) somehow. A possible solution is to put the directive in the data-model:</p> <div> <table bgcolor="#f8f8f8" border="0" cellpadding="0" cellspacing="0"> <tbody> <tr valign="top"> <td bgcolor="#000000" height="1" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> <td bgcolor="#000000" height="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> <td bgcolor="#000000" height="1" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> </tr> <tr> <td bgcolor="#000000" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> <td> <table style="margin: 0px; width: 100%;" bgcolor="#f8f8f8" border="0" cellpadding="4" cellspacing="0"> <tbody> <tr> <td> <pre style="margin: 0px;">root.put("upper", new com.example.UpperDirective());聽<span style="font-size: 1pt;"></span></pre> </td> </tr> </tbody> </table> </td> <td bgcolor="#000000" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> </tr> <tr valign="top"> <td bgcolor="#000000" height="1" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> <td bgcolor="#000000" height="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> <td bgcolor="#000000" height="1" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> </tr> </tbody> </table> </div> <p>But typically it is better practice to put commonly used directives into the <tt style="color: rgb(160, 61, 16);">Configuration</tt> as <a >shared variables</a>.</p> <p>It is also possible to put the directive into an FTL library (collection of macros and like in a template, that you <tt style="color: rgb(160, 61, 16);">include</tt> or <tt style="color: rgb(160, 61, 16);">import</tt> in other templates) using the <a ><tt>new</tt> built-in</a>:</p> <div> <table bgcolor="#d8d8d8" border="0" cellpadding="0" cellspacing="0"> <tbody> <tr valign="top"> <td bgcolor="#000000" height="1" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> <td bgcolor="#000000" height="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> <td bgcolor="#000000" height="1" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> </tr> <tr> <td bgcolor="#000000" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> <td> <table style="margin: 0px; width: 100%;" bgcolor="#d8d8d8" border="0" cellpadding="4" cellspacing="0"> <tbody> <tr> <td> <pre style="margin: 0px;"><#-- Maybe you have directives that you have implemented in FTL --><br /><#macro something><br /> ...<br /></#macro><br /><br /><#-- Now you can't use <#macro upper>, but instead you can: --><br /><#assign upper = "com.example.UpperDirective"?new()>聽<span style="font-size: 1pt;"></span></pre> </td> </tr> </tbody> </table> </td> <td bgcolor="#000000" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> </tr> <tr valign="top"> <td bgcolor="#000000" height="1" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> <td bgcolor="#000000" height="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> <td bgcolor="#000000" height="1" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> </tr> </tbody> </table> </div> <div id="blnbhdf" class="titlepage"> <div> <h3> <a name="autoid_36"> </a>Example 2</h3> </div> </div> <p> <span id="result_box" class="short_text"> <span style="font-size: large;"> <span>鎴戜滑灝嗗垱寤轟竴涓寚浠ょ殑鎵ц鎸囧畾鐨勬鏁幫紙鍚屾牱鍒楀嚭鎸囦護錛夐殢鎰忓垎闅斾笌涓涓?lt;hr> - S鐨剅epetations杈撳嚭錛屽叾宓屽鐨勫唴瀹癸紝鍐嶅涔犮?/span> <span>璁╂垜浠妸榪欑鎸囦護鈥滈噸澶嶁濄?/span> <span style="background-color: rgb(255, 255, 255);">渚嬪妯℃澘錛?/span> </span> </span> </p> <div> <table bgcolor="#d8d8d8" border="0" cellpadding="0" cellspacing="0"> <tbody> <tr valign="top"> <td bgcolor="#000000" height="1" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> <td bgcolor="#000000" height="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> <td bgcolor="#000000" height="1" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> </tr> <tr> <td bgcolor="#000000" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> <td> <table style="margin: 0px; width: 100%;" bgcolor="#d8d8d8" border="0" cellpadding="4" cellspacing="0"> <tbody> <tr> <td> <pre style="margin: 0px;"><#assign x = 1><br /><br /><strong><@repeat count=4></strong><br /> Test ${x}<br /> <#assign x = x + 1><br /><strong></@repeat></strong><br /><br /><strong><@repeat count=3 hr=true></strong><br /> Test<br /><strong></@repeat></strong><br /><br /><strong><@repeat count=3; cnt></strong><br /> ${cnt}. Test<br /><strong></@repeat></strong>聽<span style="font-size: 1pt;"></span></pre> </td> </tr> </tbody> </table> </td> <td bgcolor="#000000" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> </tr> <tr valign="top"> <td bgcolor="#000000" height="1" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> <td bgcolor="#000000" height="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> <td bgcolor="#000000" height="1" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> </tr> </tbody> </table> </div> <p>Output:</p> <div> <table bgcolor="#ccffcc" border="0" cellpadding="0" cellspacing="0"> <tbody> <tr valign="top"> <td bgcolor="#000000" height="1" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> <td bgcolor="#000000" height="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> <td bgcolor="#000000" height="1" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> </tr> <tr> <td bgcolor="#000000" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> <td> <table style="margin: 0px; width: 100%;" bgcolor="#ccffcc" border="0" cellpadding="4" cellspacing="0"> <tbody> <tr> <td> <pre style="margin: 0px;"> Test 1<br /> Test 2<br /> Test 3<br /> Test 4<br /><br /> Test<br /><hr> Test<br /><hr> Test<br /><br /> 1. Test<br /> 2. Test<br /> 3. Test<br />聽<span style="font-size: 1pt;"></span></pre> </td> </tr> </tbody> </table> </td> <td bgcolor="#000000" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> </tr> <tr valign="top"> <td bgcolor="#000000" height="1" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> <td bgcolor="#000000" height="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> <td bgcolor="#000000" height="1" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> </tr> </tbody> </table> </div> <p>The class:</p> <div> <table bgcolor="#f8f8f8" border="0" cellpadding="0" cellspacing="0"> <tbody> <tr valign="top"> <td bgcolor="#000000" height="1" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> <td bgcolor="#000000" height="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> <td bgcolor="#000000" height="1" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> </tr> <tr> <td bgcolor="#000000" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> <td> <table style="margin: 0px; width: 100%;" bgcolor="#f8f8f8" border="0" cellpadding="4" cellspacing="0"> <tbody> <tr> <td> <pre style="margin: 0px;">package com.example;<br />import java.io.IOException;<br />import java.io.Writer;<br />import java.util.Iterator;<br />import java.util.Map;<br /><br />import freemarker.core.Environment;<br />import freemarker.template.SimpleNumber;<br />import freemarker.template.TemplateBooleanModel;<br />import freemarker.template.TemplateDirectiveBody;<br />import freemarker.template.TemplateDirectiveModel;<br />import freemarker.template.TemplateException;<br />import freemarker.template.TemplateModel;<br />import freemarker.template.TemplateModelException;<br />import freemarker.template.TemplateNumberModel;<br /><br />/**<br /> * FreeMarker user-defined directive for repeating a section of a template,<br /> * optionally with separating the output of the repetations with<br /> * <tt>&lt;hr></tt>-s.<br /> *<br /> * <br /> * <p><b>Directive info</b></p><br /> * <br /> * <p>Parameters:<br /> * <ul><br /> * <li><code>count</code>: The number of repetations. Required!<br /> * Must be a non-negative number. If it is not a whole number then it will<br /> * be rounded <em>down</em>.<br /> * <li><code>hr</code>: Tells if a HTML "hr" element could be printed between<br /> * repetations. Boolean. Optional, defaults to <code>false</code>. <br /> * </ul><br /> *<br /> * <p>Loop variables: One, optional. It gives the number of the current<br /> * repetation, starting from 1.<br /> * <br /> * <p>Nested content: Yes<br /> */<br />public class RepeatDirective implements TemplateDirectiveModel {<br /><br /> private static final String PARAM_NAME_COUNT = "count";<br /> private static final String PARAM_NAME_HR = "hr";<br /><br /> public void execute(Environment env,<br /> Map params, TemplateModel[] loopVars,<br /> TemplateDirectiveBody body)<br /> throws TemplateException, IOException {<br /><br /> // ---------------------------------------------------------------------<br /> // Processing the parameters:<br /><br /> int countParam = 0;<br /> boolean countParamSet = false;<br /> boolean hrParam = false;<br /><br /> Iterator paramIter = params.entrySet().iterator();<br /> while (paramIter.hasNext()) {<br /> Map.Entry ent = (Map.Entry) paramIter.next();<br /><br /> String paramName = (String) ent.getKey();<br /> TemplateModel paramValue = (TemplateModel) ent.getValue();<br /><br /> if (paramName.equals(PARAM_NAME_COUNT)) {<br /> if (!(paramValue instanceof TemplateNumberModel)) {<br /> throw new TemplateModelException(<br /> "The \"" + PARAM_NAME_HR + "\" parameter "<br /> + "must be a number.");<br /> }<br /> countParam = ((TemplateNumberModel) paramValue)<br /> .getAsNumber().intValue();<br /> countParamSet = true;<br /> if (countParam < 0) {<br /> throw new TemplateModelException(<br /> "The \"" + PARAM_NAME_HR + "\" parameter "<br /> + "can't be negative.");<br /> }<br /> } else if (paramName.equals(PARAM_NAME_HR)) {<br /> if (!(paramValue instanceof TemplateBooleanModel)) {<br /> throw new TemplateModelException(<br /> "The \"" + PARAM_NAME_HR + "\" parameter "<br /> + "must be a boolean.");<br /> }<br /> hrParam = ((TemplateBooleanModel) paramValue)<br /> .getAsBoolean();<br /> } else {<br /> throw new TemplateModelException(<br /> "Unsupported parameter: " + paramName);<br /> }<br /> }<br /> if (!countParamSet) {<br /> throw new TemplateModelException(<br /> "The required \"" + PARAM_NAME_COUNT + "\" paramter"<br /> + "is missing.");<br /> }<br /><br /> if (loopVars.length > 1) {<br /> throw new TemplateModelException(<br /> "At most one loop variable is allowed.");<br /> }<br /><br /> // Yeah, it was long and boring...<br /><br /> // ---------------------------------------------------------------------<br /> // Do the actual directive execution:<br /><br /> Writer out = env.getOut();<br /> if (body != null) {<br /> for (int i = 0; i < countParam; i++) {<br /> // Prints a <hr> between all repetations if the "hr" parameter<br /> // was true:<br /> if (hrParam && i != 0) {<br /> out.write("<hr>");<br /> }<br /><br /> // Set the loop variable, if there is one:<br /> if (loopVars.length > 0) {<br /> loopVars[0] = new SimpleNumber(i + 1);<br /> }<br /><br /> // Executes the nested body (same as <#nested> in FTL). In this<br /> // case we don't provide a special writer as the parameter:<br /> body.render(env.getOut());<br /> }<br /> }<br /> }<br /><br />}聽<span style="font-size: 1pt;"></span></pre> </td> </tr> </tbody> </table> </td> <td bgcolor="#000000" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> </tr> <tr valign="top"> <td bgcolor="#000000" height="1" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> <td bgcolor="#000000" height="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> <td bgcolor="#000000" height="1" width="1"> <img src="http://writeblog.csdn.net/images/none.gif" alt="" border="0" height="1" hspace="0" width="1" /> </td> </tr> </tbody> </table> </div> <div id="hhvxlzp" class="titlepage"> <div> <h3> <a name="autoid_37"> </a>Notices</h3> </div> </div> <p> <span id="result_box" class="medium_text"> <span style="font-size: small;"> <span>榪欐槸闈炲父閲嶈鐨勪竴TemplateDirectiveModel瀵硅薄閫氬父涓嶅簲璇ユ湁鐘舵併?/span> <span style="background-color: rgb(255, 255, 255);">鍏稿瀷鐨勯敊璇槸瀵瑰湪璇ュ璞$殑瀛楁鎸囦護璋冪敤鎵ц鐘舵佸偍瀛樸?/span> </span> <span style="font-size: small;"> <span style="background-color: rgb(255, 255, 255);">瀵瑰悓涓鎸囦護錛屾垨鑰呮寚浠ゅ祵濂楄皟鐢ㄧ湅鎴愭槸鐢卞涓嚎紼嬪悓鏃惰闂叡浜彉閲忎嬌鐢ㄧ殑瀵硅薄銆?br /><br /></span> <span style="background-color: rgb(255, 255, 255);">鍙儨鐨勬槸錛孴emplateDirectiveModel錛屽氨鍋氫笉鏀寔浼犻掑弬鏁版寜浣嶇疆錛堣屼笉鏄悕縐幫級銆?/span> <span style="background-color: rgb(255, 255, 255);">榪欐槸鍥哄畾鐨勮搗浠稦reeMarker鐨?.4銆?/span> </span> </span> </p> </div> </div> <img src ="http://www.tkk7.com/libin2722/aggbug/328209.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/libin2722/" target="_blank">紺肩墿</a> 2010-08-07 18:11 <a href="http://www.tkk7.com/libin2722/articles/328209.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>Freemarker涓嬌鐢∣SCachehttp://www.tkk7.com/libin2722/articles/328205.html紺肩墿紺肩墿Sat, 07 Aug 2010 07:53:00 GMThttp://www.tkk7.com/libin2722/articles/328205.htmlhttp://www.tkk7.com/libin2722/comments/328205.htmlhttp://www.tkk7.com/libin2722/articles/328205.html#Feedback0http://www.tkk7.com/libin2722/comments/commentRss/328205.htmlhttp://www.tkk7.com/libin2722/services/trackbacks/328205.html
渚嬪錛?br /><#assign oscache=JspTaglibs['http://www.opensymphony.com/oscache']/>

<#assign fowUrlaa="">
<#if RequestParameters.fowUrl?exists>
<#assign fowUrlaa="${RequestParameters.fowUrl}">
</#if>
<@oscache.cache key="__oscache_categories" time=300>
聽聽聽 ${fowUrlaa}
</@oscache.cache>

鐒跺悗鍐峌RL涓婃坊鍔犲弬鏁版祴璇曪細?fowUrl=12fas11

紺肩墿 2010-08-07 15:53 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 免费一级全黄少妇性色生活片| 亚洲AV永久无码精品一百度影院| 日韩亚洲国产综合高清| 免费国产黄网站在线观看可以下载| 国产亚洲自拍一区| 中文字幕成人免费高清在线 | 亚洲人成网7777777国产| 日韩在线观看免费完整版视频| 国产成人综合久久精品免费| 亚洲丁香婷婷综合久久| 四虎亚洲国产成人久久精品 | 亚洲欧美综合精品成人导航| 日本特黄特黄刺激大片免费| 亚洲精品无码久久久久APP| 日韩成人免费视频播放| 免费无毒a网站在线观看| 国产亚洲AV夜间福利香蕉149| 中国一级特黄的片子免费 | 亚洲国产激情在线一区| 性xxxx视频播放免费| 真人无码作爱免费视频| 国产乱辈通伦影片在线播放亚洲| 91视频免费观看| 亚洲精品自拍视频| 啦啦啦在线免费视频| 人妻仑刮八A级毛片免费看| 亚洲精品美女久久777777| 久久久久免费看成人影片| 波多野结衣亚洲一级| 亚洲人成人无码网www国产| 国产午夜无码精品免费看| 亚洲国产成人久久99精品| 免费看美女让人桶尿口| 人体大胆做受免费视频| 亚洲国产女人aaa毛片在线| 成人在线视频免费| 羞羞视频免费网站在线看| 亚洲国产综合第一精品小说| 国产gav成人免费播放视频| 免费在线看污视频| 亚洲色大18成人网站WWW在线播放|