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

📄 cmsobject.java

📁 内容管理
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    this.getOnlineElementCache().clearCache();
}

/**
 * Copies a file.
 *
 * @param source the complete path of the sourcefile.
 * @param destination the complete path of the destinationfolder.
 *
 * @throws CmsException if the file couldn't be copied, or the user
 * has not the appropriate rights to copy the file.
 */
public void copyResource(String source, String destination) throws CmsException {
    CmsResource res = readFileHeader(source);
    I_CmsResourceType rt = getResourceType(res.getType());
    rt.copyResource(this, source, destination, false);
}
/**
 * Copies a file.
 *
 * @param source the complete path of the sourcefile.
 * @param destination the complete path of the destinationfolder.
 * @param keepFlags <code>true</code> if the copy should keep the source file's flags,
 *        <code>false</code> if the copy should get the user's default flags.
 *
 * @throws CmsException if the file couldn't be copied, or the user
 * has not the appropriate rights to copy the file.
 */
public void copyResource(String source, String destination, boolean keepFlags) throws CmsException {
    CmsResource res = readFileHeader(source);
    I_CmsResourceType rt = getResourceType(res.getType());
    rt.copyResource(this, source, destination, keepFlags);
}
/**
 * Copies a file.
 *
 * @param source the complete path of the sourcefile.
 * @param destination the complete path of the destinationfolder.
 *
 * @throws CmsException if the file couldn't be copied, or the user
 * has not the appropriate rights to copy the file.
 */
protected void doCopyFile(String source, String destination) throws CmsException {
    m_rb.copyFile(m_context.currentUser(), m_context.currentProject(), getSiteRoot(source), getSiteRoot(destination));
}

/**
 * Copies a folder.
 *
 * @param source the complete path of the sourcefolder.
 * @param destination the complete path of the destinationfolder.
 *
 * @throws CmsException if the folder couldn't be copied, or if the
 * user has not the appropriate rights to copy the folder.
 */
protected void doCopyFolder(String source, String destination) throws CmsException {
    m_rb.copyFolder(m_context.currentUser(), m_context.currentProject(), getSiteRoot(source), getSiteRoot(destination));
}

/**
 * Copies a file.
 *
 * @param source the complete path of the sourcefile.
 * @param destination the complete path of the destinationfolder.
 *
 * @throws CmsException if the file couldn't be copied, or the user
 * has not the appropriate rights to copy the file.
 *
 * @deprecated Use copyResource instead.
 */
public void copyFile(String source, String destination) throws CmsException {
    copyResource(source, destination);
}
/**
 * Copies a folder.
 *
 * @param source the complete path of the sourcefolder.
 * @param destination the complete path of the destinationfolder.
 *
 * @throws CmsException if the folder couldn't be copied, or if the
 * user has not the appropriate rights to copy the folder.
 *
 * @deprecated Use copyResource instead.
 */
public void copyFolder(String source, String destination) throws CmsException {
    copyResource(source, destination);
}

/**
 * Copies a resource from the online project to a new, specified project.
 * <br>
 * Copying a resource will copy the file header or folder into the specified
 * offline project and set its state to UNCHANGED.
 *
 * @param resource the name of the resource.
     * @throws CmsException if operation was not successful.
 */
public void copyResourceToProject(String resource) throws CmsException {
    CmsResource res = readFileHeader(resource);
    I_CmsResourceType rt = getResourceType(res.getType());
    rt.copyResourceToProject(this, resource);
}

/**
 * Copies a resource from the online project to a new, specified project.
 * <br>
 * Copying a resource will copy the file header or folder into the specified
 * offline project and set its state to UNCHANGED.
 *
 * @param resource the name of the resource.
     * @throws CmsException if operation was not successful.
 */
protected void doCopyResourceToProject(String resource) throws CmsException {
    m_rb.copyResourceToProject(m_context.currentUser(), m_context.currentProject(), getSiteRoot(resource));
}

