cmsworkplacemanager.java

来自「找了很久才找到到源代码」· Java 代码 · 共 1,709 行 · 第 1/5 页

JAVA
1,709
字号
        if (CmsLog.INIT.isInfoEnabled()) {
            CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_ADD_TYPE_SETTING_1, settings.getName()));
        }
        if (m_explorerTypeSettings != null) {
            // reset the list of all explorer type settings, but not during startup
            initExplorerTypeSettings();
        }
    }

    /** 
     * Adds the list of explorer type settings from the given module.<p>
     * 
     * @param module the module witch contains the explorer type settings to add
     */
    public void addExplorerTypeSettings(CmsModule module) {

        List explorerTypes = module.getExplorerTypes();
        if ((explorerTypes != null) && (explorerTypes.size() > 0)) {
            Iterator i = explorerTypes.iterator();
            while (i.hasNext()) {
                CmsExplorerTypeSettings settings = (CmsExplorerTypeSettings)i.next();
                if (m_explorerTypeSettingsFromModules.contains(settings)) {
                    m_explorerTypeSettingsFromModules.remove(settings);
                }
                m_explorerTypeSettingsFromModules.add(settings);
                if (CmsLog.INIT.isInfoEnabled()) {
                    CmsLog.INIT.info(Messages.get().getBundle().key(
                        Messages.INIT_ADD_TYPE_SETTING_1,
                        settings.getName()));
                }
            }
            // reset the list of all explorer type settings
            initExplorerTypeSettings();
        }
    }

    /**
     * Adds newly created export point to the workplace configuration.<p>
     * 
     * @param uri the export point uri
     * @param destination the export point destination
     */
    public void addExportPoint(String uri, String destination) {

        CmsExportPoint point = new CmsExportPoint(uri, destination);
        m_exportPoints.add(point);
        if (CmsLog.INIT.isInfoEnabled() && (point.getDestinationPath() != null)) {
            CmsLog.INIT.info(Messages.get().getBundle().key(
                Messages.INIT_ADD_EXPORT_POINT_2,
                point.getUri(),
                point.getDestinationPath()));
        }
    }

    /**
     * Adds a folder to the list of labeled folders.<p>
     * 
     * @param uri the folder uri to add
     */
    public void addLabeledFolder(String uri) {

        m_labelSiteFolders.add(uri);
        if (CmsLog.INIT.isInfoEnabled()) {
            CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_LABEL_LINKS_IN_FOLDER_1, uri));
        }
    }

    /**
     * Adds a new folder to the list of localized workplace folders.<p>
     * 
     * @param uri a new folder to add to the list of localized workplace folders
     */
    public void addLocalizedFolder(String uri) {

        m_localizedFolders.add(uri);
        if (CmsLog.INIT.isInfoEnabled()) {
            CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_WORKPLACE_LOCALIZED_1, uri));
        }
    }

    /**
     * Adds a menu rule set from the workplace configuration to the configured menu rules.<p>
     * 
     * @param menuRule the menu rule to add
     */
    public void addMenuRule(CmsMenuRule menuRule) {

        if (CmsLog.INIT.isInfoEnabled()) {
            CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_ADD_MENURULE_1, menuRule.getName()));
        }
        m_menuRules.add(menuRule);
    }

    /**
     * Adds a condition definition class for a given resource type glass name that is triggered before opening the editor.<p>
     * 
     * @param resourceTypeName the name of the resource type
     * @param preEditorConditionDefinitionClassName full class name of the condition definition class
     */
    public void addPreEditorConditionDefinition(String resourceTypeName, String preEditorConditionDefinitionClassName) {

        try {
            I_CmsPreEditorActionDefinition preEditorCondition = (I_CmsPreEditorActionDefinition)Class.forName(
                preEditorConditionDefinitionClassName).newInstance();
            preEditorCondition.setResourceTypeName(resourceTypeName);
            m_preEditorConditionDefinitions.add(preEditorCondition);
            if (CmsLog.INIT.isInfoEnabled()) {
                CmsLog.INIT.info(Messages.get().getBundle().key(
                    Messages.INIT_EDITOR_PRE_ACTION_2,
                    preEditorConditionDefinitionClassName,
                    resourceTypeName));
            }
        } catch (Exception e) {
            LOG.error(Messages.get().getBundle().key(
                Messages.LOG_INVALID_EDITOR_PRE_ACTION_1,
                preEditorConditionDefinitionClassName), e);
        }
    }

    /**
     * Returns if the autolock resources feature is enabled.<p>
     * 
     * @return true if the autolock resources feature is enabled, otherwise false
     */
    public boolean autoLockResources() {

        return m_autoLockResources;
    }

    /**
     * Implements the event listener of this class.<p>
     * 
     * @see org.opencms.main.I_CmsEventListener#cmsEvent(org.opencms.main.CmsEvent)
     */
    public void cmsEvent(CmsEvent event) {

        switch (event.getType()) {
            case I_CmsEventListener.EVENT_CLEAR_CACHES:
                // clear the cached message objects
                m_messages = new HashMap();
                m_editorDisplayOptions.clearCache();
                if (LOG.isDebugEnabled()) {
                    LOG.debug(Messages.get().getBundle().key(Messages.LOG_EVENT_CLEAR_CACHES_0));
                }
                break;
            default: // no operation
        }
    }

    /**
     * Creates a temporary file which is needed while working in an editor with preview option.<p>
     * 
     * @param cms the cms context
     * @param resourceName the name of the resource to copy
     * @param currentProjectId the id of the project to work with
     * 
     * @return the file name of the temporary file
     * 
     * @throws CmsException if something goes wrong
     */
    public String createTempFile(CmsObject cms, String resourceName, CmsUUID currentProjectId) throws CmsException {

        // check that the current user has write permissions
        if (!cms.hasPermissions(cms.readResource(resourceName, CmsResourceFilter.ALL), CmsPermissionSet.ACCESS_WRITE)) {
            throw new CmsPermissionViolationException(org.opencms.db.Messages.get().container(
                org.opencms.db.Messages.ERR_PERM_DENIED_2,
                resourceName,
                "w"));
        }

        // initialize admin cms context
        CmsObject adminCms = getAdminCms(cms);

        // generate the filename of the temporary file
        String temporaryFilename = CmsWorkplace.getTemporaryFileName(resourceName);

        // check if the temporary file is already present
        if (adminCms.existsResource(temporaryFilename, CmsResourceFilter.ALL)) {
            // delete old temporary file
            if (!cms.getLock(temporaryFilename).isUnlocked()) {
                // steal lock
                cms.changeLock(temporaryFilename);
            } else {
                // lock resource to current user
                cms.lockResource(temporaryFilename);
            }
            cms.deleteResource(temporaryFilename, CmsResource.DELETE_PRESERVE_SIBLINGS);
        }

        try {
            // switch to the temporary file project
            adminCms.getRequestContext().setCurrentProject(cms.readProject(getTempFileProjectId()));
            // copy the file to edit to a temporary file
            adminCms.copyResource(resourceName, temporaryFilename, CmsResource.COPY_AS_NEW);
        } finally {
            // switch back to current project
            adminCms.getRequestContext().setCurrentProject(cms.readProject(currentProjectId));
        }

        try {
            // switch to the temporary file project
            cms.getRequestContext().setCurrentProject(
                cms.readProject(OpenCms.getWorkplaceManager().getTempFileProjectId()));
            // lock the temporary file
            cms.changeLock(temporaryFilename);
            // touch the temporary file
            cms.setDateLastModified(temporaryFilename, System.currentTimeMillis(), false);
            // set the temporary file flag
            CmsResource tempFile = cms.readResource(temporaryFilename, CmsResourceFilter.ALL);
            int flags = tempFile.getFlags();
            if ((flags & CmsResource.FLAG_TEMPFILE) == 0) {
                flags += CmsResource.FLAG_TEMPFILE;
            }
            cms.chflags(temporaryFilename, flags);
            // remove eventual release & expiration date from temporary file to make preview in editor work
            cms.setDateReleased(temporaryFilename, CmsResource.DATE_RELEASED_DEFAULT, false);
            cms.setDateExpired(temporaryFilename, CmsResource.DATE_EXPIRED_DEFAULT, false);
            // remove visibility permissions for everybody on temporary file if possible
            if (cms.hasPermissions(tempFile, CmsPermissionSet.ACCESS_CONTROL)) {
                cms.chacc(
                    temporaryFilename,
                    I_CmsPrincipal.PRINCIPAL_GROUP,
                    OpenCms.getDefaultUsers().getGroupUsers(),
                    "-v");
                cms.chacc(
                    temporaryFilename,
                    I_CmsPrincipal.PRINCIPAL_GROUP,
                    OpenCms.getDefaultUsers().getGroupProjectmanagers(),
                    "-v");
            }
        } finally {
            // switch back to current project
            cms.getRequestContext().setCurrentProject(cms.readProject(currentProjectId));
        }

        return temporaryFilename;
    }

    /**
     * Returns the customized workplace foot.<p>
     * 
     * @return the customized workplace foot
     */
    public CmsWorkplaceCustomFoot getCustomFoot() {

        return m_customFoot;
    }

    /**
     * Gets the access object of the type settings.<p>
     * 
     * @return access object of the type settings
     */
    public CmsExplorerTypeAccess getDefaultAccess() {

        return m_defaultAccess;
    }

    /**
     * Returns the Workplace default locale.<p>
     * 
     * @return  the Workplace default locale
     */
    public Locale getDefaultLocale() {

        return m_defaultLocale;
    }

    /**
     * Returns the Workplace default user settings.<p>
     * 
     * @return  the Workplace default user settings
     */
    public CmsDefaultUserSettings getDefaultUserSettings() {

        return m_defaultUserSettings;
    }

    /**
     * Returns all instantiated dialog handlers for the workplace.<p>
     * 
     * @return all instantiated dialog handlers for the workplace
     */
    public Map getDialogHandler() {

        return m_dialogHandler;
    }

    /**
     * Returns the instanciated dialog handler class for the key or null, if there is no mapping for the key.<p>
     *  
     * @param key the key whose associated value is to be returned
     * @return the instanciated dialog handler class for the key
     */
    public Object getDialogHandler(String key) {

        return m_dialogHandler.get(key);
    }

    /**
     * Returns a new instance of the configured direct edit provider.<p>
     * 
     * @return a new instance of the configured direct edit provider
     */
    public I_CmsDirectEditProvider getDirectEditProvider() {

        return m_directEditProvider.newInstance();
    }

    /**
     * Returns the instanciated editor action handler class.<p>
     * 
     * @return the instanciated editor action handler class
     */
    public I_CmsEditorActionHandler getEditorActionHandler() {

        return m_editorAction;
    }

    /**
     * Returns the instanciated editor CSS handler classes.<p>
     * 
     * @return the instanciated editor CSS handler classes
     */
    public List getEditorCssHandlers() {

        return m_editorCssHandlers;
    }

    /**
     * Returns the instanciated editor display option class.<p>
     * 
     * @return the instanciated editor display option class
     */
    public CmsEditorDisplayOptions getEditorDisplayOptions() {

        return m_editorDisplayOptions;
    }

    /**
     * Returns the instanciated editor handler class.<p>
     * 

⌨️ 快捷键说明

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