Added missing metadata for the MPA to the XML (#1930).

git-svn-id: https://svn.libreccm.org/ccm/trunk@2675 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2014-06-06 13:37:55 +00:00
parent f6ae155a06
commit 03a58e56e3
2 changed files with 132 additions and 68 deletions

View File

@ -1,3 +1,21 @@
/*
* Copyright (C) 2002-2004 Red Hat Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.arsdigita.cms.contenttypes; package com.arsdigita.cms.contenttypes;
import com.arsdigita.bebop.Page; import com.arsdigita.bebop.Page;
@ -30,15 +48,18 @@ 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) {
Element content = element.newChildElement("cms:articleSectionPanel", final Element content = element.newChildElement("cms:articleSectionPanel",
CMS.CMS_XML_NS); CMS.CMS_XML_NS);
XMLGenerator xmlGenerator = getXMLGenerator(state, item); final XMLGenerator xmlGenerator = getXMLGenerator(state, item);
ArticleSection sections[] = getSections(item, state); final ArticleSection sections[] = getSections(item, state);
for (int i = 0; i < sections.length; i++) { for (int i = 0; i < sections.length; i++) {
generateSectionXML(state, content, sections[i], xmlGenerator); generateSectionXML(state, content, sections[i], xmlGenerator);
} }
final PageNumber number = getPageNumber(state);
content.addAttribute("pageNumber", number.getPageNumber().toString());
} }
public void addGlobalStateParams(final Page page) { public void addGlobalStateParams(final Page page) {
@ -49,6 +70,21 @@ public class ArticleSectionXMLGenerator implements ExtraXMLGenerator {
//nothing //nothing
} }
protected PageNumber getPageNumber(final PageState state) {
PageNumber number;
String value = state.getRequest().getParameter(PAGE_NUMBER_PARAM);
if (value == null) {
value = "1";
}
number = new PageNumber(value);
if (number == null) {
number = new PageNumber("1");
}
return number;
}
protected void generateSectionXML(final PageState state, protected void generateSectionXML(final PageState state,
final Element parent, final Element parent,
final ContentItem section, final ContentItem section,
@ -59,6 +95,7 @@ public class ArticleSectionXMLGenerator implements ExtraXMLGenerator {
setContentItem(section); setContentItem(section);
xmlGenerator.generateXML(state, parent, null); xmlGenerator.generateXML(state, parent, null);
} }
}; };
try { try {
excursion.run(); excursion.run();
@ -69,26 +106,20 @@ public class ArticleSectionXMLGenerator implements ExtraXMLGenerator {
} }
} }
protected ArticleSection[] getSections(ContentItem item, protected ArticleSection[] getSections(final ContentItem item,
final PageState state) { final PageState state) {
PageNumber number = null; // PageNumber number = null;
//try { //
// String value = state.getRequest().getParameter(PAGE_NUMBER_PARAM);
// if (value == null) {
// value = "1";
// }
// number = new PageNumber(value);
// if (number == null) {
// number = new PageNumber("1");
// }
final PageNumber number = getPageNumber(state);
//number = (PageNumber) state.getValue(pageParam);
//} catch (IllegalArgumentException e) {
// probably viewing an index item on a category,
// get the parameter from the request and set it
String value = state.getRequest().getParameter(PAGE_NUMBER_PARAM);
if (value == null) {
value = "1";
}
number = new PageNumber(value);
//state.setValue(pageParam, number);
//}
if (number == null) {
number = new PageNumber("1");
}
MultiPartArticle mpa = (MultiPartArticle) item; MultiPartArticle mpa = (MultiPartArticle) item;
if (!number.wantAllSections()) { if (!number.wantAllSections()) {
@ -106,9 +137,9 @@ public class ArticleSectionXMLGenerator implements ExtraXMLGenerator {
} }
// Get the section based on position in list of sections // Get the section based on position in list of sections
protected ArticleSection[] getSections(ContentItem item, protected ArticleSection[] getSections(final ContentItem item,
PageState state, final PageState state,
Integer number) { final Integer number) {
MultiPartArticle mpa = (MultiPartArticle) item; MultiPartArticle mpa = (MultiPartArticle) item;
ArticleSectionCollection sections = mpa.getSections(); ArticleSectionCollection sections = mpa.getSections();
int current = 1; int current = 1;
@ -122,8 +153,7 @@ public class ArticleSectionXMLGenerator implements ExtraXMLGenerator {
return new ArticleSection[]{}; return new ArticleSection[]{};
} }
ArticleSection section = (ArticleSection) sections. ArticleSection section = (ArticleSection) sections.getArticleSection();
getArticleSection();
if (section.isPageBreak()) { if (section.isPageBreak()) {
current++; current++;
@ -152,14 +182,15 @@ public class ArticleSectionXMLGenerator implements ExtraXMLGenerator {
} }
/** /**
* Try to get the section from the context * Try to get the section from the context if there isn't (eg if we are looking at an index item
* if there isn't (eg if we are looking at an index * on a category), guess the section from the item
* item on a category), guess the section from the item *
* @param state * @param state
* @param item * @param item
*
* @return * @return
*/ */
protected XMLGenerator getXMLGenerator(PageState state, 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();
@ -198,6 +229,7 @@ public class ArticleSectionXMLGenerator implements ExtraXMLGenerator {
public Integer getPageNumber() { public Integer getPageNumber() {
return m_number; return m_number;
} }
} }
// 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'
@ -232,4 +264,5 @@ public class ArticleSectionXMLGenerator implements ExtraXMLGenerator {
return PageNumber.class; return PageNumber.class;
} }
}*/ }*/
} }

View File

@ -1,3 +1,21 @@
/*
* Copyright (C) 2014 Jens Pelzetter
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.arsdigita.cms.contenttypes; package com.arsdigita.cms.contenttypes;
import com.arsdigita.bebop.Page; import com.arsdigita.bebop.Page;
@ -10,6 +28,7 @@ import com.arsdigita.xml.Element;
/** /**
* *
* @author Jens Pelzetter <jens@jp-digital.de> * @author Jens Pelzetter <jens@jp-digital.de>
* @version $Id$
*/ */
public class MultiPartArticleDataXMLGenerator implements ExtraXMLGenerator { public class MultiPartArticleDataXMLGenerator implements ExtraXMLGenerator {
@ -36,20 +55,32 @@ public class MultiPartArticleDataXMLGenerator implements ExtraXMLGenerator {
} }
private String calulateNumberOfPages(final MultiPartArticle article) { private String calulateNumberOfPages(final MultiPartArticle article) {
int numberOfPages = 0;
final ArticleSectionCollection sections = article.getSections(); final ArticleSectionCollection sections = article.getSections();
if (article.getSections().size() == 0) {
sections.close();
return "0";
}
long numberOfPages = 1;
long index = 0;
long lastIndex = sections.size() - 1;
while(sections.next()) { while(sections.next()) {
if (sections.getArticleSection().isPageBreak()) { index++;
//The check for last index is necessary because we don't want to count a page break after
//the last section
if (sections.getArticleSection().isPageBreak()
&& index < (lastIndex)) {
numberOfPages++; numberOfPages++;
} }
} }
if (numberOfPages == 0) { // if (numberOfPages == 0) {
numberOfPages = 1; // numberOfPages = 1;
} // }
return Integer.toString(numberOfPages); return Long.toString(numberOfPages);
} }
public void addGlobalStateParams(final Page page) { public void addGlobalStateParams(final Page page) {