Example usage for javax.servlet.jsp JspWriter print

List of usage examples for javax.servlet.jsp JspWriter print

Introduction

In this page you can find the example usage for javax.servlet.jsp JspWriter print.

Prototype


abstract public void print(Object obj) throws IOException;

Source Link

Document

Print an object.

Usage

From source file:org.opencms.frontend.templateone.CmsTemplateNavigation.java

/**
 * Builds the html for the inclusion of the editable element under the left navigation tree.<p>
 * /*from  ww  w  . j  av  a 2 s . c  om*/
 * @throws IOException if writing the output fails
 * @throws JspException if including the element fails
 */
public void buildNavLeftIncludeElement() throws IOException, JspException {

    JspWriter out = getJspContext().getOut();
    if (showNavLeftElement()) {
        out.print(
                "\t<div style=\"line-height: 1px; font-size: 1px; display: block; height: 4px;\">&nbsp;</div>\n");
        include(getNavLeftElementUri(), "text1", true);
    } else if (!showNavLeftTree()) {
        // none of the left navigation elements is shown, add a non breaking space to avoid html display errors
        out.print("&nbsp;");
    }
}

From source file:org.opencms.workplace.galleries.A_CmsAjaxGallery.java

/**
 * Builds the JSON code for the category list as JSON array.<p>
 *///from w w w.  j  a  va2  s .  c  o  m
protected void buildJsonCategoryList() {

    CmsCategoryService catService = CmsCategoryService.getInstance();
    List<CmsCategory> foundCategories = Collections.emptyList();
    String editedResource = null;
    if (CmsStringUtil.isNotEmpty(getParamResource())) {
        editedResource = getParamResource();
    }
    try {
        foundCategories = catService.readCategories(getCms(), "", true, editedResource);
    } catch (CmsException e) {
        // error reading categories
    }

    // the next lines sort the categories according to their path 
    Map<String, CmsCategory> sorted = new TreeMap<String, CmsCategory>();

    Iterator<CmsCategory> i = foundCategories.iterator();
    while (i.hasNext()) {
        CmsCategory category = i.next();
        String categoryPath = category.getPath();
        if (sorted.get(categoryPath) != null) {
            continue;
        }
        sorted.put(categoryPath, category);
    }

    foundCategories = new ArrayList<CmsCategory>(sorted.values());
    JSONArray categories = new JSONArray();
    i = foundCategories.iterator();
    while (i.hasNext()) {
        CmsCategory cat = i.next();

        JSONObject jsonObj = new JSONObject();
        try {
            // 1: category title
            jsonObj.put("title", cat.getTitle());
            // 2: category path
            jsonObj.put("path", cat.getPath());
            // 3: category root path
            jsonObj.put("rootpath", cat.getRootPath());
            // 4 category level
            jsonObj.put("level", CmsResource.getPathLevel(cat.getPath()));
            // 4: active flag
            jsonObj.put("active", false);
            categories.put(jsonObj);
        } catch (JSONException e) {
            // TODO: error handling
        }
    }
    JspWriter out = getJsp().getJspContext().getOut();
    try {
        out.print(categories.toString());
    } catch (IOException e) {
        if (LOG.isErrorEnabled()) {
            LOG.error(e.getLocalizedMessage(), e);
        }
    }

}

From source file:org.opencms.workplace.galleries.A_CmsAjaxGallery.java

/**
 * Builds the JSON code for the gallery list as JSON array.<p>
 *///from   w w  w . j  av a  2  s.  c  o m
