package o; import com.adobe.internal.xmp.XMPException; import org.bouncycastle.asn1.cmp.PKIFailureInfo; /* loaded from: classes.dex */ public final class BjG { public static AVp c(String str, String str2) throws XMPException { mrG e; if (str == null || str2 == null) { throw new XMPException("Parameter must not be null", 4); } AVp aVp = new AVp(); msu msuVar = new msu(); msuVar.a = str2; e(str, msuVar, aVp); while (msuVar.e < str2.length()) { msuVar.b = msuVar.e; e(str2, msuVar); msuVar.e = msuVar.b; if (str2.charAt(msuVar.b) != '[') { e = a(msuVar); } else { e = e(msuVar); } if (e.e == 1) { if (e.b.charAt(0) == '@') { StringBuilder sb = new StringBuilder("?"); sb.append(e.b.substring(1)); e.b = sb.toString(); if (!"?xml:lang".equals(e.b)) { throw new XMPException("Only xml:lang allowed with '@'", 102); } } if (e.b.charAt(0) == '?') { msuVar.d++; e.e = 2; } e(msuVar.a.substring(msuVar.d, msuVar.c)); } else if (e.e != 6) { continue; } else { if (e.b.charAt(1) == '@') { StringBuilder sb2 = new StringBuilder("[?"); sb2.append(e.b.substring(2)); e.b = sb2.toString(); if (!e.b.startsWith("[?xml:lang=")) { throw new XMPException("Only xml:lang allowed with '@'", 102); } } if (e.b.charAt(1) == '?') { msuVar.d++; e.e = 5; e(msuVar.a.substring(msuVar.d, msuVar.c)); } } aVp.c.add(e); } return aVp; } private static void e(String str, msu msuVar) throws XMPException { if (str.charAt(msuVar.b) == '/') { msuVar.b++; if (msuVar.b >= str.length()) { throw new XMPException("Empty XMPPath segment", 102); } } if (str.charAt(msuVar.b) == '*') { msuVar.b++; if (msuVar.b >= str.length() || str.charAt(msuVar.b) != '[') { throw new XMPException("Missing '[' after '*'", 102); } } } private static mrG a(msu msuVar) throws XMPException { msuVar.d = msuVar.b; while (msuVar.e < msuVar.a.length() && "/[*".indexOf(msuVar.a.charAt(msuVar.e)) < 0) { msuVar.e++; } msuVar.c = msuVar.e; if (msuVar.e == msuVar.b) { throw new XMPException("Empty XMPPath segment", 102); } return new mrG(msuVar.a.substring(msuVar.b, msuVar.e), 1); } private static mrG e(msu msuVar) throws XMPException { mrG mrg; msuVar.e++; if ('0' <= msuVar.a.charAt(msuVar.e) && msuVar.a.charAt(msuVar.e) <= '9') { while (msuVar.e < msuVar.a.length() && '0' <= msuVar.a.charAt(msuVar.e) && msuVar.a.charAt(msuVar.e) <= '9') { msuVar.e++; } mrg = new mrG(null, 3); } else { while (msuVar.e < msuVar.a.length() && msuVar.a.charAt(msuVar.e) != ']' && msuVar.a.charAt(msuVar.e) != '=') { msuVar.e++; } if (msuVar.e >= msuVar.a.length()) { throw new XMPException("Missing ']' or '=' for array index", 102); } if (msuVar.a.charAt(msuVar.e) == ']') { if (!"[last()".equals(msuVar.a.substring(msuVar.b, msuVar.e))) { throw new XMPException("Invalid non-numeric array index", 102); } mrg = new mrG(null, 4); } else { msuVar.d = msuVar.b + 1; msuVar.c = msuVar.e; msuVar.e++; char charAt = msuVar.a.charAt(msuVar.e); if (charAt != '\'' && charAt != '\"') { throw new XMPException("Invalid quote in array selector", 102); } msuVar.e++; while (msuVar.e < msuVar.a.length()) { if (msuVar.a.charAt(msuVar.e) == charAt) { if (msuVar.e + 1 >= msuVar.a.length() || msuVar.a.charAt(msuVar.e + 1) != charAt) { break; } msuVar.e++; } msuVar.e++; } if (msuVar.e >= msuVar.a.length()) { throw new XMPException("No terminating quote for array selector", 102); } msuVar.e++; mrg = new mrG(null, 6); } } if (msuVar.e >= msuVar.a.length() || msuVar.a.charAt(msuVar.e) != ']') { throw new XMPException("Missing ']' for array index", 102); } msuVar.e++; mrg.b = msuVar.a.substring(msuVar.b, msuVar.e); return mrg; } private static void e(String str, msu msuVar, AVp aVp) throws XMPException { while (msuVar.e < msuVar.a.length() && "/[*".indexOf(msuVar.a.charAt(msuVar.e)) < 0) { msuVar.e++; } if (msuVar.e == msuVar.b) { throw new XMPException("Empty initial XMPPath step", 102); } String d = d(str, msuVar.a.substring(msuVar.b, msuVar.e)); RTk e = C1235Yps.c().e(d); if (e == null) { aVp.c.add(new mrG(str, PKIFailureInfo.systemUnavail)); aVp.c.add(new mrG(d, 1)); return; } aVp.c.add(new mrG(e.e(), PKIFailureInfo.systemUnavail)); mrG mrg = new mrG(d(e.e(), e.d()), 1); mrg.c = true; mrg.a = e.c().a; aVp.c.add(mrg); if ((e.c().a & 4096) != 0) { mrG mrg2 = new mrG("[?xml:lang='x-default']", 5); mrg2.c = true; mrg2.a = e.c().a; aVp.c.add(mrg2); return; } if ((e.c().a & 512) != 0) { mrG mrg3 = new mrG("[1]", 3); mrg3.c = true; mrg3.a = e.c().a; aVp.c.add(mrg3); } } private static void e(String str) throws XMPException { int indexOf = str.indexOf(58); if (indexOf > 0) { String substring = str.substring(0, indexOf); if (C15974jzn.e(substring)) { if (C1235Yps.c().a(substring) == null) { throw new XMPException("Unknown namespace prefix for qualified name", 102); } return; } } throw new XMPException("Ill-formed qualified name", 102); } private static String d(String str, String str2) throws XMPException { if (str == null || str.length() == 0) { throw new XMPException("Schema namespace URI is required", 101); } if (str2.charAt(0) == '?' || str2.charAt(0) == '@') { throw new XMPException("Top level name must not be a qualifier", 102); } if (str2.indexOf(47) >= 0 || str2.indexOf(91) >= 0) { throw new XMPException("Top level name must be simple", 102); } String c = C1235Yps.c().c(str); if (c == null) { throw new XMPException("Unregistered schema namespace URI", 101); } int indexOf = str2.indexOf(58); if (indexOf < 0) { if (C15974jzn.b(str2)) { StringBuilder sb = new StringBuilder(); sb.append(c); sb.append(str2); return sb.toString(); } throw new XMPException("Bad XML name", 102); } if (!C15974jzn.b(str2.substring(0, indexOf))) { throw new XMPException("Bad XML name", 102); } if (C15974jzn.b(str2.substring(indexOf))) { String substring = str2.substring(0, indexOf + 1); String c2 = C1235Yps.c().c(str); if (c2 == null) { throw new XMPException("Unknown schema namespace prefix", 101); } if (substring.equals(c2)) { return str2; } throw new XMPException("Schema namespace URI and prefix mismatch", 101); } throw new XMPException("Bad XML name", 102); } }