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    /**
044     * Target for this resource.
045     * <p>
046     * Currently only useful for JSF resources reallocation in the page.
047     *
048     * @since 7.10
049     */
050    @XNode("@target")
051    public String target;
052
053    @XNode("path")
054    public String path;
055
056    @XNodeList(value = "require", type = ArrayList.class, componentType = String.class)
057    public List<String> dependencies;
058
059    @XNodeList(value = "processors/processor", type = ArrayList.class, componentType = String.class)
060    public List<String> processors;
061
062    @XNode("shrinkable")
063    public boolean shrinkable = true;
064
065    @XNode("uri")
066    protected String uri;
067
068    @Override
069    public String getName() {
070        return name;
071    }
072
073    @Override
074    public String getType() {
075        if (StringUtils.isBlank(type)) {
076            // try to infer it from name for easier declaration
077            return FileUtils.getFileExtension(name);
078        }
079        return type;
080    }
081
082    @Override
083    public List<String> getDependencies() {
084        return dependencies;
085    }
086
087    @Override
088    public List<String> getProcessors() {
089        return processors;
090    }
091
092    @Override
093    public String getPath() {
094        return path;
095    }
096
097    @Override
098    public String getURI() {
099        return uri;
100    }
101
102    @Override
103    public boolean isShrinkable() {
104        return shrinkable;
105    }
106
107    public void setURI(String uri) {
108        this.uri = uri;
109    }
110
111    /**
112     * @since 7.4
113     */
114    public void setName(String name) {
115        this.name = name;
116    }
117
118    /**
119     * @since 7.4
120     */
121    public void setType(String type) {
122        this.type = type;
123    }
124
125    /**
126     * @since 7.4
127     */
128    public void setPath(String path) {
129        this.path = path;
130    }
131
132    /**
133     * @since 7.4
134     */
135    public void setDependencies(List<String> dependencies) {
136        this.dependencies = dependencies;
137    }
138
139    /**
140     * @since 7.4
141     */
142    public void setProcessors(List<String> processors) {
143        this.processors = processors;
144    }
145
146    /**
147     * @since 7.4
148     */
149    public void setShrinkable(boolean shrinkable) {
150        this.shrinkable = shrinkable;
151    }
152
153    /**
154     * @since 7.4
155     */
156    public void setUri(String uri) {
157        this.uri = uri;
158    }
159
160    /**
161     * @since 7.10
162     */
163    public String getTarget() {
164        return target;
165    }
166
167    /**
168     * @since 7.10
169     */
170    public void setTarget(String target) {
171        this.target = target;
172    }
173
174}