Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
net.anotheria.asg.generator.view.jsp.DialogPageJspGenerator Maven / Gradle / Ivy
package net.anotheria.asg.generator.view.jsp;
import net.anotheria.asg.data.LockableObject;
import net.anotheria.asg.generator.GeneratedJSPFile;
import net.anotheria.asg.generator.GeneratorDataRegistry;
import net.anotheria.asg.generator.meta.*;
import net.anotheria.asg.generator.view.CMSMappingsConfiguratorGenerator;
import net.anotheria.asg.generator.view.action.ModuleBeanGenerator;
import net.anotheria.asg.generator.view.meta.*;
import net.anotheria.util.StringUtils;
import java.util.ArrayList;
import java.util.List;
/**
* Generates the jsps for the edit view.
*
* @author another
*/
public class DialogPageJspGenerator extends AbstractJSPGenerator {
/**
* Currently generated section.
*/
private MetaSection currentSection;
/**
* Currently generated dialog.
*/
private MetaDialog currentDialog;
/**
* Is need render JS for enabling DateTime widgets.
*/
private boolean isNeedEnableDateTimeWidgets = false;
public GeneratedJSPFile generate(MetaSection metaSection, MetaDialog dialog, MetaModuleSection section, MetaView view) {
this.currentSection = metaSection;
this.currentDialog = dialog;
GeneratedJSPFile jsp = new GeneratedJSPFile();
startNewJob(jsp);
jsp.setName(getDialogName(dialog, section.getDocument()));
jsp.setPackage(getContext().getJspPackageName(section.getModule()));
resetIdent();
currentDialog = dialog;
append(getBaseJSPHeader());
appendGenerationPoint("generateDialog");
appendString("");
appendString("");
increaseIdent();
appendString("");
increaseIdent();
appendString("" + dialog.getTitle() + " ");
generatePragmas(view);
// appendString(" ");
// *** CMS2.0 START ***
appendString(" ");
appendString(" ");
appendString(" ");
appendString(" ");
appendString(" ");
// appendString(" ");
appendString(" ");
appendString("");
appendString("");
appendString("");
appendString("");
appendString("");
// appendString("");
appendString("");
appendString("");
appendString("");
appendString("");
// *** CMS2.0 FINISH ***
// *** CMS3.0 START ***
// appendString("");
// appendString("");
// appendString("");
appendString("");
// appendString("");
appendString("");
appendString("");
appendString("");
appendString("");
appendString("");
appendString("");
// *** CMS3.0 FINISH ***
if(dialog.getJavascript() != null) {
appendString("");
}
decreaseIdent();
appendString("");
appendString("");
appendString("");
appendString("");
appendString("
");
increaseIdent();
appendString("
");
increaseIdent();
appendString("
");
appendString("
");
appendString("
");
increaseIdent();
appendString("
");
increaseIdent();
appendString("Scroll to: ");
List elements = createMultilingualList(dialog.getElements(), section.getDocument());
for (int i = 0; i < elements.size(); i++) {
MetaViewElement element = elements.get(i);
while (elements.get(i) instanceof MultilingualFieldElement) {
String caption = element.getCaption() != null ? element.getCaption() : element.getName();
appendString("");
//please don't add any style to this tag - JS validation can remove it
appendString("" + caption + " ");
appendString(" ");
appendString("");
appendString("");
increaseIdent();
String lang = getElementLanguage(element);
String nameWithLang = section.getDocument().getField(element.getName()).getName(lang);
//please don't add any style to this tag - JS validation can remove it
appendString(" " + caption
+ " ");
appendString("");
increaseIdent();
appendString("
");
increaseIdent();
appendString("
");
decreaseIdent();
appendString("
");
appendString("
");
increaseIdent();
appendString("
");
increaseIdent();
appendString("
");
increaseIdent();
appendString("
");
for (String sl : GeneratorDataRegistry.getInstance().getContext().getLanguages()) {
appendString(""
+ sl + " ");
i++;
element = elements.get(i);
}
appendString(" ");
decreaseIdent();
appendString("
");
decreaseIdent();
appendString("
");
decreaseIdent();
appendString("
");
appendString("
");
appendString("
");
appendString("
");
decreaseIdent();
appendString("
");
decreaseIdent();
appendString(" ");
appendString(" ");
}
if (element instanceof MetaFieldElement) {
String caption = element.getCaption() != null ? element.getCaption() : element.getName();
//please don't add any style to this tag - JS validation can remove it
appendString("" + caption + " ");
}
}
decreaseIdent();
appendString(" ");
appendString("
");
decreaseIdent();
for (int i = 0; i < elements.size(); i++) {
MetaViewElement element = elements.get(i);
if (element instanceof MetaListElement)
append(getElementEditor(section.getDocument(), element));
}
// SAVE AND CLOSE BUTTONS SHOULD BE HERE
appendString("
");
if (GeneratorDataRegistry.getInstance().getContext().areLanguagesSupported() && section.getDocument().isMultilingual()) {
appendString("
");
increaseIdent();
appendString("
");
increaseIdent();
appendString("
");
increaseIdent();
appendString("
");
decreaseIdent();
appendString("
");
appendString("
");
increaseIdent();
appendString("
");
increaseIdent();
appendString("
");
increaseIdent();
// *** START MULILINGUAL COPY *** //
int colspan = 2;
addMultilanguageOperations(section, colspan);
// *** END MULILINGUAL COPY *** //
appendString("
");
appendString("
");
decreaseIdent();
appendString("
");
decreaseIdent();
appendString("
");
appendIncreasedString("
");
appendString("
");
decreaseIdent();
appendString("
");
decreaseIdent();
appendString("
");
}
decreaseIdent();
appendString("
");
appendString("
");
appendString("
");
appendString("
");
appendString("
");
appendString("
");
String entryName = quote(CMSMappingsConfiguratorGenerator.getDialogFormName(currentDialog, ((MetaModuleSection) metaSection).getDocument()));
if(isAppropriateModule(section)){
if (!section.getDocument().getName().equalsIgnoreCase("RedirectUrl") && !section.getDocument().getName().equalsIgnoreCase("EntryPoint")){
String elementName = section.getDocument().getName().equalsIgnoreCase("NaviItem") ? "
" : "";
appendString(" Show usages ");
appendString(" ");
appendString(" \"/>");
appendString(" ");
appendString("
");
}
}
if (StorageType.CMS.equals(((MetaModuleSection) metaSection).getDocument().getParentModule().getStorageType())) {
String result = " \n";
String path = CMSMappingsConfiguratorGenerator.getPath(((MetaModuleSection) metaSection).getDocument(), CMSMappingsConfiguratorGenerator.ACTION_LOCK);
path += "?pId=" + "&nextAction=showEdit";
result += " Really lock "
+ CMSMappingsConfiguratorGenerator.getDialogFormName(currentDialog, ((MetaModuleSection) metaSection).getDocument())
+ " with id: ?','" + path + " ');") + ">" + getLockImage()
+ " Lock";
result += " ";
appendString(result);
appendString("");
path = CMSMappingsConfiguratorGenerator.getPath(((MetaModuleSection) metaSection).getDocument(), CMSMappingsConfiguratorGenerator.ACTION_UNLOCK);
path += "?pId=" + "&nextAction=showEdit";
String alt = ((MetaModuleSection) metaSection).getDocument().getName() + " is locked by: , at: ";
appendString(" Unlock " + ((MetaModuleSection) metaSection).getDocument().getName()
+ " with id: ?','" + path + " ');") + ">"
+ getUnLockImage(alt) + "" + " Unlock Locked by ");
appendString("at: ");
appendString(" ");
}
appendString("");
appendString("
");
appendString("");
// Link to the Links to Me page
appendString("
");
String linksToMePagePath = CMSMappingsConfiguratorGenerator.getPath(section.getDocument(), CMSMappingsConfiguratorGenerator.ACTION_LINKS_TO_ME) + "?pId=";
appendString("" + linksToMePagePath + "") + ">Show direct links to this document ");
appendString(" ");
appendString("
");
appendString("
");
appendString(" ");
appendString("
");
appendString("
");
appendString("
");
appendString("
");
increaseIdent();
appendString("
");
increaseIdent();
appendString("
");
appendString("
");
appendString("
");
appendString("
");
decreaseIdent();
appendString("
");
appendString("
");
increaseIdent();
appendString("
");
increaseIdent();
appendString("
");
appendString("
");
decreaseIdent();
appendString("
");
decreaseIdent();
appendString("
");
appendString("
");
increaseIdent();
appendString("
");
appendString("
");
decreaseIdent();
appendString("
");
decreaseIdent();
appendString("
");
appendString("
");
appendString("");
decreaseIdent();
addDialogContentToDisplayUsagesOfElement(section);
generateRichTextEditorJS(section.getDocument(), richTextElementsRegistry);
generateLinkElementEditorJS(section.getDocument(), linkElementsRegistry);
generateDateTimeWidgetJS();
decreaseIdent();
appendString("");
appendString("");
return jsp;
}
private boolean isAppropriateModule(MetaModuleSection section) {
return section.getModule().getName().equalsIgnoreCase("aswebdata") ||
section.getModule().getName().equalsIgnoreCase("aslayoutdata") ||
section.getModule().getName().equalsIgnoreCase("asgenericdata") ||
section.getModule().getName().equalsIgnoreCase("ascustomdata") ||
section.getModule().getName().equalsIgnoreCase("assitedata") ||
section.getModule().getName().equalsIgnoreCase("asresourcedata");
}
private void generateValidationParts(MetaViewElement element, String name, MetaProperty p) {
if (element.isJSValidated()){
boolean isTextField = element.isRich() || p.getType() == MetaProperty.Type.TEXT;
appendString("");
}
appendString("
");
appendString("
${validationErrors[\""+name+"\"].message} ");
appendString("
");
appendString("
");
}
private String getValueSelector(String fieldName) {
return "$('input[name="+fieldName+"]').val();";
}
private String getLinkValueSelector(String fieldName) {
return "$('input[id="+StringUtils.capitalize(fieldName)+"CurrentValueInput]').val();";
}
private String getTextValueSelector(String fieldName) {
return "(tinyMCE.get('"+fieldName+"_ID') == null || tinyMCE.get('"+fieldName+"_ID').isHidden()) ? $('textarea[name="+fieldName+"]').val() : tinyMCE.get('"+fieldName+"_ID').getContent();";
}
private String getElementEditor(MetaDocument doc, MetaViewElement element){
if (element instanceof MetaEmptyElement)
return " ";
if (element instanceof MetaFieldElement)
return getFieldEditor((MetaFieldElement)element);
if (element instanceof MetaListElement)
return getListEditor(doc, (MetaListElement)element);
if (element instanceof MetaFunctionElement)
return getFunctionEditor(doc, (MetaFunctionElement)element);
return "";
}
private String getListEditor(MetaDocument doc, MetaListElement element){
String ret = "";
List
elements = element.getElements();
for (int i=0; i";
ret += "";
ret += "";
ret += " ";
ret += "(old: )";
*/
//*** CMS2.0 START ***
String editLink = "";
if (p.getName().equalsIgnoreCase("handler")) {
String anoNotEqualNoneStartTag = "";
String anoNotEqualNoneEndTag = " ";
String anoNotEmptyStartTag = "";
String anoNotEmptyEndTag = " ";
String path = "ascustomdataCustomBoxHandlerDefEdit"+"?pId="+" ";
editLink = anoNotEmptyStartTag+
anoNotEqualNoneStartTag+
""+path+"")+">"+" Edit handler"+" " +
anoNotEqualNoneEndTag+
anoNotEmptyEndTag;
}
if (p.getName().equalsIgnoreCase("type")) {
String anoNotEqualNoneStartTag = "";
String anoNotEqualNoneEndTag = " ";
String anoNotEmptyStartTag = "";
String anoNotEmptyEndTag = " ";
String path = "ascustomdataCustomBoxTypeEdit"+"?pId="+" ";
editLink = anoNotEmptyStartTag
+anoNotEqualNoneStartTag+
""+path+"")+">"+" Edit type"+" " +
anoNotEqualNoneEndTag+
anoNotEmptyEndTag;
}
//quoted "name" attr in em, cause w3c validation says it's error
ret += "
";
ret += " (old: "+
") "+editLink;
//*** CMS2.0 FINISH ***
return ret;
}
private String getEnumerationEditor(MetaFieldElement element, MetaProperty p){
String ret = "";
String lang = getElementLanguage(element);
ret += "";
ret += "";
ret += "\" selected > ";
ret += " ";
ret += " ";
ret += " ";
ret += "(old: )";
return ret;
}
private String getFieldEditor(MetaFieldElement element){
MetaDocument doc = ((MetaModuleSection)currentSection).getDocument();
MetaProperty p = doc.getField(element.getName());
if (p.isLinked())
return getLinkEditor(element, p);
if (p instanceof MetaEnumerationProperty){
return getEnumerationEditor(element, p);
}
if (p instanceof MetaContainerProperty) {
return getContainerLinkEditor(element, (MetaContainerProperty)p);
}
switch (p.getType()) {
case STRING:
return getStringEditor(element, p);
case PASSWORD:
return getPasswordEditor(element, p);
case TEXT:
return getTextEditor(element, p);
case LONG:
return getStringEditor(element, p);
case INT:
return getStringEditor(element, p);
case DOUBLE:
return getStringEditor(element, p);
case FLOAT:
return getStringEditor(element, p);
case BOOLEAN:
return getBooleanEditor(element, p);
case IMAGE:
return getImageEditor(element, p);
default:
return p.getType().getName();
}
}
private String getContainerLinkEditor(MetaFieldElement element, MetaContainerProperty p){
String ret = "";
String lang = getElementLanguage(element);
String name = quote(CMSMappingsConfiguratorGenerator.getDialogFormName(currentDialog, ((MetaModuleSection)currentSection).getDocument()));
ret += "";
ret += "none";
ret += " ";
ret += "";
ret += " ";
ret += " ";
ret += "element";
ret += "";
ret += "s";
ret += " ";
ret += " ";
String actionName = CMSMappingsConfiguratorGenerator.getContainerPath(((MetaModuleSection)currentSection).getDocument(), p, CMSMappingsConfiguratorGenerator.ACTION_SHOW);
actionName += "?ownerId= ";
ret += " » Edit ";
ret += " ";
return ret;
}
private String getImageEditor(MetaFieldElement element, MetaProperty p){
String beanName = CMSMappingsConfiguratorGenerator.getDialogFormName(currentDialog, ((MetaModuleSection)currentSection).getDocument());
String propertyWriter = " ";
String ret ="";
ret += "\r";
ret += " \r";
ret += " \r";
ret += getUpdateAndDeleteFileAndStayFunction(((MetaModuleSection)currentSection).getDocument(),p);
ret += " \r";
ret += "
\r";
ret += "\r";
return ret;
}
private String getStringEditor(MetaFieldElement element, MetaProperty p){
return getInputEditor(element, p, "text");
}
private String getPasswordEditor(MetaFieldElement element, MetaProperty p){
return getInputEditor(element, p, "password");
}
private String getBooleanEditor(MetaFieldElement element, MetaProperty p){
return getInputEditor(element, p, "checkbox");
}
private String getInputEditor(MetaFieldElement element, MetaProperty p, String inputType){
String ret ="";
String lang = getElementLanguage(element);
ret += " ";
ret += "checked";
}
else {
ret += " value=\" \"";
// Required for DateTime widget
if (element.isDatetime()) {
ret += " class=" + quote("datetime");
isNeedEnableDateTimeWidgets = true;
}
}
if (element.isReadonly())
ret += " readonly="+quote("readonly");
if (element.isAutocompleteOff())
ret += " autocomplete="+quote("off");
ret += "/>";
if (element.isReadonly())
ret += " readonly ";
return ret;
}
private String getTextEditor(MetaFieldElement element, MetaProperty p){
String lang = getElementLanguage(element);
String ret ="";
ret += "";
return ret;
}
private void generateLinkElementEditorJS(MetaDocument doc, List linkElements){
appendString("");
}
private void generateRichTextEditorJS(MetaDocument doc, List richTextElements){
appendString("");
appendString("");
appendString("");
}
private void generateDateTimeWidgetJS() {
if (!isNeedEnableDateTimeWidgets)
return;
appendString("");
appendString("");
appendString("");
}
private String getFunctionEditor(MetaDocument doc, MetaFunctionElement element){
if (element.getName().equals("cancel")) {
String onClick = "return confirm('All unsaved data will be lost!!!. Document will be unlocked";
String cancel = CMSMappingsConfiguratorGenerator.getPath(((MetaModuleSection) currentSection).getDocument(), CMSMappingsConfiguratorGenerator.ACTION_CLOSE);
cancel += "?pId=";
return "Close ";
}
if (element.getName().equals("update")) {
return getUpdateAndCloseFunction(doc, element);
}
if (element.getName().equals("updateAndStay")) {
return getUpdateAndStayFunction(doc, element);
}
if (element.getName().equals("updateAndClose")) {
return getUpdateAndCloseFunction(doc, element);
}
if (element.getName().equals("lock") && StorageType.CMS.equals(doc.getParentModule().getStorageType())) {
//For now we dont draw Lock and Unlock functions here
//return getLockFunctionLink(doc, element);
}
if (element.getName().equals("unlock") && StorageType.CMS.equals(doc.getParentModule().getStorageType())) {
//For now we dont draw Lock and Unlock functions here
//return getUnLockFunctionLink(doc, element);
}
return "";
}
private String getUpdateAndDeleteFileAndStayFunction(MetaDocument doc, MetaProperty p){
String beanName = CMSMappingsConfiguratorGenerator.getDialogFormName(currentDialog, ((MetaModuleSection)currentSection).getDocument());
String propertyWriter = " ";
if(StorageType.CMS.equals(doc.getParentModule().getStorageType())){
//creating logic for hiding or showing current operation link in Locking CASE!!!!!
String result = "";
result += " \n";
result+=" ") + "> \n";
result+="\t \n";
result+=" \n";
result+=" \n";
result+=" \n";
result+="\t \n";
result+=" \n";
result+=" \n";
return result;
}
//Delete customSubmit in the bottom, if not using tinyMCE
return ""+
" "+
" ";
}
private String getUpdateAndStayFunction(MetaDocument doc, MetaFunctionElement element){
if(StorageType.CMS.equals(doc.getParentModule().getStorageType())){
//creating logic for hiding or showing current operation link in Locking CASE!!!!!
String result = " \n";
result+=" ") + "> \n";
result+="\t \n";
result+=" \n";
result+=" \n";
result+=" \n";
result+="\t \n";
result+=" \n";
return result;
}
//Delete customSubmit in the bottom, if not using tinyMCE
return " ";
}
private String getUpdateAndCloseFunction(MetaDocument doc, MetaFunctionElement element){
if(StorageType.CMS.equals(doc.getParentModule().getStorageType())){
//creating logic for hiding or showing current operation link in Locking CASE!!!!!
String result = " \n";
result+=" ") + "> \n";
result+="\t \n";
result+=" \n";
result+=" \n";
result+=" \n";
result+="\t \n";
result+=" \n";
return result;
}
//Delete customSubmit in the bottom, if not using tinyMCE
return " ";
}
/**
* Creating entries in JSP for Multilanguage Support!!!
* @param section
* @param colspan
*/
private void addMultilanguageOperations(MetaModuleSection section, int colspan) {
appendString("");
increaseIdent();
appendString("");
increaseIdent();
appendString("");
appendString("");
decreaseIdent();
appendString(" ");
decreaseIdent();
appendString(" ");
appendString("");
increaseIdent();
appendString("");
appendString("");
appendString(" ");
}
private void addDialogContentToDisplayUsagesOfElement(MetaModuleSection section){
if(isAppropriateModule(section)){
if (!section.getDocument().getName().equalsIgnoreCase("RedirectUrl") && !section.getDocument().getName().equalsIgnoreCase("EntryPoint")){
increaseIdent();
appendString("");
}
}
}
}