📄 status.java
字号:
final OutboundRule rule = (OutboundRule) outboundRules.get(i);
println("<h3>" + rule.getDisplayName() +
(rule.isEnabled() ? "" : " **DISABLED**") + "</h3>");
if (!StringUtils.isBlank(rule.getNote())) {
println("<dl><dd><p>" + StringUtils.nl2br(rule.getNote()) + "</p></dd></dl>");
}
print("<p>Outbound URL's matching <code>" + rule.getFrom() + "</code>");
if (!StringUtils.isBlank(rule.getTo())) {
print(" will be rewritten to <code>" + rule.getTo() + "</code>");
}
if (!rule.isEncodeFirst()) {
print(", after <code>response.encodeURL()</code> has been called");
}
if (!rule.isEncodeToUrl()) {
print(", <code>response.encodeURL()</code> will not be called");
}
println(".</p>");
showConditions(rule);
showSets(rule);
showRuns(rule);
if (!rule.isLast()) {
println("<p>Note, other outbound rules will be proessed after this rule.</p>");
}
println("</p>");
}
println("<hr />");
}
private void showHeader() {
SimpleDateFormat s = new SimpleDateFormat();
println("<html>");
println("<head>");
println("<title>UrlRewriteFilter configuration overview for " + conf.getFileName() + "</title>");
println("<style>");
InputStream is = Status.class.getResourceAsStream("org/tuckey/web/filters/urlrewrite/doc/doc.css");
if (is == null) {
log.warn("unable to load style sheet");
} else {
try {
for (int i = is.read(); i != -1; i = is.read()) {
buffer.append((char) i);
}
} catch (IOException e) {
// don't care about this too much
}
}
println("</style>");
println("<body>");
println("<h1><a href=\"http://tuckey.org/urlrewrite/\">UrlRewriteFilter</a> " +
UrlRewriteFilter.VERSION + " configuration overview " +
"(generated " + s.format(new Date()) + ")</h1>");
println("<hr />");
}
private void showRunningInfo() {
println("<h2>Running Status</h2>");
if (conf == null) {
println("<h3 class=\"err\">ERROR: UrlRewriteFilter failed to load config, check server log</h3>");
}
if (!conf.isOk()) {
println("<h3 class=\"err\">ERROR: UrlRewriteFilter NOT ACTIVE</h3>");
}
println("<p>Conf file <code>" + conf.getFileName() + "</code> loaded <em>" + conf.getLoadedDate() + "</em>.</p>");
if (urlRewriteFilter != null) {
if (urlRewriteFilter.isConfReloadCheckEnabled()) {
Date nextReloadCheckDate = new Date(urlRewriteFilter.getConfReloadLastCheck().getTime() +
(urlRewriteFilter.getConfReloadCheckInterval() * 1000));
println("<p>Conf file reload check <em>enabled</em>, last modified will be checked every <em>" +
urlRewriteFilter.getConfReloadCheckInterval() + "s</em>, last checked <em>" +
urlRewriteFilter.getConfReloadLastCheck() + "</em>, next check at <em>" +
nextReloadCheckDate + "</em> in <em>" +
Math.round(nextReloadCheckDate.getTime() - System.currentTimeMillis()) / 1000 + "s</em>.");
} else {
println("Conf file reload check <em>disabled</em>");
}
println("<p>Status path <code>" + urlRewriteFilter.getStatusPath() + "</code>.</p>");
}
}
private void displayRuleErrors(final List rules) {
for (int i = 0; i < rules.size(); i++) {
final RuleBase rule = (RuleBase) rules.get(i);
if (rule.isValid()) continue;
println("<li class=\"err\">Error in " + rule.getDisplayName());
println("<ul>");
List ruleErrors = rule.getErrors();
for (int j = 0; j < ruleErrors.size(); j++) {
println("<li class=\"err\">" + ruleErrors.get(j) + "</li>");
}
List conditions = rule.getConditions();
for (int j = 0; j < conditions.size(); j++) {
Condition condition = (Condition) conditions.get(j);
if (condition.getError() == null) continue;
println("<li class=\"err\">" + condition.getDisplayName() + " " + condition.getError() + "</li>");
}
List sets = rule.getSetAttributes();
for (int j = 0; j < sets.size(); j++) {
SetAttribute setAttribute = (SetAttribute) sets.get(j);
if (setAttribute.getError() == null) continue;
println("<li class=\"err\">" + setAttribute.getDisplayName() + " " + setAttribute.getError() + "</li>");
}
List runs = rule.getRuns();
for (int j = 0; j < runs.size(); j++) {
Run run = (Run) runs.get(j);
if (run.getError() == null) continue;
println("<li class=\"err\">" + run.getDisplayName() + " " + run.getError() + "</li>");
}
println("</ul></li>");
}
}
private void showSets(final RuleBase rule) {
if (rule.getSetAttributes().size() == 0) return;
List setAttributes = rule.getSetAttributes();
println("<p>This rule will set:</p>" +
"<ol>");
for (int j = 0; j < setAttributes.size(); j++) {
SetAttribute setAttribute = (SetAttribute) setAttributes.get(j);
println("<li>");
if ("response-header".equals(setAttribute.getType())) {
println("The <code>" + setAttribute.getName() + "</code> HTTP response header " +
"to <code>" + setAttribute.getValue() + "</code>");
} else if ("request".equals(setAttribute.getType()) ||
"session".equals(setAttribute.getType())) {
println("An attribute on the <code>" + setAttribute.getType() + "</code> object " +
"called <code>" + setAttribute.getName() + "</code> " +
"to the value " +
"<code>" + setAttribute.getValue() + "</code>");
} else if ("cookie".equals(setAttribute.getType())) {
println("A cookie " +
"called <code>" + setAttribute.getName() + "</code> " +
" to the value " +
"<code>" + setAttribute.getValue() + "</code>");
} else if ("locale".equals(setAttribute.getType())) {
println("locale to " +
"<code>" + setAttribute.getValue() + "</code>");
} else if ("status".equals(setAttribute.getType())) {
println("status to " +
"<code>" + setAttribute.getValue() + "</code>");
} else if ("content-type".equals(setAttribute.getType())) {
println("content-type to " +
"<code>" + setAttribute.getValue() + "</code>");
} else if ("charset".equals(setAttribute.getType())) {
println("charset to " +
"<code>" + setAttribute.getValue() + "</code>");
}
println("</li>");
}
println("</ol>");
}
private void showRuns(RuleBase rule) {
List runs = rule.getRuns();
if (runs.size() == 0) return;
println("<p>This rule will run:</p>" +
"<ol>");
for (int j = 0; j < runs.size(); j++) {
Run run = (Run) runs.get(j);
println("<li>");
println(" <code>" + run.getMethodStr() + "(HttpServletRequest, HttpServletResponse)</code> on an instance " +
"of " + "<code>" + run.getClassStr() + "</code>");
if (run.isNewEachTime()) {
println(" (a new instance will be created for each rule match)");
}
println("</li>");
}
println("</ol>");
println("<small>Note, if <code>init(ServletConfig)</code> or <code>destroy()</code> is found on the above " +
"object" + (runs.size() > 1 ? "s" : "") + " they will be run at when creating or destroying an instance.</small>");
}
private void showConditions(RuleBase rule) {
List conditions = rule.getConditions();
if (conditions.size() == 0) return;
println("<p>Given that the following condtion" +
(conditions.size() == 1 ? " is" : "s are") + " met.</p>" +
"<ol>");
for (int j = 0; j < conditions.size(); j++) {
Condition condition = (Condition) conditions.get(j);
println("<li>");
if ("header".equals(condition.getType())) {
println("The <code>" + condition.getName() + "</code> HTTP header " +
("notequal".equals(condition.getOperator()) ? "does NOT match" : "matches") + " the value " +
"<code>" + condition.getValue() + "</code>");
} else {
println("<code>" + condition.getType() + "</code> is <code>" +
("greater".equals(condition.getOperator()) ? "greater than" : "") +
("less".equals(condition.getOperator()) ? "less than" : "") +
("equal".equals(condition.getOperator()) ? "equal to" : "") +
("notequal".equals(condition.getOperator()) ? "NOT equal to" : "") +
("greaterorequal".equals(condition.getOperator()) ? "is greater than or equal to" : "") +
("lessorequal".equals(condition.getOperator()) ? "is less than or equal to" : "") +
"</code> the value <code>" +
(StringUtils.isBlank(condition.getValue()) ? condition.getName() : condition.getValue()) + "</code>");
}
if (j < conditions.size() - 1) {
println("<code>" + condition.getNext() + "</code>");
}
println("</li>");
}
println("</ol>");
}
private void showFooter() {
println("<br /><br /><br />");
println("</body>");
println("</html>");
}
private void print(String s) {
buffer.append(s);
}
private void println(String s) {
buffer.append(s);
buffer.append("\n");
}
public StringBuffer getBuffer() {
return buffer;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -