Skip to content

Commit 6478ba9

Browse files
Patrick Reinhartthegreystone
Patrick Reinhart
authored andcommittedMay 28, 2021
7258: Use the public XLST classes for the release notes
Reviewed-by: hirt
1 parent b273c96 commit 6478ba9

File tree

1 file changed

+78
-2
lines changed
  • releng/tools/org.openjdk.jmc.util.releasenotes/src/org/openjdk/jmc/utils/releasenotes

1 file changed

+78
-2
lines changed
 

‎releng/tools/org.openjdk.jmc.util.releasenotes/src/org/openjdk/jmc/utils/releasenotes/Transform.java

+78-2
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,91 @@
3232
*/
3333
package org.openjdk.jmc.utils.releasenotes;
3434

35-
import com.sun.org.apache.xalan.internal.xslt.Process;
35+
import static java.nio.file.Files.exists;
36+
import static java.nio.file.Files.newInputStream;
37+
import static java.nio.file.Files.newOutputStream;
38+
39+
import java.io.IOException;
40+
import java.io.InputStream;
41+
import java.io.OutputStream;
42+
import java.nio.file.Path;
43+
import java.nio.file.Paths;
44+
import java.util.ArrayDeque;
45+
import java.util.Arrays;
46+
import java.util.Deque;
47+
48+
import javax.xml.transform.TransformerException;
49+
import javax.xml.transform.TransformerFactory;
50+
import javax.xml.transform.stream.StreamResult;
51+
import javax.xml.transform.stream.StreamSource;
3652

3753
/**
3854
* Wrapper for Xalan to do an XSLT. Used to generate the release notes HTML.
3955
* <p>
4056
* Example: Transform -IN notes.xml -XSL stylesheet.xsl -OUT new_and_noteworthy.html
4157
*/
4258
public class Transform {
59+
4360
public static void main(String[] args) {
44-
Process._main(args);
61+
final Deque<String> deque = new ArrayDeque<>(Arrays.asList(args));
62+
Path inputFile = null;
63+
Path outputFile = null;
64+
Path sylesheetFile = null;
65+
while (!deque.isEmpty()) {
66+
switch (deque.poll()) {
67+
case "-IN":
68+
inputFile = checkedToPath(deque.poll(), "input file", true);
69+
break;
70+
case "-OUT":
71+
outputFile = checkedToPath(deque.poll(), "output file", false);
72+
break;
73+
case "-XSL":
74+
sylesheetFile = checkedToPath(deque.poll(), "stylesheet file", true);
75+
break;
76+
default:
77+
break;
78+
}
79+
}
80+
if (inputFile != null && outputFile != null && sylesheetFile != null) {
81+
try {
82+
transform(inputFile, outputFile, sylesheetFile);
83+
System.exit(0);
84+
} catch (IOException | TransformerException e) {
85+
e.printStackTrace();
86+
System.exit(1);
87+
}
88+
} else {
89+
usage();
90+
System.exit(1);
91+
}
92+
}
93+
94+
private static void usage() {
95+
System.out.println("Usage: Transform -IN <input file> -XSL <stylesheet file> -OUT <output file>");
96+
}
97+
98+
private static Path checkedToPath(String arg, String fileDescription, boolean isInputFile) {
99+
if (arg == null) {
100+
System.err.format("%s not given", fileDescription).println();
101+
} else {
102+
Path file = Paths.get(arg);
103+
if (isInputFile && exists(file)) {
104+
return file;
105+
} else {
106+
System.err.format("%s '%s' not found", fileDescription, file).println();
107+
}
108+
}
109+
return null;
110+
}
111+
112+
private static void transform(Path inputFile, Path outputFile, Path sylesheetFile)
113+
throws IOException, TransformerException {
114+
TransformerFactory transformerFactory = TransformerFactory.newInstance();
115+
try (InputStream xslIn = newInputStream(sylesheetFile);
116+
InputStream in = newInputStream(inputFile);
117+
OutputStream out = newOutputStream(outputFile)) {
118+
transformerFactory.newTransformer(new StreamSource(xslIn)).transform(new StreamSource(in),
119+
new StreamResult(out));
120+
}
45121
}
46122
}

0 commit comments

Comments
 (0)
Please sign in to comment.