- Verschiedene Formatierungen

- Bug im ldn-importer gefixt
- SimpleDomainObjectTraversalAdapter um remove-Methoden erweitert


git-svn-id: https://svn.libreccm.org/ccm/trunk@597 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2010-11-04 10:55:31 +00:00
parent db9baf50d5
commit 478a66f4b9
9 changed files with 280 additions and 220 deletions

View File

@ -69,6 +69,7 @@ public class ContentItemTraversalAdapter
* to the asset's adapter, otherwise delegates to
* the content item's primary adapter
*/
@Override
public boolean processProperty(DomainObject obj,
String path,
Property prop,

View File

@ -18,7 +18,6 @@
*/
package com.arsdigita.cms.dispatcher;
import com.arsdigita.bebop.PageState;
import com.arsdigita.cms.CMS;
import com.arsdigita.cms.ContentItem;
@ -45,7 +44,6 @@ import org.apache.log4j.Logger;
import java.util.Iterator;
/**
* <p>The default <tt>XMLGenerator</tt> implementation.</p>
*
@ -57,8 +55,8 @@ public class SimpleXMLGenerator implements XMLGenerator {
private static Logger s_log =
Logger.getLogger(SimpleXMLGenerator.class);
public static final String ADAPTER_CONTEXT = SimpleXMLGenerator.class.getName();
public static final String ADAPTER_CONTEXT = SimpleXMLGenerator.class.
getName();
// Register general purpose adaptor for all content items
static {
@ -70,11 +68,11 @@ public class SimpleXMLGenerator implements XMLGenerator {
DomainObjectTraversal.registerAdapter(
ContentItem.BASE_DATA_OBJECT_TYPE,
adapter,
ADAPTER_CONTEXT
);
ADAPTER_CONTEXT);
}
public SimpleXMLGenerator() {}
public SimpleXMLGenerator() {
}
/**
* Generates the XML to render the content panel.
@ -101,11 +99,13 @@ public class SimpleXMLGenerator implements XMLGenerator {
// Note that the xml that is generated is only of use if you DO NOT CACHE content pages.
// cg.
PermissionDescriptor edit = new PermissionDescriptor(PrivilegeDescriptor.get(SecurityManager.CMS_EDIT_ITEM), item, currentParty);
PermissionDescriptor edit = new PermissionDescriptor(PrivilegeDescriptor.
get(SecurityManager.CMS_EDIT_ITEM), item, currentParty);
if (PermissionService.checkPermission(edit)) {
parent.addAttribute("canEdit", "true");
}
PermissionDescriptor publish = new PermissionDescriptor(PrivilegeDescriptor.get(SecurityManager.CMS_PUBLISH), item, currentParty);
PermissionDescriptor publish = new PermissionDescriptor(PrivilegeDescriptor.
get(SecurityManager.CMS_PUBLISH), item, currentParty);
if (PermissionService.checkPermission(publish)) {
parent.addAttribute("canPublish", "true");
}
@ -115,14 +115,15 @@ public class SimpleXMLGenerator implements XMLGenerator {
if (!item.getClass().getName().equals(className)) {
s_log.info("Specializing item");
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) {
throw new UncheckedWrapperException(
(String) GlobalizationUtil.globalize(
"cms.dispatcher.cannot_find_domain_object"
).localize(), ex);
"cms.dispatcher.cannot_find_domain_object").localize(),
ex);
}
}
@ -132,7 +133,8 @@ public class SimpleXMLGenerator implements XMLGenerator {
XMLGenerator xitem = (XMLGenerator) item;
xitem.generateXML(state, parent, useContext);
} else if (className.equals("com.arsdigita.cms.UserDefinedContentItem")) {
} else if (className.equals(
"com.arsdigita.cms.UserDefinedContentItem")) {
s_log.info("Item is a user defined content item");
UserDefinedContentItem UDItem = (UserDefinedContentItem) item;
generateUDItemXML(UDItem, state, parent, useContext);
@ -157,7 +159,6 @@ public class SimpleXMLGenerator implements XMLGenerator {
}
}
/**
* Fetches the current content item. This method can be overidden to
* fetch any {@link com.arsdigita.cms.ContentItem}, but by default,
@ -191,10 +192,9 @@ public class SimpleXMLGenerator implements XMLGenerator {
element.addAttribute("javaClass", UDItem.getContentType().getClassName());
DynamicObjectType dot = new DynamicObjectType(
UDItem.getSpecificObjectType()
);
Iterator declaredProperties = dot.getObjectType()
.getDeclaredProperties();
UDItem.getSpecificObjectType());
Iterator declaredProperties =
dot.getObjectType().getDeclaredProperties();
Property currentProperty = null;
Object value = null;
while (declaredProperties.hasNext()) {
@ -216,8 +216,6 @@ public class SimpleXMLGenerator implements XMLGenerator {
}
private Element startElement(String useContext) {
Element element = new Element("cms:item", CMS.CMS_XML_NS);
if (useContext != null) {
@ -242,5 +240,4 @@ public class SimpleXMLGenerator implements XMLGenerator {
element.addAttribute("UDItemAttrValue", value);
return element;
}
}

View File

@ -38,18 +38,21 @@ public class ContentPageMetadataProvider extends ContentItemMetadataProvider {
public static final String ADAPTER_CONTEXT =
ContentPageMetadataProvider.class.getName();
private static final Logger s_log =
Logger.getLogger(ContentPageMetadataProvider.class);
Logger.getLogger(
ContentPageMetadataProvider.class);
public String getTitle(DomainObject dobj) {
if (dobj instanceof ContentPage) {
ContentPage item = (ContentPage) dobj;
s_log.debug(String.format("getting title of item with oid '%s'",
item.getOID().toString()));
s_log.debug(String.format("and name '%s'", item.getName()));
s_log.debug(String.format("and title '%s'", item.getTitle()));
String title = item.getTitle();
if (StringUtils.emptyString(title)) {
throw new IllegalArgumentException(
"ContentPage must have non-blank title!"
);
"ContentPage must have non-blank title!");
}
return title;
} else {

View File

@ -104,21 +104,39 @@ public class SimpleDomainObjectTraversalAdapter
/**
* Add a property to the attribute property set.
*
* @param path the full path to the property
* @param prop the full path to the property
*/
public void addAttributeProperty(String prop) {
m_attr.add(prop);
}
/**
* Removes a property from the attribute property set.
*
* @param prop full path of the property to remove
*/
public void removeAttributeProperty(String prop) {
m_attr.remove(prop);
}
/**
* Add a property to the association property set.
*
* @param path the full path to the property
* @param prop the full path to the property
*/
public void addAssociationProperty(String prop) {
m_assoc.add(prop);
}
/**
* Removes a association property from the association property set.
*
* @param prop full path of the property to remove
*/
public void removeAssociationProperty(String prop) {
m_assoc.remove(prop);
}
/**
* Determines whether or not to allow processing
* of a property, based on the property set and

View File

@ -59,7 +59,6 @@ public class OID {
private ObjectType m_type;
private Map m_values = new HashMap();
/** some shorthand names for common content-types */
private final static String[][] TYPE_SHORTHAND = {
{"Article", "com.arsdigita.cms.contenttypes.Article"},
@ -71,20 +70,17 @@ public class OID {
{"SiteProxy", "com.arsdigita.cms.contenttypes.SiteProxy"},
{"RelatedLink", "com.arsdigita.cms.contentassets.RelatedLink"},
{"FileAttachment", "com.arsdigita.cms.contentassets.FileAttachment"},
{"Category", "com.arsdigita.categorization.Category"},
};
{"Category", "com.arsdigita.categorization.Category"},};
/** the separator character to be used in the new OID formatting scheme */
private final static char OID_SEPARATOR_CHAR = '-';
/** A Format used for formatting/parsing OIDs */
private static MessageFormat m_format_old = new MessageFormat("[{0}:{1}]");
private static MessageFormat m_format_new = new MessageFormat("{0}" + OID_SEPARATOR_CHAR + "{1}");
private static MessageFormat m_format_new = new MessageFormat("{0}"
+ OID_SEPARATOR_CHAR
+ "{1}");
/** used to log errors */
private static final Logger m_log = Logger.getLogger(OID.class);
/**
* Creates an OID for the Object type. An example of an object
* type would be "com.arsdigita.kernel.ACSObject." Using this
@ -148,8 +144,7 @@ public class OID {
if (it.hasNext()) {
throw new PersistenceException(
"This object type has a compound key."
);
"This object type has a compound key.");
}
String attr = prop.getName();
@ -172,7 +167,6 @@ public class OID {
return type;
}
/**
* Creates an OID for the named ObjectType. The typename of the
* ObjectType must be defined in the MetadataRoot. An example
@ -197,7 +191,6 @@ public class OID {
this(lookup(typeName));
}
/**
* Creates an OID with a single attribute for the key. To create a
* multi-valued OID, use a single arg OID constructor, and add
@ -229,7 +222,6 @@ public class OID {
this(lookup(typeName), value);
}
/**
* Creates an OID with a single attribute for the key. To create a
* multi-valued OID, use a single arg OID constructor, and add
@ -258,7 +250,6 @@ public class OID {
this(typeName, new BigDecimal(value));
}
/**
* Creates an OID with a single attribute for the key. To create a
* multi-valued OID, use a single arg OID constructor, and add
@ -300,8 +291,7 @@ public class OID {
// We do some type-checking here, to ensure that OIDs are being
// created with legit types of values.
if (prop == null) {
throw new PersistenceException
("no such property: " + propertyName
throw new PersistenceException("no such property: " + propertyName
+ " for type " + m_type.getName());
}
@ -311,11 +301,11 @@ public class OID {
// we can be sure this is a simpletype because
// isAttribute was true.
SimpleType expectedType = (SimpleType) prop.getType();
if (!expectedType.getJavaClass()
.isAssignableFrom(value.getClass())) {
throw new PersistenceException
("expected " + expectedType.getJavaClass()
+ "actual type " + value.getClass());
if (!expectedType.getJavaClass().isAssignableFrom(value.getClass())) {
throw new PersistenceException("expected " + expectedType.
getJavaClass()
+ "actual type "
+ value.getClass());
}
} else if (value != null) {
if (value instanceof DataObject) {
@ -323,15 +313,15 @@ public class OID {
DataObject dobj = (DataObject) value;
ObjectType.verifySubtype(ot, dobj.getObjectType());
} else {
throw new PersistenceException
("expected DataObject for property " + propertyName
throw new PersistenceException("expected DataObject for property "
+ propertyName
+ " but got " + value.getClass());
}
}
if (hasProperty(propertyName)) {
throw new PersistenceException
(propertyName + " is already set to " + get(propertyName));
throw new PersistenceException(propertyName + " is already set to " + get(
propertyName));
}
m_values.put(propertyName, value);
@ -405,7 +395,6 @@ public class OID {
return getObjectType();
}
/**
* @return The ObjectType.
**/
@ -418,7 +407,6 @@ public class OID {
m_type = subtype;
}
/**
* Serializes the OID.
*/
@ -440,8 +428,8 @@ public class OID {
* a NPE in the line below the if.
*/
if (null == value) {
m_log.info(String.format("The value for prop \"%s\" " +
"is null. Ignoring.", key));
m_log.info(String.format("The value for prop \"%s\" "
+ "is null. Ignoring.", key));
continue;
}
/*
@ -462,7 +450,6 @@ public class OID {
return m_format_new.format(args);
}
/** Parse the oid string. If it contains a left-square-bracket,
* use the old parsing scheme. Otherwise, use the new parser.
*/
@ -478,8 +465,9 @@ public class OID {
public static OID valueOfNew(String s) throws IllegalArgumentException {
StringTokenizer st = new StringTokenizer(s, "" + OID_SEPARATOR_CHAR);
if (st.countTokens() < 2) {
throw new IllegalArgumentException
("Invalid OID '" + s + "'. It must have at least the object type and the value");
throw new IllegalArgumentException(
"Invalid OID '" + s
+ "'. It must have at least the object type and the value");
// } else if (st.countTokens() % 2 != 1) {
// throw new IllegalArgumentException
// ("Invalid OID '" + s + "'. It must have type followed by name-value pairs");
@ -515,22 +503,23 @@ public class OID {
}
return oid;
} catch (PersistenceException e) {
throw new IllegalArgumentException
("Invalid OID '" + s + "'. The type specified [" + type +
"] is not defined");
throw new IllegalArgumentException("Invalid OID '" + s
+ "'. The type specified ["
+ type + "] is not defined");
}
}
// Couldn't get MessageFormat to work, so I cheated
public static OID valueOfOld(String s) throws IllegalArgumentException {
m_log.debug(String.format("Trying to parse OID '%s'...", s));
StringTokenizer st = new StringTokenizer(s, "[:{}],");
if (st.countTokens() < 2) {
st = new StringTokenizer(java.net.URLDecoder.decode(s), "[:{}],");
if (st.countTokens() < 2) {
throw new IllegalArgumentException
("Invalid OID '" + s + "'. It must have at least the object " +
"type and the value");
throw new IllegalArgumentException("Invalid OID '" + s
+ "'. It must have at least the object "
+ "type and the value");
}
}
@ -547,6 +536,15 @@ public class OID {
while (st.hasMoreTokens()) {
String nextToken = st.nextToken();
int index = nextToken.indexOf("=");
/**
* jensp 2010-11-03: If next token is an empty string, or there
* no '=', throw an exeception.
*/
if ((nextToken.length() < 1) || (index < 0)) {
throw new IllegalArgumentException("Invalid OID '" + s
+ "'. It must have at least the object "
+ "type and the value");
}
String key = (nextToken.substring(0, index));
String value = nextToken.substring(index + 1);
@ -561,8 +559,7 @@ public class OID {
boolean bigDecimal = true;
for (int i = 0; i < value.length(); i++) {
char c = value.charAt(i);
if (!('0' <= c && c <= '9') &&
!((i == 0) && (c == '-'))) {
if (!('0' <= c && c <= '9') && !((i == 0) && (c == '-'))) {
bigDecimal = false;
break;
}
@ -577,9 +574,9 @@ public class OID {
}
return oid;
} catch (PersistenceException e) {
throw new IllegalArgumentException
("Invalid OID '" + s + "'. The type specified [" + type +
"] is not defined");
throw new IllegalArgumentException("Invalid OID '" + s
+ "'. The type specified ["
+ type + "] is not defined");
}
}
@ -594,8 +591,8 @@ public class OID {
OID oid = (OID) obj;
// we rely on the toString ecause the HashMap.equals does not
// give us what we need
return m_type.getBasetype().equals(oid.m_type.getBasetype()) &&
m_values.equals(oid.m_values);
return m_type.getBasetype().equals(oid.m_type.getBasetype()) && m_values.
equals(oid.m_values);
}
return false;
}

View File

@ -61,3 +61,5 @@ log4j.logger.com.arsdigita.packaging.Loader=INFO
# For debugging all queries run by persistence
#log4j.logger.com.redhat.persistence.engine.rdbms.RDBMSEngine=INFO
log4j.logger.com.arsdigita.cms.search.ContentPageMetadataProvider=DEBUG
log4j.logger.com.arsdigita.london.importer=DEBUG

View File

@ -28,6 +28,7 @@ import org.apache.log4j.Logger;
import com.arsdigita.cms.ContentBundle;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.ContentPage;
import com.arsdigita.cms.ContentSection;
import com.arsdigita.cms.Folder;
import com.arsdigita.domain.DataObjectNotFoundException;
@ -152,6 +153,17 @@ public class ItemImportTool extends Program {
ContentItem item =
(ContentItem) itemParser.getDomainObject();
if (item == null) {
s_log.warn("item is null.Igoring...");
return;
}
s_log.debug(String.format("Got item from ItemParser:"));
s_log.debug(String.format("OID : %s", item.getOID()));
s_log.debug(String.format("Name : %s", item.getName()));
s_log.debug(String.format("Title: %s", item.get("title")));
if (item instanceof ContentPage) {
s_log.debug("Item is a content page...");
}
/*
* Multi lang extension begin
*/
@ -160,8 +172,15 @@ public class ItemImportTool extends Program {
if (itemName.lastIndexOf('-') == -1) {
bundleName = itemName;
} else {
if (itemName.substring((itemName.lastIndexOf('-') + 1)).
equals("de")
|| itemName.substring((itemName.lastIndexOf('-') + 1)).
equals("en")) {
bundleName = itemName.substring(0, itemName.
lastIndexOf('-'));
} else {
bundleName = itemName;
}
}
/*
* Multi lang extension end
@ -177,19 +196,25 @@ public class ItemImportTool extends Program {
* Multi lang extension start
*/
ContentBundle bundle;
s_log.debug(String.format("Bundle name: %s",
bundleName));
if (itemName.lastIndexOf('-') == -1) {
s_log.debug("Item is not localized...");
bundle = new ContentBundle(item);
bundle.setParent(folder);
bundle.setName(bundleName);
bundles.put(bundleName, bundle);
} else {
s_log.debug("Item is localized...");
bundle = bundles.get(bundleName);
if (bundle == null) {
s_log.debug("No content bundle found for item, creating new.");
bundle = new ContentBundle(item);
bundle.setParent(folder);
bundle.setName(bundleName);
bundles.put(bundleName, bundle);
} else {
s_log.debug("Found content bundle for item, adding item as instance.");
bundle.addInstance(item);
}
}

View File

@ -12,8 +12,20 @@
<xrd:associations rule="include">
<xrd:property name="/object/addendum"/>
<xrd:property name="/object/contacts"/>
<xrd:property name="/object/orgaunit_children"/>
<xrd:property name="/object/contacts/person"/>
<xrd:property name="/object/contacts/address"/>
<xrd:property name="/object/contacts/contactentries"/>
<xrd:property name="/object/subDepartments"/>
<xrd:property name="/object/subDepartments/projects"/>
<xrd:property name="/object/subDepartments/contacts"/>
<xrd:property name="/object/subDepartments/contacts/address"/>
<xrd:property name="/object/subDepartments/contacts/contactentries"/>
<xrd:property name="/object/projects"/>
<xrd:property name="/object/projects/persons"/>
<xrd:property name="/object/persons"/>
<xrd:property name="/object/persons/contacts"/>
<xrd:property name="/object/persons/contacts/address"/>
<xrd:property name="/object/persons/contacts/contactentries"/>
</xrd:associations>
</xrd:adapter>
</xrd:context>

View File

@ -16,12 +16,17 @@
<xrd:property name="/object/contacts/person"/>
<xrd:property name="/object/contacts/address"/>
<xrd:property name="/object/contacts/contactentries"/>
<xrd:property name="/object/contacts/person"/>
<xrd:property name="/object/departments"/>
<xrd:property name="/object/departments/persons"/>
<xrd:property name="/object/departments/persons/contacts"/>
<xrd:property name="/object/departments/persons/contacts/address"/>
<xrd:property name="/object/departments/persons/contacts/contactentries"/>
<xrd:property name="/object/projects"/>
<xrd:property name="/object/projects/persons"/>
<xrd:property name="/object/persons"/>
<xrd:property name="/object/persons/contacts"/>
<xrd:property name="/object/persons/contacts/address"/>
<xrd:property name="/object/persons/contacts/contactentries"/>
</xrd:associations>
</xrd:adapter>
</xrd:context>