diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/AbstractContentTypeLoader.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/AbstractContentTypeLoader.java index 567f28d4d..3ce764b51 100755 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/AbstractContentTypeLoader.java +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/AbstractContentTypeLoader.java @@ -20,7 +20,6 @@ package com.arsdigita.cms.contenttypes; import com.arsdigita.cms.ContentSection; import com.arsdigita.cms.ContentType; -import com.arsdigita.cms.ContentTypeCollection; import com.arsdigita.cms.ContentTypeLifecycleDefinition; import com.arsdigita.cms.ContentTypeWorkflowTemplate; import com.arsdigita.cms.Template; @@ -45,12 +44,10 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.math.BigDecimal; import java.util.Date; import java.util.Iterator; import java.util.List; -import java.util.StringTokenizer; import org.apache.log4j.Logger; /** @@ -113,9 +110,6 @@ public abstract class AbstractContentTypeLoader extends PackageLoader { for (Iterator it = types.iterator(); it.hasNext();) { final ContentType type = (ContentType) it.next(); - // Save the ancestors for this content type - createPedigree(type); - section.addContentType(type); prepareSection(section, type, ld, wf); @@ -208,83 +202,4 @@ public abstract class AbstractContentTypeLoader extends PackageLoader { template.publish(ld, new Date()); return template; } - - /** - * Generates the pedigree for this content type - * @param type The new content type - */ - private void createPedigree(ContentType type) { - - // The parent content type - ContentType parent = null; - - // Get all content types - ContentTypeCollection cts = ContentType.getAllContentTypes(); - - // This is a brute force method, but I can't come up with something - // better atm without changing either all Loader or the xml-files. - while (cts.next()) { - ContentType ct = cts.getContentType(); - - try { - Class.forName(type.getClassName()).asSubclass(Class.forName(ct. - getClassName())); - } catch (Exception ex) { - // This cast is not valid so type is not a sublacss of ct - continue; - } - - // Save the current ct as possible parent if we haven't found any parent yet - // or if the current ancestor list is longer than that one from the possible - // parent earlier found - if (!type.getClassName().equals(ct.getClassName()) - && (parent == null - || (parent.getAncestors() != null - && ct.getAncestors() != null - && parent.getAncestors().length() < ct.getAncestors(). - length()))) { - parent = ct; - } - } - - // If there is a valid parent content type create the pedigree - if (parent != null && !parent.getClassName().equals(type.getClassName())) { - if (parent.getAncestors() != null) { - String parentAncestors = parent.getAncestors(); - - StringTokenizer strTok = new StringTokenizer(parentAncestors, - "/"); - - // Add parent ancestors to this content types ancestor list - // Also while we iterate through the list, we also need to add - // this content type as sibling to all entries in the ancestor list - while (strTok.hasMoreElements()) { - - Object token; - token = strTok.nextElement(); - s_log.error(String.format( - "Trying to convert '%s' to BigDecimal...", token)); - //BigDecimal ctID = (BigDecimal) strTok.nextElement(); - BigDecimal ctID = (BigDecimal) strTok.nextElement(); - - // Get the current content type - try { - ContentType ct = new ContentType(ctID); - ct.addSiblings(ctID); - } catch (Exception ex) { - // The db is broken. There is no content type for this ID - } - - // Add parent ancestor - type.addAncestor(ctID); - } - } - - // Add parent to ancestor list - type.addAncestor(parent.getID()); - - // Add this to parent siblings - parent.addSiblings(type.getID()); - } - } } diff --git a/ccm-cms/src/com/arsdigita/cms/installer/xml/ContentTypeHelperImpl.java b/ccm-cms/src/com/arsdigita/cms/installer/xml/ContentTypeHelperImpl.java index 766ed2200..52b322fa4 100755 --- a/ccm-cms/src/com/arsdigita/cms/installer/xml/ContentTypeHelperImpl.java +++ b/ccm-cms/src/com/arsdigita/cms/installer/xml/ContentTypeHelperImpl.java @@ -23,6 +23,7 @@ import com.arsdigita.cms.AuthoringStep; import com.arsdigita.cms.AuthoringStepCollection; import com.arsdigita.cms.ContentPage; import com.arsdigita.cms.ContentType; +import com.arsdigita.cms.ContentTypeCollection; import com.arsdigita.cms.search.ContentPageMetadataProvider; import com.arsdigita.domain.DataObjectNotFoundException; import com.arsdigita.persistence.SessionManager; @@ -30,15 +31,14 @@ import com.arsdigita.persistence.metadata.ObjectType; import com.arsdigita.search.MetadataProviderRegistry; import com.arsdigita.util.Assert; import java.math.BigDecimal; +import java.util.StringTokenizer; import org.apache.log4j.Logger; public class ContentTypeHelperImpl implements ContentTypeHelper { - private static final Logger s_log - = Logger.getLogger(ContentTypeHelperImpl.class); - + + private static final Logger s_log = Logger.getLogger(ContentTypeHelperImpl.class); private ContentType m_type; private ContentType m_parent; - // Basic Content type properties private String m_label; private String m_labelKey; @@ -50,10 +50,10 @@ public class ContentTypeHelperImpl implements ContentTypeHelper { private String m_className; private String m_createComponent; private AuthoringKit m_kit; - private boolean m_internal; - public ContentTypeHelperImpl() {} + public ContentTypeHelperImpl() { + } /** * @deprecated use setLabelBundle and setLabelKey @@ -61,7 +61,7 @@ public class ContentTypeHelperImpl implements ContentTypeHelper { public void setLabel(String label) { m_label = label; } - + /** * @deprecated use getLabelBundle and getLabelKey */ @@ -77,7 +77,7 @@ public class ContentTypeHelperImpl implements ContentTypeHelper { public void setLabelBundle(String labelBundle) { m_labelBundle = labelBundle; } - + public String getLabelBundle() { return m_labelBundle; } @@ -90,7 +90,7 @@ public class ContentTypeHelperImpl implements ContentTypeHelper { public void setLabelKey(String labelKey) { m_labelKey = labelKey; } - + public String getLabelKey() { return m_labelKey; } @@ -125,7 +125,7 @@ public class ContentTypeHelperImpl implements ContentTypeHelper { public void setDescriptionBundle(String descriptionBundle) { m_descriptionBundle = descriptionBundle; } - + public String getDescriptionBundle() { return m_descriptionBundle; } @@ -138,7 +138,7 @@ public class ContentTypeHelperImpl implements ContentTypeHelper { public void setDescriptionKey(String descriptionKey) { m_descriptionKey = descriptionKey; } - + public String getDescriptionKey() { return m_descriptionKey; } @@ -150,7 +150,7 @@ public class ContentTypeHelperImpl implements ContentTypeHelper { public String getObjectType() { return m_objectType; } - + public void setClassName(String classname) { m_className = classname; } @@ -172,13 +172,14 @@ public class ContentTypeHelperImpl implements ContentTypeHelper { Assert.exists(m_type); return m_type; } - /** Doesn't do anything */ - public void setName(String name) {} - /** Doesn't do anything */ - public void setParentType(String parentType) {} + public void setName(String name) { + } + /** Doesn't do anything */ + public void setParentType(String parentType) { + } public ContentType createType() { Assert.exists(m_label); @@ -186,20 +187,20 @@ public class ContentTypeHelperImpl implements ContentTypeHelper { Assert.exists(m_objectType); Assert.exists(m_className); - try { + try { s_log.debug("making new content type"); m_type = - ContentType.findByAssociatedObjectType(m_objectType); + ContentType.findByAssociatedObjectType(m_objectType); m_type.setLabel(m_label); m_type.setDescription(m_description); m_type.save(); } catch (DataObjectNotFoundException e) { s_log.debug("Looking for content type"); - s_log.debug("Creating ContentType Label: " + m_label - + " Description: " + m_description - + " className: " + m_className - + " AssociatedObjectType: " + m_objectType); - + s_log.debug("Creating ContentType Label: " + m_label + + " Description: " + m_description + + " className: " + m_className + + " AssociatedObjectType: " + m_objectType); + // this is what would need to be changed to make the // label and description multi-lingual. To do that, // you need to use labelKey, labelBundle, descriptionKey @@ -210,21 +211,24 @@ public class ContentTypeHelperImpl implements ContentTypeHelper { m_type.setClassName(m_className); m_type.setAssociatedObjectType(m_objectType); m_type.setInternal(m_internal); + + // create pedigree for this content type + createPedigree(m_type); + m_type.save(); - } + } // Turn on search indexing for this type - ObjectType type = SessionManager.getMetadataRoot() - .getObjectType(m_objectType); - if (type.isSubtypeOf(ContentPage.BASE_DATA_OBJECT_TYPE) && - !m_internal) { - s_log.debug("Registering search adapter for " + - m_objectType); + ObjectType type = SessionManager.getMetadataRoot().getObjectType(m_objectType); + if (type.isSubtypeOf(ContentPage.BASE_DATA_OBJECT_TYPE) + && !m_internal) { + s_log.debug("Registering search adapter for " + + m_objectType); MetadataProviderRegistry.registerAdapter( - m_objectType, - new ContentPageMetadataProvider()); + m_objectType, + new ContentPageMetadataProvider()); } - + Assert.exists(m_type); return m_type; } @@ -244,8 +248,8 @@ public class ContentTypeHelperImpl implements ContentTypeHelper { AuthoringStepCollection ac = m_kit.getSteps(); while (ac.next()) { AuthoringStep step = ac.getAuthoringStep(); - s_log.debug("Deleting authoringStep " - + step.getLabel()); + s_log.debug("Deleting authoringStep " + + step.getLabel()); m_kit.removeStep(step); step.delete(); } @@ -265,27 +269,27 @@ public class ContentTypeHelperImpl implements ContentTypeHelper { /** * @deprecated */ - public void addAuthoringStep(String label, - String description, - String component, - BigDecimal ordering) { + public void addAuthoringStep(String label, + String description, + String component, + BigDecimal ordering) { addAuthoringStep(label, null, description, null, component, ordering); } - public void addAuthoringStep(String labelKey, - String labelBundle, - String descriptionKey, - String descriptionBundle, - String component, - BigDecimal ordering) { - s_log.debug("Creating AuthoringStep " - + " LabelKey: " + labelKey - + " LabelBundle: " + labelBundle - + " DescriptionKey: " + descriptionKey - + " DescriptionBundle: " + descriptionBundle - + " Component " + component - + " Ordering: " + ordering); - + public void addAuthoringStep(String labelKey, + String labelBundle, + String descriptionKey, + String descriptionBundle, + String component, + BigDecimal ordering) { + s_log.debug("Creating AuthoringStep " + + " LabelKey: " + labelKey + + " LabelBundle: " + labelBundle + + " DescriptionKey: " + descriptionKey + + " DescriptionBundle: " + descriptionBundle + + " Component " + component + + " Ordering: " + ordering); + Assert.exists(m_kit); Assert.exists(labelKey); Assert.exists(descriptionKey); @@ -293,8 +297,8 @@ public class ContentTypeHelperImpl implements ContentTypeHelper { Assert.exists(ordering); m_kit.createStep(labelKey, labelBundle, - descriptionKey, descriptionBundle, - component, ordering); + descriptionKey, descriptionBundle, + component, ordering); m_kit.save(); m_type.save(); } @@ -304,4 +308,74 @@ public class ContentTypeHelperImpl implements ContentTypeHelper { m_type.save(); } + /** + * Generates the pedigree for this content type + * @param type The new content type + */ + private void createPedigree(ContentType type) { + + // The parent content type + ContentType parent = null; + + // Get all content types + ContentTypeCollection cts = ContentType.getAllContentTypes(); + + // This is a brute force method, but I can't come up with something + // better atm without changing either all Loader or the xml-files. + while (cts.next()) { + ContentType ct = cts.getContentType(); + + try { + Class.forName(type.getClassName()).asSubclass(Class.forName(ct.getClassName())); + } catch (Exception ex) { + // This cast is not valid so type is not a sublacss of ct + continue; + } + + // Save the current ct as possible parent if we haven't found any parent yet + // or if the current ancestor list is longer than that one from the possible + // parent earlier found + if (!type.getClassName().equals(ct.getClassName()) + && (parent == null + || (parent.getAncestors() != null + && ct.getAncestors() != null + && parent.getAncestors().length() < ct.getAncestors().length()))) { + parent = ct; + } + } + + // If there is a valid parent content type create the pedigree + if (parent != null && !parent.getClassName().equals(type.getClassName())) { + if (parent.getAncestors() != null) { + String parentAncestors = parent.getAncestors(); + + StringTokenizer strTok = new StringTokenizer(parentAncestors, "/"); + + // Add parent ancestors to this content types ancestor list + // Also while we iterate through the list, we also need to add + // this content type as sibling to all entries in the ancestor list + while (strTok.hasMoreElements()) { + + BigDecimal ctID = (BigDecimal) strTok.nextElement(); + + // Get the current content type + try { + ContentType ct = new ContentType(ctID); + ct.addSiblings(ctID); + } catch (Exception ex) { + // The db is broken. There is no content type for this ID + } + + // Add parent ancestor + type.addAncestor(ctID); + } + } + + // Add parent to ancestor list + type.addAncestor(parent.getID()); + + // Add this to parent siblings + parent.addSiblings(type.getID()); + } + } }