📄 rulebase.java
字号:
}
for (int i = 0; i < runs.size(); i++) {
final Run run = (Run) runs.get(i);
if (!run.initialise(context)) {
ok = false;
}
if (run.isFilter()) {
log.debug("rule is a filtering rule");
filter = true;
}
}
for (int i = 0; i < setAttributes.size(); i++) {
final SetAttribute setAttribute = (SetAttribute) setAttributes.get(i);
if (!setAttribute.initialise()) {
ok = false;
}
}
// make sure default set for matchType
if (!isMatchTypeWildcard()) {
matchType = DEFAULT_MATCH_TYPE;
}
// compile the from regexp
if (StringUtils.isBlank(from)) {
log.debug("rule's from is blank, setting to " + DEFAULT_RULE_FROM);
from = DEFAULT_RULE_FROM;
}
try {
if (isMatchTypeWildcard()) {
log.debug("rule match type is wildcard");
pattern = new WildcardPattern(from);
} else {
// default is regexp
pattern = new RegexPattern(from, fromCaseSensitive);
}
} catch (StringMatchingPatternSyntaxException e) {
addError("from (" + from + ") is an invalid expression - " + e.getMessage());
}
// set the substitution
if (StringUtils.isBlank(to) && setAttributes.size() == 0 && runs.size() == 0) {
addError("to is not valid because it is blank (it is allowed to be blank when there is a 'set' specified)");
} else if ("null".equalsIgnoreCase(to)) {
stopFilterChainOnMatch = true;
} else if ("-".equals(to)) {
noSubstitution = true;
} else if (StringUtils.isBlank(to)) {
toEmpty = true;
} else if (!StringUtils.isBlank(to)) {
// check for back refs
if (BackReferenceReplacer.containsBackRef(to)) {
toContainsBackReference = true;
}
// look for vars
if (VariableReplacer.containsVariable(to)) {
toContainsVariable = true;
}
// look for functions
if (FunctionReplacer.containsFunction(to)) {
toContainsFunction = true;
}
}
if (ok) {
log.debug("loaded rule " + getFullDisplayName());
} else {
log.debug("failed to load rule");
}
if (errors.size() > 0) {
ok = false;
}
valid = ok;
return ok;
}
public boolean isMatchTypeWildcard() {
return MATCH_TYPE_WILDCARD.equalsIgnoreCase(matchType);
}
public boolean isToContainsBackReference() {
return toContainsBackReference;
}
public boolean isToContainsVariable() {
return toContainsVariable;
}
public boolean isToContainsFunction() {
return toContainsFunction;
}
public String getFullDisplayName() {
return null;
}
protected void addError(String s) {
errors.add(s);
log.error(s);
}
/**
* Destroy the rule gracefully.
*/
public void destroy() {
for (int i = 0; i < runs.size(); i++) {
final Run run = (Run) runs.get(i);
run.destroy();
}
}
/**
* Will get the contents of the from element.
*
* @return the contents of the from element
*/
public String getFrom() {
return from;
}
/**
* Will set from, usually called by Digester.
*
* @param from the url to match from
*/
public void setFrom(final String from) {
this.from = from;
}
/**
* Will set the to, usually called by Digester.
*
* @param to url for redirecting/passing through to
*/
public void setTo(final String to) {
if (!StringUtils.isBlank(to)) {
this.to = to;
}
}
/**
* Set to type. note, it will default to false.
*
* @param lastStr true or false
*/
public void setToLast(final String lastStr) {
last = "true".equalsIgnoreCase(lastStr);
}
/**
* Is this rule last?.
*
* @return boolean
*/
public boolean isLast() {
return last;
}
/**
* Get to.
*
* @return String
*/
public String getTo() {
return to;
}
/**
* Will get the rule's id.
*
* @return int
*/
public int getId() {
return id;
}
/**
* Will get the list of errors.
*
* @return the list of errors
*/
public List getErrors() {
return errors;
}
/**
* Will add the condition to the List.
*
* @param condition The Condition object to add
*/
public void addCondition(final Condition condition) {
conditions.add(condition);
condition.setId(conditionIdCounter++);
}
/**
* Will add the run to the List.
*
* @param run The Run object to add
*/
public void addRun(final Run run) {
runs.add(run);
run.setId(runIdCounter++);
}
/**
* Will add the SetAttribute to the List.
*
* @param setAttribute The SetAttribute object to add
*/
public void addSetAttribute(final SetAttribute setAttribute) {
setAttributes.add(setAttribute);
}
public List getSetAttributes() {
return setAttributes;
}
/**
* Will get the List of conditions.
*
* @return the List of Condition objects
*/
public List getConditions() {
return conditions;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getNote() {
return note;
}
public void setNote(String note) {
this.note = note;
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public void setId(int id) {
this.id = id;
}
public boolean isFromCaseSensitive() {
return fromCaseSensitive;
}
public void setFromCaseSensitive(boolean fromCaseSensitive) {
this.fromCaseSensitive = fromCaseSensitive;
}
public List getRuns() {
return runs;
}
public boolean isValid() {
return valid;
}
public String getMatchType() {
return matchType;
}
public void setMatchType(String matchType) {
matchType = StringUtils.trimToNull(matchType);
if (MATCH_TYPE_WILDCARD.equalsIgnoreCase(matchType)) {
this.matchType = MATCH_TYPE_WILDCARD;
} else {
this.matchType = DEFAULT_MATCH_TYPE;
}
}
public boolean isFilter() {
return filter;
}
public boolean isNoSubstitution() {
return noSubstitution;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -