XFAJSONTransformerUtil.java 28.3 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  org.apache.commons.lang3.StringEscapeUtils
 *  org.apache.commons.lang3.StringUtils
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.api.resource.ResourceResolver
 *  org.apache.sling.api.resource.ResourceUtil
 *  org.apache.sling.api.resource.ValueMap
 *  org.apache.sling.commons.json.JSONArray
 *  org.apache.sling.commons.json.JSONObject
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.aemds.guide.xfa;

import com.adobe.aemds.guide.utils.GuideConstants;
import com.adobe.aemds.guide.utils.GuideUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.commons.json.JSONArray;
import org.apache.sling.commons.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/*
 * This class specifies class file version 49.0 but uses Java 6 signatures.  Assumed Java 6.
 */
public class XFAJSONTransformerUtil {
    private Logger logger = LoggerFactory.getLogger(XFAJSONTransformerUtil.class);
    public static final Hashtable<String, String[]> fieldUiRTMap = new Hashtable();
    public static final Hashtable<String, String> defaultFieldUiMap;
    public static final Hashtable<String, String[]> drawUiRTMap;
    public static final Hashtable<String, String> mandatoryConvertor;
    public static final Hashtable<String, String> assistPriorityConvertor;
    public static final Hashtable<String, String> multiSelectConvertor;
    public static final Hashtable<String, List<String>> oneOfChild;
    private static String UNNAMED_PREFIX;
    private int unnamedCount = 0;
    private ResourceResolver resourceResolver;
    private String xfaPath;
    private HashMap<String, Integer> nameCountMap;

    public XFAJSONTransformerUtil() {
        this.resourceResolver = null;
        this.xfaPath = "";
        this.nameCountMap = new HashMap();
    }

    public XFAJSONTransformerUtil(ResourceResolver resourceResolver, String xfaPath) {
        this.resourceResolver = resourceResolver;
        this.xfaPath = xfaPath;
        this.nameCountMap = new HashMap();
    }

    public Object getOrElse(JSONObject jsonObject, String jsonXpath, Object defaultValue, boolean isAttr) throws Exception {
        JSONObject currObject = jsonObject;
        String[] propChain = jsonXpath.split("\\.");
        Object value = null;
        block0 : for (int i = 0; i < propChain.length; ++i) {
            String property = propChain[i];
            String attrName = "";
            String attrValue = "";
            int attrIndex = property.indexOf("(");
            if (attrIndex != -1) {
                String attrString;
                property = propChain[i].substring(0, attrIndex);
                attrName = attrString = propChain[i].substring(attrIndex + 1, propChain[i].length() - 1);
                int ind = attrString.indexOf("=");
                if (ind != -1) {
                    attrName = attrString.substring(0, ind);
                    attrValue = attrString.substring(ind + 1);
                }
            }
            boolean isLastProp = i == propChain.length - 1;
            JSONObject tmpCurrentObject = currObject;
            currObject = null;
            value = null;
            if (tmpCurrentObject != null) {
                if ("oneOfChild".equals(property)) {
                    currObject = this.getOneOfChild(tmpCurrentObject, oneOfChild.get(tmpCurrentObject.get("_class")));
                    continue;
                }
                if (isLastProp && tmpCurrentObject.has(property)) {
                    value = tmpCurrentObject.get(property);
                    continue;
                }
                if ((isLastProp && isAttr || !tmpCurrentObject.has("children") || !(tmpCurrentObject.get("children") instanceof JSONArray)) && (!tmpCurrentObject.has("items") || !(tmpCurrentObject.get("items") instanceof JSONObject))) continue;
                JSONArray array = tmpCurrentObject.getJSONArray("children");
                for (int j = 0; j < array.length(); ++j) {
                    boolean flag;
                    String arrayItemAttrValue;
                    JSONObject arrayItem = array.getJSONObject(j);
                    if (!property.equals(arrayItem.getString("_class")) && (!arrayItem.has("guideNodeClass") || !property.equals(arrayItem.getString("guideNodeClass")))) continue;
                    boolean bl = flag = attrIndex == -1;
                    if (!flag && attrValue.equals(arrayItemAttrValue = arrayItem.getString(attrName))) {
                        flag = true;
                    }
                    if (!flag) continue;
                    currObject = arrayItem;
                    continue block0;
                }
                continue;
            }
            return defaultValue;
        }
        if (currObject != null) {
            return currObject;
        }
        if (value != null) {
            return value;
        }
        return defaultValue;
    }

