/*

Derby - Class org.apache.derbyDemo.vtis.example.PropertyFileVTI

Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements.  See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License.  You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

*/

package org.apache.derbyDemo.vtis.example;

import java.io.*;
import java.sql.*;
import java.text.SimpleDateFormat;

import org.apache.derbyDemo.vtis.core.*;

/**
 * <p>
 * This VTI makes a table out of a property file.
 * </p>
 */
public    class   PropertyFileVTI  extends FlatFileVTI
{
    ///////////////////////////////////////////////////////////////////////////////////
    //
    // CONSTANTS
    //
    ///////////////////////////////////////////////////////////////////////////////////

    private static  final   String[]    COLUMN_NAMES =
    {
        "propKey", "propValue"
    };

    private static  final   int PROPERTY_KEY = 0;
    private static  final   int PROPERTY_VALUE = PROPERTY_KEY + 1;

    ///////////////////////////////////////////////////////////////////////////////////
    //
    // STATE
    //
    ///////////////////////////////////////////////////////////////////////////////////
    
    ///////////////////////////////////////////////////////////////////////////////////
    //
    // CONSTRUCTORS
    //
    ///////////////////////////////////////////////////////////////////////////////////

    /**
     * <p>
     * Build a PropertyFileVTI given the name of a Derby message file in the
     * source tree.
     * </p>
     */
    public  PropertyFileVTI( String propertyFileName )
    {
        super( COLUMN_NAMES, propertyFileName );
    }

    ///////////////////////////////////////////////////////////////////////////////////
    //
    // TABLE FUNCTION METHOD
    //
    ///////////////////////////////////////////////////////////////////////////////////


    /**
     * <p>
     * This is the method which is registered as a table function.
     * </p>
     */
    public  static  ResultSet   propertyFileVTI( String propertyFileName )
        throws SQLException
    {
        return new PropertyFileVTI( propertyFileName );
    }

    ///////////////////////////////////////////////////////////////////////////////////
    //
    // FlatFileVTI BEHAVIOR TO BE IMPLEMENTED BY SUBCLASSES
    //
    ///////////////////////////////////////////////////////////////////////////////////

    /**
     * <p>
     * Parse the next chunk of text, using readLine(), and return the next row.
     * Returns null if the file is exhausted.
     * </p>
     */
    protected  String[]  parseRow( ) throws SQLException
    {
        String[]    newRow = new String[ COLUMN_NAMES.length ];
        String      nextLine = null;

        while( true )
        {
            nextLine = readLine();

            // if at EOF, get out of here
            if ( nextLine == null ) { return null; }

            nextLine = nextLine.trim();

            // skip blank lines and lines which start with the comment character
            if ( nextLine.startsWith( "#" ) ) { continue; }
            else if ( nextLine.length() == 0 ) { continue; }
            else { break; }
        }

        int         equalsIdx = nextLine.indexOf( '=' );

        try {
            newRow[ PROPERTY_KEY ] = nextLine.substring( 0, equalsIdx );
            newRow[ PROPERTY_VALUE ] = nextLine.substring( equalsIdx, nextLine.length() );
        }
        catch (Throwable t)
        {
            SQLException    se = new SQLException
                (
                 "Unparseable line number " + getLineNumber() + " in file " + getTextFileName() + ": " + nextLine
                 );
            se.initCause( t );

            throw se;
        }

        return newRow;
    }

    ///////////////////////////////////////////////////////////////////////////////////
    //
    // ResultSet METHODS
    //
    ///////////////////////////////////////////////////////////////////////////////////

    ///////////////////////////////////////////////////////////////////////////////////
    //
    // MINIONS
    //
    ///////////////////////////////////////////////////////////////////////////////////


}

@@ -3803,16 +3803,68 @@
   try %7B%0A
+            if ( equalsIdx %3E= 0 )%0A            %7B%0A    
         
@@ -3932,32 +3932,36 @@
  );%0A            
+  
+  
 newRow%5B PROPERTY
@@ -4019,24 +4019,181 @@
 length() );%0A
+            %7D%0A            else%0A            %7B%0A                newRow%5B PROPERTY_KEY %5D = nextLine;%0A                newRow%5B PROPERTY_VALUE %5D = %22%22;%0A            %7D%0A
         %7D%0A  

Improve vti which parses property files - don't choke on lines which don't have an = in them as occurs in the message properties for DRDA in 10.2 and 10.3.