001 /* 002 // $Id: //open/mondrian/src/main/mondrian/web/taglib/TransformTag.java#7 $ 003 // This software is subject to the terms of the Common Public License 004 // Agreement, available at the following URL: 005 // http://www.opensource.org/licenses/cpl.html. 006 // Copyright (C) 2002-2002 Kana Software, Inc. 007 // Copyright (C) 2002-2008 Julian Hyde and others 008 // All Rights Reserved. 009 // You must accept the terms of that agreement to use this software. 010 // 011 // Andreas Voss, 22 March, 2002 012 */ 013 package mondrian.web.taglib; 014 015 import org.w3c.dom.Document; 016 017 import javax.servlet.jsp.JspException; 018 import javax.servlet.jsp.tagext.TagSupport; 019 import javax.xml.transform.Transformer; 020 import javax.xml.transform.dom.DOMSource; 021 import javax.xml.transform.stream.StreamResult; 022 023 /** 024 * A <code>TransformTag</code> renders the result of a {@link ResultCache} 025 * object. Example:<blockquote> 026 * 027 * <pre>The current slicer is 028 * <transform query="query1" 029 * xsltURI="/WEB-INF/mdxslicer.xsl" 030 * xsltCache="true"/> 031 * <br/> 032 * <transform query="query1" 033 * xsltURI="/WEB-INF/mdxtable.xsl" 034 * xsltCache="false"/></pre> 035 * 036 * </blockquote> 037 * 038 * Attributes are 039 * {@link #setQuery query}, 040 * {@link #setXsltURI xsltURI}, 041 * {@link #setXsltCache xsltCache}. 042 */ 043 044 public class TransformTag extends TagSupport { 045 046 public TransformTag() { 047 } 048 049 public int doEndTag() throws javax.servlet.jsp.JspException { 050 try { 051 ApplResources ar = ApplResources.getInstance(pageContext.getServletContext()); 052 ResultCache rc = ResultCache.getInstance(pageContext.getSession(), pageContext.getServletContext(), query); 053 Document doc = rc.getDOM(); 054 // DOMBuilder.debug(doc); 055 Transformer transformer = ar.getTransformer(xsltURI, xsltCache); 056 transformer.transform(new DOMSource(doc), new StreamResult(pageContext.getOut())); 057 } catch (Exception e) { 058 e.printStackTrace(); 059 throw new JspException(e); 060 } 061 return EVAL_PAGE; 062 } 063 064 /** Sets the string attribute <code>query</code>, which is the name of a 065 * query declared using the {@link QueryTag <query>} tag. */ 066 public void setQuery(String newQuery) { 067 query = newQuery; 068 } 069 public String getQuery() { 070 return query; 071 } 072 073 /** Sets the string attribute <code>xsltURI</code>, which is the URI of an 074 * XSL style-sheet to transform query output. */ 075 public void setXsltURI(String newXsltURI) { 076 xsltURI = newXsltURI; 077 } 078 public String getXsltURI() { 079 return xsltURI; 080 } 081 082 /** Sets the boolean attribute <code>xsltCache</code>, which determines 083 * whether to cache the parsed representation of an XSL style-sheet. */ 084 public void setXsltCache(boolean newXsltCache) { 085 xsltCache = newXsltCache; 086 } 087 public boolean isXsltCache() { 088 return xsltCache; 089 } 090 091 private String query; 092 private String xsltURI; 093 private boolean xsltCache; 094 095 096 } 097 098 // End TransformTag.java