[Ejtools-cvs] CVS: libraries/xmlweb/src/main/net/sourceforge/ejtools/xml/taglib BeanContextXmlProxyT
Brought to you by:
letiemble
From: Laurent E. <let...@us...> - 2002-04-20 11:42:37
|
Update of /cvsroot/ejtools/libraries/xmlweb/src/main/net/sourceforge/ejtools/xml/taglib In directory usw-pr-cvs1:/tmp/cvs-serv28818 Added Files: BeanContextXmlProxyTag.java XslApplyTag.java Log Message: Initial Import --- NEW FILE: BeanContextXmlProxyTag.java --- package net.sourceforge.ejtools.xml.taglib; import java.beans.beancontext.*; import java.io.*; import java.util.*; import javax.servlet.http.HttpSession; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; import org.w3c.dom.*; import com.sun.xml.tree.*; import net.sourceforge.ejtools.xml.*; import net.sourceforge.ejtools.xml.beans.*; /** * Description of the Class * * @author letiembl * @created 26 février 2002 */ public class BeanContextXmlProxyTag extends TagSupport { /** Description of the Field */ protected String id = null; /** Constructor for the BeanContextXmlProxyTag object */ public BeanContextXmlProxyTag() { } /** * Setter for the id attribute * * @param id The new value for id attribute */ public void setId(String id) { this.id = id; } /** * Getter for the id attribute * * @return The value of id attribute */ public String getId() { return id; } /** * Description of the Method * * @return Description of the Returned Value * @exception JspException Description of Exception */ public int doStartTag() throws JspException { return SKIP_BODY; } /** * Description of the Method * * @return Description of the Returned Value * @exception JspException Description of Exception */ public int doEndTag() throws JspException { try { Object o = null; BeanContextXmlProxy object = null; if ((o = pageContext.getAttribute(id)) != null) { object = (BeanContextXmlProxy) o; } else if ((o = pageContext.getSession().getAttribute(id)) != null) { object = (BeanContextXmlProxy) o; } else if ((o = pageContext.getServletContext().getAttribute(id)) != null) { object = (BeanContextXmlProxy) o; } if (object != null) { XmlDocument doc = new XmlDocument(); XmlComponent comp = object.getXmlProxy(); comp.appendTo(doc); doc.writeXml(new XmlWriteContext(pageContext.getOut(), 3)); } } catch (Exception e) { e.printStackTrace(); } return (EVAL_PAGE); } } --- NEW FILE: XslApplyTag.java --- package net.sourceforge.ejtools.xml.taglib; import java.beans.beancontext.*; import java.io.*; import java.util.*; import javax.servlet.http.HttpSession; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; import javax.xml.transform.*; import javax.xml.transform.stream.*; /** * Description of the Class * * @author letiembl * @created 28 février 2002 */ public class XslApplyTag extends BodyTagSupport { private Transformer transformer = null; /** The body content of this tag */ private String body = null; /** The name of the XSL stylesheet bean. */ private String xsl = null; /** * Setter for the xsl attribute * * @param xsl The new value for xsl attribute */ public void setXsl(String xsl) { this.xsl = xsl; } /** * Getter for the xsl attribute * * @return The value of xsl attribute */ public String getXsl() { return xsl; } /** * Validate the attributes that were specified for consistency. Evaluate the * body content of this tag if we will be using it as the XML data source; * otherwise skip it. * * @return Description of the Returned Value * @exception JspException if a JSP error occurs */ public int doStartTag() throws JspException { try { TransformerFactory tFactory = TransformerFactory.newInstance(); transformer = tFactory.newTransformer(new StreamSource(xsl)); } catch (Exception e) { throw new JspException(e.toString()); } return (EVAL_BODY_TAG); } /** * Save the body content that has been processed, but do not iterate. * * @return Description of the Returned Value * @exception JspException if a JSP error has occurred */ public int doAfterBody() throws JspException { body = bodyContent.getString().trim(); System.out.println(body); return (SKIP_BODY); } /** * Finish up by performing the transformation and rendering the output. * * @return Description of the Returned Value * @exception JspException if a JSP exception occurs */ public int doEndTag() throws JspException { try { // Prepare an input source for the data StreamSource data = new StreamSource(new StringReader(body)); // Prepare an output source for the results StreamResult result = new StreamResult(pageContext.getOut()); transformer.transform(data, result); } catch (Exception e) { throw new JspException(e.toString()); } return (EVAL_PAGE); } /** Release any allocated resources. */ public void release() { this.body = null; } } |