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