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