<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的一個重要的組成部分可以為Cocoon的pipeline生成XML文件。XSP文件本身是XML文件,遵循XML的規范,但是支持在XML文件中包含程序代碼。XSP借助Bean Scripting Framework支持多種語言,包括Java,Javascript,Python 等。

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

    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下測試發現,其中的第2行聲明可以去掉。

    下面看一個在XSP里定義一個函數的例子:

    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>

    可以看到,定義函數的代碼被放在了<xsp:logic>元素里,另外使用<xsp:structure>和其子元素<xsp:include>元素可以導入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 文檔的根元素,它必須只包含一個用戶元素
    • xsp:structure、xsp:include — 允許將附加的 Java 類導入到 XSP 的已編譯版本中
    • xsp:logic — 允許在 XSP 的已編譯版本中包含附加的編程代碼塊;這可以包含成員變量、方法或應用程序邏輯
    • xsp:expr — 允許對 Java 表達式求值,并將它們的值添加到文檔
    • xsp:element — 允許 XSP 動態創建元素;這些元素可以用任意名稱創建,并且可以與任何名稱空間和前綴關聯
    • xsp:attribute — 允許將屬性動態地添加到元素;這些屬性可以用任意名稱和值創建,并且可以與任何名稱空間關聯
    • xsp:comment — 允許將注釋添加到已生成的文檔
    • xsp:pi — 允許動態創建處理指令,并將之添加到已生成的文檔
    • xsp:parameter — 允許為元素或屬性生成名稱

    通過使用 xsp:element,還可以動態地創建元素,如:

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

    這個示例顯示了用動態生成名稱創建元素涉及使用 xsp:element 和 xsp:param 元素。xsp:param定義了一個參數,在本例中是元素的名稱,其值是一個用于計算元素名稱的表達式。

    上面的代碼將生成 XML 輸出

    <myElementName>Element content</myElementName>

    用這種方式創建的元素還可以與一個特定的名稱空間和前綴關聯,如下例所示。請注意:這兩個名稱空間和前綴參數都是必需的;否則將產生錯誤。

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

    這個示例生成了以下 XML 輸出:

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

    如同元素一樣,可以在 XSP 頁面中動態創建屬性。xsp:attribute 元素的工作原理類似于 xsp:element,它允許動態創建屬性的名稱及其值:

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

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

    而 xsp:attribute 標記不必與 xsp:element 結合使用。它可以被放置在任何用戶元素內,而且可以用相同的方法添加屬性。例如,可以通過使用調用定義在 XSP 頁面別處的方法的表達式來動態創建 image 元素的 URL。

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

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

    創建注釋和處理指令

    xsp:comment 和 xsp:pi 元素用于創建注釋和處理指令。

    創建注釋十分簡單。任何作為 xsp:comment 元素的子元素而提供的文本都變成了 XML 注釋:

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

    然后這個注釋變成:

    <!-- This is a comment -->

    創建處理指令類似于創建動態元素或屬性。xsp:pi 元素應該有一個標識處理指令目標的嵌套參數。照例對 xsp:pi 元素的剩余內容求值。這里是一個簡單示例:

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

    輸出如下:

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

    還可以通過在 xsp:param 元素內創建處理指令的目標來自動生成它,如同以下示例演示的那樣:

    <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) 評論(0)  編輯  收藏 所屬分類: Frame

    導航

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

    統計

    常用鏈接

    留言簿(6)

    隨筆分類

    隨筆檔案(17)

    文章分類(86)

    收藏夾(3)

    flex blog

    good site

    java blog

    my friend

    tools

    抓蝦

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 国产va免费精品观看精品| xx视频在线永久免费观看| 男人都懂www深夜免费网站| 日本免费A级毛一片| 最近最新高清免费中文字幕| 97在线线免费观看视频在线观看| 成人免费无码大片A毛片抽搐| 国产亚洲福利一区二区免费看| 亚洲毛片av日韩av无码| 亚洲福利视频一区| 亚洲综合av一区二区三区不卡 | 亚洲成av人在线视| 亚洲精品视频在线观看免费| 亚洲精品无码中文久久字幕| 精品无码国产污污污免费网站国产 | 亚洲免费网站观看视频| 一个人免费观看日本www视频| 免费A级毛片在线播放| 全免费一级午夜毛片| 国产亚洲大尺度无码无码专线| 亚洲一二成人精品区| 亚洲国产精品成人午夜在线观看 | 成年大片免费高清在线看黄| 8x网站免费入口在线观看| 色吊丝永久在线观看最新免费| 亚洲无码黄色网址| 亚洲三级视频在线| 国产高清视频免费在线观看| 精品久久久久久久久免费影院| 亚洲伊人久久综合影院| 亚洲一区在线观看视频| 丰满人妻一区二区三区免费视频| 成人免费一级毛片在线播放视频| 日日噜噜噜噜夜夜爽亚洲精品| ASS亚洲熟妇毛茸茸PICS| aaa毛片免费观看| 免费鲁丝片一级观看| 亚洲av无码国产精品夜色午夜 | 一区二区三区免费看| 国产92成人精品视频免费| 亚洲人妻av伦理|