protected void buildJsonGalleryList() {

    String lastUsed = getSettings().getLastUsedGallery(getGalleryTypeId());
    // check the value of last Used, if gallery is opened for the first time
    if (CmsStringUtil.isEmpty(lastUsed)) {
        // start gallery settings for this gallery type for the current user
        String startGallerySetting = getSettings().getUserSettings().getStartGallery(getGalleryTypeName(),
                getCms());
        if (startGallerySetting != null) {
            // handle the case, "global settings" are selected
            if (startGallerySetting.equals(CmsPreferences.INPUT_DEFAULT)) {
                // get selected value from workplace xml settings
                String preselectedValue = OpenCms.getWorkplaceManager().getDefaultUserSettings()
                        .getStartGallery(getGalleryTypeName());
                if (preselectedValue != null) {
                    startGallerySetting = preselectedValue;
                }
            }
            // checks if the resource exists
            String sitePath = getCms().getRequestContext().removeSiteRoot(startGallerySetting);
            if (getCms().existsResource(sitePath)) {
                lastUsed = sitePath;
            }
        }
    }
    JSONArray galleries = new JSONArray();
    Iterator<CmsResource> i = getGalleries().iterator();
    boolean isFirst = true;
    while (i.hasNext()) {
        CmsResource res = i.next();
        String path = getCms().getSitePath(res);
        JSONObject jsonObj = new JSONObject();
        // 1: gallery title
        String title = "";
        try {
            // read the gallery title
            title = getCms().readPropertyObject(path, CmsPropertyDefinition.PROPERTY_TITLE, false).getValue("");
        } catch (CmsException e) {
            // error reading title property
            if (LOG.isErrorEnabled()) {
                LOG.error(e.getLocalizedMessage(), e);
            }
        }
        try {
            jsonObj.put("title", title);
            // 2: gallery path
            jsonObj.put("path", path);
            // 3: active flag
            boolean active = false;
            if ((CmsStringUtil.isEmpty(lastUsed) && isFirst) || path.equals(lastUsed)) {
                // TODO: adjust logic to get active gallery
                active = true;
            }
            jsonObj.put("active", active);
            galleries.put(jsonObj);
        } catch (JSONException e) {
            if (LOG.isErrorEnabled()) {
                LOG.error(e.getLocalizedMessage(), e);
            }
        }
        isFirst = false;
    }
    JspWriter out = getJsp().getJspContext().getOut();
    try {
        out.print(galleries.toString());
    } catch (IOException e) {
        if (LOG.isErrorEnabled()) {
            LOG.error(e.getLocalizedMessage(), e);
        }
    }
}

From source file:org.opencms.workplace.galleries.A_CmsAjaxGallery.java

/**
 * Builds the Javascript to set the currently active item object.<p>
 * /*  w w w  .  j  av  a2 s .  c o m*/
 * @param itemUrl the URL of the currently selected item
 */
protected void buildJsonActiveItem(String itemUrl) {

    if (itemUrl.startsWith(OpenCms.getSiteManager().getWorkplaceServer())) {
        // remove workplace server prefix
        itemUrl = itemUrl.substring(OpenCms.getSiteManager().getWorkplaceServer().length());
    }
    if (itemUrl.startsWith(OpenCms.getSystemInfo().getOpenCmsContext())) {
        // remove context prefix to read resource from VFS
        itemUrl = itemUrl.substring(OpenCms.getSystemInfo().getOpenCmsContext().length());
    }
    try {
        JspWriter out = getJsp().getJspContext().getOut();
        if (getCms().existsResource(itemUrl)) {
            try {
                out.print(buildJsonItemObject(getCms().readResource(itemUrl)));
            } catch (CmsException e) {
                // can not happen in theory, because we used existsResource() before...
            }
        } else {
            out.print(RETURNVALUE_NONE);
        }
    } catch (IOException e) {
        if (LOG.isErrorEnabled()) {
            LOG.error(e.getLocalizedMessage(), e);
        }
    }
}

From source file:org.opencms.workplace.galleries.A_CmsAjaxGallery.java

/**
 * Builds the JSON code to create items for the folder.<p>
 * /*from  www .j a  v a 2s.  co m*/
 * @param resourceitems the file resource to build the displayed items
 * @param parentFolder the parent folder of the collected files (for a gallery)
 */
