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