GuideTnCElement.java 2.39 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.xfa.Element
 *  org.apache.sling.commons.json.JSONException
 *  org.apache.sling.commons.json.JSONObject
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.aemds.guide.addon.dor.elements;

import com.adobe.aemds.guide.addon.dor.elements.DoRElement;
import com.adobe.aemds.guide.addon.dor.elements.DoRTnCElement;
import com.adobe.aemds.guide.addon.dor.elements.GuideElement;
import com.adobe.aemds.guide.addon.dor.elements.GuideElementProperties;
import com.adobe.xfa.Element;
import java.util.Properties;
import java.util.StringTokenizer;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class GuideTnCElement
extends GuideElement {
    private Logger logger = LoggerFactory.getLogger(GuideTnCElement.class);

    public GuideTnCElement(JSONObject jsonObject) {
        super(jsonObject);
        try {
            for (String key : GuideElementProperties.TNC_PROPERTIES) {
                this.properties.setProperty(key, jsonObject.getString(key));
            }
            this.initOtherProperty("items.reviewStatus.name", jsonObject);
            this.initOtherProperty("items.reviewDocument.name", jsonObject);
            String property = "tncTextContent";
            String tncTextContent = this.properties.getProperty(property);
            String replacedString = tncTextContent.replaceAll("<[^>]+>", "").replaceAll("&nbsp;", " ");
            this.properties.put(property, replacedString);
        }
        catch (JSONException e) {
            this.logger.error("Failed to construct", (Throwable)e);
        }
    }

    private void initOtherProperty(String property, JSONObject jsonObject) throws JSONException {
        StringTokenizer stringTokenizer = new StringTokenizer(property, ".");
        String token = stringTokenizer.nextToken();
        JSONObject propertyObject = jsonObject;
        while (stringTokenizer.hasMoreTokens()) {
            propertyObject = propertyObject.getJSONObject(token);
            token = stringTokenizer.nextToken();
        }
        this.properties.setProperty(property, propertyObject.getString(token));
    }

    @Override
    public DoRElement createDoRElement(Element xfaElement) throws Exception {
        return new DoRTnCElement(xfaElement);
    }
}