/*
 * 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;

/**
 * Разные нетекстовые элементы
 */
public class UnitextMisc extends UnitextItem {

    /**
     * Тип нетекстового элемента
     */
    public UnitextMiscType typ = UnitextMiscType.UNDEFINED;

    @Override
    public String toString() {
        if (typ == UnitextMiscType.ANCHOR) 
            return (typ.toString() + ": " + ((id != null ? id : "")));
        return typ.toString();
    }

    @Override
    public String getInnerTag() {
        return "misc";
    }


    @Override
    public UnitextItem clone() {
        UnitextMisc res = new UnitextMisc();
        res._cloneFrom(this);
        res.typ = typ;
        return res;
    }

    @Override
    public void getPlaintext(StringBuilder res, GetPlaintextParam pars) {
        if (pars != null && pars.setPositions) 
            beginChar = (endChar = res.length());
    }

    @Override
    public void getHtml(StringBuilder res, GetHtmlParam par) {
        if (!par.callBefore(this, res)) 
            return;
        if (id != null) 
            res.append("<a name=\"").append(id).append("\"> </a>");
        if (typ == UnitextMiscType.HORIZONTALLINE) 
            res.append("\r\n<HR/>");
        par.callAfter(this, res);
    }

    @Override
    public void getXml(com.pullenti.unisharp.XmlWriterWrapper xml) throws javax.xml.stream.XMLStreamException {
        xml.wr.writeStartElement("misc");
        this._writeXmlAttrs(xml);
        xml.wr.writeAttribute("type", typ.toString().toLowerCase());
        xml.wr.writeEndElement();
    }

    @Override
    public void fromXml(org.w3c.dom.Node xml) throws NumberFormatException {
        super.fromXml(xml);
        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), "type")) {
                    try {
                        typ = (UnitextMiscType)UnitextMiscType.of(a.getNodeValue());
                    } catch (Exception ex616) {
                    }
                }
            }
        }
    }

    @Override
    public boolean isWhitespaces() {
        return false;
    }


    public static UnitextMisc _new287(UnitextMiscType _arg1) {
        UnitextMisc res = new UnitextMisc();
        res.typ = _arg1;
        return res;
    }
    public UnitextMisc() {
        super();
    }
}
