public static CmsXmlContentDefinition getContentDefinitionForResource(CmsObject cms, CmsResource resource)
    throws CmsException {

        CmsXmlContentDefinition contentDef = null;
        I_CmsResourceType resType = OpenCms.getResourceManager().getResourceType(resource.getTypeId());
        String schema = resType.getConfiguration().get(CmsResourceTypeXmlContent.CONFIGURATION_SCHEMA);
        if (schema != null) {
            try {
                // this wont in most cases read the file content because of caching
                contentDef = unmarshal(cms, schema);
            } catch (CmsException e) {
                // this should never happen, unless the configured schema is different than the schema in the XML
                if (!LOG.isDebugEnabled()) {
                    LOG.warn(e);
                }
                LOG.debug(e.getLocalizedMessage(), e);
            }
        }
        if (contentDef == null) {
            // could still be empty since it is not mandatory to configure the resource type in the XML configuration
            // try through the XSD relation
            List<CmsRelation> relations = cms.getRelationsForResource(
                resource,
                CmsRelationFilter.TARGETS.filterType(CmsRelationType.XSD));
            if ((relations != null) && !relations.isEmpty()) {
                CmsXmlEntityResolver entityResolver = new CmsXmlEntityResolver(cms);
                String xsd = cms.getSitePath(relations.get(0).getTarget(cms, CmsResourceFilter.ALL));
                contentDef = entityResolver.getCachedContentDefinition(xsd);
            }
        }
        if (contentDef == null) {
            // could still be empty if the XML content has been saved with an OpenCms before 8.0.0
            // so, to unmarshal is the only possibility left
            CmsXmlContent content = CmsXmlContentFactory.unmarshal(cms, cms.readFile(resource));
            contentDef = content.getContentDefinition();
        }

        return contentDef;
    }
public static CmsXmlContentDefinition getContentDefinitionForResource ( CmsObject cms , CmsResource resource ) throws CmsException { CmsXmlContentDefinition contentDef = null ; I_CmsResourceType resType = OpenCms . getResourceManager ( ) . getResourceType ( resource . getTypeId ( ) ) ; String schema = resType . getConfiguration ( ) . get ( CmsResourceTypeXmlContent . CONFIGURATION_SCHEMA ) ; if ( schema != null ) { try { contentDef = unmarshal ( cms , schema ) ; } catch ( CmsException e ) { if ( ! LOG . isDebugEnabled ( ) ) { LOG . warn ( e ) ; } LOG . debug ( e . getLocalizedMessage ( ) , e ) ; } } if ( contentDef == null ) { List < CmsRelation > relations = cms . getRelationsForResource ( resource , CmsRelationFilter . TARGETS . filterType ( CmsRelationType . XSD ) ) ; if ( ( relations != null ) && ! relations . isEmpty ( ) ) { CmsXmlEntityResolver entityResolver = new CmsXmlEntityResolver ( cms ) ; String xsd = cms . getSitePath ( relations . get ( 0 ) . getTarget ( cms , CmsResourceFilter . ALL ) ) ; contentDef = entityResolver . getCachedContentDefinition ( xsd ) ; } } if ( contentDef == null ) { CmsXmlContent content = CmsXmlContentFactory . unmarshal ( cms , cms . readFile ( resource ) ) ; contentDef = content . getContentDefinition ( ) ; } return contentDef ; }
Factory method that returns the XML content definition instance for a given resource.<p>

@param cms the cms-object
@param resource the resource

@return the XML content definition

@throws CmsException if something goes wrong