package refactoring.struts; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStreamReader; import java.nio.charset.Charset; import org.apache.struts.config.ActionConfig; import refactoring.struts.beans.MappingAnnotationBean; public class ActionMappingCreator { public static final String FENIX_SRC_BASE_FOLDER = "/home/nmld/runtime-EclipseApplication/fenix-mod-struts/src/"; public static MappingAnnotationBean createActionMapping(String moduleName, ActionConfig actionConfig, LogMissingDispatchAction missingLog) throws Exception { String input = actionConfig.getInput(); String name = actionConfig.getName(); String attribute = actionConfig.getAttribute(); String path = actionConfig.getPath(); String scope = actionConfig.getScope(); String type = actionConfig.getType(); boolean validate = actionConfig.getValidate(); String parameter = actionConfig.getParameter(); if (emptyString(type)) { missingLog.addNamelessMapping(actionConfig); return null; } if (actionConfig.getForward() != null) { // System.out.println("###### Single forward in mapping: " + // actionConfig.getForward()); // System.out.println("######"); missingLog.logSingleForward(type, actionConfig); return null; } String dispatchActionFileName = new String(FENIX_SRC_BASE_FOLDER + type.replace('.', '/') + ".java"); FileInputStream fis; InputStreamReader isr = null; StringBuilder dispatchActionSourceCode = new StringBuilder(); try { fis = new FileInputStream(new File(dispatchActionFileName)); isr = new InputStreamReader(fis, Charset.forName("ISO-8859-1")); while (isr.ready()) { dispatchActionSourceCode.append((char) isr.read()); } } catch (FileNotFoundException e) { missingLog.logMapping(type, actionConfig); return null; } finally { if (isr != null) { isr.close(); } } MappingAnnotationBean mappingBean = new MappingAnnotationBean(); if (dispatchActionSourceCode.toString().contains("@Mapping") || dispatchActionSourceCode.toString().contains("@Forward")) { /* * In these situations we will want to create a new class extending * this DA file, with this Mapping and respective forwards */ missingLog.logAlreadyContainsMapping(mappingBean); mappingBean.setDAalreadyContainsMapping(true); } mappingBean.setModule(moduleName); mappingBean.setInput(input); mappingBean.setFormBean(name); mappingBean.setAttribute(attribute); mappingBean.setPath(path); mappingBean.setScope(scope); mappingBean.setDispatchActionClassName(type); mappingBean.setValidate(validate); mappingBean.setParameter(parameter); // mappingBean.setCustomMappingClass(customMappingClass); // mappingBean.setCustomMappingProperties(customMappingProperties); // mappingBean.setFormBeanClass(formBeanClass); return mappingBean; } private static boolean emptyString(String str) { if (str == null) { return true; } if (str.isEmpty()) { return true; } return false; } /* * The className parameter in the config files is the actual subclass of * ActionMapping that this ActionConfig will have. The properties are * initialized in it when it is instantiated by the RuleSet of the Digester. * Thus we will have to manually put the following annotations in the right * dispatch action files: * * From struts-departmentAdmOffice.xml: * * * * * * * * File: * net.sourceforge.fenixedu.presentationTier.Action.framework.SearchAction * -- not customMappingClass = * net.sourceforge.fenixedu.presentationTier.mapping.framework * .SearchActionMapping.class customMappingProperties = { "serviceName", * "FindPersonService", "objectAttribute", "infoPerson", "listAttribute", * "infoPersonList", "notFoundMessageKey", "errors.teacher.not.found" } * * * * * File: * net.sourceforge.fenixedu.presentationTier.Action.framework.SearchAction * -- not customMappingClass = * net.sourceforge.fenixedu.presentationTier.mapping.framework * .SearchActionMapping.class customMappingProperties = { "serviceName", * "FindTeachersServiceForDepartmentOffice", "objectAttribute", * "infoTeacher", "notFoundMessageKey", "errors.teacher.not.found" } * ----------------------------------------------- * * From struts-facultyAdmOffice.xml: * * * * * * * File: net.sourceforge.fenixedu.presentationTier.Action.grant.owner. -- ok * SearchGrantOwnerAction customMappingClass = * net.sourceforge.fenixedu.presentationTier.mapping.framework * .SearchActionMapping.class customMappingProperties = { "serviceName", * "SearchGrantOwner", "objectAttribute", "infoGrantOwner", "listAttribute", * "infoGrantOwnerList", "notFoundMessageKey", "errors.person.not.found" } * ----------------------------------------------- * * From struts-gep.xml: * * * * * * * File: net.sourceforge.fenixedu.presentationTier.Action.gep. -- not * SearchTeachersInformationAction customMappingClass = * net.sourceforge.fenixedu.presentationTier.mapping.framework * .SearchActionMapping.class customMappingProperties = { "serviceName", * "ReadTeachersInformation", "objectAttribute", * "infoSiteTeacherInformation", "listAttribute", * "infoSiteTeachersInformation", "notFoundMessageKey", "label.gep.notFound" * } * * * * * * * File: net.sourceforge.fenixedu.presentationTier.Action.gep. -- not * SearchCoursesInformationAction customMappingClass = * net.sourceforge.fenixedu.presentationTier.mapping.framework * .SearchActionMapping.class customMappingProperties = { "serviceName", * "ReadCoursesInformation", "objectAttribute", "infoSiteCourseInformation", * "listAttribute", "infoSiteCoursesInformation", "notFoundMessageKey", * "label.gep.notFound" } * * * * * * * File: net.sourceforge.fenixedu.presentationTier.Action.gep. -- not * SearchCoursesInformationAction customMappingClass = * net.sourceforge.fenixedu.presentationTier.mapping.framework * .SearchActionMapping.class customMappingProperties = { "serviceName", * "ReadCoursesInformation", "objectAttribute", "infoSiteCourseInformation", * "listAttribute", "infoSiteCoursesInformation", "notFoundMessageKey", * "label.gep.notFound" } * * * * * * * File: net.sourceforge.fenixedu.presentationTier.Action.gep. -- not * SearchCoursesInformationAction customMappingClass = * net.sourceforge.fenixedu.presentationTier.mapping.framework * .SearchActionMapping.class customMappingProperties = { "serviceName", * "ReadCoursesInformation", "objectAttribute", "infoSiteCourseInformation", * "listAttribute", "infoSiteCoursesInformation", "notFoundMessageKey", * "label.gep.notFound" } * * * * * * * File: net.sourceforge.fenixedu.presentationTier.Action.gep. -- not * SearchCoursesInformationAction customMappingClass = * net.sourceforge.fenixedu.presentationTier.mapping.framework * .SearchActionMapping.class customMappingProperties = { "serviceName", * "ReadCoursesInformation", "objectAttribute", "infoSiteCourseInformation", * "listAttribute", "infoSiteCoursesInformation", "notFoundMessageKey", * "label.gep.notFound" } * * * * * * * File: net.sourceforge.fenixedu.presentationTier.Action.gep. -- not * SearchTeachersInformationAction customMappingClass = * net.sourceforge.fenixedu.presentationTier.mapping.framework * .SearchActionMapping.class customMappingProperties = { "serviceName", * "ReadTeachersInformation", "objectAttribute", * "infoSiteTeacherInformation", "listAttribute", * "infoSiteTeachersInformation", "notFoundMessageKey", "label.gep.notFound" * } * * ---------------------------------------------- * * From struts-person.xml: * * * * * * * * File: * net.sourceforge.fenixedu.presentationTier.Action.person.QualificationAction * -- ok customMappingClass = * net.sourceforge.fenixedu.presentationTier.mapping.framework * .CRUDMapping.class customMappingProperties = { "editService", * "EditQualification", "deleteService", "DeleteQualification", * "readService", "ReadQualification", "oidProperty", "idInternal", * "requestAttribute", "infoQualification", "infoObjectClassName", * "infoObjectClassName" } * * ------------------------------------------------ * * From struts-teacher.xml: * * * * * * File: net.sourceforge.fenixedu.presentationTier.Action.teacher. -- not * TeacherAdministrationViewerDispatchAction customMappingClass = * net.sourceforge * .fenixedu.presentationTier.mapping.SiteManagementActionMapping.class * customMappingProperties = { "componentClassName", * "net.sourceforge.fenixedu.dataTransferObject.InfoSiteTeachers", * "inputForwardName", "viewTeachers", } * * * * * * * File: net.sourceforge.fenixedu.presentationTier.Action.teacher. -- not * TeacherAdministrationViewerDispatchAction customMappingClass = * net.sourceforge * .fenixedu.presentationTier.mapping.SiteManagementActionMapping.class * customMappingProperties = { "componentClassName", * "net.sourceforge.fenixedu.dataTransferObject.InfoSiteTeachers", * "inputForwardName", "associateTeacher" } * * * * * * File: net.sourceforge.fenixedu.presentationTier.Action.teacher. -- not * TeacherAdministrationViewerDispatchAction customMappingClass = * net.sourceforge * .fenixedu.presentationTier.mapping.SiteManagementActionMapping.class * customMappingProperties = { "componentClassName", * "net.sourceforge.fenixedu.dataTransferObject.InfoSiteRootSections", * "inputForwardName", "createSection" } * * * * * * * File: * net.sourceforge.fenixedu.presentationTier.Action.framework.CRUDActionByOID * -- not customMappingClass = * net.sourceforge.fenixedu.presentationTier.mapping.framework * .CRUDMapping.class customMappingProperties = { "editService", * "EditCareer", "deleteService", "DeleteCareer", "readService", * "ReadCareer", "oidProperty", "idInternal", "requestAttribute", * "infoProfessionalCareer", "infoObjectClassName", * "net.sourceforge.fenixedu.dataTransferObject.teacher.InfoProfessionalCareer" * } * * * * * * File: * net.sourceforge.fenixedu.presentationTier.Action.teacher.CareerAction -- * -- ok customMappingClass = * net.sourceforge.fenixedu.presentationTier.mapping.framework * .CRUDMapping.class customMappingProperties = { "editService", * "EditCareer", "deleteService", "DeleteCareer", "readService", * "ReadCareer", "oidProperty", "idInternal", "requestAttribute", * "infoTeachingCareer", "infoObjectClassName", * "net.sourceforge.fenixedu.dataTransferObject.teacher.InfoTeachingCareer" * } * * * * * * * * * File: * net.sourceforge.fenixedu.presentationTier.Action.framework.CRUDActionByOID * -- not customMappingClass = * net.sourceforge.fenixedu.presentationTier.mapping.framework * .CRUDMapping.class customMappingProperties = { "editService", * "EditExternalActivity", "deleteService", "DeleteExternalActivity", * "readService", "ReadExternalActivity", "oidProperty", "idInternal", * "requestAttribute", "infoExternalActivity", "infoObjectClassName", * "net.sourceforge.fenixedu.dataTransferObject.teacher.InfoExternalActivity" * } */ }