001/*
002 * (C) Copyright 2012 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Anahide Tchertchian
016 */
017package org.nuxeo.ecm.styleguide.service.descriptors;
018
019import java.io.IOException;
020import java.util.ArrayList;
021import java.util.List;
022
023import org.apache.commons.logging.Log;
024import org.apache.commons.logging.LogFactory;
025import org.apache.xml.serialize.OutputFormat;
026import org.nuxeo.common.utils.FileUtils;
027import org.nuxeo.common.xmap.DOMSerializer;
028import org.nuxeo.common.xmap.annotation.XContent;
029import org.nuxeo.common.xmap.annotation.XNode;
030import org.nuxeo.common.xmap.annotation.XNodeList;
031import org.nuxeo.common.xmap.annotation.XObject;
032import org.w3c.dom.DocumentFragment;
033
034/**
035 * @since 5.7
036 */
037@XObject("icon")
038public class IconDescriptor {
039
040    private static final Log log = LogFactory.getLog(IconDescriptor.class);
041
042    @XNode("@path")
043    protected String path;
044
045    @XNode("@enabled")
046    protected Boolean enabled = Boolean.TRUE;
047
048    @XNode("label")
049    protected String label;
050
051    // retrieve HTML tags => introspect DOM on setter
052    protected String description;
053
054    @XNode("sinceVersion")
055    protected String sinceVersion;
056
057    @XNodeList(value = "categories/category", type = ArrayList.class, componentType = String.class)
058    protected List<String> categories;
059
060    public String getPath() {
061        return path;
062    }
063
064    public String getFilename() {
065        return FileUtils.getFileName(path);
066    }
067
068    public String getLabel() {
069        return label;
070    }
071
072    public String getDescription() {
073        return description;
074    }
075
076    public String getSinceVersion() {
077        return sinceVersion;
078    }
079
080    public List<String> getCategories() {
081        return categories;
082    }
083
084    public void setPath(String path) {
085        this.path = path;
086    }
087
088    public void setLabel(String label) {
089        this.label = label;
090    }
091
092    public void setDescription(String description) {
093        this.description = description;
094    }
095
096    @XContent("description")
097    @SuppressWarnings("deprecation")
098    public void setDescription(DocumentFragment descriptionDOM) {
099        try {
100            OutputFormat of = new OutputFormat();
101            of.setOmitXMLDeclaration(true);
102            this.description = DOMSerializer.toString(descriptionDOM, of).trim();
103        } catch (IOException e) {
104            log.error(e, e);
105        }
106    }
107
108    public void setSinceVersion(String sinceVersion) {
109        this.sinceVersion = sinceVersion;
110    }
111
112    public void setCategories(List<String> categories) {
113        this.categories = categories;
114    }
115
116    public Boolean getEnabled() {
117        return enabled;
118    }
119
120    public void setEnabled(Boolean enabled) {
121        this.enabled = enabled;
122    }
123
124    public String toString() {
125        return getPath();
126    }
127
128}