Search in sources :

Example 1 with JspContext

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));
}
Also used : HttpServletResponseWrapper(javax.servlet.http.HttpServletResponseWrapper) JspContext(javax.servlet.jsp.JspContext) ServletConfig(javax.servlet.ServletConfig) HttpServletResponse(javax.servlet.http.HttpServletResponse) RequestDispatcher(javax.servlet.RequestDispatcher) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) JspException(javax.servlet.jsp.JspException) ServletContext(javax.servlet.ServletContext) PrintWriter(java.io.PrintWriter)

Example 2 with JspContext

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 + "\"/>");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) JspContext(javax.servlet.jsp.JspContext) HttpSession(javax.servlet.http.HttpSession)

Example 3 with JspContext

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.");
    }
}
Also used : DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) PrintHorizontalFormBuilder(org.akaza.openclinica.view.form.PrintHorizontalFormBuilder) JspFragment(javax.servlet.jsp.tagext.JspFragment) JspContext(javax.servlet.jsp.JspContext) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StringWriter(java.io.StringWriter) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) JspWriter(javax.servlet.jsp.JspWriter) StringWriter(java.io.StringWriter) JspWriter(javax.servlet.jsp.JspWriter) Writer(java.io.Writer)

Example 4 with JspContext

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);
}
Also used : JspFragment(javax.servlet.jsp.tagext.JspFragment) StringTokenizer(java.util.StringTokenizer) JspContext(javax.servlet.jsp.JspContext) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 5 with JspContext

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());
}
Also used : JspContext(javax.servlet.jsp.JspContext) ArrayList(java.util.ArrayList) JspWriter(javax.servlet.jsp.JspWriter)

Aggregations

JspContext (javax.servlet.jsp.JspContext)6 JspWriter (javax.servlet.jsp.JspWriter)3 ArrayList (java.util.ArrayList)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 JspFragment (javax.servlet.jsp.tagext.JspFragment)2 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)2 DisplaySectionBean (org.akaza.openclinica.bean.submit.DisplaySectionBean)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 StringTokenizer (java.util.StringTokenizer)1 RequestDispatcher (javax.servlet.RequestDispatcher)1 ServletConfig (javax.servlet.ServletConfig)1 ServletContext (javax.servlet.ServletContext)1 ServletException (javax.servlet.ServletException)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 HttpServletResponseWrapper (javax.servlet.http.HttpServletResponseWrapper)1 HttpSession (javax.servlet.http.HttpSession)1