use of javax.servlet.jsp.JspContext in project jersey by jersey.
the class Include method doTag.
public void doTag() throws JspException, IOException {
final JspContext jspContext = getJspContext();
final Class<?> resolvingClass = (Class<?>) jspContext.getAttribute(RequestDispatcherWrapper.RESOLVING_CLASS_ATTRIBUTE_NAME, PageContext.REQUEST_SCOPE);
final String basePath = (String) jspContext.getAttribute(RequestDispatcherWrapper.BASE_PATH_ATTRIBUTE_NAME, PageContext.REQUEST_SCOPE);
final ServletConfig servletConfig = (ServletConfig) getPageObject(PageContext.CONFIG);
final ServletContext servletContext = servletConfig.getServletContext();
for (Class<?> clazz = resolvingClass; clazz != Object.class; clazz = clazz.getSuperclass()) {
final String template = basePath + TemplateHelper.getAbsolutePath(clazz, page, '/');
if (servletContext.getResource(template) != null) {
// Tomcat returns a RequestDispatcher even if the JSP file doesn't exist so check if the resource exists first.
final RequestDispatcher dispatcher = servletContext.getRequestDispatcher(template);
if (dispatcher != null) {
try {
final HttpServletRequest request = (HttpServletRequest) getPageObject(PageContext.REQUEST);
final HttpServletResponse response = (HttpServletResponse) getPageObject(PageContext.RESPONSE);
dispatcher.include(request, new Wrapper(response, new PrintWriter(jspContext.getOut())));
} catch (ServletException e) {
throw new JspException(e);
}
return;
}
}
}
throw new JspException(LocalizationMessages.UNABLE_TO_FIND_PAGE_FOR_RESOLVING_CLASS(page, resolvingClass));
}
use of javax.servlet.jsp.JspContext in project jodd by oblac.
the class CsrfTokenTag method doTag.
@Override
public void doTag() throws IOException {
JspContext jspContext = this.getJspContext();
// generate token
HttpServletRequest request = (HttpServletRequest) ((PageContext) jspContext).getRequest();
HttpSession session = request.getSession();
String value = CsrfShield.prepareCsrfToken(session);
if (name == null) {
name = CsrfShield.CSRF_TOKEN_NAME;
}
jspContext.getOut().write("<input type=\"hidden\" name=\"" + name + "\" value=\"" + value + "\"/>");
}
use of javax.servlet.jsp.JspContext in project OpenClinica by OpenClinica.
the class PrintTableTag method doTag.
/**
* This JSP Tag API method creates a instance of PrintHorizontalFormBuilder,
* then generates that class's XHTML output into the web page. The tag shows
* all sections of a CRF.
*
* @throws JspException
* @throws IOException
*/
@Override
public void doTag() throws JspException, IOException {
JspContext context = getJspContext();
JspWriter tagWriter = context.getOut();
// This request attribute is generated by the PrintCRf or PrintDataEntry
// servlets
List<DisplaySectionBean> listOfDisplayBeans = (ArrayList) context.findAttribute("listOfDisplaySectionBeans");
StudyBean studyBean = (StudyBean) context.findAttribute("study");
// EventCRFBean
EventCRFBean eventCRFBean = (EventCRFBean) context.findAttribute("EventCRFBean");
String isInternetExplorer = (String) context.findAttribute("isInternetExplorer");
if (listOfDisplayBeans != null) {
PrintHorizontalFormBuilder printFormBuilder = new PrintHorizontalFormBuilder();
// Provide the form-building code with the list of display section
// beans
printFormBuilder.setDisplaySectionBeans(listOfDisplayBeans);
// The body content of the tag contains 'true' or 'false', depending
// on whether the
// printed CRF involves data entry (and possible saved data) or not.
JspFragment fragment = this.getJspBody();
Writer stringWriter = new StringWriter();
fragment.invoke(stringWriter);
if ("true".equalsIgnoreCase(stringWriter.toString())) {
printFormBuilder.setInvolvesDataEntry(true);
}
printFormBuilder.setEventCRFbean(eventCRFBean);
if ("true".equalsIgnoreCase(isInternetExplorer)) {
printFormBuilder.setInternetExplorer(true);
}
if (studyBean != null) {
printFormBuilder.setStudyBean(studyBean);
}
if ("true".equalsIgnoreCase(stringWriter.toString())) {
tagWriter.println(printFormBuilder.createMarkup());
} else
tagWriter.println(printFormBuilder.createMarkupNoDE());
} else {
tagWriter.println("The application could not generate the markup for the printable form.<br />" + "This error may have been caused by the altering of the web page's URL; the URL needs " + "an 'id' or an 'ecId' value in its query string at the URL end.");
}
}
use of javax.servlet.jsp.JspContext in project jetty.project by eclipse.
the class Date2Tag method doTag.
public void doTag() throws JspException, IOException {
String formatted = new SimpleDateFormat("long".equals(format) ? "EEE 'the' d:MMM:yyyy" : "d:MM:yy").format(new Date());
StringTokenizer tok = new StringTokenizer(formatted, ":");
JspContext context = getJspContext();
context.setAttribute("day", tok.nextToken());
context.setAttribute("month", tok.nextToken());
context.setAttribute("year", tok.nextToken());
JspFragment fragment = getJspBody();
fragment.invoke(null);
}
use of javax.servlet.jsp.JspContext in project OpenClinica by OpenClinica.
the class AlertTag method doTag.
@Override
public void doTag() throws JspException, IOException {
JspContext context = getJspContext();
JspWriter tagWriter = context.getOut();
StringBuilder builder = new StringBuilder("");
List<String> messages = (ArrayList) context.findAttribute("pageMessages");
if (messages != null) {
for (String message : messages) {
builder.append(message);
builder.append("<br />");
}
}
tagWriter.println(builder.toString());
}
Aggregations