001/* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt 010 * or http://forgerock.org/license/CDDLv1.0.html. 011 * See the License for the specific language governing permissions 012 * and limitations under the License. 013 * 014 * When distributing Covered Code, include this CDDL HEADER in each 015 * file and include the License file at legal-notices/CDDLv1_0.txt. 016 * If applicable, add the following below this CDDL HEADER, with the 017 * fields enclosed by brackets "[]" replaced with your own identifying 018 * information: 019 * Portions Copyright [yyyy] [name of copyright owner] 020 * 021 * CDDL HEADER END 022 * 023 * 024 * Copyright 2006-2008 Sun Microsystems, Inc. 025 * Portions Copyright 2014-2015 ForgeRock AS 026 */ 027package org.opends.server.tools.makeldif; 028 029import static org.opends.messages.ToolMessages.*; 030 031import java.util.List; 032 033import org.forgerock.i18n.LocalizableMessage; 034import org.opends.server.types.DN; 035import org.opends.server.types.InitializationException; 036 037/** 038 * This class defines a tag that is used to include the RDN of the current entry 039 * in the attribute value. 040 */ 041public class RDNTag 042 extends Tag 043{ 044 /** 045 * Creates a new instance of this RDN tag. 046 */ 047 public RDNTag() 048 { 049 // No implementation required. 050 } 051 052 053 054 /** 055 * Retrieves the name for this tag. 056 * 057 * @return The name for this tag. 058 */ 059 public String getName() 060 { 061 return "RDN"; 062 } 063 064 065 066 /** 067 * Indicates whether this tag is allowed for use in the extra lines for 068 * branches. 069 * 070 * @return <CODE>true</CODE> if this tag may be used in branch definitions, 071 * or <CODE>false</CODE> if not. 072 */ 073 public boolean allowedInBranch() 074 { 075 return true; 076 } 077 078 079 080 /** 081 * Performs any initialization for this tag that may be needed while parsing 082 * a branch definition. 083 * 084 * @param templateFile The template file in which this tag is used. 085 * @param branch The branch in which this tag is used. 086 * @param arguments The set of arguments provided for this tag. 087 * @param lineNumber The line number on which this tag appears in the 088 * template file. 089 * @param warnings A list into which any appropriate warning messages 090 * may be placed. 091 * 092 * @throws InitializationException If a problem occurs while initializing 093 * this tag. 094 */ 095 public void initializeForBranch(TemplateFile templateFile, Branch branch, 096 String[] arguments, int lineNumber, 097 List<LocalizableMessage> warnings) 098 throws InitializationException 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 * Performs any initialization for this tag that may be needed while parsing 112 * a template definition. 113 * 114 * @param templateFile The template file in which this tag is used. 115 * @param template The template in which this tag is used. 116 * @param arguments The set of arguments provided for this tag. 117 * @param lineNumber The line number on which this tag appears in the 118 * template file. 119 * @param warnings A list into which any appropriate warning messages 120 * may be placed. 121 * 122 * @throws InitializationException If a problem occurs while initializing 123 * this tag. 124 */ 125 public void initializeForTemplate(TemplateFile templateFile, 126 Template template, String[] arguments, 127 int lineNumber, List<LocalizableMessage> warnings) 128 throws InitializationException 129 { 130 if (arguments.length != 0) 131 { 132 LocalizableMessage message = ERR_MAKELDIF_TAG_INVALID_ARGUMENT_COUNT.get( 133 getName(), lineNumber, 0, arguments.length); 134 throw new InitializationException(message); 135 } 136 } 137 138 139 140 /** 141 * Generates the content for this tag by appending it to the provided tag. 142 * 143 * @param templateEntry The entry for which this tag is being generated. 144 * @param templateValue The template value to which the generated content 145 * should be appended. 146 * 147 * @return The result of generating content for this tag. 148 */ 149 public TagResult generateValue(TemplateEntry templateEntry, 150 TemplateValue templateValue) 151 { 152 DN dn = templateEntry.getDN(); 153 if (dn != null && !dn.isRootDN()) 154 { 155 dn.rdn().toString(templateValue.getValue()); 156 } 157 return TagResult.SUCCESS_RESULT; 158 } 159} 160