1 16 17 package org.apache.taglibs.regexp; 18 19 import java.util.*; 20 import org.apache.oro.text.*; 21 import org.apache.oro.text.perl.*; 22 import org.apache.oro.text.regex.*; 23 import javax.servlet.*; 24 import javax.servlet.http.*; 25 import javax.servlet.jsp.*; 26 import javax.servlet.jsp.tagext.*; 27 28 63 64 public class SubstituteTag extends TagSupport 65 { 66 private String regexpid = null; 67 private String textid = null; 68 69 75 public final int doEndTag() throws JspException 76 { 77 TextData td = (TextData)pageContext.getAttribute(textid,PageContext.PAGE_SCOPE); 78 if( td == null ) 79 throw new JspException( 80 "regexp tag substitute could not find text tag with id: " + 81 textid); 82 RegexpData rd = (RegexpData)pageContext.getAttribute(regexpid,PageContext.PAGE_SCOPE); 83 if( rd == null ) 84 throw new JspException( 85 "regexp tag substitute could not find regexp tag with id: " + 86 regexpid); 87 88 Perl5Util perl = new Perl5Util(rd.getPatternCache()); 89 String out = perl.substitute(rd.getRegexp(),td.getText()); 90 91 try { 92 pageContext.getOut().write(out); 93 } catch(Exception e) { 94 throw new JspException("IO Error: " + e.getMessage()); 95 } 96 97 return EVAL_PAGE; 98 } 99 100 105 public final void setRegexp(String str) 106 { 107 regexpid = str; 108 } 109 110 115 public final void setText(String str) 116 { 117 textid = str; 118 } 119 120 } 121 | Popular Tags |