package j5; import ai.clova.cic.clientlib.exoplayer2.extractor.ts.PsExtractor; import i5.b; import java.io.IOException; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import kotlin.UByte; import l5.d; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.w3c.dom.ProcessingInstruction; import org.xml.sax.InputSource; import org.xml.sax.SAXException; public class m { /* renamed from: a reason: collision with root package name */ public static final Object f90523a = new Object(); /* renamed from: b reason: collision with root package name */ public static DocumentBuilderFactory f90524b; static { DocumentBuilderFactory newInstance = DocumentBuilderFactory.newInstance(); newInstance.setNamespaceAware(true); newInstance.setIgnoringComments(true); try { newInstance.setFeature("http://javax.xml.XMLConstants/feature/secure-processing", true); newInstance.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); newInstance.setFeature("http://xml.org/sax/features/external-general-entities", false); newInstance.setFeature("http://xerces.apache.org/xerces2-j/features.html#disallow-doctype-decl", false); newInstance.setFeature("http://xml.org/sax/features/external-parameter-entities", false); newInstance.setFeature("http://xerces.apache.org/xerces2-j/features.html#external-parameter-entities", false); newInstance.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); newInstance.setXIncludeAware(false); newInstance.setExpandEntityReferences(false); } catch (Exception unused) { } f90524b = newInstance; } public static Object[] a(Node node, boolean z14, Object[] objArr) { NodeList childNodes = node.getChildNodes(); for (int i14 = 0; i14 < childNodes.getLength(); i14++) { Node item = childNodes.item(i14); if (7 == item.getNodeType()) { ProcessingInstruction processingInstruction = (ProcessingInstruction) item; if ("xpacket".equals(processingInstruction.getTarget())) { if (objArr != null) { objArr[2] = processingInstruction.getData(); } } } if (!(3 == item.getNodeType() || 7 == item.getNodeType())) { String namespaceURI = item.getNamespaceURI(); String localName = item.getLocalName(); if (("xmpmeta".equals(localName) || "xapmeta".equals(localName)) && "adobe:ns:meta/".equals(namespaceURI)) { return a(item, false, objArr); } if (z14 || !"RDF".equals(localName) || !"http://www.w3.org/1999/02/22-rdf-syntax-ns#".equals(namespaceURI)) { Object[] a14 = a(item, z14, objArr); if (a14 != null) { return a14; } } else { if (objArr != null) { objArr[0] = item; objArr[1] = f90523a; } return objArr; } } } return null; } public static Document b(InputSource inputSource) throws b { try { DocumentBuilder newDocumentBuilder = f90524b.newDocumentBuilder(); newDocumentBuilder.setErrorHandler(null); return newDocumentBuilder.parse(inputSource); } catch (SAXException e14) { throw new b("XML parsing failure", 201, e14); } catch (ParserConfigurationException e15) { throw new b("XML Parser not correctly configured", 0, e15); } catch (IOException e16) { throw new b("Error reading the XML-file", 204, e16); } } public static Document c(a aVar, d dVar) throws b { InputSource inputSource = new InputSource(aVar.c()); try { if (dVar.c(64)) { try { f90524b.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); } catch (Throwable unused) { } } return b(inputSource); } catch (b e14) { int i14 = e14.f85122b; if (i14 == 201 || i14 == 204) { if (dVar.c(16) && "UTF-8".equals(aVar.d())) { byte[] bArr = new byte[8]; a aVar2 = new a((aVar.f90482b * 4) / 3); int i15 = 0; boolean z14 = false; int i16 = 0; int i17 = 0; while (true) { int i18 = aVar.f90482b; if (i15 >= i18) { if (z14) { for (int i19 = 0; i19 < i16; i19++) { aVar2.a(z1.d.a(bArr[i19])); } } aVar = aVar2; } else if (i15 < i18) { int i24 = aVar.f90481a[i15] & UByte.MAX_VALUE; if (z14) { if (i17 <= 0 || (i24 & PsExtractor.AUDIO_STREAM) != 128) { aVar2.a(z1.d.a(bArr[0])); i15 -= i16; } else { int i25 = i16 + 1; bArr[i16] = (byte) i24; i17--; if (i17 == 0) { aVar2.b(aVar2.f90482b + i25); System.arraycopy(bArr, 0, aVar2.f90481a, aVar2.f90482b, i25); aVar2.f90482b += i25; } else { i16 = i25; } } z14 = false; i16 = 0; } else if (i24 < 127) { aVar2.b(aVar2.f90482b + 1); byte[] bArr2 = aVar2.f90481a; int i26 = aVar2.f90482b; aVar2.f90482b = i26 + 1; bArr2[i26] = (byte) i24; } else if (i24 >= 192) { i17 = -1; int i27 = i24; while (i17 < 8 && (i27 & 128) == 128) { i17++; i27 <<= 1; } bArr[i16] = (byte) i24; i16++; z14 = true; } else { aVar2.a(z1.d.a((byte) i24)); } i15++; } else { throw new IndexOutOfBoundsException("The index exceeds the valid buffer area"); } } } if (!dVar.f()) { return b(new InputSource(aVar.c())); } try { return b(new InputSource(new b(new InputStreamReader(aVar.c(), aVar.d())))); } catch (UnsupportedEncodingException unused2) { throw new b("Unsupported Encoding", 9, e14); } } else { throw e14; } } } }