/* * Copyright (C) 2001-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.dispatcher; import com.arsdigita.bebop.Page; import com.arsdigita.bebop.PageState; import com.arsdigita.cms.CMS; import com.arsdigita.cms.ContentItem; import com.arsdigita.cms.ContentItemXMLRenderer; import com.arsdigita.cms.ContentSection; import com.arsdigita.cms.ExtraXMLGenerator; import com.arsdigita.cms.SecurityManager; import com.arsdigita.cms.UserDefinedContentItem; import com.arsdigita.cms.util.GlobalizationUtil; import com.arsdigita.domain.DataObjectNotFoundException; import com.arsdigita.domain.DomainObjectFactory; import com.arsdigita.domain.DomainObjectTraversal; import com.arsdigita.domain.SimpleDomainObjectTraversalAdapter; import com.arsdigita.kernel.Kernel; import com.arsdigita.kernel.Party; import com.arsdigita.kernel.permissions.PermissionDescriptor; import com.arsdigita.kernel.permissions.PermissionService; import com.arsdigita.kernel.permissions.PrivilegeDescriptor; import com.arsdigita.metadata.DynamicObjectType; import com.arsdigita.persistence.OID; import com.arsdigita.persistence.metadata.Property; import com.arsdigita.util.UncheckedWrapperException; import com.arsdigita.xml.Element; import org.apache.log4j.Logger; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; /** *
The default XMLGenerator implementation.
* * @author Michael Pih * @version $Revision: #20 $ $DateTime: 2004/08/17 23:15:09 $ * @version $Id: SimpleXMLGenerator.java 2167 2011-06-19 21:12:12Z pboy $ */ public class SimpleXMLGenerator implements XMLGenerator { private static final Logger s_log = Logger.getLogger(SimpleXMLGenerator.class); public static final String ADAPTER_CONTEXT = SimpleXMLGenerator.class. getName(); /** * jensp 2011-10-23: Sometimes the extra XML is not needed, for example * when embedding the XML of a content item into the XML output of another * content item. The default value {@code true}. To change the value * call {@link #setUseExtraXml(booelan)} after creating an instance of * your generator. */ private boolean useExtraXml = true; /** * jensp 2012-04-18: This value is forwarded to this ExtraXMLGenerators * by calling {@link ExtraXMLGenerator#setListMode(boolean)}. The behavior * triggered by this value depends on the specific implementation of * the {@code ExtraXMLGenerator} */ private boolean listMode = false; /** * Extra attributes for the cms:item element. */ private MapContentItem that is set in the page state
* by the dispatcher.
*
* @param state The page state
* @return A content item
*/
protected ContentItem getContentItem(PageState state) {
if (CMS.getContext().hasContentItem()) {
return CMS.getContext().getContentItem();
} else {
CMSPage page = (CMSPage) state.getPage();
return page.getContentItem(state);
}
}
protected void generateUDItemXML(UserDefinedContentItem UDItem,
PageState state,
Element parent,
String useContext) {
Element element = startElement(useContext, parent);
Element additionalAttrs = UDItemElement(useContext);
element.addAttribute("type", UDItem.getContentType().getLabel());
element.addAttribute("id", UDItem.getID().toString());
element.addAttribute("name", UDItem.getName());
element.addAttribute("title", UDItem.getTitle());
element.addAttribute("javaClass", UDItem.getContentType().getClassName());
DynamicObjectType dot = new DynamicObjectType(
UDItem.getSpecificObjectType());
Iterator declaredProperties =
dot.getObjectType().getDeclaredProperties();
Property currentProperty = null;
Object value = null;
while (declaredProperties.hasNext()) {
currentProperty = (Property) declaredProperties.next();
value = (Object) UDItem.get(currentProperty.getName());
if (value != null) {
element.addContent(
UDItemAttrElement(currentProperty.getName(),
value.toString()));
} else {
element.addContent(
UDItemAttrElement(currentProperty.getName(),
"none specified"));
}
}
//element.addContent(additionalAttrs);
//parent.addContent(element);
}
private Element startElement(String useContext, Element parent) {
//Element element = new Element("cms:item", CMS.CMS_XML_NS);
//final Element element = new Element(itemElemName, itemElemNs);
final Element element = parent.newChildElement(itemElemName,
itemElemNs);
if (useContext != null) {
element.addAttribute("useContext", useContext);
}
for (Map.Entry