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