    public Object getOrElseFromAfJson(JSONObject jsonObject, String jsonXpath, Object defaultValue, boolean isAttr) throws Exception {
        JSONObject currObject = jsonObject;
        String[] propChain = jsonXpath.split("\\.");
        String value = null;
        for (int i = 0; i < propChain.length; ++i) {
            String property = propChain[i];
            boolean isLastProp = i == propChain.length - 1;
            JSONObject tmpCurrentObject = currObject;
            currObject = null;
            value = null;
            if (tmpCurrentObject == null) continue;
            if (!isAttr && tmpCurrentObject.has(property)) {
                currObject = (JSONObject)tmpCurrentObject.get(property);
                continue;
            }
            if ((!isLastProp || !isAttr) && tmpCurrentObject.has("items") && tmpCurrentObject.get("items") instanceof JSONObject) {
                JSONObject itemsJsonObject = (JSONObject)tmpCurrentObject.get("items");
                if (itemsJsonObject.has(property)) {
                    currObject = (JSONObject)itemsJsonObject.get(property);
                    continue;
                }
                currObject = null;
                continue;
            }
            if (isLastProp && isAttr) {
                value = tmpCurrentObject.getString(property);
                continue;
            }
            return defaultValue;
        }
        if (currObject != null) {
            return currObject;
        }
        if (value != null) {
            return value;
        }
        return defaultValue;
    }

    private Hashtable<String, JSONObject> getItems(JSONObject fieldJson) throws Exception {
        Hashtable<String, JSONObject> result = new Hashtable<String, JSONObject>();
        if (fieldJson.has("children") && fieldJson.get("children") instanceof JSONArray) {
            JSONObject saveItems = null;
            JSONObject displayItems = null;
            JSONArray fieldChildren = fieldJson.getJSONArray("children");
            for (int i = 0; i < fieldChildren.length(); ++i) {
                JSONObject fieldChild = fieldChildren.getJSONObject(i);
                if (!"items".equals(fieldChild.get("_class"))) continue;
                if (fieldChild.has("save") && "1".equals(fieldChild.getString("save"))) {
                    saveItems = fieldChild;
                    continue;
                }
                displayItems = fieldChild;
            }
            if (saveItems == null && displayItems != null) {
                saveItems = displayItems;
            }
            if (saveItems != null) {
                result.put("saveItems", saveItems);
                if (displayItems == null) {
                    displayItems = saveItems;
                }
                result.put("displayItems", displayItems);
            }
        }
        return result;
    }

    public String[] getDropDownOptions(JSONObject fieldJson) throws Exception {
        Hashtable<String, JSONObject> items = this.getItems(fieldJson);
        JSONObject saveItems = items.get("saveItems");
        JSONObject displayItems = items.get("displayItems");
        JSONArray saveChildren = null;
        JSONArray displayChildren = null;
        String[] result = new String[]{};
        if (saveItems != null && saveItems.has("children")) {
            saveChildren = (JSONArray)saveItems.get("children");
            displayChildren = (JSONArray)displayItems.get("children");
        }
        if (saveChildren != null && saveChildren.length() > 0) {
            result = new String[saveChildren.length()];
            for (int i = 0; i < saveChildren.length(); ++i) {
                JSONObject saveChild = saveChildren.getJSONObject(i);
                JSONObject displayChild = displayChildren.getJSONObject(i);
                String saveValue = (String)this.getOrElse(saveChild, "_value", "", true);
                String displayValue = (String)this.getOrElse(displayChild, "_value", "", true);
                result[i] = saveValue + "=" + displayValue;
            }
        }
        return result;
    }

