All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.mixer2.xhtml.util.RemoveByIdUtil Maven / Gradle / Ivy

The newest version!
package org.mixer2.xhtml.util;

import java.util.List;

import org.mixer2.jaxb.xhtml.A;
import org.mixer2.jaxb.xhtml.Abbr;
import org.mixer2.jaxb.xhtml.Acronym;
import org.mixer2.jaxb.xhtml.Address;
import org.mixer2.jaxb.xhtml.Applet;
import org.mixer2.jaxb.xhtml.Area;
import org.mixer2.jaxb.xhtml.Article;
import org.mixer2.jaxb.xhtml.Aside;
import org.mixer2.jaxb.xhtml.Audio;
import org.mixer2.jaxb.xhtml.B;
import org.mixer2.jaxb.xhtml.Bdi;
import org.mixer2.jaxb.xhtml.Bdo;
import org.mixer2.jaxb.xhtml.Big;
import org.mixer2.jaxb.xhtml.Blockquote;
import org.mixer2.jaxb.xhtml.Body;
import org.mixer2.jaxb.xhtml.Button;
import org.mixer2.jaxb.xhtml.Canvas;
import org.mixer2.jaxb.xhtml.Caption;
import org.mixer2.jaxb.xhtml.Center;
import org.mixer2.jaxb.xhtml.Cite;
import org.mixer2.jaxb.xhtml.Code;
import org.mixer2.jaxb.xhtml.Col;
import org.mixer2.jaxb.xhtml.Colgroup;
import org.mixer2.jaxb.xhtml.Datalist;
import org.mixer2.jaxb.xhtml.Dd;
import org.mixer2.jaxb.xhtml.Del;
import org.mixer2.jaxb.xhtml.Details;
import org.mixer2.jaxb.xhtml.Dfn;
import org.mixer2.jaxb.xhtml.Dir;
import org.mixer2.jaxb.xhtml.Div;
import org.mixer2.jaxb.xhtml.Dl;
import org.mixer2.jaxb.xhtml.Dt;
import org.mixer2.jaxb.xhtml.Em;
import org.mixer2.jaxb.xhtml.Fieldset;
import org.mixer2.jaxb.xhtml.Figcaption;
import org.mixer2.jaxb.xhtml.Figure;
import org.mixer2.jaxb.xhtml.Font;
import org.mixer2.jaxb.xhtml.Footer;
import org.mixer2.jaxb.xhtml.Form;
import org.mixer2.jaxb.xhtml.H1;
import org.mixer2.jaxb.xhtml.H2;
import org.mixer2.jaxb.xhtml.H3;
import org.mixer2.jaxb.xhtml.H4;
import org.mixer2.jaxb.xhtml.H5;
import org.mixer2.jaxb.xhtml.H6;
import org.mixer2.jaxb.xhtml.Head;
import org.mixer2.jaxb.xhtml.Header;
import org.mixer2.jaxb.xhtml.Hgroup;
import org.mixer2.jaxb.xhtml.Html;
import org.mixer2.jaxb.xhtml.I;
import org.mixer2.jaxb.xhtml.Iframe;
import org.mixer2.jaxb.xhtml.Ins;
import org.mixer2.jaxb.xhtml.Kbd;
import org.mixer2.jaxb.xhtml.Label;
import org.mixer2.jaxb.xhtml.Legend;
import org.mixer2.jaxb.xhtml.Li;
import org.mixer2.jaxb.xhtml.Map;
import org.mixer2.jaxb.xhtml.Mark;
import org.mixer2.jaxb.xhtml.Menu;
import org.mixer2.jaxb.xhtml.Meter;
import org.mixer2.jaxb.xhtml.Nav;
import org.mixer2.jaxb.xhtml.Noframes;
import org.mixer2.jaxb.xhtml.Noscript;
import org.mixer2.jaxb.xhtml.Ol;
import org.mixer2.jaxb.xhtml.Optgroup;
import org.mixer2.jaxb.xhtml.Option;
import org.mixer2.jaxb.xhtml.Output;
import org.mixer2.jaxb.xhtml.P;
import org.mixer2.jaxb.xhtml.Pre;
import org.mixer2.jaxb.xhtml.Progress;
import org.mixer2.jaxb.xhtml.Q;
import org.mixer2.jaxb.xhtml.Rp;
import org.mixer2.jaxb.xhtml.Rt;
import org.mixer2.jaxb.xhtml.Ruby;
import org.mixer2.jaxb.xhtml.S;
import org.mixer2.jaxb.xhtml.Samp;
import org.mixer2.jaxb.xhtml.Section;
import org.mixer2.jaxb.xhtml.Select;
import org.mixer2.jaxb.xhtml.Small;
import org.mixer2.jaxb.xhtml.Span;
import org.mixer2.jaxb.xhtml.Strike;
import org.mixer2.jaxb.xhtml.Strong;
import org.mixer2.jaxb.xhtml.Sub;
import org.mixer2.jaxb.xhtml.Summary;
import org.mixer2.jaxb.xhtml.Sup;
import org.mixer2.jaxb.xhtml.Table;
import org.mixer2.jaxb.xhtml.Tbody;
import org.mixer2.jaxb.xhtml.Td;
import org.mixer2.jaxb.xhtml.Tfoot;
import org.mixer2.jaxb.xhtml.Th;
import org.mixer2.jaxb.xhtml.Thead;
import org.mixer2.jaxb.xhtml.Time;
import org.mixer2.jaxb.xhtml.Tr;
import org.mixer2.jaxb.xhtml.Tt;
import org.mixer2.jaxb.xhtml.U;
import org.mixer2.jaxb.xhtml.Ul;
import org.mixer2.jaxb.xhtml.Var;
import org.mixer2.jaxb.xhtml.Video;
import org.mixer2.xhtml.AbstractJaxb;
import org.mixer2.xhtml.TagEnum;

