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

📄 cmsexportmoduledata.java

📁 java 编写的程序
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            addElement(m_docXml, info, C_EXPORT_TAG_PROJECT, m_cms.getRequestContext().currentProject().getName());
            addElement(m_docXml, info, C_EXPORT_TAG_VERSION, C_EXPORT_VERSION);
            // add the root element for the channels
            m_filesElement = m_docXml.createElement(C_EXPORT_TAG_CHANNELS);
            m_docXml.getDocumentElement().appendChild(m_filesElement);
            // add the root element for the masters
            m_mastersElement = m_docXml.createElement(C_EXPORT_TAG_MASTERS);
            m_docXml.getDocumentElement().appendChild(m_mastersElement);
        } catch(Exception exc) {
            throw new CmsException(CmsException.C_UNKNOWN_EXCEPTION, exc);
        }
    }

    /**
     * Gets the import resource and stores it in object-member.
     */
    private void getExportResource()
        throws CmsException {
        try {
            // add zip-extension, if needed
            if( !m_exportFile.toLowerCase().endsWith(".zip") ) {
                m_exportFile += ".zip";
            }

            // create the export-zipstream
            m_exportZipStream = new ZipOutputStream(new FileOutputStream(m_exportFile));

        } catch(Exception exc) {
            throw new CmsException(CmsException.C_UNKNOWN_EXCEPTION, exc);
        }
    }

    /**
     * Adds a element to the xml-document.
     * @param element The element to add the subelement to.
     * @param name The name of the new subelement.
     * @param value The value of the element.
     */
    private void addCdataElement(Document xmlDoc, Element element, String name, String value) {
        Element newElement = xmlDoc.createElement(name);
        element.appendChild(newElement);
        CDATASection text = xmlDoc.createCDATASection(value);
        newElement.appendChild(text);
    }
    /**
     * Adds a element to the xml-document.
     * @param element The element to add the subelement to.
     * @param name The name of the new subelement.
     * @param value The value of the element.
     */
    private void addElement(Document xmlDoc, Element element, String name, String value) {
        Element newElement = xmlDoc.createElement(name);
        element.appendChild(newElement);
        Text text = xmlDoc.createTextNode(value);
        newElement.appendChild(text);
    }

    /**
     * Exports the channels from a vector with the given channelnames
     * @param channelNames The vector with the channelNames
     * @param channelId A vector that contains the channelid of each channel
     */
    private void exportAllChannels(Vector channelNames) throws CmsException{
        for(int i = 0; i < channelNames.size(); i++){
            String curChannel = (String)channelNames.elementAt(i);
            // add the channelid to the vector of channel-ids
            m_cms.setContextToCos();
            try{
                String channelId = m_cms.readProperty(curChannel, I_CmsConstants.C_PROPERTY_CHANNELID);
                if(channelId != null){
                    if(!m_channelIds.contains(channelId)) {
                        // This channelid was not added previously. Add it now.
                        m_channelIds.put(channelId, curChannel);
                    }
                }
            } catch (CmsException e){
                throw e;
            } finally {
                m_cms.setContextToVfs();
            }
            // first add all superchannels
            addSuperChannels(curChannel);
            // get all subFolders
            // walk through all subfolders and export them
            exportChannel(curChannel);
        }
    }

    /**
     * Adds the superchannels of path to the config file,
     * starting at the top, excluding the root folder
     * @param path The path of the channel in the filesystem
     */
    private void addSuperChannels(String path) throws CmsException {
        // Initialize the "previously added folder cache"
        if(m_superChannels == null) {
            m_superChannels = new Vector();
        }
        Vector superChannels = new Vector();

        // Check, if the path is really a folder
        if(path.lastIndexOf(C_ROOT) != (path.length()-1)) {
            path = path.substring(0, path.lastIndexOf(C_ROOT)+1);
        }
        while (path.length() > C_ROOT.length()) {
            superChannels.addElement(path);
            path = path.substring(0, path.length() - 1);
            path = path.substring(0, path.lastIndexOf(C_ROOT)+1);
        }
        try{
            m_cms.setContextToCos();
            for (int i = superChannels.size()-1; i >= 0; i--) {
                String addChannel = (String)superChannels.elementAt(i);
                if(!m_superChannels.contains(addChannel)) {
                    // This super folder was NOT added previously. Add it now!
                    m_cms.setContextToCos();
                    CmsFolder channel = m_cms.readFolder(addChannel);
                    writeXmlEntrys(channel);
                    // Remember that this folder was added
                    m_superChannels.addElement(addChannel);
                }
            }
        } catch (CmsException e){
            throw e;
        } finally {
            m_cms.setContextToVfs();
        }
    }

    /**
     * Exports all subchannels of the channel
     * @param channelname The name of the channel to export
     */
     private void exportChannel(String channelname) throws CmsException{
        m_cms.setContextToCos();
        Vector subChannels = m_cms.getSubFolders(channelname);
        m_cms.setContextToVfs();
        for(int i = 0; i < subChannels.size(); i++) {
            CmsResource curChannel = (CmsResource) subChannels.elementAt(i);
            if(curChannel.getState() != C_STATE_DELETED){
                // add the channelid to the vector of channel-ids
                try{
                    m_cms.setContextToCos();
                    String channelId = m_cms.readProperty(curChannel.getAbsolutePath(), I_CmsConstants.C_PROPERTY_CHANNELID);
                    if(!m_channelIds.contains(channelId)) {
                        // This channelid was not added previously. Add it now.
                        m_channelIds.put(channelId, curChannel);
                    }
                } catch (CmsException e){
                    throw e;
                } finally {
                    m_cms.setContextToVfs();
                }
                // export this folder
                writeXmlEntrys(curChannel);
                // export all resources in this folder
                exportChannel(curChannel.getAbsolutePath());
            }
        }
     }

    /**
     * Writes the data for a resources (like acces-rights) to the manifest-xml-file.
     * @param resource The resource to get the data from.
     * @exception throws a CmsException if something goes wrong.
     */
    private void writeXmlEntrys(CmsResource resource) throws CmsException {
        System.out.print("Exporting channel: "+resource.getAbsolutePath());
        String source, type, user, group, access, launcherStartClass;

        // get all needed informations from the resource
        source = getSourceFilename(resource.getAbsolutePath());
        type = m_cms.getResourceType(resource.getType()).getResourceTypeName();
        user = m_cms.readOwner(resource).getName();
        group = m_cms.readGroup(resource).getName();
        access = resource.getAccessFlags() + "";
        launcherStartClass = resource.getLauncherClassname();

        // write these informations to the xml-manifest
        Element file = m_docXml.createElement(C_EXPORT_TAG_FILE);
        m_filesElement.appendChild(file);

        addElement(m_docXml, file, C_EXPORT_TAG_DESTINATION, source);
        addElement(m_docXml, file, C_EXPORT_TAG_TYPE, type);
        addElement(m_docXml, file, C_EXPORT_TAG_USER, user);
        addElement(m_docXml, file, C_EXPORT_TAG_GROUP, group);
        addElement(m_docXml, file, C_EXPORT_TAG_ACCESS, access);

        // append the node for properties
        Element properties = m_docXml.createElement(C_EXPORT_TAG_PROPERTIES);
        file.appendChild(properties);

        // read the properties
        Hashtable fileProperties = new Hashtable();
        try{
            m_cms.setContextToCos();
            fileProperties = m_cms.readAllProperties(resource.getAbsolutePath());
        } catch (CmsException e){
            throw e;
        } finally {
            m_cms.setContextToVfs();
        }
        Enumeration keys = fileProperties.keys();

        // create xml-elements for the properties
        while(keys.hasMoreElements()) {
            // append the node for a property
            String key = (String) keys.nextElement();
            if(!key.equals(I_CmsConstants.C_PROPERTY_CHANNELID)){
                Element property = m_docXml.createElement(C_EXPORT_TAG_PROPERTY);
                properties.appendChild(property);

                String value = (String) fileProperties.get(key);
                String propertyType = m_cms.readPropertydefinition(key, type).getType() + "";

                addElement(m_docXml, property, C_EXPORT_TAG_NAME, key);
                addElement(m_docXml, property, C_EXPORT_TAG_TYPE, propertyType);
                addCdataElement(m_docXml, property, C_EXPORT_TAG_VALUE, value);
            }
        }
        System.out.println("...OK");
    }

    /**
     * Writes the xml-config file (manifest) to the zip-file.
     */
    private void writeXmlConfigFile()
        throws CmsException {
        try {
            ZipEntry entry = new ZipEntry(C_EXPORT_XMLFILENAME);
            m_exportZipStream.putNextEntry(entry);
            A_CmsXmlContent.getXmlParser().getXmlText(m_docXml, m_exportZipStream);
            m_exportZipStream.closeEntry();
        } catch(Exception exc) {
            throw new CmsException(CmsException.C_UNKNOWN_EXCEPTION, exc);
        }
    }

    /**
     * Gets the content definition class method constructor
     * @returns content definition object
     */
    protected CmsMasterContent getContentDefinition(String classname, Class[] classes, Object[] objects) {
        CmsMasterContent cd = null;
        try {
            Class cdClass = Class.forName(classname);
            Constructor co = cdClass.getConstructor(classes);
            cd = (CmsMasterContent)co.newInstance(objects);
        } catch (InvocationTargetException ite) {
            if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
                A_OpenCms.log(A_OpenCms.C_OPENCMS_INFO, "[CmsExportModuledata] "+classname + " contentDefinitionConstructor: Invocation target exception!");
            }
        } catch (NoSuchMethodException nsm) {
            if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
                A_OpenCms.log(A_OpenCms.C_OPENCMS_INFO, "[CmsExportModuledata] "+classname + " contentDefinitionConstructor: Requested method was not found!");
            }
        } catch (InstantiationException ie) {
            if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
                A_OpenCms.log(A_OpenCms.C_OPENCMS_INFO, "[CmsExportModuledata] "+classname + " contentDefinitionConstructor: the reflected class is abstract!");
            }
        } catch (Exception e) {
            if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
                A_OpenCms.log(A_OpenCms.C_OPENCMS_INFO, "[CmsExportModuledata] "+classname + " contentDefinitionConstructor: Other exception! "+e);
            }
            if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {

⌨️ 快捷键说明

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