<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    cocoon xsp

    XSP (eXtensible Server Page )作為Cocoon的一個(gè)重要的組成部分可以為Cocoon的pipeline生成XML文件。XSP文件本身是XML文件,遵循XML的規(guī)范,但是支持在XML文件中包含程序代碼。XSP借助Bean Scripting Framework支持多種語(yǔ)言,包括Java,Javascript,Python 等。

    XSP文件的根元素為<page>,通常使用xsp名字空間(<xsp:page>)。
    一個(gè)簡(jiǎn)單的例子如:

    1: <?xml version="1.0"?>
    2: <?cocoon-process type=”xsp”?>
    3:
    4: <xsp:page
    5: language=”java”
    6: xmlns:xsp=”http://apache.org/xsp”>
    7:
    8: <date>
    9: <xsp:expr>new java.util.Date().toString()</xsp:expr>
    10: </date>
    11: </xsp:page>

    2004年出版的Professional XML Development with Apache Tools: Xerces, Xalan, FOP, Cocoon, Axis, Xindice一書稱2行是必須的,但是我在Cocoon 2.1.9下測(cè)試發(fā)現(xiàn),其中的第2行聲明可以去掉。

    下面看一個(gè)在XSP里定義一個(gè)函數(shù)的例子:

    1: <?xml version="1.0"?>
    2: <?cocoon-process type=”xsp”?>
    3:
    4: <xsp:page
    5: language=”java”
    6: xmlns:xsp=”http://apache.org/xsp”>
    7:
    8: <xsp:structure>
    9: <xsp:include>java.util.Date</xsp:include>
    10: </xsp:structure>
    11:
    12: <xsp:logic>
    13: String getDate() {
    14: Date d = new Date();
    15: return d.toString();
    16: }
    17: </xsp:logic>
    18:
    19: <date>
    20: <xsp:expr>getDate()</xsp:expr>
    21: </date>
    22: </xsp:page>

    可以看到,定義函數(shù)的代碼被放在了<xsp:logic>元素里,另外使用<xsp:structure>和其子元素<xsp:include>元素可以導(dǎo)入Java的類。

    完整的XSP元素列表如下:

    • <?cocoon-process?> This processing instruction (PI) tells Cocoon how to process this file. You may have multiple cocoon-process PIs because Cocoon can process an XSP page in two different ways. It can process the document as an XSP file, causing the language code to be executed. To indicate this style of processing, specify “xsp” as the value of the type pseudo-attribute. Cocoon can also use an XSL stylesheet to transform the document. This can occur either before or after the XSP processing. The processing order is determined by the order in which the PIs appear in the document. To use a stylesheet with an XSP document, specify “xslt” as the value of the type pseudo-attribute. If you use a stylesheet with the document, you need to supply an XML stylesheet processing instruction that tells where to find the stylesheet. (See the next item.)

    • <?xml-stylesheet?> This PI is defined by the W3C’s Associating Style Sheets with XML Documents recommendation. Associating a stylesheet is easy; you supply two pseudo-attributes. The href pseudo-attribute contains the URI for the stylesheet, and the type pseudo-attribute contains the MIME type of the stylesheet, which should be “text/xsl” for XSLT stylesheets.

    • <xsp:page> The root element of an XSP page is <xsp:page>. It takes a language attribute that allows you to specify the programming language being used in the XSP. You’ll probably also define some namespace prefixes on this element. The minimum would be for you to define the xsp prefix. The <xsp:page> must contain at least one user-defined element that’s used as the root element of the XSP result.

    • <xsp:structure> This element is a container for <xsp:include> elements.

    • <xsp:include> XSP uses the <xsp:include> element to import type definitions that are needed by the rest of the XSP. In Java, these are specified either as fully qualified classnames or in wildcarded package style, like java.util.*.

    • <xsp:logic> The implementation of the logic of an XSP should be the content of the <xsp:logic> element. For Java-based XSPs, this includes member fields and methods.

    • <xsp:expr> An <xsp:expr> element invokes logic in the <xsp:logic> to return a string valued expression. In Java, this is through method calls, field accesses, or string literals. Java string literals that appear as the content of an <xsp:expr> tag must be inside double quotes (”").

    • <xsp:element> This element allows you to dynamically create an element in the output XML. The <xsp:element> element takes a name attribute whose value is the name of the element to be created. You can nest these elements to create element subtrees dynamically. You can also insert literal XML elements and character data as part of the content of this element.

    • <xsp:attribute> The <xsp:attribute> element should appear as the child of either an <xsp:element> element or a literal XML element. It allows you to dynamically create an attribute by supplying a name attribute for the name of the new attribute. The value of the new attribute is the content of the <xsp:attribute> element.

    • <xsp:comment> To create a comment in the XSP output, use the <xsp:comment> element and make the content of the element the text of your comment.

    • <xsp:pi> The <xsp:pi> element allows you to create processing instructions. You supply a target attribute that defines the PI target name. If you wish to create pseudo-attributes, you do so via <xsp:expr> elements in the content of the <xsp:pi> element. So, to create a PI that looks like <?xml-stylesheet href=”sheet.xsl” type=”text/xsl”?>, your <xsp:pi> element would look like this:

      <xsp:pi target="xml-stylesheet">    <xsp:expr>"href=\"sheet.xsl\" type=\"text/xsl\""</xsp:expr>  </xsp:pi>
    • <xsp:content> You can use the <xsp:content> element inside an <xsp:logic> element to insert the Java code for an XSP fragment at that point on the program. This is particularly useful for inserting an XSP fragment that is to be output as the body of a loop.
    • xsp:page — XSP 文檔的根元素,它必須只包含一個(gè)用戶元素
    • xsp:structure、xsp:include — 允許將附加的 Java 類導(dǎo)入到 XSP 的已編譯版本中
    • xsp:logic — 允許在 XSP 的已編譯版本中包含附加的編程代碼塊;這可以包含成員變量、方法或應(yīng)用程序邏輯
    • xsp:expr — 允許對(duì) Java 表達(dá)式求值,并將它們的值添加到文檔
    • xsp:element — 允許 XSP 動(dòng)態(tài)創(chuàng)建元素;這些元素可以用任意名稱創(chuàng)建,并且可以與任何名稱空間和前綴關(guān)聯(lián)
    • xsp:attribute — 允許將屬性動(dòng)態(tài)地添加到元素;這些屬性可以用任意名稱和值創(chuàng)建,并且可以與任何名稱空間關(guān)聯(lián)
    • xsp:comment — 允許將注釋添加到已生成的文檔
    • xsp:pi — 允許動(dòng)態(tài)創(chuàng)建處理指令,并將之添加到已生成的文檔
    • xsp:parameter — 允許為元素或?qū)傩陨擅Q

    通過(guò)使用 xsp:element,還可以動(dòng)態(tài)地創(chuàng)建元素,如:

    <xsp:element>
    <xsp:param name="name"><xsp:expr>"myElementName"</xsp:expr></xsp:param>
    Element content
    </xsp:element>

    這個(gè)示例顯示了用動(dòng)態(tài)生成名稱創(chuàng)建元素涉及使用 xsp:element 和 xsp:param 元素。xsp:param定義了一個(gè)參數(shù),在本例中是元素的名稱,其值是一個(gè)用于計(jì)算元素名稱的表達(dá)式。

    上面的代碼將生成 XML 輸出

    <myElementName>Element content</myElementName>

    用這種方式創(chuàng)建的元素還可以與一個(gè)特定的名稱空間和前綴關(guān)聯(lián),如下例所示。請(qǐng)注意:這兩個(gè)名稱空間和前綴參數(shù)都是必需的;否則將產(chǎn)生錯(cuò)誤。

    <xsp:element prefix="my" uri="http://www.examples.org">
    <xsp:param name="name"><xsp:expr>"myElementName"</xsp:expr></xsp:param>
    Element content
    </xsp:element>

    這個(gè)示例生成了以下 XML 輸出:

    <my:myElementName xmlns:my="http://www.examples.org">Element content</my:myElementName>

    如同元素一樣,可以在 XSP 頁(yè)面中動(dòng)態(tài)創(chuàng)建屬性。xsp:attribute 元素的工作原理類似于 xsp:element,它允許動(dòng)態(tài)創(chuàng)建屬性的名稱及其值:

    <xsp:element>
    <xsp:param name="name"><xsp:expr>"myElementName"</xsp:expr></xsp:param>
    <xsp:attribute name="myAttribute">myAttributeValue</xsp:attribute>
    Element content
    </xsp:element>

    這個(gè)屬性的名稱定義在 name 屬性內(nèi),盡管是用與 xsp:element 類似的方法定義的,但它還能通過(guò)使用 xsp:param 子元素來(lái)定義。屬性值被指定成元素內(nèi)容。這可以是一個(gè)簡(jiǎn)單文本值或更有效地由 xsp:expr 元素生成。

    而 xsp:attribute 標(biāo)記不必與 xsp:element 結(jié)合使用。它可以被放置在任何用戶元素內(nèi),而且可以用相同的方法添加屬性。例如,可以通過(guò)使用調(diào)用定義在 XSP 頁(yè)面別處的方法的表達(dá)式來(lái)動(dòng)態(tài)創(chuàng)建 image 元素的 URL。

    <image>
    <xsp:attribute name="href"><xsp:expr>calculateImageURL()</xsp:expr></xsp:attribute>
    </image>

    如果生成的屬性與特定的名稱空間關(guān)聯(lián),那么這可以通過(guò)使用附加的 prefix 和 uri 屬性或 xsp:param 元素來(lái)表示,它類似于用于 xsp:element 的方法。同樣,如果只定義了其中的一個(gè),則是一個(gè)錯(cuò)誤。

    創(chuàng)建注釋和處理指令

    xsp:comment 和 xsp:pi 元素用于創(chuàng)建注釋和處理指令。

    創(chuàng)建注釋十分簡(jiǎn)單。任何作為 xsp:comment 元素的子元素而提供的文本都變成了 XML 注釋:

    <xsp:comment>This is a comment</xsp:comment>

    然后這個(gè)注釋變成:

    <!-- This is a comment -->

    創(chuàng)建處理指令類似于創(chuàng)建動(dòng)態(tài)元素或?qū)傩浴sp:pi 元素應(yīng)該有一個(gè)標(biāo)識(shí)處理指令目標(biāo)的嵌套參數(shù)。照例對(duì) xsp:pi 元素的剩余內(nèi)容求值。這里是一個(gè)簡(jiǎn)單示例:

    <xsp:pi target="myApplication">
    <xsp:expr>"param1=value, param2=value, generatorTimestamp=" +
    System.currentTimeMillis()</xsp:expr>
    </xsp:pi>

    輸出如下:

    <?myApplication param1=value, param2=value, generatorTimestamp=1017407796870?>

    還可以通過(guò)在 xsp:param 元素內(nèi)創(chuàng)建處理指令的目標(biāo)來(lái)自動(dòng)生成它,如同以下示例演示的那樣:

    <xsp:pi>
    <xsp:param name="target"><xsp:expr>"myApplication"</xsp:expr></xsp:param>
    <xsp:expr>"param1=value, param2=value, generatorTimestamp=" +
    System.currentTimeMillis()</xsp:expr>
    </xsp:pi>

    posted on 2007-01-26 12:02 leoli 閱讀(446) 評(píng)論(0)  編輯  收藏 所屬分類: Frame

    導(dǎo)航

    <2025年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    統(tǒng)計(jì)

    常用鏈接

    留言簿(6)

    隨筆分類

    隨筆檔案(17)

    文章分類(86)

    收藏夾(3)

    flex blog

    good site

    java blog

    my friend

    tools

    抓蝦

    搜索

    最新評(píng)論

    閱讀排行榜

    評(píng)論排行榜

    主站蜘蛛池模板: 久久精品国产亚洲av成人| 免费大学生国产在线观看p| 成年女人色毛片免费看| 精品剧情v国产在免费线观看| 国产中文字幕免费| 亚洲乱码日产精品a级毛片久久| 亚洲欧洲日产国码av系列天堂| 亚洲一卡2卡三卡4卡有限公司| 国产精品亚洲片夜色在线| AV激情亚洲男人的天堂国语| eeuss影院免费直达入口| 亚洲国产精品免费视频| 拨牐拨牐x8免费| 亚洲熟妇少妇任你躁在线观看无码| 久久久久亚洲av无码专区蜜芽| 亚洲国产成人精品无码区在线秒播| 亚洲heyzo专区无码综合| 中文字幕看片在线a免费| 亚洲视频在线免费播放| 亚洲国产成人在线视频| 亚洲一本到无码av中文字幕 | 99在线观看免费视频| 国产又大又粗又长免费视频 | 国产成人精品男人免费| 亚洲伊人色欲综合网| 亚洲H在线播放在线观看H| 黄色一级毛片免费看| 91香蕉国产线观看免费全集| 国产精品免费综合一区视频| 亚洲爆乳无码一区二区三区| 亚洲日韩国产一区二区三区在线 | 日本一道在线日本一道高清不卡免费| 国产成人精品日本亚洲专区61 | 一区二区三区观看免费中文视频在线播放| 最近的中文字幕大全免费版| 伊人婷婷综合缴情亚洲五月| 中文字幕亚洲精品无码| 你懂的免费在线观看网站| 日本成人免费在线| 久久久久久久亚洲Av无码| 日日狠狠久久偷偷色综合免费 |