/**
 *
 * @see org.mixer2.xhtml.AbstractJaxb#removeById(String)
 * @author watanabe
 *
 */
public class RemoveByIdUtil {

    @SuppressWarnings("unchecked")
    private static  boolean removeByIdWithinObjectList(
            String id, List list) {

        java.lang.Object tmpobj;
        int size = list.size();
        for (int i = 0; i < size; i++) {
            tmpobj = list.get(i);
            if (tmpobj instanceof AbstractJaxb) {
                if (id.equals(((AbstractJaxb) tmpobj).getId())) {
                    list.remove(i);
                    return true;
                } else {
                    if (removeById(id, (T) tmpobj)) {
                        return true;
                    }
                }
            }
        }

        return false;
    }

    public static  boolean removeById(String id,
            T target) {
        TagEnum tagEnum = TagEnum.valueOf(target.getClass().getSimpleName()
                .toUpperCase());

        if (id.equals(target.getId())) {
            return false;
        }

        switch (tagEnum) {
        case A:
            A a = (A) target;
            if (a.isSetContent()) {
                return removeByIdWithinObjectList(id, a.getContent());
            }
            break;
        case ABBR:
            Abbr abbr = (Abbr) target;
            if (abbr.isSetContent()) {
                return removeByIdWithinObjectList(id, abbr.getContent());
            }
            break;
        case ACRONYM:
            Acronym acronym = (Acronym) target;
            if (acronym.isSetContent()) {
                return removeByIdWithinObjectList(id, acronym.getContent());
            }
            break;
        case ADDRESS:
            Address address = (Address) target;
            if (address.isSetContent()) {
                return removeByIdWithinObjectList(id, address.getContent());
            }
            break;
        case APPLET:
            Applet applet = (Applet) target;
            if (applet.isSetContent()) {
                return removeByIdWithinObjectList(id, applet.getContent());
            }
            break;
        case AREA:
            // area is empty element.
            break;
        case B:
            B b = (B) target;
            if (b.isSetContent()) {
                return removeByIdWithinObjectList(id, b.getContent());
            }
            break;
        case BASE:
            // empty element.
            break;
        case BASEFONT:
            // empty element.
            break;
        case BDO:
            Bdo bdo = (Bdo) target;
            if (bdo.isSetContent()) {
                return removeByIdWithinObjectList(id, bdo.getContent());
            }
            break;
        case BIG:
            Big big = (Big) target;
            if (big.isSetContent()) {
                return removeByIdWithinObjectList(id, big.getContent());
            }
            break;
        case BLOCKQUOTE:
            Blockquote blockquote = (Blockquote) target;
            if (blockquote.isSetContent()) {
                return removeByIdWithinObjectList(id, blockquote.getContent());
            }
            break;
        case BODY:
            Body body = (Body) target;
            if (body.isSetContent()) {
                return removeByIdWithinObjectList(id, body.getContent());
            }
            break;
        case BR:
            // empty element.
            break;
        case BUTTON:
            Button button = (Button) target;
            if (button.isSetContent()) {
                return removeByIdWithinObjectList(id, button.getContent());
            }
            break;
        case CAPTION:
            Caption caption = (Caption) target;
            if (caption.isSetContent()) {
                return removeByIdWithinObjectList(id, caption.getContent());
            }
            break;
        case CENTER:
            Center center = (Center) target;
            if (center.isSetContent()) {
                return removeByIdWithinObjectList(id, center.getContent());
            }
            break;
        case CITE:
            Cite cite = (Cite) target;
            if (cite.isSetContent()) {
                return removeByIdWithinObjectList(id, cite.getContent());
            }
            break;
        case CODE:
            Code code = (Code) target;
            if (code.isSetContent()) {
                return removeByIdWithinObjectList(id, code.getContent());
            }
            break;
        case COL:
            // empty element.
            break;
        case COLGROUP:
            Colgroup colgroup = (Colgroup) target;
            if (colgroup.isSetCol()) {
                for (int i = 0; i < colgroup.getCol().size(); i++) {
                    Col col1 = colgroup.getCol().get(i);
                    if (col1.isSetId() && col1.getId().equals(col1)) {
                        colgroup.getCol().remove(i);
                        return true;
                    }
                }
            }
            break;
        case DD:
            Dd dd = (Dd) target;
            if (dd.isSetContent()) {
                return removeByIdWithinObjectList(id, dd.getContent());
            }
            break;
        case DEL:
            Del del = (Del) target;
            if (del.isSetContent()) {
                return removeByIdWithinObjectList(id, del.getContent());
            }
            break;
        case DFN:
            Dfn dfn = (Dfn) target;
            if (dfn.isSetContent()) {
                return removeByIdWithinObjectList(id, dfn.getContent());
            }
            break;
        case DIR:
            Dir dir = (Dir) target;
            if (dir.isSetLi()) {
                for (int i = 0; i < dir.getLi().size(); i++) {
                    Li li = dir.getLi().get(i);
                    if (li.isSetId() && li.getId().equals(id)) {
                        dir.getLi().remove(i);
                        return true;
                    } else {
                        if (removeById(id, li)) {
                            return true;
                        }
                    }
                }
            }
            break;
        case DIV:
            Div div = (Div) target;
            if (div.isSetContent()) {
                return removeByIdWithinObjectList(id, div.getContent());
            }
            break;
        case DL:
            Dl dl = (Dl) target;
            if (dl.isSetDtOrDd()) {
                for (int i = 0; i < dl.getDtOrDd().size(); i++) {
                    AbstractJaxb obj = dl.getDtOrDd().get(i);
                    if (id.equals(obj.getId())) {
                        dl.getDtOrDd().remove(i);
                        return true;
                    } else {
                        if (removeById(id, obj)) {
                            return true;
                        }
                    }
                }
            }
            break;
        case DT:
            Dt dt = (Dt) target;
            if (dt.isSetContent()) {
                return removeByIdWithinObjectList(id, dt.getContent());
            }
            break;
        case EM:
            Em em = (Em) target;
            if (em.isSetId() && em.getId().equals(id)) {
                return false;
            }
            if (em.isSetContent()) {
                return removeByIdWithinObjectList(id, em.getContent());
            }
            break;
        case FIELDSET:
            Fieldset fieldset = (Fieldset) target;
            if (fieldset.isSetContent()) {
                return removeByIdWithinObjectList(id, fieldset.getContent());
            }
            break;
        case FONT:
            Font font = (Font) target;
            if (font.isSetContent()) {
                return removeByIdWithinObjectList(id, font.getContent());
            }
            break;
        case FORM:
            Form form = (Form) target;
            if (form.isSetContent()) {
                return removeByIdWithinObjectList(id, form.getContent());
            }
            break;
        case H1:
            H1 h1 = (H1) target;
            if (h1.isSetContent()) {
                return removeByIdWithinObjectList(id, h1.getContent());
            }
            break;
        case H2:
            H2 h2 = (H2) target;
            if (h2.isSetContent()) {
                return removeByIdWithinObjectList(id, h2.getContent());
            }
            break;
        case H3:
            H3 h3 = (H3) target;
            if (h3.isSetContent()) {
                return removeByIdWithinObjectList(id, h3.getContent());
            }
            break;
        case H4:
            H4 h4 = (H4) target;
            if (h4.isSetContent()) {
                return removeByIdWithinObjectList(id, h4.getContent());
            }
            break;
        case H5:
            H5 h5 = (H5) target;
            if (h5.isSetContent()) {
                return removeByIdWithinObjectList(id, h5.getContent());
            }
            break;
        case H6:
            H6 h6 = (H6) target;
            if (h6.isSetContent()) {
                return removeByIdWithinObjectList(id, h6.getContent());
            }
            break;
        case HGROUP:
            Hgroup hgroup = (Hgroup)target;
            if (hgroup.isSetH1OrH2OrH3()) {
                for (AbstractJaxb obj : hgroup.getH1OrH2OrH3()) {
                    if (removeById(id,obj)) {
                        return true;
                    }
                }
            }
            break;
        case HEAD:
            Head head = (Head) target;
            for (int j =0; j




© 2015 - 2024 Weber Informatics LLC | Privacy Policy