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

📄 cmsexportmoduledata.java

📁 cms是开源的框架
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                }
            } else {
                modules = moduleNames;
            }

            // now do the export for all modules with the given channel ids
            Enumeration enumModules = modules.elements();
            while (enumModules.hasMoreElements()) {
                // get the name of the content definition class
                String classname = (String)enumModules.nextElement();
                exportCos(exportNode, classname, getExportedChannelIds());
            }

            // close the export file
            closeExportFile(exportNode);

        } catch (CmsException e) {
            getReport().println(e);

            CmsMessageContainer message = Messages.get().container(
                Messages.ERR_COS_IMPORTEXPORT_ERROR_EXPORTING_TO_FILE_1,
                getExportFileName());
            if (LOG.isDebugEnabled()) {
                LOG.debug(message, e);
            }

            throw new CmsImportExportException(message, e);
        } catch (SAXException se) {
            getReport().println(se);

            CmsMessageContainer message = Messages.get().container(
                Messages.ERR_COS_IMPORTEXPORT_ERROR_EXPORTING_TO_FILE_1,
                getExportFileName());
            if (LOG.isDebugEnabled()) {
                LOG.debug(message, se);
            }

            throw new CmsImportExportException(message, se);
        } catch (IOException ioe) {
            getReport().println(ioe);

            CmsMessageContainer message = Messages.get().container(
                Messages.ERR_COS_IMPORTEXPORT_ERROR_EXPORTING_TO_FILE_1,
                getExportFileName());
            if (LOG.isDebugEnabled()) {
                LOG.debug(message, ioe);
            }

            throw new CmsImportExportException(message, ioe);
        } finally {
            // restore the site root
            getCms().getRequestContext().restoreSiteRoot();
        }
    }

    /**
     * @see org.opencms.importexport.CmsExport#addChildResources(java.lang.String)
     */
    protected void addChildResources(String folderName) throws CmsImportExportException, IOException, SAXException {

        try {
            // collect channel id information
            String channelId = getCms().readFolder(folderName, CmsResourceFilter.IGNORE_EXPIRATION).getResourceId().toString();
            if (channelId != null) {
                getExportedChannelIds().add(channelId);
            }

            // continue with super implementation
            super.addChildResources(folderName);
        } catch (CmsImportExportException e) {

            throw e;
        } catch (CmsException e) {

            CmsMessageContainer message = Messages.get().container(
                Messages.ERR_COS_IMPORTEXPORT_ERROR_ADDING_CHILD_RESOURCES_1,
                folderName);
            if (LOG.isDebugEnabled()) {
                LOG.debug(message, e);
            }

            throw new CmsImportExportException(message, e);
        }
    }

    /**
     * Returns the set of already exported channel Ids.<p>
     * 
     * @return the set of already exported channel Ids
     */
    protected Set getExportedChannelIds() {

        return m_exportedChannelIds;
    }

    /**
     * @see org.opencms.importexport.CmsExport#getExportNodeName()
     */
    protected String getExportNodeName() {

        return com.opencms.core.I_CmsConstants.C_EXPORT_TAG_MODULEXPORT;
    }

    /**
     * @see org.opencms.importexport.CmsExport#getResourceNodeName()
     */
    protected String getResourceNodeName() {

        return "channels";
    }

    /** 
     * @see org.opencms.importexport.CmsExport#isIgnoredProperty(org.opencms.file.CmsProperty)
     */
    protected boolean isIgnoredProperty(CmsProperty property) {

        if (property == null) {
            return true;
        }
        // don't export "channel" property
        return CmsPropertyDefinition.PROPERTY_CHANNELID.equals(property.getName());
    }

    /**
     * Sets the set of already exported channel Ids.<p>
     * 
     * @param exportedChannelIds the set of already exported channel Ids
     */
    protected void setExportedChannelIds(Set exportedChannelIds) {

        m_exportedChannelIds = exportedChannelIds;
    }

    /**
     * Exports the content definition data,
     * only content definition data from selected channels will be exported.<p>
     * 
     * @param parent the export root node
     * @param classname name of the content definition class 
     * @param exportedChannelIds set of channels that have been exported
     * @throws CmsException if something goes wrong
     * @throws SAXException if something goes wrong procesing the manifest.xml
     */
    private void exportCos(Element parent, String classname, Set exportedChannelIds) throws CmsException, SAXException {

        // output something to the report for the data
        getReport().println(
            Messages.get().container(Messages.RPT_EXPORT_MODULE_BEGIN_1, classname),
            I_CmsReport.FORMAT_HEADLINE);

        Iterator keys = exportedChannelIds.iterator();
        // get the subId of the module
        int subId = getContentDefinition(classname, new Class[] {CmsObject.class}, new Object[] {getCms()}).getSubId();
        // the number for identifying each master
        int masterNr = 1;

        Element masters = parent.addElement(C_EXPORT_TAG_MASTERS);
        getSaxWriter().writeOpen(masters);

        while (keys.hasNext()) {
            String channelId = (String)keys.next();
            try {
                Vector allDatasets = new Vector();
                // execute the static method readAllByChannel of the content definition class
                allDatasets = (Vector)Class.forName(classname).getMethod(
                    "readAllByChannel",
                    new Class[] {CmsObject.class, String.class, Integer.class}).invoke(
                    null,
                    new Object[] {getCms(), channelId, new Integer(subId)});

                for (int i = 0; i < allDatasets.size(); i++) {
                    CmsMasterDataSet curDataset = (CmsMasterDataSet)allDatasets.elementAt(i);
                    if (!m_exportedMasters.contains("" + curDataset.m_masterId)) {
                        exportCosModule(masters, classname, curDataset, masterNr, subId);
                        m_exportedMasters.add("" + curDataset.m_masterId);
                        masterNr++;
                    }
                }
            } catch (InvocationTargetException e) {
                getReport().println(e);
                if (CmsLog.getLog(this).isErrorEnabled()) {
                    CmsLog.getLog(this).error("Error exporting COS data for channel id " + channelId, e);
                }
            } catch (NoSuchMethodException e) {
                getReport().println(e);
                if (CmsLog.getLog(this).isErrorEnabled()) {
                    CmsLog.getLog(this).error("Error exporting COS data for channel id " + channelId, e);
                }
            } catch (IllegalArgumentException e) {
                getReport().println(e);
                if (CmsLog.getLog(this).isErrorEnabled()) {
                    CmsLog.getLog(this).error("Error exporting COS data for channel id " + channelId, e);
                }
            } catch (SecurityException e) {
                getReport().println(e);
                if (CmsLog.getLog(this).isErrorEnabled()) {
                    CmsLog.getLog(this).error("Error exporting COS data for channel id " + channelId, e);
                }
            } catch (IllegalAccessException e) {
                getReport().println(e);
                if (CmsLog.getLog(this).isErrorEnabled()) {
                    CmsLog.getLog(this).error("Error exporting COS data for channel id " + channelId, e);
                }
            } catch (ClassNotFoundException e) {
                getReport().println(e);
                if (CmsLog.getLog(this).isErrorEnabled()) {
                    CmsLog.getLog(this).error("Error exporting COS data for channel id " + channelId, e);
                }
            }
        }

        getSaxWriter().writeClose(masters);
        parent.remove(masters);

        getReport().println(
            Messages.get().container(Messages.RPT_EXPORT_MODULE_END_0, classname),
            I_CmsReport.FORMAT_HEADLINE);
    }

    /**
     * Export a single content definition.<P>
     * 
     * @param parent the export root node
     * @param classname name of the content definition class
     * @param dataset data for the content definition object instance
     * @param masterNr id of master
     * @param subId id of content definition
     * 
     * @throws CmsException if something goes wrong
     * @throws SAXException if something goes wrong procesing the manifest.xml
     */
    private void exportCosModule(Element parent, String classname, CmsMasterDataSet dataset, int masterNr, int subId)
    throws CmsException, SAXException {

        // output something to the report for the resource

        getReport().print(
            Messages.get().container(Messages.RPT_EXPORT_WITH_ID_2, dataset.m_title, dataset.m_masterId),
            I_CmsReport.FORMAT_NOTE);

        // the name of the XML-file where the dataset is stored
        String dataSetFile = "dataset_" + subId + "_" + masterNr + ".xml";
        // create new mastercontent for getting channels and media
        CmsMasterContent content = getContentDefinition(
            classname,
            new Class[] {CmsObject.class, CmsMasterDataSet.class},
            new Object[] {getCms(), dataset});
        // write these informations to the xml-manifest
        Element master = parent.addElement(C_EXPORT_TAG_MASTER);

        master.addElement(C_EXPORT_TAG_MASTER_SUBID).addText(Integer.toString(subId));
        // add the name of the datasetfile and create the datasetfile
        // with the information from the dataset
        master.addElement(C_EXPORT_TAG_MASTER_DATASET).addText(dataSetFile);
        exportCosModuleData(dataset, dataSetFile, masterNr, subId);
        // add the channel relation of this master        
        Element channelrel = master.addElement(C_EXPORT_TAG_MASTER_CHANNELREL);
        Vector moduleChannels = content.getChannels();
        for (int i = 0; i < moduleChannels.size(); i++) {
            String channelname = (String)moduleChannels.elementAt(i);
            channelrel.addElement(C_EXPORT_TAG_MASTER_CHANNELNAME).addText(channelname);
        }
        // add the mediaset
        Element mediaset = master.addElement(C_EXPORT_TAG_MASTER_MEDIASET);
        Vector moduleMedia = content.getMedia();
        for (int i = 0; i < moduleMedia.size(); i++) {
            // for each media add the name of the xml-file for the mediadata to the manifest
            // and create the files for the media information
            String mediaFile = "media_" + subId + "_" + masterNr + "_" + i + ".xml";
            mediaset.addElement(C_EXPORT_TAG_MASTER_MEDIA).addText(mediaFile);
            exportCosModuleMedia((CmsMasterMedia)moduleMedia.elementAt(i), mediaFile, masterNr, subId, i);

⌨️ 快捷键说明

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