cmsjsptagcontentload.java

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

JAVA
918
字号
        m_directEditMode = null;
        m_isFirstLoop = false;
        m_locale = null;
        m_pageIndex = null;
        m_pageNavLength = null;
        m_pageSize = null;
        m_param = null;
        m_preload = false;
        m_property = null;
        m_resourceName = null;
        super.release();
    }

    /**
     * Sets the collector.<p>
     *
     * @param collector the collector to set
     */
    public void setCollector(String collector) {

        m_collector = collector;
    }

    /**
     * Sets the editable mode.<p>
     * 
     * @param mode the mode to set
     */
    public void setEditable(String mode) {

        m_directEditMode = CmsDirectEditMode.valueOf(mode);
    }

    /**
     * Sets the locale.<p>
     *
     * @param locale the locale to set
     */
    public void setLocale(String locale) {

        if (CmsStringUtil.isEmpty(locale)) {
            m_locale = null;
            m_contentLocale = null;
        } else {
            m_locale = CmsLocaleManager.getLocale(locale);
            m_contentLocale = m_locale;
        }
    }

    /**
     * Sets the index of the page to be displayed.<p>
     * 
     * @param pageIndex the index of the page to be displayed
     */
    public void setPageIndex(String pageIndex) {

        m_pageIndex = pageIndex;
    }

    /**
     * Sets the number of page links in the Google-like page navigation.<p>
     * 
     * @param pageNavLength the number of page links in the Google-like page navigation
     */
    public void setPageNavLength(String pageNavLength) {

        m_pageNavLength = pageNavLength;
    }

    /**
     * Sets the size of a single page to be displayed.<p>
     * 
     * @param pageSize the size of a single page to be displayed
     */
    public void setPageSize(String pageSize) {

        m_pageSize = pageSize;
    }

    /**
     * Sets the collector parameter.<p>
     *
     * @param param the collector parameter to set
     */
    public void setParam(String param) {

        m_param = param;
    }

    /**
     * Sets the preload flag for this content load tag.<p> 
     * 
     * If this is set to <code>true</code>, then the collector result will only 
     * be preloaded, but not iterated.<p> 
     * 
     * @param preload the preload flag to set
     */
    public void setPreload(String preload) {

        m_preload = Boolean.valueOf(preload).booleanValue();
    }

    /**
     * Sets the property.<p>
     *
     * @param property the property to set
     */
    public void setProperty(String property) {

        m_property = property;
    }

    /**
     * Load the next file name from the initialized list of file names.<p>
     * 
     * @throws CmsException if something goes wrong
     */
    protected void doLoadNextFile() throws CmsException {

        // get the next resource from the collector
        CmsResource resource = getNextResource();
        if (resource == null) {
            m_resourceName = null;
            m_content = null;
            return;
        }

        // set the resource name
        m_resourceName = m_cms.getSitePath(resource);

        // upgrade the resource to a file
        CmsFile file = m_cms.readFile(resource);

        // unmarshal the XML content from the resource, don't use unmarshal(CmsObject, CmsResource) 
        // as no support for getting the historic version that has been cached by a CmsHistoryResourceHandler 
        // will come from there!
        m_content = CmsXmlContentFactory.unmarshal(m_cms, file, pageContext.getRequest());

        // check if locale is available
        m_contentLocale = m_locale;
        if (!m_content.hasLocale(m_contentLocale)) {
            Iterator it = OpenCms.getLocaleManager().getDefaultLocales().iterator();
            while (it.hasNext()) {
                Locale locale = (Locale)it.next();
                if (m_content.hasLocale(locale)) {
                    // found a matching locale
                    m_contentLocale = locale;
                    break;
                }
            }
        }
    }

    /**
     * Returns the content info bean.<p>
     * 
     * @return the content info bean
     */
    protected CmsContentInfoBean getContentInfoBean() {

        return m_contentInfoBean;
    }

    /**
     * Initializes this content load tag.<p> 
     * 
     * @param container the parent container (could be a preloader)
     * 
     * @throws JspException in case something goes wrong
     */
    protected void init(I_CmsXmlContentContainer container) throws JspException {

        // check if the tag contains a pageSize, pageIndex and pageNavLength attribute, or none of them
        int pageAttribCount = 0;
        pageAttribCount += CmsStringUtil.isNotEmpty(m_pageSize) ? 1 : 0;
        pageAttribCount += CmsStringUtil.isNotEmpty(m_pageIndex) ? 1 : 0;

        if ((pageAttribCount > 0) && (pageAttribCount < 2)) {
            throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_TAG_CONTENTLOAD_INDEX_SIZE_0));
        }

        I_CmsXmlContentContainer usedContainer;
        if (container == null) {
            // no preloading ancestor has been found
            usedContainer = this;
            if (CmsStringUtil.isEmpty(m_collector)) {
                // check if the tag contains a collector attribute
                throw new CmsIllegalArgumentException(Messages.get().container(
                    Messages.ERR_TAG_CONTENTLOAD_MISSING_COLLECTOR_0));
            }
            if (CmsStringUtil.isEmpty(m_param)) {
                // check if the tag contains a param attribute
                throw new CmsIllegalArgumentException(Messages.get().container(
                    Messages.ERR_TAG_CONTENTLOAD_MISSING_PARAM_0));
            }
        } else {
            // use provided container (preloading ancestor)
            usedContainer = container;
        }

        if (isPreloader()) {
            // always disable direct edit for preload
            m_directEditMode = CmsDirectEditMode.FALSE;
        } else if (m_directEditMode == null) {
            // direct edit mode must not be null
            m_directEditMode = CmsDirectEditMode.FALSE;
        }

        // initialize OpenCms access objects
        m_controller = CmsFlexController.getController(pageContext.getRequest());
        m_cms = m_controller.getCmsObject();

        // get the resource name from the selected container
        String resourcename = getResourceName(m_cms, usedContainer);

        // initialize a string mapper to resolve EL like strings in tag attributes
        CmsMacroResolver resolver = CmsMacroResolver.newInstance().setCmsObject(m_cms).setJspPageContext(pageContext).setResourceName(
            resourcename).setKeepEmptyMacros(true);

        // resolve the collector name
        if (container == null) {
            // no preload parent container, initialize new values
            m_collectorName = resolver.resolveMacros(getCollector());
            // resolve the parameter
            m_collectorParam = resolver.resolveMacros(getParam());
            m_collectorResult = null;
        } else {
            // preload parent content container available, use values from this container
            m_collectorName = usedContainer.getCollectorName();
            m_collectorParam = usedContainer.getCollectorParam();
            m_collectorResult = usedContainer.getCollectorResult();
            if (m_locale == null) {
                // use locale from ancestor if available
                m_locale = usedContainer.getXmlDocumentLocale();
            }
        }

        if (m_locale == null) {
            // no locale set, use locale from users request context
            m_locale = m_cms.getRequestContext().getLocale();
        }

        try {
            // now collect the resources
            I_CmsResourceCollector collector = OpenCms.getResourceManager().getContentCollector(m_collectorName);
            if (collector == null) {
                throw new CmsException(Messages.get().container(Messages.ERR_COLLECTOR_NOT_FOUND_1, m_collectorName));
            }
            // execute the collector if not already done in parent tag
            if (m_collectorResult == null) {
                m_collectorResult = collector.getResults(m_cms, m_collectorName, m_collectorParam);
            }

            m_contentInfoBean = new CmsContentInfoBean();
            m_contentInfoBean.setPageSizeAsString(resolver.resolveMacros(m_pageSize));
            m_contentInfoBean.setPageIndexAsString(resolver.resolveMacros(m_pageIndex));
            m_contentInfoBean.setPageNavLengthAsString(resolver.resolveMacros(m_pageNavLength));
            m_contentInfoBean.setResultSize(m_collectorResult.size());
            m_contentInfoBean.setLocale(m_locale.toString());
            m_contentInfoBean.initResultIndex();

            if (!isPreloader()) {
                // not required when only preloading 
                m_collectorResult = CmsJspTagContentLoad.limitCollectorResult(m_contentInfoBean, m_collectorResult);
                m_contentInfoBean.initPageNavIndexes();

                String createParam = collector.getCreateParam(m_cms, m_collectorName, m_collectorParam);
                if (createParam != null) {
                    // use "create link" only if collector supports it
                    m_directEditLinkForNew = CmsEncoder.encode(m_collectorName + "|" + createParam);
                }
            } else if (isScopeVarSet()) {
                // scope variable is set, store content load bean in JSP context
                CmsJspContentLoadBean bean = new CmsJspContentLoadBean(m_cms, m_locale, m_collectorResult);
                storeAttribute(bean);
            }

        } catch (CmsException e) {
            m_controller.setThrowable(e, m_cms.getRequestContext().getUri());
            throw new JspException(e);
        }

        // reset the direct edit options (required because of re-used tags)
        m_directEditOpen = false;
        m_directEditFollowButtons = null;

        // the next loop is the first loop
        m_isFirstLoop = true;
    }

    /**
     * Returns the next resource from the collector.<p>
     * 
     * @return the next resource from the collector
     */
    private CmsResource getNextResource() {

        if ((m_collectorResult != null) && (m_collectorResult.size() > 0)) {

            m_contentInfoBean.incResultIndex();
            return (CmsResource)m_collectorResult.remove(0);
        }

        return null;
    }
}

⌨️ 快捷键说明

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