class FrevvoFormAbstractService implements FrevvoFormService {

    @Override
    public void updateXML(AcmContainerEntity entity, Authentication auth, Class<?> c)
    {
        if (entity != null)
        {
            EcmFile ecmFile = getEcmFile(entity, getFormName().toLowerCase());

            // if there is no ecmFile then we have to XML file to update so we can stop here.

            if (ecmFile != null)
            {

                Object form = null;
                String existingXml = "";

                if (ecmFile.getId() != null)
                {
                    try
                    {
                        // Taking existing XML for the form
                        existingXml = getEcmFileService().download(ecmFile.getId());

                        // Creating Frevvo form from the existing XML
                        form = convertFromXMLToObject(cleanXML(existingXml), c);
                    }
                    catch (AcmUserActionFailedException e)
                    {
                        LOG.error("Cannot download file with id={}", ecmFile.getId());
                    }
                }

                form = convertToFrevvoForm(entity, form);

                if (form != null)
                {
                    String xml = convertFromObjectToXML(form);

                    // compare the XMLs and upload the new file only if changed
                    Diff diff = DiffBuilder.compare(Input.fromString(xml))
                            .withTest(Input.fromString(existingXml))
                            .withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText))
                            .build();

                    if (diff.hasDifferences())
                    {
                        updateXML(xml, ecmFile, auth);
                    }
                }
            }
        }
    }

}