Skip to content

Commit a2b4bc4

Browse files
committed
Add module-info.java
1 parent 3d0f606 commit a2b4bc4

File tree

7 files changed

+21
-19
lines changed

7 files changed

+21
-19
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ The utilities work on any XML files; they are not XML-schema aware. Element orde
99
### XML Patch Operations
1010
These utilities make use of a difference format conformant to standard "An Extensible Markup Language (XML) Patch Operations Framework Utilizing XML Path Language (XPath) Selectors", [IETF RFC 5261](https://tools.ietf.org/html/rfc5261). Another benefit of these utilities, aside from editing Orchestra files, is that they can be used for HTTP PATCH operations with XML payloads.
1111

12-
The path format has no way to show moves. If element order is considered, then a move will be displayed as an add and remove.
12+
The patch format has no way to show moves. If element order is considered, then a move will be displayed as an add and remove.
1313

1414
## Difference
1515

src/main/java/io/fixprotocol/xml/PatchOpsListener.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.io.OutputStream;
1919
import java.io.OutputStreamWriter;
2020
import java.nio.charset.Charset;
21+
import java.nio.charset.StandardCharsets;
2122
import java.util.concurrent.atomic.AtomicBoolean;
2223

2324
import javax.xml.parsers.DocumentBuilder;
@@ -59,7 +60,7 @@ public class PatchOpsListener implements XmlDiffListener {
5960
*/
6061
public PatchOpsListener(OutputStream out)
6162
throws IOException, ParserConfigurationException, TransformerConfigurationException {
62-
writer = new OutputStreamWriter(out, Charset.forName("UTF-8"));
63+
writer = new OutputStreamWriter(out, StandardCharsets.UTF_8);
6364

6465
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
6566
dbFactory.setNamespaceAware(true);

src/main/java/io/fixprotocol/xml/RepositoryDiffReporter.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public RepositoryDiffReporter() throws TransformerConfigurationException {
4242
super();
4343
}
4444

45-
class HtmlDiffListener implements XmlDiffListener {
45+
static class HtmlDiffListener implements XmlDiffListener {
4646

4747
private boolean headerGenerated = false;
4848
private boolean firstRow = true;
@@ -181,10 +181,10 @@ public static void main(String[] args) throws Exception {
181181
} else {
182182
RepositoryDiffReporter tool = new RepositoryDiffReporter();
183183
try (
184-
HtmlDiffListener aListener = tool.new HtmlDiffListener(
185-
args.length > 2 ? new FileOutputStream(args[2]) : System.out);
186-
InputStream is1 = new FileInputStream(args[0]);
187-
InputStream is2 = new FileInputStream(args[1])) {
184+
HtmlDiffListener aListener = new HtmlDiffListener(
185+
args.length > 2 ? new FileOutputStream(args[2]) : System.out);
186+
InputStream is1 = new FileInputStream(args[0]);
187+
InputStream is2 = new FileInputStream(args[1])) {
188188
tool.setListener(aListener);
189189
tool.diff(is1, is2);
190190
}

src/main/java/io/fixprotocol/xml/XmlDiff.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,21 +144,18 @@ public void diff(InputStream is1, InputStream is2) throws Exception {
144144
Objects.requireNonNull(is1, "First input stream cannot be null");
145145
Objects.requireNonNull(is2, "Second input stream cannot be null");
146146

147-
try {
147+
try (is1; is2) {
148148
final Document doc1 = parse(is1);
149149
final Element root1 = doc1.getDocumentElement();
150150
final Document doc2 = parse(is2);
151151
final Element root2 = doc2.getDocumentElement();
152152

153153
if (!diffElements(root1, root2)) {
154154
System.err.format("Not comparing same root nodes; %s %s%n", XpathUtil.getFullXPath(root1),
155-
XpathUtil.getFullXPath(root2));
155+
XpathUtil.getFullXPath(root2));
156156
System.exit(1);
157157
}
158158
listener.close();
159-
} finally {
160-
is1.close();
161-
is2.close();
162159
}
163160
}
164161

src/main/java/io/fixprotocol/xml/XpathUtil.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ final class XpathUtil {
3434
public static String getAttribute(String xpath) {
3535
Objects.requireNonNull(xpath, "Xpath cannot be null");
3636
String[] fields = xpath.split("/");
37-
if (fields == null || fields.length == 0) {
37+
if (fields.length == 0) {
3838
return "";
3939
}
4040
if (fields[fields.length - 1].startsWith("@")) {
@@ -47,7 +47,7 @@ public static String getAttribute(String xpath) {
4747
public static String getElementLocalName(String xpath) {
4848
Objects.requireNonNull(xpath, "Xpath cannot be null");
4949
String[] fields = xpath.split("/");
50-
if (fields == null || fields.length == 0) {
50+
if (fields.length == 0) {
5151
return "";
5252
}
5353
for (int i = fields.length - 1; i >= 0; i--) {
@@ -64,7 +64,7 @@ public static String getElementLocalName(String xpath) {
6464
public static String getElementPredicate(String xpath) {
6565
Objects.requireNonNull(xpath, "Xpath cannot be null");
6666
String[] fields = xpath.split("/");
67-
if (fields == null || fields.length == 0) {
67+
if (fields.length == 0) {
6868
return "";
6969
}
7070
for (int i = fields.length - 1; i >= 0; i--) {
@@ -196,7 +196,7 @@ static String getQualifiedNodeName(Node node) {
196196
public static String getParentLocalName(String xpath) {
197197
Objects.requireNonNull(xpath, "Xpath cannot be null");
198198
String[] fields = xpath.split("/");
199-
if (fields == null || fields.length == 0) {
199+
if (fields.length == 0) {
200200
return "";
201201
}
202202
boolean elementFound = false;
@@ -218,7 +218,7 @@ public static String getParentLocalName(String xpath) {
218218
public static String getParentPredicate(String xpath) {
219219
Objects.requireNonNull(xpath, "Xpath cannot be null");
220220
String[] fields = xpath.split("/");
221-
if (fields == null || fields.length == 0) {
221+
if (fields.length == 0) {
222222
return "";
223223
}
224224
boolean elementFound = false;
@@ -244,7 +244,7 @@ public static String getParentPredicate(String xpath) {
244244
public static boolean isAttribute(String xpath) {
245245
Objects.requireNonNull(xpath, "Xpath cannot be null");
246246
String[] fields = xpath.split("/");
247-
return !(fields == null || fields.length == 0) && fields[fields.length - 1].startsWith("@");
247+
return !(fields.length == 0) && fields[fields.length - 1].startsWith("@");
248248
}
249249

250250

src/main/java/module-info.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module diff.merge {
2+
requires java.xml;
3+
requires Saxon.HE;
4+
}

src/test/java/io/fixprotocol/xml/RepositoryDiffReporterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static void setupOnce() throws Exception {
3737
@BeforeEach
3838
public void setUp() throws Exception {
3939
tool = new RepositoryDiffReporter();
40-
RepositoryDiffReporter.HtmlDiffListener aListener = tool.new HtmlDiffListener(new FileOutputStream(DIFF_FILENAME));
40+
RepositoryDiffReporter.HtmlDiffListener aListener = new RepositoryDiffReporter.HtmlDiffListener(new FileOutputStream(DIFF_FILENAME));
4141
tool.setListener(aListener);
4242
}
4343

0 commit comments

Comments
 (0)