net.anotheria.asg.generator.view.CMSMappingsConfiguratorGenerator Maven / Gradle / Ivy
package net.anotheria.asg.generator.view; import net.anotheria.asg.generator.AbstractGenerator; import net.anotheria.asg.generator.FileEntry; import net.anotheria.asg.generator.GeneratedClass; import net.anotheria.asg.generator.GeneratorDataRegistry; import net.anotheria.asg.generator.forms.meta.MetaForm; import net.anotheria.asg.generator.meta.MetaContainerProperty; import net.anotheria.asg.generator.meta.MetaDocument; import net.anotheria.asg.generator.meta.MetaListProperty; import net.anotheria.asg.generator.meta.MetaModule; import net.anotheria.asg.generator.meta.MetaProperty; import net.anotheria.asg.generator.meta.MetaTableProperty; import net.anotheria.asg.generator.meta.StorageType; import net.anotheria.asg.generator.view.action.IndexPageActionGenerator; import net.anotheria.asg.generator.view.action.ModuleActionsGenerator; import net.anotheria.asg.generator.view.jsp.IndexPageJspGenerator; import net.anotheria.asg.generator.view.jsp.JspGenerator; import net.anotheria.asg.generator.view.meta.MetaDialog; import net.anotheria.asg.generator.view.meta.MetaModuleSection; import net.anotheria.asg.generator.view.meta.MetaSection; import net.anotheria.asg.generator.view.meta.MetaView; import net.anotheria.util.StringUtils; import net.anotheria.webutils.filehandling.actions.FileAjaxUpload; import net.anotheria.webutils.filehandling.actions.GetFile; import net.anotheria.webutils.filehandling.actions.ShowFile; import net.anotheria.webutils.filehandling.actions.ShowTmpFile; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * Generator class for the CMSFilter. * * @author dmetelin * @version $Id: $Id */ public class CMSMappingsConfiguratorGenerator extends AbstractGenerator{ /** * Type op operation for dialogs. * @author lrosenberg * */ private static enum OperationType{ SINGLE, MULTIPLE_DIALOG, } public enum SectionAction{ SHOW("Show", "Show", OperationType.SINGLE, true), EDIT("Edit", "Edit", OperationType.SINGLE), NEW("New", "Edit", OperationType.SINGLE), LINKSTOME("LinksToMe", "LinksTo", OperationType.SINGLE, false){ @Override public String getClassName(MetaModuleSection section){ return "Edit" + section.getDocument().getName() + "Action"; } @Override public String getViewName(MetaModuleSection section){ MetaDocument doc = section.getDocument(); return "LinksTo"+doc.getName(); } }, CLOSE("Close", "Show", OperationType.MULTIPLE_DIALOG), UPDATE("Update", "Show", OperationType.MULTIPLE_DIALOG), DELETE("Delete", "Show", OperationType.MULTIPLE_DIALOG), DUPLICATE("Duplicate", "Show", OperationType.MULTIPLE_DIALOG), PREVIEW("Preview", "Show", OperationType.MULTIPLE_DIALOG), LOCK("Lock", "EditBoxDialog", OperationType.MULTIPLE_DIALOG), UNLOCK("UnLock", "EditBoxDialog", OperationType.MULTIPLE_DIALOG), TRANSFER("Transfer", "Show", OperationType.SINGLE), COPYLANG("CopyLang", "EditBoxDialog", OperationType.MULTIPLE_DIALOG), SWITCHMULTILANG("SwitchMultilang", "EditBoxDialog", OperationType.MULTIPLE_DIALOG), VERSIONINFO("Versioninfo", "EditBoxDialog", OperationType.MULTIPLE_DIALOG), EXPORTtoCSV("Export.csv", "Show", OperationType.SINGLE, true){ @Override public String getClassName(MetaModuleSection section){ return "Export" + section.getDocument().getName(true) + "Action"; } @Override public String getViewName(MetaModuleSection section){ MetaDocument doc = section.getDocument(); return "Show"+doc.getName(true) + "AsCSV"; } }, EXPORTtoXML("Export.xml", "Show", OperationType.SINGLE, true){ @Override public String getClassName(MetaModuleSection section){ return "Export" + section.getDocument().getName(true) + "Action"; } @Override public String getViewName(MetaModuleSection section){ MetaDocument doc = section.getDocument(); return "Show"+doc.getName(true) + "AsXML"; } }, ; private String action; private String view; private OperationType type; private boolean multiDocument; private SectionAction(String anAction, String aView, OperationType aType) { this(anAction, aView, aType, false); } private SectionAction(String anAction, String aView, OperationType aType, boolean aListDocument) { action = anAction; view = aView; type = aType; multiDocument = aListDocument; } public String getClassName(MetaModuleSection section) { switch (type) { case SINGLE: return action + section.getDocument().getName(multiDocument) + "Action"; case MULTIPLE_DIALOG: return ModuleActionsGenerator.getMultiOpDialogActionName(section); } throw new AssertionError("Unsuported OperationType!"); } public String getMappingName(MetaModuleSection section){ return getMappingName(section.getDocument()); } public String getMappingName(MetaDocument doc){ return doc.getParentModule().getName().toLowerCase()+StringUtils.capitalize(doc.getName()) + action; } public String getViewName(MetaModuleSection section){ MetaDocument doc = section.getDocument(); return view+doc.getName(multiDocument); } public String getViewPath(MetaModuleSection section){ return "/" + FileEntry.package2path(JspGenerator.getPackage(section.getModule())) + "/"; } public String getViewFullName(MetaModuleSection section){ return getViewPath(section) + getViewName(section); } public boolean isIgnoreForSection(MetaModuleSection section){ return !multiDocument && (section.getDialogs().size() == 0 || StorageType.FEDERATION == section.getModule().getStorageType()); } } public static enum SharedAction{ //SHOW("Show", "Show", OperationType.SINGLE, true, false), SEARCH("CmsSearch", "SearchResult"){ // @Override // public String getViewName(MetaModuleSection section){ // return "SearchResultMaf"; // } // @Override // public String getViewPath(MetaModuleSection section){ // return "/" + FileEntry.package2path(GeneratorDataRegistry.getInstance().getContext().getPackageName(MetaModule.SHARED)+".jsp") + "/"; // } // @Override // public String getClassName(MetaModuleSection section){ // return "SearchMafAction"; // } }, ; private String action; private String view; private SharedAction(String anAction, String aView) { action = anAction; view = aView; } public String getClassName() { return action + "Action"; } public String getMappingName(){ return action.toLowerCase(); } public String getViewName(){ return view; } public String getViewPath(){ return "/" + FileEntry.package2path(GeneratorDataRegistry.getInstance().getContext().getPackageName(MetaModule.SHARED)+".jsp") + "/"; } public String getViewFullName(){ return getViewPath() + getViewName(); } public static final String getPackageName(){ return GeneratorDataRegistry.getInstance().getContext().getPackageName(MetaModule.SHARED)+".action"; } } public static enum ContainerAction{ SHOW("Show"), DELETE("Delete"), MOVE("Move"), ADD("Add"), QUICKADD("QuickAdd"), ; private String action; private ContainerAction(String anAction) { action = anAction; } public String getClassName(MetaDocument doc, MetaContainerProperty container) { return ModuleActionsGenerator.getContainerMultiOpActionName(doc, container); } public String getMappingName(MetaDocument doc, MetaContainerProperty container){ return doc.getParentModule().getName().toLowerCase()+StringUtils.capitalize(doc.getName())+StringUtils.capitalize(container.getName())+ action; } public String getViewName(MetaDocument doc, MetaContainerProperty container){ return JspGenerator.getContainerPageName(doc, container); } } /** *
*/ public static final String ACTION_VERSIONINFO = "versioninfo"; /** Constantgenerate.
* * @param views a {@link java.util.List} object. * @return a {@link java.util.List} object. */ public Listgenerate(List views) { List ret = new ArrayList (); try{ ret.add(new FileEntry(generateCMSMapping(views))); }catch(Exception e){ System.out.println("CMSMappingsConfiguratorGenerator error: " + e.getMessage()); e.printStackTrace(); } return ret; } /** * getClassSimpleName.
* * @return a {@link java.lang.String} object. */ public static String getClassSimpleName(){ return "CMSMappingsConfigurator"; } /** *getClassName.
* * @return a {@link java.lang.String} object. */ public static String getClassName(){ return getPackageName() + "." + getClassSimpleName(); } private GeneratedClass generateCMSMapping(Listviews){ GeneratedClass clazz = new GeneratedClass(); startNewJob(clazz); clazz.setPackageName(getPackageName()); clazz.addImport(Map.class); clazz.addImport(HashMap.class); clazz.addImport(net.anotheria.maf.action.CommandForward.class); clazz.addImport(net.anotheria.maf.action.ActionMappings.class); clazz.addImport(net.anotheria.maf.action.ActionMappingsConfigurator.class); clazz.addImport(IndexPageActionGenerator.getIndexPageFullName()); clazz.addImport("net.anotheria.anosite.cms.action.LocalizationBundleExportMafAction"); clazz.addImport("net.anotheria.anosite.cms.action.LocalizationBundleImportMafAction"); clazz.addImport("net.anotheria.anosite.cms.action.LocalizationBundleExportToTxtAction"); clazz.addImport("net.anotheria.anosite.cms.action.LocalizationBundleMakeParentsMafAction"); clazz.addImport("net.anotheria.anosite.cms.action.LocalizationBundleTranslationMafAction"); clazz.addImport("net.anotheria.anosite.cms.action.LocalizationBundleSpecificTranslationMafAction"); clazz.addImport("net.anotheria.anosite.cms.action.LocalizationBundlesDifferenceMafAction"); clazz.addInterface("ActionMappingsConfigurator"); clazz.setName(getClassSimpleName()); startClassBody(); emptyline(); appendString("private static final Map showActionsRegistry;"); appendString("static{"); increaseIdent(); appendStatement("showActionsRegistry = new HashMap ()"); for(MetaView view: views){ for (MetaSection section: view.getSections()){ if (!(section instanceof MetaModuleSection)) continue; MetaModuleSection s = (MetaModuleSection)section; generateActionsRegistry(s); } } closeBlock("close static block"); emptyline(); openFun("public static String getActionPath(String parentName, String documentName)"); appendStatement("return showActionsRegistry.get(parentName + \".\" + documentName)"); closeBlock("getActionPath"); emptyline(); appendString("@Override"); openFun("public void configureActionMappings(ActionMappings mappings)"); appendStatement("mappings.addMapping(\"index\", " + IndexPageActionGenerator.getIndexPageActionName() + ".class, new CommandForward(\"success\", "+quote(IndexPageJspGenerator.getIndexJspFullName())+"))"); appendStatement("mappings.addMapping(\"asgLocalizationBundleExportView\", net.anotheria.anosite.cms.action.LocalizationBundleExportMafAction.class, new CommandForward(\"success\", \"/net/anotheria/anosite/cms/jsp/LocalizationBundleExport.jsp\"))"); appendStatement("mappings.addMapping(\"asgLocalizationBundleImportView\", net.anotheria.anosite.cms.action.LocalizationBundleImportMafAction.class, new CommandForward(\"success\", \"/net/anotheria/anosite/cms/jsp/LocalizationBundleImport.jsp\"))"); appendStatement("mappings.addMapping(\"asgLocalizationBundleMakeParentsView\", net.anotheria.anosite.cms.action.LocalizationBundleMakeParentsMafAction.class, new CommandForward(\"success\", \"/net/anotheria/anosite/cms/jsp/LocalizationBundleMakeParents.jsp\"))"); appendStatement("mappings.addMapping(\"asgLocalizationBundleTranslationView\", net.anotheria.anosite.cms.action.LocalizationBundleTranslationMafAction.class, new CommandForward(\"success\", \"/net/anotheria/anosite/cms/jsp/LocalizationBundleTranslation.jsp\"))"); appendStatement("mappings.addMapping(\"asgLocalizationBundleSpecificTranslationView\", net.anotheria.anosite.cms.action.LocalizationBundleSpecificTranslationMafAction.class, new CommandForward(\"success\", \"/net/anotheria/anosite/cms/jsp/LocalizationBundleSpecificTranslation.jsp\"))"); appendStatement("mappings.addMapping(\"asgLocalizationBundlesDifferenceView\", net.anotheria.anosite.cms.action.LocalizationBundlesDifferenceMafAction.class, new CommandForward(\"success\", \"/net/anotheria/anosite/cms/jsp/LocalizationBundlesDifference.jsp\"))"); appendStatement("mappings.addMapping(\"fileShow\", "+quote(ShowFile.class.getName())+", new CommandForward(\"success\", \"/net/anotheria/webutils/jsp/UploadFile.jsp\"))"); appendStatement("mappings.addMapping(\"fileUpload\", "+quote(FileAjaxUpload.class.getName())+")"); appendStatement("mappings.addMapping(\"exportLocalizationBundlesToTxt\", net.anotheria.anosite.cms.action.LocalizationBundleExportToTxtAction.class)"); appendStatement("mappings.addMapping(\"showTmpFile\", "+quote(ShowTmpFile.class.getName())+")"); appendStatement("mappings.addMapping(\"getFile\", "+quote(GetFile.class.getName())+")"); appendStatement("mappings.addMapping(\"login\", net.anotheria.anosite.cms.action.LoginAction.class, new CommandForward(\"success\", \"/net/anotheria/anosite/cms/jsp/Login.jsp\"))"); appendStatement("mappings.addMapping(\"logout\", net.anotheria.anosite.cms.action.LogoutAction.class, new CommandForward(\"success\", \"/net/anotheria/anosite/cms/jsp/Login.jsp\"))"); appendStatement("mappings.addMapping(\"changePass\", net.anotheria.anosite.cms.action.ChangePassAction.class, new CommandForward(\"success\", \"/net/anotheria/anosite/cms/jsp/ChangePass.jsp\"))"); appendStatement("mappings.addMapping(\"showUsages\", net.anotheria.anosite.bredcrambs.action.ShowUsagesOfDocumentAction.class)"); generateSharedMappings(clazz); for (MetaView view: views) { for (MetaSection section: view.getSections()) { if (!(section instanceof MetaModuleSection)) continue; MetaModuleSection s = (MetaModuleSection) section; appendStatement("configureActionMappings" + s.getDocument().getName() + "(mappings)"); } } closeBlock("configureActionMappings"); emptyline(); for(MetaView view: views){ for (MetaSection section: view.getSections()){ if (!(section instanceof MetaModuleSection)) continue; MetaModuleSection s = (MetaModuleSection)section; // if(s.getDialogs().size() == 0) // continue; openFun("private void configureActionMappings" + s.getDocument().getName() + "(ActionMappings mappings)"); generateSectionMappings(clazz, s); emptyline(); MetaDocument doc = s.getDocument(); for (int p=0; p ACTION_VERSIONINFO="versioninfo" ACTION_DUPLICATE="duplicate"
*/ public static final String ACTION_DUPLICATE = "duplicate"; /** ConstantACTION_DEEPCOPY="deepcopy"
*/ public static final String ACTION_DEEPCOPY = "deepcopy"; /** ConstantACTION_ADD="add"
*/ public static final String ACTION_ADD = "add"; /** ConstantACTION_QUICK_ADD="quickAdd"
*/ public static final String ACTION_QUICK_ADD = "quickAdd"; /** ConstantACTION_EXPORT="export"
*/ public static final String ACTION_EXPORT = "export"; /** ConstantACTION_SHOW_QUERIES="showQueries"
*/ public static final String ACTION_SHOW_QUERIES = "showQueries"; /** ConstantACTION_EXECUTE_QUERY="execQuery"
*/ public static final String ACTION_EXECUTE_QUERY = "execQuery"; /** ConstantACTION_LINKS_TO_ME="LinksToMe"
*/ public static final String ACTION_LINKS_TO_ME = "LinksToMe"; /** ConstantACTION_MOVE="move"
*/ public static final String ACTION_MOVE = "move"; /** ConstantACTION_SEARCH="search"
*/ public static final String ACTION_SEARCH = "search"; /** ConstantACTION_COPY_LANG="copyLang"
*/ public static final String ACTION_COPY_LANG ="copyLang"; /** ConstantACTION_SWITCH_MULTILANGUAGE_INSTANCE="switchMultilang"
*/ public static final String ACTION_SWITCH_MULTILANGUAGE_INSTANCE = "switchMultilang"; /** * show usages of an element. */ public static final String ACTION_SHOW_USAGES = "showUsages"; /** * Locks current document. */ public static final String ACTION_LOCK = "lock"; /** * Unlocks current document. */ public static final String ACTION_UNLOCK = "unLock"; /** ConstantACTION_CLOSE="close"
*/ public static final String ACTION_CLOSE = "close"; /** * Transfers current document to prod. */ public static final String ACTION_TRANSFER = "transfer"; /** *getPath.
* * @param doc a {@link net.anotheria.asg.generator.meta.MetaDocument} object. * @param action a {@link java.lang.String} object. * @return a {@link java.lang.String} object. */ public static final String getPath(MetaDocument doc, String action){ return doc.getParentModule().getName().toLowerCase()+StringUtils.capitalize(doc.getName())+StringUtils.capitalize(action); } /** *getShowQueriesPath.
* * @param doc a {@link net.anotheria.asg.generator.meta.MetaDocument} object. * @return a {@link java.lang.String} object. */ public static String getShowQueriesPath(MetaDocument doc){ return getPath(doc, ACTION_SHOW_QUERIES); } /** *getShowCMSPath.
* * @param doc a {@link net.anotheria.asg.generator.meta.MetaDocument} object. * @return a {@link java.lang.String} object. */ public static String getShowCMSPath(MetaDocument doc){ return getPath(doc, ACTION_SHOW); } /** *getDialogFormName.
* * @param dialog a {@link net.anotheria.asg.generator.view.meta.MetaDialog} object. * @param document a {@link net.anotheria.asg.generator.meta.MetaDocument} object. * @return a {@link java.lang.String} object. */ public static final String getDialogFormName(MetaDialog dialog, MetaDocument document) { return dialog.getName() + document.getParentModule().getName() + document.getName() + "Form"; } /** *getContainerPath.
* * @param doc a {@link net.anotheria.asg.generator.meta.MetaDocument} object. * @param container a {@link net.anotheria.asg.generator.meta.MetaContainerProperty} object. * @param action a {@link java.lang.String} object. * @return a {@link java.lang.String} object. */ public static final String getContainerPath(MetaDocument doc, MetaContainerProperty container, String action){ return doc.getParentModule().getName().toLowerCase()+StringUtils.capitalize(doc.getName())+StringUtils.capitalize(container.getName())+StringUtils.capitalize(action); } /** *getFormName.
* * @param form a {@link net.anotheria.asg.generator.forms.meta.MetaForm} object. * @return a {@link java.lang.String} object. */ public static String getFormName(MetaForm form){ return StringUtils.capitalize(form.getId())+"AutoForm"; } /** *getFormPath.
* * @param form a {@link net.anotheria.asg.generator.forms.meta.MetaForm} object. * @return a {@link java.lang.String} object. */ public static String getFormPath(MetaForm form){ return form.getId()+StringUtils.capitalize(form.getAction()); } /** *getExecuteQueryPath.
* * @param doc a {@link net.anotheria.asg.generator.meta.MetaDocument} object. * @return a {@link java.lang.String} object. */ public static String getExecuteQueryPath(MetaDocument doc){ return getPath(doc, ACTION_EXECUTE_QUERY); } /** *getContainerEntryFormName.
* * @param doc a {@link net.anotheria.asg.generator.meta.MetaDocument} object. * @param property a {@link net.anotheria.asg.generator.meta.MetaContainerProperty} object. * @return a {@link java.lang.String} object. */ public static final String getContainerEntryFormName(MetaDocument doc, MetaContainerProperty property){ String nameAddy = "XXX"; if (property instanceof MetaTableProperty) nameAddy = "Row"; if (property instanceof MetaListProperty) nameAddy = "Element"; return doc.getParentModule().getName().toLowerCase()+StringUtils.capitalize(doc.getName())+StringUtils.capitalize(property.getName())+nameAddy+"Form"; } /** *getContainerQuickAddFormName.
* * @param doc a {@link net.anotheria.asg.generator.meta.MetaDocument} object. * @param property a {@link net.anotheria.asg.generator.meta.MetaContainerProperty} object. * @return a {@link java.lang.String} object. */ public static final String getContainerQuickAddFormName(MetaDocument doc, MetaContainerProperty property){ String nameAddy = "XXX"; if (property instanceof MetaListProperty) nameAddy = "QuickAdd"; return doc.getParentModule().getName().toLowerCase()+StringUtils.capitalize(doc.getName())+StringUtils.capitalize(property.getName())+nameAddy+"Form"; } //TODO: end }