1 23 24 package org.enhydra.xml.xmlc.metadata; 25 26 import gnu.regexp.RE; 27 import gnu.regexp.REException; 28 import gnu.regexp.RESyntax; 29 30 import org.enhydra.xml.xmlc.XMLCException; 31 import org.w3c.dom.Document ; 32 33 36 public class URLRegExpMapping extends URLEdit { 37 40 public static final String TAG_NAME = "urlRegExpMapping"; 41 42 45 private RE regExp; 46 47 50 private String substitution; 51 52 55 public URLRegExpMapping(Document ownerDoc) { 56 super(ownerDoc, TAG_NAME); 57 } 58 59 62 private static final String REGEXP_ATTR = "regexp"; 63 private static final String SUBST_ATTR = "subst"; 64 65 68 public String getRegexp() { 69 return getAttributeNull(REGEXP_ATTR); 70 } 71 72 75 public void setRegexp(String value) { 76 setRemoveAttribute(REGEXP_ATTR, value); 77 } 78 79 82 public String getSubst() { 83 return getAttributeNull(SUBST_ATTR); 84 } 85 86 89 public void setSubst(String value) { 90 setRemoveAttribute(SUBST_ATTR, value); 91 } 92 93 97 protected void completeModifications() throws XMLCException { 98 super.completeModifications(); 99 substitution = getSubst(); 100 101 String regExpStr = getRegexp(); 102 if (regExpStr == null) { 103 regExp = null; 104 } else { 105 try { 106 regExp = new RE(regExpStr, 0, 107 RESyntax.RE_SYNTAX_POSIX_EXTENDED); 108 } catch (REException except) { 109 throw new XMLCException("invalid URL mapping regular expression: " 110 + except.toString(), 111 except); 112 } 113 114 } 115 } 116 117 122 public String mapURL(String url) throws XMLCException { 123 if (regExp.getMatch(url) == null) { 124 return null; 125 } 126 return regExp.substituteAll(url, substitution); 127 } 128 129 } 130 | Popular Tags |