use of jakarta.servlet.jsp.JspException in project spring-security by spring-projects.
the class AuthenticationTag method doEndTag.
@Override
public int doEndTag() throws JspException {
Object result = null;
// determine the value by...
if (this.property != null) {
if ((SecurityContextHolder.getContext() == null) || !(SecurityContextHolder.getContext() instanceof SecurityContext) || (SecurityContextHolder.getContext().getAuthentication() == null)) {
return Tag.EVAL_PAGE;
}
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (auth.getPrincipal() == null) {
return Tag.EVAL_PAGE;
}
try {
BeanWrapperImpl wrapper = new BeanWrapperImpl(auth);
result = wrapper.getPropertyValue(this.property);
} catch (BeansException ex) {
throw new JspException(ex);
}
}
if (this.var != null) {
/*
* Store the result, letting an IllegalArgumentException propagate back if the
* scope is invalid (e.g., if an attempt is made to store something in the
* session without any HttpSession existing).
*/
if (result != null) {
this.pageContext.setAttribute(this.var, result, this.scope);
} else {
if (this.scopeSpecified) {
this.pageContext.removeAttribute(this.var, this.scope);
} else {
this.pageContext.removeAttribute(this.var);
}
}
} else {
if (this.htmlEscape) {
writeMessage(TextEscapeUtils.escapeEntities(String.valueOf(result)));
} else {
writeMessage(String.valueOf(result));
}
}
return EVAL_PAGE;
}
use of jakarta.servlet.jsp.JspException in project spring-framework by spring-projects.
the class UrlTag method createQueryString.
/**
* Build the query string from available parameters that have not already
* been applied as template params.
* <p>The names and values of parameters are URL encoded.
* @param params the parameters to build the query string from
* @param usedParams set of parameter names that have been applied as
* template params
* @param includeQueryStringDelimiter true if the query string should start
* with a '?' instead of '&'
* @return the query string
*/
protected String createQueryString(List<Param> params, Set<String> usedParams, boolean includeQueryStringDelimiter) throws JspException {
String encoding = this.pageContext.getResponse().getCharacterEncoding();
StringBuilder qs = new StringBuilder();
for (Param param : params) {
if (!usedParams.contains(param.getName()) && StringUtils.hasLength(param.getName())) {
if (includeQueryStringDelimiter && qs.length() == 0) {
qs.append('?');
} else {
qs.append('&');
}
try {
qs.append(UriUtils.encodeQueryParam(param.getName(), encoding));
if (param.getValue() != null) {
qs.append('=');
qs.append(UriUtils.encodeQueryParam(param.getValue(), encoding));
}
} catch (UnsupportedCharsetException ex) {
throw new JspException(ex);
}
}
}
return qs.toString();
}
use of jakarta.servlet.jsp.JspException in project spring-framework by spring-projects.
the class EscapeBodyTag method doAfterBody.
@Override
public int doAfterBody() throws JspException {
try {
String content = readBodyContent();
// HTML and/or JavaScript escape, if demanded
content = htmlEscape(content);
content = (this.javaScriptEscape ? JavaScriptUtils.javaScriptEscape(content) : content);
writeBodyContent(content);
} catch (IOException ex) {
throw new JspException("Could not write escaped body", ex);
}
return (SKIP_BODY);
}
use of jakarta.servlet.jsp.JspException in project tomcat by apache.
the class TagHandlerPool method get.
/**
* Gets the next available tag handler from this tag handler pool,
* instantiating one if this tag handler pool is empty.
*
* @param handlerClass
* Tag handler class
* @return Reused or newly instantiated tag handler
* @throws JspException
* if a tag handler cannot be instantiated
*/
public Tag get(Class<? extends Tag> handlerClass) throws JspException {
Tag handler;
synchronized (this) {
if (current >= 0) {
handler = handlers[current--];
return handler;
}
}
// wait for us to construct a tag for this thread.
try {
if (useInstanceManagerForTags) {
return (Tag) instanceManager.newInstance(handlerClass.getName(), handlerClass.getClassLoader());
} else {
Tag instance = handlerClass.getConstructor().newInstance();
instanceManager.newInstance(instance);
return instance;
}
} catch (Exception e) {
Throwable t = ExceptionUtils.unwrapInvocationTargetException(e);
ExceptionUtils.handleThrowable(t);
throw new JspException(e.getMessage(), t);
}
}
use of jakarta.servlet.jsp.JspException in project spring-framework by spring-projects.
the class UrlTag method doEndTag.
@Override
public int doEndTag() throws JspException {
String url = createUrl();
RequestDataValueProcessor processor = getRequestContext().getRequestDataValueProcessor();
ServletRequest request = this.pageContext.getRequest();
if ((processor != null) && (request instanceof HttpServletRequest)) {
url = processor.processUrl((HttpServletRequest) request, url);
}
if (this.var == null) {
// print the url to the writer
try {
this.pageContext.getOut().print(url);
} catch (IOException ex) {
throw new JspException(ex);
}
} else {
// store the url as a variable
this.pageContext.setAttribute(this.var, url, this.scope);
}
return EVAL_PAGE;
}
Aggregations