diff --git a/ccm-cms/src/com/arsdigita/cms/PublishedLink.java b/ccm-cms/src/com/arsdigita/cms/PublishedLink.java index 04e9bc5e1..d8ea78b98 100755 --- a/ccm-cms/src/com/arsdigita/cms/PublishedLink.java +++ b/ccm-cms/src/com/arsdigita/cms/PublishedLink.java @@ -48,9 +48,8 @@ import java.util.Iterator; import java.util.Set; /** - * This class represents an association between a pending or live - * ContentItem (or one of its components) and a separate top-level - * Contenttem. + * This class represents an association between a pending or live ContentItem + * (or one of its components) and a separate top-level Contenttem. * */ class PublishedLink extends DomainObject { @@ -64,7 +63,7 @@ class PublishedLink extends DomainObject { static final String DRAFT_TARGET = "draftTarget"; static final String LINK_ATTRIBUTES = "linkAttributes"; static final String BASE_DATA_OBJECT_TYPE = - "com.arsdigita.cms.PublishedLink"; + "com.arsdigita.cms.PublishedLink"; @Override protected String getBaseDataObjectType() { @@ -72,8 +71,9 @@ class PublishedLink extends DomainObject { } /** - * Default constructor. The contained DataObject is - * initialized with a new DataObject with an + * Default constructor. The contained + * DataObject is initialized with a new + * DataObject with an * ObjectType of "PublishedLink". * * @see com.arsdigita.domain.DomainObject#DomainObject(String) @@ -94,11 +94,13 @@ class PublishedLink extends DomainObject { } /** - * Constructor. The contained DataObject is retrieved - * from the persistent storage mechanism with an OID - * specified by oid. + * Constructor. The contained + * DataObject is retrieved from the persistent storage + * mechanism with an + * OID specified by oid. * - * @param oid The OID for the retrieved + * @param oid The + * OID for the retrieved * DataObject. * * @see com.arsdigita.domain.DomainObject#DomainObject(OID) @@ -110,37 +112,44 @@ class PublishedLink extends DomainObject { } /** - * Creates new PublishedLink unless one already exists for the - * specified source, target, and property + * Creates new PublishedLink unless one already exists for the specified + * source, target, and property * - * @param sourceMasterItem the top-level pending or live ContentItem which - * this PublishedLink is a component of. + * @param sourceMasterItem the top-level pending or live + * ContentItem which this + * PublishedLink is a component of. * @param linkSource the immediate source of this - * PublishedLink, a component of the sourceMasterItem - * (or the item itself) - * @param propertyName the Property name for this PublishedLink - * @param linkTarget the top-level draft ContentItem which - * is the target of this PublishedLink . + * PublishedLink, a component of the sourceMasterItem (or the + * item itself) + * @param propertyName the Property name for this + * PublishedLink + * @param linkTarget the top-level draft + * ContentItem which is the target of this + * PublishedLink . * - * @return the newly-created PublishedLink, or the existing one if - * one already exists for these items. + * @return the newly-created PublishedLink, or the existing one if one + * already exists for these items. */ static PublishedLink create(ContentItem sourceMasterItem, - DomainObject linkSource, - String propertyName, - ContentItem linkTarget, - ContentItem sourceObject) { + DomainObject linkSource, + String propertyName, + ContentItem linkTarget, + ContentItem sourceObject) { OID oid = new OID(BASE_DATA_OBJECT_TYPE); - oid.set(SOURCE_MASTER_ITEM, DomainServiceInterfaceExposer.getDataObject(sourceMasterItem)); + oid.set(SOURCE_MASTER_ITEM, DomainServiceInterfaceExposer.getDataObject( + sourceMasterItem)); oid.set(PROPERTY_NAME, propertyName); - oid.set(DRAFT_TARGET, DomainServiceInterfaceExposer.getDataObject(linkTarget)); + oid.set(DRAFT_TARGET, DomainServiceInterfaceExposer.getDataObject( + linkTarget)); // this will need to be refactored if we switch to OID link sourcess if (linkSource instanceof ACSObject) { - oid.set(PENDING_SOURCE, DomainServiceInterfaceExposer.getDataObject(linkSource)); + oid.set(PENDING_SOURCE, DomainServiceInterfaceExposer.getDataObject( + linkSource)); } else { - Assert.fail("Cannot set PublishedLink source " + linkSource + "; it is not an " - + "ACSObject"); + Assert.fail("Cannot set PublishedLink source " + linkSource + + "; it is not an " + + "ACSObject"); } PublishedLink link = null; @@ -150,14 +159,17 @@ class PublishedLink extends DomainObject { link = new PublishedLink(SessionManager.getSession().create(oid)); } - if ((sourceObject != null) && sourceObject.getObjectType().getProperty(propertyName).isCollection()) { + if ((sourceObject != null) && sourceObject.getObjectType().getProperty( + propertyName).isCollection()) { - DataCollection coll = (DataCollection) sourceObject.get(propertyName + "@link"); + DataCollection coll = (DataCollection) sourceObject.get(propertyName + + "@link"); while (coll.next()) { DataObject linkObj = coll.getDataObject(); - if (linkTarget.getOID().equals(((DataObject) linkObj.getOID().get(propertyName)).getOID())) { + if (linkTarget.getOID().equals(((DataObject) linkObj.getOID(). + get(propertyName)).getOID())) { link.saveLinkAttributes(linkObj); coll.close(); } @@ -168,24 +180,28 @@ class PublishedLink extends DomainObject { } /** - * Returns the top-level pending or live ContentItem which - * this PublishedLink is a component of. + * Returns the top-level pending or live + * ContentItem which this + * PublishedLink is a component of. * - * @return the top-level pending or live ContentItem which - * this PublishedLink is a component of. + * @return the top-level pending or live + * ContentItem which this + * PublishedLink is a component of. * */ ContentItem getSourceMasterItem() { final DataObject item = (DataObject) get(SOURCE_MASTER_ITEM); return item == null ? null - : (ContentItem) DomainObjectFactory.newInstance((DataObject) item); + : (ContentItem) DomainObjectFactory.newInstance((DataObject) item); } /** - * Returns the immediate source of this PublishedLink + * Returns the immediate source of this + * PublishedLink * - * @return the immediate source of this PublishedLink + * @return the immediate source of this + * PublishedLink * */ DomainObject getLinkSource() { @@ -193,13 +209,15 @@ class PublishedLink extends DomainObject { final DataObject item = (DataObject) get(PENDING_SOURCE); return item == null ? null - : DomainObjectFactory.newInstance((DataObject) item); + : DomainObjectFactory.newInstance((DataObject) item); } /** - * Returns the Property name for this PublishedLink + * Returns the Property name for this + * PublishedLink * - * @return the Property name for this PublishedLink + * @return the Property name for this + * PublishedLink * */ String getPropertyName() { @@ -207,27 +225,29 @@ class PublishedLink extends DomainObject { } /** - * Returns the top-level draft ContentItem which - * is the target of this PublishedLink . + * Returns the top-level draft + * ContentItem which is the target of this + * PublishedLink . * - * @return the top-level draft ContentItem which - * is the target of this PublishedLink . + * @return the top-level draft + * ContentItem which is the target of this + * PublishedLink . * */ ContentItem getLinkTarget() { final DataObject item = (DataObject) get(DRAFT_TARGET); return item == null ? null - : (ContentItem) DomainObjectFactory.newInstance((DataObject) item); + : (ContentItem) DomainObjectFactory.newInstance((DataObject) item); } /** - * Updates live associations based on PublishedLinks which either - * point from or to the given - * ContentItem. If both ends of the link are now - * live, the live-live association will be updated. In addition, - * for links to this new live item, the source of the - * link is refreshed via QueueManager.queueRepublish. + * Updates live associations based on PublishedLinks which either point + * from or to the given + * ContentItem. If both ends of the link are now live, the + * live-live association will be updated. In addition, for links to + * this new live item, the source of the link is refreshed via + * QueueManager.queueRepublish. * * @param item The item which was just published */ @@ -238,7 +258,8 @@ class PublishedLink extends DomainObject { ContentItem draftItem = item.getDraftVersion(); DataCollection linksToItem = session.retrieve(BASE_DATA_OBJECT_TYPE); linksToItem.addEqualsFilter(DRAFT_TARGET + ".id", draftItem.getID()); - linksToItem.addEqualsFilter(SOURCE_MASTER_ITEM + "." + ContentItem.VERSION, ContentItem.LIVE); + linksToItem.addEqualsFilter(SOURCE_MASTER_ITEM + "." + + ContentItem.VERSION, ContentItem.LIVE); updateLiveLinksFromCollection(linksToItem, itemsToRefresh); linksToItem.close(); @@ -250,14 +271,16 @@ class PublishedLink extends DomainObject { Iterator refreshIterator = itemsToRefresh.iterator(); while (refreshIterator.hasNext()) { OID oid = (OID) refreshIterator.next(); - ContentItem refreshItem = (ContentItem) DomainObjectFactory.newInstance(oid); + ContentItem refreshItem = (ContentItem) DomainObjectFactory. + newInstance(oid); if (refreshItem.canPublishToFS()) { QueueManager.queueRepublish(refreshItem); } } } - private static void updateLiveLinksFromCollection(DataCollection coll, Set itemsToRefresh) { + private static void updateLiveLinksFromCollection(DataCollection coll, + Set itemsToRefresh) { while (coll.next()) { // will change w/ OID references DataObject master = (DataObject) coll.get(SOURCE_MASTER_ITEM); @@ -272,7 +295,8 @@ class PublishedLink extends DomainObject { DataObject target = null; DataObject draftTarget = (DataObject) coll.get(DRAFT_TARGET); DataAssociationCursor targetVersions = - ((DataAssociation) draftTarget.get(ContentItem.VERSIONS)).cursor(); + ((DataAssociation) draftTarget.get( + ContentItem.VERSIONS)).cursor(); targetVersions.addEqualsFilter(ContentItem.VERSION, ContentItem.LIVE); if (targetVersions.next()) { target = targetVersions.getDataObject(); @@ -281,7 +305,8 @@ class PublishedLink extends DomainObject { if (target != null) { ObjectType ot = src.getObjectType(); Property prop = ot.getProperty(propertyName); - Assert.exists(prop, propertyName + " for type " + ot.getQualifiedName() + ", ID: " + src.get("id")); + Assert.exists(prop, propertyName + " for type " + ot. + getQualifiedName() + ", ID: " + src.get("id")); if (prop.isCollection()) { DataAssociation da = (DataAssociation) src.get(propertyName); setLinkAttributesForLiveLink(da.add(target), linkAttributes); @@ -297,8 +322,8 @@ class PublishedLink extends DomainObject { } /** - * At unpublish time, for links to this unpublished item, - * the source of the link is refreshed via + * At unpublish time, for links to this unpublished item, the + * source of the link is refreshed via * QueueManager.queueRepublish. * * @param item The item which was just published @@ -309,7 +334,8 @@ class PublishedLink extends DomainObject { DataCollection linksToItem = session.retrieve(BASE_DATA_OBJECT_TYPE); linksToItem.addEqualsFilter(DRAFT_TARGET + ".id", item.getID()); - linksToItem.addEqualsFilter(SOURCE_MASTER_ITEM + "." + ContentItem.VERSION, ContentItem.LIVE); + linksToItem.addEqualsFilter(SOURCE_MASTER_ITEM + "." + + ContentItem.VERSION, ContentItem.LIVE); while (linksToItem.next()) { // will change w/ OID references DataObject master = (DataObject) linksToItem.get(SOURCE_MASTER_ITEM); @@ -320,7 +346,8 @@ class PublishedLink extends DomainObject { Iterator refreshIterator = itemsToRefresh.iterator(); while (refreshIterator.hasNext()) { OID oid = (OID) refreshIterator.next(); - ContentItem refreshItem = (ContentItem) DomainObjectFactory.newInstance(oid); + ContentItem refreshItem = (ContentItem) DomainObjectFactory. + newInstance(oid); if (refreshItem.canPublishToFS()) { QueueManager.queueRepublish(refreshItem); } @@ -357,7 +384,8 @@ class PublishedLink extends DomainObject { } } - private static void setLinkAttributesForLiveLink(DataObject link, byte[] linkAttributes) { + private static void setLinkAttributesForLiveLink(DataObject link, + byte[] linkAttributes) { if (linkAttributes != null) { ByteArrayInputStream data = null; @@ -386,7 +414,8 @@ class PublishedLink extends DomainObject { String propertyName = (String) keys.next(); Object value = (Object) attributes.get(propertyName); - if (link.getObjectType().hasDeclaredProperty(propertyName) && link.getSession() != null) { + if (link.getObjectType().hasDeclaredProperty(propertyName) + && link.getSession() != null) { link.set(propertyName, value); } } diff --git a/ccm-cms/src/com/arsdigita/cms/VersionCopier.java b/ccm-cms/src/com/arsdigita/cms/VersionCopier.java index 38e6e037b..322f75f15 100755 --- a/ccm-cms/src/com/arsdigita/cms/VersionCopier.java +++ b/ccm-cms/src/com/arsdigita/cms/VersionCopier.java @@ -30,9 +30,10 @@ import org.apache.log4j.Logger; import java.util.HashSet; /** - * Extends ObjectCopier to create a live version for an - * item. Clones the item, making sure that live versions of all subitems - * point only to other live versions. + * Extends + * ObjectCopier to create a live version for an item. Clones the + * item, making sure that live versions of all subitems point only to other live + * versions. * * @author Stanislav Freidin * @version $Id: VersionCopier.java 2140 2011-01-16 12:04:20Z pboy $ @@ -47,7 +48,8 @@ class VersionCopier extends ObjectCopier { private OID m_topLevelSourceOID = null; /** - * Creates a new VersionCopier with a given Lifecycle + * Creates a new + * VersionCopier with a given Lifecycle * * @param lifecycle The Lifecycle */ @@ -57,7 +59,8 @@ class VersionCopier extends ObjectCopier { } /** - * Creates a new VersionCopier with no Lifecycle + * Creates a new + * VersionCopier with no Lifecycle */ VersionCopier() { m_traversedComponents = new HashSet(); @@ -65,12 +68,10 @@ class VersionCopier extends ObjectCopier { } /** - * Copy a {@link ContentItem}, along with all of its component - * sub-objects, and return the copy. Note that the categories to - * which the source item belongs are not automatically transferred - * to the copy; the user must call {@link #copyServices(ContentItem, - * ContentItem)} in order to transfer the categories and other - * services. + * Copy a {@link ContentItem}, along with all of its component sub-objects, + * and return the copy. Note that the categories to which the source item + * belongs are not automatically transferred to the copy; the user must call {@link #copyServices(ContentItem, + * ContentItem)} in order to transfer the categories and other services. * * @param item the item to be copied * @return a copy of the item @@ -126,11 +127,12 @@ class VersionCopier extends ObjectCopier { } /** - * Kicks off the copying process. Creates a copy by value of - * source and then traverses its associations and - * repeats the process. + * Kicks off the copying process. Creates a copy by value of + * source and then traverses its associations and repeats the + * process. * - * @param source the DomainObject from which to copy + * @param source the + * DomainObject from which to copy */ @Override public DomainObject copy(final DomainObject object) { @@ -141,36 +143,33 @@ class VersionCopier extends ObjectCopier { } /** - * Copies properties. This method is called from {@link - * #copy(DomainObject)} for each property of the object being - * copied. + * Copies properties. This method is called from {@link + * #copy(DomainObject)} for each property of the object being copied. * - * Copying behavior depends on the following: - *
- *
object instanceof ContentItem && prop.isComponent()
- *
Copy ContentItem recursively, setting the version attribute, etc.
- *
object instanceof ContentItem && + * Copying behavior depends on the following:
+ * object instanceof ContentItem && prop.isComponent()
+ *
Copy ContentItem recursively, setting the version attribute, + * etc.
+ * object instanceof ContentItem && * !prop.isComponent() (and target is an already-traversed - * component of the top-level item )
- *
Return reference to already-created copy of this item
- *
object instanceof ContentItem && + * component of the top-level item )
Return reference to + * already-created copy of this item
+ * object instanceof ContentItem && * !prop.isComponent() && prop.isRequired (and target is not an already-traversed - * component of the top-level item )
- *
Assert failure: required top-level item associations are - * not allowed here.
- *
object instanceof ContentItem && + * component of the top-level item )
Assert failure: + * required top-level item associations are not allowed here.
+ * object instanceof ContentItem && * !prop.isComponent() && !prop.isRequired (and target is not an already-traversed - * component of the top-level item )
- *
Create PublishedLink for association; return null
- *
!object instanceof ContentItem
- *
object is not a ContentItem, rely on default DomainCopier - * behavior
- *
+ * component of the top-level item )
Create PublishedLink + * for association; return null
+ * !object instanceof ContentItem
object is not a + * ContentItem, rely on default DomainCopier behavior
* - * @param source the DomainObject being copied + * @param source the + * DomainObject being copied * @param target the new copy - * @param prop the Property currently under - * consideration + * @param prop the + * Property currently under consideration */ @Override protected DomainObject copy(final DomainObject source, @@ -221,13 +220,19 @@ class VersionCopier extends ObjectCopier { + "PublishedLink for the item"); if (source instanceof ContentItem) { - PublishedLink.create((ContentItem) getCopy( - m_topLevelSourceOID), target, prop.getName(), item, - (ContentItem) source); + PublishedLink.create( + (ContentItem) getCopy(m_topLevelSourceOID), + target, + prop.getName(), + item, + (ContentItem) source); } else { - PublishedLink.create((ContentItem) getCopy( - m_topLevelSourceOID), target, prop.getName(), item, - null); + PublishedLink.create( + (ContentItem) getCopy(m_topLevelSourceOID), + target, + prop.getName(), + item, + null); } m_trace.exit("copy", null); diff --git a/ccm-ldn-util/src/com/arsdigita/london/util/cmd/MetadataPrinter.java b/ccm-ldn-util/src/com/arsdigita/london/util/cmd/MetadataPrinter.java new file mode 100644 index 000000000..75f6abb49 --- /dev/null +++ b/ccm-ldn-util/src/com/arsdigita/london/util/cmd/MetadataPrinter.java @@ -0,0 +1,99 @@ +package com.arsdigita.london.util.cmd; + +import com.arsdigita.cms.ContentBundle; +import com.arsdigita.cms.ContentPage; +import com.arsdigita.domain.DomainObject; +import com.arsdigita.domain.DomainObjectFactory; +import com.arsdigita.packaging.Program; +import com.arsdigita.persistence.DataObject; +import com.arsdigita.persistence.OID; +import com.arsdigita.persistence.Session; +import com.arsdigita.persistence.SessionManager; +import com.arsdigita.persistence.metadata.Association; +import com.arsdigita.persistence.metadata.DataType; +import com.arsdigita.persistence.metadata.Model; +import com.arsdigita.persistence.metadata.ObjectType; +import com.arsdigita.persistence.metadata.Property; +import java.math.BigDecimal; +import java.util.Iterator; +import java.util.Set; +import org.apache.commons.cli.CommandLine; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +public class MetadataPrinter extends Program { + + public MetadataPrinter() { + super("MetadataPrinter", "1.0.0", ""); + } + + @Override + protected void doRun(final CommandLine cmdLine) { + final String[] args = cmdLine.getArgs(); + + if (args.length < 1) { + System.out.println("Usage:"); + System.out.println("MetadataPrinter $oid"); + System.exit(-1); + } + + final OID oid = OID.valueOf(args[0]); + final Session session = SessionManager.getSession(); + final DataObject dobj = session.retrieve(oid); + + final ObjectType objType = dobj.getObjectType(); + printObjectTypeData(objType); + + System.out.println(""); + + final DomainObject obj = DomainObjectFactory.newInstance(oid); + if (obj instanceof ContentPage) { + final ContentPage page = (ContentPage) obj; + final ContentBundle bundle = page.getContentBundle(); + final OID bundleOid = bundle.getOID(); + System.out.printf("Bundle OID: %s\n\n", bundleOid.toString()); + final DataObject bundleDobj = session.retrieve(bundleOid); + printObjectTypeData(bundleDobj.getObjectType()); + } + + } + + public static void main(final String[] args) { + new MetadataPrinter().run(args); + } + + private void printObjectTypeData(final ObjectType objType) { + System.out.printf("ObjectType: %s\n", objType.getName()); + System.out.println("Properties: "); + Iterator propIter = objType.getProperties(); + while (propIter.hasNext()) { + printPropertyData((Property) propIter.next()); + } + } + + private void printPropertyData(final Property property) { + System.out.printf("\tName..............: %s\n", property.getName()); + System.out.printf("\tisAttribute.......: %b\n", property.isAttribute()); + System.out.printf("\tisRole............: %b\n", property.isRole()); + System.out.printf("\tisCollection......: %b\n", property.isCollection()); + System.out.printf("\tisNullable........: %b\n", property.isNullable()); + System.out.printf("\tisRequired........: %b\n", property.isRequired()); + System.out.printf("\tisComponent.......: %b\n", property.isComponent()); + System.out.printf("\tisComposite.......: %b\n", property.isComponent()); + System.out.printf("\tisKeyProperty.....: %b\n", property.isComponent()); + if (property.getAssociatedProperty() != null) { + System.out.printf("\tassociatedProperty: %s\n", + property.getAssociatedProperty().getName()); + } + System.out.printf("\tType..............:\n"); + final DataType dataType = property.getType(); + System.out.printf("\t\tName.........: %s\n", dataType.getName()); + System.out.printf("\t\tQualifiedName: %s\n", dataType.getQualifiedName()); + System.out.printf("\t\tisCompound...: %b\n", dataType.isCompound()); + System.out.printf("\t\tisSimple.....: %b\n", dataType.isSimple()); + + } +} diff --git a/ccm-webpage/application.xml b/ccm-webpage/application.xml index 2dae4c560..f61cbc895 100755 --- a/ccm-webpage/application.xml +++ b/ccm-webpage/application.xml @@ -9,7 +9,7 @@ - +