001/*
002 *  Copyright 2015 Anyware Services
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 */
016package org.ametys.odf.xslt;
017
018import java.util.Map;
019
020import org.ametys.core.util.dom.AmetysAttribute;
021import org.ametys.odf.courselist.CourseList;
022import org.ametys.odf.courselist.CourseList.ChoiceType;
023import org.ametys.plugins.repository.AmetysObjectResolver;
024
025/**
026 * DOM layer on structure of {@link CourseList}.
027 */
028public class CourseListElement extends AbstractODFElement<CourseList>
029{
030    /**
031     * Constructor.
032     * @param courseList the underlying {@link CourseList}.
033     * @param depth Depth to SAX.
034     * @param parent the parent element
035     * @param resolver AmetysObjectResolver to find some elements by ID
036     */
037    public CourseListElement(CourseList courseList, int depth, AbstractODFElement<?> parent, AmetysObjectResolver resolver)
038    {
039        super(courseList, depth, parent, resolver);
040    }
041
042    @Override
043    public String getTagName()
044    {
045        return "courseList";
046    }
047    
048    @Override
049    protected Map<String, AmetysAttribute> _lookupAttributes()
050    {
051        Map<String, AmetysAttribute> result = super._lookupAttributes();
052        
053        result.put("title", new AmetysAttribute("title", "title", null, _object.getTitle(), this));
054        
055        ChoiceType type = _object.getType();
056        if (type != null)
057        {
058            result.put("type", new AmetysAttribute("type", "type", null, type.toString(), this));
059        }
060        
061        if (ChoiceType.CHOICE.equals(type))
062        {
063            result.put("min", new AmetysAttribute("min", "min", null, String.valueOf(_object.getMinNumberOfCourses()), this));
064            result.put("max", new AmetysAttribute("max", "max", null, String.valueOf(_object.getMaxNumberOfCourses()), this));
065        }
066        
067        return result;
068    }
069}