package refactoring.struts; import java.util.List; import org.apache.struts.config.ForwardConfig; public class ForwardCreator { public static String createForward(ForwardConfig forwardConfig) { StringBuilder sourceCode = new StringBuilder(); sourceCode.append("@Forward( "); String name = forwardConfig.getName(); String path = forwardConfig.getPath(); Boolean redirect = forwardConfig.getRedirect(); Boolean contextRelative = forwardConfig.getContextRelative(); sourceCode.append("name = " + name); sourceCode.append(", path = " + path); if (redirect) { sourceCode.append(", redirect = " + redirect); } if (contextRelative) { sourceCode.append(", contextRelative = " + contextRelative); } sourceCode.append(")"); return sourceCode.toString(); } public static String createForwards(List forwards) { StringBuilder sourceCode = new StringBuilder(); sourceCode.append("@Forwards( {"); sourceCode.append("\n"); int i; for (i = 0; i < (forwards.size() - 1); i++) { sourceCode.append(forwards.get(i)); sourceCode.append("," + "\n"); } sourceCode.append(forwards.get(i)); sourceCode.append("\n" + "} )"); return sourceCode.toString(); } }