Example usage for javax.servlet.jsp PageContext getOut

List of usage examples for javax.servlet.jsp PageContext getOut

Introduction

In this page you can find the example usage for javax.servlet.jsp PageContext getOut.

Prototype

abstract public JspWriter getOut();

Source Link

Document

The current value of the out object (a JspWriter).

Usage

From source file:it.scoppelletti.wui.HeadTag.java

/**
 * Implementazione./* w w w. j  av a 2 s .co  m*/
 */
@Override
public void doTag() throws IOException, JspException {
    URI uri;
    UriComponentsBuilder uriBuilder;
    WebApplicationManager applMgr;
    List<String> applList;
    ApplicationContext applCtx;
    PageContext pageCtx = (PageContext) getJspContext();

    applCtx = WebApplicationContextUtils.getRequiredWebApplicationContext(pageCtx.getServletContext());

    applMgr = applCtx.getBean(WebApplicationManager.BEAN_NAME, WebApplicationManager.class);
    applList = applMgr.listRunningApplications();

    for (String ctxPath : applList) {
        uriBuilder = UriComponentsBuilder.fromHttpUrl(applMgr.getBaseUrl());
        uriBuilder.path(ctxPath).path(HeadTag.HEAD_PATH);
        uriBuilder.queryParam(AbstractServerResource.QUERY_LOCALE, pageCtx.getRequest().getLocale().toString());
        uri = uriBuilder.build().toUri();

        try {
            head(uri, pageCtx.getOut());
        } catch (Exception ex) {
            myLogger.error(String.format("Failed to get %1$s.", uri), ex);
        }
    }
}

From source file:com.draagon.meta.web.view.html.HotLinkView.java

/**
 * Renders a hotlink view/*ww w  .  j  a  v a 2s . c o  m*/
 */
protected void doHotLinkView(PageContext page, Object o, String label, int mode, Map params)
        throws IOException, MetaException {
    String link = createLink(page, o, mode, params);
    String val = getMetaField(o).getString(o);

    if (link == null && val == null) {
        return;
    }

    if (!hasAttribute("viewRef")) {
        HtmlViewHelper.drawLink(page, link, val, getLinkClass(params), params);
    } else {
        String viewRef = (String) getAttribute("viewRef");

        WebView mv = (WebView) getMetaField(o).getView(viewRef);

        String linkClass = getLinkClass(params);

        JspWriter out = page.getOut();

        // if ( text == null ) text = "&nbsp;";

        if (link != null) {
            out.print("<a");
            if (linkClass != null) {
                out.print(" class=\"" + linkClass + "\"");
            }
            out.print(" href=\"" + link + "\">");
        }

        mv.doView(page, o, mode, params);
        // out.print( text );

        if (link != null) {
            out.print("</a>");
        }
    }
}

From source file:com.truthbean.core.web.kindeditor.FileUpload.java

