Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * The following methods come from a library written by Tom Fennelly.
 * Here was the header of the licence.
 */

import java.io.IOException;

import java.lang.reflect.Constructor;

import java.util.HashMap;

import java.util.Map;
import java.util.Properties;

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.URIResolver;

import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMResult;

import org.w3c.dom.*;

public class Main {
    public static Node applyXslToDocument2(Source xslt, Source doc, URIResolver resolver,
            Properties transformerProperties, HashMap<String, String> params)
            throws ClassNotFoundException, IllegalAccessException, InstantiationException, IOException,
            NoSuchMethodException, TransformerConfigurationException, TransformerException {
        return (applyXslToDocument2(xslt, doc, resolver, transformerProperties, params, null));
    }

    public static Node applyXslToDocument2(Source xslt, Source doc, URIResolver resolver,
            Properties transformerProperties, HashMap<String, String> params, String transformerClassName)
            throws ClassNotFoundException, IllegalAccessException, InstantiationException, IOException,
            NoSuchMethodException, TransformerConfigurationException, TransformerException {
        TransformerFactory transformerFactory = null;
        if (transformerClassName == null)
            transformerFactory = TransformerFactory.newInstance();
        else {
            Class transformerClass = Class.forName(transformerClassName);
            Constructor defaultConstructor = transformerClass.getConstructor(null);
            transformerFactory = (TransformerFactory) transformerClass.newInstance();
        }

        if (resolver != null)
            transformerFactory.setURIResolver(resolver);

        Transformer transformer = transformerFactory.newTransformer(xslt);
        if (transformerFactory != null)
            transformer.setOutputProperties(transformerProperties);

        if (params != null) {
            for (Map.Entry<String, String> cursor : params.entrySet()) {
                transformer.setParameter(cursor.getKey(), cursor.getValue());
            }
        }

        DOMResult result = new DOMResult();
        transformer.transform(doc, result);

        return (result.getNode());
    }
}