1 56 57 package org.jdom.contrib.input.scanner; 58 59 60 import org.jdom.Element; 61 import org.jdom.JDOMException; 62 import org.jdom.xpath.XPath; 63 64 import org.xml.sax.Attributes ; 65 66 import org.apache.regexp.RE; 67 import org.apache.regexp.RESyntaxException; 68 69 70 class JakartaRegExpXPathMatcher extends XPathMatcher { 71 72 75 private final RE re; 76 77 private final XPath test; 78 79 89 public JakartaRegExpXPathMatcher( 90 String expression, ElementListener listener) 91 throws JDOMException { 92 super(expression, listener); 93 94 try { 95 String pathPattern = getPathPatternAsRE(expression); 96 97 this.re = new RE(pathPattern); 98 99 String testPattern = getTestPattern(expression); 100 if (testPattern != null) { 101 testPattern = "." + testPattern; 102 103 this.test = XPath.newInstance(testPattern); 104 } 105 else { 106 this.test = null; 107 } 108 109 if (isDebug()) { 110 System.out.println("Listener " + listener + ":"); 111 System.out.println(" " + expression + 112 " -> RE = " + pathPattern); 113 System.out.println(" " + expression + 114 " -> XPath = " + testPattern); 115 } 116 } 117 catch (RESyntaxException ex1) { 118 throw (new JDOMException( 119 "Illegal XPath expression: " + expression, ex1)); 120 } 121 } 122 123 139 public boolean match(String path, Attributes attrs) { 140 return (this.re.match(path)); 141 } 142 143 161 public boolean match(String path, Element elt) { 162 if (this.test != null) { 163 boolean match = false; 164 165 try { 166 match = (this.test.selectNodes(elt).size() != 0); 167 } 168 catch (Exception ex1) { 169 ex1.printStackTrace(); 170 } 171 return (match); 172 } 173 else { 174 return (true); 175 } 176 } 177 } 178 179 | Popular Tags |