cmslayoutpagebean.java

来自「找了很久才找到到源代码」· Java 代码 · 共 1,164 行 · 第 1/3 页

JAVA
1,164
字号
                    xmlContentFileLink = CmsXmlContentFactory.unmarshal(getCmsObject(), linkToFile);
                    xmlElementsProperties = getXmlElementsProperties(linkToFile);
                } catch (Exception e) {
                    // if reading of external file fails the external file will be ignored
                    hasFileLink = false;
                }
            }
            
            // get the optional headline
            String headline = "";
            if (m_content.hasValue(xPath + NODE_HEADLINE, locale)) {
                headline = m_content.getStringValue(getCmsObject(), xPath + NODE_HEADLINE, locale);
            }
            // if headline is empty try to get it from the integrated xml content
            if (CmsStringUtil.isEmptyOrWhitespaceOnly(headline)) {
                if (hasFileLink) {
                    String titleValue = this.getPropertiesValue(
                        xmlElementsProperties,
                        KEY_HEADLINE,
                        xmlContentFileLink,
                        locale);
                    if (!CmsStringUtil.isEmptyOrWhitespaceOnly(titleValue)) {
                        // if titleValue is not empty set the headline to this value and build a link
                        // to the integrated file around it 
                        headline = "<a title=\""
                            + titleValue
                            + "\" href=\""
                            + m_jspActionElement.link(m_content.getStringValue(
                                getCmsObject(),
                                xPath + NODE_FILELINK,
                                locale))
                            + "\" target=\"_self\">"
                            + titleValue
                            + "</a>";
                    } else {
                        headline = "";
                    }
                } else {
                    headline = "";
                }
            }

            // get the paragraph text value
            String textValue = m_content.getStringValue(getCmsObject(), xPath + NODE_TEXT, locale);
            
            if (CmsStringUtil.isEmptyOrWhitespaceOnly(textValue)) {
                if (hasFileLink) {
                    String text = getPropertiesValue(xmlElementsProperties, KEY_TEXTVALUE, xmlContentFileLink, locale);
                    if (!CmsStringUtil.isEmptyOrWhitespaceOnly(text)) {
                        // if text is not empty set textValue to it, trim the size and
                        // append a link to the integrated file
                        textValue = text;
                        textValue = CmsStringUtil.trimToSize(textValue, 250);
                        textValue += "<a href=\""
                            + m_jspActionElement.link(m_content.getStringValue(
                                getCmsObject(),
                                xPath + NODE_FILELINK,
                                locale))
                            + "\" target=\"_self\">&gt; "
                            + messages.keyDefault("link.more", "")
                            + "</a>";
                    } else {
                        textValue = "";
                    }
                } else {
                    textValue = "";
                }
            }

            // process optional image
            xPath += NODE_IMAGE + "/";
            String imgDesc = "";
            String paragraphType = "";
            String imgTag = "";
            String imgUrl = "";
            int imgWidth = getColumnWidth();
            boolean imagePresent = false;

            if (m_content.hasValue(xPath, locale)) {
                // image node found, check VFS presence by reading image size property
                String imgUri = m_content.getStringValue(getCmsObject(), xPath + NODE_IMAGE, locale);
                
                if (CmsStringUtil.isEmptyOrWhitespaceOnly(imgUri)) {
                    if (hasFileLink) {
                        String imgValue = getPropertiesValue(
                            xmlElementsProperties,
                            KEY_IMGURI,
                            xmlContentFileLink,
                            locale);
                        if (!CmsStringUtil.isEmptyOrWhitespaceOnly(imgValue)) {
                            imgUri = imgValue;
                        } else {
                            imgUri = "";
                        }
                    } else {
                        imgUri = "";
                    }
                }
                
                String imgSize = null;
                try {
                    imgSize = getCmsObject().readPropertyObject(
                        imgUri,
                        CmsPropertyDefinition.PROPERTY_IMAGE_SIZE,
                        false).getValue();
                } catch (CmsException e) {
                    // file property not found, ignore
                }
                if (imgSize != null) {
                    // image exists, create image tag to show
                    imagePresent = true;
                    if (m_content.hasValue(xPath + NODE_DESCRIPTION, locale)) {
                        // get image description
                        imgDesc = m_content.getStringValue(getCmsObject(), xPath + NODE_DESCRIPTION, locale);
                    }
                    paragraphType = m_content.getStringValue(getCmsObject(), xPath + NODE_ALIGN, locale);
                    // get initialized image scaler for the image                   
                    CmsImageScaler scaler = getImageScaler(paragraphType, imgSize);
                    imgWidth = scaler.getWidth();

                    // determine image description String to show
                    String imgTitle = imgDesc;
                    if (showImgLinks) {
                        // append localized note for large image link to description
                        StringBuffer tempImgTitle = new StringBuffer(128);
                        tempImgTitle.append(imgDesc);
                        if (CmsStringUtil.isNotEmpty(imgDesc)) {
                            tempImgTitle.append(" ");
                        }
                        tempImgTitle.append(imgLinkTitleLocalized);
                        imgTitle = tempImgTitle.toString();
                    }

                    // create image tag with additional "alt", "title" and "border" attributes
                    Map attrs = new HashMap(4);
                    attrs.put("alt", imgTitle);
                    attrs.put("title", imgTitle);
                    attrs.put("border", "0");
                    imgTag = getCmsJspActionElement().img(imgUri, scaler, attrs);

                    // create link around image if configured
                    macros.putContextVariable(MACRO_IMAGE, imgTag);
                    if (showImgLinks) {
                        // use macro with link
                        imgUrl = getLinkToLargeImage(imgUri, imgSize);
                        macros.putContextVariable(MACRO_TITLE, imgTitle);
                        macros.putContextVariable(MACRO_TARGET, imgUrl);
                        imgTag = macros.getResult("image_with_link");
                    } else {
                        // use macro without link
                        imgTag = macros.getResult("image_without_link");
                    }

                }
            }

            macros.putContextVariable(MACRO_DESCRIPTION, imgDesc);
            if (imagePresent && showImgLinks) {
                // use description with link to image
                macros.putContextVariable(MACRO_TITLE, imgLinkTitleLocalized);
                macros.putContextVariable(MACRO_TARGET, imgUrl);
                imgDesc = macros.getResult("description_with_link");
            } else {
                // use description without link to image
                imgDesc = macros.getResult("description_without_link");
            }

            if (CmsStringUtil.isEmpty(paragraphType)) {
                // set default paragraph display type (in case no image was found)
                paragraphType = PARAGRAPH_TYPE_TEXT_ONLY;
            }

            // create paragraph output

            if (firstInRow || !showTwoCols) {
                // open row (tr) 
                result.append(macros.getResult("row_start"));
            }

            // open td
            result.append(macros.getResult("element_start"));

            // put macro variables in context to use for this paragraph
            macros.putContextVariable(MACRO_HEADLINE, headline);
            macros.putContextVariable(MACRO_TEXT, textValue);
            macros.putContextVariable(MACRO_IMAGE, imgTag);
            macros.putContextVariable(MACRO_IMAGE_WIDTH, new Integer(imgWidth));
            macros.putContextVariable(MACRO_DESCRIPTION, imgDesc);
            // add resolved macro layout paragraph to result
            result.append(macros.getResult(paragraphType));

            // close td
            result.append(macros.getResult("element_end"));

            if (!showTwoCols || !firstInRow || (firstInRow && !i.hasNext())) {
                if (showTwoCols && firstInRow && !i.hasNext()) {
                    // append additional empty dummy element in two column mode
                    result.append(macros.getResult("element_start"));
                    result.append(macros.getResult("element_end"));
                }
                // close row (tr)
                result.append(macros.getResult("row_end"));
            }

            firstInRow = !firstInRow;
        }

        // close column table
        result.append(macros.getResult("content_end"));

        return result.toString();
    }

    /**
     * Fills the default paragraph layout patterns to show.<p>
     */
    public void createDefaultLayoutPatterns() {

        m_layoutPatterns.put(PARAGRAPH_TYPE_BOTTOM, IMG_WIDTH_LARGE);
        m_layoutPatterns.put(PARAGRAPH_TYPE_BOTTOM_DESCRIPTION, IMG_WIDTH_LARGE);
        m_layoutPatterns.put(PARAGRAPH_TYPE_TOP, IMG_WIDTH_LARGE);
        m_layoutPatterns.put(PARAGRAPH_TYPE_TOP_DESCRIPTION, IMG_WIDTH_LARGE);
        m_layoutPatterns.put(PARAGRAPH_TYPE_IMAGE_LEFT, IMG_WIDTH_MEDIUM);
        m_layoutPatterns.put(PARAGRAPH_TYPE_IMAGE_LEFT_DESCRIPTION, IMG_WIDTH_MEDIUM);
        m_layoutPatterns.put(PARAGRAPH_TYPE_IMAGE_RIGHT, IMG_WIDTH_MEDIUM);
        m_layoutPatterns.put(PARAGRAPH_TYPE_IMAGE_RIGHT_DESCRIPTION, IMG_WIDTH_MEDIUM);
        m_layoutPatterns.put(PARAGRAPH_TYPE_IMAGE_LEFT_TEXT_RIGHT, IMG_WIDTH_SMALL);
        m_layoutPatterns.put(PARAGRAPH_TYPE_IMAGE_LEFT_TEXT_RIGHT_DESCRIPTION, IMG_WIDTH_SMALL);
        m_layoutPatterns.put(PARAGRAPH_TYPE_IMAGE_RIGHT_TEXT_LEFT, IMG_WIDTH_SMALL);
        m_layoutPatterns.put(PARAGRAPH_TYPE_IMAGE_RIGHT_TEXT_LEFT_DESCRIPTION, IMG_WIDTH_SMALL);
    }

    /**
     * Returns the width of the content area of the template.<p>
     *
     * @return the width of the content area of the template
     */
    public int getBodyWidth() {

        return m_bodyWdith;
    }

    /**
     * Returns the padding of the columns in the content area.<p>
     *
     * @return the padding of the columns in the content area
     */
    public int getColPadding() {

        return m_colPadding;
    }

    /**
     * Returns the spacing of the columns in the content area.<p>
     *
     * @return the spacing of the columns in the content area
     */
    public int getColSpacing() {

        return m_colSpacing;
    }

    /**
     * Returns the column layout of the parapgraphs in the content area.<p>
     *
     * @return the column layout of the parapgraphs in the content area
     */
    public String getColumnLayout() {

        return m_columnLayout;
    }

    /**
     * Returns the calculated width of a single paragraph column.<p>
     *
     * @return the calculated width of a single paragraph column
     */
    public int getColumnWidth() {

        return m_columnWidth;
    }

    /**
     * Returns the XML content that stores the layout.<p>
     *
     * @return the XML content that stores the layout
     */
    public CmsXmlContent getContent() {

        return m_content;
    }

    /**
     * Returns the image width to use for large images in fixed image size mode.<p>
     *
     * @return the image width to use for large images in fixed image size mode
     */
    public int getImgWidthLarge() {

        return m_imgWidthLarge;
    }

    /**
     * Returns the image width to use for medium images in fixed image size mode.<p>
     *
     * @return the image width to use for medium images in fixed image size mode
     */
    public int getImgWidthMedium() {

        return m_imgWidthMedium;
    }

    /**
     * Returns the image width to use for small images in fixed image size mode.<p>
     *
     * @return the image width to use for small images in fixed image size mode
     */
    public int getImgWidthSmall() {

        return m_imgWidthSmall;
    }

    /**
     * Returns the layout patterns with the layout name as key, the value is the corresponding image width.<p>
     * 
     * @return the layout patterns with the layout name as key, the value is the corresponding image width
     */
    public Map getLayoutPatterns() {

        return m_layoutPatterns;
    }

    /**
     * Returns the VFS path to the html snippet files to include to render the layout paragraphs.<p>
     * 
     * @return the VFS path to the html snippet files to include to render the layout paragraphs
     */
    public String getPathLayoutElements() {

        return m_pathLayoutElements;
    }

    /**
     * Returns the layout variant to show, e.g. "common", "print" or "accessibe".<p>
     *
     * @return the layout variant to show, e.g. "common", "print" or "accessibe"
     */
    public String getVariant() {

        return m_variant;
    }

    /**
     * Initialize this bean with the OpenCms user context, the XML content, the layout variant and width information.<p>
     * 
     * It is required to call either the init() method or set the members manually before you can use the 
     * instance of this bean.
     * 
     * @param jsp the current JSP action element
     * @param content the XML content that configures the layout
     * @param variant the layout variant to show, e.g. "common", "print" or "accessibe"
     * @param bodyWith the width of the content area of the template
     * @param colPadding the padding of the columns in the content area
     * @param colSpacing the spacing of the columns in the content area
     */
    public void init(
        CmsJspActionElement jsp,
        CmsXmlContent content,
        String variant,
        int bodyWith,
        int colPadding,
        int colSpacing) {

        // set default path to html snippet files to use
        setPathLayoutElements(VFS_PATH_LAYOUTELEMENTS);
        // set CmsObject
        setCmsJspActionElement(jsp);
        // set layout configuration XML content file
        setContent(content);
        // set the variant to display
        setVariant(variant);

        // set column layout defined in content
        String layout = m_content.getStringValue(
            getCmsObject(),
            NODE_COLUMNS_LAYOUT,
            jsp.getRequestContext().getLocale());
        if (CmsStringUtil.isEmptyOrWhitespaceOnly(layout)) {

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?