Permalink
Browse files

Merge branch 'hotfix/2.4.6'

  • Loading branch information...
jelovirt committed Apr 18, 2017
2 parents a308c40 + 3c3c038 commit f3cf6d1f722914f9f37a3079d2ad8a85b47ed3d6
View
@@ -9,7 +9,7 @@ apply plugin: 'java'
apply plugin: 'maven'
group = 'org.dita-ot'
version = '2.4.5'
version = '2.4.6'
description = """DITA Open Toolkit"""
@@ -9,7 +9,6 @@
package org.dita.dost.module;
import static java.util.stream.Collectors.toMap;
import static org.dita.dost.util.Configuration.configuration;
import static org.dita.dost.util.Constants.*;
import static org.dita.dost.util.Job.*;
import static org.dita.dost.util.URLUtils.*;
@@ -19,6 +18,7 @@
import java.io.IOException;
import java.net.URI;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.dita.dost.module.GenMapAndTopicListModule.TempFileNameScheme;
@@ -135,7 +135,6 @@ private void initFilters() {
}
/** Collect topics for key reference processing and modify map to reflect new file names. */
// FIXME multple topirefs in a single scope result in redundant copies, allow duplicates inside scope
private List<ResolveTask> collectProcessingTopics(final Collection<FileInfo> fis, final KeyScope rootScope, final Document doc) {
final List<ResolveTask> res = new ArrayList<>();
res.add(new ResolveTask(rootScope, job.getFileInfo(job.getInputMap()), null));
@@ -147,9 +146,26 @@ private void initFilters() {
res.add(processTopic(f, rootScope, f.isResourceOnly));
}
}
return adjustResourceRenames(res);
final List<ResolveTask> deduped = removeDuplicateResolveTargets(res);
return adjustResourceRenames(deduped);
}
/** Remove duplicate sources within the same scope */
private List<ResolveTask> removeDuplicateResolveTargets(List<ResolveTask> renames) {
return renames.stream()
.collect(Collectors.groupingBy(
rt -> rt.scope,
Collectors.toMap(
rt -> rt.in.uri,
Function.identity(),
(rt1, rt2) -> rt1
)
)).values().stream()
.flatMap(m -> m.values().stream())
.collect(Collectors.toList());
}
/** Adjust key targets per rewrites */
List<ResolveTask> adjustResourceRenames(final List<ResolveTask> renames) {
final Map<KeyScope, List<ResolveTask>> scopes = renames.stream().collect(Collectors.groupingBy(rt -> rt.scope));
@@ -158,6 +174,7 @@ private void initFilters() {
final KeyScope scope = group.getKey();
final List<ResolveTask> tasks = group.getValue();
final Map<URI, URI> rewrites = tasks.stream()
// FIXME this should be filtered out earlier
.filter(t -> t.out != null)
.collect(toMap(
t -> t.in.uri,
@@ -203,8 +220,8 @@ KeyScope rewriteScopeTargets(KeyScope scope, Map<URI, URI> rewrites) {
}
}
/** Recursively walk map and process topics that have keyrefs. */
private void walkMap(final Element elem, final KeyScope scope, final List<ResolveTask> res) {
/** Recursively walk map and process topics that have keyrefs. */
void walkMap(final Element elem, final KeyScope scope, final List<ResolveTask> res) {
List<KeyScope> ss = Collections.singletonList(scope);
if (elem.getAttributeNode(ATTRIBUTE_NAME_KEYSCOPE) != null) {
ss = new ArrayList<>();
@@ -224,12 +241,22 @@ private void walkMap(final Element elem, final KeyScope scope, final List<Resolv
final URI href = stripFragment(job.getInputMap().resolve(hrefNode.getValue()));
final FileInfo fi = job.getFileInfo(href);
if (fi != null && fi.hasKeyref) {
final ResolveTask resolveTask = processTopic(fi, s, isResourceOnly);
res.add(resolveTask);
final Integer used = usage.get(fi.uri);
if (used > 1) {
final URI value = tempFileNameScheme.generateTempFileName(resolveTask.out.result);
hrefNode.setValue(value.toString());
final int count = usage.getOrDefault(fi.uri, 0);
final Optional<ResolveTask> existing = res.stream().filter(rt -> rt.scope.equals(s) && rt.in.uri.equals(fi.uri)).findAny();
if (count != 0 && existing.isPresent()) {
final ResolveTask resolveTask = existing.get();
if (resolveTask.out != null) {
final URI value = tempFileNameScheme.generateTempFileName(resolveTask.out.result);
hrefNode.setValue(value.toString());
}
} else {
final ResolveTask resolveTask = processTopic(fi, s, isResourceOnly);
res.add(resolveTask);
final Integer used = usage.get(fi.uri);
if (used > 1) {
final URI value = tempFileNameScheme.generateTempFileName(resolveTask.out.result);
hrefNode.setValue(value.toString());
}
}
}
}
@@ -5,7 +5,7 @@
# See the accompanying LICENSE file for applicable license.
#DITA-OT configuration properties
otrelease = 2.4
otversion = 2.4.5
otversion = 2.4.6
default.cascade = merge
temp-file-name-scheme = org.dita.dost.module.GenMapAndTopicListModule$DefaultTempFileScheme
@@ -10,7 +10,7 @@ See the accompanying LICENSE file for applicable license.
xmlns:related-links="http://dita-ot.sourceforge.net/ns/200709/related-links"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="2.0"
extension-element-prefixes="related-links xs">
exclude-result-prefixes="related-links xs">
<!-- Concepts have their own group. -->
<xsl:template match="*[contains(@class, ' topic/link ')][@type='concept']" mode="related-links:get-group"
@@ -91,7 +91,7 @@ See the accompanying LICENSE file for applicable license.
"/>
</xsl:function>
<xsl:function name="table:get-entry-colspec" as="element()">
<xsl:function name="table:get-entry-colspec" as="element()?">
<xsl:param name="entry" as="element()"/>
<xsl:sequence select="
@@ -27,9 +27,16 @@ See the accompanying LICENSE file for applicable license.
<xsl:apply-templates select="." mode="dita2html:get-max-entry-count"/>
</xsl:variable>
<xsl:variable name="col-widths" as="xs:double*">
<xsl:variable name="widths" select="tokenize(normalize-space(@relcolwidth), '\s+')" as="xs:string*"/>
<xsl:variable name="widths" select="tokenize(normalize-space(translate(@relcolwidth, '*', '')), '\s+')" as="xs:string*"/>
<xsl:for-each select="$widths">
<xsl:sequence select="xs:double(substring(., 1, string-length(.) - 1))"/>
<xsl:choose>
<xsl:when test=". castable as xs:double">
<xsl:sequence select="xs:double(.)"/>
</xsl:when>
<xsl:otherwise>
<xsl:sequence select="xs:double(1)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<xsl:for-each select="1 to ($col-count - count($widths))">
<xsl:sequence select="xs:double(1)"/>
@@ -104,7 +111,7 @@ See the accompanying LICENSE file for applicable license.
<!-- If there is a header, get the ID from the head cell in this column.
Go up to simpletable, into the row, to the entry at column $thiscolnum -->
<xsl:variable name="header">
<xsl:if test="parent::*/parent::*/*[contains(@class, ' topic/sthead ')]">
<xsl:if test="parent::*/parent::*/*[contains(@class, ' topic/sthead ')]/*[contains(@class, ' topic/stentry ')][number($thiscolnum)]">
<xsl:value-of select="dita-ot:generate-html-id(parent::*/parent::*/*[contains(@class, ' topic/sthead ')]/*[contains(@class, ' topic/stentry ')][number($thiscolnum)])"/>
</xsl:if>
</xsl:variable>
@@ -35,6 +35,11 @@ See the accompanying LICENSE file for applicable license.
<xsl:attribute-set name="linklist">
</xsl:attribute-set>
<xsl:attribute-set name="linklist.title">
<xsl:attribute name="font-weight">bold</xsl:attribute>
<xsl:attribute name="keep-with-next.within-column">always</xsl:attribute>
</xsl:attribute-set>
<xsl:attribute-set name="linkpool">
</xsl:attribute-set>
@@ -35,11 +35,6 @@ See the accompanying LICENSE file for applicable license.
xmlns:fo="http://www.w3.org/1999/XSL/Format"
version="2.0">
<xsl:attribute-set name="linklist.title">
<xsl:attribute name="font-weight">bold</xsl:attribute>
<xsl:attribute name="keep-with-next.within-column">always</xsl:attribute>
</xsl:attribute-set>
<!--Common-->
<xsl:attribute-set name="li.itemgroup">
<xsl:attribute name="space-after">3pt</xsl:attribute>
@@ -9,7 +9,7 @@ See the accompanying LICENSE file for applicable license.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:ot-placeholder="http://suite-sol.com/namespaces/ot-placeholder"
extension-element-prefixes="ot-placeholder"
exclude-result-prefixes="ot-placeholder"
version="2.0">
<xsl:template match="ot-placeholder:glossarylist" name="createGlossary">
@@ -628,6 +628,12 @@ See the accompanying LICENSE file for applicable license.
<xsl:apply-templates/>
</fo:block>
</xsl:template>
<xsl:template match="*[contains(@class,' topic/linklist ')]/*[contains(@class,' topic/title ')]">
<fo:block xsl:use-attribute-sets="linklist.title">
<xsl:apply-templates/>
</fo:block>
</xsl:template>
<xsl:template match="*[contains(@class,' topic/linkinfo ')]">
<fo:block xsl:use-attribute-sets="linkinfo">
@@ -38,12 +38,6 @@ See the accompanying LICENSE file for applicable license.
xmlns:fo="http://www.w3.org/1999/XSL/Format"
version="2.0">
<xsl:template match="*[contains(@class,' topic/linklist ')]/*[contains(@class,' topic/title ')]">
<fo:block xsl:use-attribute-sets="linklist.title">
<xsl:apply-templates/>
</fo:block>
</xsl:template>
<!--Lists-->
<xsl:template match="*[contains(@class, ' topic/ul ')]">
<xsl:apply-templates select="*[contains(@class,' ditaot-d/ditaval-startprop ')]" mode="outofline"/>
@@ -435,8 +435,8 @@ See the accompanying LICENSE file for applicable license.
</xsl:template>
<xsl:template name="processEntryContent">
<xsl:variable name="entryNumber" select="@dita-ot:x" as="xs:integer"/>
<xsl:variable name="colspec" select="ancestor::*[contains(@class, ' topic/tgroup ')][1]/*[contains(@class, ' topic/colspec ')][position() = $entryNumber]"/>
<xsl:variable name="entryNumber" select="@dita-ot:x" as="xs:integer?"/>
<xsl:variable name="colspec" select="ancestor::*[contains(@class, ' topic/tgroup ')][1]/*[contains(@class, ' topic/colspec ')][position() = $entryNumber]" as="element()?"/>
<xsl:variable name="char" as="xs:string?">
<xsl:choose>
<xsl:when test="@char">
@@ -366,7 +366,7 @@ See the accompanying LICENSE file for applicable license.
<xsl:variable name="row" select=".." as="element()"/>
<xsl:variable name="body" select="../.." as="element()"/>
<xsl:variable name="group" select="../../.." as="element()"/>
<xsl:variable name="colspec" select="../../../*[contains(@class, ' topic/colspec ')][@colname and @colname = $this-colname]" as="element()"/>
<xsl:variable name="colspec" select="../../../*[contains(@class, ' topic/colspec ')][@colname and @colname = $this-colname]" as="element()?"/>
<xsl:variable name="table" select="../../../.." as="element()"/>
<xsl:variable name="framevalue">
@@ -721,9 +721,16 @@ See the accompanying LICENSE file for applicable license.
<xsl:apply-templates select="." mode="dita2html:get-max-entry-count"/>
</xsl:variable>
<xsl:variable name="col-widths" as="xs:double*">
<xsl:variable name="widths" select="tokenize(normalize-space(@relcolwidth), '\s+')" as="xs:string*"/>
<xsl:variable name="widths" select="tokenize(normalize-space(translate(@relcolwidth, '*', '')), '\s+')" as="xs:string*"/>
<xsl:for-each select="$widths">
<xsl:sequence select="xs:double(substring(., 1, string-length(.) - 1))"/>
<xsl:choose>
<xsl:when test=". castable as xs:double">
<xsl:sequence select="xs:double(.)"/>
</xsl:when>
<xsl:otherwise>
<xsl:sequence select="xs:double(1)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<xsl:for-each select="1 to ($col-count - count($widths))">
<xsl:sequence select="xs:double(1)"/>
@@ -829,7 +836,7 @@ See the accompanying LICENSE file for applicable license.
<!-- If there is a header, get the ID from the head cell in this column.
Go up to simpletable, into the row, to the entry at column $thiscolnum -->
<xsl:variable name="header">
<xsl:if test="parent::*/parent::*/*[contains(@class, ' topic/sthead ')]">
<xsl:if test="parent::*/parent::*/*[contains(@class, ' topic/sthead ')]/*[contains(@class, ' topic/stentry ')][number($thiscolnum)]">
<xsl:value-of select="dita-ot:generate-html-id(parent::*/parent::*/*[contains(@class, ' topic/sthead ')]/*[contains(@class, ' topic/stentry ')][number($thiscolnum)])"/>
</xsl:if>
</xsl:variable>
@@ -9,6 +9,7 @@
package org.dita.dost.module;
import com.google.common.collect.ImmutableMap;
import org.dita.dost.TestUtils;
import org.dita.dost.TestUtils.TestLogger;
import org.dita.dost.module.KeyrefModule.ResolveTask;
import org.dita.dost.util.Job;
@@ -17,29 +18,57 @@
import org.dita.dost.util.KeyScope;
import org.junit.Before;
import org.junit.Test;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.util.List;
import java.util.Map;
import java.util.*;
import static java.util.Collections.EMPTY_LIST;
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
import static java.net.URI.create;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static org.dita.dost.TestUtils.createTempDir;
import static org.dita.dost.util.Constants.INPUT_DIR_URI;
import static org.dita.dost.util.Constants.INPUT_DITAMAP_URI;
import static org.junit.Assert.assertEquals;
public class KeyrefModuleTest {
private static final File baseDir = TestUtils.getResourceDir(KeyrefModuleTest.class);
private static final URI inputMap = new File(baseDir, "xsrc" + File.separator + "test.ditamap").toURI();
KeyrefModule module;
@Before
public void setUp() throws IOException {
final File tempDir = createTempDir(KeyrefModuleTest.class);
module = new KeyrefModule();
module.setJob(new Job(tempDir));
final Job job = new Job(tempDir);
job.setProperty(INPUT_DIR_URI, new File(baseDir, "xsrc").toURI().toString());
job.setProperty(INPUT_DITAMAP_URI, URI.create("test.ditamap").toString());
job.add(new Job.FileInfo.Builder()
.uri(URI.create("topic.dita"))
.src(new File(baseDir, "xsrc" + File.separator + "topic.dita").toURI())
.result(new File(baseDir, "xsrc" + File.separator + "topic.dita").toURI())
.format("dita")
.hasKeyref(true)
.build());
job.add(new Job.FileInfo.Builder()
.uri(URI.create("test.ditamap"))
.src(new File(baseDir, "xsrc" + File.separator + "test.ditamap").toURI())
.result(new File(baseDir, "xsrc" + File.separator + "test.ditamap").toURI())
.format("ditamap")
.build());
module.setJob(job);
module.setLogger(new TestLogger());
}
@@ -89,4 +118,27 @@ public void testRewriteScopeTargets() {
assertEquals(exp, act);
}
@Test
public void testWalkMap() throws ParserConfigurationException, IOException, SAXException {
final DocumentBuilder b = DocumentBuilderFactory.newInstance().newDocumentBuilder();
final Document act = b.parse(new File(baseDir, "src" + File.separator + "test.ditamap"));
final KeyScope keyScope =
new KeyScope(null,
ImmutableMap.of(
"VAR", new KeyDef("VAR", null, "local", "dita", inputMap, null),
"A.VAR", new KeyDef("VAR", null, "local", "dita", inputMap, null)),
singletonList(
new KeyScope("A",
ImmutableMap.of(
"VAR", new KeyDef("VAR", null, "local", "dita", inputMap, null),
"A.VAR", new KeyDef("VAR", null, "local", "dita", inputMap, null)),
EMPTY_LIST)
));
final List<ResolveTask> res = new ArrayList<>();
module.walkMap(act.getDocumentElement(), keyScope, res);
final Document exp = b.parse(new File(baseDir, "exp" + File.separator + "test.ditamap"));
assertXMLEqual(exp, act);
}
}
@@ -0,0 +1,8 @@
<map xmlns:ditaarch="http://dita.oasis-open.org/architecture/2005/" xmlns:dita-ot="http://dita-ot.sourceforge.net/ns/201007/dita-ot" cascade="merge" class="- map/map " ditaarch:DITAArchVersion="1.3" domains="(map mapgroup-d) (topic abbrev-d) (topic delay-d) a(props deliveryTarget) (map ditavalref-d) (map glossref-d) (topic hazard-d) (topic hi-d) (topic indexing-d) (topic markup-d) (topic pr-d) (topic relmgmt-d) (topic sw-d) (topic ui-d) (topic ut-d) (topic markup-d xml-d)">
<topicref class="- map/topicref " href="topic.dita"/>
<topicref class="- map/topicref " href="topic.dita"/>
<topicgroup class="+ map/topicref mapgroup-d/topicgroup " keyscope="A">
<topicref class="- map/topicref " href="topic-1.dita"/>
<topicref class="- map/topicref " href="topic-1.dita"/>
</topicgroup>
</map>
@@ -0,0 +1,8 @@
<map xmlns:ditaarch="http://dita.oasis-open.org/architecture/2005/" xmlns:dita-ot="http://dita-ot.sourceforge.net/ns/201007/dita-ot" cascade="merge" class="- map/map " ditaarch:DITAArchVersion="1.3" domains="(map mapgroup-d) (topic abbrev-d) (topic delay-d) a(props deliveryTarget) (map ditavalref-d) (map glossref-d) (topic hazard-d) (topic hi-d) (topic indexing-d) (topic markup-d) (topic pr-d) (topic relmgmt-d) (topic sw-d) (topic ui-d) (topic ut-d) (topic markup-d xml-d)">
<topicref class="- map/topicref " href="topic.dita"/>
<topicref class="- map/topicref " href="topic.dita"/>
<topicgroup class="+ map/topicref mapgroup-d/topicgroup " keyscope="A">
<topicref class="- map/topicref " href="topic.dita"/>
<topicref class="- map/topicref " href="topic.dita"/>
</topicgroup>
</map>

0 comments on commit f3cf6d1

Please sign in to comment.