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

📄 cmsxmlformtemplatefile.java

📁 cms是开源的框架
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
* File   : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/defaults/CmsXmlFormTemplateFile.java,v $
* Date   : $Date: 2005/06/27 23:22:23 $
* Version: $Revision: 1.3 $
*
* This library is part of OpenCms -
* the Open Source Content Mananagement System
*
* Copyright (C) 2001  The OpenCms Group
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* For further information about OpenCms, please see the
* OpenCms Website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

package com.opencms.defaults;

import org.opencms.file.CmsFile;
import org.opencms.file.CmsObject;
import org.opencms.main.CmsException;

import com.opencms.legacy.CmsLegacyException;
import com.opencms.template.CmsXmlTemplateFile;
import com.opencms.workplace.CmsWorkplaceDefault;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Hashtable;
import java.util.Vector;

import org.w3c.dom.Element;

/**
 * Template content definition for generating HTML forms.
 * This is an extension of the default template content definition.
 * Special tags for handling HTML form elements are added here.
 * See the handleXxxTag Methods for more details.
 *
 * @author Alexander Lucas
 * @version $Revision: 1.3 $ $Date: 2005/06/27 23:22:23 $
 * 
 * @deprecated Will not be supported past the OpenCms 6 release.
 */
public class CmsXmlFormTemplateFile extends CmsXmlTemplateFile {

    /**
     * Default constructor.
     * 
     * @throws CmsException if something goes wrong
     */
    public CmsXmlFormTemplateFile() throws CmsException {
        super();
        registerMyTags();
    }

    /**
     * Constructor for creating a new object containing the content
     * of the given file.<p>
     *
     * @param cms CmsObject object for accessing system resources
     * @param file the file that should be read
     * @throws CmsException if something goes wrong
     */
    public CmsXmlFormTemplateFile(CmsObject cms, CmsFile file) throws CmsException {
        super();
        registerMyTags();
        init(cms, file);
    }

    /**
     * Constructor for creating a new object containing the content
     * of the given filename.<p>
     *
     * @param cms CmsObject object for accessing system resources
     * @param filename Name of the body file that shoul be read
     * @throws CmsException if something goes wrong
     */
    public CmsXmlFormTemplateFile(CmsObject cms, String filename) throws CmsException {
        super();
        registerMyTags();
        init(cms, filename);
    }

    /**
     * Gets the expected tagname for the XML documents of this content type.<p>
     * 
     * @return Expected XML tagname.
     */
    public String getXmlDocumentTagName() {
        return "XMLTEMPLATE";
    }

    /**
     * Handles any occurence of the special XML tag <code>&lt;RADIOBUTTON&gt;</code> for
     * generating HTML form radio buttons.
     * <P>
     * The definition of a HTML radio button will be taken from I_CmsWpConstants.C_VFS_PATH_DEFAULT_INTERNAL + "HTMLFormDefs".
     * If the file is missing, this method will crash. Ensure this file is created and filled
     * with all required XML tags.
     * <P>
     * Radio buttons can be generated by adding the special XML tag
     * <code>&lt;RADIOBUTTON class="myClass" method="myMethod" name="myName"/&gt;</code>
     * to the template file. This tag will be replaced with the correspondig group of radio buttons
     * while processing the template file. The <code>class</code> parameter is optional.
     * The <code>method</code> parameter will be used to look up a user defined method
     * in the template class assigned to the template file. This method should look like
     * <br/>
     * <code>public Integer myMethod(CmsObject cms, Vector names, Vector values, Hashtable parameters)</code><br/>
     * and will be used to get the content of the requested radion button group. The vectors <code>names</code>
     * and <code>values</code> should be filled with the appropriate values. The return value should be an
     * Integer containing the pre-selected radio button or -1, if no value should be pre-selected.<p>
     *
     * @param n XML element containing the current special workplace tag
     * @param callingObject reference to the calling object
     * @param userObj hashtable containig all user parameters
     * @return the radio button definition
     * @throws CmsException if something goes wrong
     */
    public Object handleRadiobuttonTag(Element n, Object callingObject, Object userObj) throws CmsException {
        Hashtable parameters = (Hashtable)userObj;

        // StringBuffer for the generated output
        StringBuffer result = new StringBuffer();

        // Here the different select box options will be stored
        Vector values = new Vector();
        Vector names = new Vector();
        Integer returnObject = null;

        // Read radiobutton parameters
        String radioClass = n.getAttribute(CmsWorkplaceDefault.C_SELECTBOX_CLASS);
        String radioName = n.getAttribute(CmsWorkplaceDefault.C_RADIO_NAME);
        String radioMethod = n.getAttribute(CmsWorkplaceDefault.C_RADIO_METHOD);
        String radioOrder = n.getAttribute(CmsWorkplaceDefault.C_RADIO_ORDER);
        if (radioOrder == null || ((!"row".equals(radioOrder)) && (!"col".equals(radioOrder)))) {
            radioOrder = "col";
        }

        // call the method for generating listbox elements
        Method groupsMethod = null;
        int selectedOption = 0;
        try {
            groupsMethod = callingObject.getClass().getMethod(radioMethod, new Class[] {
                CmsObject.class, Vector.class, Vector.class, Hashtable.class
            });
            returnObject = (Integer)groupsMethod.invoke(callingObject, new Object[] {
                m_cms, names, values, parameters
            });
        } catch (NoSuchMethodException exc) {

            // The requested method was not found.
            throwException("Could not find radio button method " + radioMethod + " in calling class " + callingObject.getClass().getName()
                    + " for generating select box content.", CmsLegacyException.C_NOT_FOUND);
        } catch (InvocationTargetException targetEx) {

            // the method could be invoked, but throwed a exception
            // itself. Get this exception and throw it again.
            Throwable e = targetEx.getTargetException();
            if (!(e instanceof CmsException)) {

                // Only print an error if this is NO CmsException
                throwException("Radio button method " + radioMethod + " in calling class " + callingObject.getClass().getName()
                        + " throwed an exception. " + e, CmsLegacyException.C_UNKNOWN_EXCEPTION);
            } else {

                // This is a CmsException
                // Error printing should be done previously.
                throw (CmsException)e;
            }
        } catch (Exception exc2) {
            throwException("Radio button method " + radioMethod + " in calling class " + callingObject.getClass().getName()
                    + " was found but could not be invoked. " + exc2, CmsLegacyException.C_XML_NO_USER_METHOD);

⌨️ 快捷键说明

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