001/*
002 * (C) Copyright 2015 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-2.1.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.web.resources.core;
018
019import java.util.ArrayList;
020import java.util.List;
021
022import org.apache.commons.lang.StringUtils;
023import org.nuxeo.common.utils.FileUtils;
024import org.nuxeo.common.xmap.annotation.XNode;
025import org.nuxeo.common.xmap.annotation.XNodeList;
026import org.nuxeo.common.xmap.annotation.XObject;
027import org.nuxeo.ecm.web.resources.api.Resource;
028
029/**
030 * @since 7.3
031 */
032@XObject("resource")
033public class ResourceDescriptor implements Resource {
034
035    private static final long serialVersionUID = 1L;
036
037    @XNode("@name")
038    public String name;
039
040    @XNode("@type")
041    public String type;
042
043    @XNode("path")
044    public String path;
045
046    @XNodeList(value = "require", type = ArrayList.class, componentType = String.class)
047    public List<String> dependencies;
048
049    @XNodeList(value = "processors/processor", type = ArrayList.class, componentType = String.class)
050    public List<String> processors;
051
052    @XNode("shrinkable")
053    public boolean shrinkable = true;
054
055    @XNode("uri")
056    protected String uri;
057
058    @Override
059    public String getName() {
060        return name;
061    }
062
063    @Override
064    public String getType() {
065        if (StringUtils.isBlank(type)) {
066            // try to infer it from name for easier declaration
067            return FileUtils.getFileExtension(name);
068        }
069        return type;
070    }
071
072    @Override
073    public List<String> getDependencies() {
074        return dependencies;
075    }
076
077    @Override
078    public List<String> getProcessors() {
079        return processors;
080    }
081
082    @Override
083    public String getPath() {
084        return path;
085    }
086
087    @Override
088    public String getURI() {
089        return uri;
090    }
091
092    @Override
093    public boolean isShrinkable() {
094        return shrinkable;
095    }
096
097    public void setURI(String uri) {
098        this.uri = uri;
099    }
100
101    /**
102     * @since 7.4
103     */
104    public void setName(String name) {
105        this.name = name;
106    }
107
108    /**
109     * @since 7.4
110     */
111    public void setType(String type) {
112        this.type = type;
113    }
114
115    /**
116     * @since 7.4
117     */
118    public void setPath(String path) {
119        this.path = path;
120    }
121
122    /**
123     * @since 7.4
124     */
125    public void setDependencies(List<String> dependencies) {
126        this.dependencies = dependencies;
127    }
128
129    /**
130     * @since 7.4
131     */
132    public void setProcessors(List<String> processors) {
133        this.processors = processors;
134    }
135
136    /**
137     * @since 7.4
138     */
139    public void setShrinkable(boolean shrinkable) {
140        this.shrinkable = shrinkable;
141    }
142
143    /**
144     * @since 7.4
145     */
146    public void setUri(String uri) {
147        this.uri = uri;
148    }
149
150}