package com.tencent.mm.c;

import com.tencent.matrix.trace.core.AppMethodBeat;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public final class f {
    private static boolean cdt = false;

    /* JADX WARNING: Removed duplicated region for block: B:25:0x0085 A:{Splitter:B:19:0x0062, ExcHandler: SAXException (e org.xml.sax.SAXException)} */
    /* JADX WARNING: Removed duplicated region for block: B:27:0x008a A:{Splitter:B:19:0x0062, ExcHandler: IOException (e java.io.IOException)} */
    /* JADX WARNING: Removed duplicated region for block: B:29:0x008f A:{Splitter:B:19:0x0062, ExcHandler: Exception (e java.lang.Exception)} */
    /* JADX WARNING: Failed to process nested try/catch */
    /* JADX WARNING: Missing block: B:26:0x0086, code skipped:
            com.tencent.matrix.trace.core.AppMethodBeat.o(125707);
     */
    /* JADX WARNING: Missing block: B:28:0x008b, code skipped:
            com.tencent.matrix.trace.core.AppMethodBeat.o(125707);
     */
    /* JADX WARNING: Missing block: B:30:0x0090, code skipped:
            com.tencent.matrix.trace.core.AppMethodBeat.o(125707);
     */
    /* JADX WARNING: Missing block: B:49:0x00fc, code skipped:
            r2 = null;
     */
    /* JADX WARNING: Missing block: B:56:?, code skipped:
            return null;
     */
    /* JADX WARNING: Missing block: B:57:?, code skipped:
            return null;
     */
    /* JADX WARNING: Missing block: B:58:?, code skipped:
            return null;
     */
    public static java.util.Map<java.lang.String, java.lang.String> z(java.lang.String r8, java.lang.String r9) {
        /*
        r7 = 0;
        r0 = 0;
        r6 = 125707; // 0x1eb0b float:1.76153E-40 double:6.21075E-319;
        com.tencent.matrix.trace.core.AppMethodBeat.i(r6);
        if (r8 != 0) goto L_0x0019;
    L_0x000a:
        r1 = -1;
    L_0x000b:
        if (r1 >= 0) goto L_0x0020;
    L_0x000d:
        r1 = java.lang.System.err;
        r2 = "text not in xml format";
        r1.println(r2);
        com.tencent.matrix.trace.core.AppMethodBeat.o(r6);
    L_0x0018:
        return r0;
    L_0x0019:
        r1 = 60;
        r1 = r8.indexOf(r1);
        goto L_0x000b;
    L_0x0020:
        if (r1 <= 0) goto L_0x0036;
    L_0x0022:
        r2 = java.lang.System.err;
        r3 = "fix xml header from ";
        r4 = java.lang.String.valueOf(r1);
        r3 = r3.concat(r4);
        r2.println(r3);
        r8 = r8.substring(r1);
    L_0x0036:
        if (r8 == 0) goto L_0x003e;
    L_0x0038:
        r1 = r8.length();
        if (r1 > 0) goto L_0x0042;
    L_0x003e:
        com.tencent.matrix.trace.core.AppMethodBeat.o(r6);
        goto L_0x0018;
    L_0x0042:
        r1 = new java.util.HashMap;
        r1.<init>();
        r2 = javax.xml.parsers.DocumentBuilderFactory.newInstance();
        r2 = r2.newDocumentBuilder();	 Catch:{ ParserConfigurationException -> 0x005d }
        if (r2 != 0) goto L_0x0062;
    L_0x0051:
        r1 = java.lang.System.err;
        r2 = "new Document Builder failed";
        r1.println(r2);
        com.tencent.matrix.trace.core.AppMethodBeat.o(r6);
        goto L_0x0018;
    L_0x005d:
        r1 = move-exception;
        com.tencent.matrix.trace.core.AppMethodBeat.o(r6);
        goto L_0x0018;
    L_0x0062:
        r3 = new org.xml.sax.InputSource;	 Catch:{ DOMException -> 0x00fb, SAXException -> 0x0085, IOException -> 0x008a, Exception -> 0x008f }
        r4 = new java.io.ByteArrayInputStream;	 Catch:{ DOMException -> 0x00fb, SAXException -> 0x0085, IOException -> 0x008a, Exception -> 0x008f }
        r5 = r8.getBytes();	 Catch:{ DOMException -> 0x00fb, SAXException -> 0x0085, IOException -> 0x008a, Exception -> 0x008f }
        r4.<init>(r5);	 Catch:{ DOMException -> 0x00fb, SAXException -> 0x0085, IOException -> 0x008a, Exception -> 0x008f }
        r3.<init>(r4);	 Catch:{ DOMException -> 0x00fb, SAXException -> 0x0085, IOException -> 0x008a, Exception -> 0x008f }
        r2 = r2.parse(r3);	 Catch:{ DOMException -> 0x00fb, SAXException -> 0x0085, IOException -> 0x008a, Exception -> 0x008f }
        r2.normalize();	 Catch:{ DOMException -> 0x00ff, SAXException -> 0x0085, IOException -> 0x008a, Exception -> 0x008f }
    L_0x0077:
        if (r2 != 0) goto L_0x0094;
    L_0x0079:
        r1 = java.lang.System.err;
        r2 = "new Document failed";
        r1.println(r2);
        com.tencent.matrix.trace.core.AppMethodBeat.o(r6);
        goto L_0x0018;
    L_0x0085:
        r1 = move-exception;
        com.tencent.matrix.trace.core.AppMethodBeat.o(r6);
        goto L_0x0018;
    L_0x008a:
        r1 = move-exception;
        com.tencent.matrix.trace.core.AppMethodBeat.o(r6);
        goto L_0x0018;
    L_0x008f:
        r1 = move-exception;
        com.tencent.matrix.trace.core.AppMethodBeat.o(r6);
        goto L_0x0018;
    L_0x0094:
        r2 = r2.getDocumentElement();
        if (r2 != 0) goto L_0x00a7;
    L_0x009a:
        r1 = java.lang.System.err;
        r2 = "getDocumentElement failed";
        r1.println(r2);
        com.tencent.matrix.trace.core.AppMethodBeat.o(r6);
        goto L_0x0018;
    L_0x00a7:
        r3 = r2.getNodeName();
        r3 = r9.equals(r3);
        if (r3 == 0) goto L_0x00c7;
    L_0x00b1:
        r0 = "";
        r3 = "";
        a(r1, r0, r3, r2, r7);
    L_0x00ba:
        r0 = cdt;
        if (r0 == 0) goto L_0x00c1;
    L_0x00be:
        e(r1);
    L_0x00c1:
        com.tencent.matrix.trace.core.AppMethodBeat.o(r6);
        r0 = r1;
        goto L_0x0018;
    L_0x00c7:
        r2 = r2.getElementsByTagName(r9);
        r3 = r2.getLength();
        if (r3 > 0) goto L_0x00de;
    L_0x00d1:
        r1 = java.lang.System.err;
        r2 = "parse item null";
        r1.println(r2);
        com.tencent.matrix.trace.core.AppMethodBeat.o(r6);
        goto L_0x0018;
    L_0x00de:
        r0 = r2.getLength();
        r3 = 1;
        if (r0 <= r3) goto L_0x00ed;
    L_0x00e5:
        r0 = java.lang.System.err;
        r3 = "parse items more than one";
        r0.println(r3);
    L_0x00ed:
        r0 = "";
        r3 = "";
        r2 = r2.item(r7);
        a(r1, r0, r3, r2, r7);
        goto L_0x00ba;
    L_0x00fb:
        r2 = move-exception;
        r2 = r0;
        goto L_0x0077;
    L_0x00ff:
        r3 = move-exception;
        goto L_0x0077;
        */
        throw new UnsupportedOperationException("Method not decompiled: com.tencent.mm.c.f.z(java.lang.String, java.lang.String):java.util.Map");
    }

    private static void a(Map<String, String> map, String str, String str2, Node node, int i) {
        AppMethodBeat.i(125708);
        if (node.getNodeName().equals("#text")) {
            map.put(str, node.getNodeValue());
            map.put(str2, node.getNodeValue());
            AppMethodBeat.o(125708);
        } else if (node.getNodeName().equals("#cdata-section")) {
            map.put(str, node.getNodeValue());
            map.put(str2, node.getNodeValue());
            AppMethodBeat.o(125708);
        } else {
            Object obj;
            int i2;
            Object stringBuilder = new StringBuilder(String.valueOf(str)).append(".").append(node.getNodeName()).toString();
            String stringBuilder2 = new StringBuilder(String.valueOf(str2)).append(".").append(node.getNodeName()).toString();
            if (i > 0) {
                stringBuilder = new StringBuilder(String.valueOf(stringBuilder)).append(i).toString();
                map.put(stringBuilder, node.getNodeValue());
                stringBuilder2 = new StringBuilder(String.valueOf(stringBuilder2)).append("#").append(i).toString();
                map.put(stringBuilder2, node.getNodeValue());
                obj = stringBuilder2;
            } else {
                map.put(stringBuilder, node.getNodeValue());
                map.put(stringBuilder2, node.getNodeValue());
                String obj2 = stringBuilder2;
            }
            NamedNodeMap attributes = node.getAttributes();
            if (attributes != null) {
                for (i2 = 0; i2 < attributes.getLength(); i2++) {
                    Node item = attributes.item(i2);
                    map.put(new StringBuilder(String.valueOf(stringBuilder)).append(".$").append(item.getNodeName()).toString(), item.getNodeValue());
                    map.put(new StringBuilder(String.valueOf(obj2)).append(".$").append(item.getNodeName()).toString(), item.getNodeValue());
                }
            }
            HashMap hashMap = new HashMap();
            NodeList childNodes = node.getChildNodes();
            for (int i3 = 0; i3 < childNodes.getLength(); i3++) {
                Node item2 = childNodes.item(i3);
                Integer num = (Integer) hashMap.get(item2.getNodeName());
                if (num == null) {
                    i2 = 0;
                } else {
                    i2 = num.intValue();
                }
                a(map, stringBuilder, obj2, item2, i2);
                hashMap.put(item2.getNodeName(), Integer.valueOf(i2 + 1));
            }
            AppMethodBeat.o(125708);
        }
    }

    private static void e(Map<String, String> map) {
        AppMethodBeat.i(125709);
        if (map.size() <= 0) {
            System.err.println("empty values");
            AppMethodBeat.o(125709);
            return;
        }
        for (Entry entry : map.entrySet()) {
            System.err.println("key=" + ((String) entry.getKey()) + " value=" + ((String) entry.getValue()));
        }
        AppMethodBeat.o(125709);
    }
}
