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

📄 cmsafterpublishstaticexporthandler.java

📁 一个cms内容管理平台
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            m_busy = false;
        }
    }

    /**
     * @see org.opencms.staticexport.A_CmsOnDemandStaticExportHandler#getRelatedFilesToPurge(java.lang.String, java.lang.String)
     */
    protected List getRelatedFilesToPurge(String exportFileName, String vfsName) {

        return Collections.EMPTY_LIST;
    }

    /**
     * Starts the static export on publish.<p>
     * 
     * Exports all modified resources after a publish process into the real FS.<p>
     * 
     * @param publishHistoryId the publichHistoryId of the published project
     * @param report an <code>{@link I_CmsReport}</code> instance to print output message, or <code>null</code> to write messages to the log file   
     *  
     * @throws CmsException in case of errors accessing the VFS
     * @throws IOException in case of erros writing to the export output stream
     * @throws ServletException in case of errors accessing the servlet 
     */
    private void exportAfterPublish(CmsUUID publishHistoryId, I_CmsReport report)
    throws CmsException, IOException, ServletException {

        // first check if the test resource was published already
        // if not, we must do a complete export of all static resources
        String rfsName = CmsFileUtil.normalizePath(OpenCms.getStaticExportManager().getExportPath(
            OpenCms.getStaticExportManager().getTestResource())
            + OpenCms.getStaticExportManager().getTestResource());

        if (LOG.isDebugEnabled()) {
            LOG.debug(Messages.get().getBundle().key(Messages.LOG_CHECKING_TEST_RESOURCE_1, rfsName));
        }
        File file = new File(rfsName);
        if (!file.exists()) {
            if (LOG.isDebugEnabled()) {
                LOG.debug(Messages.get().getBundle().key(Messages.LOG_TEST_RESOURCE_NOT_EXISTANT_0));
            }
            // the file is not there, so export everything
            OpenCms.getStaticExportManager().exportFullStaticRender(true, report);
        } else {
            if (LOG.isDebugEnabled()) {
                LOG.debug(Messages.get().getBundle().key(Messages.LOG_TEST_RESOURCE_EXISTS_0));
            }

            // delete all resources deleted during the publish process
            scrubExportFolders(publishHistoryId);

            // get the list of published resources from the publish history table
            CmsObject cms = OpenCms.initCmsObject(OpenCms.getDefaultUsers().getUserExport());
            List publishedResources = cms.readPublishedResources(publishHistoryId);

            // do the export
            doExportAfterPublish(publishedResources, report);
        }

    }

    /**
     * Exports all non template resources found in a list of published resources.<p>
     * 
     * @param cms the current cms object
     * @param publishedResources the list of published resources
     * @param report an I_CmsReport instance to print output message, or null to write messages to the log file
     * 
     * @return true if some template resources were found whil looping the list of published resources
     * 
     * @throws CmsException in case of errors accessing the VFS
     * @throws IOException in case of erros writing to the export output stream
     * @throws ServletException in case of errors accessing the servlet 
     */
    private boolean exportNonTemplateResources(CmsObject cms, List publishedResources, I_CmsReport report)
    throws CmsException, IOException, ServletException {

        CmsStaticExportManager manager = OpenCms.getStaticExportManager();
        String vfsName = null;
        List resourcesToExport = new ArrayList();
        boolean templatesFound = false;

        int count = 1;

        report.println(
            Messages.get().container(Messages.RPT_STATICEXPORT_NONTEMPLATE_RESOURCES_BEGIN_0),
            I_CmsReport.FORMAT_HEADLINE);

        // loop through all resources
        Iterator i = publishedResources.iterator();

        if (LOG.isDebugEnabled()) {
            LOG.debug(Messages.get().getBundle().key(
                Messages.LOG_EXPORTING_NON_TEMPLATE_1,
                new Integer(publishedResources.size())));
        }

        while (i.hasNext()) {
            CmsPublishedResource pupRes = (CmsPublishedResource)i.next();

            vfsName = pupRes.getRootPath();

            // only process this resource, if it is within the tree of allowed folders for static export
            if (manager.getExportFolderMatcher().match(vfsName)) {

                // only export VFS files, other data is handled elsewhere 
                if (pupRes.isVfsResource()) {
                    // get the export data object, if null is returned, this resource cannot be exported
                    CmsStaticExportData exportData = manager.getExportData(vfsName, cms);
                    if (exportData != null) {
                        CmsResource resource = null;
                        if (pupRes.isFile()) {
                            resource = exportData.getResource();
                        } else {
                            // the resource is a folder, check if PROPERTY_DEFAULT_FILE is set on folder
                            try {
                                String defaultFileName = cms.readPropertyObject(
                                    vfsName,
                                    CmsPropertyDefinition.PROPERTY_DEFAULT_FILE,
                                    false).getValue();
                                if (defaultFileName != null) {
                                    resource = cms.readResource(vfsName + defaultFileName);
                                }
                            } catch (CmsException e) {
                                // resource is (still) a folder, check default files specified in configuration
                                for (int j = 0; j < OpenCms.getDefaultFiles().size(); j++) {
                                    String tmpResourceName = vfsName + OpenCms.getDefaultFiles().get(j);
                                    try {
                                        resource = cms.readResource(tmpResourceName);
                                        break;
                                    } catch (CmsException e1) {
                                        // ignore all other exceptions and continue the lookup process
                                    }
                                }
                            }
                        }
                        if (resource != null) {
                            // check loader for current resource if it must be processed before exported
                            I_CmsResourceLoader loader = OpenCms.getResourceManager().getLoader(resource);
                            if (!loader.isStaticExportProcessable()) {
                                // this resource must not be processed, so export it (if it's not marked as deleted)
                                if (pupRes.getState() != CmsResource.STATE_DELETED) {
                                    // mark the resource for export to the real file system                  
                                    resourcesToExport.add(exportData);
                                }
                            } else {
                                // the resource is a template resource or a folder, so store the name of it in the DB for further use                  
                                templatesFound = true;
                                cms.writeStaticExportPublishedResource(
                                    exportData.getRfsName(),
                                    CmsStaticExportManager.EXPORT_LINK_WITHOUT_PARAMETER,
                                    "",
                                    System.currentTimeMillis());
                            }
                        }
                    }
                }
            }
        }

        // now do the export
        i = resourcesToExport.iterator();
        int size = resourcesToExport.size();

        if (LOG.isDebugEnabled()) {
            LOG.debug(Messages.get().getBundle().key(Messages.LOG_NUM_EXPORT_1, new Integer(size)));
        }
        while (i.hasNext()) {
            CmsStaticExportData exportData = (CmsStaticExportData)i.next();
            if (LOG.isDebugEnabled()) {
                LOG.debug(Messages.get().getBundle().key(
                    Messages.LOG_EXPORT_FILE_2,
                    exportData.getVfsName(),
                    exportData.getRfsName()));
            }

            report.print(org.opencms.report.Messages.get().container(
                org.opencms.report.Messages.RPT_SUCCESSION_2,
                new Integer(count++),
                new Integer(size)), I_CmsReport.FORMAT_NOTE);
            report.print(Messages.get().container(Messages.RPT_EXPORTING_0), I_CmsReport.FORMAT_NOTE);
            report.print(org.opencms.report.Messages.get().container(
                org.opencms.report.Messages.RPT_ARGUMENT_1,
                exportData.getVfsName()));
            report.print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0));
            int status = manager.export(null, null, cms, exportData);
            if (status == HttpServletResponse.SC_OK) {
                report.println(
                    org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0),
                    I_CmsReport.FORMAT_OK);
            } else {
                report.println(
                    org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_IGNORED_0),
                    I_CmsReport.FORMAT_NOTE);
            }

            if (LOG.isInfoEnabled()) {
                Object[] arguments = new Object[] {
                    exportData.getVfsName(),
                    exportData.getRfsName(),
                    new Integer(status)};
                LOG.info(Messages.get().getBundle().key(Messages.LOG_EXPORT_FILE_STATUS_3, arguments));
            }
        }

        resourcesToExport = null;

        report.println(
            Messages.get().container(Messages.RPT_STATICEXPORT_NONTEMPLATE_RESOURCES_END_0),
            I_CmsReport.FORMAT_HEADLINE);

        return templatesFound;
    }

⌨️ 快捷键说明

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