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 getValue(String text) {
        String value = "";
        int idx_s = text.indexOf(">");
        int idx_e = text.indexOf("</");
        if (idx_e > idx_s) {
            value = text.substring(idx_s + 1, idx_e);
        }
        return cleanValue(value);
    }

    static public String cleanValue(String value) {
        String cleanValue = value;
        if (value.startsWith("\"")) {
            cleanValue = value.substring(1);
        }
        if (value.endsWith("\"")) {
            cleanValue = cleanValue.substring(0, cleanValue.length() - 1);
        }
        if (cleanValue.startsWith("<![CDATA[") && cleanValue.endsWith("]]>")) {
            cleanValue = cleanValue.substring(9, cleanValue.length() - 3);
        }
        return cleanValue.trim();
    }
}