📄 confighelper.java
字号:
* otherwise return <code>null</code>.
*
* @param path Request path for which a mapping is requested
*/
public ActionMapping getActionMapping(String path) {
ActionMappings mappings = getActionMappings();
if (mappings == null)
return null;
return mappings.findMapping(path);
}
/**
* Return the form action converted into an action mapping path. The
* value of the <code>action</code> property is manipulated as follows in
* computing the name of the requested mapping:
* <ul>
* <li>Any filename extension is removed (on the theory that extension
* mapping is being used to select the controller servlet).</li>
* <li>If the resulting value does not start with a slash, then a
* slash is prepended.</li>
* </ul>
*/
public String getActionMappingName(String action) {
String value = action;
int question = action.indexOf("?");
if (question >= 0)
value = value.substring(0, question);
int slash = value.lastIndexOf("/");
int period = value.lastIndexOf(".");
if ((period >= 0) && (period > slash))
value = value.substring(0, period);
if (value.startsWith("/"))
return (value);
else
return ("/" + value);
}
/**
* Return the form action converted into a server-relative URL.
*/
public String getActionMappingURL(String action) {
StringBuffer value = new StringBuffer(this.request.getContextPath());
// Use our servlet mapping, if one is specified
String servletMapping = getServletMapping();
if (servletMapping != null) {
String queryString = null;
int question = action.indexOf("?");
if (question >= 0)
queryString = action.substring(question);
String actionMapping = getActionMappingName(action);
if (servletMapping.startsWith("*.")) {
value.append(actionMapping);
value.append(servletMapping.substring(1));
} else if (servletMapping.endsWith("/*")) {
value.append(servletMapping.substring(0, servletMapping.length() - 2));
value.append(actionMapping);
}
if (queryString != null)
value.append(queryString);
}
// Otherwise, assume extension mapping is in use and extension is
// already included in the action property
else {
if (!action.startsWith("/"))
value.append("/");
value.append(action);
}
// Return the completed value
return (value.toString());
}
/**
* Return the url encoded to maintain the user session, if any.
*/
public String getEncodeURL(String url) {
if ((session != null) && (response != null)) {
boolean redirect = false;
if (forward != null)
redirect = forward.getRedirect();
if (redirect)
return response.encodeRedirectURL(url);
else
return response.encodeURL(url);
} else
return (url);
}
// ------------------------------------------------ Presentation API
/**
* Renders the reference for a HTML <base> element
*/
public String getOrigRef() {
// HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();
if (request == null)
return null;
StringBuffer result = new StringBuffer();
result.append(request.getScheme());
result.append("://");
result.append(request.getServerName());
if ("http".equals(request.getScheme()) && (80 == request.getServerPort())) {
;
} else if ("https".equals(request.getScheme()) && (443 == request.getServerPort())) {
;
} else {
result.append(":");
result.append(request.getServerPort());
}
result.append(request.getRequestURI());
return result.toString();
}
/**
* Renders the reference for a HTML <base> element.
*/
public String getBaseRef() {
if (request == null)
return null;
StringBuffer result = new StringBuffer();
result.append(request.getScheme());
result.append("://");
result.append(request.getServerName());
if ("http".equals(request.getScheme()) && (80 == request.getServerPort())) {
;
} else if ("https".equals(request.getScheme()) && (443 == request.getServerPort())) {
;
} else {
result.append(":");
result.append(request.getServerPort());
}
String path = null;
if (forward == null)
path = request.getRequestURI();
else
path = request.getContextPath() + forward.getPath();
result.append(path);
return result.toString();
}
/**
* Return the path for the specified forward,
* otherwise return <code>null</code>.
*
* @param name Name given to local or global forward.
*/
public String getLink(String name) {
ActionForward forward = getActionForward(name);
if (forward == null)
return null;
StringBuffer path = new StringBuffer(this.request.getContextPath());
path.append(forward.getPath());
// :TODO: What about runtime parameters?
return getEncodeURL(path.toString());
}
/**
* Return the localized message for the specified key,
* otherwise return <code>null</code>.
*
* @param key Message key
*/
public String getMessage(String key) {
MessageResources resources = getMessageResources();
if (resources == null)
return null;
return resources.getMessage(getLocale(), key);
}
/**
* Look up and return a message string, based on the specified parameters.
*
* @param key Message key to be looked up and returned
* @param args Replacement parameters for this message
*/
public String getMessage(String key, Object args[]) {
MessageResources resources = getMessageResources();
if (resources == null)
return null;
// Return the requested message
if (args == null)
return (resources.getMessage(getLocale(), key));
else
return (resources.getMessage(getLocale(), key, args));
}
/**
* Return the URL for the specified ActionMapping,
* otherwise return <code>null</code>.
*
* @param path Name given to local or global forward.
*/
public String getAction(String path) {
return getEncodeURL(getActionMappingURL(path));
}
/**
* Return the number of error messages.
*/
public int getErrorSize() {
ActionErrors actionErrors = getActionErrors();
if (actionErrors == null)
return 0;
return actionErrors.size();
}
/**
* Return true if there are no errors queued
*/
public boolean getErrorsEmpty() {
ActionErrors actionErrors = getActionErrors();
if (actionErrors == null)
return false;
return actionErrors.isEmpty();
}
/**
* Return the error messages
*/
public Iterator getErrors() {
ActionErrors actionErrors = getActionErrors();
if (actionErrors == null)
return null;
return actionErrors.get();
}
/**
* Return an ActionError for a property
*
* @param property Property name
*/
public Iterator getErrors(String property) {
ActionErrors actionErrors = getActionErrors();
if (actionErrors == null)
return null;
return actionErrors.get(property);
}
/**
* Return the number of error messages.
*
* @param property Property name
*/
public int getErrorSize(String property) {
ActionErrors actionErrors = getActionErrors();
if (actionErrors == null)
return 0;
return actionErrors.size(property);
}
/**
* Returns the errors.header, any errors, and the errors.footer.
*
* @param property Property name
*/
public String getErrorOutput(String property) {
ActionErrors errors = getActionErrors();
if ((errors == null) || (errors.isEmpty())) {
return null;
}
// Check for presence of header and footer message keys
boolean headerPresent = isMessage("errors.header");
boolean footerPresent = isMessage("errors.footer");
// Render the error messages appropriately
StringBuffer results = new StringBuffer();
String message = null;
if (headerPresent)
message = getMessage("errors.header");
Iterator reports = null;
if (property == null)
reports = errors.get();
else
reports = errors.get(property);
// Render header if this is a global tag or there is an error for this property
boolean propertyMsgPresent = reports.hasNext();
if ((message != null) && (property == null) || propertyMsgPresent) {
results.append(message);
results.append("\r\n");
}
while (reports.hasNext()) {
ActionError report = (ActionError) reports.next();
message = getMessage(report.getKey(), report.getValues());
if (message != null) {
results.append(message);
results.append("\r\n");
}
}
message = null;
if (footerPresent)
message = getMessage("errors.footer");
if ((message != null) && (property == null) || propertyMsgPresent) {
results.append(message);
results.append("\r\n");
}
// return result
return results.toString();
}
/**
* Wrapper for getErrorMarkup(null)
*/
public String getErrorOutput() {
return getErrorOutput(null);
}
// --------------------------------------------- Presentation Wrappers
/**
* Wrapper for getLink(String)
*
* @param name Name given to local or global forward.
*/
public String link(String name) {
return getLink(name);
}
/**
* Wrapper for getMessage(String)
*
* @param key Message key
*/
public String message(String key) {
return getMessage(key);
}
/**
* Wrapper for getMessage(String,Object[])
*
* @param key Message key to be looked up and returned
* @param args Replacement parameters for this message
*/
public String message(String key, Object args[]) {
return getMessage(key, args);
}
/**
* Wrapper for getAction(String)
*
* @param path Name given to local or global forward.
*/
public String action(String path) {
return getAction(path);
}
/**
* Alias for getErrorSize()
*/
public int errorSize() {
return getErrorSize();
}
/**
* Wrapper for getErrorEmpty()
*/
public boolean errorsEmpty() {
return getErrorsEmpty();
}
/**
* Wrapper for getErrors()
*/
public Iterator errors() {
return errors();
}
/**
* Wrapper for getErrors(String)
*/
public Iterator errors(String property) {
return getErrors(property);
}
/**
* Wrapper for getErrorSize(String)
*
* @param property Property name
*/
public int errorSize(String property) {
return getErrorSize(property);
}
/**
* Wrapper for getErrorMarkup(String)
*/
public String errorOutput(String property) {
return getErrorOutput(property);
}
/**
* Wrapper for getErrorMarkup()
*/
public String errorOutput() {
return getErrorOutput();
}
// ------------------------------------------------------- Constructors
public ConfigHelper() {
super();
}
public ConfigHelper(
ServletContext application,
HttpServletRequest request,
HttpServletResponse response) {
super();
setResources(application, request, response);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -