package com.brilliance.isc.doc.convert;

import com.brilliance.mda.runtime.mda.util.MdaUtils;
import freemarker.template.SimpleScalar;
import freemarker.template.TemplateMethodModelEx;
import freemarker.template.TemplateModelException;
import org.apache.commons.lang.StringEscapeUtils;
import org.springframework.util.CollectionUtils;

import java.util.List;

public class FormatHtmlHelper implements TemplateMethodModelEx {

    @Override
    public Object exec(List list) throws TemplateModelException {
        if (CollectionUtils.isEmpty(list) || list.get(0) == null) {
            return "<p> </p>";
        }
        String value = ((SimpleScalar)list.get(0)).getAsString();
        if(MdaUtils.isEmpty(value)){
            return "<p> </p>";
        }
        return "<p>"+ StringEscapeUtils.escapeHtml(value) +"</p>";
    }
}
