DoRDocumentFragmentElement.java 2.89 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.aemds.guide.addon.dor.DoRThreadLocal
 *  com.adobe.aemds.guide.addon.dor.DoRUtils
 *  com.adobe.forms.foundation.util.ContentConverterUtils
 *  com.adobe.xfa.Element
 *  com.adobe.xfa.Node
 *  com.adobe.xfa.content.Content
 *  com.adobe.xfa.template.Value
 *  org.apache.commons.lang3.StringUtils
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.api.resource.ValueMap
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.aemds.guide.addon.dor.elements;

import com.adobe.aemds.guide.addon.dor.DoRThreadLocal;
import com.adobe.aemds.guide.addon.dor.DoRUtils;
import com.adobe.aemds.guide.addon.dor.elements.DoRTextDrawElement;
import com.adobe.forms.foundation.util.ContentConverterUtils;
import com.adobe.xfa.Element;
import com.adobe.xfa.Node;
import com.adobe.xfa.content.Content;
import com.adobe.xfa.template.Value;
import java.util.Properties;
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DoRDocumentFragmentElement
extends DoRTextDrawElement {
    private static Logger logger = LoggerFactory.getLogger(DoRDocumentFragmentElement.class);

    public DoRDocumentFragmentElement(Element xfaElement) throws Exception {
        super(xfaElement);
    }

    @Override
    public void applyProperties(Properties properties) throws Exception {
        String data = "";
        if (!properties.containsKey("_value")) {
            if (properties.containsKey("assetRef")) {
                String assetRef = properties.getProperty("assetRef");
                Resource resource = DoRThreadLocal.getResourceResolver().getResource(assetRef);
                data = (String)resource.getValueMap().get((Object)"jcr:data");
            }
            properties.put("_value", data);
        }
        Value valueNode = (Value)this.xfaElement.resolveNode("#value");
        DoRUtils.enableRichText((Value)valueNode);
        if (properties.containsKey("_value")) {
            String text = properties.getProperty("_value");
            text = this.massageText(text);
            DoRUtils.setValue((Content)((Content)valueNode.getOneOfChild()), (String)text, (String)"text/html");
            properties.remove("_value");
        }
        super.applyProperties(properties, true);
    }

    @Override
    protected String massageText(String text) {
        String result = "";
        try {
            if (StringUtils.isNotBlank((CharSequence)text)) {
                result = ContentConverterUtils.convertToXFAHTML((String)text);
            }
        }
        catch (Exception e) {
            logger.error("Unable to convert HTML rich text to XFA compliant rich text for document fragment\n" + e.getMessage(), (Throwable)e);
        }
        return result;
    }
}