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