    public String convertItemsToOptions(JSONObject fieldJson) throws Exception {
        Hashtable<String, JSONObject> items = this.getItems(fieldJson);
        JSONObject saveItems = items.get("saveItems");
        if (saveItems != null && saveItems.has("children") && saveItems.get("children") instanceof JSONArray && saveItems.getJSONArray("children").length() > 0) {
            JSONObject itemValueChild = saveItems.getJSONArray("children").getJSONObject(0);
            String itemOption = (String)this.getOrElse(itemValueChild, "_value", "", true);
            String title = this.getTitle(fieldJson);
            return itemOption + "=" + title;
        }
        return null;
    }

    public JSONObject getOneOfChild(JSONObject jsonObject, List<String> oneOfChildList) throws Exception {
        if (jsonObject != null && jsonObject.has("children") && jsonObject.get("children") instanceof JSONArray) {
            JSONArray objectChildren = jsonObject.getJSONArray("children");
            for (int i = 0; i < objectChildren.length(); ++i) {
                JSONObject child = (JSONObject)objectChildren.get(i);
                String childType = child.getString("_class");
                if (!oneOfChildList.contains(childType)) continue;
                return child;
            }
        }
        return null;
    }

    public Hashtable<String, Object> getTableProperties(Hashtable<String, Object> input) {
        if (input == null) {
            input = new Hashtable();
        }
        input.put((String)"sling:resourceType", (String)"fd/af/components/table");
        input.put("guideNodeClass", "guideTable");
        return input;
    }

    public Hashtable<String, Object> getPanelProperties(Hashtable<String, Object> input) {
        if (input == null) {
            input = new Hashtable();
        }
        input.put((String)"sling:resourceType", (String)"fd/af/components/panel");
        input.put("guideNodeClass", "guidePanel");
        return input;
    }

    public Hashtable<String, Object> getLayoutProperties(Hashtable<String, Object> input, boolean isTableMode) {
        if (input == null) {
            input = new Hashtable();
        }
        input.put((String)"jcr:primaryType", (String)"nt:unstructured");
        if (isTableMode) {
            input.put("sling:resourceType", "fd/af/layouts/tableLayout");
            input.put("mobileLayout", "headersLeft");
        } else {
            input.put("sling:resourceType", "fd/af/layouts/gridFluidLayout");
        }
        return input;
    }

    public Hashtable<String, Object> getCommonProperties(Hashtable<String, Object> input, JSONObject jsonObject) throws Exception {
        if (input == null) {
            input = new Hashtable();
        }
        input.put((String)"name", (String)GuideUtils.getOrGenerateUniqueName(this.getOrGenerateName(jsonObject), this.nameCountMap));
        String title = this.getTitle(jsonObject);
        if (title == null) {
            title = "";
        }
        input.put("jcr:title", title);
        input.put("jcr:primaryType", "nt:unstructured");
        this.putGuideProp(input, jsonObject, "bindRef", "extras.extras(name=FS_EXTRAS).text(name=FS_SOM)._value", null, null);
        this.putGuideProp(input, jsonObject, "dataSom", "extras.extras(name=FS_EXTRAS).text(name=FS_DATA_SOM)._value", null, null);
        this.putGuideProp(input, jsonObject, "isFragment", "extras.extras(name=FS_EXTRAS).text(name=isFragment)._value", null, null);
        String usehref = (String)this.getOrElse(jsonObject, "extras.extras(name=FS_EXTRAS).text(name=usehref)._value", null, true);
        if (usehref != null && usehref.length() > 0) {
            this.handleXDPFragment(input, jsonObject, usehref);
        }
        return input;
    }

