import java.util.ArrayList; import java.io.BufferedReader; import java.io.FileReader; /** * This class holds the data from a Property file. **/ public class propertyFile { // ----- Private Fields ----- /** *Comments from the file */ private String comment; /** * Delimiter for individual fields */ private String fieldDelimiter; // was char /** * Delimiter for each row */ private String rowDelimiter; /** * Root element to use for output XML */ private String xmlRootName; /** * Element to use for each row */ private String recordName; /** *How many fields are there - Note: This is 1 based, not zero based. */ private int fieldCount; /** * array of fields */ private ArrayList fields = new ArrayList(88); /** *Set to int > 0 for debug output */ private int debug=0; /** A single instance of this will hold all the relavant details for ONE PropertyFile. *@param filePath String name of the property file. * * **/ public propertyFile(String filePath) { //StreamReader reader = new StreamReader( filePath ); try { BufferedReader reader = new BufferedReader (new FileReader (filePath)); String line = null; while ( (line = reader.readLine()) != null ) { if ( line.length() != 0 ) //was != "" { if (debug> 0) System.err.println("String is: " + line + "lth: " + line.length()); if ( line.charAt(0) != '[' && !( line.startsWith("//") ) ) { String propertyValue = line.split("=")[1]; // Assign Comment if ( line.toUpperCase().startsWith("COMMENT=") ) this.comment = propertyValue; // Assign Field Delimter if ( line.toUpperCase().startsWith("FIELDDELIMITER") ) this.fieldDelimiter = propertyValue.substring(0); // Assign Row Delimiter if ( line.toUpperCase().startsWith("ROWDELIMITER") ) { if ( propertyValue.substring(0,1).toUpperCase() == "\\" && propertyValue.toUpperCase().charAt(1) == 'N') this.rowDelimiter = "\r\n"; else this.rowDelimiter = propertyValue; } // Assign Root Document Name if ( line.toUpperCase().startsWith("ROOTNAME") ) this.xmlRootName = propertyValue; // Assign Record Name if ( line.toUpperCase().startsWith("RECORDNAME") ) this.recordName = propertyValue; // Assign Field Count if ( line.toUpperCase().startsWith("FIELDS") ) this.fieldCount = Integer.parseInt(propertyValue); } else { if ( line.toUpperCase().startsWith("[FIELDS]") ) { while ( (line = reader.readLine()) != null ) { if ( line.length() == 0) break; else{ if (debug > 0) System.err.println("Adding: "+line.split("=")[1]); this.fields.add( line.split("=")[1] ); } } break; } } } } reader.close(); } catch (java.io.IOException e) { System.out.println("**** IO Error on input file. Quitting"); System.exit(2); } } /** * Return the comment int the property file *@return String, the comment value, if any */ public String comment () { return this.comment; } /** * The delimiter to be used for each field, often comma. *@return String, the character(s) */ public String fieldDelimiter() { return this.fieldDelimiter; } /** /** * Row Delimiter - often '\n' *@return String, the character(s) */ public String rowDelimiter () { return this.rowDelimiter; } /** * The XML document root node. * @return String, the element name **/ public String XMLRootName() { return this.xmlRootName; } /** ** The node name for each record **/ public String recordName() { return this.recordName; } /** ** Number of Fields per record/node *@return integer count of number of fields, 1 based. **/ public int fields() { return this.fieldCount; } // ----- Public Methods ----- /** ** The value of the nth field, 0 based. ** ** @param index Which field to return * @return String the field value **/ public String fieldNames(int index) { if (index ") ; System.exit (1) ; } propertyFile p = new propertyFile(argv[0]); } }