public static String createResource ( CmsObject cmsObject , String newLink , Locale locale , String sitePath , String modelFileName , String mode , String postCreateHandler ) { String [ ] newLinkParts = newLink . split ( "\\|" ) ; String rootPath = newLinkParts [ 1 ] ; String typeName = newLinkParts [ 2 ] ; CmsFile modelFile = null ; if ( StringUtils . equalsIgnoreCase ( mode , CmsEditorConstants . MODE_COPY ) ) { try { modelFile = cmsObject . readFile ( sitePath ) ; } catch ( CmsException e ) { LOG . warn ( "The resource at path" + sitePath + "could not be read. Thus it can not be used as model file." , e ) ; } } CmsADEConfigData adeConfig = OpenCms . getADEManager ( ) . lookupConfiguration ( cmsObject , rootPath ) ; CmsResourceTypeConfig typeConfig = adeConfig . getResourceType ( typeName ) ; CmsResource newElement = null ; try { CmsObject cmsClone = cmsObject ; if ( ( locale != null ) && ! cmsObject . getRequestContext ( ) . getLocale ( ) . equals ( locale ) ) { // in case the content locale does not match the request context locale, use a clone cms with the appropriate locale cmsClone = OpenCms . initCmsObject ( cmsObject ) ; cmsClone . getRequestContext ( ) . setLocale ( locale ) ; } newElement = typeConfig . createNewElement ( cmsClone , modelFile , rootPath ) ; CmsPair < String , String > handlerParameter = I_CmsCollectorPostCreateHandler . splitClassAndConfig ( postCreateHandler ) ; I_CmsCollectorPostCreateHandler handler = A_CmsResourceCollector . getPostCreateHandler ( handlerParameter . getFirst ( ) ) ; handler . onCreate ( cmsClone , cmsClone . readFile ( newElement ) , modelFile != null , handlerParameter . getSecond ( ) ) ; } catch ( CmsException e ) { LOG . error ( "Could not create resource." , e ) ; } return newElement == null ? null : cmsObject . getSitePath ( newElement ) ; }
Creates a new resource .