use of javax.servlet.jsp.JspException in project sonarqube by SonarSource.
the class FormTag method lookup.
// ------------------------------------------------------ Protected Methods
/**
* Look up values for the <code>name</code>, <code>scope</code>, and
* <code>type</code> properties if necessary.
*
* @throws JspException if a required value cannot be looked up
*/
protected void lookup() throws JspException {
// Look up the module configuration information we need
moduleConfig = TagUtils.getInstance().getModuleConfig(pageContext);
if (moduleConfig == null) {
JspException e = new JspException(messages.getMessage("formTag.collections"));
pageContext.setAttribute(Globals.EXCEPTION_KEY, e, PageContext.REQUEST_SCOPE);
throw e;
}
String calcAction = this.action;
// If the action is not specified, use the original request uri
if (this.action == null) {
HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
postbackAction = (String) request.getAttribute(Globals.ORIGINAL_URI_KEY);
String prefix = moduleConfig.getPrefix();
if (postbackAction != null && prefix.length() > 0 && postbackAction.startsWith(prefix)) {
postbackAction = postbackAction.substring(prefix.length());
}
calcAction = postbackAction;
} else {
// Translate the action if it is an actionId
ActionConfig actionConfig = moduleConfig.findActionConfigId(this.action);
if (actionConfig != null) {
this.action = actionConfig.getPath();
calcAction = this.action;
}
}
servlet = (ActionServlet) pageContext.getServletContext().getAttribute(Globals.ACTION_SERVLET_KEY);
// Look up the action mapping we will be submitting to
String mappingName = TagUtils.getInstance().getActionMappingName(calcAction);
mapping = (ActionMapping) moduleConfig.findActionConfig(mappingName);
if (mapping == null) {
JspException e = new JspException(messages.getMessage("formTag.mapping", mappingName));
pageContext.setAttribute(Globals.EXCEPTION_KEY, e, PageContext.REQUEST_SCOPE);
throw e;
}
// Look up the form bean definition
FormBeanConfig formBeanConfig = moduleConfig.findFormBeanConfig(mapping.getName());
if (formBeanConfig == null) {
JspException e = null;
if (mapping.getName() == null) {
e = new JspException(messages.getMessage("formTag.name", calcAction));
} else {
e = new JspException(messages.getMessage("formTag.formBean", mapping.getName(), calcAction));
}
pageContext.setAttribute(Globals.EXCEPTION_KEY, e, PageContext.REQUEST_SCOPE);
throw e;
}
// Calculate the required values
beanName = mapping.getAttribute();
beanScope = mapping.getScope();
beanType = formBeanConfig.getType();
}
use of javax.servlet.jsp.JspException in project sonarqube by SonarSource.
the class ImageTag method src.
// ------------------------------------------------------ Protected Methods
/**
* Return the base source URL that will be rendered in the
* <code>src</code> property for this generated element, or
* <code>null</code> if there is no such URL.
*
* @throws JspException if an error occurs
*/
protected String src() throws JspException {
// Deal with a direct context-relative page that has been specified
if (this.page != null) {
if ((this.src != null) || (this.srcKey != null) || (this.pageKey != null)) {
JspException e = new JspException(messages.getMessage("imgTag.src"));
TagUtils.getInstance().saveException(pageContext, e);
throw e;
}
HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
ModuleConfig config = ModuleUtils.getInstance().getModuleConfig(this.module, request, pageContext.getServletContext());
String pageValue = this.page;
if (config != null) {
pageValue = TagUtils.getInstance().pageURL(request, this.page, config);
}
return (request.getContextPath() + pageValue);
}
// Deal with an indirect context-relative page that has been specified
if (this.pageKey != null) {
if ((this.src != null) || (this.srcKey != null)) {
JspException e = new JspException(messages.getMessage("imgTag.src"));
TagUtils.getInstance().saveException(pageContext, e);
throw e;
}
HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
ModuleConfig config = ModuleUtils.getInstance().getModuleConfig(this.module, request, pageContext.getServletContext());
String pageValue = TagUtils.getInstance().message(pageContext, getBundle(), getLocale(), this.pageKey);
if (config != null) {
pageValue = TagUtils.getInstance().pageURL(request, pageValue, config);
}
return (request.getContextPath() + pageValue);
}
// Deal with an absolute source that has been specified
if (this.src != null) {
if (this.srcKey != null) {
JspException e = new JspException(messages.getMessage("imgTag.src"));
TagUtils.getInstance().saveException(pageContext, e);
throw e;
}
return (this.src);
}
// Deal with an indirect source that has been specified
if (this.srcKey == null) {
JspException e = new JspException(messages.getMessage("imgTag.src"));
TagUtils.getInstance().saveException(pageContext, e);
throw e;
}
return TagUtils.getInstance().message(pageContext, getBundle(), getLocale(), this.srcKey);
}
use of javax.servlet.jsp.JspException in project sonarqube by SonarSource.
the class HeaderTag method handleMultipleHeaders.
/**
* Expose an array of header values.
*
* @throws JspException
* @since Struts 1.2
*/
protected void handleMultipleHeaders() throws JspException {
ArrayList values = new ArrayList();
Enumeration items = ((HttpServletRequest) pageContext.getRequest()).getHeaders(name);
while (items.hasMoreElements()) {
values.add(items.nextElement());
}
if (values.isEmpty() && (this.value != null)) {
values.add(this.value);
}
String[] headers = new String[values.size()];
if (headers.length == 0) {
JspException e = new JspException(messages.getMessage("header.get", name));
TagUtils.getInstance().saveException(pageContext, e);
throw e;
}
pageContext.setAttribute(id, values.toArray(headers));
}
use of javax.servlet.jsp.JspException in project sonarqube by SonarSource.
the class MessageTag method doStartTag.
// --------------------------------------------------------- Public Methods
/**
* Process the start tag.
*
* @throws JspException if a JSP exception has occurred
*/
public int doStartTag() throws JspException {
String key = this.key;
if (key == null) {
// Look up the requested property value
Object value = TagUtils.getInstance().lookup(pageContext, name, property, scope);
if ((value != null) && !(value instanceof String)) {
JspException e = new JspException(messages.getMessage("message.property", key));
TagUtils.getInstance().saveException(pageContext, e);
throw e;
}
key = (String) value;
}
// Construct the optional arguments array we will be using
Object[] args = new Object[] { arg0, arg1, arg2, arg3, arg4 };
// Retrieve the message string we are looking for
String message = TagUtils.getInstance().message(pageContext, this.bundle, this.localeKey, key, args);
if (message == null) {
Locale locale = TagUtils.getInstance().getUserLocale(pageContext, this.localeKey);
String localeVal = (locale == null) ? "default locale" : locale.toString();
JspException e = new JspException(messages.getMessage("message.message", "\"" + key + "\"", "\"" + ((bundle == null) ? "(default bundle)" : bundle) + "\"", localeVal));
TagUtils.getInstance().saveException(pageContext, e);
throw e;
}
TagUtils.getInstance().write(pageContext, message);
return (SKIP_BODY);
}
use of javax.servlet.jsp.JspException in project sonarqube by SonarSource.
the class ParameterTag method doStartTag.
// --------------------------------------------------------- Public Methods
/**
* Retrieve the required property and expose it as a scripting variable.
*
* @throws JspException if a JSP exception has occurred
*/
public int doStartTag() throws JspException {
// Deal with a single parameter value
if (multiple == null) {
String value = pageContext.getRequest().getParameter(name);
if ((value == null) && (this.value != null)) {
value = this.value;
}
if (value == null) {
JspException e = new JspException(messages.getMessage("parameter.get", name));
TagUtils.getInstance().saveException(pageContext, e);
throw e;
}
pageContext.setAttribute(id, value);
return (SKIP_BODY);
}
// Deal with multiple parameter values
String[] values = pageContext.getRequest().getParameterValues(name);
if ((values == null) || (values.length == 0)) {
if (this.value != null) {
values = new String[] { this.value };
}
}
if ((values == null) || (values.length == 0)) {
JspException e = new JspException(messages.getMessage("parameter.get", name));
TagUtils.getInstance().saveException(pageContext, e);
throw e;
}
pageContext.setAttribute(id, values);
return (SKIP_BODY);
}
Aggregations