package refactoring.struts; import java.util.List; import net.sourceforge.fenixedu.util.StringUtils; import org.apache.struts.config.ExceptionConfig; public class ExceptionsCreator { public static String createException(final ExceptionConfig exceptionConfig) { StringBuilder sourceCode = new StringBuilder(); final String exceptionHandler = exceptionConfig.getHandler(); final String messageKey = exceptionConfig.getKey(); final String exceptionTypeName = exceptionConfig.getType(); sourceCode.append("@ExceptionHandling("); if (!StringUtils.isEmpty(exceptionTypeName)) { sourceCode.append("type = " + exceptionTypeName + ".class"); } else { throw new RuntimeException("Struts refactoring: an Exception handler had no exception type"); } if (!StringUtils.isEmpty(messageKey)) { sourceCode.append(", key = " + messageKey); } if (!StringUtils.isEmpty(exceptionHandler)) { sourceCode.append(", handler = " + exceptionHandler + ".class"); } sourceCode.append(")"); return sourceCode.toString(); } public static String createExceptionsAnnotation(final List exceptionsList) { StringBuilder sourceCode = new StringBuilder(); sourceCode.append("@Exceptions( {"); sourceCode.append("\n"); int i; for (i = 0; i < (exceptionsList.size() - 1); i++) { sourceCode.append(exceptionsList.get(i)); sourceCode.append("," + "\n"); } sourceCode.append(exceptionsList.get(i)); sourceCode.append("\n" + "} )"); return sourceCode.toString(); } }