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; 018import org.forgerock.i18n.LocalizableMessage; 019 020 021 022import java.util.List; 023 024import org.opends.server.types.InitializationException; 025 026import static org.opends.messages.ToolMessages.*; 027 028 029 030/** This class defines a tag that is used to include a last name in the attribute value. */ 031public class LastNameTag 032 extends Tag 033{ 034 /** The template file with which this tag is associated. */ 035 private TemplateFile templateFile; 036 037 038 039 /** Creates a new instance of this last name tag. */ 040 public LastNameTag() 041 { 042 // No implementation required. 043 } 044 045 046 047 /** 048 * Retrieves the name for this tag. 049 * 050 * @return The name for this tag. 051 */ 052 @Override 053 public String getName() 054 { 055 return "Last"; 056 } 057 058 059 060 /** 061 * Indicates whether this tag is allowed for use in the extra lines for 062 * branches. 063 * 064 * @return <CODE>true</CODE> if this tag may be used in branch definitions, 065 * or <CODE>false</CODE> if not. 066 */ 067 @Override 068 public boolean allowedInBranch() 069 { 070 return false; 071 } 072 073 074 075 /** 076 * Performs any initialization for this tag that may be needed while parsing 077 * a template definition. 078 * 079 * @param templateFile The template file in which this tag is used. 080 * @param template The template in which this tag is used. 081 * @param arguments The set of arguments provided for this tag. 082 * @param lineNumber The line number on which this tag appears in the 083 * template file. 084 * @param warnings A list into which any appropriate warning messages 085 * may be placed. 086 * 087 * @throws InitializationException If a problem occurs while initializing 088 * this tag. 089 */ 090 @Override 091 public void initializeForTemplate(TemplateFile templateFile, 092 Template template, String[] arguments, 093 int lineNumber, List<LocalizableMessage> warnings) 094 throws InitializationException 095 { 096 this.templateFile = templateFile; 097 098 if (arguments.length != 0) 099 { 100 LocalizableMessage message = ERR_MAKELDIF_TAG_INVALID_ARGUMENT_COUNT.get( 101 getName(), lineNumber, 0, arguments.length); 102 throw new InitializationException(message); 103 } 104 } 105 106 107 108 /** 109 * Generates the content for this tag by appending it to the provided tag. 110 * 111 * @param templateEntry The entry for which this tag is being generated. 112 * @param templateValue The template value to which the generated content 113 * should be appended. 114 * 115 * @return The result of generating content for this tag. 116 */ 117 @Override 118 public TagResult generateValue(TemplateEntry templateEntry, 119 TemplateValue templateValue) 120 { 121 templateValue.append(templateFile.getLastName()); 122 return TagResult.SUCCESS_RESULT; 123 } 124} 125