1 28 29 package com.idaremedia.antx.solo; 30 31 import java.io.File ; 32 import java.net.MalformedURLException ; 33 import java.net.URL ; 34 import java.util.ArrayList ; 35 import java.util.Iterator ; 36 import java.util.List ; 37 38 import org.apache.tools.ant.BuildException; 39 import org.apache.tools.ant.Project; 40 41 import com.idaremedia.antx.AntX; 42 import com.idaremedia.antx.apis.AntLibFriendly; 43 import com.idaremedia.antx.helpers.InnerString; 44 import com.idaremedia.antx.helpers.Tk; 45 import com.idaremedia.antx.starters.ListFriendly; 46 import com.idaremedia.antx.starters.StringItemList; 47 48 84 85 public final class UrlList extends StringItemList 86 implements ListFriendly, AntLibFriendly 87 { 88 89 public static final String DEFAULT_DELIMITER = ";"; 90 91 92 95 public UrlList() 96 { 97 super(AntX.fixture+"UrlList:"); 98 } 99 100 101 107 public void setDelim(String delimiter) 108 { 109 require_(delimiter!=null,"setDelim- nonzro delim"); 110 if (isReference()) { 111 throw tooManyAttributes(); 112 } 113 m_delim = delimiter; 114 edited(); 115 } 116 117 118 123 public String getDelim() 124 { 125 if (isReference()) { 126 return getOtherList().getDelim(); 127 } 128 return m_delim; 129 } 130 131 132 139 public void setPrefix(String prefix) 140 { 141 setPrefixString(prefix); 142 } 143 144 145 149 public String getPrefix() 150 { 151 if (isReference()) { 152 return getOtherList().getPrefix(); 153 } 154 return getPrefixString(); 155 } 156 157 158 165 public void setSuffix(String suffix) 166 { 167 setSuffixString(suffix); 168 } 169 170 171 175 public String getSuffix() 176 { 177 if (isReference()) { 178 return getOtherList().getSuffix(); 179 } 180 return getSuffixString(); 181 } 182 183 184 190 public void setFile(File f) 191 { 192 require_(f!=null,"setfil- nonzro fil"); 193 addFileOrURL(f.getPath()); 194 } 195 196 197 204 public void setResource(String rn) 205 { 206 require_(rn!=null,"setRez- nonzro reznam"); 207 addResource(rn); 208 } 209 210 211 219 public void addConfiguredURL(InnerString urlstring) 220 { 221 require_(urlstring!=null,"addURL- nonzro urlstr"); 222 addItem(urlstring,getProject()); 223 addedURLstring(); 224 } 225 226 227 233 public String stringFrom(Project theProject) 234 { 235 if (isReference()) { 236 return getOtherList().stringFrom(theProject); 237 } 238 StringBuffer sb = new StringBuffer (150); 239 final String theDelimiter = getDelim(); 240 241 int N=0; 242 Iterator itr= readonlyStringIterator(null); 243 244 while (itr.hasNext()) { 245 if (N>0) { 246 sb.append(theDelimiter); 247 } 248 sb.append(itr.next().toString()); 249 N++; 250 } 251 itr=null; 252 return sb.substring(0); 253 } 254 255 256 259 public String toString() 260 { 261 return stringFrom(getProject()); 262 } 263 264 265 270 protected boolean includeItem(String string) 271 { 272 return !Tk.isWhitespace(string); 273 } 274 275 276 283 protected List copyOfItems(Project p) 284 { 285 ArrayList l = (ArrayList )m_URLs.clone(); 286 if (!l.isEmpty()) { 287 try { 288 for (int i=0,N=l.size();i<N;i++) { 289 l.set(i, new URL (l.get(i).toString())); 290 } 291 } catch(MalformedURLException mfx) { 292 throw new BuildException(mfx); 293 } 294 } 295 return l; 296 } 297 298 299 305 protected void cloneInternals(StringItemList cloned) 306 { 307 super.cloneInternals(cloned); 308 ((UrlList)cloned).m_URLs = (ArrayList )copyOfItems(null); 309 } 310 311 312 318 private URL convertURL(String urlstr) 319 { 320 try { 321 if (shouldModifyStrings()) { 322 StringBuffer sb = new StringBuffer (urlstr.length()+20); 323 sb.append(getPrefixString()); 324 sb.append(urlstr); 325 sb.append(getSuffixString()); 326 urlstr = sb.substring(0); 327 } 328 return new URL (urlstr); 329 } catch (MalformedURLException mfx) { 330 String error = uistrs().get("solo.urls.malformed",getId(),urlstr); 331 log(error,Project.MSG_ERR); 332 throw new BuildException(error); 333 } 334 } 335 336 337 340 private void addedURLstring() 341 { 342 List sl= rawStringsList(); 343 String urlstr = (String )sl.get(sl.size()-1); 344 m_URLs.add(convertURL(urlstr)); 345 ensure_(sl.size()==m_URLs.size(),"addedURL- synced lists"); 346 } 347 348 349 private final UrlList getOtherList() 350 { 351 return (UrlList)getOtherItemList(UrlList.class); 352 } 353 354 355 private String m_delim = DEFAULT_DELIMITER; 356 private ArrayList m_URLs = new ArrayList (5); 357 } 358 359 360 | Popular Tags |