Missing file
git-svn-id: https://svn.libreccm.org/ccm/trunk@2510 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
e67b6ead1b
commit
f9e11f3f34
|
|
@ -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 <jens@jp-digital.de>
|
||||||
|
*/
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue