From 1a574abe703ed4428f04e27d8f90a55137d8cd9f Mon Sep 17 00:00:00 2001 From: jensp Date: Thu, 25 Nov 2010 08:00:27 +0000 Subject: [PATCH] =?UTF-8?q?Bei=20Publizieren=20eines=20Items=20mit=20einem?= =?UTF-8?q?=20RelatatedLink=20kam=20es=20zu=20einer=20ClassCastException,?= =?UTF-8?q?=20da=20RelatedLink=20Objekte=20sich=20nicht=20zu=20ContentItem?= =?UTF-8?q?=20casten=20lassen=20(letzter=20Parameter=20von=20PublishedLink?= =?UTF-8?q?#create()).=20Korrigiert,=20indem=20in=20VersionCopier=20f?= =?UTF-8?q?=C3=BCr=20Objekte,=20die=20nicht=20von=20ContentItem=20abgeleit?= =?UTF-8?q?et=20sind=20'null'=20im=20Parameter=20sourceObject=20=C3=BCberg?= =?UTF-8?q?eben=20wird.=20In=20PublishedLink#create()=20wird=20nun=20gepr?= =?UTF-8?q?=C3=BCft,=20ob=20sourceObject=20'null'=20ist.=20Wenn=20der=20Pa?= =?UTF-8?q?rameter=20nicht=20'null'=20ist,=20werden=20LinkAttribute=20(daf?= =?UTF-8?q?=C3=BCr=20ist=20dieser=20Parameter=20erforderlich)=20kopiert.?= =?UTF-8?q?=20Falls=20der=20Parameter=20'null'=20ist,=20wird=20dieser=20Me?= =?UTF-8?q?thodenaufruf=20=C3=BCbersprungen=20(in=20diesem=20Fall=20w?= =?UTF-8?q?=C3=A4re=20er=20auch=20sinnlos).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://svn.libreccm.org/ccm/trunk@634 8810af33-2d31-482b-a856-94f89814c4df --- .../src/com/arsdigita/cms/PublishedLink.java | 2 +- .../src/com/arsdigita/cms/VersionCopier.java | 80 +++++++++++-------- 2 files changed, 46 insertions(+), 36 deletions(-) diff --git a/ccm-cms/src/com/arsdigita/cms/PublishedLink.java b/ccm-cms/src/com/arsdigita/cms/PublishedLink.java index 62b177ee9..f3023150f 100755 --- a/ccm-cms/src/com/arsdigita/cms/PublishedLink.java +++ b/ccm-cms/src/com/arsdigita/cms/PublishedLink.java @@ -150,7 +150,7 @@ class PublishedLink extends DomainObject { link = new PublishedLink(SessionManager.getSession().create(oid)); } - if (sourceObject.getObjectType().getProperty(propertyName).isCollection()) { + if ((sourceObject != null) && sourceObject.getObjectType().getProperty(propertyName).isCollection()) { link.saveLinkAttributes((DataCollection) sourceObject.get(propertyName + "@link")); } diff --git a/ccm-cms/src/com/arsdigita/cms/VersionCopier.java b/ccm-cms/src/com/arsdigita/cms/VersionCopier.java index fdb99b080..c4971d16a 100755 --- a/ccm-cms/src/com/arsdigita/cms/VersionCopier.java +++ b/ccm-cms/src/com/arsdigita/cms/VersionCopier.java @@ -21,6 +21,7 @@ package com.arsdigita.cms; import com.arsdigita.cms.lifecycle.Lifecycle; import com.arsdigita.cms.lifecycle.LifecycleService; import com.arsdigita.domain.DomainObject; +import com.arsdigita.kernel.ACSObject; import com.arsdigita.persistence.metadata.Property; import com.arsdigita.persistence.OID; import com.arsdigita.util.Assert; @@ -39,7 +40,6 @@ import java.util.HashSet; class VersionCopier extends ObjectCopier { private static Logger s_log = Logger.getLogger(VersionCopier.class); - private final Lifecycle m_lifecycle; private boolean m_once = false; private long m_start = 0; @@ -91,10 +91,10 @@ class VersionCopier extends ObjectCopier { m_once = true; } - m_topLevelSourceOID = item.getOID(); + m_topLevelSourceOID = item.getOID(); final ContentItem version = createVersion(item); - //Assert.isTrue(m_topLevelSourceOID == null, - // "CopyItem should be called only once for a given copier instance"); + //Assert.isTrue(m_topLevelSourceOID == null, + // "CopyItem should be called only once for a given copier instance"); if (m_lifecycle != null) { LifecycleService.setLifecycle(version, m_lifecycle); @@ -108,9 +108,10 @@ class VersionCopier extends ObjectCopier { } if (s_log.isInfoEnabled()) { - s_log.info("Done publishing " + item + " (" + - (System.currentTimeMillis() - m_start) + - " millis)"); + s_log.info("Done publishing " + item + " (" + (System. + currentTimeMillis() + - m_start) + + " millis)"); } return version; @@ -133,10 +134,10 @@ class VersionCopier extends ObjectCopier { */ @Override public DomainObject copy(final DomainObject object) { - if (object != null) { - m_traversedComponents.add(object); - } - return super.copy(object); + if (object != null) { + m_traversedComponents.add(object); + } + return super.copy(object); } /** @@ -173,9 +174,9 @@ class VersionCopier extends ObjectCopier { */ @Override protected DomainObject copy(final DomainObject source, - final DomainObject target, - final DomainObject object, - final Property prop) { + final DomainObject target, + final DomainObject object, + final Property prop) { m_trace.enter("copy", object, prop); if (s_log.isDebugEnabled()) { @@ -197,8 +198,8 @@ class VersionCopier extends ObjectCopier { } if (prop.isComponent()) { - s_log.debug("The property is a component; creating a " + - "live or pending version"); + s_log.debug("The property is a component; creating a " + + "live or pending version"); final ContentItem copy = createVersion(item); @@ -206,26 +207,35 @@ class VersionCopier extends ObjectCopier { return copy; } else if (m_traversedComponents.contains(object)) { - final DomainObject copy = copy(object); - - m_trace.exit("copy", copy); - - return copy; - } else if (prop.isRequired()) { - Assert.fail("1..1 associations to non-component top-level ContentItems are not allowed"); - return null; - } else { - s_log.debug("The property is not a component; creating " + - "PublishedLink for the item"); + final DomainObject copy = copy(object); - PublishedLink.create((ContentItem) getCopy(m_topLevelSourceOID), target, prop.getName(), item, (ContentItem) source); + m_trace.exit("copy", copy); + + return copy; + } else if (prop.isRequired()) { + Assert.fail( + "1..1 associations to non-component top-level ContentItems are not allowed"); + return null; + } else { + s_log.debug("The property is not a component; creating " + + "PublishedLink for the item"); + + if (source instanceof ContentItem) { + PublishedLink.create((ContentItem) getCopy( + m_topLevelSourceOID), target, prop.getName(), item, + (ContentItem) source); + } else { + PublishedLink.create((ContentItem) getCopy( + m_topLevelSourceOID), target, prop.getName(), item, + null); + } m_trace.exit("copy", null); return null; } } else { - s_log.debug("The property is not a content item; using " + - "domain object copier"); + s_log.debug("The property is not a content item; using " + + "domain object copier"); final DomainObject copy = super.copy(source, target, object, prop); @@ -244,11 +254,11 @@ class VersionCopier extends ObjectCopier { final ContentItem version = (ContentItem) copy(item); - s_log.debug("The copy is pending; associating it with " + - "the draft item"); - - version.setVersion(ContentItem.PENDING); - item.addPendingVersion(version); + s_log.debug("The copy is pending; associating it with " + + "the draft item"); + + version.setVersion(ContentItem.PENDING); + item.addPendingVersion(version); version.copyServicesFrom(item);