1 16 17 package org.apache.taglibs.xtags.xpath; 18 19 import java.util.Iterator ; 20 import java.util.List ; 21 22 import javax.servlet.ServletContext ; 23 import javax.servlet.jsp.JspException ; 24 import javax.servlet.jsp.JspWriter ; 25 import javax.servlet.jsp.PageContext ; 26 import javax.servlet.jsp.tagext.TagSupport ; 27 28 import org.dom4j.Node; 29 import org.dom4j.XPath; 30 import org.dom4j.DocumentHelper; 31 import org.dom4j.rule.Stylesheet; 32 33 34 39 public class ApplyTemplatesTag extends AbstractTag { 40 41 42 private String mode; 43 44 45 private XPath xpath; 46 47 48 public ApplyTemplatesTag() { 49 } 50 51 public int doStartTag() throws JspException { 54 return SKIP_BODY; 55 } 56 57 public int doEndTag() throws JspException { 58 flush(); 59 Stylesheet stylesheet = getStylesheet(); 60 if ( stylesheet == null ) { 61 throw new JspException ( 62 "applytemplates tag requires a Stylesheet to be in scope" 63 ); 64 } 65 else { 66 try { 67 TemplateTag templateTag = (TemplateTag) findAncestorWithClass( 70 this, TemplateTag.class 71 ); 72 templateTag.preApplyTemplates(); 73 74 Object context = getInputNodes(); 75 if ( xpath != null ) { 76 stylesheet.applyTemplates( context, xpath ); 77 } 78 else { 79 stylesheet.applyTemplates( context ); 80 } 81 setInputNodes( context ); 83 } 84 catch (JspException e) { 85 throw e; 86 } 87 catch (Exception e) { 88 handleException(e); 89 } 90 } 91 return EVAL_PAGE; 92 } 93 94 public void release() { 95 super.release(); 96 xpath = null; 97 mode = null; 98 } 99 100 103 public void setSelect( String select ) { 104 xpath = createXPath( select ); 105 } 106 107 110 public void setMode(String mode) { 111 this.mode = mode; 112 } 113 } 114 | Popular Tags |