⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmsresourcecomparisondialog.java

📁 OpenCms 是一个J2EE的产品
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        while (i.hasNext()) {
            CmsAttributeComparison compare = (CmsAttributeComparison)i.next();
            res1.append(key(compare.getName())).append(": ").append(compare.getVersion1()).append("\n");
            res2.append(key(compare.getName())).append(": ").append(compare.getVersion2()).append("\n");
        }
        return new String[] {res1.toString(), res2.toString()};
    }

    /**
     * Returns the paramCompare.<p>
     *
     * @return the paramCompare
     */
    public String getParamCompare() {

        return m_paramCompare;
    }

    /**
     * Returns the paramElement.<p>
     *
     * @return the paramElement
     */
    public String getParamElement() {

        return m_paramElement;
    }

    /**
     * Returns the paramLocale.<p>
     *
     * @return the paramLocale
     */
    public String getParamLocale() {

        return m_paramLocale;
    }

    /**
     * Returns the paramPath1.<p>
     *
     * @return the paramPath1
     */
    public String getParamPath1() {

        return m_paramPath1;
    }

    /**
     * Returns the paramPath2.<p>
     *
     * @return the paramPath2
     */
    public String getParamPath2() {

        return m_paramPath2;
    }

    /**
     * Returns the paramTagId1.<p>
     *
     * @return the paramTagId1
     */
    public String getParamTagId1() {

        return m_paramTagId1;
    }

    /**
     * Returns the paramTagId2.<p>
     *
     * @return the paramTagId2
     */
    public String getParamTagId2() {

        return m_paramTagId2;
    }

    /**
     * Returns the paramTextmode.<p>
     *
     * @return the paramTextmode
     */
    public String getParamTextmode() {

        return m_paramTextmode;
    }

    /**
     * Returns the paramVersion1.<p>
     *
     * @return the paramVersion1
     */
    public String getParamVersion1() {

        return m_paramVersion1;
    }

    /**
     * Returns the paramVersion2.<p>
     *
     * @return the paramVersion2
     */
    public String getParamVersion2() {

        return m_paramVersion2;
    }

    /**
     * Converts an attribute list to a string.<p>
     * 
     * @param properties a list of compared properties to be converted to a string
     * @return a string respresentation of the attribute list
     */
    public String[] getPropertiesAsString(List properties) {

        Iterator i = properties.iterator();
        StringBuffer res1 = new StringBuffer(512);
        StringBuffer res2 = new StringBuffer(512);
        while (i.hasNext()) {
            CmsAttributeComparison compare = (CmsAttributeComparison)i.next();
            res1.append(compare.getName()).append(": ").append(compare.getVersion1()).append("\n");
            res2.append(compare.getName()).append(": ").append(compare.getVersion2()).append("\n");
        }
        return new String[] {res1.toString(), res2.toString()};
    }

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

        m_paramCompare = paramCompare;
    }

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

        m_paramElement = paramElement;
    }

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

        m_paramLocale = paramLocale;
    }

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

        m_paramPath1 = paramPath1;
    }

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

        m_paramPath2 = paramPath2;
    }

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

        m_paramTagId1 = paramTagId1;
    }

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

        m_paramTagId2 = paramTagId2;
    }

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

        m_paramTextmode = paramTextmode;
    }

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

        m_paramVersion1 = paramVersion1;
    }

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

        m_paramVersion2 = paramVersion2;
    }

    /**
     * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
     */
    protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) {

        super.initWorkplaceRequestValues(settings, request);     
        try {
            CmsFile file1 = CmsResourceComparisonDialog.readFile(
                getCms(),
                getParamPath1(),
                getParamVersion1(),
                Integer.parseInt(getParamTagId1()));
            CmsFile file2 = CmsResourceComparisonDialog.readFile(
                getCms(),
                getParamPath2(),
                getParamVersion2(),
                Integer.parseInt(getParamTagId2()));
            // if certain element is compared, use html difference dialog
            if (CmsStringUtil.isNotEmpty(getParamElement())) {
                m_differenceDialog = new CmsHtmlDifferenceDialog(getJsp());
            } else {
                m_differenceDialog = new CmsDifferenceDialog(getJsp());
            }
            if (CmsResourceComparisonDialog.COMPARE_ATTRIBUTES.equals(getParamCompare())) {
                List comparedAttributes = CmsResourceComparison.compareAttributes(getCms(), file1, file2);
                String[] attributeStrings = getAttributesAsString(comparedAttributes);
                m_differenceDialog.setOriginalSource(attributeStrings[0]);
                m_differenceDialog.setCopySource(attributeStrings[1]);
            } else if (CmsResourceComparisonDialog.COMPARE_PROPERTIES.equals(getParamCompare())) {
                List comparedProperties = CmsResourceComparison.compareProperties(getCms(), file1, file2);
                String[] propertyStrings = getPropertiesAsString(comparedProperties);
                m_differenceDialog.setOriginalSource(propertyStrings[0]);
                m_differenceDialog.setCopySource(propertyStrings[1]);
            } else {

                setContentAsSource(file1, file2);
            }

        } catch (CmsException e) {

            LOG.error(e.getMessage(), e);
        } catch (UnsupportedEncodingException e) {

            LOG.error(e.getMessage(), e);
        }
    }

    /** 
     * Returns the content of all elements of an xml document appended.<p>
     * 
     * @param xmlDoc the xml document to extract the elements from
     * @return the content of all elements of an xml document appended
     */
    private String extractElements(I_CmsXmlDocument xmlDoc) {

        StringBuffer result = new StringBuffer();
        if (xmlDoc instanceof CmsXmlPage) {
        List locales = xmlDoc.getLocales();
        Iterator i = locales.iterator();
        boolean firstIter = true;
        while (i.hasNext()) {
            if (!firstIter) {
                result.append("\n\n-----");
            }
            Locale locale = (Locale)i.next();
            result.append("\n\n[").append(locale.toString()).append(']');
            List elements = xmlDoc.getValues(locale);
            Iterator j = elements.iterator();
            while (j.hasNext()) {
                    I_CmsXmlContentValue value = (I_CmsXmlContentValue)j.next();
                    result.append("\n\n[");
                    // output value of name attribute
                    result.append(value.getElement().attribute(0).getValue());
                    result.append("]\n\n");
                    try {
                        I_CmsWidget widget = value.getDocument().getContentDefinition().getContentHandler().getWidget(
                            value);
                        result.append(widget.getWidgetStringValue(
                            getCms(),
                            new CmsFileInfoDialog(getJsp()),
                            (I_CmsWidgetParameter)value));
                    } catch (CmsXmlException e) {
                        LOG.error(e.getMessage(), e);
                    }
                }
            firstIter = false;
        }
        } else if (xmlDoc instanceof CmsXmlContent) {
            CmsXmlContentTextExtractor visitor = new CmsXmlContentTextExtractor(result);
            ((CmsXmlContent)xmlDoc).visitAllValuesWith(visitor);
            
        }
        return result.toString();
    }

    /**
     * Extracts the content from the files according to the file type.<p>
     * 
     * @param file1 the first file to compare
     * @param file2 the second file to compare
     * 
     * @throws CmsException if something goes wrong
     * @throws UnsupportedEncodingException if the encoding of one file is not supported
     */
    private void setContentAsSource(CmsFile file1, CmsFile file2) throws CmsException, UnsupportedEncodingException {

        CmsObject cms = getCms();
        if (CmsStringUtil.isNotEmpty(getParamElement())) {

            I_CmsXmlDocument resource1;
            I_CmsXmlDocument resource2;
            if (file1.getTypeId() == CmsResourceTypeXmlPage.getStaticTypeId()) {
                resource1 = CmsXmlPageFactory.unmarshal(cms, file1);
            } else {
                resource1 = CmsXmlContentFactory.unmarshal(cms, file1);
            }
            if (file2.getTypeId() == CmsResourceTypeXmlPage.getStaticTypeId()) {
                resource2 = CmsXmlPageFactory.unmarshal(cms, file2);
            } else {
                resource2 = CmsXmlContentFactory.unmarshal(cms, file2);
            }
            I_CmsXmlContentValue value1 = resource1.getValue(getParamElement(), new Locale(getParamLocale()));
            I_CmsXmlContentValue value2 = resource2.getValue(getParamElement(), new Locale(getParamLocale()));
            if (value1 == null) {
                m_differenceDialog.setOriginalSource("");
            } else {
                m_differenceDialog.setOriginalSource(value1.getStringValue(cms));
            }
            if (value2 == null) {
                m_differenceDialog.setCopySource("");
            } else {
                m_differenceDialog.setCopySource(value2.getStringValue(cms));
            }
        } else if (CmsResourceComparisonDialog.COMPARE_ALL_ELEMENTS.equals(getParamCompare())) {

            I_CmsXmlDocument resource1;
            I_CmsXmlDocument resource2;
            if (file1.getTypeId() == CmsResourceTypeXmlPage.getStaticTypeId()) {
                resource1 = CmsXmlPageFactory.unmarshal(cms, file1);
            } else {
                resource1 = CmsXmlContentFactory.unmarshal(cms, file1);
            }
            if (file2.getTypeId() == CmsResourceTypeXmlPage.getStaticTypeId()) {
                resource2 = CmsXmlPageFactory.unmarshal(cms, file2);
            } else {
                resource2 = CmsXmlContentFactory.unmarshal(cms, file2);
            }
            m_differenceDialog.setOriginalSource(extractElements(resource1));
            m_differenceDialog.setCopySource(extractElements(resource2));

        } else {
            // compare whole plain text file
            m_differenceDialog.setOriginalSource(new String(file1.getContents(), cms.getRequestContext().getEncoding()));
            m_differenceDialog.setCopySource(new String(file2.getContents(), cms.getRequestContext().getEncoding()));
        }
    }
}

⌨️ 快捷键说明

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