Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/* gvSIG. Geographic Information System of the Valencian Government
 *
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
 * of the Valencian Government (CIT)
 * 
 * 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.
 * 
 */

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

import org.w3c.dom.Document;

public class Main {
    /**
     * Transforms a memory document with XML format into another with HTML
     * format according an XSL file, and stores it in a file
     * 
     * @param doc
     *            The document to read
     * @param htmlFile
     *            The name of the output (HTML) file
     * @param xslFile
     *            The name of the XSL file which allows transform XML into HTML
     *            according its style
     * 
     * @throws FileNotFoundException
     *             java.io.FileNotFoundException
     * @throws TransformerException
     *             javax.xml.transform.TransformerException
     */
    public static void write_DOM_into_an_HTML_file(Document doc, String htmlFile, String xslFile)
            throws FileNotFoundException, TransformerException {
        // An instance of a object transformer factory
        TransformerFactory tFactory = TransformerFactory.newInstance();

        // Creates the output file
        File SalidaHTML = new File(htmlFile);

        // Associates the file to a file output stream
        FileOutputStream os = new FileOutputStream(SalidaHTML);

        // Creates a transformer object associated to the XSL file
        Transformer transformer = tFactory.newTransformer(new StreamSource(xslFile));

        // Holds a tree with the information of a document in the form of a DOM
        // tree
        DOMSource sourceId = new DOMSource(doc);

        // Makes the transformation from the source in XML to the output in HML
        // according the transformer in XSL
        transformer.transform(sourceId, new StreamResult(os));
    }
}