com.hotaviano.tableexporter.DefaultStringTableParser.java Source code

Java tutorial

Introduction

Here is the source code for com.hotaviano.tableexporter.DefaultStringTableParser.java

Source

/*
 * This software is a html table text convert to conventional formats
 * Copyright (C) 2014  Melo, Hotaviano
 * 
 * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

package com.hotaviano.tableexporter;

import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import org.jdom2.Document;
import org.jdom2.JDOMException;
import org.jdom2.input.SAXBuilder;
import org.jdom2.input.sax.XMLReaderJDOMFactory;
import org.jdom2.input.sax.XMLReaderXSDFactory;

/**
 * Transform html string in JDom Document object.
 *
 * @author Melo, Hotaviano <melo.hotaviano@gmail.com>
 */
public class DefaultStringTableParser implements StringTableParser {

    private final static String XSD_TABLE = "src/main/java/table.xsd";

    @Override
    public Document parse(String table) throws JDOMException, IOException {
        File xsdfile = new File(XSD_TABLE);
        XMLReaderJDOMFactory schemafac = new XMLReaderXSDFactory(xsdfile);
        SAXBuilder builder = new SAXBuilder(schemafac);

        return builder.build(new StringReader(table));
    }

}