public void save(
        CmsObject cms,
        String name,
        boolean newOrdering,
        CmsResource pageResource,
        List<CmsContainerElementBean> elements) throws CmsException {

        cms = OpenCms.initCmsObject(cms);
        cms.getRequestContext().setSiteRoot("");
        String configPath;
        if (pageResource.isFolder()) {
            configPath = CmsStringUtil.joinPaths(
                pageResource.getRootPath(),
                CmsContainerConfigurationCache.INHERITANCE_CONFIG_FILE_NAME);
        } else {
            configPath = CmsStringUtil.joinPaths(
                CmsResource.getParentFolder(pageResource.getRootPath()),
                CmsContainerConfigurationCache.INHERITANCE_CONFIG_FILE_NAME);
        }
        CmsInheritedContainerState state = OpenCms.getADEManager().getInheritedContainerState(
            cms,
            CmsResource.getParentFolder(CmsResource.getParentFolder(configPath)),
            name);
        Set<String> keys = state.getNewElementKeys();

        CmsResource configRes = null;
        boolean needToUnlock = false;
        if (!cms.existsResource(configPath)) {
            // create it
            configRes = cms.createResource(
                configPath,
                OpenCms.getResourceManager().getResourceType(
                    CmsResourceTypeXmlContainerPage.INHERIT_CONTAINER_CONFIG_TYPE_NAME));
            needToUnlock = true;
        }
        if (configRes == null) {
            configRes = cms.readResource(configPath);
        }
        CmsFile configFile = cms.readFile(configRes);
        // make sure the internal flag is set
        configFile.setFlags(configFile.getFlags() | CmsResource.FLAG_INTERNAL);
        CmsXmlContent content = CmsXmlContentFactory.unmarshal(cms, configFile);
        for (Locale localeToRemoveEntryFrom : content.getLocales()) {
            removeExistingEntry(cms, content, localeToRemoveEntryFrom, name);
        }
        CmsContainerConfiguration configuration = createConfigurationBean(newOrdering, elements, keys);

        Locale saveLocale = Locale.ENGLISH;
        for (Locale locale : content.getLocales()) {
            if (!saveLocale.equals(locale)) {
                content.removeLocale(locale);
            }
        }
        if (!content.hasLocale(saveLocale)) {
            content.addLocale(cms, saveLocale);
        }
        Element parentElement = content.getLocaleNode(saveLocale);
        serializeSingleConfiguration(cms, name, configuration, parentElement);
        byte[] contentBytes = content.marshal();
        configFile.setContents(contentBytes);
        CmsLock prevLock = cms.getLock(configRes);
        boolean alreadyLocked = prevLock.isOwnedBy(cms.getRequestContext().getCurrentUser());
        if (!alreadyLocked) {
            cms.lockResourceTemporary(configRes);
            needToUnlock = true;
        }
        try {
            cms.writeFile(configFile);
        } finally {
            if (needToUnlock) {
                cms.unlockResource(configRes);
            }
        }
    }
public void save ( CmsObject cms , String name , boolean newOrdering , CmsResource pageResource , List < CmsContainerElementBean > elements ) throws CmsException { cms = OpenCms . initCmsObject ( cms ) ; cms . getRequestContext ( ) . setSiteRoot ( "" ) ; String configPath ; if ( pageResource . isFolder ( ) ) { configPath = CmsStringUtil . joinPaths ( pageResource . getRootPath ( ) , CmsContainerConfigurationCache . INHERITANCE_CONFIG_FILE_NAME ) ; } else { configPath = CmsStringUtil . joinPaths ( CmsResource . getParentFolder ( pageResource . getRootPath ( ) ) , CmsContainerConfigurationCache . INHERITANCE_CONFIG_FILE_NAME ) ; } CmsInheritedContainerState state = OpenCms . getADEManager ( ) . getInheritedContainerState ( cms , CmsResource . getParentFolder ( CmsResource . getParentFolder ( configPath ) ) , name ) ; Set < String > keys = state . getNewElementKeys ( ) ; CmsResource configRes = null ; boolean needToUnlock = false ; if ( ! cms . existsResource ( configPath ) ) { configRes = cms . createResource ( configPath , OpenCms . getResourceManager ( ) . getResourceType ( CmsResourceTypeXmlContainerPage . INHERIT_CONTAINER_CONFIG_TYPE_NAME ) ) ; needToUnlock = true ; } if ( configRes == null ) { configRes = cms . readResource ( configPath ) ; } CmsFile configFile = cms . readFile ( configRes ) ; configFile . setFlags ( configFile . getFlags ( ) | CmsResource . FLAG_INTERNAL ) ; CmsXmlContent content = CmsXmlContentFactory . unmarshal ( cms , configFile ) ; for ( Locale localeToRemoveEntryFrom : content . getLocales ( ) ) { removeExistingEntry ( cms , content , localeToRemoveEntryFrom , name ) ; } CmsContainerConfiguration configuration = createConfigurationBean ( newOrdering , elements , keys ) ; Locale saveLocale = Locale . ENGLISH ; for ( Locale locale : content . getLocales ( ) ) { if ( ! saveLocale . equals ( locale ) ) { content . removeLocale ( locale ) ; } } if ( ! content . hasLocale ( saveLocale ) ) { content . addLocale ( cms , saveLocale ) ; } Element parentElement = content . getLocaleNode ( saveLocale ) ; serializeSingleConfiguration ( cms , name , configuration , parentElement ) ; byte [ ] contentBytes = content . marshal ( ) ; configFile . setContents ( contentBytes ) ; CmsLock prevLock = cms . getLock ( configRes ) ; boolean alreadyLocked = prevLock . isOwnedBy ( cms . getRequestContext ( ) . getCurrentUser ( ) ) ; if ( ! alreadyLocked ) { cms . lockResourceTemporary ( configRes ) ; needToUnlock = true ; } try { cms . writeFile ( configFile ) ; } finally { if ( needToUnlock ) { cms . unlockResource ( configRes ) ; } } }
Saves a list of container element beans to a file in the VFS.<p>

@param cms the current CMS context
@param name the name of the configuration to save
@param newOrdering true if a new ordering needs to be saved
@param pageResource a container page or folder
@param elements the elements whose data should be saved

@throws CmsException if something goes wrong