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.apache.commons.lang3.StringUtils;
021
022import org.ametys.core.util.dom.AmetysAttribute;
023import org.ametys.odf.program.Program;
024import org.ametys.plugins.repository.AmetysObjectResolver;
025
026/**
027 * DOM layer on structure of {@link Program}.
028 */
029public class ProgramElement extends AbstractODFElement<Program>
030{
031    /**
032     * Constructor.
033     * @param program the underlying {@link Program}.
034     * @param resolver AmetysObjectResolver to find some elements by ID
035     */
036    public ProgramElement(Program program, AmetysObjectResolver resolver)
037    {
038        this(program, -1, null, resolver);
039    }
040    
041    /**
042     * Constructor.
043     * @param program the underlying {@link Program}.
044     * @param depth Set to positive number to get child subprograms structure until given depth. Set negative number to get all child subprograms structure
045     * @param resolver AmetysObjectResolver to find some elements by ID
046     */
047    public ProgramElement(Program program, int depth, AmetysObjectResolver resolver)
048    {
049        this(program, depth, null, resolver);
050    }
051    
052    /**
053     * Constructor.
054     * @param program the underlying {@link Program}.
055     * @param depth Set to positive value to get children subprogram structure
056     * @param parent Parent of the element. Always be null
057     * @param resolver AmetysObjectResolver to find some elements by ID
058     */
059    public ProgramElement(Program program, int depth, AbstractODFElement<?> parent, AmetysObjectResolver resolver)
060    {
061        super(program, depth, parent, resolver);
062    }
063
064    @Override
065    public String getTagName()
066    {
067        return "program";
068    }
069    
070    @Override
071    protected Map<String, AmetysAttribute> _lookupAttributes()
072    {
073        Map<String, AmetysAttribute> result = super._lookupAttributes();
074        
075        result.put("title", new AmetysAttribute("title", "title", null, _object.getTitle(), this));
076        
077        // FIXME ODF-1689 ProgramElement : Remonter les domaines ?
078//        String domain = _object.getDomain();
079//        if (StringUtils.isNotEmpty(domain))
080//        {
081//            result.put("domain", new AmetysAttribute("domain", "domain", null, domain, this));
082//        }
083        
084        String degree = _object.getDegree();
085        if (StringUtils.isNotEmpty(degree))
086        {
087            result.put("degree", new AmetysAttribute("degree", "degree", null, degree, this));
088        }
089        
090        String ects = _object.getEcts();
091        if (StringUtils.isNotEmpty(ects))
092        {
093            result.put("ects", new AmetysAttribute("ects", "ects", null, ects, this));
094        }
095        
096        String parentPath = _object.getContextPath();
097        if (parentPath != null)
098        {
099            result.put("path", new AmetysAttribute("path", "path", null, parentPath + "/" + _object.getName(), this));
100        }
101        
102        return result;
103    }
104}