Skip to content

Commit

Permalink
Add module-info.java
Browse files Browse the repository at this point in the history
  • Loading branch information
donmendelson committed Aug 13, 2019
1 parent 3d0f606 commit a2b4bc4
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The utilities work on any XML files; they are not XML-schema aware. Element orde
### XML Patch Operations
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.

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.
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.

## Difference

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/io/fixprotocol/xml/PatchOpsListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.atomic.AtomicBoolean;

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

DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
dbFactory.setNamespaceAware(true);
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/io/fixprotocol/xml/RepositoryDiffReporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public RepositoryDiffReporter() throws TransformerConfigurationException {
super();
}

class HtmlDiffListener implements XmlDiffListener {
static class HtmlDiffListener implements XmlDiffListener {

private boolean headerGenerated = false;
private boolean firstRow = true;
Expand Down Expand Up @@ -181,10 +181,10 @@ public static void main(String[] args) throws Exception {
} else {
RepositoryDiffReporter tool = new RepositoryDiffReporter();
try (
HtmlDiffListener aListener = tool.new HtmlDiffListener(
args.length > 2 ? new FileOutputStream(args[2]) : System.out);
InputStream is1 = new FileInputStream(args[0]);
InputStream is2 = new FileInputStream(args[1])) {
HtmlDiffListener aListener = new HtmlDiffListener(
args.length > 2 ? new FileOutputStream(args[2]) : System.out);
InputStream is1 = new FileInputStream(args[0]);
InputStream is2 = new FileInputStream(args[1])) {
tool.setListener(aListener);
tool.diff(is1, is2);
}
Expand Down
7 changes: 2 additions & 5 deletions src/main/java/io/fixprotocol/xml/XmlDiff.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,18 @@ public void diff(InputStream is1, InputStream is2) throws Exception {
Objects.requireNonNull(is1, "First input stream cannot be null");
Objects.requireNonNull(is2, "Second input stream cannot be null");

try {
try (is1; is2) {
final Document doc1 = parse(is1);
final Element root1 = doc1.getDocumentElement();
final Document doc2 = parse(is2);
final Element root2 = doc2.getDocumentElement();

if (!diffElements(root1, root2)) {
System.err.format("Not comparing same root nodes; %s %s%n", XpathUtil.getFullXPath(root1),
XpathUtil.getFullXPath(root2));
XpathUtil.getFullXPath(root2));
System.exit(1);
}
listener.close();
} finally {
is1.close();
is2.close();
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/main/java/io/fixprotocol/xml/XpathUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ final class XpathUtil {
public static String getAttribute(String xpath) {
Objects.requireNonNull(xpath, "Xpath cannot be null");
String[] fields = xpath.split("/");
if (fields == null || fields.length == 0) {
if (fields.length == 0) {
return "";
}
if (fields[fields.length - 1].startsWith("@")) {
Expand All @@ -47,7 +47,7 @@ public static String getAttribute(String xpath) {
public static String getElementLocalName(String xpath) {
Objects.requireNonNull(xpath, "Xpath cannot be null");
String[] fields = xpath.split("/");
if (fields == null || fields.length == 0) {
if (fields.length == 0) {
return "";
}
for (int i = fields.length - 1; i >= 0; i--) {
Expand All @@ -64,7 +64,7 @@ public static String getElementLocalName(String xpath) {
public static String getElementPredicate(String xpath) {
Objects.requireNonNull(xpath, "Xpath cannot be null");
String[] fields = xpath.split("/");
if (fields == null || fields.length == 0) {
if (fields.length == 0) {
return "";
}
for (int i = fields.length - 1; i >= 0; i--) {
Expand Down Expand Up @@ -196,7 +196,7 @@ static String getQualifiedNodeName(Node node) {
public static String getParentLocalName(String xpath) {
Objects.requireNonNull(xpath, "Xpath cannot be null");
String[] fields = xpath.split("/");
if (fields == null || fields.length == 0) {
if (fields.length == 0) {
return "";
}
boolean elementFound = false;
Expand All @@ -218,7 +218,7 @@ public static String getParentLocalName(String xpath) {
public static String getParentPredicate(String xpath) {
Objects.requireNonNull(xpath, "Xpath cannot be null");
String[] fields = xpath.split("/");
if (fields == null || fields.length == 0) {
if (fields.length == 0) {
return "";
}
boolean elementFound = false;
Expand All @@ -244,7 +244,7 @@ public static String getParentPredicate(String xpath) {
public static boolean isAttribute(String xpath) {
Objects.requireNonNull(xpath, "Xpath cannot be null");
String[] fields = xpath.split("/");
return !(fields == null || fields.length == 0) && fields[fields.length - 1].startsWith("@");
return !(fields.length == 0) && fields[fields.length - 1].startsWith("@");
}


Expand Down
4 changes: 4 additions & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module diff.merge {
requires java.xml;
requires Saxon.HE;
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static void setupOnce() throws Exception {
@BeforeEach
public void setUp() throws Exception {
tool = new RepositoryDiffReporter();
RepositoryDiffReporter.HtmlDiffListener aListener = tool.new HtmlDiffListener(new FileOutputStream(DIFF_FILENAME));
RepositoryDiffReporter.HtmlDiffListener aListener = new RepositoryDiffReporter.HtmlDiffListener(new FileOutputStream(DIFF_FILENAME));
tool.setListener(aListener);
}

Expand Down

0 comments on commit a2b4bc4

Please sign in to comment.