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 51 52 public class RegexpTag extends BodyTagSupport 53 { 54 private String regexptext = null; 56 57 62 public final int doStartTag() throws JspException 63 { 64 return EVAL_BODY_TAG; 65 } 66 67 72 public final int doAfterBody() throws JspException 73 { 74 BodyContent body = getBodyContent(); 76 regexptext = body.getString().trim(); 77 body.clearBody(); 80 81 if( regexptext == null || regexptext.length() <= 0 ) 83 throw new JspException( 84 "regexp tag regexp could not find a regular expresion in body of tag."); 85 86 RegexpData rd = new RegexpData(regexptext); 88 PatternCacheLRU regexp = RegexpData.getPatternCache(); 89 try { 90 regexp.addPattern(regexptext, 91 Perl5Compiler.MULTILINE_MASK|Perl5Compiler.READ_ONLY_MASK); 92 } catch(MalformedPatternException e) { 93 throw new JspException("regexp tag regexp, malformed pattern \"" + 94 regexptext + "\" " + e.getMessage()); 95 } 96 97 pageContext.setAttribute(id,rd,PageContext.PAGE_SCOPE); 98 return SKIP_BODY; 99 } 100 } 101 | Popular Tags |