1 16 package org.apache.cocoon.portal.layout.renderer.aspect.impl; 17 18 import java.util.ArrayList ; 19 import java.util.Iterator ; 20 import java.util.List ; 21 import java.util.Map ; 22 23 import org.apache.cocoon.environment.ObjectModelHelper; 24 import org.apache.cocoon.environment.Request; 25 import org.apache.cocoon.environment.Session; 26 import org.apache.cocoon.portal.PortalService; 27 import org.apache.cocoon.portal.acting.helpers.CopletEventDescription; 28 import org.apache.cocoon.portal.acting.helpers.LayoutEventDescription; 29 import org.apache.cocoon.portal.coplet.CopletInstanceData; 30 import org.apache.cocoon.portal.layout.Layout; 31 import org.apache.cocoon.portal.layout.impl.CopletLayout; 32 import org.apache.cocoon.portal.layout.renderer.aspect.RendererAspectContext; 33 import org.xml.sax.ContentHandler ; 34 import org.xml.sax.SAXException ; 35 36 37 57 public class HistoryAspect 58 extends AbstractAspect { 59 60 67 protected void addValues(String id, List state, Map values, String prefix,boolean isCopletEvent) { 68 final Iterator iter = values.entrySet().iterator(); 69 while ( iter.hasNext() ) { 70 final Map.Entry entry = (Map.Entry )iter.next(); 71 final String path = prefix + entry.getKey(); 72 if(!isCopletEvent){ 73 LayoutEventDescription led = new LayoutEventDescription(); 74 led.path = path; 75 led.layoutId = id; 76 led.data = entry.getValue(); 77 state.add(led); 78 }else{ 79 CopletEventDescription ced = new CopletEventDescription(); 80 ced.path = path; 81 ced.copletId = id; 82 ced.data = entry.getValue(); 83 state.add(ced); 84 } 85 } 86 } 87 88 91 public void toSAX(RendererAspectContext context, 92 Layout layout, 93 PortalService service, 94 ContentHandler handler) 95 throws SAXException { 96 if ( layout.getId() != null ) { 97 final Request request = ObjectModelHelper.getRequest(context.getObjectModel()); 98 final Session session = request.getSession(false); 99 if ( session != null ) { 100 List history = (List )session.getAttribute("portal-history"); 101 if ( history == null ) { 102 103 history = new ArrayList (); 104 } 105 List state = (List )request.getAttribute("portal-history"); 106 if ( state == null ) { 107 state = new ArrayList (); 108 request.setAttribute("portal-history", state); 109 history.add(state); 110 } 111 112 this.addValues(layout.getId(), state, layout.getAspectDatas(), "aspectDatas/",false); 113 this.addValues(layout.getId(), state, layout.getParameters(), "parameters/",false); 114 115 if ( layout instanceof CopletLayout ) { 117 CopletInstanceData cid = ((CopletLayout)layout).getCopletInstanceData(); 118 this.addValues(cid.getId(), state, cid.getAspectDatas(), "aspectDatas/",true); 119 this.addValues(cid.getId(), state, cid.getAttributes(), "attributes/",true); 120 } 121 session.setAttribute("portal-history", history); 122 } 123 } 124 context.invokeNext(layout, service, handler); 125 } 126 127 } 128 | Popular Tags |