Author: mbooth Date: 2005-02-02 17:51:23 +0100 (Wed, 02 Feb 2005) New Revision: 192 Added: ccm-cms-assets-fileattachment/trunk/src/com/arsdigita/cms/contentassets/FileAttachmentURLFinder.java ccm-cms/trunk/src/com/arsdigita/cms/dispatcher/AssetURLFinder.java Modified: ccm-cms-assets-fileattachment/trunk/src/com/arsdigita/cms/contentassets/FileAttachmentInitializer.java ccm-cms/trunk/src/com/arsdigita/cms/Initializer.java Log: Generic URLFinder for Assets and one for FileAttachments which will link to the containing item in the draft context. Modified: ccm-cms/trunk/src/com/arsdigita/cms/Initializer.java =================================================================== --- ccm-cms/trunk/src/com/arsdigita/cms/Initializer.java 2005-02-02 14:23:39 UTC (rev 191) +++ ccm-cms/trunk/src/com/arsdigita/cms/Initializer.java 2005-02-02 16:51:23 UTC (rev 192) @@ -19,6 +19,7 @@ package com.arsdigita.cms; import com.arsdigita.cms.contenttypes.Link; +import com.arsdigita.cms.dispatcher.AssetURLFinder; import com.arsdigita.cms.dispatcher.ItemURLFinder; import com.arsdigita.cms.dispatcher.ItemTemplatePatternGenerator; import com.arsdigita.cms.dispatcher.ItemDelegatedURLPatternGenerator; @@ -112,6 +113,8 @@ new ItemURLFinder()); URLService.registerFinder(Template.BASE_DATA_OBJECT_TYPE, new ItemURLFinder()); + URLService.registerFinder(Asset.BASE_DATA_OBJECT_TYPE, + new AssetURLFinder()); URLService.registerFinder( Link.BASE_DATA_OBJECT_TYPE, Added: ccm-cms/trunk/src/com/arsdigita/cms/dispatcher/AssetURLFinder.java =================================================================== --- ccm-cms/trunk/src/com/arsdigita/cms/dispatcher/AssetURLFinder.java 2005-02-02 14:23:39 UTC (rev 191) +++ ccm-cms/trunk/src/com/arsdigita/cms/dispatcher/AssetURLFinder.java 2005-02-02 16:51:23 UTC (rev 192) @@ -0,0 +1,66 @@ +/* + * 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 + */ + +package com.arsdigita.cms.dispatcher; + +import com.arsdigita.cms.Asset; +import com.arsdigita.cms.ContentItem; + +import com.arsdigita.kernel.NoValidURLException; +import com.arsdigita.kernel.URLFinder; +import com.arsdigita.persistence.OID; +import com.arsdigita.web.Web; +import com.arsdigita.web.WebConfig; + +/** + * @author mb...@re... + * + * Implementation of URLFinder for Assets + */ +public class AssetURLFinder implements URLFinder { + /** + * + * find URL for an asset + * + * @param oid the OID of the asset + * @param context the context of the lookup (live/draft) + * + */ + public String find(OID oid, String context) throws NoValidURLException { + if( !"live".equals( context ) ) + throw new NoValidURLException("No draft URL for assets"); + + WebConfig config = Web.getConfig(); + + StringBuffer url = new StringBuffer(); + url.append( config.getDispatcherServletPath() ); + url.append( config.getDispatcherContextPath() ); + url.append( "/cms-service/stream/asset/?asset_id=" ); + url.append( oid.get( Asset.ID ).toString() ); + + return url.toString(); + } + + /** + * + * find URL for an asset in the live context + * + * @param oid the OID of the asset + */ + public String find(OID oid) throws NoValidURLException { + return find(oid, "live"); + } +} Modified: ccm-cms-assets-fileattachment/trunk/src/com/arsdigita/cms/contentassets/FileAttachmentInitializer.java =================================================================== --- ccm-cms-assets-fileattachment/trunk/src/com/arsdigita/cms/contentassets/FileAttachmentInitializer.java 2005-02-02 14:23:39 UTC (rev 191) +++ ccm-cms-assets-fileattachment/trunk/src/com/arsdigita/cms/contentassets/FileAttachmentInitializer.java 2005-02-02 16:51:23 UTC (rev 192) @@ -16,8 +16,11 @@ import com.arsdigita.cms.ContentPage; import com.arsdigita.cms.contenttypes.ContentAssetInitializer; +import com.arsdigita.cms.contentassets.FileAttachment; import com.arsdigita.cms.contentassets.ui.FileAttachmentsStep; + import com.arsdigita.globalization.GlobalizedMessage; +import com.arsdigita.kernel.URLService; import com.arsdigita.runtime.LegacyInitEvent; import com.arsdigita.search.MetadataProviderRegistry; @@ -69,17 +72,11 @@ return 2; // XXX config param please } -/* public void init(LegacyInitEvent evt) { super.init(evt); - MetadataProviderRegistry.registerAdapter( - FileAttachment.BASE_DATA_OBJECT_TYPE, - new ContentPageMetadataProvider()); - URLService.registerFinder( - ArticleSection.BASE_DATA_OBJECT_TYPE, - new MultiPartArticleSectionURLFinder()); + FileAttachment.BASE_DATA_OBJECT_TYPE, + new FileAttachmentURLFinder()); } -*/ } Added: ccm-cms-assets-fileattachment/trunk/src/com/arsdigita/cms/contentassets/FileAttachmentURLFinder.java =================================================================== --- ccm-cms-assets-fileattachment/trunk/src/com/arsdigita/cms/contentassets/FileAttachmentURLFinder.java 2005-02-02 14:23:39 UTC (rev 191) +++ ccm-cms-assets-fileattachment/trunk/src/com/arsdigita/cms/contentassets/FileAttachmentURLFinder.java 2005-02-02 16:51:23 UTC (rev 192) @@ -0,0 +1,88 @@ +/* + * 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 + * + * Created on 11-May-04 + */ + +package com.arsdigita.cms.contentassets; + +import com.arsdigita.cms.ContentItem; +import com.arsdigita.cms.contentassets.FileAttachment; +import com.arsdigita.cms.dispatcher.AssetURLFinder; + +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 + * @author mb...@re... + * + * A URLFinder for FileAttachments. In the draft context (ie, in CMS + * backend search) it will return the draft url for the containing item. + * Otherwise it will delegate to an AssetURLFinder. + */ +public class FileAttachmentURLFinder implements URLFinder { + + private static final AssetURLFinder s_assetFinder = new AssetURLFinder(); + + /** + * + * find URL for a file attachment by finding its article + * + * @param oid the OID of the file attachment + * @param content the context of the search (ie draft/live) + */ + public String find(OID oid, String context) throws NoValidURLException { + if (!"draft".equals(context)) + return s_assetFinder.find(oid, context); + + DataObject dobj = SessionManager.getSession().retrieve(oid); + if (dobj == null) { + throw new NoValidURLException("No such data object " + oid); + } + + if (!dobj + .getObjectType() + .getQualifiedName() + .equals(FileAttachment.BASE_DATA_OBJECT_TYPE)) { + throw new NoValidURLException( + "Data Object is not a file attachment " + + dobj.getObjectType().getQualifiedName() + + " " + + oid); + } + + FileAttachment file = new FileAttachment(dobj); + ContentItem owner = file.getFileOwner(); + return URLService.locate(owner.getOID(), context); + } + + /** + * + * find URL for the live context of a file attachment. Delegates to + * AssetURLFinder. + * + * @param oid the OID of the file attachment + * + */ + public String find(OID oid) throws NoValidURLException { + return s_assetFinder.find(oid); + } +} |