/* XBN Java: Generically useful, non-GUI Java code. http://sourceforge.net/projects/xbnjava Copyright (C) 1997-2003, Jeff Epstein All rights reserved. Modifications: No Redistribution in binary form, with or without modifications, are permitted provided that the following conditions are met: * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * If modifications are made to source code then this license should indicate that fact in the "Modifications" section above. * Neither the author, nor the contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. [NOTE: This license contains NO advertising clause.] */ package xbn.template; import xbn.XBNObject; import xbn.array.AOSLookup; import xbn.array.APString; import xbn.named.Named; /**

Holds the data for a single Template. See Template.

Source code:  TemplateData.java.

@version 0.9b @author Jeff Epstein, http://sourceforge.net/projects/xbnjava. **/ public class TemplateData extends XBNObject implements Named, Cloneable { private String sName = null; //The objects created as a result of parsing the template source text. //For an in depth description of these objects, see the bottom of //this document. private AOSLookup aosl = null; private APString apsSurrText = null; private String sTagStart = null; private String sTagEnd = null; /**

Create a TemplateData.

Equal to TemplateData(s_name, aos_lookup, aps_surrText, s_tagStart, s_tagEnd, true)

**/ public TemplateData(String s_name, AOSLookup aos_lookup, APString aps_surrText, String s_tagStart, String s_tagEnd) { this(s_name, aos_lookup, aps_surrText, s_tagStart, s_tagEnd, true); } /**

Create a TemplateData.

@param s_name The name of this template. See getName. @param aos_lookup The AOSLookup containing metadata about the gaps. May not be null. See getAOSLookup. @param aps_surrText An APString where the string array contains the surrounding text for this template. May not be null. See getAPSSurrText. @param s_tagStart The full text of the start tag for a gap. May not be null, or zero characters in length. See getTagStart @param s_tagEnd The full text of the end tag for a gap. May not be null, or zero characters in length. See getTagEnd. @param b_validateParams Should all parameters be validated? If true, then yes (and crash if any errors found). Otherwise no. Assume all parameters are valid. Be very sure that, if you set this to false, that the parameters are valid. Otherwise, this class (and entire package) will behave unpredictably. **/ public TemplateData(String s_name, AOSLookup aos_lookup, APString aps_surrText, String s_tagStart, String s_tagEnd, boolean b_validateParams) { if(b_validateParams) { throwAXIfNull(aos_lookup, "aos_lookup", sCNSTR); throwAXIfNull(aps_surrText, "aps_surrText", sCNSTR); throwAXIfBadStr(s_tagStart, "s_tagStart", sCNSTR); throwAXIfBadStr(s_tagEnd, "s_tagEnd", sCNSTR); } sName = s_name; aosl = aos_lookup; apsSurrText = aps_surrText; sTagStart = s_tagStart; sTagEnd = s_tagEnd; } /**

Get the AOSLookup for direct manipulation.

@return aos_lookup Exactly as provided to the constructor. **/ public AOSLookup getAOSLookup() { return aosl; } /**

Get the array of strings representing the surrounding, static text. Each element of surrounding text goes between each absolute gap.

This object always has exactly one more element than does

aos_lookup.getUSAPAbsolute().getLength()

The first bit of surrounding text is before the first gap. The second between the first and second gaps, ..., the last bit of surrounding text comes after the last gap.

This contains the text of everything except the gap names themselves (and the tag start and end).

@return aps_surrText Exactly as provided to the constructor. **/ public APString getAPSSurrText() { return apsSurrText; } /**

Get the tag that starts a gap. This text is found immediately before the gap name.

For example: In "\~G\~my_gap_name\~EG\~", \~G\~ is the gap start tag.

@return s_tagStart Exactly as provided to the constructor. **/ public String getTagStart() { return sTagStart; } /**

Get the tag that ends a gap. This text is found immediately after the gap name.

For example: In "\~G\~my_gap_name\~EG\~", \~EG\~ is the gap end tag.

@return s_tagEnd Exactly as provided to the constructor. **/ public String getTagEnd() { return sTagEnd; } //REQUIRED BY xbn.named.Named...START /** @return s_name Exactly as provided to the constructor. **/ public String getName() { return sName; } //REQUIRED BY xbn.named.Named...END //Cloning...START /**

Get a full (deep) copy of this TemplateData.

@return (TemplateData)clone() **/ public TemplateData getTDClone() { try { return (TemplateData)clone(); } catch(CloneNotSupportedException cnsx) { throwAX("getTDClone [SHOULD NEVER HAPPEN!]: " + cnsx.toString()); } //Never reached. Required for compile. return null; } /**

Get a full (deep) copy of this TemplateData as an Object.

**/ protected Object clone() throws CloneNotSupportedException { return new TemplateData(sName, aosl, apsSurrText, sTagStart, sTagEnd, false); } //Cloning...END }