📄 coreutil.java
字号:
return session.getAttribute(Constants.WIZARD_SEQUENCE) != null;
}
/**
* Check whether the session has a VPN client running
*
* @param session session
* @return has a vpn client
*/
public static boolean isVPNClientAvailable(HttpSession session) {
return CoreServlet.getServlet().getLogonController().getPrimaryVPNSession(
CoreServlet.getServlet().getLogonController().getVPNSessionsByLogon(
(String) session.getAttribute(Constants.LOGON_TICKET))) != null;
}
/**
* Reset the main navigation menu so it gets rebuilt upon the next request
*
* @param request request
*/
public static void resetMainNavigation(HttpSession session) {
session.removeAttribute(Constants.MENU_TREE);
session.removeAttribute(Constants.NAV_BAR);
}
/**
* Get if the menu is currently available. This is often used to determine
* if the user is on a page that cannot be safely navigated away from.
*
* @param session
* @return menu is available
*/
public static boolean isMenuAvailable(HttpServletRequest request) {
return request.getAttribute(Constants.SELECTED_MENU) != null
&& request.getSession().getAttribute(Constants.PAGE_INTERCEPTED) == null;
}
public static void addRequiredFieldMessage(Action action, HttpServletRequest request) {
ActionMessages mesgs = (ActionMessages) request.getAttribute(Globals.MESSAGE_KEY);
if (mesgs == null) {
mesgs = new ActionMessages();
request.setAttribute(Globals.MESSAGE_KEY, mesgs);
}
mesgs.add(Globals.MESSAGE_KEY, new BundleActionMessage("navigation", "info.requiredFieldIndicator", "<img src=\""
+ getThemePath(request.getSession()) + "/images/required.gif" + "\" border=\"0\"/>"));
}
static Replacer createGlobalReplacer() {
return new Replacer() {
public String getReplacement(Pattern pattern, Matcher matcher, String replacementPattern) {
String match = matcher.group();
String key = match.substring(2, match.length() - 1);
try {
int idx = key.indexOf(":");
if (idx == -1) {
throw new Exception("String replacement pattern is in incorrect format for " + key
+ ". Must be <TYPE>:<key>");
}
String type = key.substring(0, idx);
key = key.substring(idx + 1);
if (log.isDebugEnabled())
log.debug("Found replacement variable " + type + ":" + key);
if (type.equalsIgnoreCase(KeyStoreManager.DEFAULT_KEY_STORE)) {
if (key.equals("untrustedCertificate")) {
return String
.valueOf(!KeyStoreManager.getInstance(KeyStoreManager.DEFAULT_KEY_STORE)
.isCertificateTrusted(
ContextHolder.getContext().getContextProperty("webServer.alias")));
} else {
throw new Exception("Unknown key " + key + " for type " + type + ".");
}
} else if (type.equalsIgnoreCase("server")) {
// NOTE 29/1/06 - BPS - This is here to maintain
// compatibility with current extension descriptors
if (key.equals("untrustedCertificate")) {
return String
.valueOf(!KeyStoreManager.getInstance(KeyStoreManager.DEFAULT_KEY_STORE)
.isCertificateTrusted(
ContextHolder.getContext().getContextProperty("webServer.alias")));
} else {
throw new Exception("Unknown key " + key + " for type " + type + ".");
}
} else if (type.equalsIgnoreCase("context")) {
if (key.equals("conf.dir")) {
return ContextHolder.getContext().getConfDirectory().getAbsolutePath();
} else if (key.equals("log.dir")) {
return ContextHolder.getContext().getLogDirectory().getAbsolutePath();
} else if (key.equals("db.dir")) {
return ContextHolder.getContext().getDBDirectory().getAbsolutePath();
} else if (key.equals("temp.dir")) {
return ContextHolder.getContext().getTempDirectory().getAbsolutePath();
} else if (key.equals("version")) {
return ContextHolder.getContext().getVersion().toString();
} else {
throw new Exception("Unknown key " + key + " for type " + type + ".");
}
}
} catch (Exception e) {
log.error("A replacement failed for " + key + ".", e);
}
return null;
}
};
}
public static String doStandardReplacements(final ExtensionBundle bundle, final String input) {
if (log.isDebugEnabled())
log.debug("Doing standard replacements from bundle " + bundle.getId() + " input = '" + input + "'");
ReplacementEngine engine = new ReplacementEngine();
engine.addPattern("\\$\\{[^}]*\\}", createGlobalReplacer(), null);
engine.addPattern("\\$\\{[^}]*\\}", new Replacer() {
public String getReplacement(Pattern pattern, Matcher matcher, String replacementPattern) {
String match = matcher.group();
String key = match.substring(2, match.length() - 1);
try {
int idx = key.indexOf(":");
if (idx == -1) {
throw new Exception("String replacement pattern is in incorrect format for " + key
+ ". Must be <TYPE>:<key>");
}
String type = key.substring(0, idx);
key = key.substring(idx + 1);
if (log.isDebugEnabled())
log.debug("Found replacement variable " + type + ":" + key);
if (type.equalsIgnoreCase("bundle")) {
if (bundle == null) {
return null;
}
if (key.equals("id")) {
return bundle.getId();
} else if (key.equals("name")) {
return bundle.getName();
} else if (key.equals("description")) {
return bundle.getDescription();
} else if (key.equals("baseDir")) {
if (log.isDebugEnabled())
log.debug("Replacing base dir with " + bundle.getBaseDir().getCanonicalPath());
return bundle.getBaseDir().getCanonicalPath();
} else {
throw new Exception("Unknown key " + key + " for type " + type + ".");
}
}
} catch (Exception e) {
log.error("A replacement failed for " + key + ".", e);
}
return null;
}
}, null);
return engine.replace(input);
}
public static String doStandardReplacements(final ExtensionDescriptor application, final Map parameters, String input) {
ReplacementEngine engine = new ReplacementEngine();
engine.addPattern("\\$\\{[^}]*\\}", createGlobalReplacer(), null);
engine.addPattern("\\$\\{[^}]*\\}", new Replacer() {
public String getReplacement(Pattern pattern, Matcher matcher, String replacementPattern) {
String match = matcher.group();
String key = match.substring(2, match.length() - 1);
try {
int idx = key.indexOf(":");
if (idx == -1) {
throw new Exception("String replacement pattern is in incorrect format for " + key
+ ". Must be <TYPE>:<key>");
}
String type = key.substring(0, idx);
key = key.substring(idx + 1);
if (log.isDebugEnabled())
log.debug("Found replacement variable " + type + ":" + key);
if (type.equalsIgnoreCase("shortcut")) {
if (parameters == null) {
return null;
}
String val = (String) parameters.get(key);
if (val == null) {
throw new Exception("Unknown key " + key + " for type " + type + ".");
}
return val;
} else if (type.equalsIgnoreCase("application")) {
if (application == null) {
return null;
}
if (key.equals("id")) {
return application.getId();
} else if (key.equals("name")) {
return application.getName();
} else if (key.equals("description")) {
return application.getDescription();
} else if (key.equals("path")) {
return "/fs/apps/" + application.getApplicationBundle().getId();
} else {
throw new Exception("Unknown key " + key + " for type " + type + ".");
}
}
} catch (Exception e) {
log.error("A replacement failed for " + key + ".", e);
}
return null;
}
}, null);
return engine.replace(input);
}
public static String doStandardReplacements(final HttpServletRequest request, String input) {
ReplacementEngine engine = new ReplacementEngine();
engine.addPattern("\\$\\{[^}]*\\}", createGlobalReplacer(), null);
engine.addPattern("\\$\\{[^}]*\\}", new Replacer() {
public String getReplacement(Pattern pattern, Matcher matcher, String replacementPattern) {
String match = matcher.group();
String key = match.substring(2, match.length() - 1);
try {
int idx = key.indexOf(":");
if (idx == -1) {
throw new Exception("String replacement pattern is in incorrect format for " + key
+ ". Must be <TYPE>:<key>");
}
String type = key.substring(0, idx);
key = key.substring(idx + 1);
if (log.isDebugEnabled())
log.debug("Found replacement variable " + type + ":" + key);
if (type.equalsIgnoreCase("request")) {
if (request == null) {
return null;
} else if (key.equals("serverName")) {
return request.getServerName();
} else if (key.equals("serverPort")) {
return String.valueOf(request.getServerPort());
} else if (key.startsWith("param.")) {
return request.getParameter(key.substring(6));
} else if (key.startsWith("attr.")) {
return request.getAttribute(key.substring(5)).toString();
} else if (key.equals("userAgent")) {
return request.getHeader("User-Agent");
}
}
} catch (Exception e) {
log.error("A replacement failed for " + key + ".", e);
}
return null;
}
}, null);
return engine.replace(input);
}
public static String doStandardReplacements(final String username, final String input) {
if (username == null || username.equals("")) {
return input;
}
ReplacementEngine engine = new ReplacementEngine();
engine.addPattern("\\$\\{[^}]*\\}", createGlobalReplacer(), null);
engine.addPattern("\\$\\{[^}]*\\}", new Replacer() {
public String getReplacement(Pattern pattern, Matcher matcher, String replacementPattern) {
String match = matcher.group();
String key = match.substring(2, match.length() - 1);
try {
int idx = key.indexOf(":");
if (idx == -1) {
throw new Exception("String replacement pattern is in incorrect format for " + key
+ ". Must be <TYPE>:<key>");
}
String type = key.substring(0, idx);
key = key.substring(idx + 1);
if (log.isDebugEnabled())
log.debug("Found replacement variable " + type + ":" + key);
if (type.equalsIgnoreCase("attr")) {
UserAttributeDefinition def = CoreServlet.getServlet().getUserDatabase().getUserAttributeDefinition(key);
if (def == null) {
log.warn("Invalid user attribute '" + key + "'");
return null;
} else {
User u = CoreServlet.getServlet().getUserDatabase().getAccount(username);
return u.getAttributes().getProperty(key, def.getDefaultValue());
}
}
} catch (Exception e) {
log.error("A replacement failed for " + key + ".", e);
}
return null;
}
}, null);
return engine.replace(input);
}
public static String doStandardReplacements(final SessionInfo sessionInfo, final String input) {
return doStandardReplacements(sessionInfo, input, null);
}
public static String doStandardReplacements(final SessionInfo sessionInfo, final String input, ReplacementEngine.Encoder encoder) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -