1 16 17 package org.apache.taglibs.gnat; 18 19 import org.apache.taglibs.gnat.util.*; 20 import javax.servlet.jsp.*; 21 import javax.servlet.jsp.tagext.*; 22 import java.io.*; 23 import java.util.*; 24 25 public class echoTag extends TagSupport 26 { 27 private String message=null; 28 private File f = null; private String file = null; private boolean append = false; 31 private ResourceBundle gnatRB = ListResourceBundle.getBundle("org.apache.taglibs.gnat.util.GnatTagStrings"); 32 private ResourceBundle gnatERB = ListResourceBundle.getBundle("org.apache.taglibs.gnat.util.GnatExceptionStrings"); 33 34 public void setMessage(String msg) 35 { 36 this.message = msg; 37 } 38 39 public void setFile(String file) 40 { 41 this.file = file; 42 } 43 44 47 public void setAppend(boolean append) 48 { 49 this.append = append; 50 } 51 52 53 public int doStartTag() throws JspException 54 { 55 if (message == null) 56 { 57 return EVAL_BODY_INCLUDE; 58 } 59 else 60 return SKIP_BODY; 61 } 62 63 66 public int doEndTag() throws JspException 67 { 68 if (file != null) 69 { 70 f = new File(file); 71 72 if (f.isDirectory()) 73 { 74 throw new JspTagException( gnatRB.getString("echo.tag") + ": " + 75 gnatERB.getString("echo.dir.fail") ); 76 } 77 78 FileWriter out = null; 79 try 80 { 81 out = new FileWriter( f.getAbsolutePath(), append ); 82 out.write( message, 0, message.length() ); 83 } 84 catch (IOException ioe) 85 { 86 throw new JspTagException( gnatRB.getString("echo.tag") + ": " + 87 ioe.getMessage() ); 88 } 89 finally 90 { 91 if (out != null) 92 { 93 try 94 { 95 out.close(); 96 } 97 catch (IOException ioex) 98 { 99 throw new JspTagException( gnatRB.getString("echo.tag") + ": " + 100 ioex.getMessage() ); 101 } 102 } 103 } 104 } 105 else if (message != null) 106 { 107 try 108 { 109 pageContext.getOut().write(message); 110 } 111 catch(IOException ioe) 112 { 113 throw new JspTagException( gnatRB.getString("echo.tag") + ": " + 114 ioe.getMessage() ); 115 } 116 } 117 return EVAL_PAGE; 118 } 119 120 123 public String getMessage() { return message; } 124 125 public String getFile() { return file; } 126 127 public boolean getAppend() { return append; } 128 } 129 | Popular Tags |