/*
 * 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 DocxToText implements AutoCloseable {

    public int maxTableRows;

    public DocxToText(String fileName, byte[] content, boolean isXml, boolean setFormulaAsImage) throws Exception, javax.xml.stream.XMLStreamException, java.io.IOException, org.xml.sax.SAXException, java.io.FileNotFoundException {
        setFormulasAsImage = setFormulaAsImage;
        if (isXml) {
            xmlFile = new com.pullenti.unisharp.XmlDocumentWrapper();
            if (content != null) {
                try (com.pullenti.unisharp.MemoryStream mem = new com.pullenti.unisharp.MemoryStream(content)) {
                    xmlFile.load(mem);
                }
            }
            else {
                try (com.pullenti.unisharp.FileStream fs = new com.pullenti.unisharp.FileStream(fileName, "r", "")) {
                    xmlFile.load(fs);
                }
            }
            this._prepareXml();
        }
        else {
            zipFile = new com.pullenti.unitext.internal.misc.MyZipFile(fileName, content);
            this._prepareZip();
        }
    }

    private boolean setFormulasAsImage;

    private void _prepareZip() {
        for (com.pullenti.unitext.internal.misc.MyZipEntry o : zipFile.entries) {
            if (o.isDirectory || o.encrypted || o.uncompressDataSize == 0) 
                continue;
            parts.add(DocxPart._new488(o.name, o));
        }
    }

    private void _prepareXml() {
        if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(xmlFile.doc.getDocumentElement()), "wordDocument")) {
            parts.add(DocxPart._new489("word/document.xml", xmlFile.doc.getDocumentElement()));
            return;
        }
        for (org.w3c.dom.Node xml : (new com.pullenti.unisharp.XmlNodeListWrapper(xmlFile.doc.getDocumentElement().getChildNodes())).arr) {
            if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(xml), "part")) {
                DocxPart p = new DocxPart();
                if (xml.getAttributes() != null) {
                    for (org.w3c.dom.Node a : (new com.pullenti.unisharp.XmlAttrListWrapper(xml.getAttributes())).arr) {
                        if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "name")) {
                            p.name = a.getNodeValue();
                            if (p.name.startsWith("/")) 
                                p.name = p.name.substring(1);
                            break;
                        }
                    }
                }
                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), "xmlData")) {
                        for (org.w3c.dom.Node xx : (new com.pullenti.unisharp.XmlNodeListWrapper(x.getChildNodes())).arr) {
                            p.xml = xx;
                            break;
                        }
                        break;
                    }
                    else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "binaryData")) {
                        try {
                            p.data = java.util.Base64.getDecoder().decode((x.getTextContent()).replace("\r", "").replace("\n", ""));
                        } catch (Exception ex) {
                        }
                        break;
                    }
                }
                if (p.name != null && ((p.xml != null || p.data != null))) 
                    parts.add(p);
            }
        }
    }

    @Override
    public void close() {
        try {
            if (zipFile != null) {
                zipFile.close();
                zipFile = null;
            }
        } catch (Exception ex) {
        }
    }

    private com.pullenti.unitext.internal.misc.MyZipFile zipFile = null;

    private com.pullenti.unisharp.XmlDocumentWrapper xmlFile = null;

    private java.util.ArrayList<DocxPart> parts = new java.util.ArrayList<DocxPart>();

    private java.util.HashMap<String, String> m_Hyperlinks = new java.util.HashMap<String, String>();

    private java.util.HashMap<String, String> m_DataControls = new java.util.HashMap<String, String>();

    public DocTextStyles m_Styles = new DocTextStyles();

    public DocNumStyles m_NumStyles = new DocNumStyles();

    private java.util.ArrayList<DocSection> m_Sections = new java.util.ArrayList<DocSection>();

    private com.pullenti.unitext.UnitextPagesection m_CurSection;

    private java.util.HashMap<String, String> m_Collontituls = new java.util.HashMap<String, String>();

    public com.pullenti.unitext.UnitextDocument createUniDoc(boolean onlyForPureText, com.pullenti.unitext.FileFormat frm, com.pullenti.unitext.CreateDocumentParam pars) throws Exception, javax.xml.stream.XMLStreamException, java.io.IOException, org.xml.sax.SAXException, NumberFormatException, java.io.FileNotFoundException {
        java.util.HashMap<String, String> sheets = new java.util.HashMap<String, String>();
        java.util.HashMap<String, String> idImages = new java.util.HashMap<String, String>();
        java.util.HashMap<String, String> idEmbeds = new java.util.HashMap<String, String>();
        java.util.ArrayList<com.pullenti.unitext.UnitextItem> sharedStrings = new java.util.ArrayList<com.pullenti.unitext.UnitextItem>();
        java.util.HashMap<Integer, com.pullenti.unitext.UnitextItem> pptSlides = new java.util.HashMap<Integer, com.pullenti.unitext.UnitextItem>();
        java.util.HashMap<Integer, java.util.HashMap<String, String>> pptImages = new java.util.HashMap<Integer, java.util.HashMap<String, String>>();
        org.w3c.dom.Node xmlDoc = null;
        org.w3c.dom.Node xmlBook = null;
        org.w3c.dom.Node xmlComments = null;
        org.w3c.dom.Node xmlSettings = null;
        org.w3c.dom.Node xmlFootnotes = null;
        org.w3c.dom.Node xmlEndnotes = null;
        org.w3c.dom.Node xmlOdtContent = null;
        org.w3c.dom.Node xmlOdtStyle = null;
        for (DocxPart p : parts) {
            if (p.name != null && p.name.startsWith("word/theme/")) 
                m_Styles.readTheme(p.getXmlNode(false));
        }
        for (DocxPart p : parts) {
            if (p.isName("word/numbering.xml")) {
                org.w3c.dom.Node xmlNum = p.getXmlNode(false);
                if (xmlNum != null) 
                    m_NumStyles.readAllStyles(xmlNum);
            }
        }
        for (DocxPart p : parts) {
            if (p.isName("word/styles.xml")) 
                m_Styles.readAllStyles(p.getXmlNode(false), m_NumStyles);
        }
        for (DocxPart p : parts) {
            if (p.isName("word/document.xml")) 
                xmlDoc = p.getXmlNode(false);
            else if (p.isName("word/footnotes.xml")) 
                xmlFootnotes = p.getXmlNode(false);
            else if (p.isName("word/endnotes.xml")) 
                xmlEndnotes = p.getXmlNode(false);
            else if (p.isName("word/styles.xml")) {
            }
            else if (p.isName("word/settings.xml")) 
                xmlSettings = p.getXmlNode(false);
            else if (p.isName("word/comments.xml")) {
                xmlComments = p.getXmlNode(false);
                if (xmlComments != null) {
                    for (org.w3c.dom.Node x : (new com.pullenti.unisharp.XmlNodeListWrapper(xmlComments.getChildNodes())).arr) {
                        if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "comment")) {
                            com.pullenti.unitext.UnitextComment cmt = new com.pullenti.unitext.UnitextComment();
                            String id = null;
                            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), "id")) 
                                        id = a.getNodeValue();
                                    else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "author")) 
                                        cmt.author = a.getNodeValue();
                                }
                            }
                            if (id == null || m_Comments.containsKey(id)) 
                                continue;
                            com.pullenti.unitext.internal.uni.UnitextGen gen = new com.pullenti.unitext.internal.uni.UnitextGen();
                            java.util.ArrayList<org.w3c.dom.Node> xxx = new java.util.ArrayList<org.w3c.dom.Node>();
                            xxx.add(x);
                            m_Styles.ignore = true;
                            this.readNode(xxx, gen, null, -1);
                            m_Styles.ignore = false;
                            com.pullenti.unitext.UnitextItem it = gen.finish(true, null);
                            if (it != null) {
                                StringBuilder tmp = new StringBuilder();
                                it.getPlaintext(tmp, null);
                                if (tmp.length() > 0) {
                                    cmt.text = tmp.toString();
                                    m_Comments.put(id, cmt);
                                }
                            }
                        }
                    }
                }
            }
            else if (p.isName("content.xml")) 
                xmlOdtContent = p.getXmlNode(true);
            else if (p.isName("styles.xml")) 
                xmlOdtStyle = p.getXmlNode(true);
            else if (p.isName("xl/workbook.xml")) 
                xmlBook = p.getXmlNode(false);
            else if (p.isName("xl/sharedStrings.xml")) {
                org.w3c.dom.Node xml = p.getXmlNode(false);
                if (xml != null) {
                    for (org.w3c.dom.Node xx : (new com.pullenti.unisharp.XmlNodeListWrapper(xml.getChildNodes())).arr) {
                        if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(xx), "si")) {
                            com.pullenti.unitext.internal.uni.UnitextGen gg = new com.pullenti.unitext.internal.uni.UnitextGen();
                            java.util.ArrayList<org.w3c.dom.Node> xxx = new java.util.ArrayList<org.w3c.dom.Node>();
                            xxx.add(xx);
                            m_Styles.ignore = true;
                            this.readNode(xxx, gg, null, -1);
                            m_Styles.ignore = false;
                            com.pullenti.unitext.UnitextItem ff = gg.finish(true, null);
                            if (ff != null) 
                                ff = ff.optimize(true, pars);
                            sharedStrings.add(ff);
                        }
                    }
                }
            }
            else if (p.isName("xl/styles.xml")) {
                org.w3c.dom.Node xml = p.getXmlNode(false);
                if (xml != null) 
                    m_Styles.readAllExcelStyles(xml);
            }
            else if (((p.isNameStarts("word/_rels/") || p.isNameStarts("xl/_rels/") || p.isNameStarts("ppt/slides/_rels/"))) && ((p.zipEntry != null && !p.zipEntry.isDirectory))) {
                org.w3c.dom.Node xmlRels = p.getXmlNode(false);
                if (xmlRels != null) {
                    java.util.HashMap<String, String> pptImgs = null;
                    if (p.name.startsWith("ppt")) {
                        int ii = p.name.indexOf("rels/slide");
                        if (ii < 0) 
                            continue;
                        String nam = p.name.substring(ii + 10);
                        ii = nam.indexOf('.');
                        if (ii < 0) 
                            continue;
                        com.pullenti.unisharp.Outargwrapper<Integer> wrapii490 = new com.pullenti.unisharp.Outargwrapper<Integer>();
                        boolean inoutres491 = com.pullenti.unisharp.Utils.parseInteger(nam.substring(0, 0 + ii), 0, null, wrapii490);
                        ii = (wrapii490.value != null ? wrapii490.value : 0);
                        if (!inoutres491) 
                            continue;
                        if (pptImages.containsKey(ii)) 
                            continue;
                        pptImgs = new java.util.HashMap<String, String>();
                        pptImages.put(ii, pptImgs);
                    }
                    for (org.w3c.dom.Node xx : (new com.pullenti.unisharp.XmlNodeListWrapper(xmlRels.getChildNodes())).arr) {
                        if (xx.getAttributes() != null) {
                            if (com.pullenti.unisharp.Utils.getXmlAttrByName(xx.getAttributes(), "Id") != null && com.pullenti.unisharp.Utils.getXmlAttrByName(xx.getAttributes(), "Target") != null && com.pullenti.unisharp.Utils.getXmlAttrByName(xx.getAttributes(), "Type") != null) {
                                String id = com.pullenti.unisharp.Utils.getXmlAttrByName(xx.getAttributes(), "Id").getNodeValue();
                                String val = com.pullenti.unisharp.Utils.getXmlAttrByName(xx.getAttributes(), "Target").getNodeValue();
                                String typ = com.pullenti.unisharp.Utils.getXmlAttrByName(xx.getAttributes(), "Type").getNodeValue();
                                if (typ.endsWith("/header")) 
                                    m_Collontituls.put(id, val);
                                else if (typ.endsWith("/footer")) 
                                    m_Collontituls.put(id, val);
                                else if (typ.endsWith("/worksheet")) 
                                    sheets.put(id, val);
                                else if (typ.endsWith("/image")) {
                                    if (pptImgs != null) {
                                        if (!pptImgs.containsKey(id)) 
                                            pptImgs.put(id, val);
                                    }
                                    else if (!idImages.containsKey(id)) 
                                        idImages.put(id, val);
                                }
                                else if (typ.endsWith("/package")) {
                                    if (!idEmbeds.containsKey(id)) 
                                        idEmbeds.put(id, val);
                                }
                                else if (typ.endsWith("/hyperlink")) {
                                    if (!com.pullenti.unisharp.Utils.isNullOrEmpty(val) && !m_Hyperlinks.containsKey(id)) 
                                        m_Hyperlinks.put(id, val);
                                }
                            }
                        }
                    }
                }
            }
            else if (p.isNameStarts("ppt/slides/slide") && p.name.endsWith(".xml")) {
                xmlDoc = p.getXmlNode(false);
                if (xmlDoc == null) 
                    continue;
                com.pullenti.unitext.internal.uni.UnitextGen gen = new com.pullenti.unitext.internal.uni.UnitextGen();
                java.util.ArrayList<org.w3c.dom.Node> xxx = new java.util.ArrayList<org.w3c.dom.Node>();
                xxx.add(xmlDoc);
                this.readNode(xxx, gen, null, -1);
                com.pullenti.unitext.UnitextItem slide = gen.finish(true, null);
                if (slide == null) 
                    continue;
                String nam = p.name.substring("ppt/slides/slide".length());
                int ii = nam.indexOf('.');
                if (ii < 0) 
                    continue;
                com.pullenti.unisharp.Outargwrapper<Integer> wrapii492 = new com.pullenti.unisharp.Outargwrapper<Integer>();
                boolean inoutres493 = com.pullenti.unisharp.Utils.parseInteger(nam.substring(0, 0 + ii), 0, null, wrapii492);
                ii = (wrapii492.value != null ? wrapii492.value : 0);
                if (inoutres493) {
                }
                else 
                    ii = pptSlides.size() + 1;
                for (; ; ii++) {
                    if (!pptSlides.containsKey(ii)) {
                        pptSlides.put(ii, slide);
                        break;
                    }
                }
            }
        }
        if (xmlOdtContent != null) {
            com.pullenti.unitext.internal.misc.OdtHelper dh = new com.pullenti.unitext.internal.misc.OdtHelper();
            com.pullenti.unitext.UnitextDocument res = dh.createUni(xmlOdtContent, (xmlOdtStyle == null ? null : xmlOdtStyle));
            if (res == null) 
                return null;
            java.util.ArrayList<com.pullenti.unitext.UnitextItem> its = new java.util.ArrayList<com.pullenti.unitext.UnitextItem>();
            java.util.ArrayList<String> keys = new java.util.ArrayList<String>();
            res.getAllItems(its, 0);
            for (com.pullenti.unitext.UnitextItem it : its) {
                if ((it instanceof com.pullenti.unitext.UnitextImage) && it.id != null && !keys.contains(it.id.toLowerCase())) 
                    keys.add(it.id.toLowerCase());
            }
            if (its.size() > 0 && !onlyForPureText) {
                for (com.pullenti.unitext.internal.misc.MyZipEntry o : zipFile.entries) {
                    String kkk = o.name.toLowerCase();
                    if (!keys.contains(kkk)) 
                        continue;
                    byte[] dat = o.getData();
                    if (dat != null && dat.length > 0) {
                        for (com.pullenti.unitext.UnitextItem it : its) {
                            if ((it instanceof com.pullenti.unitext.UnitextImage) && it.id != null && com.pullenti.unisharp.Utils.stringsEq(it.id.toLowerCase(), kkk)) 
                                ((com.pullenti.unitext.UnitextImage)com.pullenti.unisharp.Utils.cast(it, com.pullenti.unitext.UnitextImage.class)).content = dat;
                        }
                    }
                }
            }
            return res;
        }
        if (pptSlides.size() > 0) {
            com.pullenti.unitext.UnitextDocument res = com.pullenti.unitext.UnitextDocument._new494(com.pullenti.unitext.FileFormat.PPTX, m_DataControls);
            com.pullenti.unitext.UnitextContainer cnt = new com.pullenti.unitext.UnitextContainer();
            res.content = cnt;
            for (java.util.Map.Entry<Integer, com.pullenti.unitext.UnitextItem> kp : pptSlides.entrySet()) {
                if (cnt.children.size() > 0) 
                    cnt.children.add(new com.pullenti.unitext.UnitextPagebreak());
                cnt.children.add(kp.getValue());
                if (pptImages.containsKey(kp.getKey())) {
                    java.util.ArrayList<com.pullenti.unitext.UnitextItem> imgs = new java.util.ArrayList<com.pullenti.unitext.UnitextItem>();
                    kp.getValue().getAllItems(imgs, 0);
                    for (com.pullenti.unitext.UnitextItem it : imgs) {
                        com.pullenti.unitext.UnitextImage im = (com.pullenti.unitext.UnitextImage)com.pullenti.unisharp.Utils.cast(it, com.pullenti.unitext.UnitextImage.class);
                        if (im != null && pptImages.get(kp.getKey()).containsKey((im.id != null ? im.id : ""))) {
                            im.id = pptImages.get(kp.getKey()).get(im.id);
                            if (im.id.startsWith("../")) 
                                im.id = im.id.substring(3);
                        }
                    }
                }
            }
            if (!onlyForPureText) {
                java.util.ArrayList<com.pullenti.unitext.UnitextItem> ims = new java.util.ArrayList<com.pullenti.unitext.UnitextItem>();
                res.getAllItems(ims, 0);
                for (DocxPart p : parts) {
                    String kkk = p.name.toLowerCase();
                    byte[] dat = null;
                    for (com.pullenti.unitext.UnitextItem im : ims) {
                        if ((im instanceof com.pullenti.unitext.UnitextImage) && im.id != null) {
                            if (kkk.endsWith(im.id)) {
                                if (dat == null) 
                                    dat = p.getBytes();
                                ((com.pullenti.unitext.UnitextImage)com.pullenti.unisharp.Utils.cast(im, com.pullenti.unitext.UnitextImage.class)).content = dat;
                            }
                        }
                    }
                }
            }
            return res;
        }
        if (idEmbeds.size() > 0) {
            for (DocxPart p : parts) {
                for (java.util.Map.Entry<String, String> kp : idEmbeds.entrySet()) {
                    if (!m_Embeds.containsKey(kp.getKey())) {
                        if (p.name.toLowerCase().endsWith(kp.getValue().toLowerCase())) {
                            byte[] dat = p.getBytes();
                            if (dat != null && dat.length > 0) {
                                com.pullenti.unitext.UnitextDocument doc1 = com.pullenti.unitext.UnitextService.createDocument(p.name, dat, null);
                                if (doc1 != null && doc1.content != null) 
                                    m_Embeds.put(kp.getKey(), doc1.content);
                            }
                            break;
                        }
                    }
                }
            }
        }
        if (xmlDoc != null) {
            com.pullenti.unitext.UnitextDocument res = com.pullenti.unitext.UnitextDocument._new494(com.pullenti.unitext.FileFormat.DOCX, m_DataControls);
            com.pullenti.unitext.UnitextStyledFragment rootStyle = new com.pullenti.unitext.UnitextStyledFragment();
            rootStyle.setDoc(res);
            if (m_Styles.defStyle != null) {
                m_Styles.defStyle = m_Styles.registerStyle(m_Styles.defStyle);
                rootStyle.setStyle(m_Styles.defStyle);
            }
            m_Sections.add(new DocSection());
            m_CurSection = m_Sections.get(0).uSect;
            m_CurSection.id = "ps1";
            boolean evenAndOddHeaders = false;
            if (xmlSettings != null) {
                for (org.w3c.dom.Node x : (new com.pullenti.unisharp.XmlNodeListWrapper(xmlSettings.getChildNodes())).arr) {
                    if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "evenAndOddHeaders")) 
                        evenAndOddHeaders = true;
                }
            }
            if (xmlFootnotes != null) {
                java.util.ArrayList<org.w3c.dom.Node> li = new java.util.ArrayList<org.w3c.dom.Node>();
                li.add(xmlFootnotes);
                this.readFootnotes(li, false, rootStyle);
            }
            if (xmlEndnotes != null) {
                java.util.ArrayList<org.w3c.dom.Node> li = new java.util.ArrayList<org.w3c.dom.Node>();
                li.add(xmlEndnotes);
                this.readFootnotes(li, true, rootStyle);
            }
            com.pullenti.unitext.internal.uni.UnitextGen gen = new com.pullenti.unitext.internal.uni.UnitextGen();
            gen.setStyle(rootStyle);
            java.util.ArrayList<org.w3c.dom.Node> xxx = new java.util.ArrayList<org.w3c.dom.Node>();
            xxx.add(xmlDoc);
            this.readNode(xxx, gen, rootStyle, -1);
            com.pullenti.unitext.UnitextItem body = gen.finish(true, null);
            if (body == null) 
                return null;
            res.content = body;
            res.content.m_StyledFrag = rootStyle;
            if (m_Sections.size() > 0 && !m_Sections.get(m_Sections.size() - 1).loaded) 
                m_Sections.remove(m_Sections.size() - 1);
            m_CurSection = null;
            for (DocSection s : m_Sections) {
                res.sections.add(s.uSect);
                for (int k = 0; k < 2; k++) {
                    java.util.HashMap<com.pullenti.unitext.UnitextPagesectionItemPages, String> ids = (k == 0 ? s.headIds : s.footIds);
                    java.util.ArrayList<com.pullenti.unitext.UnitextPagesectionItem> pits = new java.util.ArrayList<com.pullenti.unitext.UnitextPagesectionItem>();
                    for (java.util.Map.Entry<com.pullenti.unitext.UnitextPagesectionItemPages, String> kp : ids.entrySet()) {
                        if (!m_Collontituls.containsKey(kp.getValue())) 
                            continue;
                        if (!evenAndOddHeaders) {
                            if (kp.getKey() == com.pullenti.unitext.UnitextPagesectionItemPages.EVEN || kp.getKey() == com.pullenti.unitext.UnitextPagesectionItemPages.ODD) 
                                continue;
                        }
                        if (!s.titlePg) {
                            if (kp.getKey() == com.pullenti.unitext.UnitextPagesectionItemPages.FIRST) 
                                continue;
                        }
                        String fnam = m_Collontituls.get(kp.getValue());
                        com.pullenti.unitext.UnitextStyledFragment sectRootStyle = new com.pullenti.unitext.UnitextStyledFragment();
                        sectRootStyle.setDoc(res);
                        com.pullenti.unitext.internal.uni.UnitextGen g = new com.pullenti.unitext.internal.uni.UnitextGen();
                        g.setStyle(sectRootStyle);
                        for (DocxPart p : parts) {
                            String kkk = p.name;
                            int ii = kkk.indexOf('/');
                            if (ii < 0) 
                                continue;
                            kkk = kkk.substring(ii + 1);
                            if (com.pullenti.unisharp.Utils.stringsNe(kkk, fnam)) 
                                continue;
                            org.w3c.dom.Node xml = p.getXmlNode(false);
                            if (xml != null) {
                                xxx.clear();
                                xxx.add(xml);
                                this.readNode(xxx, g, sectRootStyle, -1);
                                break;
                            }
                        }
                        com.pullenti.unitext.UnitextItem fi = g.finish(true, null);
                        com.pullenti.unitext.UnitextPagesectionItem it = new com.pullenti.unitext.UnitextPagesectionItem();
                        if (k > 0) 
                            it.isFooter = true;
                        it.pages = kp.getKey();
                        it.content = fi;
                        java.util.ArrayList<com.pullenti.unitext.UnitextItem> its = new java.util.ArrayList<com.pullenti.unitext.UnitextItem>();
                        fi.getAllItems(its, 0);
                        for (com.pullenti.unitext.UnitextItem ii : its) {
                            if (ii instanceof com.pullenti.unitext.UnitextContainer) {
                                com.pullenti.unitext.UnitextContainer ccc = (com.pullenti.unitext.UnitextContainer)com.pullenti.unisharp.Utils.cast(ii, com.pullenti.unitext.UnitextContainer.class);
                                for (int i = 0; i < ccc.children.size(); i++) {
                                    if (ccc.children.get(i) instanceof com.pullenti.unitext.UnitextPagebreak) 
                                        com.pullenti.unisharp.Utils.putArrayValue(ccc.children, i, new com.pullenti.unitext.UnitextNewline());
                                }
                            }
                        }
                        if (it.pages == com.pullenti.unitext.UnitextPagesectionItemPages.FIRST) 
                            pits.add(0, it);
                        else 
                            pits.add(it);
                    }
                    com.pullenti.unisharp.Utils.addToArrayList(s.uSect.items, pits);
                    if (s.titlePg) {
                        boolean hasTitle = false;
                        for (com.pullenti.unitext.UnitextPagesectionItem pi : pits) {
                            if (pi.pages == com.pullenti.unitext.UnitextPagesectionItemPages.FIRST) 
                                hasTitle = true;
                        }
                        if (!hasTitle && res.sections.size() > 1) {
                            com.pullenti.unitext.UnitextPagesection sprev = res.sections.get(res.sections.size() - 2);
                            for (com.pullenti.unitext.UnitextPagesectionItem it : sprev.items) {
                                if (it.pages == com.pullenti.unitext.UnitextPagesectionItemPages.FIRST && it.isFooter == (k > 0)) {
                                    com.pullenti.unitext.UnitextPagesectionItem it2 = (com.pullenti.unitext.UnitextPagesectionItem)com.pullenti.unisharp.Utils.cast(it.clone(), com.pullenti.unitext.UnitextPagesectionItem.class);
                                    s.uSect.items.add(it2);
                                    break;
                                }
                            }
                        }
                    }
                    if (!evenAndOddHeaders) {
                        boolean has = false;
                        for (com.pullenti.unitext.UnitextPagesectionItem pi : pits) {
                            if (pi.pages == com.pullenti.unitext.UnitextPagesectionItemPages.DEFAULT) 
                                has = true;
                        }
                        if (!has && res.sections.size() > 1) {
                            com.pullenti.unitext.UnitextPagesection sprev = res.sections.get(res.sections.size() - 2);
                            for (com.pullenti.unitext.UnitextPagesectionItem it : sprev.items) {
                                if (it.pages == com.pullenti.unitext.UnitextPagesectionItemPages.DEFAULT && it.isFooter == (k > 0)) {
                                    com.pullenti.unitext.UnitextPagesectionItem it2 = (com.pullenti.unitext.UnitextPagesectionItem)com.pullenti.unisharp.Utils.cast(it.clone(), com.pullenti.unitext.UnitextPagesectionItem.class);
                                    s.uSect.items.add(it2);
                                    break;
                                }
                            }
                        }
                    }
                    else {
                        boolean has = false;
                        for (com.pullenti.unitext.UnitextPagesectionItem pi : pits) {
                            if (pi.pages == com.pullenti.unitext.UnitextPagesectionItemPages.EVEN) 
                                has = true;
                        }
                        if (!has && res.sections.size() > 1) {
                            com.pullenti.unitext.UnitextPagesection sprev = res.sections.get(res.sections.size() - 2);
                            for (com.pullenti.unitext.UnitextPagesectionItem it : sprev.items) {
                                if (it.pages == com.pullenti.unitext.UnitextPagesectionItemPages.EVEN && it.isFooter == (k > 0)) {
                                    com.pullenti.unitext.UnitextPagesectionItem it2 = (com.pullenti.unitext.UnitextPagesectionItem)com.pullenti.unisharp.Utils.cast(it.clone(), com.pullenti.unitext.UnitextPagesectionItem.class);
                                    s.uSect.items.add(it2);
                                    break;
                                }
                            }
                        }
                        has = false;
                        for (com.pullenti.unitext.UnitextPagesectionItem pi : pits) {
                            if (pi.pages == com.pullenti.unitext.UnitextPagesectionItemPages.DEFAULT || pi.pages == com.pullenti.unitext.UnitextPagesectionItemPages.ODD) 
                                has = true;
                        }
                        if (!has && res.sections.size() > 1) {
                            com.pullenti.unitext.UnitextPagesection sprev = res.sections.get(res.sections.size() - 2);
                            for (com.pullenti.unitext.UnitextPagesectionItem it : sprev.items) {
                                if (((it.pages == com.pullenti.unitext.UnitextPagesectionItemPages.DEFAULT || it.pages == com.pullenti.unitext.UnitextPagesectionItemPages.ODD)) && it.isFooter == (k > 0)) {
                                    com.pullenti.unitext.UnitextPagesectionItem it2 = (com.pullenti.unitext.UnitextPagesectionItem)com.pullenti.unisharp.Utils.cast(it.clone(), com.pullenti.unitext.UnitextPagesectionItem.class);
                                    s.uSect.items.add(it2);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            res.styles = m_Styles.uStyles;
            if (!onlyForPureText) {
                java.util.ArrayList<com.pullenti.unitext.UnitextItem> its = new java.util.ArrayList<com.pullenti.unitext.UnitextItem>();
                res.getAllItems(its, 0);
                java.util.ArrayList<com.pullenti.unitext.UnitextImage> iii = new java.util.ArrayList<com.pullenti.unitext.UnitextImage>();
                java.util.ArrayList<String> iiids = new java.util.ArrayList<String>();
                for (com.pullenti.unitext.UnitextItem i : its) {
                    if ((i instanceof com.pullenti.unitext.UnitextImage) && i.id != null && idImages.containsKey(i.id)) {
                        iii.add((com.pullenti.unitext.UnitextImage)com.pullenti.unisharp.Utils.cast(i, com.pullenti.unitext.UnitextImage.class));
                        i.tag = idImages.get(i.id);
                        iiids.add((String)com.pullenti.unisharp.Utils.cast(i.tag, String.class));
                        i.id = null;
                    }
                }
                if (iii.size() > 0) {
                    for (DocxPart p : parts) {
                        String kkk = p.name;
                        if (!iiids.contains(kkk)) {
                            int ii = kkk.indexOf('/');
                            if (ii < 0) 
                                continue;
                            kkk = kkk.substring(ii + 1);
                            if (!iiids.contains(kkk)) 
                                continue;
                        }
                        byte[] dat = p.getBytes();
                        if (dat != null) {
                            for (com.pullenti.unitext.UnitextImage kp : iii) {
                                if (com.pullenti.unisharp.Utils.stringsEq((String)com.pullenti.unisharp.Utils.cast(kp.tag, String.class), kkk)) 
                                    kp.content = dat;
                            }
                        }
                    }
                }
            }
            return res;
        }
        if (xmlBook != null && zipFile != null) {
            com.pullenti.unitext.UnitextDocument res = com.pullenti.unitext.UnitextDocument._new494(com.pullenti.unitext.FileFormat.XLSX, m_DataControls);
            java.util.HashMap<String, String> books = new java.util.HashMap<String, String>();
            for (org.w3c.dom.Node xml : (new com.pullenti.unisharp.XmlNodeListWrapper(xmlBook.getChildNodes())).arr) {
                if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(xml), "sheets")) {
                    for (org.w3c.dom.Node xx : (new com.pullenti.unisharp.XmlNodeListWrapper(xml.getChildNodes())).arr) {
                        String id = null;
                        String nams = null;
                        if (xx.getAttributes() != null) {
                            for (org.w3c.dom.Node a : (new com.pullenti.unisharp.XmlAttrListWrapper(xx.getAttributes())).arr) {
                                if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "name")) 
                                    nams = a.getNodeValue();
                                else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "id")) 
                                    id = a.getNodeValue();
                            }
                        }
                        if (id != null && nams != null && !books.containsKey(nams)) 
                            books.put(id, nams);
                    }
                }
            }
            java.util.HashMap<String, com.pullenti.unitext.UnitextItem> sss = new java.util.HashMap<String, com.pullenti.unitext.UnitextItem>();
            for (com.pullenti.unitext.internal.misc.MyZipEntry o : zipFile.entries) {
                String kkk = o.name;
                int ii = kkk.indexOf('/');
                if (ii < 0) 
                    continue;
                kkk = kkk.substring(ii + 1);
                String id = null;
                for (java.util.Map.Entry<String, String> kp : sheets.entrySet()) {
                    if (com.pullenti.unisharp.Utils.stringsEq(kp.getValue(), kkk)) {
                        id = kp.getKey();
                        break;
                    }
                }
                if (id == null) 
                    continue;
                String sheetName = null;
                com.pullenti.unisharp.Outargwrapper<String> wrapsheetName497 = new com.pullenti.unisharp.Outargwrapper<String>();
                com.pullenti.unisharp.Utils.tryGetValue(books, id, wrapsheetName497);
                sheetName = wrapsheetName497.value;
                byte[] dat = o.getData();
                if (dat == null) 
                    continue;
                com.pullenti.unitext.internal.misc.MyXmlReader xr = com.pullenti.unitext.internal.misc.MyXmlReader.create(dat);
                com.pullenti.unitext.UnitextItem cnt = com.pullenti.unitext.internal.misc.ExcelHelper.readSheet(xr, sharedStrings, sheetName, m_Styles, maxTableRows);
                if (cnt == null) 
                    continue;
                sss.put(id, cnt);
            }
            java.util.ArrayList<com.pullenti.unitext.UnitextItem> ss = new java.util.ArrayList<com.pullenti.unitext.UnitextItem>();
            for (java.util.Map.Entry<String, String> kp : books.entrySet()) {
                if (sss.containsKey(kp.getKey())) {
                    if (sss.get(kp.getKey()) != null) 
                        ss.add(sss.get(kp.getKey()));
                }
            }
            if (ss.size() == 0) 
                return null;
            if (ss.size() == 1) 
                res.content = ss.get(0);
            else {
                com.pullenti.unitext.UnitextContainer cnt = new com.pullenti.unitext.UnitextContainer();
                for (int ii = 0; ii < ss.size(); ii++) {
                    if (ii > 0) 
                        cnt.children.add(new com.pullenti.unitext.UnitextPagebreak());
                    cnt.children.add(ss.get(ii));
                }
                res.content = cnt;
            }
            res.optimize(false, pars);
            return res;
        }
        return null;
    }

    private java.util.HashMap<String, com.pullenti.unitext.UnitextComment> m_Comments = new java.util.HashMap<String, com.pullenti.unitext.UnitextComment>();

    private java.util.HashMap<String, com.pullenti.unitext.UnitextItem> m_Embeds = new java.util.HashMap<String, com.pullenti.unitext.UnitextItem>();

    private java.util.HashMap<String, com.pullenti.unitext.UnitextItem> m_Footnotes = new java.util.HashMap<String, com.pullenti.unitext.UnitextItem>();

    private void readFootnotes(java.util.ArrayList<org.w3c.dom.Node> stackList, boolean end, com.pullenti.unitext.UnitextStyledFragment rootStyle) {
        org.w3c.dom.Node node = stackList.get(stackList.size() - 1);
        for (org.w3c.dom.Node xml : (new com.pullenti.unisharp.XmlNodeListWrapper(node.getChildNodes())).arr) {
            if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(xml), "footnote") || com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(xml), "endnote")) {
                String id = null;
                if (xml.getAttributes() != null) {
                    for (org.w3c.dom.Node a : (new com.pullenti.unisharp.XmlAttrListWrapper(xml.getAttributes())).arr) {
                        if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "id")) {
                            id = a.getNodeValue();
                            if (end) 
                                id = "end" + id;
                            break;
                        }
                    }
                }
                if (id == null || m_Footnotes.containsKey(id)) 
                    continue;
                com.pullenti.unitext.internal.uni.UnitextGen gen = new com.pullenti.unitext.internal.uni.UnitextGen();
                gen.setStyle(rootStyle);
                stackList.add(xml);
                this.readNode(stackList, gen, rootStyle, -1);
                stackList.remove(stackList.size() - 1);
                com.pullenti.unitext.UnitextItem fi = gen.finish(true, null);
                if (fi != null) 
                    m_Footnotes.put(id, fi);
            }
        }
    }

    private String m_lastRSID = "";

    private char m_lastChar = ' ';

    public void readNode(java.util.ArrayList<org.w3c.dom.Node> stackNodes, com.pullenti.unitext.internal.uni.UnitextGen gen, com.pullenti.unitext.UnitextStyledFragment sfrag, int pictTop) {
        if (stackNodes.size() == 0) 
            return;
        org.w3c.dom.Node node = stackNodes.get(stackNodes.size() - 1);
        for (org.w3c.dom.Node child : (new com.pullenti.unisharp.XmlNodeListWrapper(node.getChildNodes())).arr) {
            if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(child), "Fallback")) {
                stackNodes.add(child);
                this.readNode(stackNodes, gen, sfrag, pictTop);
                stackNodes.remove(stackNodes.size() - 1);
                return;
            }
        }
        String delText = null;
        boolean proofErr = false;
        for (int i = 0; i < node.getChildNodes().getLength(); i++) {
            org.w3c.dom.Node child = node.getChildNodes().item(i);
            String locname = com.pullenti.unisharp.Utils.getXmlLocalName(child);
            if (com.pullenti.unisharp.Utils.isNullOrEmpty(locname)) 
                continue;
            if (com.pullenti.unisharp.Utils.stringsEq(locname, "#text")) 
                continue;
            if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(node), "p")) {
            }
            if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(child), "r")) {
            }
            if (i == 7) {
            }
            if (proofErr) 
                continue;
            switch (locname) { 
            case "del":
                break;
            case "delText":
                break;
            case "moveFrom":
                break;
            case "AlternateContent":
                for (org.w3c.dom.Node x : (new com.pullenti.unisharp.XmlNodeListWrapper(child.getChildNodes())).arr) {
                    if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "Choice")) {
                        stackNodes.add(x);
                        this.readNode(stackNodes, gen, sfrag, pictTop);
                        stackNodes.remove(stackNodes.size() - 1);
                        break;
                    }
                }
                break;
            case "t":
                String text = child.getTextContent();
                if (com.pullenti.unisharp.Utils.stringsEq(text, "НЕ ВЫДЕЛ")) {
                }
                if (com.pullenti.unisharp.Utils.isNullOrEmpty(text) || com.pullenti.unisharp.Utils.stringsEq(text, delText)) 
                    m_lastChar = ' ';
                else {
                    if (delText != null) {
                        if (text.startsWith(delText)) 
                            text = text.substring(delText.length());
                    }
                    if (sfrag != null && sfrag.getStyle() != null && com.pullenti.unisharp.Utils.stringsEq(sfrag.getStyle().getAttr("upper-case"), "true")) 
                        text = text.toUpperCase();
                    m_lastChar = text.charAt(text.length() - 1);
                    gen.appendText(text, false);
                    if (text.startsWith("Дого")) {
                    }
                }
                delText = null;
                break;
            case "sym":
                String ch = null;
                if (child.getAttributes() != null) {
                    String font = null;
                    for (org.w3c.dom.Node a : (new com.pullenti.unisharp.XmlAttrListWrapper(child.getAttributes())).arr) {
                        if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "font")) {
                            font = a.getNodeValue();
                            break;
                        }
                    }
                    for (org.w3c.dom.Node a : (new com.pullenti.unisharp.XmlAttrListWrapper(child.getAttributes())).arr) {
                        if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "char")) {
                            int nn = 0;
                            for (int jj = 0; jj < a.getNodeValue().length(); jj++) {
                                int dig = (int)a.getNodeValue().charAt(jj);
                                if (dig >= 0x30 && dig <= 0x39) 
                                    nn = ((nn * 16) + dig) - 0x30;
                                else if (dig >= 0x41 && dig <= 0x46) 
                                    nn = (((nn * 16) + dig) - 0x41) + 10;
                                else if (dig >= 0x61 && dig <= 0x66) 
                                    nn = (((nn * 16) + dig) - 0x61) + 10;
                            }
                            if (a.getNodeValue().charAt(0) == 'F') 
                                nn -= 0xF000;
                            char uch = (char)0;
                            if (com.pullenti.unisharp.Utils.stringsCompare((font != null ? font : ""), "Symbol", true) == 0) 
                                uch = com.pullenti.unitext.internal.misc.SymbolHelper.getUnicode(nn);
                            else 
                                uch = com.pullenti.unitext.internal.misc.WingdingsHelper.getUnicode(nn);
                            if (uch == ((char)0)) 
                                ch = " ";
                            else 
                                ch = (String.valueOf(uch));
                        }
                    }
                }
                if (ch != null) {
                    gen.appendText(ch, false);
                    m_lastChar = ch.charAt(0);
                }
                break;
            case "cr":
                gen.appendNewline(false, false);
                break;
            case "commentRangeStart":
                if (child.getAttributes() != null) {
                    for (org.w3c.dom.Node a : (new com.pullenti.unisharp.XmlAttrListWrapper(child.getAttributes())).arr) {
                        if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "id")) {
                            com.pullenti.unitext.UnitextComment cmt;
                            com.pullenti.unisharp.Outargwrapper<com.pullenti.unitext.UnitextComment> wrapcmt498 = new com.pullenti.unisharp.Outargwrapper<com.pullenti.unitext.UnitextComment>();
                            boolean inoutres499 = com.pullenti.unisharp.Utils.tryGetValue(m_Comments, (String)com.pullenti.unisharp.Utils.notnull(a.getNodeValue(), ""), wrapcmt498);
                            cmt = wrapcmt498.value;
                            if (inoutres499) {
                                if (cmt.id == null) 
                                    cmt.id = "comment" + a.getNodeValue();
                                gen.append(cmt, null, -1, false);
                            }
                        }
                    }
                }
                break;
            case "commentRangeEnd":
                if (child.getAttributes() != null) {
                    for (org.w3c.dom.Node a : (new com.pullenti.unisharp.XmlAttrListWrapper(child.getAttributes())).arr) {
                        if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "id")) {
                            com.pullenti.unitext.UnitextComment cmt;
                            com.pullenti.unisharp.Outargwrapper<com.pullenti.unitext.UnitextComment> wrapcmt501 = new com.pullenti.unisharp.Outargwrapper<com.pullenti.unitext.UnitextComment>();
                            boolean inoutres502 = com.pullenti.unisharp.Utils.tryGetValue(m_Comments, (String)com.pullenti.unisharp.Utils.notnull(a.getNodeValue(), ""), wrapcmt501);
                            cmt = wrapcmt501.value;
                            if (inoutres502) {
                                com.pullenti.unitext.UnitextComment ecmt = com.pullenti.unitext.UnitextComment._new500(cmt.id + "_end", cmt.id, true);
                                cmt.twinId = ecmt.id;
                                ecmt.text = cmt.text;
                                ecmt.author = cmt.author;
                                gen.append(ecmt, null, -1, false);
                                m_Comments.remove(a.getNodeValue());
                            }
                        }
                    }
                }
                break;
            case "br":
                String val = null;
                if (child.getAttributes() != null && child.getAttributes().getLength() > 0 && (child.getAttributes().item(0).getNodeName().indexOf("type") >= 0)) 
                    val = child.getAttributes().item(0).getNodeValue();
                if (com.pullenti.unisharp.Utils.stringsEq(val, "page")) 
                    gen.appendPagebreak();
                else {
                    boolean isNewLine = false;
                    if (gen.lastNotSpaceChar == ':' || gen.lastNotSpaceChar == '.') 
                        isNewLine = true;
                    if (isNewLine) 
                        gen.appendNewline(false, true);
                    else 
                        gen.appendNewline(false, true);
                }
                break;
            case "pict":
                com.pullenti.unitext.UnitextImage img1 = null;
                for (org.w3c.dom.Node x : (new com.pullenti.unisharp.XmlNodeListWrapper(child.getChildNodes())).arr) {
                    if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "binData")) {
                        if (img1 == null) 
                            img1 = new com.pullenti.unitext.UnitextImage();
                        try {
                            img1.content = java.util.Base64.getDecoder().decode((x.getTextContent()).replace("\r", "").replace("\n", ""));
                        } catch (Exception ex) {
                        }
                        gen.append(img1, null, -1, false);
                    }
                    else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "shape") && 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), "style") && a.getNodeValue() != null) {
                                if (img1 == null) 
                                    img1 = new com.pullenti.unitext.UnitextImage();
                                _setImageSize(img1, a.getNodeValue());
                            }
                        }
                    }
                }
                if (img1 != null && img1.content != null) 
                    return;
                com.pullenti.unitext.internal.uni.UnitextGen gg = new com.pullenti.unitext.internal.uni.UnitextGen();
                gg.appendPagesection(m_CurSection);
                stackNodes.add(child);
                this.readNode(stackNodes, gg, sfrag, pictTop);
                stackNodes.remove(stackNodes.size() - 1);
                com.pullenti.unitext.UnitextItem it = gg.finish(true, null);
                if (it == null) 
                    break;
                if (it instanceof com.pullenti.unitext.UnitextContainer) 
                    ((com.pullenti.unitext.UnitextContainer)com.pullenti.unisharp.Utils.cast(it, com.pullenti.unitext.UnitextContainer.class)).typ = com.pullenti.unitext.UnitextContainerType.SHAPE;
                else {
                    com.pullenti.unitext.UnitextContainer cnt = com.pullenti.unitext.UnitextContainer._new94(com.pullenti.unitext.UnitextContainerType.SHAPE);
                    cnt.children.add(it);
                    it = cnt.optimize(false, null);
                }
                if (it != null) {
                    gen.append(it, null, -1, false);
                    gen.appendNewline(false, false);
                }
                break;
            case "tab":
                if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(node), "tabs")) {
                }
                else 
                    gen.appendText("\t", false);
                break;
            case "sectPr":
                m_Sections.get(m_Sections.size() - 1).load(child);
                DocSection se = new DocSection();
                m_Sections.add(se);
                se.uSect.id = ("ps" + m_Sections.size());
                m_CurSection = se.uSect;
                gen.appendPagesection(m_CurSection);
                break;
            case "tbl":
                DocTable tbl = new DocTable();
                stackNodes.add(child);
                tbl.read(this, sfrag, stackNodes);
                stackNodes.remove(stackNodes.size() - 1);
                com.pullenti.unitext.UnitextTable tab = tbl.createUni(maxTableRows);
                if (tab != null) 
                    gen.append(tab, null, -1, false);
                break;
            case "bookmarkStart":
                for (org.w3c.dom.Node a : (new com.pullenti.unisharp.XmlAttrListWrapper(child.getAttributes())).arr) {
                    if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "name")) {
                        if (com.pullenti.unisharp.Utils.stringsEq(a.getNodeValue(), "_GoBack")) 
                            continue;
                        com.pullenti.unitext.UnitextMisc mi = new com.pullenti.unitext.UnitextMisc();
                        mi.typ = com.pullenti.unitext.UnitextMiscType.ANCHOR;
                        mi.id = a.getNodeValue();
                        if (mi.id.endsWith("54874551")) {
                        }
                        if (com.pullenti.unisharp.Utils.stringsEq(mi.id, "_GoBack")) {
                        }
                        gen.append(mi, null, -1, false);
                        break;
                    }
                }
                break;
            case "fldSimple":
                com.pullenti.unitext.internal.uni.UnitextGen ggg1 = new com.pullenti.unitext.internal.uni.UnitextGen();
                ggg1.appendPagesection(m_CurSection);
                for (org.w3c.dom.Node a : (new com.pullenti.unisharp.XmlAttrListWrapper(child.getAttributes())).arr) {
                    if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "instr")) {
                        String vvv = a.getNodeValue().trim();
                        if (vvv.startsWith("SEQ")) 
                            ggg1.textGenRegime = true;
                    }
                }
                stackNodes.add(child);
                this.readNode(stackNodes, ggg1, sfrag, pictTop);
                stackNodes.remove(stackNodes.size() - 1);
                com.pullenti.unitext.UnitextItem ggt = ggg1.finish(true, null);
                if (ggg1.textGenRegime && ggt != null) 
                    gen.append(ggt, null, -1, false);
                else {
                    String txt = (ggt == null ? null : com.pullenti.unitext.internal.uni.UnitextHelper.getPlaintext(ggt, null));
                    if (!com.pullenti.unisharp.Utils.isNullOrEmpty(txt) && !gen.getLastText().endsWith(txt)) 
                        gen.appendText(txt, false);
                }
                break;
            case "hyperlink":
            case "hlink":
                boolean ok = false;
                if (child.getAttributes() != null) {
                    for (org.w3c.dom.Node a : (new com.pullenti.unisharp.XmlAttrListWrapper(child.getAttributes())).arr) {
                        if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "id")) {
                            if (m_Hyperlinks.containsKey(a.getNodeValue())) {
                                com.pullenti.unitext.internal.uni.UnitextGen ggg = new com.pullenti.unitext.internal.uni.UnitextGen();
                                ggg.appendPagesection(m_CurSection);
                                stackNodes.add(child);
                                this.readNode(stackNodes, ggg, sfrag, pictTop);
                                stackNodes.remove(stackNodes.size() - 1);
                                com.pullenti.unitext.UnitextItem cnt = ggg.finish(true, null);
                                if (cnt != null) {
                                    if (m_Hyperlinks.containsKey((String)com.pullenti.unisharp.Utils.notnull(a.getNodeValue(), ""))) {
                                        try {
                                            com.pullenti.unitext.UnitextHyperlink hr = com.pullenti.unitext.UnitextHyperlink._new59(m_Hyperlinks.get(a.getNodeValue()).toString());
                                            hr.content = cnt;
                                            gen.append(hr, null, -1, false);
                                        } catch (Exception xx) {
                                            gen.append(cnt, null, -1, false);
                                        }
                                    }
                                    else 
                                        gen.append(cnt, null, -1, false);
                                    ok = true;
                                    break;
                                }
                            }
                        }
                        else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "dest") || com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "anchor")) {
                            com.pullenti.unitext.internal.uni.UnitextGen ggg = new com.pullenti.unitext.internal.uni.UnitextGen();
                            ggg.appendPagesection(m_CurSection);
                            stackNodes.add(child);
                            this.readNode(stackNodes, ggg, sfrag, pictTop);
                            stackNodes.remove(stackNodes.size() - 1);
                            com.pullenti.unitext.UnitextItem cnt = ggg.finish(true, null);
                            if (cnt != null) {
                                com.pullenti.unitext.UnitextHyperlink hr = com.pullenti.unitext.UnitextHyperlink._new59(a.getNodeValue());
                                if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "anchor")) 
                                    hr.isInternal = true;
                                hr.content = cnt;
                                gen.append(hr, null, -1, false);
                                ok = true;
                                break;
                            }
                        }
                    }
                }
                if (!ok) {
                    stackNodes.add(child);
                    this.readNode(stackNodes, gen, sfrag, pictTop);
                    stackNodes.remove(stackNodes.size() - 1);
                }
                break;
            case "p":
                com.pullenti.unitext.internal.uni.IUnitextGenNumStyle numStyle = null;
                int lev = 0;
                DocTextStyle numTxtStyle = null;
                com.pullenti.unitext.UnitextStyledFragment para = null;
                if (sfrag != null) {
                    para = com.pullenti.unitext.UnitextStyledFragment._new506(sfrag, com.pullenti.unitext.UnitextStyledFragmentType.PARAGRAPH);
                    sfrag.children.add(para);
                }
                com.pullenti.unitext.UnitextStyle defParaStyle = null;
                if (m_Styles.defStyles.containsKey("paragraph")) {
                    defParaStyle = m_Styles.registerStyle(m_Styles.defStyles.get("paragraph"));
                    if (para != null) 
                        para.setStyle(defParaStyle);
                }
                com.pullenti.unitext.internal.uni.UnitextGen pgen = new com.pullenti.unitext.internal.uni.UnitextGen();
                pgen.setStyle(para);
                pgen.appendPagesection(m_CurSection);
                boolean hidden = false;
                com.pullenti.unitext.UnitextStyle numExStyle = null;
                for (org.w3c.dom.Node xx : (new com.pullenti.unisharp.XmlNodeListWrapper(child.getChildNodes())).arr) {
                    if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(xx), "pPr")) {
                        if (para != null) {
                            com.pullenti.unitext.UnitextStyle ust0 = new com.pullenti.unitext.UnitextStyle();
                            if (defParaStyle != null) 
                                defParaStyle.copyTo(ust0);
                            m_Styles.readUnitextStyle(xx, ust0, false);
                            ust0.removeInheritAttrs(para.parent);
                            if (com.pullenti.unisharp.Utils.stringsEq(ust0.getAttr("font-size"), "1pt")) {
                                hidden = true;
                                if (sfrag != null) 
                                    sfrag.children.remove(sfrag);
                                break;
                            }
                            para.setStyle(m_Styles.registerStyle(ust0));
                        }
                        String id = null;
                        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), "numPr")) {
                                for (org.w3c.dom.Node chh : (new com.pullenti.unisharp.XmlNodeListWrapper(xxx.getChildNodes())).arr) {
                                    if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(chh), "numId") && chh.getAttributes() != null && chh.getAttributes().getLength() == 1) 
                                        id = chh.getAttributes().item(0).getNodeValue();
                                    else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(chh), "ilvl") && chh.getAttributes() != null && chh.getAttributes().getLength() == 1) {
                                        com.pullenti.unisharp.Outargwrapper<Integer> wraplev507 = new com.pullenti.unisharp.Outargwrapper<Integer>();
                                        com.pullenti.unisharp.Utils.parseInteger((String)com.pullenti.unisharp.Utils.notnull(chh.getAttributes().item(0).getNodeValue(), ""), 0, null, wraplev507);
                                        lev = (wraplev507.value != null ? wraplev507.value : 0);
                                    }
                                }
                            }
                            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(xxx), "listPr")) {
                                numStyle = DocNumStyles.readNumberStyle(xxx);
                                lev = numStyle.getLvl();
                            }
                            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(xxx), "pStyle")) {
                                numTxtStyle = m_Styles.getStyle(xxx, "val");
                                if (numTxtStyle != null && numTxtStyle.numId != null) {
                                    if (id != null || lev > 0) {
                                    }
                                    else {
                                        id = numTxtStyle.numId;
                                        lev = numTxtStyle.numLvl;
                                    }
                                }
                            }
                            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(xxx), "pageBreakBefore")) 
                                pgen.appendPagebreak();
                            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(xxx), "rPr")) {
                                numExStyle = new com.pullenti.unitext.UnitextStyle();
                                m_Styles.readUnitextStyle(xxx, numExStyle, false);
                            }
                        }
                        numStyle = m_NumStyles.getStyle(id);
                    }
                }
                if (hidden) 
                    break;
                gen.appendPagesection(m_CurSection);
                stackNodes.add(child);
                this.readNode(stackNodes, pgen, para, pictTop);
                pgen.textGenRegime = false;
                if (pictTop < 0) 
                    pgen.appendNewline(false, false);
                com.pullenti.unitext.UnitextItem fi = pgen.finish(false, null);
                if (fi != null) {
                    if ((numStyle != null && numExStyle != null && para != null) && para.getStyle() != null) {
                        com.pullenti.unitext.UnitextStyledFragment npara = com.pullenti.unitext.UnitextStyledFragment._new506(para, com.pullenti.unitext.UnitextStyledFragmentType.INLINE);
                        numExStyle.removeInheritAttrs(para);
                        npara.setStyle(m_Styles.registerStyle(numExStyle));
                        para.children.add(npara);
                        gen.setNumStyle(npara);
                    }
                    gen.append(fi, numStyle, lev, false);
                    gen.setNumStyle(null);
                }
                stackNodes.remove(stackNodes.size() - 1);
                break;
            case "r":
                if (child.getAttributes() != null) {
                    for (org.w3c.dom.Node a : (new com.pullenti.unisharp.XmlAttrListWrapper(child.getAttributes())).arr) {
                        if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "rsidRPr")) {
                            if (!com.pullenti.unisharp.Utils.isNullOrEmpty(m_lastRSID) && com.pullenti.unisharp.Utils.stringsCompare(a.getNodeValue(), m_lastRSID, true) != 0) {
                                m_lastRSID = com.pullenti.unisharp.Utils.getXmlLocalName(a);
                                if (((int)gen.lastChar) != 0 && !com.pullenti.unisharp.Utils.isWhitespace(gen.lastChar)) 
                                    gen.appendText(" ", false);
                            }
                        }
                    }
                }
                com.pullenti.unitext.UnitextStyle ust = null;
                int isSup = -1;
                boolean fldCharBegin = false;
                boolean hidden2 = false;
                boolean gtr = gen.textGenRegime;
                for (org.w3c.dom.Node rpr : (new com.pullenti.unisharp.XmlNodeListWrapper(child.getChildNodes())).arr) {
                    if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(rpr), "rPr")) {
                        ust = new com.pullenti.unitext.UnitextStyle();
                        m_Styles.readUnitextStyle(rpr, ust, false);
                        if (sfrag != null) 
                            ust.removeInheritAttrs(sfrag);
                        if (com.pullenti.unisharp.Utils.stringsEq(ust.getAttr("font-size"), "1pt")) {
                            hidden2 = true;
                            break;
                        }
                        ust = m_Styles.registerStyle(ust);
                        for (org.w3c.dom.Node xxx : (new com.pullenti.unisharp.XmlNodeListWrapper(rpr.getChildNodes())).arr) {
                            if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(xxx), "vertAlign") && xxx.getAttributes() != null && xxx.getAttributes().getLength() > 0) {
                                if (com.pullenti.unisharp.Utils.stringsEq(xxx.getAttributes().item(0).getNodeValue(), "superscript")) 
                                    isSup = 1;
                                else if (com.pullenti.unisharp.Utils.stringsEq(xxx.getAttributes().item(0).getNodeValue(), "subscript")) 
                                    isSup = 0;
                            }
                        }
                    }
                    else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(rpr), "fldChar")) {
                        for (org.w3c.dom.Node aa : (new com.pullenti.unisharp.XmlAttrListWrapper(rpr.getAttributes())).arr) {
                            if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(aa), "fldCharType") && com.pullenti.unisharp.Utils.stringsEq(aa.getNodeValue(), "begin")) 
                                fldCharBegin = true;
                        }
                    }
                }
                if (hidden2) 
                    break;
                if (fldCharBegin) {
                    com.pullenti.unitext.internal.uni.UnitextGen gg1 = new com.pullenti.unitext.internal.uni.UnitextGen();
                    String anchor = null;
                    gg1.appendPagesection(m_CurSection);
                    int ii = -1;
                    StringBuilder instrText = null;
                    for (int j = i; j < node.getChildNodes().getLength(); j++) {
                        org.w3c.dom.Node chh = node.getChildNodes().item(j);
                        if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(chh), "bookmarkStart")) {
                            for (org.w3c.dom.Node a : (new com.pullenti.unisharp.XmlAttrListWrapper(chh.getAttributes())).arr) {
                                if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "name")) {
                                    if (com.pullenti.unisharp.Utils.stringsEq(a.getNodeValue(), "_GoBack")) 
                                        continue;
                                    com.pullenti.unitext.UnitextMisc mi = new com.pullenti.unitext.UnitextMisc();
                                    mi.typ = com.pullenti.unitext.UnitextMiscType.ANCHOR;
                                    mi.id = a.getNodeValue();
                                    gen.append(mi, null, -1, false);
                                    break;
                                }
                            }
                            continue;
                        }
                        if (com.pullenti.unisharp.Utils.stringsNe(com.pullenti.unisharp.Utils.getXmlLocalName(chh), "r")) 
                            continue;
                        for (org.w3c.dom.Node rpr : (new com.pullenti.unisharp.XmlNodeListWrapper(chh.getChildNodes())).arr) {
                            if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(rpr), "instrText") || com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(rpr), "instr")) {
                                if (instrText == null) 
                                    instrText = new StringBuilder();
                                instrText.append((String)com.pullenti.unisharp.Utils.notnull(rpr.getTextContent(), ""));
                            }
                            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(rpr), "fldChar")) {
                                for (org.w3c.dom.Node aa : (new com.pullenti.unisharp.XmlAttrListWrapper(rpr.getAttributes())).arr) {
                                    if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(aa), "fldCharType") && com.pullenti.unisharp.Utils.stringsEq(aa.getNodeValue(), "end")) 
                                        fldCharBegin = false;
                                }
                            }
                        }
                        stackNodes.add(chh);
                        this.readNode(stackNodes, gg1, sfrag, pictTop);
                        stackNodes.remove(stackNodes.size() - 1);
                        ii = j;
                        if (!fldCharBegin) 
                            break;
                    }
                    if (instrText != null) {
                        String vvv = instrText.toString().trim();
                        if (vvv.startsWith("SEQ ")) 
                            gg1.textGenRegime = true;
                        int iii = vvv.indexOf("REF ");
                        if (iii >= 0 && !(vvv.indexOf("STYLEREF") >= 0)) {
                            vvv = vvv.substring(iii + 4);
                            for (int k = 1; k < vvv.length(); k++) {
                                if (com.pullenti.unisharp.Utils.isWhitespace(vvv.charAt(k))) {
                                    vvv = vvv.substring(0, 0 + k);
                                    break;
                                }
                            }
                            anchor = vvv;
                        }
                    }
                    if (anchor != null) {
                        com.pullenti.unitext.UnitextHyperlink hy = com.pullenti.unitext.UnitextHyperlink._new509(true, anchor);
                        hy.content = gg1.finish(false, null);
                        gen.append(hy, null, -1, false);
                        i = ii;
                        break;
                    }
                    if (gg1.textGenRegime) {
                        com.pullenti.unitext.UnitextItem tmp = gg1.finish(true, null);
                        if (tmp != null) {
                            gen.append(tmp, null, -1, false);
                            i = ii;
                            break;
                        }
                        else 
                            gen.textGenRegime = true;
                    }
                }
                if (isSup >= 0) {
                    com.pullenti.unitext.internal.uni.UnitextGen gg1 = new com.pullenti.unitext.internal.uni.UnitextGen();
                    gg1.appendPagesection(m_CurSection);
                    stackNodes.add(child);
                    this.readNode(stackNodes, gg1, sfrag, pictTop);
                    stackNodes.remove(stackNodes.size() - 1);
                    com.pullenti.unitext.UnitextItem tmp = gg1.finish(true, null);
                    if (tmp == null) 
                        break;
                    String tt = com.pullenti.unitext.internal.uni.UnitextHelper.getPlaintext(tmp, null);
                    if (tt == null) 
                        tt = "";
                    tt = tt.trim();
                    if (tt.startsWith("<") && tt.endsWith(">")) 
                        tt = tt.substring(1, 1 + tt.length() - 2);
                    if (tt.length() > 0 && (tt.length() < 10)) {
                        com.pullenti.unitext.UnitextPlaintext tp = com.pullenti.unitext.UnitextPlaintext._new58(tt, (isSup == 0 ? com.pullenti.unitext.UnitextPlaintextType.SUB : com.pullenti.unitext.UnitextPlaintextType.SUP));
                        gen.append(tp, null, -1, false);
                        break;
                    }
                }
                stackNodes.add(child);
                if (ust == null || sfrag == null) 
                    this.readNode(stackNodes, gen, sfrag, pictTop);
                else {
                    com.pullenti.unitext.UnitextStyledFragment ifr = com.pullenti.unitext.UnitextStyledFragment._new506(sfrag, com.pullenti.unitext.UnitextStyledFragmentType.INLINE);
                    ifr.setStyle(ust);
                    com.pullenti.unitext.internal.uni.UnitextGen gg1 = new com.pullenti.unitext.internal.uni.UnitextGen();
                    gg1.setStyle(ifr);
                    gg1.appendPagesection(m_CurSection);
                    gg1.textGenRegime = gen.textGenRegime;
                    this.readNode(stackNodes, gg1, ifr, pictTop);
                    com.pullenti.unitext.UnitextItem v = gg1.finish(false, null);
                    if (v != null) {
                        gen.append(v, null, -1, false);
                        sfrag.children.add(ifr);
                        gen.textGenRegime = false;
                    }
                }
                stackNodes.remove(stackNodes.size() - 1);
                break;
            case "footnoteReference":
                delText = null;
                if (child.getAttributes() == null) 
                    break;
                for (org.w3c.dom.Node a : (new com.pullenti.unisharp.XmlAttrListWrapper(child.getAttributes())).arr) {
                    if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "customMarkFollows") && com.pullenti.unisharp.Utils.stringsEq(a.getNodeValue(), "1") && ((i + 1) < node.getChildNodes().getLength())) {
                        org.w3c.dom.Node ch1 = node.getChildNodes().item(i + 1);
                        if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(ch1), "t")) {
                            delText = ch1.getTextContent();
                            i++;
                            break;
                        }
                    }
                }
                for (org.w3c.dom.Node a : (new com.pullenti.unisharp.XmlAttrListWrapper(child.getAttributes())).arr) {
                    if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "id") && m_Footnotes.containsKey(a.getNodeValue())) {
                        com.pullenti.unitext.UnitextItem cnt = m_Footnotes.get(a.getNodeValue());
                        if (!com.pullenti.unisharp.Utils.isNullOrEmpty(delText)) {
                            com.pullenti.unitext.UnitextPlaintext pl = (com.pullenti.unitext.UnitextPlaintext)com.pullenti.unisharp.Utils.cast(cnt, com.pullenti.unitext.UnitextPlaintext.class);
                            if (pl != null && pl.text.startsWith(delText)) 
                                pl.text = pl.text.substring(delText.length()).trim();
                        }
                        if ((cnt.m_StyledFrag != null && cnt.m_StyledFrag.parent == null && (cnt instanceof com.pullenti.unitext.UnitextContainer)) && sfrag != null) {
                            com.pullenti.unitext.UnitextContainer cc = (com.pullenti.unitext.UnitextContainer)com.pullenti.unisharp.Utils.cast(cnt, com.pullenti.unitext.UnitextContainer.class);
                            if (cc.children.size() == 1 && (cc.children.get(0) instanceof com.pullenti.unitext.UnitextContainer)) {
                                cnt = cc.children.get(0);
                                if (cnt.m_StyledFrag != null && cnt.m_StyledFrag.parent != null) {
                                    cnt.m_StyledFrag.typ = com.pullenti.unitext.UnitextStyledFragmentType.FOOTNOTE;
                                    cnt.m_StyledFrag.parent.children.remove(cnt.m_StyledFrag);
                                    sfrag.children.add(cnt.m_StyledFrag);
                                    cnt.m_StyledFrag.parent = sfrag;
                                }
                            }
                        }
                        gen.append(com.pullenti.unitext.UnitextFootnote._new330(cnt, delText), null, -1, false);
                        break;
                    }
                }
                break;
            case "endnoteReference":
                if (child.getAttributes() != null) {
                    for (org.w3c.dom.Node a : (new com.pullenti.unisharp.XmlAttrListWrapper(child.getAttributes())).arr) {
                        if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "id") && m_Footnotes.containsKey("end" + a.getNodeValue())) {
                            com.pullenti.unitext.UnitextItem cnt = m_Footnotes.get("end" + a.getNodeValue());
                            if ((cnt.m_StyledFrag != null && cnt.m_StyledFrag.parent == null && (cnt instanceof com.pullenti.unitext.UnitextContainer)) && sfrag != null) {
                                com.pullenti.unitext.UnitextContainer cc = (com.pullenti.unitext.UnitextContainer)com.pullenti.unisharp.Utils.cast(cnt, com.pullenti.unitext.UnitextContainer.class);
                                if (cc.children.size() == 1 && (cc.children.get(0) instanceof com.pullenti.unitext.UnitextContainer)) {
                                    cnt = cc.children.get(0);
                                    if (cnt.m_StyledFrag != null && cnt.m_StyledFrag.parent != null) {
                                        cnt.m_StyledFrag.typ = com.pullenti.unitext.UnitextStyledFragmentType.FOOTNOTE;
                                        cnt.m_StyledFrag.parent.children.remove(cnt.m_StyledFrag);
                                        sfrag.children.add(cnt.m_StyledFrag);
                                        cnt.m_StyledFrag.parent = sfrag;
                                    }
                                }
                            }
                            gen.append(com.pullenti.unitext.UnitextFootnote._new285(cnt, true), null, -1, false);
                            break;
                        }
                    }
                }
                break;
            case "footnote":
            case "endnote":
                com.pullenti.unitext.internal.uni.UnitextGen gg2 = new com.pullenti.unitext.internal.uni.UnitextGen();
                gg2.appendPagesection(m_CurSection);
                stackNodes.add(child);
                this.readNode(stackNodes, gg2, sfrag, pictTop);
                stackNodes.remove(stackNodes.size() - 1);
                com.pullenti.unitext.UnitextItem tmp2 = gg2.finish(true, null);
                if (tmp2 == null) 
                    break;
                com.pullenti.unitext.UnitextFootnote fn = com.pullenti.unitext.UnitextFootnote._new514(com.pullenti.unisharp.Utils.stringsEq(locname, "endnote"), tmp2);
                gen.append(fn, null, -1, false);
                break;
            case "blip":
                if (child.getAttributes() != null) {
                    for (org.w3c.dom.Node a : (new com.pullenti.unisharp.XmlAttrListWrapper(child.getAttributes())).arr) {
                        if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "embed")) {
                            com.pullenti.unitext.UnitextImage img = com.pullenti.unitext.UnitextImage._new96(a.getNodeValue());
                            gen.append(img, null, -1, false);
                            for (int ii = stackNodes.size() - 1; ii >= 0; ii--) {
                                for (org.w3c.dom.Node xxx : (new com.pullenti.unisharp.XmlNodeListWrapper(stackNodes.get(ii).getChildNodes())).arr) {
                                    if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(xxx), "extent") && xxx.getAttributes() != null) {
                                        int xw = 0;
                                        int yh = 0;
                                        for (org.w3c.dom.Node aa : (new com.pullenti.unisharp.XmlAttrListWrapper(xxx.getAttributes())).arr) {
                                            if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(aa), "cx")) {
                                                com.pullenti.unisharp.Outargwrapper<Integer> wrapxw516 = new com.pullenti.unisharp.Outargwrapper<Integer>();
                                                com.pullenti.unisharp.Utils.parseInteger(aa.getNodeValue(), 0, null, wrapxw516);
                                                xw = (wrapxw516.value != null ? wrapxw516.value : 0);
                                            }
                                            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(aa), "cy")) {
                                                com.pullenti.unisharp.Outargwrapper<Integer> wrapyh517 = new com.pullenti.unisharp.Outargwrapper<Integer>();
                                                com.pullenti.unisharp.Utils.parseInteger(aa.getNodeValue(), 0, null, wrapyh517);
                                                yh = (wrapyh517.value != null ? wrapyh517.value : 0);
                                            }
                                        }
                                        if (xw > 0 && yh > 0) {
                                            img.width = ((((Integer)((xw * 72) / 914400)).toString()) + "pt");
                                            img.height = ((((Integer)((yh * 72) / 914400)).toString()) + "pt");
                                        }
                                    }
                                }
                            }
                            break;
                        }
                    }
                }
                break;
            case "imagedata":
                if (child.getAttributes() != null) {
                    for (org.w3c.dom.Node a : (new com.pullenti.unisharp.XmlAttrListWrapper(child.getAttributes())).arr) {
                        if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "id")) {
                            com.pullenti.unitext.UnitextImage img = com.pullenti.unitext.UnitextImage._new96(a.getNodeValue());
                            gen.append(img, null, -1, false);
                            if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(node), "shape") && node.getAttributes() != null) {
                                for (org.w3c.dom.Node aa : (new com.pullenti.unisharp.XmlAttrListWrapper(node.getAttributes())).arr) {
                                    if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(aa), "style")) {
                                        _setImageSize(img, aa.getNodeValue());
                                        break;
                                    }
                                }
                            }
                            break;
                        }
                    }
                }
                break;
            case "OLEObject":
                if (child.getAttributes() != null) {
                    for (org.w3c.dom.Node a : (new com.pullenti.unisharp.XmlAttrListWrapper(child.getAttributes())).arr) {
                        if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "id")) {
                            if (m_Embeds.containsKey(a.getNodeValue())) {
                                gen.append(m_Embeds.get(a.getNodeValue()), null, -1, false);
                                break;
                            }
                        }
                    }
                }
                break;
            case "sdt":
                String tag = null;
                String valu = null;
                com.pullenti.unitext.UnitextStyle ust1 = null;
                for (org.w3c.dom.Node x : (new com.pullenti.unisharp.XmlNodeListWrapper(child.getChildNodes())).arr) {
                    if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "sdtPr")) {
                        for (org.w3c.dom.Node xx : (new com.pullenti.unisharp.XmlNodeListWrapper(x.getChildNodes())).arr) {
                            if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(xx), "tag")) 
                                tag = _getAttrValue(xx, "val");
                            else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(xx), "date")) 
                                valu = _getAttrValue(xx, "fullDate");
                        }
                        ust1 = new com.pullenti.unitext.UnitextStyle();
                        m_Styles.readUnitextStyle(x, ust1, false);
                        if (sfrag != null) 
                            ust1.removeInheritAttrs(sfrag);
                        ust1 = m_Styles.registerStyle(ust1);
                    }
                }
                for (org.w3c.dom.Node x : (new com.pullenti.unisharp.XmlNodeListWrapper(child.getChildNodes())).arr) {
                    if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "sdtContent")) {
                        com.pullenti.unitext.UnitextStyledFragment sfrag1 = sfrag;
                        if (ust1 != null) {
                            sfrag1 = com.pullenti.unitext.UnitextStyledFragment._new519(com.pullenti.unitext.UnitextStyledFragmentType.INLINE, ust1, sfrag1);
                            sfrag.children.add(sfrag1);
                        }
                        com.pullenti.unitext.internal.uni.UnitextGen gg3 = new com.pullenti.unitext.internal.uni.UnitextGen();
                        gg3.setStyle(sfrag1);
                        gg3.appendPagesection(m_CurSection);
                        stackNodes.add(x);
                        this.readNode(stackNodes, gg3, sfrag1, pictTop);
                        stackNodes.remove(stackNodes.size() - 1);
                        com.pullenti.unitext.UnitextItem tmp3 = gg3.finish(true, null);
                        if (tmp3 == null) 
                            break;
                        if (valu == null) 
                            valu = com.pullenti.unitext.internal.uni.UnitextHelper.getPlaintext(tmp3, null);
                        if (tmp3 instanceof com.pullenti.unitext.UnitextContainer) 
                            ((com.pullenti.unitext.UnitextContainer)com.pullenti.unisharp.Utils.cast(tmp3, com.pullenti.unitext.UnitextContainer.class)).typ = com.pullenti.unitext.UnitextContainerType.CONTENTCONTROL;
                        else {
                            com.pullenti.unitext.UnitextContainer ccc = com.pullenti.unitext.UnitextContainer._new452(com.pullenti.unitext.UnitextContainerType.CONTENTCONTROL, sfrag1);
                            ccc.children.add(tmp3);
                            tmp3.parent = ccc;
                            tmp3 = ccc;
                        }
                        tmp3.htmlTitle = ("Content control: " + ((tag != null ? tag : "?")));
                        ((com.pullenti.unitext.UnitextContainer)com.pullenti.unisharp.Utils.cast(tmp3, com.pullenti.unitext.UnitextContainer.class)).data = valu;
                        tmp3.id = tag;
                        gen.append(tmp3, null, -1, false);
                    }
                }
                if (tag != null && valu != null) {
                    if (!m_DataControls.containsKey(tag)) 
                        m_DataControls.put(tag, valu);
                }
                break;
            case "ffData":
                String nam1 = null;
                for (org.w3c.dom.Node x : (new com.pullenti.unisharp.XmlNodeListWrapper(child.getChildNodes())).arr) {
                    if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "name")) 
                        nam1 = _getAttrValue(x, "val");
                    else if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(x), "textInput")) {
                        for (org.w3c.dom.Node xx : (new com.pullenti.unisharp.XmlNodeListWrapper(x.getChildNodes())).arr) {
                            if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(xx), "default")) {
                                String val1 = _getAttrValue(xx, "val");
                                if (val1 != null && nam1 != null) {
                                    if (!m_DataControls.containsKey(nam1)) 
                                        m_DataControls.put(nam1, val1);
                                }
                            }
                        }
                    }
                }
                break;
            case "rect":
                for (org.w3c.dom.Node a : (new com.pullenti.unisharp.XmlAttrListWrapper(child.getAttributes())).arr) {
                    if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), "style")) {
                        if (pictTop < 0) 
                            pictTop = 0;
                        for (String s : com.pullenti.unisharp.Utils.split(a.getNodeValue(), String.valueOf(';'), false)) {
                            int ii = s.indexOf(':');
                            if (ii <= 0) 
                                continue;
                            String key = s.substring(0, 0 + ii).trim().toLowerCase();
                            String va = s.substring(ii + 1).trim();
                            if (com.pullenti.unisharp.Utils.stringsEq(key, "position")) {
                                if (com.pullenti.unisharp.Utils.stringsNe(va, "absolute")) 
                                    break;
                            }
                            if (com.pullenti.unisharp.Utils.stringsNe(key, "top")) 
                                continue;
                            for (int j = va.length() - 1; j > 0; j--) {
                                if (Character.isDigit(va.charAt(j))) {
                                    com.pullenti.unisharp.Outargwrapper<Integer> wrapii521 = new com.pullenti.unisharp.Outargwrapper<Integer>();
                                    boolean inoutres522 = com.pullenti.unisharp.Utils.parseInteger(va.substring(0, 0 + j + 1), 0, null, wrapii521);
                                    ii = (wrapii521.value != null ? wrapii521.value : 0);
                                    if (!inoutres522) 
                                        break;
                                    if (ii > pictTop) {
                                        gen.appendNewline(true, false);
                                        pictTop = ii;
                                    }
                                    break;
                                }
                            }
                            break;
                        }
                    }
                }
                stackNodes.add(child);
                this.readNode(stackNodes, gen, sfrag, pictTop);
                stackNodes.remove(stackNodes.size() - 1);
                break;
            case "drawing":
                com.pullenti.unitext.internal.uni.UnitextGen gg4 = new com.pullenti.unitext.internal.uni.UnitextGen();
                gg4.setStyle(sfrag);
                gg4.appendPagesection(m_CurSection);
                stackNodes.add(child);
                this.readNode(stackNodes, gg4, sfrag, pictTop);
                stackNodes.remove(stackNodes.size() - 1);
                com.pullenti.unitext.UnitextContainer drsh = com.pullenti.unitext.UnitextContainer._new452(com.pullenti.unitext.UnitextContainerType.SHAPE, sfrag);
                com.pullenti.unitext.UnitextItem tgg4 = gg4.finish(false, null);
                if (tgg4 != null) 
                    drsh.children.add(tgg4);
                gen.append(drsh, null, -1, false);
                break;
            case "oMath":
                if (setFormulasAsImage) {
                    gen.append(new com.pullenti.unitext.UnitextImage(), null, -1, false);
                    break;
                }
                com.pullenti.unitext.internal.uni.UnitextGen gg5 = new com.pullenti.unitext.internal.uni.UnitextGen();
                gg5.setStyle(sfrag);
                gg5.appendPagesection(m_CurSection);
                stackNodes.add(child);
                this.readNode(stackNodes, gg5, sfrag, pictTop);
                stackNodes.remove(stackNodes.size() - 1);
                com.pullenti.unitext.UnitextContainer drsh5 = com.pullenti.unitext.UnitextContainer._new452(com.pullenti.unitext.UnitextContainerType.FORMULA, sfrag);
                int nary = _calcNary(child);
                if (nary > 0) 
                    drsh5.data = ((Integer)nary).toString();
                com.pullenti.unitext.UnitextItem tgg5 = gg5.finish(false, null);
                if (tgg5 != null) {
                    java.util.ArrayList<com.pullenti.unitext.UnitextItem> its = new java.util.ArrayList<com.pullenti.unitext.UnitextItem>();
                    tgg5.getAllItems(its, 0);
                    for (com.pullenti.unitext.UnitextItem ii : its) {
                        if ((ii instanceof com.pullenti.unitext.UnitextNewline) || (ii instanceof com.pullenti.unitext.UnitextPagebreak)) 
                            tgg5.replaceChild(ii, com.pullenti.unitext.UnitextPlaintext._new57(" "));
                    }
                    drsh5.children.add(tgg5);
                }
                gen.append(drsh5, null, -1, false);
                break;
            default: 
                if ((pictTop < 0) && com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(child), "txbxContent")) 
                    gen.appendText(" ", false);
                stackNodes.add(child);
                this.readNode(stackNodes, gen, sfrag, pictTop);
                stackNodes.remove(stackNodes.size() - 1);
                if ((pictTop < 0) && com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(child), "txbxContent")) 
                    gen.appendText(" ", false);
                break;
        }
        }
    }

    private static int _calcNary(org.w3c.dom.Node xml) {
        int res = 0;
        if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(xml), "nary")) 
            res++;
        for (org.w3c.dom.Node xx : (new com.pullenti.unisharp.XmlNodeListWrapper(xml.getChildNodes())).arr) {
            res += _calcNary(xx);
        }
        return res;
    }

    private static void _setImageSize(com.pullenti.unitext.UnitextImage img, String style) {
        int ii = style.indexOf("width:");
        if (ii >= 0) {
            img.width = style.substring(ii + 6).trim();
            if ((((ii = img.width.indexOf(';')))) > 0) 
                img.width = img.width.substring(0, 0 + ii).trim();
        }
        ii = style.indexOf("height:");
        if (ii >= 0) {
            img.height = style.substring(ii + 7).trim();
            if ((((ii = img.height.indexOf(';')))) > 0) 
                img.height = img.height.substring(0, 0 + ii).trim();
        }
    }

    private static String _getAttrValue(org.w3c.dom.Node n, String attrName) {
        if (n.getAttributes() != null) {
            for (org.w3c.dom.Node a : (new com.pullenti.unisharp.XmlAttrListWrapper(n.getAttributes())).arr) {
                if (com.pullenti.unisharp.Utils.stringsEq(com.pullenti.unisharp.Utils.getXmlLocalName(a), attrName)) 
                    return a.getNodeValue();
            }
        }
        return null;
    }
    public DocxToText() {
    }
}
