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