MPA Toc now contains only fragments links for sections on the current page

git-svn-id: https://svn.libreccm.org/ccm/trunk@6210 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2019-09-19 17:54:03 +00:00
parent 0b586dd19d
commit 1af32913b0
1 changed files with 32 additions and 20 deletions

View File

@ -35,7 +35,8 @@ import javax.servlet.ServletException;
/** /**
* *
* @author Jens Pelzetter * @author Jens Pelzetter
* @version $Id$ * @version $Id: ArticleSectionXMLGenerator.java 3268 2015-02-25 08:31:00Z jensp
* $
*/ */
public class ArticleSectionXMLGenerator implements ExtraXMLGenerator { public class ArticleSectionXMLGenerator implements ExtraXMLGenerator {
@ -48,10 +49,11 @@ public class ArticleSectionXMLGenerator implements ExtraXMLGenerator {
public void generateXML(final ContentItem item, public void generateXML(final ContentItem item,
final Element element, final Element element,
final PageState state) { final PageState state) {
final Element content = element.newChildElement("cms:articleSectionPanel", final Element content = element.newChildElement(
"cms:articleSectionPanel",
CMS.CMS_XML_NS); CMS.CMS_XML_NS);
generateToc(item, content); generateToc(item, content, state);
final XMLGenerator xmlGenerator = getXMLGenerator(state, item); final XMLGenerator xmlGenerator = getXMLGenerator(state, item);
@ -64,7 +66,8 @@ public class ArticleSectionXMLGenerator implements ExtraXMLGenerator {
if (number.wantAllSections()) { if (number.wantAllSections()) {
content.addAttribute("pageNumber", "all"); content.addAttribute("pageNumber", "all");
} else { } else {
content.addAttribute("pageNumber", number.getPageNumber().toString()); content
.addAttribute("pageNumber", number.getPageNumber().toString());
} }
} }
@ -91,7 +94,9 @@ public class ArticleSectionXMLGenerator implements ExtraXMLGenerator {
return number; return number;
} }
protected void generateToc(final ContentItem item, final Element parent) { protected void generateToc(
final ContentItem item, final Element parent, final PageState state
) {
if (!(item instanceof MultiPartArticle)) { if (!(item instanceof MultiPartArticle)) {
throw new IllegalArgumentException("Item is not a MultiPartArticle"); throw new IllegalArgumentException("Item is not a MultiPartArticle");
} }
@ -100,6 +105,7 @@ public class ArticleSectionXMLGenerator implements ExtraXMLGenerator {
final MultiPartArticle mparticle = (MultiPartArticle) item; final MultiPartArticle mparticle = (MultiPartArticle) item;
final ArticleSectionCollection sections = mparticle.getSections(); final ArticleSectionCollection sections = mparticle.getSections();
final PageNumber currentPage = getPageNumber(state);
int sectionNr = 1; int sectionNr = 1;
int pageNr = 1; int pageNr = 1;
ArticleSection section; ArticleSection section;
@ -108,9 +114,13 @@ public class ArticleSectionXMLGenerator implements ExtraXMLGenerator {
section = sections.getArticleSection(); section = sections.getArticleSection();
sectionElem = tocElem.newChildElement("section"); sectionElem = tocElem.newChildElement("section");
sectionElem.setCDATASection(section.getTitle()); sectionElem.setCDATASection(section.getTitle());
sectionElem.addAttribute("link", String.format("?page=%d#section-%d", final String link;
pageNr, if (currentPage.getPageNumber() == pageNr) {
sectionNr)); link = String.format("#section-%d", pageNr);
} else {
link = String.format("?page=%d#section-%d", pageNr, sectionNr);
}
sectionElem.addAttribute("link", link);
sectionElem.addAttribute("rank", section.getRank().toString()); sectionElem.addAttribute("rank", section.getRank().toString());
sectionNr++; sectionNr++;
if (section.isPageBreak()) { if (section.isPageBreak()) {
@ -123,7 +133,7 @@ public class ArticleSectionXMLGenerator implements ExtraXMLGenerator {
final Element parent, final Element parent,
final ContentItem section, final ContentItem section,
final XMLGenerator xmlGenerator) { final XMLGenerator xmlGenerator) {
CMSExcursion excursion = new CMSExcursion() { final CMSExcursion excursion = new CMSExcursion() {
public void excurse() { public void excurse() {
setContentItem(section); setContentItem(section);
@ -187,7 +197,8 @@ public class ArticleSectionXMLGenerator implements ExtraXMLGenerator {
return new ArticleSection[]{}; return new ArticleSection[]{};
} }
ArticleSection section = (ArticleSection) sections.getArticleSection(); ArticleSection section = (ArticleSection) sections
.getArticleSection();
if (section.isPageBreak()) { if (section.isPageBreak()) {
current++; current++;
@ -216,15 +227,16 @@ public class ArticleSectionXMLGenerator implements ExtraXMLGenerator {
} }
/** /**
* Try to get the section from the context if there isn't (eg if we are looking at an index item * Try to get the section from the context if there isn't (eg if we are
* on a category), guess the section from the item * looking at an index item on a category), guess the section from the item
* *
* @param state * @param state
* @param item * @param item
* *
* @return * @return
*/ */
protected XMLGenerator getXMLGenerator(final PageState state, final ContentItem item) { protected XMLGenerator getXMLGenerator(final PageState state,
final ContentItem item) {
ContentSection section = null; ContentSection section = null;
try { try {
section = CMS.getContext().getContentSection(); section = CMS.getContext().getContentSection();
@ -265,6 +277,7 @@ public class ArticleSectionXMLGenerator implements ExtraXMLGenerator {
} }
} }
// A parameter which is either an Integer number indicating // A parameter which is either an Integer number indicating
// the position in the list of sections, or the string 'all' // the position in the list of sections, or the string 'all'
/*private class PageParameter extends ParameterModel { /*private class PageParameter extends ParameterModel {
@ -298,5 +311,4 @@ public class ArticleSectionXMLGenerator implements ExtraXMLGenerator {
return PageNumber.class; return PageNumber.class;
} }
}*/ }*/
} }