Skip to content

Commit

Permalink
Merge branch 'hotfix/4.2.4' into 4528_HTML_Indexterms
Browse files Browse the repository at this point in the history
  • Loading branch information
jlacour31 authored Nov 20, 2024
2 parents a9594b3 + 1c25ac7 commit 055b5b7
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/main/config/configuration.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ registry = https://plugins.dita-ot.org/

# PDF2 defaults
org.dita.pdf2.i18n.enabled = true

# Compatibility modes
# Treat keyref elements that contain only whitespace as empty.
compatibility.keyref.treat-blank-as-empty=true
23 changes: 22 additions & 1 deletion src/main/java/org/dita/dost/writer/KeyrefPaser.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ public final class KeyrefPaser extends AbstractXMLFilter {
private Set<URI> normalProcessingRoleTargets;
private MergeUtils mergeUtils;

private boolean compatibilityMode;

/**
* Constructor.
*/
Expand All @@ -189,6 +191,8 @@ public KeyrefPaser() {
elemName = new ArrayDeque<>();
hasSubElem = new ArrayDeque<>();
mergeUtils = new MergeUtils();
compatibilityMode =
Boolean.parseBoolean(Configuration.configuration.get("compatibility.keyref.treat-blank-as-empty"));
}

@Override
Expand All @@ -203,6 +207,13 @@ public void setJob(final Job job) {
mergeUtils.setJob(job);
}

/**
* Set compatibility mode for {@code compatibility.keyref.treat-blank-as-empty}.
*/
public void setCompatibilityMode(boolean compatibilityMode) {
this.compatibilityMode = compatibilityMode;
}

public void setKeyDefinition(final KeyScope definitionMap) {
this.definitionMaps.push(definitionMap);
}
Expand Down Expand Up @@ -237,9 +248,19 @@ public void startDocument() throws SAXException {
getContentHandler().startDocument();
}

private boolean isEmpty(final char[] ch, final int start, final int length) {
if (length == 0) {
return true;
}
if (compatibilityMode) {
return new String(ch, start, length).isBlank();
}
return false;
}

@Override
public void characters(final char[] ch, final int start, final int length) throws SAXException {
if (keyrefLevel != 0 && (length == 0 || new String(ch, start, length).trim().isEmpty())) {
if (keyrefLevel != 0 && isEmpty(ch, start, length)) {
if (!hasChecked) {
empty = true;
}
Expand Down
24 changes: 24 additions & 0 deletions src/test/java/org/dita/dost/writer/KeyrefPaserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.dita.dost.util.Job;
import org.dita.dost.util.KeyScope;
import org.dita.dost.util.XMLUtils;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
Expand Down Expand Up @@ -72,6 +73,7 @@ public void testWrite(Path file, Path map) throws Exception {

private static Stream<Arguments> testWriteArguments() {
return Stream.of(
Arguments.of(Paths.get("whitespace.xml"), Paths.get("keys.ditamap")),
Arguments.of(Paths.get("a.xml"), Paths.get("keys.ditamap")),
Arguments.of(Paths.get("subdir", "subdirtopic.xml"), Paths.get("keys.ditamap")),
Arguments.of(Paths.get("id.xml"), Paths.get("keys.ditamap")),
Expand All @@ -83,6 +85,28 @@ private static Stream<Arguments> testWriteArguments() {
);
}

@Test
public void compatibulityMode() throws Exception {
Path file = Paths.get("compatibility.xml");
Path map = Paths.get("keys.ditamap");

TestUtils.copy(srcDir, tempDir);

final KeyScope keyDefinition = readKeyMap(map);
final KeyrefPaser parser = new KeyrefPaser();
parser.setLogger(new TestUtils.TestLogger());
parser.setJob(new Job(tempDir, new StreamStore(tempDir, new XMLUtils())));
parser.setKeyDefinition(keyDefinition);
parser.setCurrentFile(Paths.get(tempDir.getAbsolutePath(), file.toString()).toUri());
parser.setCompatibilityMode(false);
parser.write(Paths.get(tempDir.getAbsolutePath(), file.toString()).toFile());

assertXMLEqual(
new InputSource(Paths.get(expDir.getAbsolutePath(), file.toString()).toUri().toString()),
new InputSource(Paths.get(tempDir.getAbsolutePath(), file.toString()).toUri().toString())
);
}

@ParameterizedTest(name = "{0}")
@MethodSource("testDomToSaxArguments")
public void testDomToSax(String ignore, SaplingElement src, SaplingNode exp, boolean retainElements)
Expand Down
10 changes: 10 additions & 0 deletions src/test/resources/KeyrefPaserTest/exp/compatibility.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<topic xmlns:ditaarch="http://dita.oasis-open.org/architecture/2005/" class="- topic/topic "
domains="(topic hi-d) (topic ut-d) (topic indexing-d) (topic hazard-d) (topic abbrev-d) (topic pr-d) (topic sw-d) (topic ui-d) "
id="a" ditaarch:DITAArchVersion="1.3">
<title class="- topic/title ">Whitespace</title>
<body class="- topic/body ">
<p class="- topic/p ">
<keyword class="- topic/keyword " keyref="keyword"> </keyword>
</p>
</body>
</topic>
10 changes: 10 additions & 0 deletions src/test/resources/KeyrefPaserTest/exp/whitespace.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<topic xmlns:ditaarch="http://dita.oasis-open.org/architecture/2005/" class="- topic/topic "
domains="(topic hi-d) (topic ut-d) (topic indexing-d) (topic hazard-d) (topic abbrev-d) (topic pr-d) (topic sw-d) (topic ui-d) "
id="a" ditaarch:DITAArchVersion="1.3">
<title class="- topic/title ">Whitespace</title>
<body class="- topic/body ">
<p class="- topic/p ">
<keyword class="- topic/keyword " keyref="keyword">keyword keyword</keyword>
</p>
</body>
</topic>
10 changes: 10 additions & 0 deletions src/test/resources/KeyrefPaserTest/src/compatibility.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<topic xmlns:ditaarch="http://dita.oasis-open.org/architecture/2005/" class="- topic/topic "
domains="(topic hi-d) (topic ut-d) (topic indexing-d) (topic hazard-d) (topic abbrev-d) (topic pr-d) (topic sw-d) (topic ui-d) "
id="a" ditaarch:DITAArchVersion="1.3">
<title class="- topic/title ">Whitespace</title>
<body class="- topic/body ">
<p class="- topic/p ">
<keyword class="- topic/keyword " keyref="keyword"> </keyword>
</p>
</body>
</topic>
10 changes: 10 additions & 0 deletions src/test/resources/KeyrefPaserTest/src/whitespace.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<topic xmlns:ditaarch="http://dita.oasis-open.org/architecture/2005/" class="- topic/topic "
domains="(topic hi-d) (topic ut-d) (topic indexing-d) (topic hazard-d) (topic abbrev-d) (topic pr-d) (topic sw-d) (topic ui-d) "
id="a" ditaarch:DITAArchVersion="1.3">
<title class="- topic/title ">Whitespace</title>
<body class="- topic/body ">
<p class="- topic/p ">
<keyword class="- topic/keyword " keyref="keyword"> </keyword>
</p>
</body>
</topic>
3 changes: 3 additions & 0 deletions src/test/resources/configuration.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ plugin.ignores =
# PDF2 defaults
org.dita.pdf2.index.frame-markup = false
org.dita.pdf2.i18n.enabled = true

# Compatibility modes
compatibility.keyref.treat-blank-as-empty=true

0 comments on commit 055b5b7

Please sign in to comment.