private void createResourceType() {

        CmsProject currentProject = m_cms.getRequestContext().getCurrentProject();
        try {

            CmsProject workProject = m_cms.createProject(
                "Add_resource_type_project",
                "Add resource type project",
                OpenCms.getDefaultUsers().getGroupAdministrators(),
                OpenCms.getDefaultUsers().getGroupAdministrators(),
                CmsProject.PROJECT_TYPE_TEMPORARY);
            m_cms.getRequestContext().setCurrentProject(workProject);

            if (!m_cms.existsResource(m_parentSchema.getValue())) {

                I_CmsResourceType type = OpenCms.getResourceManager().getResourceType(
                    CmsResourceTypeFolder.RESOURCE_TYPE_NAME);
                CmsResource res = m_cms.createResource(m_parentSchema.getValue(), type);
                m_cms.unlockResource(res);

            }
            if (!m_cms.existsResource(m_parentFormatter.getValue())) {

                I_CmsResourceType type = OpenCms.getResourceManager().getResourceType(
                    CmsResourceTypeFolder.RESOURCE_TYPE_NAME);
                CmsResource res = m_cms.createResource(m_parentFormatter.getValue(), type);
                m_cms.unlockResource(res);

            }

            String formatterPath = m_parentFormatter.getValue() + m_typeShortName.getValue() + ".jsp";
            String formatterConfigPath = m_parentFormatter.getValue() + m_typeShortName.getValue() + ".xml";
            String schemaPath = m_parentSchema.getValue() + m_typeShortName.getValue() + ".xsd";
            if (!m_cms.existsResource(formatterPath)) {
                m_cms.copyResource(SAMPLE_FORMATTER, formatterPath);
            }
            if (!m_cms.existsResource(schemaPath)) {
                m_cms.copyResource(SAMPLE_SCHEMA, schemaPath);
            }

            if (!m_cms.existsResource(formatterConfigPath)) {
                I_CmsResourceType configType = OpenCms.getResourceManager().getResourceType(
                    CmsFormatterConfigurationCache.TYPE_FORMATTER_CONFIG);
                List<CmsProperty> props = new ArrayList<CmsProperty>();
                props.add(new CmsProperty(CmsPropertyDefinition.PROPERTY_LOCALE, "en", null));
                props.add(new CmsProperty(CmsPropertyDefinition.PROPERTY_AVAILABLE_LOCALES, "en", null));

                m_cms.createResource(formatterConfigPath, configType, null, props);
            }
            CmsLockUtil.tryUnlock(m_cms, m_cms.readResource(formatterPath));
            CmsLockUtil.tryUnlock(m_cms, m_cms.readResource(formatterConfigPath));
            CmsLockUtil.tryUnlock(m_cms, m_cms.readResource(schemaPath));
            addResourceToModule(formatterPath, m_module);
            addResourceToModule(formatterConfigPath, m_module);
            addResourceToModule(schemaPath, m_module);
            adjustFormatterConfig(formatterPath, formatterConfigPath);
            adjustSchema(schemaPath, m_typeXPathName.getValue());
            adjustModuleConfig();

            List<I_CmsResourceType> types = new ArrayList<I_CmsResourceType>(m_module.getResourceTypes());
            // create the new resource type
            CmsResourceTypeXmlContent type = new CmsResourceTypeXmlContent();
            type.addConfigurationParameter(CmsResourceTypeXmlContent.CONFIGURATION_SCHEMA, schemaPath);
            type.setAdditionalModuleResourceType(true);
            type.setModuleName(m_module.getName());
            type.initConfiguration(
                m_typeShortName.getValue(),
                m_typeID.getValue(),
                CmsResourceTypeXmlContent.class.getName());
            types.add(type);
            m_module.setResourceTypes(types);

            List<CmsExplorerTypeSettings> settings = new ArrayList<CmsExplorerTypeSettings>(
                m_module.getExplorerTypes());
            // create the matching explorer type
            CmsExplorerTypeSettings setting = new CmsExplorerTypeSettings();
            setting.setTypeAttributes(
                m_typeShortName.getValue(),
                m_typeName.getValue(), //ToDo nicename
                null,
                null,
                ICON_SMALL_DEFAULT,
                ICON_BIG_DEFAULT,
                "xmlcontent",
                null,
                "false",
                null,
                null);
            setting.setAutoSetNavigation("false");
            setting.setAutoSetTitle("false");
            setting.setNewResourceOrder("10");
            setting.setAddititionalModuleExplorerType(true);
            addTypeMessages(setting, getMessageParentFolder(m_module.getName()));
            settings.add(setting);
            m_module.setExplorerTypes(settings);
            m_cms.unlockProject(workProject.getUuid());
            OpenCms.getPublishManager().publishProject(
                m_cms,
                new CmsLogReport(m_cms.getRequestContext().getLocale(), getClass()));
            OpenCms.getPublishManager().waitWhileRunning();
        } catch (Exception e) {
            LOG.error("Unable to create resource type", e);
        } finally {
            m_cms.getRequestContext().setCurrentProject(currentProject);
        }
    }
