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