⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 valueprintingreport.java

📁 java编写的OCR软件
💻 JAVA
字号:
package de.spieleck.app.jacson.report;

import java.util.ListIterator;
import java.util.StringTokenizer;

import de.spieleck.config.ConfigNode;

import de.spieleck.app.jacson.JacsonConfigException;

/**
 * This report only prints values of the structured data.
 * It does not print the structured adresses. Additionall
 * you can specify a path, what to print. This is most
 * heavily used in jobs which modify a file and do not
 * need all the surrounding structure.
 * @author fsn
 */
public class ValuePrintingReport
    extends PrintingReport
{
    public final static String DEBUG_NODE = "debug";
    public final static String SECTION_NODE = "section";

    protected String[] secs = null;
    protected boolean debug;

    public ValuePrintingReport()
    {
    }

    public void init(ConfigNode config)
        throws JacsonConfigException
    {
        super.init(config);
        debug = config.getBoolean(DEBUG_NODE, false);
        String sec = config.getString(SECTION_NODE, null);
        if ( sec != null )
        {
            StringTokenizer tok = new StringTokenizer(sec,"/");
            int n = tok.countTokens();
            int i = n;
            secs = new String[n];
            while ( i > 0 )
                secs[--i]  = tok.nextToken();
            if ( debug )
                System.err.println(" * n= "+n+" "+sec);
        }
    }

    public boolean accept(ConfigNode node)
    {
        String name = node.getName();
        return name.equals(DEBUG_NODE)
            || name.equals(SECTION_NODE)
            || super.accept(node);
    }

    public void report(String localName, String value)
    {
        if ( secs == null || sectionMatch(localName) )
            pw.println(value);
        pw.flush();
    }

    public boolean sectionMatch(String localName)
    {
        if ( !localName.equals(secs[0]) ) 
            return false;
        ListIterator li = begins.listIterator(begins.size());
        int i = 1;
        while ( i < secs.length && li.hasPrevious() )
        {
            String s = (String) li.previous();
            if ( debug )
                System.err.println("vpr "+(s.equals(secs[i]))+" "+i+" "+secs[i]+" "+s);
            if ( !s.equals(secs[i]) )
            {
                if ( debug )
                    System.err.println("vpr != i="+i+" "+s+" != "+secs[i]);
                return false;
            }
            i++;
        }
        if ( debug )
            System.err.println("vpr i="+i+" length="+secs.length);
        return i >= secs.length;
    }
}
//
//    Jacson - Text Filtering with Java.
//    Copyright (C) 2002 Frank S. Nestel (nestefan -at- users.sourceforge.net)
//
//    This library is free software; you can redistribute it and/or
//    modify it under the terms of the GNU Lesser General Public
//    License as published by the Free Software Foundation; either
//    version 2.1 of the License, or (at your option) any later version.
//
//    This library 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
//    Lesser General Public License for more details.
//
//    You should have received a copy of the GNU Lesser General Public
//    License along with this library; if not, write to the Free Software
//    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -