2
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
25
import java.io.BufferedOutputStream;
27
import java.io.FileOutputStream;
28
import java.io.IOException;
29
import java.io.OutputStream;
30
import java.util.ArrayList;
33
import javax.xml.parsers.DocumentBuilder;
34
import javax.xml.parsers.DocumentBuilderFactory;
35
import javax.xml.parsers.ParserConfigurationException;
36
import javax.xml.transform.Transformer;
37
import javax.xml.transform.TransformerException;
38
import javax.xml.transform.TransformerFactory;
39
import javax.xml.transform.dom.DOMSource;
40
import javax.xml.transform.stream.StreamSource;
41
import javax.xml.transform.stream.StreamResult;
43
import org.xml.sax.ErrorHandler;
44
import org.xml.sax.SAXException;
45
import org.xml.sax.SAXParseException;
46
import org.w3c.dom.Document;
47
import org.w3c.dom.DOMException;
51
private static final int EXIT_FAILURE_ERROR = 1;
52
private static final int EXIT_FAILURE_BADARGUMENTS = 2;
54
private static boolean verbose = false;
57
* Write out usage and exit.
59
private static void showUsage() {
60
System.err.println("usage:");
61
System.err.println(" java jvmtiGen " +
63
"-IN <input XML file name> " +
65
"-OUT <output file name> " +
66
"[-PARAM <name> <expression> ...]");
67
System.exit(EXIT_FAILURE_BADARGUMENTS); // There is no returning from showUsage()
70
public static void main (String argv []) {
71
String inFileName = null;
72
String xslFileName = null;
73
String outFileName = null;
74
final List<String> params = new ArrayList<String>();
75
for (int ii = 0; ii < argv.length; ii++) {
76
if (argv[ii].equals("-verbose")) {
78
} else if (argv[ii].equals("-IN")) {
79
inFileName = argv[++ii];
80
} else if (argv[ii].equals("-XSL")) {
81
xslFileName = argv[++ii];
82
} else if (argv[ii].equals("-OUT")) {
83
outFileName = argv[++ii];
84
} else if (argv[ii].equals("-PARAM")) {
85
if (ii + 2 < argv.length) {
86
final String name = argv[++ii];
88
final String expression = argv[++ii];
89
params.add(expression);
97
if (inFileName == null || xslFileName == null || outFileName == null) {
101
final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
103
factory.setNamespaceAware(true);
104
factory.setValidating(true);
105
factory.setXIncludeAware(true);
107
final File datafile = new File(inFileName);
108
final File stylesheet = new File(xslFileName);
111
final OutputStream os = new BufferedOutputStream(new FileOutputStream(outFileName));
113
final StreamSource stylesource = new StreamSource(stylesheet);
114
// Use a Transformer for output
115
final Transformer transformer =
116
TransformerFactory.newInstance().newTransformer(stylesource);
117
for (int ii = 0; ii < params.size(); ii += 2) {
118
transformer.setParameter(params.get(ii), params.get(ii + 1));
120
final DocumentBuilder builder = factory.newDocumentBuilder();
121
builder.setErrorHandler(new ErrorHandler() {
122
public void fatalError(SAXParseException exn) throws SAXException {
123
throw new SAXException(exn);
125
public void error(SAXParseException exn) throws SAXException {
128
public void warning(SAXParseException exn) throws SAXException {
130
System.err.println("jvmtiGen warning: " + exn.getMessage());
134
final Document document = builder.parse(datafile);
135
final DOMSource source = new DOMSource(document);
136
final StreamResult result = new StreamResult(os);
137
transformer.transform(source, result);
139
| ParserConfigurationException
141
| TransformerException exn) {
142
System.err.print("jvmtiGen error: " + exn.getMessage());
143
exn.printStackTrace(System.err);
144
System.exit(EXIT_FAILURE_ERROR);