package epson.epsonconnectregistration;

import android.util.Xml;
import com.epson.mobilephone.common.EpLog;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;

public abstract class SoapConfigDataParser {
    private static final String ELEMENT_D = "d";
    private static final String ELEMENT_DATA = "Data";
    private static final String ELEMENT_GROUP = "Group";
    private static final String ELEMENT_ID = "id";
    private static final String ELEMENT_RETURN = "return";
    private static final String NAMESPACE = "ijcp";
    private static final String SCHEMA = "http://schemas.epson.net/ws/2008/07/config-data";
    private static final String TAG = "SoapConfigDataParser";
    private String groupId;
    private boolean ret = false;
    private HashMap<String, String> valueMap;

    public SoapConfigDataParser(String str) {
        groupId = str;
        valueMap = new HashMap<>();
    }

    public String getGroupId() {
        return groupId;
    }

    public void parseXml(InputStream inputStream) throws XmlPullParserException, IOException {
        XmlPullParserFactory newInstance = XmlPullParserFactory.newInstance();
        newInstance.setNamespaceAware(true);
        XmlPullParser newPullParser = newInstance.newPullParser();
        inputStream.reset();
        ret = false;
        valueMap.clear();
        newPullParser.setInput(inputStream, Xml.Encoding.UTF_8.name());
        String str = null;
        boolean z = false;
        for (int eventType = newPullParser.getEventType(); eventType != 1; eventType = newPullParser.next()) {
            if (eventType == 0) {
                EpLog.m70d(TAG, "Start document");
            } else if (eventType == 2) {
                String name = newPullParser.getName();
                EpLog.m70d(TAG, "Start tag " + newPullParser.getName() + " prefix = " + newPullParser.getNamespacePrefix(newPullParser.getDepth()));
                if (!ELEMENT_DATA.equals(name)) {
                    if (ELEMENT_GROUP.equals(name)) {
                        String attributeValue = newPullParser.getAttributeValue((String) null, "id");
                        if (attributeValue.equals("ijcp:" + groupId)) {
                            ret = "true".equalsIgnoreCase(newPullParser.getAttributeValue((String) null, ELEMENT_RETURN));
                            z = true;
                        } else {
                            EpLog.m70d(TAG, "Unexpected group" + attributeValue);
                        }
                    } else if (ELEMENT_D.equals(name)) {
                        str = newPullParser.getAttributeValue((String) null, "id");
                    } else {
                        EpLog.m83w(TAG, "Unknown tag " + newPullParser.getName());
                    }
                }
            } else if (eventType == 3) {
                String name2 = newPullParser.getName();
                EpLog.m70d(TAG, "End tag " + name2);
                if (ELEMENT_GROUP.equals(name2)) {
                    z = false;
                }
                str = null;
            } else if (eventType == 4) {
                String text = newPullParser.getText();
                if (!(!z || str == null || text == null)) {
                    valueMap.put(str, text);
                    EpLog.m70d(TAG, "Data = " + str + " : " + text);
                }
            }
        }
        EpLog.m70d(TAG, "End document");
    }

    public String getValue(String str) {
        HashMap<String, String> hashMap = valueMap;
        return hashMap.get("ijcp:" + str);
    }

    public boolean getRetVal() {
        return ret;
    }
}
