defaultdef.java
来自「数据仓库展示程序」· Java 代码 · 共 1,687 行 · 第 1/5 页
JAVA
1,687 行
template.substring(end, template.length());
templateParts = new String[count];
System.arraycopy(ss, 0, templateParts, 0, count);
return;
}
previousEnd = end;
end = template.indexOf('}', start);
if (end == -1) {
// there was a "${" but not '}' in template
String msg = "Bad template \"" +
template +
"\", it had a \"${\", but no '}'";
msgRecorder.reportError(msg);
return;
}
String name = template.substring(start+2, end);
int pos = convertNameToID(name,
templateNames,
msgRecorder);
if (pos == BAD_ID) {
return;
}
poss[count] = pos;
ss[count] = template.substring(previousEnd, start);
start = template.indexOf("${", end);
end++;
count++;
}
} finally {
msgRecorder.popContextName();
}
}
private int convertNameToID(final String name,
final String[] templateNames,
final mondrian.recorder.MessageRecorder msgRecorder) {
if (name == null) {
String msg = "Template name is null";
msgRecorder.reportError(msg);
return BAD_ID;
}
for (int i = 0; i < templateNames.length; i++) {
if (templateNames[i].equals(name)) {
return i;
}
}
String msg = "Bad template name \"" +
name +
"\"";
msgRecorder.reportError(msg);
return BAD_ID;
}
public String getRegex(final String[] names) {
final String space = getSpace();
final String dot = getDot();
final StringBuffer buf = new StringBuffer();
//
// Remember that:
// templateParts.length == templateNamePos.length+1
//
buf.append(templateParts[0]);
for (int i = 0; i < templateNamePos.length; i++) {
String n = names[templateNamePos[i]];
if (n == null) {
// its ok for a name to be null, it just
// eliminates the current regex from consideration
return null;
}
if (space != null) {
n = n.replaceAll(" ", space);
}
if (dot != null) {
n = n.replaceAll("\\.", dot);
}
buf.append(n);
buf.append(templateParts[i+1]);
}
String regex = buf.toString();
if (AggRules.getLogger().isDebugEnabled()) {
StringBuffer bf = new StringBuffer(64);
bf.append(getName());
bf.append(".getRegex:");
bf.append(" for names ");
for (int i = 0; i < names.length; i++) {
bf.append('"');
bf.append(names[i]);
bf.append('"');
if (i+1 < names.length) {
bf.append(", ");
}
}
bf.append(" regex is \"");
bf.append(regex);
bf.append('"');
String msg = bf.toString();
AggRules.getLogger().debug(msg);
}
return regex;
}
protected java.util.regex.Pattern getPattern(final String[] names) {
final String charcase = getCharCase();
if (charcase.equals("ignore")) {
// the case of name does not matter
// since the Pattern will be create to ignore case
final String regex = getRegex(names);
if (regex == null) {
return null;
}
final java.util.regex.Pattern pattern =
java.util.regex.Pattern.compile(regex,
java.util.regex.Pattern.CASE_INSENSITIVE);
return pattern;
} else if (charcase.equals("exact")) {
// the case of name is not changed
// since we are interested in exact case matching
final String regex = getRegex(names);
if (regex == null) {
return null;
}
final java.util.regex.Pattern pattern =
java.util.regex.Pattern.compile(regex);
return pattern;
} else if (charcase.equals("upper")) {
// convert name to upper case
String[] ucNames = new String[names.length];
for (int i = 0; i < names.length; i++) {
String name = names[i];
ucNames[i] = (name == null)
? null: name.toUpperCase();
}
final String regex = getRegex(ucNames);
if (regex == null) {
return null;
}
final java.util.regex.Pattern pattern =
java.util.regex.Pattern.compile(regex);
return pattern;
} else {
// lower
// convert name to lower case
String[] lcNames = new String[names.length];
for (int i = 0; i < names.length; i++) {
String name = names[i];
lcNames[i] = (name == null)
? null: name.toLowerCase();
}
final String regex = getRegex(lcNames);
if (regex == null) {
return null;
}
final java.util.regex.Pattern pattern =
java.util.regex.Pattern.compile(regex);
return pattern;
}
}
// END pass-through code block ---
}
/**
*/
public static abstract class RegexMapper extends Base
{
public RegexMapper()
{
}
public RegexMapper(org.eigenbase.xom.DOMWrapper _def)
throws org.eigenbase.xom.XOMException
{
try {
org.eigenbase.xom.DOMElementParser _parser = new org.eigenbase.xom.DOMElementParser(_def, "", DefaultDef.class);
_parser = _parser;
org.eigenbase.xom.NodeDef[] _tempArray = null;
_tempArray = _tempArray;
id = (String)_parser.getAttribute("id", "String", null, null, true);
enabled = (Boolean)_parser.getAttribute("enabled", "Boolean", "true", null, false);
_tempArray = _parser.getArray(Regex.class, 0, 0);
regexs = new Regex[_tempArray.length];
for(int _i=0; _i<regexs.length; _i++)
regexs[_i] = (Regex)_tempArray[_i];
} catch(org.eigenbase.xom.XOMException _ex) {
throw new org.eigenbase.xom.XOMException("In element '" + getName() + "': " + _ex.getMessage());
}
}
public String id; // required attribute
/**
* This is an array of Regex. A match occurs if any one of
* the Regex matches; it is the equivalent of or-ing the
* regular expressions together. A candidate string is processed
* sequentially by each Regex in their document order until
* one matches. In none match, well, none match.
*/
public Regex[] regexs; //optional array
public String getName()
{
return "RegexMapper";
}
public void display(java.io.PrintWriter _out, int _indent)
{
_out.println(getName());
displayAttribute(_out, "id", id, _indent+1);
displayAttribute(_out, "enabled", enabled, _indent+1);
displayElementArray(_out, "regexs", regexs, _indent+1);
}
public void displayXML(org.eigenbase.xom.XMLOutput _out, int _indent)
{
_out.beginTag("(%RegexMapper;)", new org.eigenbase.xom.XMLAttrVector()
.add("id", id)
.add("enabled", enabled)
);
displayXMLElementArray(_out, regexs);
_out.endTag("(%RegexMapper;)");
}
public boolean displayDiff(org.eigenbase.xom.ElementDef _other, java.io.PrintWriter _out, int _indent)
{
boolean _diff = true;
RegexMapper _cother = (RegexMapper)_other;
_diff = _diff && displayAttributeDiff("id", id, _cother.id, _out, _indent+1);
_diff = _diff && displayElementArrayDiff("regexs", regexs, _cother.regexs, _out, _indent+1);
return _diff;
}
// BEGIN pass-through code block ---
protected String getTag() {
return id;
}
public void validate(final AggRules rules,
final mondrian.recorder.MessageRecorder msgRecorder) {
msgRecorder.pushContextName(getName());
try {
String[] templateNames = getTemplateNames();
for (int i = 0; i < regexs.length; i++) {
Regex regex = regexs[i];
regex.validate(rules, templateNames, msgRecorder);
}
} finally {
msgRecorder.popContextName();
}
}
/**
* This must be defined in derived classes. It returns an array of
* symbolic names that are the symbolic names allowed to appear
* in the regular expression templates.
*
* @return array of symbol names
*/
protected abstract String[] getTemplateNames();
protected Recognizer.Matcher getMatcher(final String[] names) {
final java.util.regex.Pattern[] patterns =
new java.util.regex.Pattern[regexs.length];
for (int i = 0; i < regexs.length; i++) {
Regex regex = regexs[i];
patterns[i] = regex.getPattern(names);
}
return new Recognizer.Matcher() {
public boolean matches(String name) {
for (int i = 0; i < patterns.length; i++) {
java.util.regex.Pattern pattern = patterns[i];
if ((pattern != null) &&
pattern.matcher(name).matches()) {
if (AggRules.getLogger().isDebugEnabled()) {
debug(name, pattern);
}
return true;
}
}
return false;
}
private void debug(String name, java.util.regex.Pattern p) {
StringBuffer bf = new StringBuffer(64);
bf.append("DefaultDef.RegexMapper");
bf.append(".Matcher.matches:");
bf.append(" name ");
bf.append('"');
bf.append(name);
bf.append('"');
bf.append(" matches regex ");
bf.append('"');
bf.append(p.pattern());
bf.append('"');
if ((p.flags() &
java.util.regex.Pattern.CASE_INSENSITIVE) != 0) {
bf.append(" case_insensitive");
}
String msg = bf.toString();
AggRules.getLogger().debug(msg);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?