| Method from org.apache.commons.digester.RulesBase Detail: |
public void add(String pattern,
Rule rule) {
// to help users who accidently add '/' to the end of their patterns
int patternLength = pattern.length();
if (patternLength >1 && pattern.endsWith("/")) {
pattern = pattern.substring(0, patternLength-1);
}
List list = (List) cache.get(pattern);
if (list == null) {
list = new ArrayList();
cache.put(pattern, list);
}
list.add(rule);
rules.add(rule);
if (this.digester != null) {
rule.setDigester(this.digester);
}
if (this.namespaceURI != null) {
rule.setNamespaceURI(this.namespaceURI);
}
}
Register a new Rule instance matching the specified pattern. |
public void clear() {
cache.clear();
rules.clear();
}
Clear all existing Rule instance registrations. |
public Digester getDigester() {
// ------------------------------------------------------------- Properties
return (this.digester);
}
Return the Digester instance with which this Rules instance is
associated. |
public String getNamespaceURI() {
return (this.namespaceURI);
}
Return the namespace URI that will be applied to all subsequently
added Rule objects. |
protected List lookup(String namespaceURI,
String pattern) {
// Optimize when no namespace URI is specified
List list = (List) this.cache.get(pattern);
if (list == null) {
return (null);
}
if ((namespaceURI == null) || (namespaceURI.length() == 0)) {
return (list);
}
// Select only Rules that match on the specified namespace URI
ArrayList results = new ArrayList();
Iterator items = list.iterator();
while (items.hasNext()) {
Rule item = (Rule) items.next();
if ((namespaceURI.equals(item.getNamespaceURI())) ||
(item.getNamespaceURI() == null)) {
results.add(item);
}
}
return (results);
}
Return a List of Rule instances for the specified pattern that also
match the specified namespace URI (if any). If there are no such
rules, return null. |
public List match(String pattern) {
return (match(null, pattern));
} Deprecated! Call - match(namespaceURI,pattern) instead.
Return a List of all registered Rule instances that match the specified
nesting pattern, or a zero-length List if there are no matches. If more
than one Rule instance matches, they must be returned
in the order originally registered through the add()
method. |
public List match(String namespaceURI,
String pattern) {
// List rulesList = (List) this.cache.get(pattern);
List rulesList = lookup(namespaceURI, pattern);
if ((rulesList == null) || (rulesList.size() < 1)) {
// Find the longest key, ie more discriminant
String longKey = "";
Iterator keys = this.cache.keySet().iterator();
while (keys.hasNext()) {
String key = (String) keys.next();
if (key.startsWith("*/")) {
if (pattern.equals(key.substring(2)) ||
pattern.endsWith(key.substring(1))) {
if (key.length() > longKey.length()) {
// rulesList = (List) this.cache.get(key);
rulesList = lookup(namespaceURI, key);
longKey = key;
}
}
}
}
}
if (rulesList == null) {
rulesList = new ArrayList();
}
return (rulesList);
}
Return a List of all registered Rule instances that match the specified
nesting pattern, or a zero-length List if there are no matches. If more
than one Rule instance matches, they must be returned
in the order originally registered through the add()
method. |
public List rules() {
return (this.rules);
}
Return a List of all registered Rule instances, or a zero-length List
if there are no registered Rule instances. If more than one Rule
instance has been registered, they must be returned
in the order originally registered through the add()
method. |
public void setDigester(Digester digester) {
this.digester = digester;
Iterator items = rules.iterator();
while (items.hasNext()) {
Rule item = (Rule) items.next();
item.setDigester(digester);
}
}
Set the Digester instance with which this Rules instance is associated. |
public void setNamespaceURI(String namespaceURI) {
this.namespaceURI = namespaceURI;
}
Set the namespace URI that will be applied to all subsequently
added Rule objects. |