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