001 package railo.runtime.tag; 002 003 import java.io.StringReader; 004 005 import org.xml.sax.InputSource; 006 007 import railo.commons.lang.StringUtil; 008 import railo.runtime.exp.PageException; 009 import railo.runtime.ext.tag.BodyTagImpl; 010 import railo.runtime.op.Caster; 011 import railo.runtime.text.xml.XMLCaster; 012 import railo.runtime.text.xml.XMLUtil; 013 014 /** 015 * Creates a XML document object that contains the markup in the tag body. This tag can include XML and CFML tags. Railo processes the CFML code in the tag body, then assigns the resulting text to an XML document object variable. 016 * 017 * 018 * 019 **/ 020 public final class Xml extends BodyTagImpl { 021 022 /** name of an xml variable */ 023 private String variable; 024 private String validator; 025 026 /** yes: maintains the case of document elements and attributes */ 027 private boolean casesensitive; 028 029 private String strXML; 030 031 032 /** 033 * @see javax.servlet.jsp.tagext.Tag#release() 034 */ 035 public void release() { 036 super.release(); 037 variable=null; 038 casesensitive=false; 039 strXML=null; 040 validator=null; 041 } 042 043 /** set the value variable 044 * name of an xml variable 045 * @param variable value to set 046 **/ 047 public void setVariable(String variable) { 048 this.variable=variable; 049 } 050 051 /** set the value casesensitive 052 * yes: maintains the case of document elements and attributes 053 * @param casesensitive value to set 054 **/ 055 public void setCasesensitive(boolean casesensitive) { 056 this.casesensitive=casesensitive; 057 } 058 059 060 /** 061 * @see javax.servlet.jsp.tagext.Tag#doStartTag() 062 */ 063 public int doStartTag() { 064 return EVAL_BODY_BUFFERED; 065 } 066 067 /** 068 * @see javax.servlet.jsp.tagext.Tag#doEndTag() 069 */ 070 public int doEndTag() throws PageException { 071 try { 072 InputSource vis = StringUtil.isEmpty(validator)?null:XMLUtil.toInputSource(pageContext,validator); 073 pageContext.setVariable(variable,XMLCaster.toXMLStruct(XMLUtil.parse(new InputSource(new StringReader(strXML)),vis,false),casesensitive)); 074 } 075 catch (Exception e) { 076 throw Caster.toPageException(e); 077 } 078 079 return EVAL_PAGE; 080 } 081 082 /** 083 * @see javax.servlet.jsp.tagext.BodyTag#doInitBody() 084 */ 085 public void doInitBody() { 086 087 } 088 089 /** 090 * @see javax.servlet.jsp.tagext.BodyTag#doAfterBody() 091 */ 092 public int doAfterBody() { 093 strXML=bodyContent.getString().trim(); 094 return SKIP_BODY; 095 } 096 097 /** 098 * @param validator the validator to set 099 */ 100 public void setValidator(String validator) { 101 this.validator = validator; 102 } 103 }