@Override
public void service(final HttpServletRequest request, final HttpServletResponse response)
        throws IOException, ServletException {

    final PageContext pageContext;
    HttpSession session = null;/*ww w .j  a  v  a  2 s  .  c om*/
    final ServletContext application;
    final ServletConfig config;
    JspWriter out = null;
    final Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;

    try {
        response.setContentType("text/html; charset=UTF-8");
        pageContext = _jspxFactory.getPageContext(this, request, response, null, true, 8192, true);
        _jspx_page_context = pageContext;
        application = pageContext.getServletContext();
        config = pageContext.getServletConfig();
        session = pageContext.getSession();
        out = pageContext.getOut();
        _jspx_out = out;

        out.write("\r\n");
        out.write("\r\n");
        out.write("\r\n");
        out.write("\r\n");
        out.write("\r\n");
        out.write("\r\n");
        out.write("\r\n");

        /**
         * KindEditor JSP
         *
         * JSP???? ??
         *
         */
        // ?
        String savePath = pageContext.getServletContext().getRealPath("/") + "resource/";

        String savePath$ = savePath;

        // ?URL
        String saveUrl = request.getContextPath() + "/resource/";

        // ???
        HashMap<String, String> extMap = new HashMap<>();
        extMap.put("image", "gif,jpg,jpeg,png,bmp");
        extMap.put("flash", "swf,flv");
        extMap.put("media", "swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb");
        extMap.put("file", "doc,docx,xls,xlsx,ppt,htm,html,txt,zip,rar,gz,bz2");

        // ?
        long maxSize = 10 * 1024 * 1024 * 1024L;

        response.setContentType("text/html; charset=UTF-8");

        if (!ServletFileUpload.isMultipartContent(request)) {
            out.println(getError(""));
            return;
        }
        // 
        File uploadDir = new File(savePath);
        if (!uploadDir.isDirectory()) {
            out.println(getError("?"));
            return;
        }
        // ??
        if (!uploadDir.canWrite()) {
            out.println(getError("??"));
            return;
        }

        String dirName = request.getParameter("dir");
        if (dirName == null) {
            dirName = "image";
        }
        if (!extMap.containsKey(dirName)) {
            out.println(getError("???"));
            return;
        }
        // 
        savePath += dirName + "/";
        saveUrl += dirName + "/";
        File saveDirFile = new File(savePath);
        if (!saveDirFile.exists()) {
            saveDirFile.mkdirs();
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String ymd = sdf.format(new Date());
        savePath += ymd + "/";
        saveUrl += ymd + "/";
        File dirFile = new File(savePath);
        if (!dirFile.exists()) {
            dirFile.mkdirs();
        }

        FileItemFactory factory = new DiskFileItemFactory();
        ServletFileUpload upload = new ServletFileUpload(factory);
        upload.setHeaderEncoding("UTF-8");
        List items = upload.parseRequest(request);
        Iterator itr = items.iterator();
        while (itr.hasNext()) {
            FileItem item = (FileItem) itr.next();
            String fileName = item.getName();
            if (!item.isFormField()) {
                // ?
                if (item.getSize() > maxSize) {
                    out.println(getError("??"));
                    return;
                }
                // ??
                String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
                if (!Arrays.asList(extMap.get(dirName).split(",")).contains(fileExt)) {
                    out.println(getError("??????\n??"
                            + extMap.get(dirName) + "?"));
                    return;
                }

                SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
                String newFileName = df.format(new Date()) + "_" + new Random().nextInt(1000) + "." + fileExt;
                try {
                    File uploadedFile = new File(savePath, newFileName);
                    item.write(uploadedFile);
                } catch (Exception e) {
                    out.println(getError(""));
                    return;
                }

                JSONObject obj = new JSONObject();
                obj.put("error", 0);
                obj.put("url", saveUrl + newFileName);

                request.getSession().setAttribute("fileName", savePath$ + fileName);
                request.getSession().setAttribute("filePath", savePath + newFileName);
                request.getSession().setAttribute("fileUrl", saveUrl + newFileName);

                out.println(obj.toJSONString());
            }
        }

        out.write('\r');
        out.write('\n');
    } catch (IOException | FileUploadException t) {
        if (!(t instanceof javax.servlet.jsp.SkipPageException)) {
            out = _jspx_out;
            if (out != null && out.getBufferSize() != 0) {
                if (response.isCommitted()) {
                    out.flush();
                } else {
                    out.clearBuffer();
                }
            }
            if (_jspx_page_context != null) {
                _jspx_page_context.handlePageException(t);
            } else {
                throw new ServletException(t);
            }
        }
    } finally {
        _jspxFactory.releasePageContext(_jspx_page_context);
    }
}

From source file:com.draagon.meta.web.view.html.DateView.java

/**
 * Draws a date view of the field// ww  w. ja  v a2  s  .  com
 */
protected void doDateView(PageContext page, String label, int mode, Date dateVal, Map params)
        throws IOException {
    Calendar c = Calendar.getInstance();

    String emptyString = ViewHelper.getStringParam(params, ATTR_EMPTYVALUE, null);
    if (emptyString == null && hasAttribute(ATTR_EMPTYVALUE)) {
        emptyString = (String) getAttribute(ATTR_EMPTYVALUE);
    }
    if (emptyString != null) {
        setEmptyString(emptyString);
    }

    boolean useZero = (emptyString != null); // ViewHelper.getBooleanParam( params, ATTR_USEZERO, false );

    int year = 0;
    int mon = 0;
    int day = 0;

    if (dateVal != null) {
        c.setTime(dateVal);

        year = c.get(Calendar.YEAR);
        mon = c.get(Calendar.MONTH) + 1;
        day = c.get(Calendar.DAY_OF_MONTH);
    } else if (!useZero) {
        year = c.get(Calendar.YEAR);
        mon = c.get(Calendar.MONTH) + 1;
        day = c.get(Calendar.DAY_OF_MONTH);
    }

    // Output the Date Views

    JspWriter out = page.getOut();
    if (mode == WebView.READ) {
        if (year == 0 && mon == 0 && day == 0) {
            out.print("[NO DATE DEFINED]");
        } else {
            doMonthView(page, mode, label + "-mon", mon, params);
            out.print("&nbsp;");

            doDayView(page, mode, label + "-day", day, params);

            if (year > 0) {
                out.print("&nbsp;, ");
                HtmlViewHelper.drawText(page, "" + year, params);
            }
        }
    } else if (mode == WebView.EDIT) {
        //hasEmptyValue = empty;
        out.print("<table border=0 cellspacing=0 cellpadding=0><tr><td>");
        doMonthView(page, mode, label + "-mon", mon, params);
        out.print("</td><td>");
        doDayView(page, mode, label + "-day", day, params);
        out.print("</td><td>");

        c = Calendar.getInstance();
        int defMin = c.get(Calendar.YEAR) - 10;
        int defMax = c.get(Calendar.YEAR) + 30;

        try {
            defMin = Integer.parseInt((String) getAttribute(ATTR_MINRANGE));
        } catch (Exception e) {
        }
        try {
            defMax = Integer.parseInt((String) getAttribute(ATTR_MAXRANGE));
        } catch (Exception e) {
        }

        int min = ViewHelper.getIntParam(params, ATTR_MINRANGE, defMin);
        int max = ViewHelper.getIntParam(params, ATTR_MAXRANGE, defMax);

        //ystem.out.println( "min: " + min + ", max: " + max );

        if (min > 0 || max > 0) {
            doYearView(page, mode, label + "-year", year, min, max, params);
        } else if (year > 0) {
            HtmlViewHelper.drawTextBox(page, label + "-year", "" + year, 4, 4, params);
        } else {
            HtmlViewHelper.drawTextBox(page, label + "-year", "", 4, 4, params);
        }

        out.print("</td></tr></table>");
    } else {
        HtmlViewHelper.drawHidden(page, params);
    }
}

From source file:org.apache.jsp.WEB_002dINF.pages.includes.topmenu_jsp.java

private boolean _jspx_meth_fmt_005fmessage_005f0(javax.servlet.jsp.tagext.JspTag _jspx_th_c_005fif_005f0,
        javax.servlet.jsp.PageContext _jspx_page_context) throws java.lang.Throwable {
    javax.servlet.jsp.PageContext pageContext = _jspx_page_context;
    javax.servlet.jsp.JspWriter out = _jspx_page_context.getOut();
    //  fmt:message
    org.apache.taglibs.standard.tag.rt.fmt.MessageTag _jspx_th_fmt_005fmessage_005f0 = (org.apache.taglibs.standard.tag.rt.fmt.MessageTag) _005fjspx_005ftagPool_005ffmt_005fmessage_0026_005fkey_005fnobody
            .get(org.apache.taglibs.standard.tag.rt.fmt.MessageTag.class);
    _jspx_th_fmt_005fmessage_005f0.setPageContext(_jspx_page_context);
    _jspx_th_fmt_005fmessage_005f0.setParent((javax.servlet.jsp.tagext.Tag) _jspx_th_c_005fif_005f0);
    // /WEB-INF/pages/includes/topmenu.jsp(13,50) name = key type = null reqTime = true required = false fragment = false deferredValue = false expectedTypeName = null deferredMethod = false methodSignature = null
    _jspx_th_fmt_005fmessage_005f0.setKey("pamelaChu.logo");
    int _jspx_eval_fmt_005fmessage_005f0 = _jspx_th_fmt_005fmessage_005f0.doStartTag();
    if (_jspx_th_fmt_005fmessage_005f0.doEndTag() == javax.servlet.jsp.tagext.Tag.SKIP_PAGE) {
        _005fjspx_005ftagPool_005ffmt_005fmessage_0026_005fkey_005fnobody.reuse(_jspx_th_fmt_005fmessage_005f0);
        return true;
    }//from  w  w w . j  ava2 s .  com
    _005fjspx_005ftagPool_005ffmt_005fmessage_0026_005fkey_005fnobody.reuse(_jspx_th_fmt_005fmessage_005f0);
    return false;
}

From source file:org.apache.jsp.WEB_002dINF.pages.includes.topmenu_jsp.java

private boolean _jspx_meth_fmt_005fmessage_005f1(javax.servlet.jsp.tagext.JspTag _jspx_th_c_005fif_005f0,
        javax.servlet.jsp.PageContext _jspx_page_context) throws java.lang.Throwable {
    javax.servlet.jsp.PageContext pageContext = _jspx_page_context;
    javax.servlet.jsp.JspWriter out = _jspx_page_context.getOut();
    //  fmt:message
    org.apache.taglibs.standard.tag.rt.fmt.MessageTag _jspx_th_fmt_005fmessage_005f1 = (org.apache.taglibs.standard.tag.rt.fmt.MessageTag) _005fjspx_005ftagPool_005ffmt_005fmessage_0026_005fkey_005fnobody
            .get(org.apache.taglibs.standard.tag.rt.fmt.MessageTag.class);
    _jspx_th_fmt_005fmessage_005f1.setPageContext(_jspx_page_context);
    _jspx_th_fmt_005fmessage_005f1.setParent((javax.servlet.jsp.tagext.Tag) _jspx_th_c_005fif_005f0);
    // /WEB-INF/pages/includes/topmenu.jsp(14,12) name = key type = null reqTime = true required = false fragment = false deferredValue = false expectedTypeName = null deferredMethod = false methodSignature = null
    _jspx_th_fmt_005fmessage_005f1.setKey("pamelaChu.title");
    int _jspx_eval_fmt_005fmessage_005f1 = _jspx_th_fmt_005fmessage_005f1.doStartTag();
    if (_jspx_th_fmt_005fmessage_005f1.doEndTag() == javax.servlet.jsp.tagext.Tag.SKIP_PAGE) {
        _005fjspx_005ftagPool_005ffmt_005fmessage_0026_005fkey_005fnobody.reuse(_jspx_th_fmt_005fmessage_005f1);
        return true;
    }/*from w ww.j  a  v  a2s .com*/
    _005fjspx_005ftagPool_005ffmt_005fmessage_0026_005fkey_005fnobody.reuse(_jspx_th_fmt_005fmessage_005f1);
    return false;
}

From source file:org.apache.jsp.WEB_002dINF.pages.includes.topmenu_jsp.java

private boolean _jspx_meth_fmt_005fmessage_005f2(javax.servlet.jsp.tagext.JspTag _jspx_th_c_005fif_005f0,
        javax.servlet.jsp.PageContext _jspx_page_context) throws java.lang.Throwable {
    javax.servlet.jsp.PageContext pageContext = _jspx_page_context;
    javax.servlet.jsp.JspWriter out = _jspx_page_context.getOut();
    //  fmt:message
    org.apache.taglibs.standard.tag.rt.fmt.MessageTag _jspx_th_fmt_005fmessage_005f2 = (org.apache.taglibs.standard.tag.rt.fmt.MessageTag) _005fjspx_005ftagPool_005ffmt_005fmessage_0026_005fkey_005fnobody
            .get(org.apache.taglibs.standard.tag.rt.fmt.MessageTag.class);
    _jspx_th_fmt_005fmessage_005f2.setPageContext(_jspx_page_context);
    _jspx_th_fmt_005fmessage_005f2.setParent((javax.servlet.jsp.tagext.Tag) _jspx_th_c_005fif_005f0);
    // /WEB-INF/pages/includes/topmenu.jsp(33,32) name = key type = null reqTime = true required = false fragment = false deferredValue = false expectedTypeName = null deferredMethod = false methodSignature = null
    _jspx_th_fmt_005fmessage_005f2.setKey("pamelaChu.timeline");
    int _jspx_eval_fmt_005fmessage_005f2 = _jspx_th_fmt_005fmessage_005f2.doStartTag();
    if (_jspx_th_fmt_005fmessage_005f2.doEndTag() == javax.servlet.jsp.tagext.Tag.SKIP_PAGE) {
        _005fjspx_005ftagPool_005ffmt_005fmessage_0026_005fkey_005fnobody.reuse(_jspx_th_fmt_005fmessage_005f2);
        return true;
    }/*from   w  ww .j  av  a 2 s.c  om*/
    _005fjspx_005ftagPool_005ffmt_005fmessage_0026_005fkey_005fnobody.reuse(_jspx_th_fmt_005fmessage_005f2);
    return false;
}

From source file:org.apache.jsp.WEB_002dINF.pages.includes.topmenu_jsp.java

private boolean _jspx_meth_fmt_005fmessage_005f3(javax.servlet.jsp.tagext.JspTag _jspx_th_c_005fif_005f0,
        javax.servlet.jsp.PageContext _jspx_page_context) throws java.lang.Throwable {
    javax.servlet.jsp.PageContext pageContext = _jspx_page_context;
    javax.servlet.jsp.JspWriter out = _jspx_page_context.getOut();
    //  fmt:message
    org.apache.taglibs.standard.tag.rt.fmt.MessageTag _jspx_th_fmt_005fmessage_005f3 = (org.apache.taglibs.standard.tag.rt.fmt.MessageTag) _005fjspx_005ftagPool_005ffmt_005fmessage_0026_005fkey_005fnobody
            .get(org.apache.taglibs.standard.tag.rt.fmt.MessageTag.class);
    _jspx_th_fmt_005fmessage_005f3.setPageContext(_jspx_page_context);
    _jspx_th_fmt_005fmessage_005f3.setParent((javax.servlet.jsp.tagext.Tag) _jspx_th_c_005fif_005f0);
    // /WEB-INF/pages/includes/topmenu.jsp(43,28) name = key type = null reqTime = true required = false fragment = false deferredValue = false expectedTypeName = null deferredMethod = false methodSignature = null
    _jspx_th_fmt_005fmessage_005f3.setKey("pamelaChu.menu.about");
    int _jspx_eval_fmt_005fmessage_005f3 = _jspx_th_fmt_005fmessage_005f3.doStartTag();
    if (_jspx_th_fmt_005fmessage_005f3.doEndTag() == javax.servlet.jsp.tagext.Tag.SKIP_PAGE) {
        _005fjspx_005ftagPool_005ffmt_005fmessage_0026_005fkey_005fnobody.reuse(_jspx_th_fmt_005fmessage_005f3);
        return true;
    }/* w w  w.jav  a 2s .  c  o m*/
    _005fjspx_005ftagPool_005ffmt_005fmessage_0026_005fkey_005fnobody.reuse(_jspx_th_fmt_005fmessage_005f3);
    return false;
}

From source file:org.apache.jsp.WEB_002dINF.pages.includes.topmenu_jsp.java

private boolean _jspx_meth_fmt_005fmessage_005f4(javax.servlet.jsp.tagext.JspTag _jspx_th_c_005fif_005f0,
        javax.servlet.jsp.PageContext _jspx_page_context) throws java.lang.Throwable {
    javax.servlet.jsp.PageContext pageContext = _jspx_page_context;
    javax.servlet.jsp.JspWriter out = _jspx_page_context.getOut();
    //  fmt:message
    org.apache.taglibs.standard.tag.rt.fmt.MessageTag _jspx_th_fmt_005fmessage_005f4 = (org.apache.taglibs.standard.tag.rt.fmt.MessageTag) _005fjspx_005ftagPool_005ffmt_005fmessage_0026_005fkey_005fnobody
            .get(org.apache.taglibs.standard.tag.rt.fmt.MessageTag.class);
    _jspx_th_fmt_005fmessage_005f4.setPageContext(_jspx_page_context);
    _jspx_th_fmt_005fmessage_005f4.setParent((javax.servlet.jsp.tagext.Tag) _jspx_th_c_005fif_005f0);
    // /WEB-INF/pages/includes/topmenu.jsp(52,32) name = key type = null reqTime = true required = false fragment = false deferredValue = false expectedTypeName = null deferredMethod = false methodSignature = null
    _jspx_th_fmt_005fmessage_005f4.setKey("pamelaChu.menu.presentation");
    int _jspx_eval_fmt_005fmessage_005f4 = _jspx_th_fmt_005fmessage_005f4.doStartTag();
    if (_jspx_th_fmt_005fmessage_005f4.doEndTag() == javax.servlet.jsp.tagext.Tag.SKIP_PAGE) {
        _005fjspx_005ftagPool_005ffmt_005fmessage_0026_005fkey_005fnobody.reuse(_jspx_th_fmt_005fmessage_005f4);
        return true;
    }//from   w  w  w .j av a2 s . c  o  m
    _005fjspx_005ftagPool_005ffmt_005fmessage_0026_005fkey_005fnobody.reuse(_jspx_th_fmt_005fmessage_005f4);
    return false;
}

From source file:org.apache.jsp.WEB_002dINF.pages.includes.topmenu_jsp.java

private boolean _jspx_meth_fmt_005fmessage_005f5(javax.servlet.jsp.tagext.JspTag _jspx_th_c_005fif_005f0,
        javax.servlet.jsp.PageContext _jspx_page_context) throws java.lang.Throwable {
    javax.servlet.jsp.PageContext pageContext = _jspx_page_context;
    javax.servlet.jsp.JspWriter out = _jspx_page_context.getOut();
    //  fmt:message
    org.apache.taglibs.standard.tag.rt.fmt.MessageTag _jspx_th_fmt_005fmessage_005f5 = (org.apache.taglibs.standard.tag.rt.fmt.MessageTag) _005fjspx_005ftagPool_005ffmt_005fmessage_0026_005fkey_005fnobody
            .get(org.apache.taglibs.standard.tag.rt.fmt.MessageTag.class);
    _jspx_th_fmt_005fmessage_005f5.setPageContext(_jspx_page_context);
    _jspx_th_fmt_005fmessage_005f5.setParent((javax.servlet.jsp.tagext.Tag) _jspx_th_c_005fif_005f0);
    // /WEB-INF/pages/includes/topmenu.jsp(58,32) name = key type = null reqTime = true required = false fragment = false deferredValue = false expectedTypeName = null deferredMethod = false methodSignature = null
    _jspx_th_fmt_005fmessage_005f5.setKey("pamelaChu.menu.tos");
    int _jspx_eval_fmt_005fmessage_005f5 = _jspx_th_fmt_005fmessage_005f5.doStartTag();
    if (_jspx_th_fmt_005fmessage_005f5.doEndTag() == javax.servlet.jsp.tagext.Tag.SKIP_PAGE) {
        _005fjspx_005ftagPool_005ffmt_005fmessage_0026_005fkey_005fnobody.reuse(_jspx_th_fmt_005fmessage_005f5);
        return true;
    }//from   ww  w . j a  v  a  2  s .c  o m
    _005fjspx_005ftagPool_005ffmt_005fmessage_0026_005fkey_005fnobody.reuse(_jspx_th_fmt_005fmessage_005f5);
    return false;
}