protected void buildJsonResourceItems(List<CmsResource> resourceitems, String parentFolder) {

    if (resourceitems == null) {
        resourceitems = new ArrayList<CmsResource>();
    }

    boolean isPublishEnabled = false;
    boolean hasDirectPublish = false;
    boolean hasWritePermission = false;
    if (CmsStringUtil.isNotEmpty(parentFolder)) {
        // check if there are changes in the currently selected gallery and the user has direct edit permissions
        try {
            if ((OpenCms.getPublishManager()
                    .getPublishList(getCms(), getCms().readResource(parentFolder), false).size() > 0)) {
                isPublishEnabled = true;
            }
        } catch (CmsException e) {
            // ignore, gallery can not be published
        }
        // check if the user has direst publish permissions, 
        // used to enable the gallerypublish button, if user has enough permissions
        try {
            if (getCms().hasPermissions(getCms().readResource(parentFolder),
                    CmsPermissionSet.ACCESS_DIRECT_PUBLISH, false, CmsResourceFilter.ALL)) {
                hasDirectPublish = true;
            }
        } catch (CmsException e) {
            // ignore, no publish permissions for gallery  
        }
        try {
            // check if the user has write permissions,
            // used to display the upload buttons
            if (getCms().hasPermissions(getCms().readResource(parentFolder), CmsPermissionSet.ACCESS_WRITE,
                    false, CmsResourceFilter.ALL)) {
                hasWritePermission = true;
            }
        } catch (CmsException e) {
            // ignore, no write permissions for gallery
        }
    }
    JSONObject publishInfo = new JSONObject();
    try {
        publishInfo.put("publishable", isPublishEnabled);
        publishInfo.put("directpublish", hasDirectPublish);
        publishInfo.put("writepermission", hasWritePermission);
    } catch (JSONException e) {
        // ignore
    }
    JSONArray items = new JSONArray();
    items.put(publishInfo);
    Iterator<CmsResource> i = resourceitems.iterator();
    while (i.hasNext()) {
        CmsResource res = i.next();
        // build a JSON object from the item and add it to the list
        items.put(buildJsonItemObject(res));
    }
    JspWriter out = getJsp().getJspContext().getOut();
    try {
        // print the JSON array
        out.print(items.toString());
    } catch (IOException e) {
        if (LOG.isErrorEnabled()) {
            LOG.error(e.getLocalizedMessage(), e);
        }
    }
}

From source file:org.opencms.frontend.templateone.CmsTemplateBean.java

/**
 * Includes the page elements if they are present.<p>
 * /*from  w w w  .  ja  va2s .c o m*/
 * The page elements are layouted in a 4 row, 2 columns layout.
 * If one element of a single row is missing, the present element
 * will be spanned across the 2 columns.<p>
 * 
 * @throws IOException if writing the output fails
 * @throws JspException if including an element fails
 */
public void includeElements() throws IOException, JspException {

    // check if elements to show are present 
    boolean elementsPresent = template("text1,text2,text3,text4,text5,text6,text7,text8", false);

    // get the list(s) of content items to display between elements
    String configFile = (String) getProperties().get(PROPERTY_LAYOUT_CENTER);
    List contents = new ArrayList();
    if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(configFile) && !PROPERTY_VALUE_NONE.equals(configFile)) {
        // get the content list(s) for the center area
        contents = getContentListItems(configFile, CmsTemplateContentListItem.DISPLAYAREA_CENTER);
    }
    // determine if list can show page links
    int size = contents.size();
    boolean showPageLinks = true;
    if (size > 1) {
        // more than one list is displayed, do not show page links on lists
        showPageLinks = false;
    }

    if (elementsPresent || size > 0) {
        // at least one element or list is present, create writer        
        JspWriter out = getJspContext().getOut();
        String elementName = FOLDER_ELEMENTS + "elements.jsp";
        // create start part (common layout only)
        out.print(getTemplateParts().includePart(elementName, "start", getLayout(), this));

        // calculate start point for content lists
        int startPoint = 3 - size;
        int listIndex = 0;
        for (int i = 0; i < 4; i++) {
            int elementIndex = (i * 2) + 1;
            // include the element row
            includeContentRow("text" + (elementIndex), "text" + (elementIndex + 1), out);
            if ((listIndex < size) && (i >= startPoint)) {
                // include the list item
                CmsTemplateContentListItem item = (CmsTemplateContentListItem) contents.get(listIndex);
                out.print(getTemplateParts().includePart(elementName, "column_start", getLayout(), this));
                out.print(getTemplateParts().includePart(elementName, "element_start_1", getLayout(), this));
                item.includeListItem(this, showPageLinks);
                out.print(getTemplateParts().includePart(elementName, "element_end", getLayout(), this));
                out.print(getTemplateParts().includePart(elementName, "column_end", getLayout(), this));
                listIndex++;
            }
        }
        // create end part (common layout only)
        out.print(getTemplateParts().includePart(elementName, "end", getLayout(), this));
    }
}