    public void handleXDPFragment(Hashtable<String, Object> input, JSONObject obj, String usehref) {
        try {
            String xdpRef = StringUtils.substringBeforeLast((String)usehref, (String)"#");
            String fragmentModelRootFromUsehref = "";
            String fragRef = null;
            String bindRef = (String)input.get("bindRef");
            fragmentModelRootFromUsehref = StringUtils.substringAfter((String)usehref, (String)"#subform");
            fragmentModelRootFromUsehref = StringUtils.substringBeforeLast((String)fragmentModelRootFromUsehref, (String)")");
            fragmentModelRootFromUsehref = StringUtils.replace((String)fragmentModelRootFromUsehref, (String)".", (String)"[0].") + "[0]";
            String basePathOfXFAFile = StringUtils.substringBeforeLast((String)this.xfaPath, (String)"/");
            xdpRef = StringUtils.replace((String)xdpRef, (String)"\\", (String)"/");
            xdpRef = StringUtils.substringBeforeLast((String)xdpRef, (String)"#");
            xdpRef = basePathOfXFAFile + "/" + xdpRef;
            xdpRef = ResourceUtil.normalize((String)xdpRef);
            String query = "/jcr:root/content/dam/formsanddocuments//element(*, dam:Asset) \n[\njcr:content/metadata/@xdpRef = '" + xdpRef + "'\n]";
            Iterator fragmentNodes = this.resourceResolver.findResources(query, "xpath");
            if (fragmentNodes.hasNext()) {
                Resource resource = (Resource)fragmentNodes.next();
                fragRef = resource.getPath();
                Resource fMmetaDataNode = resource.getChild("jcr:content").getChild("metadata");
                ValueMap valueMap = (ValueMap)fMmetaDataNode.adaptTo(ValueMap.class);
                String fragmentModelRootFromMetaData = (String)valueMap.get((Object)"fragmentModelRoot");
                if (StringUtils.contains((CharSequence)fragmentModelRootFromMetaData, (CharSequence)fragmentModelRootFromUsehref)) {
                    input.put("fragRef", fragRef);
                }
            }
            if (!input.containsKey("fragRef")) {
                input.put("usehref", xdpRef + "#" + fragmentModelRootFromUsehref);
            }
        }
        catch (Exception e) {
            this.logger.error("Error in handling usehref for fragment", (Throwable)e);
        }
    }

