/*
 * SDK Pullenti Unitext, version 4.33, fabruary 2026. Copyright (c) 2013-2026, Pullenti. All rights reserved. 
 * Non-Commercial Freeware and Commercial Software. 
 * This class is generated using the converter Unisharping (www.unisharping.ru) from Pullenti C# project. 
 * The latest version of the code is available on the site www.pullenti.ru
 */

package com.pullenti.unitext.internal.word;

public class DocNumStyles {

    private java.util.HashMap<String, com.pullenti.unitext.internal.uni.UnitextGenNumStyleEx> m_NumStyles = new java.util.HashMap<String, com.pullenti.unitext.internal.uni.UnitextGenNumStyleEx>();

    public com.pullenti.unitext.internal.uni.UnitextGenNumStyleEx getStyle(String id) {
        if (id == null) 
            return null;
        if (m_NumStyles.containsKey(id)) 
            return m_NumStyles.get(id);
        return null;
    }

    private static String _readAttrVal(org.w3c.dom.Node x, String nam, String nam2) {
        if (x.getAttributes() != null) {
            for (org.w3c.dom.Node a : (new com.pullenti.unisharp.XmlAttrListWrapper(x.getAttributes())).arr) {
                if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), nam)) 
                    return a.getNodeValue();
                else if (nam2 != null && com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), nam2)) 
                    return a.getNodeValue();
            }
        }
        if (com.pullenti.unisharp.Utils.stringsEq(nam, "val")) {
            if (x.getAttributes() != null) {
                for (org.w3c.dom.Node a : (new com.pullenti.unisharp.XmlAttrListWrapper(x.getAttributes())).arr) {
                    return a.getNodeValue();
                }
            }
        }
        return null;
    }

    private void _readNumLvl(com.pullenti.unitext.internal.uni.UniTextGenNumLevel nlev, org.w3c.dom.Node xx) {
        for (org.w3c.dom.Node xxx : (new com.pullenti.unisharp.XmlNodeListWrapper(xx.getChildNodes())).arr) {
            if (xxx.getAttributes() != null) {
                if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(xxx), "numFmt")) 
                    nlev.type = getNumTyp(_readAttrVal(xxx, "val", null));
                else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(xxx), "lvlText")) {
                    nlev.format = _readAttrVal(xxx, "val", null);
                    StringBuilder tmp = new StringBuilder();
                    int max = 0;
                    for (int i = 0; i < nlev.format.length(); i++) {
                        char ch = nlev.format.charAt(i);
                        if (ch != '%' || (i + 1) >= nlev.format.length()) {
                            tmp.append(ch);
                            continue;
                        }
                        i++;
                        int n = (((int)nlev.format.charAt(i)) - ((int)'0'));
                        if (n <= max || n > 9) 
                            continue;
                        max = n;
                        tmp.append("%").append(n);
                    }
                    nlev.format = tmp.toString();
                }
                else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(xxx), "start")) {
                    int ii;
                    com.pullenti.unisharp.Outargwrapper<Integer> wrapii435 = new com.pullenti.unisharp.Outargwrapper<Integer>();
                    boolean inoutres436 = com.pullenti.unisharp.Utils.parseInteger((String)com.pullenti.unisharp.Utils.notnull(_readAttrVal(xxx, "val", null), ""), 0, null, wrapii435);
                    ii = (wrapii435.value != null ? wrapii435.value : 0);
                    if (inoutres436) 
                        nlev.start = ii;
                }
            }
            if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(xxx), "pPr")) {
                if (nlev.style == null) 
                    nlev.style = new com.pullenti.unitext.UnitextStyle();
                DocTextStyles.readUnitextStyleExt(xxx, nlev.style, true, false);
            }
        }
    }

    public void readAllStyles(org.w3c.dom.Node node) {
        java.util.HashMap<String, com.pullenti.unitext.internal.uni.UnitextGenNumStyle> abstr = new java.util.HashMap<String, com.pullenti.unitext.internal.uni.UnitextGenNumStyle>();
        for (org.w3c.dom.Node xnum : (new com.pullenti.unisharp.XmlNodeListWrapper(node.getChildNodes())).arr) {
            if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(xnum), "abstractNum") && xnum.getAttributes() != null && xnum.getAttributes().getLength() >= 1) {
                String id = _readAttrVal(xnum, "abstractNumId", null);
                if (id == null || abstr.containsKey(id)) 
                    continue;
                if (com.pullenti.unisharp.Utils.stringsEq(id, "14")) {
                }
                com.pullenti.unitext.internal.uni.UnitextGenNumStyle nsty = com.pullenti.unitext.internal.uni.UnitextGenNumStyle._new110(id);
                abstr.put(id, nsty);
                for (org.w3c.dom.Node xx : (new com.pullenti.unisharp.XmlNodeListWrapper(xnum.getChildNodes())).arr) {
                    if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(xx), "lvl")) {
                        com.pullenti.unitext.internal.uni.UniTextGenNumLevel nlev = new com.pullenti.unitext.internal.uni.UniTextGenNumLevel();
                        nsty.levels.add(nlev);
                        this._readNumLvl(nlev, xx);
                    }
                    else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(xx), "numStyleLink")) {
                        String lid = _readAttrVal(xx, "val", null);
                        if (lid != null && abstr.containsKey(lid)) 
                            com.pullenti.unisharp.Utils.addToArrayList(nsty.levels, abstr.get(lid).levels);
                    }
                }
            }
            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(xnum), "num")) {
                String id = _readAttrVal(xnum, "numId", null);
                String intId = null;
                for (org.w3c.dom.Node xx : (new com.pullenti.unisharp.XmlNodeListWrapper(xnum.getChildNodes())).arr) {
                    if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(xx), "abstractNumId")) 
                        intId = _readAttrVal(xx, "val", null);
                }
                if (intId == null || id == null) 
                    continue;
                com.pullenti.unitext.internal.uni.UnitextGenNumStyle num0;
                com.pullenti.unisharp.Outargwrapper<com.pullenti.unitext.internal.uni.UnitextGenNumStyle> wrapnum0443 = new com.pullenti.unisharp.Outargwrapper<com.pullenti.unitext.internal.uni.UnitextGenNumStyle>();
                boolean inoutres444 = com.pullenti.unisharp.Utils.tryGetValue(abstr, intId, wrapnum0443);
                num0 = wrapnum0443.value;
                if (!inoutres444) 
                    continue;
                com.pullenti.unitext.internal.uni.UnitextGenNumStyleEx num = com.pullenti.unitext.internal.uni.UnitextGenNumStyleEx._new438(num0.clone());
                num.setId(id);
                if (!m_NumStyles.containsKey(id)) 
                    m_NumStyles.put(id, num);
                for (org.w3c.dom.Node xx : (new com.pullenti.unisharp.XmlNodeListWrapper(xnum.getChildNodes())).arr) {
                    if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(xx), "lvlOverride")) {
                        int l;
                        com.pullenti.unisharp.Outargwrapper<Integer> wrapl441 = new com.pullenti.unisharp.Outargwrapper<Integer>();
                        boolean inoutres442 = com.pullenti.unisharp.Utils.parseInteger((String)com.pullenti.unisharp.Utils.notnull(_readAttrVal(xx, "val", null), ""), 0, null, wrapl441);
                        l = (wrapl441.value != null ? wrapl441.value : 0);
                        if (!inoutres442) 
                            continue;
                        if ((l < 0) || l >= num.src.levels.size()) 
                            continue;
                        for (org.w3c.dom.Node xxx : (new com.pullenti.unisharp.XmlNodeListWrapper(xx.getChildNodes())).arr) {
                            if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(xxx), "startOverride")) {
                                int s;
                                com.pullenti.unisharp.Outargwrapper<Integer> wraps439 = new com.pullenti.unisharp.Outargwrapper<Integer>();
                                boolean inoutres440 = com.pullenti.unisharp.Utils.parseInteger((String)com.pullenti.unisharp.Utils.notnull(_readAttrVal(xxx, "val", null), ""), 0, null, wraps439);
                                s = (wraps439.value != null ? wraps439.value : 0);
                                if (inoutres440) {
                                    if (!num.overrideStarts.containsKey(l)) 
                                        num.overrideStarts.put(l, s);
                                }
                            }
                            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(xxx), "lvl")) 
                                this._readNumLvl(num.src.levels.get(l), xxx);
                        }
                    }
                }
            }
        }
    }

    public static com.pullenti.unitext.internal.uni.UnitextGenNumStyle readNumberStyle(org.w3c.dom.Node xml) {
        com.pullenti.unitext.internal.uni.UnitextGenNumStyle res = null;
        for (org.w3c.dom.Node x : (new com.pullenti.unisharp.XmlNodeListWrapper(xml.getChildNodes())).arr) {
            if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "ilvl")) {
                res = new com.pullenti.unitext.internal.uni.UnitextGenNumStyle();
                int nn;
                com.pullenti.unisharp.Outargwrapper<Integer> wrapnn445 = new com.pullenti.unisharp.Outargwrapper<Integer>();
                boolean inoutres446 = com.pullenti.unisharp.Utils.parseInteger((String)com.pullenti.unisharp.Utils.notnull(_readAttrVal(x, "val", null), ""), 0, null, wrapnn445);
                nn = (wrapnn445.value != null ? wrapnn445.value : 0);
                if (inoutres446) 
                    res.setLvl(nn);
            }
            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "ilfo")) {
                String vv = _readAttrVal(x, "val", null);
                if (com.pullenti.unisharp.Utils.stringsEq(vv, "2")) 
                    res.setBullet(true);
            }
            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "t") && res != null) 
                res.setTxt(_readAttrVal(x, "val", null));
        }
        return res;
    }

    public static com.pullenti.unitext.internal.uni.UniTextGenNumType getNumTyp(String ty) {
        if (com.pullenti.unisharp.Utils.stringsEq(ty, "bullet")) 
            return com.pullenti.unitext.internal.uni.UniTextGenNumType.BULLET;
        if ((ty.indexOf("decimal") >= 0)) 
            return com.pullenti.unitext.internal.uni.UniTextGenNumType.DECIMAL;
        if (com.pullenti.unisharp.Utils.stringsEq(ty, "lowerLetter")) 
            return com.pullenti.unitext.internal.uni.UniTextGenNumType.LOWERLETTER;
        if (com.pullenti.unisharp.Utils.stringsEq(ty, "russianLower")) 
            return com.pullenti.unitext.internal.uni.UniTextGenNumType.LOWERCYRLETTER;
        if (com.pullenti.unisharp.Utils.stringsEq(ty, "russianUpper")) 
            return com.pullenti.unitext.internal.uni.UniTextGenNumType.UPPERCYRLETTER;
        if (com.pullenti.unisharp.Utils.stringsEq(ty, "upperLetter")) 
            return com.pullenti.unitext.internal.uni.UniTextGenNumType.UPPERLETTER;
        if (com.pullenti.unisharp.Utils.stringsEq(ty, "lowerRoman")) 
            return com.pullenti.unitext.internal.uni.UniTextGenNumType.LOWERROMAN;
        if ((ty.indexOf("oman") >= 0)) 
            return com.pullenti.unitext.internal.uni.UniTextGenNumType.UPPERROMAN;
        return com.pullenti.unitext.internal.uni.UniTextGenNumType.DECIMAL;
    }
    public DocNumStyles() {
    }
}