/**
 * Counts the locked resources in a project.
 *
 * @param id the id of the project
 * @return the number of locked resources in this project.
 *
 * @throws CmsException if operation was not successful.
 */
public int countLockedResources(int id) throws CmsException {
    return m_rb.countLockedResources(m_context.currentUser(), m_context.currentProject(), id);
}
/**
 * Creates a new file with the given content and resourcetype.<br>
 *
 * @param folder the complete path to the folder in which the file will be created.
 * @param filename the name of the new file.
 * @param contents the contents of the new file.
 * @param type the resourcetype of the new file.
 *
 * @return file a <code>CmsFile</code> object representing the newly created file.
 *
 * @throws if the resourcetype is set to folder. The CmsException is also thrown, if the
 * filename is not valid or if the user has not the appropriate rights to create a new file.
 *
 * @deprecated Use createResource instead.
 */
public CmsFile createFile(String folder, String filename, byte[] contents, String type) throws CmsException {
    return (CmsFile)createResource(folder, filename, type, null, contents);
}
/**
 * Creates a new file with the given content and resourcetype.
 *
 * @param folder the complete path to the folder in which the file will be created.
 * @param filename the name of the new file.
 * @param contents the contents of the new file.
 * @param type the resourcetype of the new file.
 * @param properties A Hashtable of properties, that should be set for this file.
 * The keys for this Hashtable are the names for properties, the values are
 * the values for the properties.
 *
 * @return file a <code>CmsFile</code> object representing the newly created file.
 *
 * @throws CmsException or if the resourcetype is set to folder.
 * The CmsException is also thrown, if the filename is not valid or if the user
 * has not the appropriate rights to create a new file.
 *
 * @deprecated Use createResource instead.
 */
public CmsFile createFile(String folder, String filename, byte[] contents, String type, Hashtable properties) throws CmsException {
    return (CmsFile)createResource(folder, filename, type, properties, contents);
}

    /**
     * Replaces and existing resource by another file with different content
     * and different file type.
     * 
     * @param filename the resource to replace
     * @param type the type of the new resource
     * @param newContent the content of the new resource
     */
    public void replaceResource(String filename, String type, Hashtable newProperties, byte[] newContent) throws CmsException {
        // save the properties of the old file
        Hashtable oldProperties = null;
        try {
            oldProperties = this.readAllProperties(filename);
        }
        catch (CmsException e) {
            oldProperties = new Hashtable();
        }
        
        // add the properties that might have been collected during
        // a file-upload-dialogue chain etc.
        if (newProperties!=null) {
            oldProperties.putAll( newProperties );
        }

        try {
            // delete the old file
            this.deleteResource(filename);

            // re-create the resource with the new content and the properties
            // of the old file that we deleted before
            this.createResource(filename, type, oldProperties, newContent, null);
        }
        catch (CmsException e1) {
            throw new CmsException( CmsException.C_FILESYSTEM_ERROR, e1 );
        }
        
        // clean-up the link management
        this.joinLinksToTargets( new CmsShellReport() );        
    }

/**
 * Creates a new folder.
 *
 * @param folder the complete path to the folder in which the new folder
 * will be created.
 * @param newFolderName the name of the new folder.
 *
 * @return folder a <code>CmsFolder</code> object representing the newly created folder.
 *
 * @throws CmsException if the foldername is not valid, or if the user has not the appropriate rights to create
 * a new folder.
 *
 * @deprecated Use createResource instead.
 */
public CmsFolder createFolder(String folder, String newFolderName) throws CmsException {
    return (CmsFolder)createResource(folder, newFolderName, C_TYPE_FOLDER_NAME);
}

/**
 * Creates a new channel.
 *
 * @param parentChannel the complete path to the channel in which the new channel
 * will be created.
 * @param newChannelName the name of the new channel.
 *
 * @return folder a <code>CmsFolder</code> object representing the newly created channel.
 *
 * @throws CmsException if the channelname is not valid, or if the user has not the appropriate rights to create
 * a new channel.
 *
 */
