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

📄 cmsresourcetypeplain.java

📁 内容管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            setDefaultFlags(cms, destination);
        }
    }

    /**
     * Copies the resourcename to the current offline project
     * @param cms The CmsObject
     * @param resourceName The name of the resource
     *
     * @throws CmsException if operation was not successful.
     */
    public void copyResourceToProject(CmsObject cms, String resourceName) throws CmsException{
        cms.doCopyResourceToProject(resourceName);
    };

    /**
     * Creates a new resource
     *
     * @param cms The CmsObject
     * @param folder The name of the parent folder
     * @param name The name of the file
     * @param properties The properties of the file
     * @param contents The file content
     * @param parameter an object (e.g. a HashMap) holding parameters (e.g. key/value coded) to create the new resource
     *
     * @throws CmsException if operation was not successful.
     */
    public CmsResource createResource(CmsObject cms, String newFileName, Map properties, byte[] contents, Object parameter) throws CmsException{
        CmsResource res;
        if (m_resourceTypeName == null) {
            res = cms.doCreateFile(newFileName, contents, I_CmsConstants.C_TYPE_PLAIN_NAME, properties); 
        } else {            
            res = cms.doCreateFile(newFileName, contents, m_resourceTypeName, properties);
        }
        // lock the new file
        cms.doLockResource(res.getAbsolutePath(), true);
        return res;
    }



    /**
    * Deletes a resource.
    *
    * @param filename the complete path of the file.
    *
    * @throws CmsException if the file couldn't be deleted, or if the user
    * has not the appropriate rights to delete the file.
    */
    public void deleteResource(CmsObject cms, String filename) throws CmsException{
        cms.doDeleteFile(filename);
    }

    /**
    * Deletes a resource.
    *
    * @param filename the complete path of the file.
    *
    * @throws CmsException if the file couldn't be deleted, or if the user
    * has not the appropriate rights to delete the file.
    */
    public void undeleteResource(CmsObject cms, String filename) throws CmsException{
        cms.doUndeleteFile(filename);
    }

    /**
     * Does the Linkmanagement when a resource will be exported.
     * When a resource has to be exported, the ID磗 inside the
     * Linkmanagement-Tags have to be changed to the corresponding URL磗
     *
     * @param file is the file that has to be changed
     */
    public CmsFile exportResource(CmsObject cms, CmsFile file) throws CmsException {
        // nothing to do here, because there couldn磘 be any Linkmanagement-Tags inside a plain-resource
        return file;
    }

    /**
     * Imports a resource.
     *
     * @param cms The current CmsObject.
     * @param source The sourcepath of the resource to import.
     * @param destination The destinationpath of the resource to import.
     * @param type The type of the resource to import.
     * @param user The name of the owner of the resource.
     * @param group The name of the group of the resource.
     * @param access The access flags of the resource.
     * @param properties A Hashtable with the properties of the resource.
     * The key is the name of the propertydefinition, the value is the propertyvalue.
     * @param launcherStartClass The name of the launcher startclass.
     * @param content The filecontent if the resource is of type file
     * @param importPath The name of the import path
     * 
     * @return CmsResource The imported resource.
     * 
     * @throws Throws CmsException if the resource could not be imported
     * 
     */
    public CmsResource importResource(CmsObject cms, String source, String destination, String type,
                                       String user, String group, String access, long lastmodified, 
                                       Map properties, String launcherStartClass, byte[] content, String importPath) 
                       throws CmsException {
        CmsResource importedResource = null;

        destination = importPath + destination;

        boolean changed = true;
        int resourceType = cms.getResourceType(type).getResourceType();
		int launcherType = cms.getResourceType(type).getLauncherType();
		if((launcherStartClass == null) || ("".equals(launcherStartClass))){
			launcherStartClass = cms.getResourceType(type).getLauncherClass();
        }
        // try to read the new owner and group
        CmsUser resowner = null;
        CmsGroup resgroup = null;
        try{
            resowner = cms.readUser(user);
        } catch (CmsException e){
            if (DEBUG>0) System.err.println("[" + this.getClass().getName() + ".importResource/1] User " + user + " not found");
            if(I_CmsLogChannels.C_LOGGING && A_OpenCms.isLogging(I_CmsLogChannels.C_OPENCMS_CRITICAL)) {
                A_OpenCms.log(I_CmsLogChannels.C_OPENCMS_CRITICAL, "[" + this.getClass().getName() + ".importResource/1] User " + user + " not found");
            }                
            resowner = cms.getRequestContext().currentUser();   
        }
        try{
            resgroup = cms.readGroup(group);
        } catch (CmsException e){
            if (DEBUG>0) System.err.println("[" + this.getClass().getName() + ".importResource/2] Group " + group + " not found");
            if(I_CmsLogChannels.C_LOGGING && A_OpenCms.isLogging(I_CmsLogChannels.C_OPENCMS_CRITICAL)) {
                A_OpenCms.log(I_CmsLogChannels.C_OPENCMS_CRITICAL, "[" + this.getClass().getName() + ".importResource/2] Group " + group + " not found");
            }  
            resgroup = cms.getRequestContext().currentGroup();  
        }       
        try {
            importedResource = cms.doImportResource(destination, resourceType ,properties, launcherType, 
                                             launcherStartClass, resowner.getName(), resgroup.getName(), Integer.parseInt(access), lastmodified, content);
            if(importedResource != null){
                changed = false;
            }
        } catch (CmsException e) {
            // an exception is thrown if the resource already exists
        }
        if(changed){
        	// if the resource already exists it must be updated
            lockResource(cms,destination, true);
            cms.doWriteResource(destination,properties,resowner.getName(), resgroup.getName(),Integer.parseInt(access),resourceType,content);
            importedResource = cms.readFileHeader(destination);
        }

        return importedResource;
    }

    /**
    * Locks a given resource.
    * <br>
    * A user can lock a resource, so he is the only one who can write this
    * resource.
    *
    * @param resource the complete path to the resource to lock.
    * @param force if force is <code>true</code>, a existing locking will be overwritten.
    *
    * @throws CmsException if the user has not the rights to lock this resource.
    * It will also be thrown, if there is a existing lock and force was set to false.
    */
    public void lockResource(CmsObject cms, String resource, boolean force) throws CmsException{
        cms.doLockResource(resource, force);
    }

    /**
    * Moves a resource to the given destination.
    *
    * @param source the complete path of the sourcefile.
    * @param destination the complete path of the destinationfile.
    *
    * @throws CmsException if the user has not the rights to move this resource,
    * or if the file couldn't be moved.
    */
    public void moveResource(CmsObject cms, String source, String destination) throws CmsException{
        cms.doMoveFile(source, destination);
    }

    /**
    * Renames the file to the new name.
    *
    * @param oldname the complete path to the file which will be renamed.
    * @param newname the new name of the file.
    *
    * @throws CmsException if the user has not the rights
    * to rename the file, or if the file couldn't be renamed.
    */
    public void renameResource(CmsObject cms, String oldname, String newname) throws CmsException{
        cms.doRenameFile(oldname, newname);
    }

    /**
     * Restores a file in the current project with a version in the backup
     *
     * @param cms The CmsObject
     * @param versionId The version id of the resource
     * @param filename The name of the file to restore
     *
     * @throws CmsException  Throws CmsException if operation was not succesful.
     */
    public void restoreResource(CmsObject cms, int versionId, String filename) throws CmsException{
        if(!cms.accessWrite(filename)){
            throw new CmsException(filename, CmsException.C_NO_ACCESS);
        }
        cms.doRestoreResource(versionId, filename);
    }

    /**
    * Undo changes in a resource.
    * <br>
    *
    * @param resource the complete path to the resource to be restored.
    *
    * @throws CmsException if the user has not the rights
    * to write this resource.
    */
    public void undoChanges(CmsObject cms, String resource) throws CmsException{
        if(!cms.accessWrite(resource)){
            throw new CmsException(resource, CmsException.C_NO_ACCESS);
        }
        cms.doUndoChanges(resource);
    }

    /**
    * Unlocks a resource.
    * <br>
    * A user can unlock a resource, so other users may lock this file.
    *
    * @param resource the complete path to the resource to be unlocked.
    *
    * @throws CmsException if the user has not the rights
    * to unlock this resource.
    */
    public void unlockResource(CmsObject cms, String resource) throws CmsException{
        cms.doUnlockResource(resource);
    }

    /**
     * Set the access flags of the copied resource to the default values.
     * @param cms The CmsObject.
     * @param filename The name of the file.
     * @throws Throws CmsException if something goes wrong.
     */
    protected void setDefaultFlags(CmsObject cms, String filename)
        throws CmsException {

        Hashtable startSettings=null;
        Integer accessFlags=null;
        startSettings=(Hashtable)cms.getRequestContext().currentUser().getAdditionalInfo(C_ADDITIONAL_INFO_STARTSETTINGS);
        if (startSettings != null) {
            accessFlags=(Integer)startSettings.get(C_START_ACCESSFLAGS);
        }
        if (accessFlags == null) {
            accessFlags = new Integer(C_ACCESS_DEFAULT_FLAGS);
        }
        chmod(cms, filename, accessFlags.intValue(), false);
    }

    /**
     * Changes the project-id of the resource to the new project
     * for publishing the resource directly
     *
     * @param newProjectId The Id of the new project
     * @param resourcename The name of the resource to change
     */
    public void changeLockedInProject(CmsObject cms, int newProjectId, String resourcename)
        throws CmsException{
        cms.doChangeLockedInProject(newProjectId, resourcename);
    }
}

⌨️ 快捷键说明

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