From source file:jp.terasoluna.fw.web.taglib.WriteCodeValueTag.java

/**
 * ^O]Jn?\bh?B/*from  w w  w  .  j a  v  a2s.  c  o  m*/
 *
 * <p>
 * T?[ubgReLXg?AApplicationContext?A
 * &quot;codeList&quot; ?w id
 *  CodeListLoader ?AR?[hXg
 * l?A?o?B
 * &quot;key&quot; ?w?AL?[l?A
 * w?A&quot;name&quot; ?wbean
 * L?[p?B
 *
 * R?[hXg???A
 * L?[????A?o?B
 * </p>
 *
 * @return ???w?B? EVAL_BODY_INCLUDE
 * @throws JspException JSP O
 */
@Override
public int doStartTag() throws JspException {
    if (log.isDebugEnabled()) {
        log.debug("doStartTag() called.");
    }

    if ("".equals(codeList) || codeList == null) {
        // codeListw??
        log.error("codeList is required.");
        throw new JspTagException("codeList is required.");
    }

    if (key == null && name == null) {
        // keynamew??
        log.error("key and name is required.");
        throw new JspTagException("key and name is required.");
    }

    String codeKey = null;

    if ((key == null) && (name != null)) {
        if (TagUtil.lookup(pageContext, name, scope) == null) {
            log.error("bean id:" + name + " is not defined.");
            throw new JspTagException("bean id:" + name + " is not defined.");
        }
        Object bean = null;
        try {
            bean = TagUtil.lookup(pageContext, name, property, scope);
        } catch (JspException e) {
            // 
        }
        if (bean == null) {
            log.error("Cannot get property[" + name + "." + property + "].");
            throw new JspTagException("Cannot get property[" + name + "." + property + "].");
        }
        codeKey = bean.toString();
    } else {
        codeKey = key;
    }

    // T?[ubgReLXg?AApplicationContext?B
    ServletContext sc = pageContext.getServletContext();
    ApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);

    CodeListLoader loader = null;

    if (context.containsBean(codeList)) {
        try {
            loader = (CodeListLoader) context.getBean(codeList);
        } catch (ClassCastException e) {
            // BeanCodeListLoaderOX??[
            String errorMessage = "bean id:" + codeList + " is not instance of CodeListLoader.";
            log.error(errorMessage);
            throw new JspTagException(errorMessage, e);
        }
    }

    JspWriter out = pageContext.getOut();

    if (loader == null) {
        log.error("CodeListLoader:" + codeList + " is not defined.");
        throw new JspTagException("CodeListLoader:" + codeList + " is not defined.");
    }

    // ?P?[
    Locale locale = RequestUtils.getUserLocale((HttpServletRequest) pageContext.getRequest(),
            Globals.LOCALE_KEY);

    CodeBean[] codeBeanArray = loader.getCodeBeans(locale);
    if (codeBeanArray == null) {
        // codeBeanListnull??
        if (log.isWarnEnabled()) {
            log.warn("Codebean is null. CodeListLoader(bean id:" + codeList + ")");
        }
        // 
    } else {
        try {
            // ????R?[hXgl?o?B
            for (int i = 0; i < codeBeanArray.length; i++) {
                if (codeKey.equals(codeBeanArray[i].getId())) {
                    out.print(codeBeanArray[i].getName());
                    break;
                }
            }
            // 
        } catch (IOException ioe) {
            log.error("", ioe);
            throw new JspTagException(ioe);
        }

    }

    return EVAL_BODY_INCLUDE;
}

From source file:org.opencms.workplace.galleries.A_CmsAjaxGallery.java

/**
 * Changes the title property value of the given item.<p>
 * /*from w  w w .  j a v  a2s  . co m*/
 * @param itemUrl the item URL on which the title is changed
 */
protected void changeItemTitle(String itemUrl) {

    try {
        JspWriter out = getJsp().getJspContext().getOut();
        if (getCms().existsResource(itemUrl)) {
            try {
                writeTitleProperty(getCms().readResource(itemUrl));
                out.print(buildJsonItemObject(getCms().readResource(itemUrl)));
            } catch (CmsException e) {
                // can not happen in theory, because we used existsResource() before...
            }
        } else {
            out.print(RETURNVALUE_NONE);
        }
    } catch (IOException e) {
        if (LOG.isErrorEnabled()) {
            LOG.error(e.getLocalizedMessage(), e);
        }
    }
}

From source file:org.opencms.frontend.templateone.CmsTemplateBean.java

/**
 * Includes one row of page elements.<p>
 * // www  .  j ava2 s . co  m
 * Builds a row with one element spanning the row or
 * with two elements in different cells  depending on the
 * presence of the elements.<p>
 * 
 * @param elementLeft the name of the left element to show
 * @param elementRight the name of the right element to show
 * @param out the Writer to write the output to
 * @throws IOException if writing the output fails
 * @throws JspException if including an element fails
 */
private void includeContentRow(String elementLeft, String elementRight, JspWriter out)
        throws IOException, JspException {

    if (template(elementLeft + "," + elementRight, false)) {
        // at least one element is present, create row (common layout only)
        String elementName = FOLDER_ELEMENTS + "elements.jsp";
        out.print(getTemplateParts().includePart(elementName, "column_start", getLayout(), this));

        if (template(elementLeft, true)) {
            // left element is present
            if (template(elementRight, true)) {
                // right element is present, too
                out.print(getTemplateParts().includePart(elementName, "element_start_2", getLayout(), this));
            } else {
                // no right element
                out.print(getTemplateParts().includePart(elementName, "element_start_1", getLayout(), this));
            }
            include(null, elementLeft, true);
            out.print(getTemplateParts().includePart(elementName, "element_end", getLayout(), this));
        }
        if (template(elementRight, true)) {
            // right element is present
            if (template(elementLeft, true)) {
                // left element is present, too
                out.print(getTemplateParts().includePart(elementName, "element_start_2", getLayout(), this));
            } else {
                // no left element
                out.print(getTemplateParts().includePart(elementName, "element_start_1", getLayout(), this));
            }
            include(null, elementRight, true);
            out.print(getTemplateParts().includePart(elementName, "element_end", getLayout(), this));
        }
        // close row (common layout only)
        out.print(getTemplateParts().includePart(elementName, "column_end", getLayout(), this));
    }
}

From source file:no.kantega.commons.taglib.util.LabelTag.java

public int doStartTag() throws JspException {
    JspWriter out;
    try {/*from w  w w  .j a v a2s  . co  m*/
        out = pageContext.getOut();
        HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
        if (key != null) {
            Locale locale;
            if (isNotBlank(this.locale)) {
                String[] localePair = this.locale.split("_");
                if (localePair.length == 2) {
                    locale = new Locale(localePair[0], localePair[1]);
                } else {
                    locale = new Locale(localePair[0]);
                }
            } else {
                locale = LocaleLabels.getLocaleFromRequestOrDefault(request);
            }

            String textLabel = "";
            // Try site-bundle first, so that the project may overwrite properties from DEFAULT_BUNDLE
            if (bundle.equals(LocaleLabels.DEFAULT_BUNDLE)) {
                textLabel = LocaleLabels.getLabel(key, "site", locale, params);
            }
            if (!bundle.equals(LocaleLabels.DEFAULT_BUNDLE) || textLabel.equals(key)) {
                textLabel = LocaleLabels.getLabel(key, bundle, locale, params);
            }
            if (escapeJavascript) {
                textLabel = JavaScriptUtils.javaScriptEscape(textLabel);
            }
            out.print(textLabel);
        } else {
            out.print("ERROR: LabelTag, missing key " + key);
        }
        params = null;
        escapeJavascript = false;
        key = null;
        bundle = LocaleLabels.DEFAULT_BUNDLE;
        locale = null;
    } catch (IOException e) {
        throw new JspException("ERROR: LabelTag:" + e.getMessage(), e);
    }

    return SKIP_BODY;
}