1 18 19 20 package org.apache.struts.taglib.tiles; 21 22 import javax.servlet.jsp.JspException ; 23 import javax.servlet.jsp.tagext.TagSupport ; 24 25 import org.apache.struts.tiles.DefinitionsFactory; 26 import org.apache.struts.tiles.DefinitionsFactoryConfig; 27 import org.apache.struts.tiles.DefinitionsFactoryException; 28 import org.apache.struts.tiles.TilesUtil; 29 30 33 public class InitDefinitionsTag extends TagSupport implements ComponentConstants { 34 35 36 private String filename = null; 37 private String classname = null; 38 39 42 public InitDefinitionsTag() { 43 super(); 44 } 45 46 49 public void release() { 50 51 super.release(); 52 filename = null; 53 } 54 55 58 public void setFile(String name){ 59 this.filename = name; 60 } 61 62 65 public void setClassname(String classname){ 66 this.classname = classname; 67 } 68 69 72 public int doStartTag() throws JspException 73 { 74 DefinitionsFactory factory = TilesUtil.getDefinitionsFactory(pageContext.getRequest(),pageContext.getServletContext()); 75 if(factory != null ) 76 return SKIP_BODY; 77 78 DefinitionsFactoryConfig factoryConfig = new DefinitionsFactoryConfig(); 79 factoryConfig.setFactoryClassname( classname ); 80 factoryConfig.setDefinitionConfigFiles( filename ); 81 82 try 83 { 84 factory = TilesUtil.createDefinitionsFactory(pageContext.getServletContext(), factoryConfig); 85 } 86 catch( DefinitionsFactoryException ex ) 87 { 88 ex.printStackTrace(); 89 throw new JspException ( ex.getMessage() + " See console for details" ); 90 } 91 return SKIP_BODY; 92 } 93 94 97 public int doEndTag() throws JspException { 98 return EVAL_PAGE; 99 } 100 101 } 102 | Popular Tags |