1 28 29 package com.idaremedia.antx.init; 30 31 import org.apache.tools.ant.BuildException; 32 import org.apache.tools.ant.Project; 33 34 import com.idaremedia.antx.AntX; 35 import com.idaremedia.antx.ExportScope; 36 import com.idaremedia.antx.FlexString; 37 import com.idaremedia.antx.apis.AntLibFriendly; 38 import com.idaremedia.antx.parameters.FlexValueSupport; 39 import com.idaremedia.antx.starters.MsgTask; 40 41 57 58 public final class CopyMsgTask extends MsgTask 59 implements FlexValueSupport, AntLibFriendly 60 { 61 64 public static final ExportScope DEFAULT_SCOPE= ExportScope.THREAD; 65 66 67 70 public CopyMsgTask() 71 { 72 super(AntX.uism); 73 } 74 75 76 81 public void setProperty(String property) 82 { 83 require_(property!=null, "setProp- nonzro name"); 84 checkNewCopyTarget(); 85 m_value.set(property); 86 m_value.setIsProperty(true); 87 } 88 89 90 95 public void setVariable(String property) 96 { 97 require_(property!=null, "setVar- nonzro name"); 98 checkNewCopyTarget(); 99 m_value.set(property); 100 m_value.setIsExported(true); 101 } 102 103 104 108 public void setScope(ExportScope scope) 109 { 110 require_(scope!=null,"setScop- nonzro"); 111 m_scope = scope; 112 } 113 114 115 119 public final ExportScope getScope() 120 { 121 return m_scope; 122 } 123 124 125 130 public void setReference(String refid) 131 { 132 require_(refid!=null, "setRef- nonzro refid"); 133 checkNewCopyTarget(); 134 m_value.set(refid); 135 m_value.setIsReference(true); 136 } 137 138 139 142 public void execute() 143 { 144 verifyCanExecute_("execute"); 145 146 if (testIfCondition() && testUnlessCondition()) { 147 String what = getMsg(); 148 String key = m_value.get(); 149 Project P = getProject(); 150 151 if (m_value.isProperty()) { 152 if (ExportScope.ALL.equals(getScope())) { 153 P.setInheritedProperty(key,what); 154 } else { 155 P.setNewProperty(key,what); 156 } 157 } 158 else if (m_value.isExported()) { 159 ExportScope.setTheProperty(getScope(),P, key,what,false); 160 } 161 else if (m_value.isReference()) { 162 P.addReference(key,what); 163 } 164 } 165 } 166 167 168 173 protected void verifyCanExecute_(String calr) 174 { 175 super.verifyCanExecute_(calr); 176 177 String ermsg = null; 178 if (m_value.isLiteral()) { 179 ermsg = uistrs().get("task.needs.this.attr", getTaskName(), 180 "property|reference|variable"); 181 } else if (getMsgId()==null && getDefaultMsg().length()==0) { 182 ermsg = uistrs().get("task.needs.this.attr", getTaskName(), 183 "msgid|message"); 184 } 185 if (ermsg!=null) { 186 log(ermsg,Project.MSG_ERR); 187 throw new BuildException(ermsg,getLocation()); 188 } 189 } 190 191 192 197 private void checkNewCopyTarget() 198 { 199 if (m_copytargets>0) { 200 String ermsg = uistrs().get("task.too.many.flex.attrs"); 201 log(ermsg,Project.MSG_ERR); 202 throw new BuildException(ermsg,getLocation()); 203 } 204 m_copytargets++; 205 } 206 207 208 private FlexString m_value = new FlexString(); 209 private ExportScope m_scope = ExportScope.DEFAULT_SCOPE; 210 private int m_copytargets; 211 } 212 213 214 | Popular Tags |