Versuch, die zusätzlichen JSPs für MultiPartArticle etc. loszuwerden. Funktioniert soweit, aber: Funktioniert nur mit
Mandalay. Mit dem alten Theme funktioniert der MPA derzeit NICHT! git-svn-id: https://svn.libreccm.org/ccm/trunk@1073 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
29952fdc4c
commit
f9b612b3db
|
|
@ -0,0 +1,230 @@
|
||||||
|
package com.arsdigita.cms.contenttypes;
|
||||||
|
|
||||||
|
import com.arsdigita.bebop.Page;
|
||||||
|
import com.arsdigita.bebop.PageState;
|
||||||
|
import com.arsdigita.cms.CMS;
|
||||||
|
import com.arsdigita.cms.CMSExcursion;
|
||||||
|
import com.arsdigita.cms.ContentItem;
|
||||||
|
import com.arsdigita.cms.ContentSection;
|
||||||
|
import com.arsdigita.cms.ExtraXMLGenerator;
|
||||||
|
import com.arsdigita.cms.dispatcher.XMLGenerator;
|
||||||
|
import com.arsdigita.util.UncheckedWrapperException;
|
||||||
|
import com.arsdigita.xml.Element;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jens Pelzetter
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
public class ArticleSectionXMLGenerator implements ExtraXMLGenerator {
|
||||||
|
|
||||||
|
public static final String PAGE_NUMBER_PARAM = "page";
|
||||||
|
//private final PageParameter pageParam = new PageParameter(PAGE_NUMBER_PARAM);
|
||||||
|
|
||||||
|
public ArticleSectionXMLGenerator() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void generateXML(final ContentItem item,
|
||||||
|
final Element element,
|
||||||
|
final PageState state) {
|
||||||
|
Element content = element.newChildElement("cms:articleSectionPanel",
|
||||||
|
CMS.CMS_XML_NS);
|
||||||
|
|
||||||
|
XMLGenerator xmlGenerator = getXMLGenerator(state, item);
|
||||||
|
|
||||||
|
ArticleSection sections[] = getSections(item, state);
|
||||||
|
for (int i = 0; i < sections.length; i++) {
|
||||||
|
generateSectionXML(state, content, sections[i], xmlGenerator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addGlobalStateParams(final Page page) {
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void generateSectionXML(final PageState state,
|
||||||
|
final Element parent,
|
||||||
|
final ContentItem section,
|
||||||
|
final XMLGenerator xmlGenerator) {
|
||||||
|
CMSExcursion excursion = new CMSExcursion() {
|
||||||
|
|
||||||
|
public void excurse() {
|
||||||
|
setContentItem(section);
|
||||||
|
xmlGenerator.generateXML(state, parent, null);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
excursion.run();
|
||||||
|
} catch (ServletException ex) {
|
||||||
|
throw new UncheckedWrapperException("excursion failed", ex);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
throw new UncheckedWrapperException("excursion failed", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ArticleSection[] getSections(ContentItem item,
|
||||||
|
final PageState state) {
|
||||||
|
PageNumber number = null;
|
||||||
|
//try {
|
||||||
|
|
||||||
|
|
||||||
|
//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;
|
||||||
|
if (!number.wantAllSections()) {
|
||||||
|
return getSections(item, state, number.getPageNumber());
|
||||||
|
} else {
|
||||||
|
ArticleSectionCollection sections = mpa.getSections();
|
||||||
|
ArticleSection[] page = new ArticleSection[(int) sections.size()];
|
||||||
|
int i = 0;
|
||||||
|
while (sections.next()) {
|
||||||
|
page[i] = (ArticleSection) sections.getArticleSection();
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return page;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the section based on position in list of sections
|
||||||
|
protected ArticleSection[] getSections(ContentItem item,
|
||||||
|
PageState state,
|
||||||
|
Integer number) {
|
||||||
|
MultiPartArticle mpa = (MultiPartArticle) item;
|
||||||
|
ArticleSectionCollection sections = mpa.getSections();
|
||||||
|
int current = 1;
|
||||||
|
int desired = number.intValue();
|
||||||
|
|
||||||
|
ArrayList page;
|
||||||
|
try {
|
||||||
|
// Skip over sections until we hit the desired page
|
||||||
|
while (current < desired) {
|
||||||
|
if (!sections.next()) {
|
||||||
|
|
||||||
|
return new ArticleSection[]{};
|
||||||
|
}
|
||||||
|
ArticleSection section = (ArticleSection) sections.
|
||||||
|
getArticleSection();
|
||||||
|
|
||||||
|
if (section.isPageBreak()) {
|
||||||
|
current++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now capture sections until we hit the next page (or end of sections)
|
||||||
|
int subsequent = desired + 1;
|
||||||
|
page = new ArrayList();
|
||||||
|
while (current < subsequent) {
|
||||||
|
if (!sections.next()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ArticleSection section = (ArticleSection) sections.
|
||||||
|
getArticleSection();
|
||||||
|
page.add(section);
|
||||||
|
if (section.isPageBreak()) {
|
||||||
|
current++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
sections.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
return (ArticleSection[]) page.toArray(new ArticleSection[page.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Try to get the section from the context
|
||||||
|
* if there isn't (eg if we are looking at an index
|
||||||
|
* item on a category), guess the section from the item
|
||||||
|
* @param state
|
||||||
|
* @param item
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected XMLGenerator getXMLGenerator(PageState state, ContentItem item) {
|
||||||
|
ContentSection section = null;
|
||||||
|
try {
|
||||||
|
section = CMS.getContext().getContentSection();
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
if (section == null) {
|
||||||
|
section = item.getContentSection();
|
||||||
|
CMS.getContext().setContentSection(section);
|
||||||
|
}
|
||||||
|
return section.getXMLGenerator();
|
||||||
|
}
|
||||||
|
|
||||||
|
// A class representing either an Integer number indicating
|
||||||
|
// the position in the list of sections, or the string 'all'
|
||||||
|
private class PageNumber {
|
||||||
|
|
||||||
|
private boolean m_all;
|
||||||
|
private Integer m_number;
|
||||||
|
|
||||||
|
public PageNumber(String number)
|
||||||
|
throws NumberFormatException {
|
||||||
|
|
||||||
|
if ("all".equals(number.toLowerCase())) {
|
||||||
|
m_all = true;
|
||||||
|
m_number = null;
|
||||||
|
} else {
|
||||||
|
m_all = false;
|
||||||
|
m_number = new Integer(number);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean wantAllSections() {
|
||||||
|
return m_all;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getPageNumber() {
|
||||||
|
return m_number;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// A parameter which is either an Integer number indicating
|
||||||
|
// the position in the list of sections, or the string 'all'
|
||||||
|
/*private class PageParameter extends ParameterModel {
|
||||||
|
|
||||||
|
public PageParameter(String name) {
|
||||||
|
super(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object transformValue(HttpServletRequest request)
|
||||||
|
throws IllegalArgumentException {
|
||||||
|
return transformSingleValue(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object unmarshal(String encoded)
|
||||||
|
throws IllegalArgumentException {
|
||||||
|
|
||||||
|
if (encoded == null || encoded.length() == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return new PageNumber(encoded);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new IllegalArgumentException(getName()
|
||||||
|
+ " should be a BigDecimal: '"
|
||||||
|
+ encoded + "'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Class getValueClass() {
|
||||||
|
return PageNumber.class;
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
|
@ -19,6 +19,8 @@
|
||||||
package com.arsdigita.cms.contenttypes;
|
package com.arsdigita.cms.contenttypes;
|
||||||
|
|
||||||
import com.arsdigita.cms.ContentPage;
|
import com.arsdigita.cms.ContentPage;
|
||||||
|
import com.arsdigita.cms.ExtraXMLGenerator;
|
||||||
|
import com.arsdigita.cms.contenttypes.ui.mparticle.ArticleSectionPanel;
|
||||||
import com.arsdigita.domain.DataObjectNotFoundException;
|
import com.arsdigita.domain.DataObjectNotFoundException;
|
||||||
import com.arsdigita.domain.DomainObjectFactory;
|
import com.arsdigita.domain.DomainObjectFactory;
|
||||||
import com.arsdigita.persistence.DataAssociation;
|
import com.arsdigita.persistence.DataAssociation;
|
||||||
|
|
@ -29,8 +31,7 @@ import com.arsdigita.persistence.OID;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Collection;
|
import java.util.List;
|
||||||
import java.util.HashSet;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CMS content type that represents a multi-part article.
|
* CMS content type that represents a multi-part article.
|
||||||
|
|
@ -292,5 +293,14 @@ public class MultiPartArticle extends ContentPage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ExtraXMLGenerator> getExtraXMLGenerators() {
|
||||||
|
final List<ExtraXMLGenerator> generators = super.getExtraXMLGenerators();
|
||||||
|
|
||||||
|
//generators.add(new ArticleSectionPanel());
|
||||||
|
generators.add(new ArticleSectionXMLGenerator());
|
||||||
|
|
||||||
|
return generators;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1592,8 +1592,6 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
||||||
return newItem;
|
return newItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs the actual mechanics of copying a content item.
|
* Performs the actual mechanics of copying a content item.
|
||||||
* Non-final so that subtypes can extend copying behavior.
|
* Non-final so that subtypes can extend copying behavior.
|
||||||
|
|
@ -2171,14 +2169,13 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
||||||
public String getLastModifiedIP() {
|
public String getLastModifiedIP() {
|
||||||
return m_audit_trail.getLastModifiedIP();
|
return m_audit_trail.getLastModifiedIP();
|
||||||
}
|
}
|
||||||
protected static List extraXMLGenerators = new ArrayList();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override this to explicit that your content items
|
* Override this to explicit that your content items
|
||||||
* have extra XML to generate.
|
* have extra XML to generate.
|
||||||
* ATM This is used in navigation for GreetingItems.
|
* @return A list of all extra XML Generators for this content item.
|
||||||
*/
|
*/
|
||||||
public List getExtraXMLGenerators() {
|
public List<ExtraXMLGenerator> getExtraXMLGenerators() {
|
||||||
return extraXMLGenerators;
|
return new ArrayList<ExtraXMLGenerator>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ package com.arsdigita.cms;
|
||||||
|
|
||||||
import com.arsdigita.bebop.Page;
|
import com.arsdigita.bebop.Page;
|
||||||
import com.arsdigita.bebop.PageState;
|
import com.arsdigita.bebop.PageState;
|
||||||
import com.arsdigita.cms.ContentItem;
|
|
||||||
import com.arsdigita.xml.Element;
|
import com.arsdigita.xml.Element;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -20,11 +19,15 @@ public interface ExtraXMLGenerator {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specify the XML for a given content item.
|
* Specify the XML for a given content item.
|
||||||
|
* @param item The content item to render
|
||||||
|
* @param element The element to add the rendered content to
|
||||||
|
* @param state The current page state
|
||||||
*/
|
*/
|
||||||
public void generateXML(ContentItem item, Element element, PageState state);
|
public void generateXML(ContentItem item, Element element, PageState state);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add all required global parameters.
|
* Add all required global parameters.
|
||||||
|
* @param p The page which contains to item to render
|
||||||
*/
|
*/
|
||||||
public void addGlobalStateParams(Page p);
|
public void addGlobalStateParams(Page p);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,13 @@
|
||||||
*/
|
*/
|
||||||
package com.arsdigita.cms.dispatcher;
|
package com.arsdigita.cms.dispatcher;
|
||||||
|
|
||||||
|
import com.arsdigita.bebop.Page;
|
||||||
import com.arsdigita.bebop.PageState;
|
import com.arsdigita.bebop.PageState;
|
||||||
import com.arsdigita.cms.CMS;
|
import com.arsdigita.cms.CMS;
|
||||||
import com.arsdigita.cms.ContentItem;
|
import com.arsdigita.cms.ContentItem;
|
||||||
import com.arsdigita.cms.ContentItemXMLRenderer;
|
import com.arsdigita.cms.ContentItemXMLRenderer;
|
||||||
import com.arsdigita.cms.ContentSection;
|
import com.arsdigita.cms.ContentSection;
|
||||||
|
import com.arsdigita.cms.ExtraXMLGenerator;
|
||||||
import com.arsdigita.cms.SecurityManager;
|
import com.arsdigita.cms.SecurityManager;
|
||||||
import com.arsdigita.cms.UserDefinedContentItem;
|
import com.arsdigita.cms.UserDefinedContentItem;
|
||||||
import com.arsdigita.cms.util.GlobalizationUtil;
|
import com.arsdigita.cms.util.GlobalizationUtil;
|
||||||
|
|
@ -101,13 +103,15 @@ public class SimpleXMLGenerator implements XMLGenerator {
|
||||||
// Note that the xml that is generated is only of use if you DO NOT CACHE content pages.
|
// Note that the xml that is generated is only of use if you DO NOT CACHE content pages.
|
||||||
// cg.
|
// cg.
|
||||||
|
|
||||||
PermissionDescriptor edit = new PermissionDescriptor(PrivilegeDescriptor.
|
PermissionDescriptor edit =
|
||||||
get(SecurityManager.CMS_EDIT_ITEM), item, currentParty);
|
new PermissionDescriptor(PrivilegeDescriptor.get(
|
||||||
|
SecurityManager.CMS_EDIT_ITEM), item, currentParty);
|
||||||
if (PermissionService.checkPermission(edit)) {
|
if (PermissionService.checkPermission(edit)) {
|
||||||
parent.addAttribute("canEdit", "true");
|
parent.addAttribute("canEdit", "true");
|
||||||
}
|
}
|
||||||
PermissionDescriptor publish = new PermissionDescriptor(PrivilegeDescriptor.
|
PermissionDescriptor publish =
|
||||||
get(SecurityManager.CMS_PUBLISH), item, currentParty);
|
new PermissionDescriptor(PrivilegeDescriptor.get(
|
||||||
|
SecurityManager.CMS_PUBLISH), item, currentParty);
|
||||||
if (PermissionService.checkPermission(publish)) {
|
if (PermissionService.checkPermission(publish)) {
|
||||||
parent.addAttribute("canPublish", "true");
|
parent.addAttribute("canPublish", "true");
|
||||||
}
|
}
|
||||||
|
|
@ -117,7 +121,9 @@ public class SimpleXMLGenerator implements XMLGenerator {
|
||||||
if (!item.getClass().getName().equals(className)) {
|
if (!item.getClass().getName().equals(className)) {
|
||||||
s_log.info("Specializing item");
|
s_log.info("Specializing item");
|
||||||
try {
|
try {
|
||||||
item = (ContentItem) DomainObjectFactory.newInstance(new OID(item. getObjectType().getQualifiedName(), item.getID()));
|
item =
|
||||||
|
(ContentItem) DomainObjectFactory.newInstance(new OID(item.
|
||||||
|
getObjectType().getQualifiedName(), item.getID()));
|
||||||
} catch (DataObjectNotFoundException ex) {
|
} catch (DataObjectNotFoundException ex) {
|
||||||
throw new UncheckedWrapperException(
|
throw new UncheckedWrapperException(
|
||||||
(String) GlobalizationUtil.globalize(
|
(String) GlobalizationUtil.globalize(
|
||||||
|
|
@ -143,7 +149,8 @@ public class SimpleXMLGenerator implements XMLGenerator {
|
||||||
// This is the preferred method
|
// This is the preferred method
|
||||||
Element content = startElement(useContext);
|
Element content = startElement(useContext);
|
||||||
|
|
||||||
ContentItemXMLRenderer renderer = new ContentItemXMLRenderer(content);
|
ContentItemXMLRenderer renderer =
|
||||||
|
new ContentItemXMLRenderer(content);
|
||||||
|
|
||||||
renderer.setWrapAttributes(true);
|
renderer.setWrapAttributes(true);
|
||||||
renderer.setWrapRoot(false);
|
renderer.setWrapRoot(false);
|
||||||
|
|
@ -153,11 +160,15 @@ public class SimpleXMLGenerator implements XMLGenerator {
|
||||||
renderer.walk(item, ADAPTER_CONTEXT);
|
renderer.walk(item, ADAPTER_CONTEXT);
|
||||||
|
|
||||||
parent.addContent(content);
|
parent.addContent(content);
|
||||||
|
|
||||||
|
for (ExtraXMLGenerator generator : item.getExtraXMLGenerators()) {
|
||||||
|
generator.generateXML(item, parent, state);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches the current content item. This method can be overidden to
|
* Fetches the current content item. This method can be overridden to
|
||||||
* fetch any {@link com.arsdigita.cms.ContentItem}, but by default,
|
* fetch any {@link com.arsdigita.cms.ContentItem}, but by default,
|
||||||
* it fetches the <code>ContentItem</code> that is set in the page state
|
* it fetches the <code>ContentItem</code> that is set in the page state
|
||||||
* by the dispatcher.
|
* by the dispatcher.
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ public class SimplePage extends com.arsdigita.ui.SimplePage {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
public Element generateXMLHelper(PageState state,
|
public Element generateXMLHelper(PageState state,
|
||||||
Document parent) {
|
Document parent) {
|
||||||
Element page = super.generateXMLHelper(state, parent);
|
Element page = super.generateXMLHelper(state, parent);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue