001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2014 ForgeRock AS
015 */
016package org.forgerock.doc.maven.utils.helper;
017
018import freemarker.template.SimpleScalar;
019import freemarker.template.TemplateMethodModelEx;
020import freemarker.template.TemplateModelException;
021import org.forgerock.doc.maven.utils.NameUtils;
022
023import java.util.List;
024
025/**
026 * FreeMarker method for getting a single document name.
027 */
028public class NameMethod implements TemplateMethodModelEx {
029
030    @Override
031    public Object exec(List args) throws TemplateModelException {
032        if (args.size() != 4) {
033            throw new TemplateModelException("Bad arguments list");
034        }
035
036        return NameUtils.renameDoc(
037                ((SimpleScalar) args.get(0)).getAsString(),
038                ((SimpleScalar) args.get(1)).getAsString(),
039                ((SimpleScalar) args.get(2)).getAsString(),
040                ((SimpleScalar) args.get(3)).getAsString());
041    }
042}