    public Hashtable<String, Object> getFieldProperties(Hashtable<String, Object> input, JSONObject fieldJson) throws Exception {
        if (fieldJson == null) {
            return null;
        }
        if (input == null) {
            input = new Hashtable();
        }
        input = this.getCommonProperties(input, fieldJson);
        String fieldUiType = (String)this.getOrElse(fieldJson, "ui.oneOfChild._class", "defaultUi", true);
        String fieldValueType = (String)this.getOrElse(fieldJson, "value.oneOfChild._class", null, true);
        if ("defaultUi".equals(fieldUiType) && fieldValueType != null) {
            fieldUiType = defaultFieldUiMap.get(fieldValueType);
        }
        if ("imageEdit".equals(fieldUiType)) {
            String scribbleName = (String)this.getOrElse(fieldJson, "ui.extras.name", null, true);
            if ("x-scribble-add-on".equals(scribbleName)) {
                fieldUiType = "scribble";
            }
        } else if ("dateTimeEdit".equals(fieldUiType) && ("time".equals(fieldValueType) || "dateTime".equals(fieldValueType))) {
            fieldUiType = "textEdit";
        }
        String[] guideUiType = null;
        if (fieldUiType != null) {
            guideUiType = fieldUiRTMap.get(fieldUiType);
        }
        if (guideUiType != null && guideUiType.length == 2) {
            String prop;
            input.put("sling:resourceType", guideUiType[0]);
            input.put("guideNodeClass", guideUiType[1]);
            this.putGuideProp(input, fieldJson, "mandatory", "validate.nullTest", "false", mandatoryConvertor);
            this.putGuideProp(input, fieldJson, "mandatoryMessage", "validate.message.text(name=nullTest)._value", null, null);
            this.putGuideProp(input, fieldJson, "_value", "value.oneOfChild._value", null, null);
            this.putGuideProp(input, fieldJson, "validateExpMessage", "validate.message.text(name=scriptTest)._value", null, null);
            this.putGuideProp(input, fieldJson, "validatePictureClauseMessage", "validate.message.text(name=formatTest)._value", null, null);
            this.putGuideProp(input, fieldJson, "assistPriority", "assist.speak.priority", null, assistPriorityConvertor);
            this.putGuideProp(input, fieldJson, "custom", "assist.speak._value", null, null);
            this.putGuideProp(input, fieldJson, "shortDescription", "assist.toolTip._value", null, null);
            if (!"time".equals(fieldValueType) && !"dateTime".equals(fieldValueType)) {
                prop = (String)this.getOrElse(fieldJson, "format.picture._value", null, true);
                if (prop != null && prop.length() > 0) {
                    input.put("displayPictureClause", prop);
                }
                if ((prop = (String)this.getOrElse(fieldJson, "validate.picture._value", null, true)) != null && prop.length() > 0) {
                    input.put("validatePictureClause", prop);
                }
            }
            if ("guideScribble".equals(guideUiType[1])) {
                input.put("aspectRatio", "" + XFAJSONTransformerUtil.calculateAspectRatio(fieldJson) + "");
            }
            if ("guideDatePicker".equals(guideUiType[1]) && (prop = (String)this.getOrElse(fieldJson, "ui.picture._value", null, true)) != null && prop.length() > 0) {
                input.put("editPictureClause", prop);
            }
            if ("guideCheckBox".equals(guideUiType[1])) {
                String[] option = new String[]{this.convertItemsToOptions(fieldJson)};
                input.put("options", option);
            } else if ("guideNumericBox".equals(guideUiType[1])) {
                input.put("dataType", fieldValueType);
                this.putGuideProp(input, fieldJson, "leadDigits", "value.oneOfChild.fracDigits", null, null);
                this.putGuideProp(input, fieldJson, "leadDigits", "value.oneOfChild.leadDigits", null, null);
            } else if ("guideTextBox".equals(guideUiType[1])) {
                Hashtable<String, String> multiLineConvertor = new Hashtable<String, String>();
                multiLineConvertor.put("1", "true");
                this.putGuideProp(input, fieldJson, "multiLine", "ui.textEdit.multiLine", null, multiLineConvertor);
                this.putGuideProp(input, fieldJson, "maxChars", "value.text.maxChars", null, null);
            } else if ("guideDropDownList".equals(guideUiType[1])) {
                this.putGuideProp(input, fieldJson, "multiSelect", "ui.choiceList.open", null, multiSelectConvertor);
                String[] options = this.getDropDownOptions(fieldJson);
                if (options.length > 0) {
                    input.put("options", options);
                }
            }
        } else {
            this.logger.warn("unrecognized type, treating it as text: " + fieldUiType + " : " + fieldUiType);
            input.put("sling:resourceType", "fd/af/components/guidetextbox");
            input.put("guideNodeClass", "guideTextBox");
        }
        return input;
    }

    public static double calculateAspectRatio(JSONObject fieldJson) throws Exception {
        double height = GuideUtils.convertToPx((String)fieldJson.get("h"));
        double ratio = height - 34.0 > 0.0 ? GuideUtils.convertToPx((String)fieldJson.get("w")) / height : GuideConstants.DEFAULT_ASPECT_RATIO;
        return ratio;
    }

