FacetValue.java 4.13 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.day.cq.searchpromote.xml.result;

import com.day.cq.searchpromote.xml.result.AbstractResultEntity;
import com.day.cq.searchpromote.xml.result.FacetValueChildList;
import com.day.cq.searchpromote.xml.result.ResultParser;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class FacetValue
extends AbstractResultEntity {
    private static final Logger LOG = LoggerFactory.getLogger(FacetValue.class);
    private static final String LABEL_NODE = "label";
    private static final String COUNT_NODE = "count";
    private static final String LINK_NODE = "link";
    private static final String UNDO_LINK_NODE = "undolink";
    private static final String SELECTED_NODE = "selected";
    private static final String HAS_CHILDREN_NODE = "facet-has-children";
    private static final String CHILDREN_NODE = "children";
    private String label;
    private String undoQueryString;
    private String queryString;
    private Long count;
    private boolean selected;
    private boolean hasChildren;
    private FacetValueChildList childList;

    @Override
    public void parse(XMLEventReader reader) throws Exception {
        XMLEvent nextEvent;
        LOG.debug("Parsing facet value");
        while (reader.hasNext() && !(nextEvent = ResultParser.getNextEvent(reader)).isEndElement()) {
            String data;
            StartElement element = nextEvent.asStartElement();
            String localPart = element.getName().getLocalPart();
            LOG.debug("Parsing node {}", (Object)localPart);
            if ("label".equals(localPart)) {
                this.label = data = this.readData(reader);
                ResultParser.getNextEvent(reader);
                continue;
            }
            if ("count".equals(localPart)) {
                data = this.readData(reader);
                this.count = ResultParser.strToLong(data);
                ResultParser.getNextEvent(reader);
                continue;
            }
            if ("link".equals(localPart)) {
                this.queryString = data = this.readData(reader);
                ResultParser.getNextEvent(reader);
                continue;
            }
            if ("undolink".equals(localPart)) {
                this.undoQueryString = data = this.readData(reader);
                ResultParser.getNextEvent(reader);
                continue;
            }
            if ("selected".equals(localPart)) {
                data = this.readData(reader);
                this.selected = ResultParser.strToBool(data);
                ResultParser.getNextEvent(reader);
                continue;
            }
            if ("facet-has-children".equals(localPart)) {
                data = this.readData(reader);
                this.hasChildren = ResultParser.strToBool(data);
                ResultParser.getNextEvent(reader);
                continue;
            }
            if (element.getName().getLocalPart().equals("children")) {
                this.childList = new FacetValueChildList();
                this.childList.parse(reader);
                continue;
            }
            ResultParser.parseUnknownTag(reader);
        }
    }

    public String getLabel() {
        return this.label;
    }

    public String getUndoQueryString() {
        return this.undoQueryString;
    }

    public Boolean hasUndoQueryString() {
        return this.undoQueryString != null && !"".equals(this.undoQueryString);
    }

    public String getQueryString() {
        return this.queryString;
    }

    public Boolean hasQueryString() {
        return this.queryString != null && !"".equals(this.queryString);
    }

    public Long getCount() {
        return this.count;
    }

    public boolean isSelected() {
        return this.selected;
    }

    public boolean hasChildren() {
        return this.hasChildren;
    }

    public FacetValueChildList getChildList() {
        return this.childList;
    }
}