/* 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.config; import xbn.XBNObject; import xbn.string.SOBString; /**

Configuration related to variables in a ConfigReader, provided via CRConfig. Provided to ConfigReader via CRConfig.

Source code:  CRCVariable.java

@version 0.9b @author Jeff Epstein, http://sourceforge.net/projects/xbnjava. **/ public class CRCVariable extends XBNObject { private CRCVTrim crcvt = null; private CRCVUnescape crcvu = null; private boolean b1stLineWSIsES = false; private String sNullValue = null; /**

Create a CRCVariable with default settings.

Equal to CRCVariable(new CRCVTrim())

**/ public CRCVariable() { this(new CRCVTrim()); } /**

Create a CRCVariable.

Equal to CRCVariable(crcv_trim, (new CRCVUnescape()))

**/ public CRCVariable(CRCVTrim crcv_trim) { this(crcv_trim, (new CRCVUnescape())); } /**

Create a CRCVariable.

Equal to CRCVariable((new CRCVTrim()), crcv_unescape)

**/ public CRCVariable(CRCVUnescape crcv_unescape) { this((new CRCVTrim()), crcv_unescape); } /**

Create a CRCVariable.

Equal to CRCVariable((new CRCVTrim()), s_nullValue)

**/ public CRCVariable(String s_nullValue) { this((new CRCVTrim()), s_nullValue); } /**

Create a CRCVariable.

Equal to CRCVariable((new CRCVTrim()), b_1stLineWSIsEmptyString)

**/ public CRCVariable(boolean b_1stLineWSIsEmptyString) { this((new CRCVTrim()), b_1stLineWSIsEmptyString); } /**

Create a CRCVariable.

Equal to CRCVariable(crcv_trim, crcv_unescape, "__NULL__")

**/ public CRCVariable(CRCVTrim crcv_trim, CRCVUnescape crcv_unescape) { this(crcv_trim, crcv_unescape, "__NULL__"); } /**

Create a CRCVariable.

Equal to CRCVariable(crcv_trim, (new CRCVUnescape()), s_nullValue)

**/ public CRCVariable(CRCVTrim crcv_trim, String s_nullValue) { this(crcv_trim, (new CRCVUnescape()), s_nullValue); } /**

Create a CRCVariable.

Equal to CRCVariable(crcv_trim, (new CRCVUnescape()), b_1stLineWSIsEmptyString)

**/ public CRCVariable(CRCVTrim crcv_trim, boolean b_1stLineWSIsEmptyString) { this(crcv_trim, (new CRCVUnescape()), b_1stLineWSIsEmptyString); } /**

Create a CRCVariable.

Equal to CRCVariable((new CRCVTrim()), crcv_unescape, s_nullValue)

**/ public CRCVariable(CRCVUnescape crcv_unescape, String s_nullValue) { this((new CRCVTrim()), crcv_unescape, s_nullValue); } /**

Create a CRCVariable.

Equal to CRCVariable((new CRCVTrim()), crcv_unescape, b_1stLineWSIsEmptyString)

**/ public CRCVariable(CRCVUnescape crcv_unescape, boolean b_1stLineWSIsEmptyString) { this((new CRCVTrim()), crcv_unescape, b_1stLineWSIsEmptyString); } /**

Create a CRCVariable.

Equal to CRCVariable((new CRCVTrim()), s_nullValue, b_1stLineWSIsEmptyString)

**/ public CRCVariable(String s_nullValue, boolean b_1stLineWSIsEmptyString) { this((new CRCVTrim()), s_nullValue, b_1stLineWSIsEmptyString); } /**

Create a CRCVariable.

Equal to CRCVariable(crcv_trim, crcv_unescape, s_nullValue, true)

**/ public CRCVariable(CRCVTrim crcv_trim, CRCVUnescape crcv_unescape, String s_nullValue) { this(crcv_trim, crcv_unescape, s_nullValue, true); } /**

Create a CRCVariable.

Equal to CRCVariable(crcv_trim, crcv_unescape, "__NULL__", b_1stLineWSIsEmptyString)

**/ public CRCVariable(CRCVTrim crcv_trim, CRCVUnescape crcv_unescape, boolean b_1stLineWSIsEmptyString) { this(crcv_trim, crcv_unescape, "__NULL__", b_1stLineWSIsEmptyString); } /**

Create a CRCVariable.

Equal to CRCVariable(crcv_trim, (new CRCVUnescape()), "__NULL__", b_1stLineWSIsEmptyString)

**/ public CRCVariable(CRCVTrim crcv_trim, String s_nullValue, boolean b_1stLineWSIsEmptyString) { this(crcv_trim, (new CRCVUnescape()), s_nullValue, b_1stLineWSIsEmptyString); } /**

Create a CRCVariable.

Equal to CRCVariable((new CRCVTrim()), crcv_unescape, s_nullValue, b_1stLineWSIsEmptyString)

**/ public CRCVariable(CRCVUnescape crcv_unescape, String s_nullValue, boolean b_1stLineWSIsEmptyString) { this((new CRCVTrim()), crcv_unescape, s_nullValue, b_1stLineWSIsEmptyString); } /**

Create a CRCVariable.

This object, as a whole, is provided to the CRConfig constructor. Some of these requirements are enforced there, some here.

Regarding these characters:

They must all be unique, not invisible, and crcv_unescape.getUSCIgnore().isSpcfcIgnored(THE_CHAR) must equal false.

@param crcv_trim Configuration regarding trimming the name and value lines. May not be null. See getCRCVTrim. @param crcv_unescape Configuration regarding what and how characters should be unescaped. May not be null. See getCRCVUnescape. @param s_nullValue The special string to be defined as (truly) null, when the first line of a value is equal to it. May not be null or zero characters in length. See getNullValue. @param b_1stLineWSIsEmptyString If the first line of a variable's value is nothing but whitespace, should it be considered as empty string? See is1stLineWSEmptyString. **/ public CRCVariable(CRCVTrim crcv_trim, CRCVUnescape crcv_unescape, String s_nullValue, boolean b_1stLineWSIsEmptyString) { SOBString ssNV = new SOBString(s_nullValue); ZCICharErr cice = new ZCICharErr(); try { if(crcv_trim.doUseESChar()) { cice.ciCharErr(crcv_trim.getESChar(), "crcv_trim.getESChar()", crcv_unescape, ssNV); } } catch(NullPointerException npx) { throwAXIfNull(crcv_trim, "crcv_trim", sCNSTR); throwAXIfNull(crcv_unescape, "crcv_unescape", sCNSTR); } //1/2: Putting this first avoids 2/2 from checking //invisible chars against one another (and therefore //presenting invisible strings in the error message). cice.ciCharErr(crcv_unescape.getEscapeChar(), "crcv_unescape.getEscapeChar()", null, ssNV); //2/2 if(crcv_trim.doUseESChar() && crcv_trim.getESChar() == crcv_unescape.getEscapeChar()) { throwAX("constructor: crcv_trim.doUseESChar() equals true, and crcv_trim.getESChar() ('" + crcv_trim.getESChar() + "') equals crcv_unescape.getEscapeChar() ('" + crcv_unescape.getEscapeChar() + "')."); } crcvt = crcv_trim; crcvu = crcv_unescape; sNullValue = s_nullValue; b1stLineWSIsES = b_1stLineWSIsEmptyString; } /**

Get the CRCVTrim for direct manipulation.

@return crcv_trim Exactly as provided to the constructor. **/ public final CRCVTrim getCRCVTrim() { return crcvt; } /**

Get the CRCVUnescape for direct manipulation.

@return crcv_unescape Exactly as provided to the constructor. **/ public final CRCVUnescape getCRCVUnescape() { return crcvu; } /**

Get the special string defined as null.

When the first line of the value of a variable is equal to this, the value is equal to null.

How to make a value literally equal to this string?

For the sake of this documentation section, assume this string and the special empty string character equal their default values ("__NULL__" and '|', respectively).

To make a variable's value literally equal to "__NULL__", you must trim value lines (getCRCVTrim().doTrimVLs() must equal true).

If the empty string character is being used (getCRCVTrim().doUseESChar() equals true), set your variable's value equal to __NU\\|LL__.

If the empty string character is not being used, set the second or subsequent line of the value equal to __NULL__. This method requires that is1stLineWSEmptyString equals false.

@return s_nullValue Exactly as provided to the constructor. **/ public final String getNullValue() { return sNullValue; } /**

If the first line of a variable's value is nothing but whitespace, should it be considered as empty string?

For example, take this variable:

name_of_variable1  =

This

is an "X":  x
and the
value "one":  1

name_of_variable2=  Value of 2

The first line of this variable's value is only spaces or tabs, or nothing (empty string). If this function returns true, you'll get a "stray text found" error, when CRLineAnalyzer attempts to process the "This" line.

If this function returns false, then the value is "...This...is...the...value of 1".

I personally prefer the former: The user gets an error. In order to make the first line of the value have whitespace only, configure CRCVTrim to trim value lines and to use the special empty string character:

name_of_variable1  =		|

This

is a pipe \\|
and the
value of 1

For whitespace on the first line:

name_of_variable1  =		|   		|

This

is a pipe \\|
and the
value of 1
@return b_1stLineWSIsEmptyString Exactly as provided to the constructor. **/ public final boolean is1stLineWSEmptyString() { return b1stLineWSIsES; } /**

Get some information about this CRCVariable.

**/ public String toString() { return this.getClass().getName() + ": getNullValue()='" + getNullValue() + "', is1stLineWSEmptyString()=" + is1stLineWSEmptyString() + ", [" + getCRCVTrim().toString() + "], [" + getCRCVUnescape().toString() + "]"; } }