private static void updateFile(CmsObject cms, CmsFile file, CmsMacroResolver macroResolver) throws CmsException {

        String encoding = cms.readPropertyObject(file, CmsPropertyDefinition.PROPERTY_CONTENT_ENCODING, true).getValue(
            OpenCms.getSystemInfo().getDefaultEncoding());
        String content;
        try {
            content = macroResolver.resolveMacros(new String(file.getContents(), encoding));
        } catch (UnsupportedEncodingException e) {
            try {
                content = macroResolver.resolveMacros(
                    new String(file.getContents(), Charset.defaultCharset().toString()));
            } catch (UnsupportedEncodingException e1) {
                content = macroResolver.resolveMacros(new String(file.getContents()));
            }
        }
        // update the content
        try {
            file.setContents(content.getBytes(encoding));
        } catch (UnsupportedEncodingException e) {
            try {
                file.setContents(content.getBytes(Charset.defaultCharset().toString()));
            } catch (UnsupportedEncodingException e1) {
                file.setContents(content.getBytes());
            }
        }
        // write the target file
        cms.writeFile(file);
    }
private static void updateFile ( CmsObject cms , CmsFile file , CmsMacroResolver macroResolver ) throws CmsException { String encoding = cms . readPropertyObject ( file , CmsPropertyDefinition . PROPERTY_CONTENT_ENCODING , true ) . getValue ( OpenCms . getSystemInfo ( ) . getDefaultEncoding ( ) ) ; String content ; try { content = macroResolver . resolveMacros ( new String ( file . getContents ( ) , encoding ) ) ; } catch ( UnsupportedEncodingException e ) { try { content = macroResolver . resolveMacros ( new String ( file . getContents ( ) , Charset . defaultCharset ( ) . toString ( ) ) ) ; } catch ( UnsupportedEncodingException e1 ) { content = macroResolver . resolveMacros ( new String ( file . getContents ( ) ) ) ; } } try { file . setContents ( content . getBytes ( encoding ) ) ; } catch ( UnsupportedEncodingException e ) { try { file . setContents ( content . getBytes ( Charset . defaultCharset ( ) . toString ( ) ) ) ; } catch ( UnsupportedEncodingException e1 ) { file . setContents ( content . getBytes ( ) ) ; } } cms . writeFile ( file ) ; }
Updates a single file with the given macro resolver.<p>

@param cms the cms context
@param file the file to update
@param macroResolver the macro resolver to update with

@throws CmsException if something goes wrong