/* 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_examples.config; import xbn.programs.XBNStatic; import xbn.array.VWObject; import xbn.config.ConfigReaderFA; import xbn.config.UtilConfig; import xbn.output.OSysDotOut; import xbn.placeholder.sb_sb_c; import xbn.string.UtilString; import xbn.string.FLRString; import xbn.config.ConfigFormatException; /**

Demonstrates ConfigReaderFA, where the variable values in the source text are all single-line.

Source code:  XmplConfigReaderFA_SL.java

The source text

Each line is surrounded by single quotes (') for clarity. They are not in the actual source text.
'{'
         '	Multiple'
         '		line'
         '			comment'
         '}'
         ''
         ''
         'one=		|		Value of one\\=*this*  :'  )'
         '	two=        |     Value of two            |'
         'three=		Value of three'
         ''
         '# Empty string value'
         'four='
         ''
         ''
         '# Empty string value, version 2'
         'five=			|'
         ''
         '# Null'
         'six=		__NULL__'
@version 0.9b @author Jeff Epstein, http://sourceforge.net/projects/xbnjava. **/ public class XmplConfigReaderFA_SL extends XBNStatic { private static final String sLS = sLINE_SEP; private static final String sSOURCE_TEXT = "{" + sLS + " Multiple" + sLS + " line" + sLS + " comment" + sLS + "}" + sLS + sLS + sLS + "one= | Value of one\\=*this* :' )" + sLS + " two= | Value of two |" + sLS + "three= Value of three" + sLS + sLS + "# Empty string value" + sLS + "four=" + sLS + sLS + sLS + "# Empty string value, version 2" + sLS + "five= |" + sLS + sLS + "# Null" + sLS + "six= __NULL__"; public static void main(String[] as_cmdLineParams) { sopl("XmplConfigReaderFA_SL...START"); sopl("SOURCE TEXT: \n--------------\n" + sSOURCE_TEXT + "\n--------------\n\n\n"); FLRString flrsSourceText = new FLRString(sSOURCE_TEXT); UtilConfig uConfig = new UtilConfig(); sb_sb_c[] aSbsbc = null; try { ConfigReaderFA crfa = new ConfigReaderFA(); //Debugging output: VWObject vwo = crfa.getVWObject(flrsSourceText, (new OSysDotOut())); //No debugging output: //VWObject vwo = crfa.getVWObject(flrsSourceText); aSbsbc = uConfig.getAOsb_sb_c(vwo, true); } catch(ConfigFormatException cfx) { sopl("...ERROR: " + cfx.toString()); return; } //------------------------------ //Reading in variables example: ABOVE //Printing out variables example: BELOW //------------------------------ if(aSbsbc.length < 1) { sopl("ZERO VARIABLES IN SOURCE TEXT"); return; } else { sopl(sLS + sLS + "Variables:"); } UtilString uStr = new UtilString(); for(int i = 0; i < aSbsbc.length; i++) { //Get the value String sValue = null; if(aSbsbc[i].sb2 != null) { //and display hidden characters, and surround it //with square brackets. This makes it absolutely //clear what the value is. sValue = "[" + uStr.getVisible(aSbsbc[i].sb2.toString()) + "]"; } sopl(sLS + "NAME='" + aSbsbc[i].sb1 + "' (delimiter='" + aSbsbc[i].c + "')" + sLS + "VALUE=" + sValue); } sopl("XmplConfigReaderFA_SL...END"); } }