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;
@ -16,7 +34,7 @@ import javax.servlet.ServletException;
/** /**
* *
* @author Jens Pelzetter * @author Jens Pelzetter
* @version $Id$ * @version $Id$
*/ */
public class ArticleSectionXMLGenerator implements ExtraXMLGenerator { public class ArticleSectionXMLGenerator implements ExtraXMLGenerator {
@ -30,25 +48,43 @@ 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) {
} }
@Override @Override
public void setListMode(final boolean listMode) { public void setListMode(final boolean listMode) {
//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) {
//number = (PageNumber) state.getValue(pageParam); // value = "1";
//} catch (IllegalArgumentException e) { // }
// probably viewing an index item on a category, // number = new PageNumber(value);
// get the parameter from the request and set it // if (number == null) {
String value = state.getRequest().getParameter(PAGE_NUMBER_PARAM); // number = new PageNumber("1");
if (value == null) { // }
value = "1";
} final PageNumber number = getPageNumber(state);
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++;
@ -138,7 +168,7 @@ public class ArticleSectionXMLGenerator implements ExtraXMLGenerator {
break; break;
} }
ArticleSection section = (ArticleSection) sections. ArticleSection section = (ArticleSection) sections.
getArticleSection(); getArticleSection();
page.add(section); page.add(section);
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();
@ -180,7 +211,7 @@ public class ArticleSectionXMLGenerator implements ExtraXMLGenerator {
private Integer m_number; private Integer m_number;
public PageNumber(String number) public PageNumber(String number)
throws NumberFormatException { throws NumberFormatException {
if ("all".equals(number.toLowerCase())) { if ("all".equals(number.toLowerCase())) {
m_all = true; m_all = true;
@ -198,38 +229,40 @@ 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'
/*private class PageParameter extends ParameterModel { /*private class PageParameter extends ParameterModel {
public PageParameter(String name) { public PageParameter(String name) {
super(name); super(name);
} }
public Object transformValue(HttpServletRequest request) public Object transformValue(HttpServletRequest request)
throws IllegalArgumentException { throws IllegalArgumentException {
return transformSingleValue(request); return transformSingleValue(request);
} }
public Object unmarshal(String encoded) public Object unmarshal(String encoded)
throws IllegalArgumentException { throws IllegalArgumentException {
if (encoded == null || encoded.length() == 0) { if (encoded == null || encoded.length() == 0) {
return null; return null;
} }
try { try {
return new PageNumber(encoded); return new PageNumber(encoded);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
e.printStackTrace(); e.printStackTrace();
throw new IllegalArgumentException(getName() throw new IllegalArgumentException(getName()
+ " should be a BigDecimal: '" + " should be a BigDecimal: '"
+ encoded + "'"); + encoded + "'");
} }
} }
public Class getValueClass() { public Class getValueClass() {
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) {