Facet.java 3.19 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.FacetValue;
import com.day.cq.searchpromote.xml.result.ResultParser;
import java.util.ArrayList;
import java.util.List;
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 Facet
extends AbstractResultEntity {
    private static final Logger LOG = LoggerFactory.getLogger(Facet.class);
    private static final String SELECTED_NODE = "selected";
    private static final String TITLE_NODE = "facet-title";
    private static final String UNDO_LINK_NODE = "undo-link";
    private static final String ITEM_NODE = "facet-value";
    private static final String BEHAVIOR_NODE = "behavior";
    private boolean selected;
    private String title;
    private String undoQueryString;
    private List<FacetValue> items = new ArrayList<FacetValue>();
    private String behavior;

    @Override
    public void parse(XMLEventReader reader) throws Exception {
        XMLEvent event;
        LOG.debug("Parsing facet...");
        while (reader.hasNext() && !(event = ResultParser.getNextEvent(reader)).isEndElement()) {
            StartElement startElement = event.asStartElement();
            String localPart = startElement.getName().getLocalPart();
            LOG.debug("Parsing node {}", (Object)localPart);
            if (localPart.equals("selected")) {
                this.selected = ResultParser.strToBool(this.readData(reader));
                ResultParser.getNextEvent(reader);
            } else if (localPart.equals("facet-title")) {
                this.title = this.readData(reader);
                LOG.debug("Facet title is {}", (Object)this.title);
                ResultParser.getNextEvent(reader);
            } else if (localPart.equals("behavior")) {
                this.behavior = this.readData(reader);
                ResultParser.getNextEvent(reader);
            } else if (localPart.equals("undo-link")) {
                this.undoQueryString = this.readData(reader);
                ResultParser.getNextEvent(reader);
            } else if (localPart.equals("facet-value")) {
                FacetValue item = new FacetValue();
                item.parse(reader);
                this.items.add(item);
            } else {
                ResultParser.parseUnknownTag(reader);
            }
            LOG.debug("Done parsing facet {}", (Object)this.title);
        }
    }

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

    public String getTitle() {
        return this.title;
    }

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

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

    public List<FacetValue> getItems() {
        return this.items;
    }

    public String getBehavior() {
        return this.behavior;
    }
}