Moved the generation of the links to the sections of a MPA to Java code. The XML now provides a toc element containing the

links to all sections of the MPA the correct parameters. Foundry uses these informations now, with a fallback to the XSL based
generation of the links which does not work in some cases. This commit should solve the issues #2366, #2354 and #2358.


git-svn-id: https://svn.libreccm.org/ccm/trunk@3268 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2015-02-25 08:31:00 +00:00
parent 9259c8ec59
commit 70b7a5e4be
2 changed files with 68 additions and 24 deletions

View File

@ -51,6 +51,8 @@ public class ArticleSectionXMLGenerator implements ExtraXMLGenerator {
final Element content = element.newChildElement("cms:articleSectionPanel",
CMS.CMS_XML_NS);
generateToc(item, content);
final XMLGenerator xmlGenerator = getXMLGenerator(state, item);
final ArticleSection sections[] = getSections(item, state);
@ -89,6 +91,34 @@ public class ArticleSectionXMLGenerator implements ExtraXMLGenerator {
return number;
}
protected void generateToc(final ContentItem item, final Element parent) {
if (!(item instanceof MultiPartArticle)) {
throw new IllegalArgumentException("Item is not a MultiPartArticle");
}
final Element tocElem = parent.newChildElement("toc");
final MultiPartArticle mparticle = (MultiPartArticle) item;
final ArticleSectionCollection sections = mparticle.getSections();
int sectionNr = 1;
int pageNr = 1;
ArticleSection section;
Element sectionElem;
while(sections.next()) {
section = sections.getArticleSection();
sectionElem = tocElem.newChildElement("section");
sectionElem.setCDATASection(section.getTitle());
sectionElem.addAttribute("link", String.format("?page=%d#section-%d",
pageNr,
sectionNr));
sectionElem.addAttribute("rank", section.getRank().toString());
sectionNr++;
if (section.isPageBreak()) {
pageNr++;
}
}
}
protected void generateSectionXML(final PageState state,
final Element parent,
final ContentItem section,

View File

@ -76,42 +76,56 @@
<xsl:variable name="number-of-pages"
select="$contentitem-tree/cms:mpadata/numberOfPages"/>
<xsl:for-each select="$contentitem-tree/sections">
<xsl:sort select="./rank" data-type="number"/>
<xsl:choose>
<xsl:when test="$contentitem-tree/cms:articleSectionPanel/toc">
<xsl:for-each select="$contentitem-tree/cms:articleSectionPanel/toc/section">
<xsl:apply-templates select="$section-layout-tree/*">
<xsl:with-param name="mpa-section-title" tunnel="yes" select="."/>
<xsl:with-param name="href" tunnel="yes" select="@link"/>
</xsl:apply-templates>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="current-rank" select="./rank"/>
<xsl:variable name="page-number"
<xsl:for-each select="$contentitem-tree/sections">
<xsl:sort select="./rank" data-type="number"/>
<xsl:variable name="current-rank" select="./rank"/>
<xsl:variable name="page-number"
select="count($contentitem-tree/sections[./pageBreak = 'true'
and ./rank &lt; ($current-rank + 1)])"/>
<xsl:apply-templates select="$section-layout-tree/*">
<xsl:apply-templates select="$section-layout-tree/*">
<xsl:with-param name="mpa-section-title" tunnel="yes" select="./title"/>
<xsl:with-param name="href" tunnel="yes">
<xsl:choose>
<xsl:when test="./pageBreak = 'true'
or ($page-number &lt;= $number-of-pages)">
<xsl:with-param name="mpa-section-title" tunnel="yes" select="./title"/>
<xsl:with-param name="href" tunnel="yes">
<xsl:choose>
<xsl:when test="$current-page = 'all'
<xsl:when test="./pageBreak = 'true'
or ($page-number &lt;= $number-of-pages)">
<xsl:choose>
<xsl:when test="$current-page = 'all'
or $page-number = $current-page">
<xsl:value-of select="concat('#section-', $current-rank)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('?page=',
<xsl:value-of select="concat('#section-',
$current-rank)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('?page=',
$page-number,
'#section-',
$current-rank)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('#section-', $current-rank)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('#section-', $current-rank)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
</xsl:apply-templates>
</xsl:for-each>
</xsl:with-param>
</xsl:apply-templates>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<foundry:doc section="user" type="template-tag">