From 70b7a5e4bee0f82fe0ed968d0c59f2163e9c3ffc Mon Sep 17 00:00:00 2001 From: jensp Date: Wed, 25 Feb 2015 08:31:00 +0000 Subject: [PATCH] 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 --- .../ArticleSectionXMLGenerator.java | 30 +++++++++ .../lib/template-tags/content-items/mpa.xsl | 62 ++++++++++++------- 2 files changed, 68 insertions(+), 24 deletions(-) diff --git a/ccm-cms-types-mparticle/src/com/arsdigita/cms/contenttypes/ArticleSectionXMLGenerator.java b/ccm-cms-types-mparticle/src/com/arsdigita/cms/contenttypes/ArticleSectionXMLGenerator.java index 1100c17e9..3281de92b 100644 --- a/ccm-cms-types-mparticle/src/com/arsdigita/cms/contenttypes/ArticleSectionXMLGenerator.java +++ b/ccm-cms-types-mparticle/src/com/arsdigita/cms/contenttypes/ArticleSectionXMLGenerator.java @@ -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, diff --git a/ccm-core/web/themes/foundry/foundry/lib/template-tags/content-items/mpa.xsl b/ccm-core/web/themes/foundry/foundry/lib/template-tags/content-items/mpa.xsl index d8078845e..c9f3e2f2d 100644 --- a/ccm-core/web/themes/foundry/foundry/lib/template-tags/content-items/mpa.xsl +++ b/ccm-core/web/themes/foundry/foundry/lib/template-tags/content-items/mpa.xsl @@ -76,42 +76,56 @@ - - + + + + + + + + + + + + + - - + - + - - - - + + - + + - - - - + + + + + + + + + - - - - - - - - - + + + + +