001/*
002 * (C) Copyright 2015-2018 Nuxeo (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Anahide Tchertchian
018 */
019package org.nuxeo.ecm.web.resources.core;
020
021import java.util.ArrayList;
022import java.util.List;
023
024import org.apache.commons.lang3.StringUtils;
025import org.nuxeo.common.utils.FileUtils;
026import org.nuxeo.common.xmap.annotation.XNode;
027import org.nuxeo.common.xmap.annotation.XNodeList;
028import org.nuxeo.common.xmap.annotation.XObject;
029import org.nuxeo.ecm.web.resources.api.Resource;
030
031/**
032 * @since 7.3
033 */
034@XObject("resource")
035public class ResourceDescriptor implements Resource {
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    @Override
164    public String getTarget() {
165        return target;
166    }
167
168    /**
169     * @since 7.10
170     */
171    public void setTarget(String target) {
172        this.target = target;
173    }
174
175}