1 28 29 package com.idaremedia.antx.ownhelpers; 30 31 import java.util.Map ; 32 import java.util.Vector ; 33 34 import org.apache.tools.ant.BuildException; 35 import org.apache.tools.ant.Project; 36 import org.apache.tools.ant.PropertyHelper; 37 38 import com.idaremedia.antx.AntX; 39 import com.idaremedia.antx.helpers.NameValuePair; 40 41 54 55 public class PropertyExaminer extends ProjectDependentSkeleton 56 { 57 private static final String IAM_ = AntX.utilities+"PropertyExaminer:"; 58 59 60 61 private static final int DONTCHECK= 0; 62 63 private static final int SIMPLE= DONTCHECK+100; 64 65 private static final int THOROUGH= SIMPLE+1; 66 67 68 73 public PropertyExaminer() 74 { 75 } 76 77 78 82 public PropertyExaminer(Project P) 83 { 84 setProject(P); 85 } 86 87 88 94 public final void setCheckSimpleBrokenSubstitution() 95 { 96 m_checkBadSubst = SIMPLE; 97 } 98 99 100 107 public final void setCheckBrokenSubstitution() 108 { 109 m_checkBadSubst = THOROUGH; 110 } 111 112 113 117 public final void clearCheckBrokenSubstitution() 118 { 119 m_checkBadSubst = DONTCHECK; 120 } 121 122 123 129 public final boolean willCheckBrokenSubstitution() 130 { 131 return m_checkBadSubst!=DONTCHECK; 132 } 133 134 135 142 public final void setBrokenSubstitutionProxy(String valueProxy) 143 { 144 AntX.require_(valueProxy!=null,IAM_,"setProxy- nonzro valu"); 145 m_valueProxy = valueProxy; 146 } 147 148 149 155 private boolean isBroken(String value, Project P, String name) 156 { 157 boolean broken = value==null; 158 if (!broken && m_checkBadSubst!=DONTCHECK) { 159 value = value.trim(); 160 broken = value.startsWith("${") && value.endsWith("}"); 161 162 if (!broken && m_checkBadSubst!=SIMPLE) { int i = value.indexOf("${"); 164 if (i>=0) { 165 PropertyHelper Ph= PropertyHelper.getPropertyHelper(P); 166 Vector ignore = new Vector (); 167 Vector misses = new Vector (); 168 try { 169 Ph.parsePropertyString(value,ignore,misses); 170 if (!misses.isEmpty()) { 171 broken= true; 172 } 173 } catch(BuildException malformX) { 174 String warning = AntX.uistrs().get 175 ("fixture.bad.propdef.found", name,value); 176 P.log(warning,Project.MSG_WARN); 177 broken= true; 178 } 179 } } 181 } 182 return broken; 183 } 184 185 186 193 public boolean verifiedLiteral(String value, Project P) 194 { 195 AntX.require_(value!=null,IAM_,"verifyLiteral- nonzro value"); 196 AntX.require_(P!=null,IAM_,"verifyLiteral- nonzro project"); 197 return !isBroken(value,P,""); 198 } 199 200 201 206 public final boolean verifiedLiteral(String value) 207 { 208 return verifiedLiteral(value,getProject()); 209 } 210 211 212 221 public Map.Entry verifiedPropertyValue(Map.Entry entry, Project P) 222 { 223 AntX.require_(entry!=null && entry.getKey()!=null,IAM_, 224 "verifyProp- nonzro property"); 225 AntX.require_(P!=null,IAM_,"verifyProp- nonzro project"); 226 227 Map.Entry result = entry; 228 boolean broken = isBroken((String )entry.getValue(),P, 229 entry.getKey().toString()); 230 if (broken) { 231 if (m_valueProxy!=null) { 233 NameValuePair nvp = new NameValuePair(); 234 result = nvp; 235 nvp.setName(entry.getKey().toString()); 236 nvp.setValue(m_valueProxy); 237 } 238 else { 240 result = null; 241 } 242 } 243 return result; 244 } 245 246 247 252 public final Map.Entry verifiedPropertyValue(Map.Entry entry) 253 { 254 return verifiedPropertyValue(entry,getProject()); 255 } 256 257 258 private int m_checkBadSubst=SIMPLE; private String m_valueProxy;} 261 262 263 264 | Popular Tags |