private void createResourceType ( ) { CmsProject currentProject = m_cms . getRequestContext ( ) . getCurrentProject ( ) ; try { CmsProject workProject = m_cms . createProject ( "Add_resource_type_project" , "Add resource type project" , OpenCms . getDefaultUsers ( ) . getGroupAdministrators ( ) , OpenCms . getDefaultUsers ( ) . getGroupAdministrators ( ) , CmsProject . PROJECT_TYPE_TEMPORARY ) ; m_cms . getRequestContext ( ) . setCurrentProject ( workProject ) ; if ( ! m_cms . existsResource ( m_parentSchema . getValue ( ) ) ) { I_CmsResourceType type = OpenCms . getResourceManager ( ) . getResourceType ( CmsResourceTypeFolder . RESOURCE_TYPE_NAME ) ; CmsResource res = m_cms . createResource ( m_parentSchema . getValue ( ) , type ) ; m_cms . unlockResource ( res ) ; } if ( ! m_cms . existsResource ( m_parentFormatter . getValue ( ) ) ) { I_CmsResourceType type = OpenCms . getResourceManager ( ) . getResourceType ( CmsResourceTypeFolder . RESOURCE_TYPE_NAME ) ; CmsResource res = m_cms . createResource ( m_parentFormatter . getValue ( ) , type ) ; m_cms . unlockResource ( res ) ; } String formatterPath = m_parentFormatter . getValue ( ) + m_typeShortName . getValue ( ) + ".jsp" ; String formatterConfigPath = m_parentFormatter . getValue ( ) + m_typeShortName . getValue ( ) + ".xml" ; String schemaPath = m_parentSchema . getValue ( ) + m_typeShortName . getValue ( ) + ".xsd" ; if ( ! m_cms . existsResource ( formatterPath ) ) { m_cms . copyResource ( SAMPLE_FORMATTER , formatterPath ) ; } if ( ! m_cms . existsResource ( schemaPath ) ) { m_cms . copyResource ( SAMPLE_SCHEMA , schemaPath ) ; } if ( ! m_cms . existsResource ( formatterConfigPath ) ) { I_CmsResourceType configType = OpenCms . getResourceManager ( ) . getResourceType ( CmsFormatterConfigurationCache . TYPE_FORMATTER_CONFIG ) ; List < CmsProperty > props = new ArrayList < CmsProperty > ( ) ; props . add ( new CmsProperty ( CmsPropertyDefinition . PROPERTY_LOCALE , "en" , null ) ) ; props . add ( new CmsProperty ( CmsPropertyDefinition . PROPERTY_AVAILABLE_LOCALES , "en" , null ) ) ; m_cms . createResource ( formatterConfigPath , configType , null , props ) ; } CmsLockUtil . tryUnlock ( m_cms , m_cms . readResource ( formatterPath ) ) ; CmsLockUtil . tryUnlock ( m_cms , m_cms . readResource ( formatterConfigPath ) ) ; CmsLockUtil . tryUnlock ( m_cms , m_cms . readResource ( schemaPath ) ) ; addResourceToModule ( formatterPath , m_module ) ; addResourceToModule ( formatterConfigPath , m_module ) ; addResourceToModule ( schemaPath , m_module ) ; adjustFormatterConfig ( formatterPath , formatterConfigPath ) ; adjustSchema ( schemaPath , m_typeXPathName . getValue ( ) ) ; adjustModuleConfig ( ) ; List < I_CmsResourceType > types = new ArrayList < I_CmsResourceType > ( m_module . getResourceTypes ( ) ) ; CmsResourceTypeXmlContent type = new CmsResourceTypeXmlContent ( ) ; type . addConfigurationParameter ( CmsResourceTypeXmlContent . CONFIGURATION_SCHEMA , schemaPath ) ; type . setAdditionalModuleResourceType ( true ) ; type . setModuleName ( m_module . getName ( ) ) ; type . initConfiguration ( m_typeShortName . getValue ( ) , m_typeID . getValue ( ) , CmsResourceTypeXmlContent . class . getName ( ) ) ; types . add ( type ) ; m_module . setResourceTypes ( types ) ; List < CmsExplorerTypeSettings > settings = new ArrayList < CmsExplorerTypeSettings > ( m_module . getExplorerTypes ( ) ) ; CmsExplorerTypeSettings setting = new CmsExplorerTypeSettings ( ) ; setting . setTypeAttributes ( m_typeShortName . getValue ( ) , m_typeName . getValue ( ) , null , null , ICON_SMALL_DEFAULT , ICON_BIG_DEFAULT , "xmlcontent" , null , "false" , null , null ) ; setting . setAutoSetNavigation ( "false" ) ; setting . setAutoSetTitle ( "false" ) ; setting . setNewResourceOrder ( "10" ) ; setting . setAddititionalModuleExplorerType ( true ) ; addTypeMessages ( setting , getMessageParentFolder ( m_module . getName ( ) ) ) ; settings . add ( setting ) ; m_module . setExplorerTypes ( settings ) ; m_cms . unlockProject ( workProject . getUuid ( ) ) ; OpenCms . getPublishManager ( ) . publishProject ( m_cms , new CmsLogReport ( m_cms . getRequestContext ( ) . getLocale ( ) , getClass ( ) ) ) ; OpenCms . getPublishManager ( ) . waitWhileRunning ( ) ; } catch ( Exception e ) { LOG . error ( "Unable to create resource type" , e ) ; } finally { m_cms . getRequestContext ( ) . setCurrentProject ( currentProject ) ; } }
Creates the new resource type.<p>