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 /** 035 * Creates a new instance of this RDN tag. 036 */ 037 public RDNTag() 038 { 039 // No implementation required. 040 } 041 042 043 044 /** 045 * Retrieves the name for this tag. 046 * 047 * @return The name for this tag. 048 */ 049 public String getName() 050 { 051 return "RDN"; 052 } 053 054 055 056 /** 057 * Indicates whether this tag is allowed for use in the extra lines for 058 * branches. 059 * 060 * @return <CODE>true</CODE> if this tag may be used in branch definitions, 061 * or <CODE>false</CODE> if not. 062 */ 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 public void initializeForBranch(TemplateFile templateFile, Branch branch, 086 String[] arguments, int lineNumber, 087 List<LocalizableMessage> warnings) 088 throws InitializationException 089 { 090 if (arguments.length != 0) 091 { 092 LocalizableMessage message = ERR_MAKELDIF_TAG_INVALID_ARGUMENT_COUNT.get( 093 getName(), lineNumber, 0, arguments.length); 094 throw new InitializationException(message); 095 } 096 } 097 098 099 100 /** 101 * Performs any initialization for this tag that may be needed while parsing 102 * a template definition. 103 * 104 * @param templateFile The template file in which this tag is used. 105 * @param template The template in which this tag is used. 106 * @param arguments The set of arguments provided for this tag. 107 * @param lineNumber The line number on which this tag appears in the 108 * template file. 109 * @param warnings A list into which any appropriate warning messages 110 * may be placed. 111 * 112 * @throws InitializationException If a problem occurs while initializing 113 * this tag. 114 */ 115 public void initializeForTemplate(TemplateFile templateFile, 116 Template template, String[] arguments, 117 int lineNumber, List<LocalizableMessage> warnings) 118 throws InitializationException 119 { 120 if (arguments.length != 0) 121 { 122 LocalizableMessage message = ERR_MAKELDIF_TAG_INVALID_ARGUMENT_COUNT.get( 123 getName(), lineNumber, 0, arguments.length); 124 throw new InitializationException(message); 125 } 126 } 127 128 129 130 /** 131 * Generates the content for this tag by appending it to the provided tag. 132 * 133 * @param templateEntry The entry for which this tag is being generated. 134 * @param templateValue The template value to which the generated content 135 * should be appended. 136 * 137 * @return The result of generating content for this tag. 138 */ 139 public TagResult generateValue(TemplateEntry templateEntry, 140 TemplateValue templateValue) 141 { 142 DN dn = templateEntry.getDN(); 143 if (dn != null && !dn.isRootDN()) 144 { 145 templateValue.getValue().append(dn.rdn()); 146 } 147 return TagResult.SUCCESS_RESULT; 148 } 149} 150