Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/**
 * Created by IntelliJ IDEA.
 * User: Piek Vossen
 * Date: 17-dec-2008
 * Time: 14:38:37
 * To change this template use File | Settings | File Templates.
 * This file is part of KafSaxParser.
    
 KafSaxParser 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 3 of the License, or
 (at your option) any later version.
    
 KafSaxParser 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 KafSaxParser.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    static public String getTagContentFromPosition_old(String inputTXT, String tag, int nPosition) {
        String content = "";
        String tagEnd = "</" + tag.toLowerCase() + ">";
        int idx_tagEnd = inputTXT.indexOf(tagEnd, nPosition);
        //       System.out.println("nPosition:"+nPosition);
        //       System.out.println("idx_tagEnd:"+idx_tagEnd);
        if (idx_tagEnd == -1) {
            tagEnd = "</" + tag.toUpperCase() + ">";
            idx_tagEnd = inputTXT.indexOf(tagEnd, nPosition);
        }
        if (idx_tagEnd > nPosition) {
            content = inputTXT.substring(nPosition, idx_tagEnd);
        }
        //          System.out.println("Content is:" + content);
        return content;
    }

    static public String getTagContentFromPosition_old(String inputTXT, String tag) {
        String content = "";
        String tagStart = "<" + tag.toLowerCase() + ">";
        int idx_tagStart = inputTXT.indexOf(tagStart);
        //       System.out.println(tagStart);
        if (idx_tagStart == -1) {
            tagStart = "<" + tag.toUpperCase() + ">";
            idx_tagStart = inputTXT.indexOf(tagStart);
            //         System.out.println(tagStart);
        }
        if (idx_tagStart == -1) {
            tagStart = "<" + tag.toLowerCase() + " ";
            idx_tagStart = inputTXT.indexOf(tagStart);
            //          System.out.println(tagStart);
        }
        if (idx_tagStart == -1) {
            tagStart = "<" + tag.toUpperCase() + " ";
            idx_tagStart = inputTXT.indexOf(tagStart);
            //         System.out.println(tagStart);
        }
        if (idx_tagStart == -1) {
            tagStart = "<" + tag.toLowerCase() + "\t";
            idx_tagStart = inputTXT.indexOf(tagStart);
            //          System.out.println(tagStart);
        }
        if (idx_tagStart == -1) {
            tagStart = "<" + tag.toUpperCase() + "\t";
            idx_tagStart = inputTXT.indexOf(tagStart);
            //         System.out.println(tagStart);
        }
        if (idx_tagStart != -1) {
            int idx_contentStart = inputTXT.indexOf(">", idx_tagStart);
            if (idx_contentStart != -1) {
                String tagEnd = "</" + tag.toLowerCase() + ">";
                int idx_tagEnd = inputTXT.indexOf(tagEnd, idx_contentStart);
                if (idx_tagEnd == -1) {
                    tagEnd = "</" + tag.toUpperCase() + ">";
                    idx_tagEnd = inputTXT.indexOf(tagEnd, idx_contentStart);
                }
                if (idx_tagEnd != -1) {
                    content = inputTXT.substring(idx_contentStart + 1, idx_tagEnd);
                }
            }
        }
        //      System.out.println("Content is:" + content);
        return content;
    }
}