1 package net.sf.saxon.functions; 2 3 import net.sf.saxon.Configuration; 4 import net.sf.saxon.om.Validation; 5 import net.sf.saxon.trans.XPathException; 6 import org.xml.sax.XMLReader ; 7 8 import java.io.File ; 9 import java.io.FilenameFilter ; 10 import java.util.StringTokenizer ; 11 import java.util.regex.Pattern ; 12 13 16 17 public class URIQueryParameters { 18 19 FilenameFilter filter = null; 20 Boolean recurse = null; 21 Integer validation = null; 22 Boolean strip = null; 23 Integer onError = null; 24 XMLReader parser = null; 25 26 public static final int ON_ERROR_FAIL = 1; 27 public static final int ON_ERROR_WARNING = 2; 28 public static final int ON_ERROR_IGNORE = 3; 29 30 public URIQueryParameters(String query, Configuration config) { 31 if (query != null) { 32 StringTokenizer t = new StringTokenizer (query, ";&"); 33 while (t.hasMoreTokens()) { 34 String tok = t.nextToken(); 35 int eq = tok.indexOf('='); 36 if (eq > 0 && eq < (tok.length()-1)) { 37 String keyword = tok.substring(0, eq); 38 String value = tok.substring(eq+1); 39 40 if (keyword.equals("select")) { 41 String s = '^' + value + '$'; 42 s = s.replaceAll("\\.", "\\\\."); 45 s = s.replaceAll("\\*", ".*"); 48 Pattern pattern = Pattern.compile(s); 49 filter = new RegexFilter(pattern); 50 } else if (keyword.equals("recurse")) { 51 recurse = Boolean.valueOf("yes".equals(value)); 52 } else if (keyword.equals("validation")) { 53 int v = Validation.getCode(value); 54 if (v != Validation.INVALID) { 55 validation = new Integer (v); 56 } 57 } else if (keyword.equals("strip-space")) { 58 strip = Boolean.valueOf("yes".equals(value)); 59 } else if (keyword.equals("on-error")) { 60 if (value.equals("warning")) { 61 onError = new Integer (ON_ERROR_WARNING); 62 } else if (value.equals("ignore")) { 63 onError = new Integer (ON_ERROR_IGNORE); 64 } else if (value.equals("fail")) { 65 onError = new Integer (ON_ERROR_FAIL); 66 } 67 } else if (tok.startsWith("parser=")) { 68 String p = tok.substring(7); 69 try { 70 if (config == null) { 71 config = new Configuration(); 72 } 73 parser = (XMLReader )config.getInstance(p, null); 74 } catch (XPathException err) { 75 } 77 } 78 } 79 } 80 } 81 82 } 83 84 87 88 public Boolean getStripSpace() { 89 return strip; 90 } 91 92 95 96 public Integer getValidationMode() { 97 return validation; 98 } 99 100 103 104 public FilenameFilter getFilenameFilter() { 105 return filter; 106 } 107 108 111 112 public Boolean getRecurse() { 113 return recurse; 114 } 115 116 119 120 public Integer getOnError() { 121 return onError; 122 } 123 124 127 128 public XMLReader getXMLReader() { 129 return parser; 130 } 131 132 public static class RegexFilter implements FilenameFilter { 133 134 private Pattern pattern; 135 136 public RegexFilter(Pattern regex) { 137 this.pattern = regex; 138 } 139 140 148 149 public boolean accept(File dir, String name) { 150 return new File (dir, name).isDirectory() || pattern.matcher(name).matches(); 151 } 152 } 153 } 154 155 173 | Popular Tags |