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 2006-2008 Sun Microsystems, Inc.
015 * Portions Copyright 2014-2016 ForgeRock AS.
016 */
017package org.opends.server.tools.makeldif;
018
019import java.util.List;
020
021import org.forgerock.i18n.LocalizableMessage;
022import org.opends.server.types.InitializationException;
023
024import static org.opends.messages.ToolMessages.*;
025
026/** This class defines a tag that is used to include a first name in the attribute value. */
027public class FirstNameTag
028       extends Tag
029{
030  /** The template file with which this tag is associated. */
031  private TemplateFile templateFile;
032
033  /** Creates a new instance of this first name tag. */
034  public FirstNameTag()
035  {
036    // No implementation required.
037  }
038
039  @Override
040  public String getName()
041  {
042    return "First";
043  }
044
045  @Override
046  public boolean allowedInBranch()
047  {
048    return false;
049  }
050
051  @Override
052  public void initializeForTemplate(TemplateFile templateFile,
053                                    Template template, String[] arguments,
054                                    int lineNumber, List<LocalizableMessage> warnings)
055         throws InitializationException
056  {
057    this.templateFile = templateFile;
058
059    if (arguments.length != 0)
060    {
061      LocalizableMessage message = ERR_MAKELDIF_TAG_INVALID_ARGUMENT_COUNT.get(
062          getName(), lineNumber, 0, arguments.length);
063      throw new InitializationException(message);
064    }
065  }
066
067  @Override
068  public TagResult generateValue(TemplateEntry templateEntry,
069                                 TemplateValue templateValue)
070  {
071    templateValue.append(templateFile.getFirstName());
072    return TagResult.SUCCESS_RESULT;
073  }
074}