Skip to content

Commit

Permalink
LanguageUpdater is able to cleanup the ref file
Browse files Browse the repository at this point in the history
  • Loading branch information
hneemann committed Jan 15, 2021
1 parent 905c9d7 commit f745215
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/test/java/de/neemann/digital/lang/LanguageUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import de.neemann.digital.integration.Resources;
import org.jdom2.*;
import org.jdom2.filter.Filter;
import org.jdom2.input.SAXBuilder;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;
Expand All @@ -20,7 +19,6 @@
import java.util.Enumeration;
import java.util.HashSet;
import java.util.List;
import java.util.function.Predicate;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

Expand Down Expand Up @@ -120,7 +118,7 @@ private void checkComment(Document doc, String comment) {
}

private void add(Document xml, String key, String text) throws IOException {
for (Element e : (List<Element>) xml.getRootElement().getChildren()) {
for (Element e : xml.getRootElement().getChildren()) {
String k = e.getAttributeValue("name");
if (k.equals(key)) {
throw new IOException("key " + key + " is already present in " + xml);
Expand All @@ -132,7 +130,7 @@ private void add(Document xml, String key, String text) throws IOException {
}

private boolean replace(Document xml, String key, String text) throws IOException {
for (Element e : (List<Element>) xml.getRootElement().getChildren()) {
for (Element e : xml.getRootElement().getChildren()) {
String k = e.getAttributeValue("name");
if (k.equals(key)) {
if (e.getText().trim().equals(text.trim())) {
Expand All @@ -147,16 +145,16 @@ private boolean replace(Document xml, String key, String text) throws IOExceptio
}

private void update() throws IOException {
// if (modified > 0) {
Format format = Format.getPrettyFormat()
.setIndent(" ")
.setTextMode(Format.TextMode.PRESERVE);
new XMLOutputter(format).output(ref, new FileOutputStream(refFileName));
new XMLOutputter(format).output(lang, new FileOutputStream(langFileName));
System.out.println(modified + " keys updated!");
// } else {
// System.out.println("no modification found!");
// }
if (modified > 0) {
Format format = Format.getPrettyFormat()
.setIndent(" ")
.setTextMode(Format.TextMode.PRESERVE);
new XMLOutputter(format).output(ref, new FileOutputStream(refFileName));
new XMLOutputter(format).output(lang, new FileOutputStream(langFileName));
System.out.println(modified + " keys updated!");
} else {
System.out.println("no modification found!");
}
}

public static void main(String[] args) throws JDOMException, IOException {
Expand Down

0 comments on commit f745215

Please sign in to comment.