Skip to content

Commit

Permalink
Detected loops while processing @keyref
Browse files Browse the repository at this point in the history
  • Loading branch information
rmraya committed Feb 20, 2023
1 parent df8c0ca commit 6b81558
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 23 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ XML and JSON filters are configurable

Version | Comment | Release Date
:------:|---------|:-----------:
3.3.0 | Detected loops while processing @keyref in DITA | February 20th, 2023
3.2.0 | Improved file management | February 4th, 2023
3.1.0 | Improved DITA merge | January 24th, 2023
3.0.0 | Moved XML code to project [XMLJava](https://github.com/rmraya/XMLJava) | January 9th, 2023
Expand Down
Binary file modified lib/openxliff.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions src/com/maxprograms/converters/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ private Constants() {

public static final String TOOLID = "OpenXLIFF";
public static final String TOOLNAME = "OpenXLIFF Filters";
public static final String VERSION = "3.2.0";
public static final String BUILD = "20230208_1000";
public static final String VERSION = "3.3.0";
public static final String BUILD = "20230220_1511";

public static final String SUCCESS = "0";
public static final String ERROR = "1";
Expand Down
52 changes: 31 additions & 21 deletions src/com/maxprograms/converters/ditamap/DitaParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public int hashCode() {
private Scope rootScope;

private Set<StringArray> searchedConref;
private Set<String> visiting;
private Map<Key, Set<String>> usedKeys;
private Set<String> recursed;
private Set<String> pendingRecurse;
Expand All @@ -110,7 +111,6 @@ public int hashCode() {
private static TreeSet<String> imageSet;
private List<String> ignored;
private Map<StringArray, Element> referenceChache;
private boolean containsText;
private Catalog catalog;
private List<String> skipped;
private Map<String, List<String>> images;
Expand All @@ -128,6 +128,7 @@ public List<String> run(Map<String, String> params, Catalog catalog)
referenceChache = new HashMap<>();
skipped = new ArrayList<>();
images = new HashMap<>();
visiting = new TreeSet<>();

String inputFile = params.get("source");
this.catalog = catalog;
Expand Down Expand Up @@ -203,9 +204,8 @@ public List<String> run(Map<String, String> params, Catalog catalog)
}
Element e = builder.build(file).getRootElement();
if ("svg".equals(e.getName())) {
containsText = false;
recurseSVG(e);
if (!containsText) {
if (!containsText(e)) {
recursed.add(file);
continue;
}
}
Expand All @@ -223,24 +223,24 @@ public List<String> run(Map<String, String> params, Catalog catalog)
return result;
}

private void recurseSVG(Element e) {
private boolean containsText(Element e) {
if ("text".equals(e.getName()) && !svgText(e).isEmpty()) {
containsText = true;
return;
return true;
}
if ("title".equals(e.getName()) && !svgText(e).isEmpty()) {
containsText = true;
return;
return true;
}
if ("desc".equals(e.getName()) && !svgText(e).isEmpty()) {
containsText = true;
return;
return true;
}
List<Element> children = e.getChildren();
Iterator<Element> it = children.iterator();
while (it.hasNext()) {
recurseSVG(it.next());
if (containsText(it.next())) {
return true;
}
}
return false;
}

private String svgText(Element e) {
Expand Down Expand Up @@ -520,16 +520,26 @@ private void recurse(Element e, String parentFile) throws IOException, SAXExcept
usedKeys.put(k, new TreeSet<>());
}
usedKeys.get(k).add(parentFile);
filesMap.add(k.getHref());
Element ref = getConKeyReferenced(k.getHref(), id);
if (ref != null) {
e.setContent(ref.getContent());
List<Element> children = e.getChildren();
Iterator<Element> ie = children.iterator();
while (ie.hasNext()) {
recurse(ie.next(), k.getHref());
String kref = k.getHref();
filesMap.add(kref);
if (!visiting.contains(id + "|" + kref)) {
visiting.add(id + "|" + kref);
Element ref = getConKeyReferenced(k.getHref(), id);
if (ref != null) {
e.setContent(ref.getContent());
List<Element> children = e.getChildren();
Iterator<Element> ie = children.iterator();
while (ie.hasNext()) {
recurse(ie.next(), kref);
}
return;
}
return;
visiting.remove(id + "|" + kref);
} else {
MessageFormat mf = new MessageFormat("Loop detected processing @keyref \"{0}\" in file {1}");
String issue = mf.format(new Object[] { keyref, parentFile });
logger.log(Level.WARNING, issue);
issues.add(issue);
}
}
}
Expand Down

0 comments on commit 6b81558

Please sign in to comment.