Author: mbooth Date: 2005-01-18 14:56:42 +0100 (Tue, 18 Jan 2005) New Revision: 182 Added: ccm-cms-types-mparticle/trunk/src/com/arsdigita/cms/contenttypes/MultiPartArticleSectionURLFinder.java Modified: ccm-cms-types-mparticle/trunk/pdl/com/arsdigita/content-types/MultiPartArticle.pdl ccm-cms-types-mparticle/trunk/src/WEB-INF/traversal-adapters/com/arsdigita/cms/contenttypes/MultiPartArticle.xml ccm-cms-types-mparticle/trunk/src/com/arsdigita/cms/contenttypes/ArticleSection.java ccm-cms-types-mparticle/trunk/src/com/arsdigita/cms/contenttypes/MultiPartArticle.java ccm-cms-types-mparticle/trunk/src/com/arsdigita/cms/contenttypes/MultiPartArticleInitializer.java Log: Index article sections seperately Modified: ccm-cms-types-mparticle/trunk/pdl/com/arsdigita/content-types/MultiPartArticle.pdl =================================================================== --- ccm-cms-types-mparticle/trunk/pdl/com/arsdigita/content-types/MultiPartArticle.pdl 2005-01-18 13:49:26 UTC (rev 181) +++ ccm-cms-types-mparticle/trunk/pdl/com/arsdigita/content-types/MultiPartArticle.pdl 2005-01-18 13:56:42 UTC (rev 182) @@ -26,9 +26,32 @@ // the summary of the article String [0..1] summary = ct_mp_articles.summary VARCHAR(4000); + + reference key ( ct_mp_articles.article_id ); + +} + +association { + composite MultiPartArticle[1..1] mparticle = join ct_mp_sections.article_id + to ct_mp_articles.article_id; component ArticleSection[0..n] sections = join ct_mp_articles.article_id to ct_mp_sections.article_id; +} + +query PageNumberForArticleSection { + Integer pageNumber; - reference key ( ct_mp_articles.article_id ); + do { + + SELECT count (a.section_id) + 1 as page + from ct_mp_sections a, + ct_mp_sections b + where a.page_break=1 + and a.rank < b.rank + and a.article_id = b.article_id + and b.section_id = :section + } map { + pageNumber = page; + } } Modified: ccm-cms-types-mparticle/trunk/src/WEB-INF/traversal-adapters/com/arsdigita/cms/contenttypes/MultiPartArticle.xml =================================================================== --- ccm-cms-types-mparticle/trunk/src/WEB-INF/traversal-adapters/com/arsdigita/cms/contenttypes/MultiPartArticle.xml 2005-01-18 13:49:26 UTC (rev 181) +++ ccm-cms-types-mparticle/trunk/src/WEB-INF/traversal-adapters/com/arsdigita/cms/contenttypes/MultiPartArticle.xml 2005-01-18 13:56:42 UTC (rev 182) @@ -99,21 +99,38 @@ <xrd:property name="/object/sections/image/mimeType/objectType"/> <xrd:property name="/object/sections/image/content"/> </xrd:attributes> + <!-- <xrd:associations rule="include"> <xrd:property name="/object/sections"/> <xrd:property name="/object/sections/text"/> <xrd:property name="/object/sections/image"/> <xrd:property name="/object/sections/image/mimeType"/> </xrd:associations> + --> </xrd:adapter> + <xrd:adapter objectType="com.arsdigita.cms.contenttypes.ArticleSection" extends="com.arsdigita.cms.ContentPage" traversalClass="com.arsdigita.cms.contenttypes.ContentItemTraversalAdapter"> + <xrd:attributes rule="exclude"> + <xrd:property name="/object/text/id"/> + <xrd:property name="/object/text/defaultDomainClass"/> + <xrd:property name="/object/text/objectType"/> + <xrd:property name="/object/text/displayName"/> + <xrd:property name="/object/text/isDeleted"/> + <xrd:property name="/object/text/ancestors"/> + <xrd:property name="/object/text/version"/> + <xrd:property name="/object/text/name"/> + <xrd:property name="/object/text/language"/> + </xrd:attributes> + <xrd:associations rule="include"> + <xrd:property name="/object/text"/> + </xrd:associations> + </xrd:adapter> </xrd:context> <!-- For assets, we want to pull out all HTML, or binary files --> <xrd:context name="com.arsdigita.cms.search.ContentPageAssetExtractor"> - <xrd:adapter objectType="com.arsdigita.cms.contenttypes.MultiPartArticle" extends="com.arsdigita.cms.ContentItem" traversalClass="com.arsdigita.cms.contenttypes.ContentItemTraversalAdapter"> + <xrd:adapter objectType="com.arsdigita.cms.contenttypes.ArticleSection" extends="com.arsdigita.cms.ContentItem" traversalClass="com.arsdigita.cms.contenttypes.ContentItemTraversalAdapter"> <xrd:associations rule="include"> - <xrd:property name="/object/sections"/> - <xrd:property name="/object/sections/text"/> + <xrd:property name="/object/text"/> </xrd:associations> </xrd:adapter> </xrd:context> Modified: ccm-cms-types-mparticle/trunk/src/com/arsdigita/cms/contenttypes/ArticleSection.java =================================================================== --- ccm-cms-types-mparticle/trunk/src/com/arsdigita/cms/contenttypes/ArticleSection.java 2005-01-18 13:49:26 UTC (rev 181) +++ ccm-cms-types-mparticle/trunk/src/com/arsdigita/cms/contenttypes/ArticleSection.java 2005-01-18 13:56:42 UTC (rev 182) @@ -24,6 +24,7 @@ import com.arsdigita.cms.ImageAsset; import com.arsdigita.cms.TextAsset; import com.arsdigita.domain.DataObjectNotFoundException; +import com.arsdigita.domain.DomainObjectFactory; import com.arsdigita.persistence.DataObject; import com.arsdigita.persistence.OID; import com.arsdigita.persistence.metadata.ObjectType; @@ -49,6 +50,7 @@ public static final String IMAGE = "image"; public static final String RANK = "rank"; public static final String PAGE_BREAK = "pageBreak"; + public static final String MP_ARTICLE = "mparticle"; public static final String BASE_DATA_OBJECT_TYPE = "com.arsdigita.cms.contenttypes.ArticleSection"; @@ -111,6 +113,10 @@ set(RANK, rank); } + public MultiPartArticle getMPArticle() { + DataObject obj = (DataObject) get( MP_ARTICLE ); + return (MultiPartArticle) DomainObjectFactory.newInstance( obj ); + } /** Accessor. Get the text associated with this item. */ public TextAsset getText() { Modified: ccm-cms-types-mparticle/trunk/src/com/arsdigita/cms/contenttypes/MultiPartArticle.java =================================================================== --- ccm-cms-types-mparticle/trunk/src/com/arsdigita/cms/contenttypes/MultiPartArticle.java 2005-01-18 13:49:26 UTC (rev 181) +++ ccm-cms-types-mparticle/trunk/src/com/arsdigita/cms/contenttypes/MultiPartArticle.java 2005-01-18 13:56:42 UTC (rev 182) @@ -24,6 +24,7 @@ import com.arsdigita.cms.CustomCopy; import com.arsdigita.cms.ItemCopier; import com.arsdigita.domain.DataObjectNotFoundException; +import com.arsdigita.domain.DomainObject; import com.arsdigita.domain.DomainObjectFactory; import com.arsdigita.persistence.DataAssociation; import com.arsdigita.persistence.DataAssociationCursor; @@ -47,7 +48,7 @@ */ public class MultiPartArticle extends ContentPage { - private static final Logger log = Logger.getLogger(MultiPartArticle.class); + private static final Logger s_log = Logger.getLogger(MultiPartArticle.class); /** PDL property names */ public static final String SUMMARY = "summary"; @@ -110,10 +111,21 @@ super(type); } - public void beforeSave() { - super.beforeSave(); - - Assert.exists(getContentType(), ContentType.class); + protected void afterSave() { + DataAssociationCursor dac = ((DataAssociation) get(SECTIONS)).cursor(); + while( dac.next() ) { + ArticleSection section = (ArticleSection) + DomainObjectFactory.newInstance( dac.getDataObject() ); + + if( s_log.isDebugEnabled() ) { + s_log.debug( "Saving section " + section.getOID() ); + } + + section.setLanguage( getLanguage() ); + section.save(); + } + + super.afterSave(); } public String getBaseDataObjectType() { @@ -150,7 +162,7 @@ * @param rank the rank of the ArticleSection in the association. */ public void addSection( ArticleSection section, Integer rank ) { - log.info("adding section:" + section.getName() + + s_log.info("adding section:" + section.getName() + " with rank " + rank.toString()); section.setRank(rank); add(SECTIONS,section); @@ -230,8 +242,8 @@ * the max section rank inclusively. */ public void changeSectionRank(ArticleSection source, int destRank) { - if (log.isDebugEnabled()) { - log.debug("*** changeSectionRank, section ID = " + source.getID() + if (s_log.isDebugEnabled()) { + s_log.debug("*** changeSectionRank, section ID = " + source.getID() + "destRank = " + destRank); } Modified: ccm-cms-types-mparticle/trunk/src/com/arsdigita/cms/contenttypes/MultiPartArticleInitializer.java =================================================================== --- ccm-cms-types-mparticle/trunk/src/com/arsdigita/cms/contenttypes/MultiPartArticleInitializer.java 2005-01-18 13:49:26 UTC (rev 181) +++ ccm-cms-types-mparticle/trunk/src/com/arsdigita/cms/contenttypes/MultiPartArticleInitializer.java 2005-01-18 13:56:42 UTC (rev 182) @@ -18,17 +18,11 @@ */ package com.arsdigita.cms.contenttypes; -import com.arsdigita.cms.ContentType; - -import com.arsdigita.db.*; -import com.arsdigita.persistence.pdl.*; -import com.arsdigita.runtime.*; -import com.arsdigita.domain.DomainObject; -import com.arsdigita.domain.DomainObjectFactory; -import com.arsdigita.domain.DomainObjectInstantiator; +import com.arsdigita.cms.search.ContentPageMetadataProvider; +import com.arsdigita.kernel.URLService; import com.arsdigita.persistence.DataObject; -import com.arsdigita.xml.XML; -import com.arsdigita.domain.xml.TraversalHandler; +import com.arsdigita.runtime.LegacyInitEvent; +import com.arsdigita.search.MetadataProviderRegistry; /** * The CMS initializer. @@ -58,4 +52,15 @@ }; } + public void init(LegacyInitEvent evt) { + super.init(evt); + + MetadataProviderRegistry.registerAdapter( + ArticleSection.BASE_DATA_OBJECT_TYPE, + new ContentPageMetadataProvider()); + + URLService.registerFinder( + ArticleSection.BASE_DATA_OBJECT_TYPE, + new MultiPartArticleSectionURLFinder()); + } } Added: ccm-cms-types-mparticle/trunk/src/com/arsdigita/cms/contenttypes/MultiPartArticleSectionURLFinder.java =================================================================== --- ccm-cms-types-mparticle/trunk/src/com/arsdigita/cms/contenttypes/MultiPartArticleSectionURLFinder.java 2005-01-18 13:49:26 UTC (rev 181) +++ ccm-cms-types-mparticle/trunk/src/com/arsdigita/cms/contenttypes/MultiPartArticleSectionURLFinder.java 2005-01-18 13:56:42 UTC (rev 182) @@ -0,0 +1,97 @@ +/* + * 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 + * + * Originally created on 11-May-04 + * + * Copyright West Sussex County Council + */ +package com.arsdigita.cms.contenttypes; + +import com.arsdigita.cms.contenttypes.ArticleSection; +import com.arsdigita.cms.contenttypes.MultiPartArticle; +import com.arsdigita.kernel.NoValidURLException; +import com.arsdigita.kernel.URLFinder; +import com.arsdigita.kernel.URLService; +import com.arsdigita.persistence.DataObject; +import com.arsdigita.persistence.DataQuery; +import com.arsdigita.persistence.OID; +import com.arsdigita.persistence.SessionManager; + +/** + * @author cgyg9330 + * + * Implementation of URLFinder for a specific ArticleSection + * + */ +public class MultiPartArticleSectionURLFinder implements URLFinder { + public static final String FIND_PAGE_FOR_SECTION_QUERY = "com.arsdigita.cms.contenttypes.PageNumberForArticleSection"; + + /** + * + * find URL for a multipart article section. URL is of the format + * content/folder/articlename?page=X where articlename is the multipart + * article that this section is from and page is the page that the section + * appears on. + * + * @param oid the OID of the article section + */ + public String find(OID oid) throws NoValidURLException { + DataObject dobj = SessionManager.getSession().retrieve(oid); + if (dobj == null) { + throw new NoValidURLException("No such data object " + oid); + } + + if (!dobj + .getObjectType() + .getQualifiedName() + .equals(ArticleSection.BASE_DATA_OBJECT_TYPE)) { + throw new NoValidURLException( + "Data Object is not a multipart article section " + + dobj.getObjectType().getQualifiedName() + + " " + + oid); + } + + ArticleSection thisSection = new ArticleSection(dobj); + MultiPartArticle article = thisSection.getMPArticle(); + StringBuffer articleURL = new StringBuffer(URLService.locate(article.getOID())); + + Integer sectionNumber = thisSection.getRank(); + if (sectionNumber.intValue() != 1) { + DataQuery pageNumber = SessionManager.getSession().retrieveQuery + ( FIND_PAGE_FOR_SECTION_QUERY ); + pageNumber.setParameter("section", thisSection.getID()); + while (pageNumber.next()) { + // just in case there are existing parameters on the url + if (articleURL.toString().indexOf("?") != -1) { + articleURL.append("&"); + } else { + articleURL.append("?"); + } + articleURL.append("page="); + articleURL.append(pageNumber.get("pageNumber")); + } + + } + return articleURL.toString(); + } + + /** + * Simply calls find(OID). context is ignored. + */ + public String find(OID oid, String context) throws NoValidURLException { + return find(oid); + } +} |