public CmsFolder createChannel(String parentChannel, String newChannelName) throws CmsException {
    try {
        setContextToCos();
        Hashtable properties = new Hashtable();
        int newChannelId = com.opencms.dbpool.CmsIdGenerator.nextId(com.opencms.defaults.master.CmsChannelBackoffice.C_TABLE_CHANNELID);
        properties.put(I_CmsConstants.C_PROPERTY_CHANNELID, newChannelId+"");
        return (CmsFolder)createResource(parentChannel, newChannelName, C_TYPE_FOLDER_NAME, properties);
    } finally {
        setContextToVfs();
    }
}

public CmsResource createResource(String folder, String name, String type) throws CmsException {
    return this.createResource(folder + name, type, new HashMap(), new byte[0], null );
}

public CmsResource createResource(String folder, String name, String type, Map properties) throws CmsException {
    return this.createResource(folder + name, type, properties, new byte[0], null);
}

public CmsResource createResource(String folder, String name, String type, Map properties, byte[] contents) throws CmsException {
    return this.createResource(folder + name, type, properties, contents, null);
}

public CmsResource createResource(String newResourceName, String type, Map properties, byte[] contents, Object parameter) throws CmsException {
    I_CmsResourceType rt = getResourceType(type);
    return rt.createResource(this, newResourceName, properties, contents, parameter);
}

/**
 * Creates a new file with the given content and resourcetype.<br>
 *
 * @param folder the complete path to the folder in which the file will be created.
 * @param filename the name of the new file.
 * @param contents the contents of the new file.
 * @param type the resourcetype of the new file.
 *
 * @return file a <code>CmsFile</code> object representing the newly created file.
 *
 * @throws CmsException if the resourcetype is set to folder. The CmsException is also thrown, if the
 * filename is not valid or if the user has not the appropriate rights to create a new file.
 */
protected CmsFile doCreateFile(String newFileName, byte[] contents, String type) throws CmsException {
    CmsFile file = m_rb.createFile(m_context.currentUser(), m_context.currentGroup(),
                                   m_context.currentProject(), getSiteRoot(newFileName), contents,
                                   type, new HashMap());
    return file;
}
/**
 * Creates a new file with the given content and resourcetype.
 *
 * @param folder the complete path to the folder in which the file will be created.
 * @param filename the name of the new file.
 * @param contents the contents of the new file.
 * @param type the resourcetype of the new file.
 * @param properties A Hashtable of properties, that should be set for this file.
 * The keys for this Hashtable are the names for properties, the values are
 * the values for the properties.
 *
 * @return file a <code>CmsFile</code> object representing the newly created file.
 *
 * @throws CmsException if the wrong properties are given, or if the resourcetype is set to folder.
 * The CmsException is also thrown, if the filename is not valid or if the user
 * has not the appropriate rights to create a new file.
 */
protected CmsFile doCreateFile(String newFileName, byte[] contents, String type, Map properties) throws CmsException {
    // avoid null-pointer exceptions
    if(properties == null) {
        properties = new Hashtable();
    }
    CmsFile file = m_rb.createFile(m_context.currentUser(), m_context.currentGroup(),
                                   m_context.currentProject(), getSiteRoot(newFileName), contents,
                                   type, properties);
    return file;
}

/**
 * Creates a new folder.
 *
 * @param folder the complete path to the folder in which the new folder
 * will be created.
 * @param newFolderName the name of the new folder.
 *
 * @return folder a <code>CmsFolder</code> object representing the newly created folder.
 *
 * @throws CmsException if the foldername is not valid, or if the user has not the appropriate rights to create
 * a new folder.
 */
protected CmsFolder doCreateFolder(String folder, String newFolderName) throws CmsException {
    CmsFolder cmsFolder = m_rb.createFolder(m_context.currentUser(), m_context.currentGroup(), m_context.currentProject(),
                                            getSiteRoot(folder + newFolderName + C_FOLDER_SEPARATOR), new Hashtable());
    return cmsFolder;
}

/**

⌨️ 快捷键说明

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