1 16 package org.apache.cocoon.portal.coplets.basket; 17 18 import org.apache.avalon.framework.activity.Disposable; 19 import org.apache.avalon.framework.parameters.ParameterException; 20 import org.apache.avalon.framework.parameters.Parameters; 21 import org.apache.avalon.framework.service.ServiceException; 22 import org.apache.avalon.framework.service.ServiceManager; 23 import org.apache.cocoon.portal.PortalService; 24 import org.apache.cocoon.portal.coplet.CopletInstanceData; 25 import org.apache.cocoon.portal.coplets.basket.events.AddItemEvent; 26 import org.apache.cocoon.portal.event.Event; 27 import org.apache.cocoon.portal.layout.Layout; 28 import org.apache.cocoon.portal.layout.impl.CopletLayout; 29 import org.apache.cocoon.portal.layout.renderer.aspect.RendererAspectContext; 30 import org.apache.cocoon.portal.layout.renderer.aspect.impl.AbstractAspect; 31 import org.apache.cocoon.xml.XMLUtils; 32 import org.xml.sax.ContentHandler ; 33 import org.xml.sax.SAXException ; 34 35 43 public final class AddToBasketAspect 44 extends AbstractAspect 45 implements Disposable { 46 47 48 protected BasketManager basketManager; 49 50 51 54 public void service(ServiceManager manager) throws ServiceException { 55 super.service(manager); 56 this.basketManager = (BasketManager)this.manager.lookup(BasketManager.ROLE); 57 } 58 59 60 63 public void dispose() { 64 if ( this.manager != null ) { 65 this.manager.release(this.basketManager); 66 this.basketManager = null; 67 this.manager = null; 68 } 69 } 70 71 74 public void toSAX(RendererAspectContext context, 75 Layout layout, 76 PortalService service, 77 ContentHandler contenthandler) 78 throws SAXException { 79 final CopletInstanceData cid = ((CopletLayout)layout).getCopletInstanceData(); 80 final ContentStore store; 81 final String elementName; 82 if ( context.getAspectConfiguration().equals(Boolean.TRUE) ) { 83 store = this.basketManager.getBasket(); 84 elementName = "basket-add-content"; 85 } else { 86 store = this.basketManager.getBriefcase(); 87 elementName = "briefcase-add-content"; 88 } 89 90 Boolean b = (Boolean )cid.getCopletData().getAttribute("basket-content"); 91 if ( b != null && b.equals(Boolean.TRUE) ) { 92 Object item = new ContentItem(cid, true); 93 Event event = new AddItemEvent(store, item); 94 XMLUtils.createElement(contenthandler, elementName, service.getComponentManager().getLinkService().getLinkURI(event)); 95 } 96 b = (Boolean )cid.getCopletData().getAttribute("basket-link"); 97 if ( b != null && b.equals(Boolean.TRUE) ) { 98 Object item = new ContentItem(cid, false); 99 Event event = new AddItemEvent(store, item); 100 XMLUtils.createElement(contenthandler, elementName, service.getComponentManager().getLinkService().getLinkURI(event)); 101 } 102 103 context.invokeNext( layout, service, contenthandler ); 104 } 105 106 109 public Object prepareConfiguration(Parameters configuration) 110 throws ParameterException { 111 if ( configuration.getParameter("use-store", "basket").equalsIgnoreCase("basket") ) { 112 return Boolean.TRUE; 113 } 114 return Boolean.FALSE; 115 } 116 } 117 | Popular Tags |