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

📄 cmsxmlcontenteditor.java

📁 OpenCms 是一个J2EE的产品
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                result.append(widget.getDialogInitCall(getCms(), this));
            }
        } catch (Exception e) {
            showErrorPage(e);
        }
        return result.toString();
    }

    /**
     * Generates the JavaScript initialization methods for the used widgets.<p>
     * 
     * @return the JavaScript initialization methods for the used widgets
     * 
     * @throws JspException if an error occurs during JavaScript generation
     */
    public String getXmlEditorInitMethods() throws JspException {

        StringBuffer result = new StringBuffer(32);
        try {
            // iterate over unique widgets from collector
            Iterator i = getWidgetCollector().getUniqueWidgets().iterator();
            while (i.hasNext()) {
                I_CmsWidget widget = (I_CmsWidget)i.next();
                result.append(widget.getDialogInitMethod(getCms(), this));
                result.append("\n");
            }
        } catch (Exception e) {
            showErrorPage(e);
        }
        return result.toString();
    }

    /**
     * Returns true if the edited content contains validation errors, otherwise false.<p>
     * 
     * @return true if the edited content contains validation errors, otherwise false
     */
    public boolean hasValidationErrors() {

        return getErrorHandler().hasErrors();
    }

    /**
     * Returns true if the preview is available for the edited xml content.<p>
     * 
     * This method has to use the resource request parameter and read the file from vfs because the temporary file is
     * not available in the upper button frame.<p>
     * 
     * @return true if the preview is enabled, otherwise false
     */
    public boolean isPreviewEnabled() {

        try {
            // read the original file because temporary file is not created when opening button frame
            CmsFile file = getCms().readFile(getParamResource(), CmsResourceFilter.ALL);
            CmsXmlContent content = CmsXmlContentFactory.unmarshal(getCms(), file);
            return content.getContentDefinition().getContentHandler().getPreview(
                getCms(),
                m_content,
                getParamResource()) != null;
        } catch (Exception e) {
            // error reading or unmarshalling, no preview available
            return false;
        }
    }

    /**
     * Sets the editor values for the locale with the parameters from the request.<p>
     * 
     * Called before saving the xml content, redisplaying the input form, 
     * changing the language and adding or removing elements.<p>
     * 
     * @param locale the locale of the content to save
     * @throws CmsXmlException if something goes wrong
     */
    public void setEditorValues(Locale locale) throws CmsXmlException {

        List valueNames = getSimpleValueNames(m_content.getContentDefinition(), "", locale);
        Iterator i = valueNames.iterator();
        while (i.hasNext()) {
            String valueName = (String)i.next();
            I_CmsXmlContentValue value = m_content.getValue(valueName, locale);
            I_CmsWidget widget = value.getContentDefinition().getContentHandler().getWidget(value);
            widget.setEditorValue(getCms(), getJsp().getRequest().getParameterMap(), this, (I_CmsWidgetParameter)value);
        }
    }

    /**
     * Sets the index of the element to add or remove.<p>
     *
     * @param elementIndex the index of the element to add or remove
     */
    public void setParamElementIndex(String elementIndex) {

        m_paramElementIndex = elementIndex;
    }

    /**
     * Sets the name of the element to add or remove.<p>
     *
     * @param elementName the name of the element to add or remove
     */
    public void setParamElementName(String elementName) {

        m_paramElementName = elementName;
    }

    /**
     * Sets the "new link" parameter.<p>
     *
     * @param paramNewLink the "new link" parameter to set
     */
    public void setParamNewLink(String paramNewLink) {

        m_paramNewLink = CmsEncoder.decode(paramNewLink);
    }

    /**
     * Determines if the element language selector is shown dependent on the available Locales.<p>
     * 
     * @return true, if more than one Locale is available, otherwise false
     */
    public boolean showElementLanguageSelector() {

        List locales = OpenCms.getLocaleManager().getAvailableLocales(getCms(), getParamResource());
        if (locales == null || locales.size() < 2) {
            // for less than two available locales, do not create language selector
            return false;
        }
        return true;
    }

    /**
     * @see org.opencms.workplace.tools.CmsToolDialog#useNewStyle()
     */
    public boolean useNewStyle() {

        return false;
    }

    /**
     * Initializes the editor content when opening the editor for the first time.<p>
     * 
     * Not necessary for the xmlcontent editor.<p>
     */
    protected void initContent() {

        // nothing to be done for the xmlcontent editor form
    }

    /**
     * Initializes the element language for the first call of the editor.<p>
     */
    protected void initElementLanguage() {

        // get all locales of the content
        List locales = new ArrayList();
        if (m_content != null) {
            locales = m_content.getLocales();
        }
        Locale defaultLocale = (Locale)OpenCms.getLocaleManager().getDefaultLocales(getCms(), getParamResource()).get(0);

        if (locales.size() > 0) {
            // locale element present, get the language
            if (locales.contains(defaultLocale)) {
                // get the element for the default locale
                setParamElementlanguage(defaultLocale.toString());
                return;
            } else {
                // get the first element that can be found
                setParamElementlanguage(locales.get(0).toString());
                return;
            }
        }
        setParamElementlanguage(defaultLocale.toString());
    }

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

        // fill the parameter values in the get/set methods
        fillParamValues(request);
        // set the dialog type
        setParamDialogtype(EDITOR_TYPE);

        if (getParamNewLink() != null) {
            setParamAction(EDITOR_ACTION_NEW);
        } else {
            // initialize a content object from the temporary file
            if (getParamTempfile() != null && !"null".equals(getParamTempfile())) {
                try {
                    m_file = getCms().readFile(this.getParamTempfile(), CmsResourceFilter.ALL);
                    m_content = CmsXmlContentFactory.unmarshal(getCms(), m_file);
                } catch (CmsException e) {
                    // error during initialization, show error page
                    try {
                        showErrorPage(this, e);
                    } catch (JspException exc) {
                        // should usually never happen
                        if (LOG.isInfoEnabled()) {
                            LOG.info(exc);
                        }
                    }
                }
            }
        }

        // set the action for the JSP switch 
        if (EDITOR_SAVE.equals(getParamAction())) {
            setAction(ACTION_SAVE);
        } else if (EDITOR_SAVEEXIT.equals(getParamAction())) {
            setAction(ACTION_SAVEEXIT);
        } else if (EDITOR_EXIT.equals(getParamAction())) {
            setAction(ACTION_EXIT);
        } else if (EDITOR_ACTION_CHECK.equals(getParamAction())) {
            setAction(ACTION_CHECK);
        } else if (EDITOR_SAVEACTION.equals(getParamAction())) {
            setAction(ACTION_SAVEACTION);
            try {
                actionDirectEdit();
            } catch (Exception e) {
                // should usually never happen
                if (LOG.isInfoEnabled()) {
                    LOG.info(e.getLocalizedMessage(), e);
                }
            }
            setAction(ACTION_EXIT);
        } else if (EDITOR_SHOW.equals(getParamAction())) {
            setAction(ACTION_SHOW);
        } else if (EDITOR_SHOW_ERRORMESSAGE.equals(getParamAction())) {
            setAction(ACTION_SHOW_ERRORMESSAGE);
        } else if (EDITOR_CHANGE_ELEMENT.equals(getParamAction())) {
            setAction(ACTION_SHOW);
            actionChangeElementLanguage();
        } else if (EDITOR_ACTION_ELEMENT_ADD.equals(getParamAction())) {
            setAction(ACTION_ELEMENT_ADD);
            try {
                actionToggleElement();
            } catch (JspException e) {
                if (LOG.isErrorEnabled()) {
                    LOG.error(org.opencms.workplace.Messages.get().getBundle().key(
                        org.opencms.workplace.Messages.LOG_INCLUDE_ERRORPAGE_FAILED_0));
                }
            }
            if (getAction() != ACTION_CANCEL && getAction() != ACTION_SHOW_ERRORMESSAGE) {
                // no error ocurred, redisplay the input form
                setAction(ACTION_SHOW);
            }
        } else if (EDITOR_ACTION_ELEMENT_REMOVE.equals(getParamAction())) {
            setAction(ACTION_ELEMENT_REMOVE);
            try {
                actionToggleElement();
            } catch (JspException e) {
                if (LOG.isErrorEnabled()) {
                    LOG.error(org.opencms.workplace.Messages.get().getBundle().key(
                        org.opencms.workplace.Messages.LOG_INCLUDE_ERRORPAGE_FAILED_0));
                }
            }
            if (getAction() != ACTION_CANCEL && getAction() != ACTION_SHOW_ERRORMESSAGE) {
                // no error ocurred, redisplay the input form
                setAction(ACTION_SHOW);
            }
        } else if (EDITOR_ACTION_ELEMENT_MOVE_DOWN.equals(getParamAction())) {
            setAction(ACTION_ELEMENT_MOVE_DOWN);
            try {
                actionMoveElement();
            } catch (JspException e) {
                if (LOG.isErrorEnabled()) {
                    LOG.error(org.opencms.workplace.Messages.get().getBundle().key(
                        org.opencms.workplace.Messages.LOG_INCLUDE_ERRORPAGE_FAILED_0));
                }
            }
            if (getAction() != ACTION_CANCEL && getAction() != ACTION_SHOW_ERRORMESSAGE) {
                // no error ocurred, redisplay the input form
                setAction(ACTION_SHOW);
            }
        } else if (EDITOR_ACTION_ELEMENT_MOVE_UP.equals(getParamAction())) {
            setAction(ACTION_ELEMENT_MOVE_UP);
            try {
                actionMoveElement();
            } catch (JspException e) {
                if (LOG.isErrorEnabled()) {
                    LOG.error(org.opencms.workplace.Messages.get().getBundle().key(
                        org.opencms.workplace.Messages.LOG_INCLUDE_ERRORPAGE_FAILED_0));
                }
            }
            if (getAction() != ACTION_CANCEL && getAction() != ACTION_SHOW_ERRORMESSAGE) {
                // no error ocurred, redisplay the input form
                setAction(ACTION_SHOW);
            }
        } else if (EDITOR_ACTION_NEW.equals(getParamAction())) {
            setAction(ACTION_NEW);
            return;
        } else if (EDITOR_PREVIEW.equals(getParamAction())) {
            setAction(ACTION_PREVIEW);
        } else {
            // initial call of editor
            setAction(ACTION_DEFAULT);
            try {
                // lock resource if autolock is enabled in configuration
                if (Boolean.valueOf(getParamDirectedit()).booleanValue()) {
                    // set a temporary lock in direct edit mode
                    checkLock(getParamResource(), CmsLock.TEMPORARY);
                } else {
                    // set common lock
                    checkLock(getParamResource());
                }
                // create the temporary file
                setParamTempfile(createTempFile());
                // initialize a content object from the created temporary file
                m_file = getCms().readFile(this.getParamTempfile(), CmsResourceFilter.ALL);
                m_content = CmsXmlContentFactory.unmarshal(getCms(), m_file);
            } catch (CmsException e) {
                // error during initialization
                try {
                    showErrorPage(this, e);
                } catch (JspException exc) {
                    // should usually never happen
                    if (LOG.isInfoEnabled()) {
                        LOG.info(exc);
                    }
                }
            }
            // set the initial element language if not given in request parameters
            if (getParamElementlanguage() == null) {
                initElementLanguage();
            }
        }
    }

    /**
     * Returns the html for the element operation buttons add, move, remove.<p>
     * 
     * @param elementName name of the element
     * @param index the index of the element
     * @param addElement if true, the button to add an element is shown
     * @param removeElement if true, the button to remove an element is shown
     * @return the html for the element operation buttons
     */
    private String buildElementButtons(String elementName, int index, boolean addElement, boolean removeElement) {

        StringBuffer jsCall = new StringBuffer(512);

        // indicates if at least one button is active
        boolean buttonPresent = false;

        jsCall.append("showElementButtons('");
        jsCall.append(elementName);
        jsCall.append("', ");
        jsCall.append(index);
        jsCall.append(", ");

        // build the remove element button if required
        if (removeElement) {
            jsCall.append(Boolean.TRUE);
            buttonPresent = true;
        } else {
            jsCall.append(Boolean.FALSE);
        }
        jsCall.append(", ");

⌨️ 快捷键说明

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