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 FormatXmlHelper implements TemplateMethodModelEx {

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