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

📄 cmsresourcetypeimage.java

📁 cms是开源的框架
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                parentFolder,
                CmsPropertyDefinition.PROPERTY_IMAGE_SIZE,
                false);
            if (!fileSizeProperty.isNullProperty()) {
                // image.size property has been set
                String value = fileSizeProperty.getValue().trim();
                if (CmsStringUtil.isNotEmpty(value)) {
                    if (PROPERTY_VALUE_UNLIMITED.equals(value)) {
                        // in this case no downscaling must be done
                        return null;
                    } else {
                        CmsImageScaler scaler = new CmsImageScaler(value);
                        if (scaler.isValid()) {
                            // special folder based scaler settings have been set
                            return scaler;
                        }
                    }
                }
            }
        } catch (CmsException e) {
            // ignore, continue with given downScaler
        }
        return (CmsImageScaler)m_downScaler.clone();
    }

    /**
     * Returns the static type id of this (default) resource type.<p>
     * 
     * @return the static type id of this (default) resource type
     */
    public static int getStaticTypeId() {

        return m_staticTypeId;
    }

    /**
     * Returns the static type name of this (default) resource type.<p>
     * 
     * @return the static type name of this (default) resource type
     */
    public static String getStaticTypeName() {

        return RESOURCE_TYPE_NAME;
    }

    /**
     * @see org.opencms.file.types.I_CmsResourceType#createResource(org.opencms.file.CmsObject, org.opencms.db.CmsSecurityManager, java.lang.String, byte[], java.util.List)
     */
    public CmsResource createResource(
        CmsObject cms,
        CmsSecurityManager securityManager,
        String resourcename,
        byte[] content,
        List properties) throws CmsException {

        if (CmsImageLoader.isEnabled()) {
            String rootPath = cms.getRequestContext().addSiteRoot(resourcename);
            // get the downscaler to use
            CmsImageScaler downScaler = getDownScaler(cms, rootPath);
            // create a new image scale adjuster
            CmsImageAdjuster adjuster = new CmsImageAdjuster(content, rootPath, properties, downScaler);
            // update the image scale adjuster - this will calculate the image dimensions and (optionally) downscale the size
            adjuster.adjust();
            // continue with the updated content and properties
            content = adjuster.getContent();
            properties = adjuster.getProperties();
        }
        return super.createResource(cms, securityManager, resourcename, content, properties);
    }

    /**
     * @see org.opencms.file.types.I_CmsResourceType#getLoaderId()
     */
    public int getLoaderId() {

        return m_staticLoaderId;
    }

    /**
     * @see org.opencms.file.types.I_CmsResourceType#importResource(org.opencms.file.CmsObject, org.opencms.db.CmsSecurityManager, java.lang.String, org.opencms.file.CmsResource, byte[], java.util.List)
     */
    public CmsResource importResource(
        CmsObject cms,
        CmsSecurityManager securityManager,
        String resourcename,
        CmsResource resource,
        byte[] content,
        List properties) throws CmsException {

        if (CmsImageLoader.isEnabled()) {
            // siblings have null content in import
            if (content != null) {
                // get the downscaler to use
                CmsImageScaler downScaler = getDownScaler(cms, resource.getRootPath());
                // create a new image scale adjuster
                CmsImageAdjuster adjuster = new CmsImageAdjuster(
                    content,
                    resource.getRootPath(),
                    properties,
                    downScaler);
                // update the image scale adjuster - this will calculate the image dimensions and (optionally) adjust the size
                adjuster.adjust();
                // continue with the updated content and properties
                content = adjuster.getContent();
                properties = adjuster.getProperties();
            }
        }
        return super.importResource(cms, securityManager, resourcename, resource, content, properties);
    }

    /**
     * @see org.opencms.file.types.A_CmsResourceType#initConfiguration(java.lang.String, java.lang.String, String)
     */
    public void initConfiguration(String name, String id, String className) throws CmsConfigurationException {

        if ((OpenCms.getRunLevel() > OpenCms.RUNLEVEL_2_INITIALIZING) && m_staticFrozen) {
            // configuration already frozen
            throw new CmsConfigurationException(Messages.get().container(
                Messages.ERR_CONFIG_FROZEN_3,
                this.getClass().getName(),
                getStaticTypeName(),
                new Integer(getStaticTypeId())));
        }

        if (!RESOURCE_TYPE_NAME.equals(name)) {
            // default resource type MUST have default name
            throw new CmsConfigurationException(Messages.get().container(
                Messages.ERR_INVALID_RESTYPE_CONFIG_NAME_3,
                this.getClass().getName(),
                RESOURCE_TYPE_NAME,
                name));
        }

        // freeze the configuration
        m_staticFrozen = true;

        super.initConfiguration(RESOURCE_TYPE_NAME, id, className);
        // set static members with values from the configuration        
        m_staticTypeId = m_typeId;

        if (CmsImageLoader.isEnabled()) {
            // the image loader is enabled, image operations are supported
            m_staticLoaderId = CmsImageLoader.RESOURCE_LOADER_ID_IMAGE_LOADER;
            // set the maximum size scaler
            String downScaleParams = CmsImageLoader.getDownScaleParams();
            if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(downScaleParams)) {
                m_downScaler = new CmsImageScaler(downScaleParams);
                if (!m_downScaler.isValid()) {
                    // ignore invalid parameters
                    m_downScaler = null;
                }
            }
        } else {
            // no image operations are supported, use dump loader
            m_staticLoaderId = CmsDumpLoader.RESOURCE_LOADER_ID;
            // disable maximum image size operation
            m_downScaler = null;
        }
    }

    /**
     * @see org.opencms.file.types.I_CmsResourceType#replaceResource(org.opencms.file.CmsObject, org.opencms.db.CmsSecurityManager, org.opencms.file.CmsResource, int, byte[], java.util.List)
     */
    public void replaceResource(
        CmsObject cms,
        CmsSecurityManager securityManager,
        CmsResource resource,
        int type,
        byte[] content,
        List properties) throws CmsException {

        if (CmsImageLoader.isEnabled()) {
            // check if the user has write access and if resource is locked
            // done here so that no image operations are performed in case no write access is granted
            securityManager.checkPermissions(
                cms.getRequestContext(),
                resource,
                CmsPermissionSet.ACCESS_WRITE,
                true,
                CmsResourceFilter.ALL);

            // get the downscaler to use
            CmsImageScaler downScaler = getDownScaler(cms, resource.getRootPath());
            // create a new image scale adjuster
            CmsImageAdjuster adjuster = new CmsImageAdjuster(content, resource.getRootPath(), properties, downScaler);
            // update the image scale adjuster - this will calculate the image dimensions and (optionally) adjust the size
            adjuster.adjust();
            // continue with the updated content 
            content = adjuster.getContent();
            if (adjuster.getProperties() != null) {
                // write properties
                writePropertyObjects(cms, securityManager, resource, adjuster.getProperties());
            }
        }
        super.replaceResource(cms, securityManager, resource, type, content, properties);
    }

    /**
     * @see org.opencms.file.types.I_CmsResourceType#writeFile(org.opencms.file.CmsObject, org.opencms.db.CmsSecurityManager, org.opencms.file.CmsFile)
     */
    public CmsFile writeFile(CmsObject cms, CmsSecurityManager securityManager, CmsFile resource)
    throws CmsException, CmsVfsException, CmsSecurityException {

        if (CmsImageLoader.isEnabled()) {
            // check if the user has write access and if resource is locked
            // done here so that no image operations are performed in case no write access is granted
            securityManager.checkPermissions(
                cms.getRequestContext(),
                resource,
                CmsPermissionSet.ACCESS_WRITE,
                true,
                CmsResourceFilter.ALL);

            // get the downscaler to use
            CmsImageScaler downScaler = getDownScaler(cms, resource.getRootPath());
            // create a new image scale adjuster
            CmsImageAdjuster adjuster = new CmsImageAdjuster(
                resource.getContents(),
                resource.getRootPath(),
                null,
                downScaler);
            // update the image scale adjuster - this will calculate the image dimensions and (optionally) adjust the size
            adjuster.adjust();
            // continue with the updated content 
            resource.setContents(adjuster.getContent());
            if (adjuster.getProperties() != null) {
                // write properties
                writePropertyObjects(cms, securityManager, resource, adjuster.getProperties());
            }
        }
        return super.writeFile(cms, securityManager, resource);
    }
}

⌨️ 快捷键说明

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