1 30 package com.genimen.djeneric.structure; 31 32 import java.io.UnsupportedEncodingException ; 33 34 import com.genimen.djeneric.language.Messages; 35 import com.genimen.djeneric.util.DjBase64; 36 37 public class ScriptDefinition 38 { 39 40 String _title; 41 String _code; 42 boolean _markedForDelete = false; 43 44 public Object clone() 45 { 46 ScriptDefinition result = new ScriptDefinition(); 47 result._title = _title; 48 result._code = _code; 49 result._markedForDelete = _markedForDelete; 50 return result; 51 } 52 53 public boolean equals(Object obj) 54 { 55 if (!(obj instanceof ScriptDefinition)) return false; 56 57 ScriptDefinition other = (ScriptDefinition) obj; 58 59 return safeCompare(_title, other._title) && safeCompare(_code, other._code); 60 } 61 62 public int hashCode() 63 { 64 int result = 0; 65 if (_title != null) result += _title.hashCode(); 66 if (_code != null) result += _code.hashCode(); 67 68 return result; 69 } 70 71 private boolean safeCompare(Object one, Object two) 72 { 73 if (one == null && two == null) return true; 74 if (one == null || two == null) return false; 75 76 return one.equals(two); 77 } 78 79 public ScriptDefinition() 80 { 81 _title = Messages.getString("ScriptDefinition.NewScript"); 82 _code = ""; 83 } 84 85 public ScriptDefinition(String name, String code) 86 { 87 _title = name; 88 _code = code; 89 } 90 91 public String getTitle() 92 { 93 return _title; 94 } 95 96 public void setTitle(String title) 97 { 98 if (title != null && title.trim().length() == 0) title = null; 99 _title = title; 100 } 101 102 public String toString() 103 { 104 return _title; 105 } 106 107 public boolean isMarkedForDelete() 108 { 109 return _markedForDelete; 110 } 111 112 public void setMarkedForDelete(boolean markedForDelete) 113 { 114 _markedForDelete = markedForDelete; 115 } 116 117 public String getCode() 118 { 119 return _code; 120 } 121 122 public void setCode(String string) 123 { 124 _code = string; 125 } 126 127 public String getBase64() throws UnsupportedEncodingException 128 { 129 StringBuffer result = new StringBuffer (10000); 130 131 String encoded = DjBase64.encode(getCode().getBytes()); 132 int lineLength = 80; 133 134 int idx = 0; 135 while (idx < encoded.length()) 136 { 137 int length = lineLength; 138 if (idx + length > encoded.length()) length = encoded.length() - idx; 139 result.append(encoded.subSequence(idx, idx + length)); 140 result.append("\n"); 141 idx += length; 142 } 143 return result.toString(); 144 } 145 146 public void setBase64(String base64) throws UnsupportedEncodingException 147 { 148 setCode(new String (DjBase64.decode(base64))); 149 } 150 151 } | Popular Tags |