use of jakarta.servlet.jsp.JspException in project spring-framework by spring-projects.
the class UrlTag method replaceUriTemplateParams.
/**
* Replace template markers in the URL matching available parameters. The
* name of matched parameters are added to the used parameters set.
* <p>Parameter values are URL encoded.
* @param uri the URL with template parameters to replace
* @param params parameters used to replace template markers
* @param usedParams set of template parameter names that have been replaced
* @return the URL with template parameters replaced
*/
protected String replaceUriTemplateParams(String uri, List<Param> params, Set<String> usedParams) throws JspException {
String encoding = this.pageContext.getResponse().getCharacterEncoding();
for (Param param : params) {
String template = URL_TEMPLATE_DELIMITER_PREFIX + param.getName() + URL_TEMPLATE_DELIMITER_SUFFIX;
if (uri.contains(template)) {
usedParams.add(param.getName());
String value = param.getValue();
try {
uri = StringUtils.replace(uri, template, (value != null ? UriUtils.encodePath(value, encoding) : ""));
} catch (UnsupportedCharsetException ex) {
throw new JspException(ex);
}
} else {
template = URL_TEMPLATE_DELIMITER_PREFIX + '/' + param.getName() + URL_TEMPLATE_DELIMITER_SUFFIX;
if (uri.contains(template)) {
usedParams.add(param.getName());
String value = param.getValue();
try {
uri = StringUtils.replace(uri, template, (value != null ? UriUtils.encodePathSegment(value, encoding) : ""));
} catch (UnsupportedCharsetException ex) {
throw new JspException(ex);
}
}
}
}
return uri;
}
use of jakarta.servlet.jsp.JspException in project spring-framework by spring-projects.
the class EvalTag method doEndTag.
@Override
public int doEndTag() throws JspException {
EvaluationContext evaluationContext = (EvaluationContext) this.pageContext.getAttribute(EVALUATION_CONTEXT_PAGE_ATTRIBUTE);
if (evaluationContext == null) {
evaluationContext = createEvaluationContext(this.pageContext);
this.pageContext.setAttribute(EVALUATION_CONTEXT_PAGE_ATTRIBUTE, evaluationContext);
}
if (this.var != null) {
Object result = (this.expression != null ? this.expression.getValue(evaluationContext) : null);
this.pageContext.setAttribute(this.var, result, this.scope);
} else {
try {
String result = (this.expression != null ? this.expression.getValue(evaluationContext, String.class) : null);
result = ObjectUtils.getDisplayString(result);
result = htmlEscape(result);
result = (this.javaScriptEscape ? JavaScriptUtils.javaScriptEscape(result) : result);
this.pageContext.getOut().print(result);
} catch (IOException ex) {
throw new JspException(ex);
}
}
return EVAL_PAGE;
}
use of jakarta.servlet.jsp.JspException in project spring-framework by spring-projects.
the class RequestContextAwareTag method doStartTag.
/**
* Create and expose the current RequestContext.
* Delegates to {@link #doStartTagInternal()} for actual work.
* @see #REQUEST_CONTEXT_PAGE_ATTRIBUTE
* @see org.springframework.web.servlet.support.JspAwareRequestContext
*/
@Override
public final int doStartTag() throws JspException {
try {
this.requestContext = (RequestContext) this.pageContext.getAttribute(REQUEST_CONTEXT_PAGE_ATTRIBUTE);
if (this.requestContext == null) {
this.requestContext = new JspAwareRequestContext(this.pageContext);
this.pageContext.setAttribute(REQUEST_CONTEXT_PAGE_ATTRIBUTE, this.requestContext);
}
return doStartTagInternal();
} catch (JspException | RuntimeException ex) {
logger.error(ex.getMessage(), ex);
throw ex;
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
throw new JspTagException(ex.getMessage());
}
}
use of jakarta.servlet.jsp.JspException in project spring-framework by spring-projects.
the class TransformTag method doStartTagInternal.
@Override
protected final int doStartTagInternal() throws JspException {
if (this.value != null) {
// Find the containing EditorAwareTag (e.g. BindTag), if applicable.
EditorAwareTag tag = (EditorAwareTag) TagSupport.findAncestorWithClass(this, EditorAwareTag.class);
if (tag == null) {
throw new JspException("TransformTag can only be used within EditorAwareTag (e.g. BindTag)");
}
// OK, let's obtain the editor...
String result = null;
PropertyEditor editor = tag.getEditor();
if (editor != null) {
// If an editor was found, edit the value.
editor.setValue(this.value);
result = editor.getAsText();
} else {
// Else, just do a toString.
result = this.value.toString();
}
result = htmlEscape(result);
if (this.var != null) {
this.pageContext.setAttribute(this.var, result, TagUtils.getScope(this.scope));
} else {
try {
// Else, just print it out.
this.pageContext.getOut().print(result);
} catch (IOException ex) {
throw new JspException(ex);
}
}
}
return SKIP_BODY;
}
use of jakarta.servlet.jsp.JspException in project spring-framework by spring-projects.
the class BindTagTests method bindTagWithoutBean.
@Test
void bindTagWithoutBean() throws JspException {
PageContext pc = createPageContext();
BindTag tag = new BindTag();
tag.setPageContext(pc);
tag.setPath("tb");
assertThatExceptionOfType(JspException.class).isThrownBy(tag::doStartTag);
}
Aggregations