KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > web > taglib > TransformTag


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/web/taglib/TransformTag.java#6 $
3 // This software is subject to the terms of the Common Public License
4 // Agreement, available at the following URL:
5 // http://www.opensource.org/licenses/cpl.html.
6 // Copyright (C) 2002-2002 Kana Software, Inc.
7 // Copyright (C) 2002-2005 Julian Hyde and others
8 // All Rights Reserved.
9 // You must accept the terms of that agreement to use this software.
10 //
11 // Andreas Voss, 22 March, 2002
12 */

13 package mondrian.web.taglib;
14
15 import org.w3c.dom.Document JavaDoc;
16
17 import javax.servlet.jsp.JspException JavaDoc;
18 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
19 import javax.xml.transform.Transformer JavaDoc;
20 import javax.xml.transform.dom.DOMSource JavaDoc;
21 import javax.xml.transform.stream.StreamResult JavaDoc;
22
23 /**
24  * A <code>TransformTag</code> renders the result of a {@link ResultCache}
25  * object. Example:<blockquote>
26  *
27  * <pre>The current slicer is
28  * &lt;transform query="query1"
29  * xsltURI="/WEB-INF/mdxslicer.xsl"
30  * xsltCache="true"/&gt;
31  * &lt;br/&gt;
32  * &lt;transform query="query1"
33  * xsltURI="/WEB-INF/mdxtable.xsl"
34  * xsltCache="false"/&gt;</pre>
35  *
36  * </blockquote>
37  *
38  * Attributes are
39  * {@link #setQuery query},
40  * {@link #setXsltURI xsltURI},
41  * {@link #setXsltCache xsltCache}.
42  */

43
44 public class TransformTag extends TagSupport JavaDoc {
45
46     public TransformTag() {
47     }
48
49     public int doEndTag() throws javax.servlet.jsp.JspException JavaDoc {
50         try {
51             ApplResources ar = ApplResources.getInstance(pageContext.getServletContext());
52             ResultCache rc = ResultCache.getInstance(pageContext.getSession(), pageContext.getServletContext(), query);
53             Document JavaDoc doc = rc.getDOM();
54             // DOMBuilder.debug(doc);
55
Transformer JavaDoc transformer = ar.getTransformer(xsltURI, xsltCache);
56             transformer.transform(new DOMSource JavaDoc(doc), new StreamResult JavaDoc(pageContext.getOut()));
57         }
58         catch (Exception JavaDoc e) {
59             e.printStackTrace();
60             throw new JspException JavaDoc(e);
61         }
62         return EVAL_PAGE;
63     }
64
65     /** Sets the string attribute <code>query</code>, which is the name of a
66      * query declared using the {@link QueryTag &lt;query&gt;} tag. */

67     public void setQuery(String JavaDoc newQuery) {
68         query = newQuery;
69     }
70     public String JavaDoc getQuery() {
71         return query;
72     }
73
74     /** Sets the string attribute <code>xsltURI</code>, which is the URI of an
75      * XSL style-sheet to transform query output. */

76     public void setXsltURI(String JavaDoc newXsltURI) {
77         xsltURI = newXsltURI;
78     }
79     public String JavaDoc getXsltURI() {
80         return xsltURI;
81     }
82
83     /** Sets the boolean attribute <code>xsltCache</code>, which determines
84      * whether to cache the parsed representation of an XSL style-sheet. */

85     public void setXsltCache(boolean newXsltCache) {
86         xsltCache = newXsltCache;
87     }
88     public boolean isXsltCache() {
89         return xsltCache;
90     }
91
92     private String JavaDoc query;
93     private String JavaDoc xsltURI;
94     private boolean xsltCache;
95
96
97 }
98
99 // End TransformTag.java
100
Popular Tags