    public Hashtable<String, Object> getExclGroupProperties(Hashtable<String, Object> input, JSONObject exclGroupJson) throws Exception {
        if (exclGroupJson == null) {
            return null;
        }
        if (input == null) {
            input = new Hashtable();
        }
        input = this.getCommonProperties(input, exclGroupJson);
        input.put("sling:resourceType", "fd/af/components/guideradiobutton");
        input.put("guideNodeClass", "guideRadioButton");
        if (exclGroupJson.has("children") && exclGroupJson.get("children") instanceof JSONArray) {
            JSONArray children = exclGroupJson.getJSONArray("children");
            ArrayList<String> options = new ArrayList<String>();
            String value = null;
            for (int i = 0; i < children.length(); ++i) {
                JSONObject child = children.getJSONObject(i);
                if (!"field".equals(child.getString("_class"))) continue;
                options.add(this.convertItemsToOptions(child));
                value = (String)this.getOrElse(child, "value.oneOfChild._value", value, true);
            }
            input.put("options", options.toArray(new String[options.size()]));
            if (value != null) {
                input.put("_value", value);
            }
            this.putGuideProp(input, exclGroupJson, "mandatory", "validate.nullTest", "false", mandatoryConvertor);
            this.putGuideProp(input, exclGroupJson, "mandatoryMessage", "validate.message.text(name=nullTest)._value", null, null);
        }
        return input;
    }

    public Hashtable<String, Object> getDrawProperties(Hashtable<String, Object> input, JSONObject drawJson) throws Exception {
        if (drawJson == null) {
            return null;
        }
        if (input == null) {
            input = new Hashtable();
        }
        input = this.getCommonProperties(input, drawJson);
        String drawUiType = (String)this.getOrElse(drawJson, "ui.oneOfChild._class", "defaultUi", true);
        String drawValueType = (String)this.getOrElse(drawJson, "value.oneOfChild._class", null, true);
        if ("defaultUi".equals(drawUiType) && drawValueType != null) {
            drawUiType = defaultFieldUiMap.get(drawValueType);
        }
        String[] guideUiType = null;
        if (drawUiType != null) {
            guideUiType = drawUiRTMap.get(drawUiType);
        }
        if (guideUiType != null && guideUiType.length == 2) {
            input.put("sling:resourceType", guideUiType[0]);
            input.put("guideNodeClass", guideUiType[1]);
            if ("guideTextDraw".equals(guideUiType[1])) {
                String textValue = (String)this.getOrElse(drawJson, "value." + drawValueType + "._value", "", true);
                input.put("_value", StringEscapeUtils.escapeHtml4((String)textValue));
                if ("text".equals(drawValueType)) {
                    input.put("textIsRich", false);
                } else if ("exData".equals(drawValueType)) {
                    input.put("textIsRich", true);
                }
            }
        } else {
            this.logger.warn("Unsupported draw type:" + drawUiType + ":" + drawValueType);
        }
        return input;
    }

    public String getTitle(JSONObject jsonObject) throws Exception {
        String title = null;
        if ("field".equals(jsonObject.getString("_class"))) {
            title = (String)this.getOrElse(jsonObject, "caption.value.text._value", null, true);
        }
        if (title == null && jsonObject.has("name")) {
            String nodeName = jsonObject.getString("name");
            title = GuideUtils.humanize(nodeName);
        }
        return title;
    }

    public String getOrGenerateName(JSONObject jsonObject) throws Exception {
        String name = (String)this.getOrElse(jsonObject, "name", null, true);
        if (name == null || "".equals(name)) {
            name = UNNAMED_PREFIX + this.unnamedCount++ + "_" + jsonObject.getString("_class");
        }
        return name;
    }

    private boolean putGuideProp(Hashtable<String, Object> input, JSONObject obj, String guideProp, String xfaProp, String def, Hashtable<String, String> convertor) throws Exception {
        String val = (String)this.getOrElse(obj, xfaProp, null, true);
        val = convertor == null ? val : (val == null ? val : convertor.get(val));
        String string = val = val == null ? def : val;
        if (val != null) {
            input.put(guideProp, val);
            return true;
        }
        return false;
    }

