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;
public class ActionMappingCreator {
private static final String FENIX_SRC_BASE_FOLDER = "../fenix/src/";
public static void createActionMapping(String moduleName, ActionConfig actionConfig, LogMissingDispatchAction missingLog)
throws Exception {
// unused String attribute = actionConfig.getAttribute();
// unused String include = actionConfig.getInclude();
// unused String multipartClass = actionConfig.getMultipartClass();
// unused String roles = actionConfig.getRoles();
// unused String suffix = actionConfig.getSuffix();
/*
* FIXME cases like this: from the struts-default.xml
*/
// possibly a problem? String forward = actionConfig.getForward();
// unused String prefix = actionConfig.getPrefix();
// always the same? String parameter = actionConfig.getParameter();
String input = actionConfig.getInput();
String name = actionConfig.getName();
String path = actionConfig.getPath();
String scope = actionConfig.getScope();
String type = actionConfig.getType();
boolean validate = actionConfig.getValidate();
if (emptyString(type)) {
return;
}
StringBuilder mappingAnnotation = new StringBuilder();
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(dispatchActionFileName, actionConfig);
} finally {
if (isr != null) {
isr.close();
}
}
mappingAnnotation.append("@Mapping(");
if (!emptyString(moduleName)) {
mappingAnnotation.append("module = " + moduleName + ", ");
}
if (!emptyString(path)) {
mappingAnnotation.append("path = " + path + ", ");
}
if (!emptyString(input)) {
mappingAnnotation.append("input = " + input + ", ");
}
if (!emptyString(name)) {
mappingAnnotation.append("formBean = " + name + ", ");
}
if (!emptyString(scope)) {
mappingAnnotation.append("scope = " + scope + ", ");
}
mappingAnnotation.append("validate = " + validate);
mappingAnnotation.append(")");
// System.out.println(mappingAnnotation.toString());
if (dispatchActionSourceCode.toString().contains("@Mapping")) {
/*
* In these situations we will want to create a new class extending
* this DA file, with this Mapping and respective forwards
*/
DispatchActionCreator.createDispatchAction(moduleName, type);
}
}
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
* 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
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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
* 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.
* 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.
* 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.
* 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
* 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
* 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
* 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"
* }
*/
}