view src/kryshen/tema/TemplateReader.java @ 1:548a93c24e55 release_0_1jk

Tema 0.1jk - Javakonkurs edition (imported from CVS).
author Mikhail Kryshen <mikhail@kryshen.net>
date Thu, 14 Dec 2006 23:22:05 +0300
parents
children
line wrap: on
line source

/*
 *  Copyright (C) 2006 Mikhail A. Kryshen
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *  $Id: TemplateReader.java,v 1.5 2006/12/14 14:39:22 mikhail Exp $
 */

package kryshen.tema;

import java.io.Reader;
import java.io.LineNumberReader;
import java.io.FilterReader;
import java.io.IOException;

/**
 * Reader for TEMA templates. Stores data source name (commonly
 * filename) and tracks line numbers for error reporting.
 *
 * @author Mikhail A. Kryshen
 */
public class TemplateReader extends FilterReader {
    private String source = null;

    private LineNumberReader lnReader = null;
    private TemplateReader parentReader = null;

    public TemplateReader(LineNumberReader in, String source) {
        super(in);
        this.lnReader = in;
        this.source = source;
    }

    public TemplateReader(Reader in, TemplateReader parent) {
        super(in);
        this.source = source;
    }

    public String getSource() {
        if (source != null)
            return source;
        
        return parentReader.getSource();
    }
    
    public int getLineNumber() {
        if (lnReader != null)
            return lnReader.getLineNumber();
        
        return parentReader.getLineNumber();
    }
}