1 16 package org.directwebremoting.extend; 17 18 import java.util.ArrayList ; 19 import java.util.Iterator ; 20 import java.util.List ; 21 22 import org.directwebremoting.ScriptBuffer; 23 import org.directwebremoting.ScriptBuffer.StringWrapper; 24 25 29 public class ScriptBufferUtil 30 { 31 34 private ScriptBufferUtil() 35 { 36 } 37 38 45 public static String createOutput(ScriptBuffer buffer, ConverterManager converterManager) throws MarshallException 46 { 47 OutboundContext context = new OutboundContext(); 48 List ovs = new ArrayList (); 49 50 for (Iterator it = buffer.getParts().iterator(); it.hasNext();) 52 { 53 Object element = it.next(); 54 if (!(element instanceof StringWrapper)) 55 { 56 OutboundVariable ov = converterManager.convertOutbound(element, context); 57 ovs.add(ov); 58 } 59 else 60 { 61 ovs.add(element); 62 } 63 } 64 65 StringBuffer output = new StringBuffer (); 66 67 for (Iterator it = ovs.iterator(); it.hasNext();) 69 { 70 Object element = it.next(); 71 if (element instanceof OutboundVariable) 72 { 73 OutboundVariable ov = (OutboundVariable) element; 74 output.append(ov.getDeclareCode()); 75 } 76 } 77 78 for (Iterator it = ovs.iterator(); it.hasNext();) 80 { 81 Object element = it.next(); 82 if (element instanceof OutboundVariable) 83 { 84 OutboundVariable ov = (OutboundVariable) element; 85 output.append(ov.getBuildCode()); 86 } 87 } 88 89 for (Iterator it = ovs.iterator(); it.hasNext();) 91 { 92 Object element = it.next(); 93 if (element instanceof StringWrapper) 94 { 95 StringWrapper str = (StringWrapper) element; 96 output.append(str.toString()); 97 } 98 else 99 { 100 OutboundVariable ov = (OutboundVariable) element; 101 output.append(ov.getAssignCode()); 102 } 103 } 104 105 String exported = output.toString(); 106 return exported; 107 } 108 } 109 | Popular Tags |