    static {
        String[] arr = new String[]{"fd/af/components/guidebutton", "guideButton"};
        fieldUiRTMap.put("button", arr);
        String[] arr1 = new String[]{"fd/af/components/guidecheckbox", "guideCheckBox"};
        fieldUiRTMap.put("checkButton", arr1);
        String[] arr2 = new String[]{"fd/af/components/guidedropdownlist", "guideDropDownList"};
        fieldUiRTMap.put("choiceList", arr2);
        String[] arr3 = new String[]{"fd/af/components/guidedatepicker", "guideDatePicker"};
        fieldUiRTMap.put("dateTimeEdit", arr3);
        String[] arr4 = new String[]{"fd/af/components/guidenumericbox", "guideNumericBox"};
        fieldUiRTMap.put("numericEdit", arr4);
        String[] arr5 = new String[]{"fd/af/components/guidepasswordbox", "guidePasswordBox"};
        fieldUiRTMap.put("passwordEdit", arr5);
        String[] arr6 = new String[]{"fd/af/components/guidetextbox", "guideTextBox"};
        fieldUiRTMap.put("textEdit", arr6);
        String[] arr7 = new String[]{"fd/af/components/guidescribble", "guideScribble"};
        fieldUiRTMap.put("scribble", arr7);
        String[] arr8 = new String[]{};
        fieldUiRTMap.put("defaultUi", arr8);
        fieldUiRTMap.put("exObject", arr8);
        fieldUiRTMap.put("imageEdit", arr8);
        fieldUiRTMap.put("signature", arr8);
        fieldUiRTMap.put("barcode", arr8);
        drawUiRTMap = new Hashtable();
        drawUiRTMap.put("textEdit", new String[]{"fd/af/components/guidetextdraw", "guideTextDraw"});
        drawUiRTMap.put("imageEdit", new String[]{"fd/af/components/guideimage", "guideImage"});
        defaultFieldUiMap = new Hashtable();
        defaultFieldUiMap.put("integer", "numericEdit");
        defaultFieldUiMap.put("boolean", "checkButton");
        defaultFieldUiMap.put("decimal", "numericEdit");
        defaultFieldUiMap.put("float", "numericEdit");
        defaultFieldUiMap.put("date", "dateTimeEdit");
        defaultFieldUiMap.put("dateTime", "dateTimeEdit");
        defaultFieldUiMap.put("time", "dateTimeEdit");
        defaultFieldUiMap.put("text", "textEdit");
        defaultFieldUiMap.put("exdata", "textEdit");
        defaultFieldUiMap.put("arc", "defaultUi");
        defaultFieldUiMap.put("line", "defaultUi");
        defaultFieldUiMap.put("rectangle", "defaultUi");
        defaultFieldUiMap.put("image", "imageEdit");
        oneOfChild = new Hashtable();
        oneOfChild.put("ui", Arrays.asList("barcode", "button", "checkButton", "choiceList", "dateTimeEdit", "defaultUi", "exObject", "imageEdit", "numericEdit", "passwordEdit", "signature", "textEdit"));
        oneOfChild.put("value", Arrays.asList("arc", "boolean", "date", "dateTime", "decimal", "exData", "float", "image", "integer", "line", "rectangle", "text", "time"));
        mandatoryConvertor = new Hashtable();
        mandatoryConvertor.put("disabled", "false");
        mandatoryConvertor.put("error", "true");
        mandatoryConvertor.put("warning", "false");
        assistPriorityConvertor = new Hashtable();
        assistPriorityConvertor.put("custom", "custom");
        assistPriorityConvertor.put("toolTip", "shortDescription");
        assistPriorityConvertor.put("caption", "label");
        assistPriorityConvertor.put("name", "name");
        multiSelectConvertor = new Hashtable();
        multiSelectConvertor.put("multiSelect", "true");
        UNNAMED_PREFIX = "_unnamed";
    }
}