1 15 package org.apache.tapestry.junit.script; 16 17 import java.util.ArrayList ; 18 import java.util.List ; 19 20 import org.apache.hivemind.Resource; 21 import org.apache.tapestry.IScriptProcessor; 22 import org.apache.tapestry.util.IdAllocator; 23 24 30 public class MockScriptProcessor implements IScriptProcessor 31 { 32 private StringBuffer _body; 33 34 private StringBuffer _initialization; 35 36 private List _externalScripts; 37 38 private IdAllocator _idAllocator = new IdAllocator(); 39 40 public void addBodyScript(String script) 41 { 42 if (_body == null) 43 _body = new StringBuffer (); 44 45 _body.append(script); 46 } 47 48 public String getBody() 49 { 50 if (_body == null) 51 return null; 52 53 return _body.toString(); 54 } 55 56 public void addInitializationScript(String script) 57 { 58 if (_initialization == null) 59 _initialization = new StringBuffer (); 60 61 _initialization.append(script); 62 } 63 64 public String getInitialization() 65 { 66 if (_initialization == null) 67 return null; 68 69 return _initialization.toString(); 70 } 71 72 public void addExternalScript(Resource scriptResource) 73 { 74 if (_externalScripts == null) 75 _externalScripts = new ArrayList (); 76 77 _externalScripts.add(scriptResource); 78 } 79 80 public Resource[] getExternalScripts() 81 { 82 if (_externalScripts == null) 83 return null; 84 85 int count = _externalScripts.size(); 86 87 return (Resource[]) _externalScripts.toArray(new Resource[count]); 88 } 89 90 public String getUniqueString(String baseValue) 91 { 92 return _idAllocator.allocateId(baseValue); 93 } 94 95 } | Popular Tags |