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.lang.StringUtils;
021
022import org.ametys.core.util.dom.AmetysAttribute;
023import org.ametys.odf.program.SubProgram;
024import org.ametys.plugins.repository.AmetysObjectResolver;
025
026/**
027 * DOM layer on structure of {@link SubProgram}.
028 */
029public class SubProgramElement extends AbstractODFElement<SubProgram>
030{
031    /**
032     * Constructor.
033     * @param subProgram the underlying {@link SubProgram}.
034     * @param resolver AmetysObjectResolver to find some elements by ID
035     */
036    public SubProgramElement(SubProgram subProgram, AmetysObjectResolver resolver)
037    {
038        this(subProgram, -1, null, resolver);
039    }
040    
041    /**
042     * Constructor.
043     * @param subProgram the underlying {@link SubProgram}.
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 SubProgramElement(SubProgram subProgram, int depth, AmetysObjectResolver resolver)
048    {
049        this(subProgram, depth, null, resolver);
050    }
051    
052    /**
053     * Constructor.
054     * @param subProgram the underlying {@link SubProgram}.
055     * @param depth Set to positive value to get children subprogram structure
056     * @param parent Parent of the element. Can be null
057     * @param resolver AmetysObjectResolver to find some elements by ID
058     */
059    public SubProgramElement(SubProgram subProgram, int depth, AbstractODFElement<?> parent, AmetysObjectResolver resolver)
060    {
061        super(subProgram, depth, parent, resolver);
062    }
063
064    @Override
065    public String getTagName()
066    {
067        return "subprogram";
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        String ects = _object.getEcts();
078        if (StringUtils.isNotEmpty(ects))
079        {
080            result.put("ects", new AmetysAttribute("ects", "ects", null, ects, this));
081        }
082        
083        String parentPath = _object.getContextPath();
084        if (parentPath != null)
085        {
086            result.put("path", new AmetysAttribute("path", "path", null, parentPath + "/" + _object.getName(), this));
087        }
088        
089        return result;
090    }
091}