I'm working on an old Struts application which has an abstract action to create Excel exports by filling Excel template files. Each Excel export action extends this parent class and adds its own implementation for filling the Excel template and defines its own template and output filename.
public abstract class ExcelExport extends BaseAction {
protected abstract String getInputFilename();
protected abstract String getOutputFilename();
protected abstract HSSFWorkbook modifyWorkbook(HSSFWorkbook workbook, HttpServletRequest request);
@Override
protected final ActionForward run(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception {
Workbook workbook = new Workbook(getInputFilename());
workbook = modifyWorkbook(workbook, request);
addWorkBookToResponse(workbook, getOutputFilename());
return null;
}
...
}
Implementations are looking like this and this is where the code duplications come from:
public class BudgetReportExcelAction extends ExcelExport {
private static final String INPUT_FILENAME = "Report-Budget-Template.xls";
private final static String OUTPUT_FILENAME = "Report-Customerbudget.xls";
@Override
protected String getInputFilename() {
return INPUT_FILENAME;
}
@Override
protected String getOutputFilename() {
return OUTPUT_FILENAME;
}
@Override
protected HSSFWorkbook modifyWorkbook(HSSFWorkbook workbook, HttpServletRequest request) {
/* modify the workbook */
return workbook;
}
}
Any ideas how to avoid the duplications?
Aucun commentaire:
Enregistrer un commentaire