cmsnewresourceupload.java

来自「java 编写的程序」· Java 代码 · 共 377 行 · 第 1/2 页

JAVA
377
字号

                        // the file type is an image
                        template = "image";
                        xmlTemplateDocument.setData("MIME", filename);
                        xmlTemplateDocument.setData("SIZE", "Not yet available");
                        xmlTemplateDocument.setData("FILESIZE", new Integer(filecontent.length).toString() + " Bytes");
                    }
                    else {

                        // create the new file.
                        // todo: error handling if file already exits

                        try{
                            cms.createResource(currentFolder, filename, type.getResourceTypeName(), new Hashtable(), filecontent);
                        }catch(CmsException e){
                            // remove the values form the session
                            session.removeValue(C_PARA_FILE);
                            session.removeValue(C_PARA_FILECONTENT);
                            session.removeValue(C_PARA_NEWTYPE);
                            xmlTemplateDocument.setData("details", Utils.getStackTrace(e));
                            return startProcessing(cms, xmlTemplateDocument, "", parameters, "error2");

                        }
                        // remove the values form the session
                        session.removeValue(C_PARA_FILE);
                        session.removeValue(C_PARA_FILECONTENT);
                        session.removeValue(C_PARA_NEWTYPE);

                        // return to the filelist
                        try {

                            //cms.getRequestContext().getResponse().sendCmsRedirect( getConfigFile(cms).getWorkplaceActionPath()+C_WP_EXPLORER_FILELIST);
                            if((lastUrl != null) && (lastUrl != "")) {
                                cms.getRequestContext().getResponse().sendRedirect(lastUrl);
                            }
                            else {
                                cms.getRequestContext().getResponse().sendCmsRedirect(getConfigFile(cms).getWorkplaceActionPath() + C_WP_EXPLORER_FILELIST);
                            }
                        }
                        catch(Exception ex) {
                            throw new CmsException("Redirect fails :" + getConfigFile(cms).getWorkplaceActionPath() + C_WP_EXPLORER_FILELIST, CmsException.C_UNKNOWN_EXCEPTION, ex);
                        }
                        return null;
                    }
                }
                else {
                    if(step.equals("3")) {

                        // get the data from the special image upload dialog

                        // check if a new filename is given
                        if(newname != null) {
                            filename = newname;
                        }

                        // create the new file.

                        // todo: error handling if file already exits
                        I_CmsResourceType type = cms.getResourceType(newtype);
                        Hashtable prop = new Hashtable();
                        // check if a file title was given
                        if(title != null) {
                            prop.put(C_PROPERTY_TITLE, title);
                        }
                        CmsResource file = cms.createResource(currentFolder, filename,
                                               type.getResourceTypeName(), prop, filecontent);

                        // remove the values form the session
                        session.removeValue(C_PARA_FILE);
                        session.removeValue(C_PARA_FILECONTENT);
                        session.removeValue(C_PARA_NEWTYPE);
                        session.removeValue("lasturl");

                        // return to the filelist
                        try {
                            if((lastUrl != null) && (lastUrl != "")) {
                                cms.getRequestContext().getResponse().sendRedirect(lastUrl);
                            }
                            else {
                                cms.getRequestContext().getResponse().sendCmsRedirect(getConfigFile(cms).getWorkplaceActionPath() + C_WP_EXPLORER_FILELIST);
                            }
                        }
                        catch(Exception ex) {
                            throw new CmsException("Redirect fails :" + getConfigFile(cms).getWorkplaceActionPath() + C_WP_EXPLORER_FILELIST, CmsException.C_UNKNOWN_EXCEPTION, ex);
                        }
                        return null;
                    }
                }
            }
        }
        if(filename != null) {
            xmlTemplateDocument.setData("FILENAME", filename);
        }

        // process the selected template
        return startProcessing(cms, xmlTemplateDocument, "", parameters, template);
    }

    /**
     * Gets the resources displayed in the Radiobutton group on the chtype dialog.
     * @param cms The CmsObject.
     * @param lang The langauge definitions.
     * @param names The names of the new rescources.
     * @param values The links that are connected with each resource.
     * @param parameters Hashtable of parameters (not used yet).
     * @param descriptions Description that will be displayed for the new resource.
     * @returns The vectors names and values are filled with the information found in the workplace.ini.
     * @return the number of the preselected item, -1 if none preselected
     * @exception Throws CmsException if something goes wrong.
     */
    public int getResources(CmsObject cms, CmsXmlLanguageFile lang, Vector names, Vector values, Vector descriptions, Hashtable parameters) throws CmsException {
        I_CmsSession session = cms.getRequestContext().getSession(true);
        String filename = (String)session.getValue(C_PARA_FILE);
        String suffix = filename.substring(filename.lastIndexOf('.') + 1);
        suffix = suffix.toLowerCase(); // file extension of filename

        // read the known file extensions from the database
        Hashtable extensions = cms.readFileExtensions();
        String resType = new String();
        if(extensions != null) {
            resType = (String)extensions.get(suffix);
        }
        if(resType == null) {
            resType = "";
        }
        int ret = 0;

        // Check if the list of available resources is not yet loaded from the workplace.ini
        if(m_names == null || m_values == null) {
            m_names = new Vector();
            m_values = new Vector();
            CmsXmlWpConfigFile configFile = new CmsXmlWpConfigFile(cms);
            configFile.getWorkplaceIniData(m_names, m_values, "RESOURCETYPES", "RESOURCE");
        }

        // Check if the temportary name and value vectors are not initialized, create
        // them if nescessary.
        if(names == null) {
            names = new Vector();
        }
        if(values == null) {
            values = new Vector();
        }
        if(descriptions == null) {
            descriptions = new Vector();
        }

        // OK. Now m_names and m_values contain all available
        // resource information.
        // Loop through the vectors and fill the result vectors.
        int numViews = m_names.size();
        for(int i = 0;i < numViews;i++) {
            String loopValue = (String)m_values.elementAt(i);
            String loopName = (String)m_names.elementAt(i);
            values.addElement(loopValue);
            names.addElement("file_" + loopName);
            String descr;
            if(lang != null) {
                descr = lang.getLanguageValue("fileicon." + loopName);
            }
            else {
                descr = loopName;
            }
            descriptions.addElement(descr);
            if(resType.equals(loopName)) {

                // known file extension
                ret = i;
            }
        }
        return ret;
    }

    /**
     * Indicates if the results of this class are cacheable.
     *
     * @param cms CmsObject Object for accessing system resources
     * @param templateFile Filename of the template file
     * @param elementName Element name of this template in our parent template.
     * @param parameters Hashtable with all template class parameters.
     * @param templateSelector template section that should be processed.
     * @return <EM>true</EM> if cacheable, <EM>false</EM> otherwise.
     */
    public boolean isCacheable(CmsObject cms, String templateFile, String elementName, Hashtable parameters, String templateSelector) {
        return false;
    }
}

⌨️ 快捷键说明

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