134 helper.reportError("The string \"" + trArg + "\" is not a " + 135 "valid translate pattern"); 136 return; 137 } 138 139 // Extract relevant parts 140 String suffix = m.group("suffix"); 141 String classname = m.group("class"); 142 String extra = m.group("extra"); 143 144 // Valid suffix? 145 if (suffix.matches("\\.(class|java)")) { 146 helper.reportError("You cannot have a translator for " + 147 suffix + " files!"); 148 return; 149 } 150 151 // Construct transformer 152 try { 153 Class<?> trCls = Class.forName(classname); 154 @SuppressWarnings("deprecation") 155 Transformer transformer = (Transformer) trCls.newInstance(); 156 transformer.setExtra(extra); 157 helper.addTransformer(suffix, transformer); 158 } catch (Exception e) { 159 helper.reportError("Cannot use " + classname + 160 " as a translator: " + e.getMessage()); 161 } 162 } 163 }, 164 COPY("-copy", "Copy resources") { 165 @Override 166 protected void processMatching(ArgumentIterator iter, OptionHelper helper) { 167 if (!iter.hasNext()) { 168 helper.reportError(arg + " must be followed by a resource type"); 169 return; 170 } 171 172 String copyArg = iter.next(); 173 174 // Validate argument syntax. Examples: .gif, .html 175 if (!copyArg.matches("\\.[a-zA-Z_][a-zA-Z0-9_]*")) { | 134 helper.reportError("The string \"" + trArg + "\" is not a " + 135 "valid translate pattern"); 136 return; 137 } 138 139 // Extract relevant parts 140 String suffix = m.group("suffix"); 141 String classname = m.group("class"); 142 String extra = m.group("extra"); 143 144 // Valid suffix? 145 if (suffix.matches("\\.(class|java)")) { 146 helper.reportError("You cannot have a translator for " + 147 suffix + " files!"); 148 return; 149 } 150 151 // Construct transformer 152 try { 153 Class<?> trCls = Class.forName(classname); 154 Transformer transformer = 155 (Transformer) trCls.getConstructor(new Class<?>[0]).newInstance((Object[])null); 156 transformer.setExtra(extra); 157 helper.addTransformer(suffix, transformer); 158 } catch (Exception e) { 159 helper.reportError("Cannot use " + classname + 160 " as a translator: " + e.getMessage()); 161 } 162 } 163 }, 164 COPY("-copy", "Copy resources") { 165 @Override 166 protected void processMatching(ArgumentIterator iter, OptionHelper helper) { 167 if (!iter.hasNext()) { 168 helper.reportError(arg + " must be followed by a resource type"); 169 return; 170 } 171 172 String copyArg = iter.next(); 173 174 // Validate argument syntax. Examples: .gif, .html 175 if (!copyArg.matches("\\.[a-zA-Z_][a-zA-Z0-9_]*")) { |