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.*;
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
*/
public class CMSMappingsConfiguratorGenerator extends AbstractGenerator{
/**
* Type op operation for dialogs.
* @author lrosenberg
*
*/
private static enum OperationType{
SINGLE,
MULTIPLE_DIALOG,
}
public static 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),
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 List generate(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;
}
public static String getClassSimpleName(){
return "CMSMappingsConfigurator";
}
public static String getClassName(){
return getPackageName() + "." + getClassSimpleName();
}
private GeneratedClass generateCMSMapping(List views){
GeneratedClass clazz = new GeneratedClass();
startNewJob(clazz);
clazz.setPackageName(getPackageName());
clazz.addImport(Map.class);
clazz.addImport(HashMap.class);
clazz.addImport("net.anotheria.maf.action.ActionForward");
clazz.addImport("net.anotheria.maf.action.ActionMappings");
clazz.addImport("net.anotheria.maf.action.ActionMappingsConfigurator");
clazz.addImport(IndexPageActionGenerator.getIndexPageFullName());
clazz.addInterface("ActionMappingsConfigurator");
clazz.setName(getClassSimpleName());
startClassBody();
emptyline();
appendString("private static final Map showActionsRegistry;");
appendString("static{");
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");
openFun("public static String getActionPath(String parentName, String documentName)");
appendStatement("return showActionsRegistry.get(parentName + \".\" + documentName)");
closeBlock("getActionPath");
appendString("@Override");
openFun("public void configureActionMappings(ActionMappings mappings)");
appendStatement("mappings.addMapping(\"index\", " + IndexPageActionGenerator.getIndexPageActionName() + ".class, new ActionForward(\"success\", "+quote(IndexPageJspGenerator.getIndexJspFullName())+"))");
appendStatement("mappings.addMapping(\"fileShow\", "+quote(ShowFile.class.getName())+", new ActionForward(\"success\", \"/net/anotheria/webutils/jsp/UploadFile.jsp\"))");
appendStatement("mappings.addMapping(\"fileUpload\", "+quote(FileAjaxUpload.class.getName())+")");
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 ActionForward(\"success\", \"/net/anotheria/anosite/cms/jsp/Login.jsp\"))");
appendStatement("mappings.addMapping(\"logout\", net.anotheria.anosite.cms.action.LogoutAction.class, new ActionForward(\"success\", \"/net/anotheria/anosite/cms/jsp/Login.jsp\"))");
appendStatement("mappings.addMapping(\"changePass\", net.anotheria.anosite.cms.action.ChangePassAction.class, new ActionForward(\"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;
// if(s.getDialogs().size() == 0)
// continue;
appendCommentLine("Mapping " + s.getDocument().getName());
generateSectionMappings(clazz, s);
emptyline();
MetaDocument doc = s.getDocument();
for (int p=0; p
© 2015 - 2025 Weber Informatics LLC | Privacy Policy