1 16 package org.apache.cocoon.portal.coplets.basket; 17 18 import java.io.IOException ; 19 import java.util.ArrayList ; 20 import java.util.Enumeration ; 21 import java.util.List ; 22 23 import org.apache.avalon.framework.service.ServiceException; 24 import org.apache.cocoon.ProcessingException; 25 import org.apache.cocoon.environment.wrapper.RequestParameters; 26 import org.apache.cocoon.portal.PortalService; 27 import org.apache.cocoon.portal.coplets.basket.events.UploadItemEvent; 28 import org.apache.cocoon.portal.event.Event; 29 import org.apache.cocoon.xml.AttributesImpl; 30 import org.xml.sax.Attributes ; 31 import org.xml.sax.SAXException ; 32 33 39 public class FolderTransformer extends AbstractBasketTransformer { 40 41 42 protected static final String UPLOAD_ITEM_ELEMENT = "upload-item"; 43 44 45 protected static final String UPLOAD_FORM_ELEMENT = "upload-form"; 46 47 48 protected List uploadElements = new ArrayList (); 49 50 53 public void recycle() { 54 this.uploadElements.clear(); 55 super.recycle(); 56 } 57 58 61 public void endTransformingElement(String uri, String name, String raw) 62 throws ProcessingException, IOException , SAXException { 63 if ( UPLOAD_ITEM_ELEMENT.equals(name) ) { 64 this.endElement("", "input", "input"); 65 } else if ( UPLOAD_FORM_ELEMENT.equals(name) ) { 66 this.endElement("", "form", "form"); 67 this.uploadElements = new ArrayList (); 68 } 69 } 70 71 74 public void startTransformingElement(String uri, String name, 75 String raw, Attributes attr) 76 throws ProcessingException, IOException , SAXException { 77 if ( UPLOAD_ITEM_ELEMENT.equals(name) ) { 78 this.uploadElements.add(attr.getValue("name")); 79 this.startElement("", "input", "input", attr); 80 } else if ( UPLOAD_FORM_ELEMENT.equals(name) ) { 81 AttributesImpl ai = new AttributesImpl(attr); 82 PortalService service = null; 83 String parameters; 84 try { 85 service = (PortalService)this.manager.lookup(PortalService.ROLE); 86 Event e = new UploadItemEvent(this.basketManager.getFolder(), this.uploadElements); 87 parameters = service.getComponentManager().getLinkService().getLinkURI(e); 88 int pos = parameters.indexOf('?'); 89 ai.addCDATAAttribute("action", parameters.substring(0, pos)); 90 parameters = parameters.substring(pos+1); 91 } catch (ServiceException se) { 92 throw new SAXException ("Unable to lookup portal service.", se); 93 } finally { 94 this.manager.release(service); 95 } 96 this.startElement("", "form", "form", ai); 97 if ( parameters != null && parameters.length() > 0 ) { 98 RequestParameters pars = new RequestParameters(parameters); 100 Enumeration enumPars = pars.getParameterNames(); 101 while ( enumPars.hasMoreElements() ) { 102 String pName = (String )enumPars.nextElement(); 103 String pValue = pars.getParameter(pName); 104 AttributesImpl hiddenAttrs = new AttributesImpl(); 105 hiddenAttrs.addCDATAAttribute("type", "hidden"); 106 hiddenAttrs.addCDATAAttribute("name", pName); 107 hiddenAttrs.addCDATAAttribute("value", pValue); 108 this.startElement("", "input", "input", hiddenAttrs); 109 this.endElement("", "input", "input"); 110 } 111 } 112 } 113 } 114 115 } 116 | Popular Tags |