diff --git a/ccm-cms-types-mparticle/src/com/arsdigita/cms/contenttypes/MultiPartArticleDataXMLGenerator.java b/ccm-cms-types-mparticle/src/com/arsdigita/cms/contenttypes/MultiPartArticleDataXMLGenerator.java new file mode 100644 index 000000000..9d438e2cc --- /dev/null +++ b/ccm-cms-types-mparticle/src/com/arsdigita/cms/contenttypes/MultiPartArticleDataXMLGenerator.java @@ -0,0 +1,63 @@ +package com.arsdigita.cms.contenttypes; + +import com.arsdigita.bebop.Page; +import com.arsdigita.bebop.PageState; +import com.arsdigita.cms.CMS; +import com.arsdigita.cms.ContentItem; +import com.arsdigita.cms.ExtraXMLGenerator; +import com.arsdigita.xml.Element; + +/** + * + * @author Jens Pelzetter + */ +public class MultiPartArticleDataXMLGenerator implements ExtraXMLGenerator { + + public MultiPartArticleDataXMLGenerator() { + //Nothing + } + + public void generateXML(final ContentItem item, + final Element element, + final PageState state) { + if (!(item instanceof MultiPartArticle)) { + throw new IllegalArgumentException("This ExtraXMLGenerator can only process " + + "MultiPartArticleItems."); + } + + final MultiPartArticle article = (MultiPartArticle) item; + + final Element root = element.newChildElement("cms:mpadata", CMS.CMS_XML_NS); + + final Element numberOfPages = root.newChildElement("numberOfPages"); + numberOfPages.setText(calulateNumberOfPages(article)); + + + } + + private String calulateNumberOfPages(final MultiPartArticle article) { + int numberOfPages = 0; + + final ArticleSectionCollection sections = article.getSections(); + while(sections.next()) { + if (sections.getArticleSection().isPageBreak()) { + numberOfPages++; + } + } + + if (numberOfPages == 0) { + numberOfPages = 1; + } + + return Integer.toString(numberOfPages); + } + + public void addGlobalStateParams(final Page page) { + //Nothing + } + + public void setListMode(final boolean listMode) { + //Ignored here + } + +}