001/*
002 * (C) Copyright 2014 Nuxeo SA (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.platform.forms.layout.descriptors;
020
021import java.util.ArrayList;
022import java.util.HashMap;
023import java.util.List;
024import java.util.Map;
025
026import org.nuxeo.common.xmap.annotation.XNode;
027import org.nuxeo.common.xmap.annotation.XNodeList;
028import org.nuxeo.common.xmap.annotation.XNodeMap;
029import org.nuxeo.common.xmap.annotation.XObject;
030import org.nuxeo.ecm.platform.forms.layout.api.LayoutTypeConfiguration;
031import org.nuxeo.ecm.platform.forms.layout.api.LayoutTypeDefinition;
032import org.nuxeo.ecm.platform.forms.layout.api.impl.LayoutTypeDefinitionImpl;
033
034/**
035 * @since 6.0
036 */
037@XObject("layoutType")
038public class LayoutTypeDescriptor {
039
040    @XNode("@name")
041    String name;
042
043    @XNodeList(value = "aliases/alias", type = ArrayList.class, componentType = String.class)
044    List<String> aliases;
045
046    @XNodeMap(value = "templates/template", key = "@mode", type = HashMap.class, componentType = String.class)
047    Map<String, String> templates = new HashMap<String, String>();
048
049    @XNode("configuration")
050    LayoutTypeConfigurationDescriptor configuration;
051
052    @XNodeList(value = "categories/category", type = String[].class, componentType = String.class)
053    String[] categories = new String[0];
054
055    public String getName() {
056        return name;
057    }
058
059    public List<String> getAliases() {
060        return aliases;
061    }
062
063    public Map<String, String> getTemplates() {
064        return templates;
065    }
066
067    public LayoutTypeConfiguration getConfiguration() {
068        if (configuration == null) {
069            return null;
070        }
071        return configuration.getLayoutTypeConfiguration();
072    }
073
074    public String[] getCategories() {
075        return categories;
076    }
077
078    public LayoutTypeDefinition getLayoutTypeDefinition() {
079        LayoutTypeDefinitionImpl res = new LayoutTypeDefinitionImpl(name, templates, getConfiguration());
080        res.setAliases(getAliases());
081        return res;
082    }
083
084}