From dcecdd25a45f5664f7737b3a7c345e20ecbbbc98 Mon Sep 17 00:00:00 2001 From: Adrian Crum Date: Sun, 18 Jan 2015 21:03:40 +0000 Subject: [PATCH] Reorganized the screen widget src folder so classes are more organized. This commit might break some Groovy scripts. There seemed to be a lot of C&P widget import statements, but there were no widget classes being used in the script, so I removed them. I might have overlooked something though. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@1652852 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/org/ofbiz/content/cms/CmsEvents.java | 6 +- .../ofbiz/content/content/ContentWorker.java | 2 +- .../content/data/DataResourceWorker.java | 12 +- .../ofbiz/content/output/OutputServices.java | 6 +- .../actions/survey/EditSurveyQuestions.groovy | 2 +- .../ProductionRunActualComponents.groovy | 2 +- .../jobshopmgt/ProductionRunComponents.groovy | 2 +- .../jobshopmgt/ProductionRunCosts.groovy | 2 +- .../ProductionRunDeclaration.groovy | 2 +- .../ProductionRunFixedAssets.groovy | 2 +- .../routing/EditCalendarExceptionDay.groovy | 2 +- .../routing/EditCalendarExceptionWeek.groovy | 2 +- .../jobshopmgt/ShowProductionRun.groovy | 2 +- .../order/OrderDeliveryScheduleInfo.groovy | 2 +- .../EditProductConfigItemContent.groovy | 2 +- ...EditProductConfigItemContentContent.groovy | 2 +- .../config/EditProductConfigOptions.groovy | 2 +- .../actions/shipment/EditShipment.groovy | 2 +- .../actions/shipment/EditShipmentPlan.groovy | 2 +- .../org/ofbiz/common/email/EmailServices.java | 6 +- .../webcommon/WEB-INF/handlers-controller.xml | 10 +- framework/common/widget/PortalPageScreens.xml | 2 +- framework/resources/templates/web.xml | 2 +- .../artifactinfo/ArtifactInfoFactory.java | 11 +- .../artifactinfo/FormWidgetArtifactInfo.java | 2 +- .../ScreenWidgetArtifactInfo.java | 2 +- .../webtools/print/FoPrintServerEvents.java | 4 +- .../config/freemarkerTransforms.properties | 2 +- .../src/org/ofbiz/widget/WidgetFactory.java | 6 +- .../src/org/ofbiz/widget/WidgetWorker.java | 4 +- .../widget/artifact/ArtifactInfoGatherer.java | 154 +- .../{ => content}/ContentWorkerInterface.java | 96 +- .../DataResourceWorkerInterface.java | 74 +- .../{ => content}/WidgetContentWorker.java | 84 +- .../WidgetDataResourceWorker.java | 84 +- .../{ => model}/AbstractModelAction.java | 4 +- .../{ => model}/AbstractModelCondition.java | 3 +- .../{ => model}/CommonWidgetModels.java | 2 +- .../widget/{form => model}/FieldInfo.java | 5 +- .../widget/{form => model}/FormFactory.java | 262 +- .../widget/{screen => model}/HtmlWidget.java | 623 +- .../IterateSectionWidget.java | 774 +- .../widget/{menu => model}/MenuFactory.java | 236 +- .../ofbiz/widget/{ => model}/ModelAction.java | 2 +- .../{ => model}/ModelActionVisitor.java | 6 +- .../widget/{ => model}/ModelCondition.java | 2 +- .../{ => model}/ModelConditionFactory.java | 2 +- .../{ => model}/ModelConditionVisitor.java | 30 +- .../widget/{ => model}/ModelFieldVisitor.java | 44 +- .../widget/{form => model}/ModelForm.java | 3712 ++++---- .../{form => model}/ModelFormAction.java | 547 +- .../{form => model}/ModelFormField.java | 7608 +++++++++-------- .../ModelFormFieldBuilder.java | 48 +- .../widget/{menu => model}/ModelMenu.java | 1070 ++- .../{menu => model}/ModelMenuAction.java | 466 +- .../{menu => model}/ModelMenuCondition.java | 138 +- .../widget/{menu => model}/ModelMenuItem.java | 1341 ++- .../widget/{screen => model}/ModelScreen.java | 388 +- .../ModelScreenCondition.java | 192 +- .../{screen => model}/ModelScreenWidget.java | 3923 +++++---- .../widget/{tree => model}/ModelTree.java | 2274 +++-- .../{tree => model}/ModelTreeAction.java | 923 +- .../{tree => model}/ModelTreeCondition.java | 80 +- .../ofbiz/widget/{ => model}/ModelWidget.java | 309 +- .../{ => model}/ModelWidgetCondition.java | 2 +- .../{ => model}/ModelWidgetVisitor.java | 11 +- .../{screen => model}/ScreenFactory.java | 425 +- .../widget/{tree => model}/TreeFactory.java | 174 +- .../XmlAbstractWidgetVisitor.java} | 17 +- .../XmlWidgetActionVisitor.java | 39 +- .../XmlWidgetConditionVisitor.java | 34 +- .../{xml => model}/XmlWidgetFieldVisitor.java | 34 +- .../{xml => model}/XmlWidgetVisitor.java | 68 +- .../widget/{ => portal}/PortalPageWorker.java | 353 +- .../PortalPageWorkerInterface.java | 66 +- .../{ => portal}/WidgetPortalPageWorker.java | 83 +- .../{form => renderer}/FormRenderer.java | 11 +- .../FormStringRenderer.java | 195 +- .../MenuStringRenderer.java | 80 +- .../{menu => renderer}/MenuWrapTransform.java | 400 +- .../widget/{form => renderer}/Paginator.java | 3 +- .../ScreenRenderException.java | 96 +- .../{screen => renderer}/ScreenRenderer.java | 634 +- .../ScreenStringRenderer.java | 133 +- .../TreeStringRenderer.java | 76 +- .../{form => renderer}/UtilHelpText.java | 174 +- .../{ => renderer}/fo/FoFormRenderer.java | 854 +- .../{ => renderer}/fo/FoScreenRenderer.java | 390 +- .../fo}/ScreenFopViewHandler.java | 285 +- .../{ => renderer}/html/HtmlFormRenderer.java | 5646 ++++++------ .../{ => renderer}/html/HtmlFormWrapper.java | 400 +- .../{ => renderer}/html/HtmlMenuRenderer.java | 1184 +-- .../html/HtmlMenuRendererImage.java | 160 +- .../{ => renderer}/html/HtmlMenuWrapper.java | 504 +- .../html/HtmlMenuWrapperImage.java | 161 +- .../html/HtmlScreenRenderer.java | 1876 ++-- .../{ => renderer}/html/HtmlTreeRenderer.java | 684 +- .../html/HtmlWidgetRenderer.java | 198 +- .../macro}/MacroFormRenderer.java | 6256 +++++++------- .../macro}/MacroMenuRenderer.java | 11 +- .../macro}/MacroScreenRenderer.java | 2093 ++--- .../macro}/MacroScreenViewHandler.java | 335 +- .../macro}/MacroTreeRenderer.java | 740 +- .../{ => renderer}/text/TextFormRenderer.java | 604 +- .../text/TextScreenRenderer.java | 306 +- .../{ => renderer}/xml/XmlFormRenderer.java | 686 +- .../widget/templates/htmlFormMacroLibrary.ftl | 2 +- .../birt/src/org/ofbiz/birt/BirtFactory.java | 2 +- .../ofbiz/birt/email/BirtEmailServices.java | 4 +- .../birt/webapp/birt/WEB-INF/web.xml | 2 +- .../WEB-INF/actions/content/Mrv.groovy | 3 +- .../WEB-INF/actions/content/Search.groovy | 2 +- .../actions/forum/ContentAddPrep.groovy | 3 +- .../WEB-INF/actions/forum/ContentPrep.groovy | 3 +- .../actions/forum/CurrentValPrep.groovy | 3 +- .../WEB-INF/actions/forum/EditAddPrep.groovy | 3 +- .../WEB-INF/actions/forum/FormPrep.groovy | 4 +- .../WEB-INF/actions/forum/HtmlAreaPrep.groovy | 3 +- .../actions/forum/NodeTrailPrep.groovy | 3 +- .../actions/forum/OwnerContentPrep.groovy | 3 +- .../WEB-INF/actions/forum/PermPrep.groovy | 3 +- .../WEB-INF/actions/forum/PubInit.groovy | 3 +- .../actions/forum/RespondPermAndPrep.groovy | 3 +- .../WEB-INF/actions/forum/ResponsePrep.groovy | 3 +- .../WEB-INF/actions/forum/ViewPrep.groovy | 3 +- .../WEB-INF/actions/includes/MruAdd.groovy | 3 +- .../webapp/ecommerce/WEB-INF/controller.xml | 4 +- .../ofbiz/example/ExamplePrintServices.java | 4 +- .../googleCheckout/PrepareXMLTemplate.xml | 10 +- .../webapp/googlecheckout/WEB-INF/web.xml | 2 +- .../src/org/ofbiz/oagis/OagisServices.java | 6 +- .../ofbiz/oagis/OagisShipmentServices.java | 6 +- .../scrum/webapp/demotest/WEB-INF/web.xml | 2 +- .../scrum/webapp/scrum/WEB-INF/web.xml | 2 +- .../webapp/webpos/WEB-INF/controller.xml | 2 +- themes/bluelight/includes/appbarOpen.ftl | 2 +- .../droppingcrumbs/includes/appbarClose.ftl | 2 +- themes/droppingcrumbs/includes/appbarOpen.ftl | 2 +- themes/tomahawk/includes/appbarClose.ftl | 2 +- themes/tomahawk/includes/appbarOpen.ftl | 2 +- 140 files changed, 26091 insertions(+), 26109 deletions(-) rename framework/widget/src/org/ofbiz/widget/{ => content}/ContentWorkerInterface.java (97%) rename framework/widget/src/org/ofbiz/widget/{ => content}/DataResourceWorkerInterface.java (95%) rename framework/widget/src/org/ofbiz/widget/{ => content}/WidgetContentWorker.java (96%) rename framework/widget/src/org/ofbiz/widget/{ => content}/WidgetDataResourceWorker.java (96%) rename framework/widget/src/org/ofbiz/widget/{ => model}/AbstractModelAction.java (97%) rename framework/widget/src/org/ofbiz/widget/{ => model}/AbstractModelCondition.java (97%) rename framework/widget/src/org/ofbiz/widget/{ => model}/CommonWidgetModels.java (97%) rename framework/widget/src/org/ofbiz/widget/{form => model}/FieldInfo.java (95%) rename framework/widget/src/org/ofbiz/widget/{form => model}/FormFactory.java (97%) rename framework/widget/src/org/ofbiz/widget/{screen => model}/HtmlWidget.java (96%) rename framework/widget/src/org/ofbiz/widget/{screen => model}/IterateSectionWidget.java (97%) rename framework/widget/src/org/ofbiz/widget/{menu => model}/MenuFactory.java (97%) rename framework/widget/src/org/ofbiz/widget/{ => model}/ModelAction.java (95%) rename framework/widget/src/org/ofbiz/widget/{ => model}/ModelActionVisitor.java (91%) rename framework/widget/src/org/ofbiz/widget/{ => model}/ModelCondition.java (94%) rename framework/widget/src/org/ofbiz/widget/{ => model}/ModelConditionFactory.java (96%) rename framework/widget/src/org/ofbiz/widget/{ => model}/ModelConditionVisitor.java (67%) rename framework/widget/src/org/ofbiz/widget/{ => model}/ModelFieldVisitor.java (63%) rename framework/widget/src/org/ofbiz/widget/{form => model}/ModelForm.java (97%) rename framework/widget/src/org/ofbiz/widget/{form => model}/ModelFormAction.java (97%) rename framework/widget/src/org/ofbiz/widget/{form => model}/ModelFormField.java (97%) rename framework/widget/src/org/ofbiz/widget/{form => model}/ModelFormFieldBuilder.java (94%) rename framework/widget/src/org/ofbiz/widget/{menu => model}/ModelMenu.java (97%) rename framework/widget/src/org/ofbiz/widget/{menu => model}/ModelMenuAction.java (97%) rename framework/widget/src/org/ofbiz/widget/{menu => model}/ModelMenuCondition.java (95%) rename framework/widget/src/org/ofbiz/widget/{menu => model}/ModelMenuItem.java (95%) rename framework/widget/src/org/ofbiz/widget/{screen => model}/ModelScreen.java (96%) rename framework/widget/src/org/ofbiz/widget/{screen => model}/ModelScreenCondition.java (88%) rename framework/widget/src/org/ofbiz/widget/{screen => model}/ModelScreenWidget.java (96%) rename framework/widget/src/org/ofbiz/widget/{tree => model}/ModelTree.java (97%) rename framework/widget/src/org/ofbiz/widget/{tree => model}/ModelTreeAction.java (97%) rename framework/widget/src/org/ofbiz/widget/{tree => model}/ModelTreeCondition.java (92%) rename framework/widget/src/org/ofbiz/widget/{ => model}/ModelWidget.java (96%) rename framework/widget/src/org/ofbiz/widget/{ => model}/ModelWidgetCondition.java (97%) rename framework/widget/src/org/ofbiz/widget/{ => model}/ModelWidgetVisitor.java (87%) rename framework/widget/src/org/ofbiz/widget/{screen => model}/ScreenFactory.java (97%) rename framework/widget/src/org/ofbiz/widget/{tree => model}/TreeFactory.java (97%) rename framework/widget/src/org/ofbiz/widget/{xml/AbstractWidgetVisitor.java => model/XmlAbstractWidgetVisitor.java} (91%) rename framework/widget/src/org/ofbiz/widget/{xml => model}/XmlWidgetActionVisitor.java (82%) rename framework/widget/src/org/ofbiz/widget/{xml => model}/XmlWidgetConditionVisitor.java (82%) rename framework/widget/src/org/ofbiz/widget/{xml => model}/XmlWidgetFieldVisitor.java (90%) rename framework/widget/src/org/ofbiz/widget/{xml => model}/XmlWidgetVisitor.java (90%) rename framework/widget/src/org/ofbiz/widget/{ => portal}/PortalPageWorker.java (97%) rename framework/widget/src/org/ofbiz/widget/{ => portal}/PortalPageWorkerInterface.java (95%) rename framework/widget/src/org/ofbiz/widget/{ => portal}/WidgetPortalPageWorker.java (92%) rename framework/widget/src/org/ofbiz/widget/{form => renderer}/FormRenderer.java (97%) rename framework/widget/src/org/ofbiz/widget/{form => renderer}/FormStringRenderer.java (97%) rename framework/widget/src/org/ofbiz/widget/{menu => renderer}/MenuStringRenderer.java (90%) rename framework/widget/src/org/ofbiz/widget/{menu => renderer}/MenuWrapTransform.java (96%) rename framework/widget/src/org/ofbiz/widget/{form => renderer}/Paginator.java (96%) rename framework/widget/src/org/ofbiz/widget/{screen => renderer}/ScreenRenderException.java (95%) rename framework/widget/src/org/ofbiz/widget/{screen => renderer}/ScreenRenderer.java (97%) rename framework/widget/src/org/ofbiz/widget/{screen => renderer}/ScreenStringRenderer.java (97%) rename framework/widget/src/org/ofbiz/widget/{tree => renderer}/TreeStringRenderer.java (94%) rename framework/widget/src/org/ofbiz/widget/{form => renderer}/UtilHelpText.java (96%) rename framework/widget/src/org/ofbiz/widget/{ => renderer}/fo/FoFormRenderer.java (90%) rename framework/widget/src/org/ofbiz/widget/{ => renderer}/fo/FoScreenRenderer.java (94%) rename framework/widget/src/org/ofbiz/widget/{screen => renderer/fo}/ScreenFopViewHandler.java (93%) rename framework/widget/src/org/ofbiz/widget/{ => renderer}/html/HtmlFormRenderer.java (94%) rename framework/widget/src/org/ofbiz/widget/{ => renderer}/html/HtmlFormWrapper.java (94%) rename framework/widget/src/org/ofbiz/widget/{ => renderer}/html/HtmlMenuRenderer.java (96%) rename framework/widget/src/org/ofbiz/widget/{ => renderer}/html/HtmlMenuRendererImage.java (93%) rename framework/widget/src/org/ofbiz/widget/{ => renderer}/html/HtmlMenuWrapper.java (95%) rename framework/widget/src/org/ofbiz/widget/{ => renderer}/html/HtmlMenuWrapperImage.java (94%) rename framework/widget/src/org/ofbiz/widget/{ => renderer}/html/HtmlScreenRenderer.java (95%) rename framework/widget/src/org/ofbiz/widget/{ => renderer}/html/HtmlTreeRenderer.java (95%) rename framework/widget/src/org/ofbiz/widget/{ => renderer}/html/HtmlWidgetRenderer.java (95%) rename framework/widget/src/org/ofbiz/widget/{form => renderer/macro}/MacroFormRenderer.java (96%) rename framework/widget/src/org/ofbiz/widget/{menu => renderer/macro}/MacroMenuRenderer.java (95%) rename framework/widget/src/org/ofbiz/widget/{screen => renderer/macro}/MacroScreenRenderer.java (96%) rename framework/widget/src/org/ofbiz/widget/{screen => renderer/macro}/MacroScreenViewHandler.java (95%) rename framework/widget/src/org/ofbiz/widget/{tree => renderer/macro}/MacroTreeRenderer.java (95%) rename framework/widget/src/org/ofbiz/widget/{ => renderer}/text/TextFormRenderer.java (88%) rename framework/widget/src/org/ofbiz/widget/{ => renderer}/text/TextScreenRenderer.java (95%) rename framework/widget/src/org/ofbiz/widget/{ => renderer}/xml/XmlFormRenderer.java (89%) diff --git a/applications/content/src/org/ofbiz/content/cms/CmsEvents.java b/applications/content/src/org/ofbiz/content/cms/CmsEvents.java index 6b21bee8ba..6d403b7c48 100644 --- a/applications/content/src/org/ofbiz/content/cms/CmsEvents.java +++ b/applications/content/src/org/ofbiz/content/cms/CmsEvents.java @@ -47,9 +47,9 @@ import org.ofbiz.entity.util.EntityUtilProperties; import org.ofbiz.service.LocalDispatcher; import org.ofbiz.webapp.control.RequestHandler; import org.ofbiz.webapp.website.WebSiteWorker; -import org.ofbiz.widget.form.FormStringRenderer; -import org.ofbiz.widget.form.MacroFormRenderer; -import org.ofbiz.widget.screen.ScreenRenderer; +import org.ofbiz.widget.renderer.FormStringRenderer; +import org.ofbiz.widget.renderer.ScreenRenderer; +import org.ofbiz.widget.renderer.macro.MacroFormRenderer; import freemarker.template.TemplateException; diff --git a/applications/content/src/org/ofbiz/content/content/ContentWorker.java b/applications/content/src/org/ofbiz/content/content/ContentWorker.java index 3f7d96cb4e..2b57db8b01 100644 --- a/applications/content/src/org/ofbiz/content/content/ContentWorker.java +++ b/applications/content/src/org/ofbiz/content/content/ContentWorker.java @@ -69,7 +69,7 @@ import freemarker.ext.dom.NodeModel; /** * ContentWorker Class */ -public class ContentWorker implements org.ofbiz.widget.ContentWorkerInterface { +public class ContentWorker implements org.ofbiz.widget.content.ContentWorkerInterface { public static final String module = ContentWorker.class.getName(); diff --git a/applications/content/src/org/ofbiz/content/data/DataResourceWorker.java b/applications/content/src/org/ofbiz/content/data/DataResourceWorker.java index d4f7f4b506..876414ff3d 100644 --- a/applications/content/src/org/ofbiz/content/data/DataResourceWorker.java +++ b/applications/content/src/org/ofbiz/content/data/DataResourceWorker.java @@ -76,11 +76,11 @@ import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.entity.util.EntityUtilProperties; import org.ofbiz.service.GenericServiceException; import org.ofbiz.service.LocalDispatcher; -import org.ofbiz.widget.screen.MacroScreenRenderer; -import org.ofbiz.widget.screen.ModelScreen; -import org.ofbiz.widget.screen.ScreenFactory; -import org.ofbiz.widget.screen.ScreenRenderer; -import org.ofbiz.widget.screen.ScreenStringRenderer; +import org.ofbiz.widget.model.ModelScreen; +import org.ofbiz.widget.model.ScreenFactory; +import org.ofbiz.widget.renderer.ScreenRenderer; +import org.ofbiz.widget.renderer.ScreenStringRenderer; +import org.ofbiz.widget.renderer.macro.MacroScreenRenderer; import org.w3c.dom.Document; import org.xml.sax.SAXException; @@ -90,7 +90,7 @@ import freemarker.template.TemplateException; /** * DataResourceWorker Class */ -public class DataResourceWorker implements org.ofbiz.widget.DataResourceWorkerInterface { +public class DataResourceWorker implements org.ofbiz.widget.content.DataResourceWorkerInterface { public static final String module = DataResourceWorker.class.getName(); public static final String err_resource = "ContentErrorUiLabels"; diff --git a/applications/content/src/org/ofbiz/content/output/OutputServices.java b/applications/content/src/org/ofbiz/content/output/OutputServices.java index 1f9b1f8aec..f6755dd99b 100644 --- a/applications/content/src/org/ofbiz/content/output/OutputServices.java +++ b/applications/content/src/org/ofbiz/content/output/OutputServices.java @@ -63,9 +63,9 @@ import org.ofbiz.entity.util.EntityUtilProperties; import org.ofbiz.service.DispatchContext; import org.ofbiz.service.ServiceUtil; import org.ofbiz.webapp.view.ApacheFopWorker; -import org.ofbiz.widget.fo.FoFormRenderer; -import org.ofbiz.widget.fo.FoScreenRenderer; -import org.ofbiz.widget.screen.ScreenRenderer; +import org.ofbiz.widget.renderer.fo.FoFormRenderer; +import org.ofbiz.widget.renderer.fo.FoScreenRenderer; +import org.ofbiz.widget.renderer.ScreenRenderer; /** diff --git a/applications/content/webapp/content/WEB-INF/actions/survey/EditSurveyQuestions.groovy b/applications/content/webapp/content/WEB-INF/actions/survey/EditSurveyQuestions.groovy index e5d1ad23c0..53fa09fe1e 100644 --- a/applications/content/webapp/content/WEB-INF/actions/survey/EditSurveyQuestions.groovy +++ b/applications/content/webapp/content/WEB-INF/actions/survey/EditSurveyQuestions.groovy @@ -20,7 +20,7 @@ import org.ofbiz.entity.* import org.ofbiz.entity.condition.* import org.ofbiz.base.util.* -import org.ofbiz.widget.html.* +import org.ofbiz.widget.renderer.html.* surveyQuestionId = parameters.surveyQuestionId; context.surveyQuestionId = surveyQuestionId; diff --git a/applications/manufacturing/webapp/manufacturing/WEB-INF/actions/jobshopmgt/ProductionRunActualComponents.groovy b/applications/manufacturing/webapp/manufacturing/WEB-INF/actions/jobshopmgt/ProductionRunActualComponents.groovy index 49e6897009..8163a6087a 100644 --- a/applications/manufacturing/webapp/manufacturing/WEB-INF/actions/jobshopmgt/ProductionRunActualComponents.groovy +++ b/applications/manufacturing/webapp/manufacturing/WEB-INF/actions/jobshopmgt/ProductionRunActualComponents.groovy @@ -17,7 +17,7 @@ * under the License. */ -import org.ofbiz.widget.html.HtmlFormWrapper; +import org.ofbiz.widget.renderer.html.HtmlFormWrapper; productionRunId = parameters.productionRunId ?: parameters.workEffortId; diff --git a/applications/manufacturing/webapp/manufacturing/WEB-INF/actions/jobshopmgt/ProductionRunComponents.groovy b/applications/manufacturing/webapp/manufacturing/WEB-INF/actions/jobshopmgt/ProductionRunComponents.groovy index 8bc5a5022a..db69b534c5 100644 --- a/applications/manufacturing/webapp/manufacturing/WEB-INF/actions/jobshopmgt/ProductionRunComponents.groovy +++ b/applications/manufacturing/webapp/manufacturing/WEB-INF/actions/jobshopmgt/ProductionRunComponents.groovy @@ -17,7 +17,7 @@ * under the License. */ -import org.ofbiz.widget.html.HtmlFormWrapper; +import org.ofbiz.widget.renderer.html.HtmlFormWrapper; productionRunId = parameters.productionRunId ?: parameters.workEffortId; diff --git a/applications/manufacturing/webapp/manufacturing/WEB-INF/actions/jobshopmgt/ProductionRunCosts.groovy b/applications/manufacturing/webapp/manufacturing/WEB-INF/actions/jobshopmgt/ProductionRunCosts.groovy index 74d0108ad1..6c25da5abf 100644 --- a/applications/manufacturing/webapp/manufacturing/WEB-INF/actions/jobshopmgt/ProductionRunCosts.groovy +++ b/applications/manufacturing/webapp/manufacturing/WEB-INF/actions/jobshopmgt/ProductionRunCosts.groovy @@ -18,7 +18,7 @@ */ import org.ofbiz.entity.util.EntityUtil; -import org.ofbiz.widget.html.HtmlFormWrapper; +import org.ofbiz.widget.renderer.html.HtmlFormWrapper; productionRunId = parameters.productionRunId ?: parameters.workEffortId; taskCosts = []; diff --git a/applications/manufacturing/webapp/manufacturing/WEB-INF/actions/jobshopmgt/ProductionRunDeclaration.groovy b/applications/manufacturing/webapp/manufacturing/WEB-INF/actions/jobshopmgt/ProductionRunDeclaration.groovy index 8367e940ea..f456717f82 100644 --- a/applications/manufacturing/webapp/manufacturing/WEB-INF/actions/jobshopmgt/ProductionRunDeclaration.groovy +++ b/applications/manufacturing/webapp/manufacturing/WEB-INF/actions/jobshopmgt/ProductionRunDeclaration.groovy @@ -22,7 +22,7 @@ import org.ofbiz.entity.util.EntityUtil; import org.ofbiz.entity.GenericValue; -import org.ofbiz.widget.html.HtmlFormWrapper; +import org.ofbiz.widget.renderer.html.HtmlFormWrapper; import org.ofbiz.manufacturing.jobshopmgt.ProductionRun; import javolution.util.FastList; diff --git a/applications/manufacturing/webapp/manufacturing/WEB-INF/actions/jobshopmgt/ProductionRunFixedAssets.groovy b/applications/manufacturing/webapp/manufacturing/WEB-INF/actions/jobshopmgt/ProductionRunFixedAssets.groovy index c1d6714cf5..eb99298290 100644 --- a/applications/manufacturing/webapp/manufacturing/WEB-INF/actions/jobshopmgt/ProductionRunFixedAssets.groovy +++ b/applications/manufacturing/webapp/manufacturing/WEB-INF/actions/jobshopmgt/ProductionRunFixedAssets.groovy @@ -17,7 +17,7 @@ * under the License. */ -import org.ofbiz.widget.html.HtmlFormWrapper; +import org.ofbiz.widget.renderer.html.HtmlFormWrapper; productionRunId = parameters.productionRunId ?: parameters.workEffortId; diff --git a/applications/manufacturing/webapp/manufacturing/WEB-INF/actions/routing/EditCalendarExceptionDay.groovy b/applications/manufacturing/webapp/manufacturing/WEB-INF/actions/routing/EditCalendarExceptionDay.groovy index e076d6a66c..ce1dea6e17 100644 --- a/applications/manufacturing/webapp/manufacturing/WEB-INF/actions/routing/EditCalendarExceptionDay.groovy +++ b/applications/manufacturing/webapp/manufacturing/WEB-INF/actions/routing/EditCalendarExceptionDay.groovy @@ -21,7 +21,7 @@ import java.util.*; import org.ofbiz.base.util.*; import org.ofbiz.entity.*; -import org.ofbiz.widget.html.*; +import org.ofbiz.widget.renderer.html.HtmlFormWrapper; if (security.hasEntityPermission("MANUFACTURING", "_VIEW", session)) { context.hasPermission = Boolean.TRUE; diff --git a/applications/manufacturing/webapp/manufacturing/WEB-INF/actions/routing/EditCalendarExceptionWeek.groovy b/applications/manufacturing/webapp/manufacturing/WEB-INF/actions/routing/EditCalendarExceptionWeek.groovy index 7907a4f55d..8886d69b9e 100644 --- a/applications/manufacturing/webapp/manufacturing/WEB-INF/actions/routing/EditCalendarExceptionWeek.groovy +++ b/applications/manufacturing/webapp/manufacturing/WEB-INF/actions/routing/EditCalendarExceptionWeek.groovy @@ -18,7 +18,7 @@ */ -import org.ofbiz.widget.html.HtmlFormWrapper; +import org.ofbiz.widget.renderer.html.HtmlFormWrapper; import org.ofbiz.base.util.*; if (security.hasEntityPermission("MANUFACTURING", "_VIEW", session)) { diff --git a/applications/manufacturing/webapp/manufacturing/jobshopmgt/ShowProductionRun.groovy b/applications/manufacturing/webapp/manufacturing/jobshopmgt/ShowProductionRun.groovy index ae8c36291d..b11a78febc 100644 --- a/applications/manufacturing/webapp/manufacturing/jobshopmgt/ShowProductionRun.groovy +++ b/applications/manufacturing/webapp/manufacturing/jobshopmgt/ShowProductionRun.groovy @@ -25,7 +25,7 @@ import org.ofbiz.entity.util.EntityUtil; import org.ofbiz.base.util.*; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilValidate; -import org.ofbiz.widget.html.HtmlFormWrapper; +import org.ofbiz.widget.renderer.html.HtmlFormWrapper; import org.ofbiz.manufacturing.jobshopmgt.ProductionRun; delegator = request.getAttribute("delegator"); diff --git a/applications/order/webapp/ordermgr/WEB-INF/actions/order/OrderDeliveryScheduleInfo.groovy b/applications/order/webapp/ordermgr/WEB-INF/actions/order/OrderDeliveryScheduleInfo.groovy index 9fbd1b9200..073c6091ba 100644 --- a/applications/order/webapp/ordermgr/WEB-INF/actions/order/OrderDeliveryScheduleInfo.groovy +++ b/applications/order/webapp/ordermgr/WEB-INF/actions/order/OrderDeliveryScheduleInfo.groovy @@ -19,7 +19,7 @@ import org.ofbiz.base.util.*; import org.ofbiz.entity.*; -import org.ofbiz.widget.html.*; +import org.ofbiz.widget.renderer.html.HtmlFormWrapper; orderId = request.getParameter("orderId"); orderTypeId = null; diff --git a/applications/product/webapp/catalog/WEB-INF/actions/config/EditProductConfigItemContent.groovy b/applications/product/webapp/catalog/WEB-INF/actions/config/EditProductConfigItemContent.groovy index 5ce758f1b4..7fae990d47 100644 --- a/applications/product/webapp/catalog/WEB-INF/actions/config/EditProductConfigItemContent.groovy +++ b/applications/product/webapp/catalog/WEB-INF/actions/config/EditProductConfigItemContent.groovy @@ -21,7 +21,7 @@ import org.ofbiz.base.util.* import org.ofbiz.base.util.string.* import org.ofbiz.entity.* import org.ofbiz.entity.util.EntityUtilProperties; -import org.ofbiz.widget.html.* +import org.ofbiz.widget.renderer.html.HtmlFormWrapper; // make the image file formats imageFilenameFormat = "configitems/${configItemId}"; diff --git a/applications/product/webapp/catalog/WEB-INF/actions/config/EditProductConfigItemContentContent.groovy b/applications/product/webapp/catalog/WEB-INF/actions/config/EditProductConfigItemContentContent.groovy index 0370d1ef85..65f1414980 100644 --- a/applications/product/webapp/catalog/WEB-INF/actions/config/EditProductConfigItemContentContent.groovy +++ b/applications/product/webapp/catalog/WEB-INF/actions/config/EditProductConfigItemContentContent.groovy @@ -20,7 +20,7 @@ import org.ofbiz.entity.*; import org.ofbiz.entity.util.*; import org.ofbiz.base.util.*; -import org.ofbiz.widget.html.*; +import org.ofbiz.widget.renderer.html.HtmlFormWrapper; contentId = request.getParameter("contentId") ?: null; diff --git a/applications/product/webapp/catalog/WEB-INF/actions/config/EditProductConfigOptions.groovy b/applications/product/webapp/catalog/WEB-INF/actions/config/EditProductConfigOptions.groovy index bd3a6e4cc9..4db0b0ef6d 100644 --- a/applications/product/webapp/catalog/WEB-INF/actions/config/EditProductConfigOptions.groovy +++ b/applications/product/webapp/catalog/WEB-INF/actions/config/EditProductConfigOptions.groovy @@ -17,7 +17,7 @@ * under the License. */ -import org.ofbiz.widget.html.* +import org.ofbiz.widget.renderer.html.HtmlFormWrapper createConfigOptionWrapper = new HtmlFormWrapper("component://product/widget/catalog/ConfigForms.xml", "CreateConfigOption", request, response); createConfigOptionWrapper.putInContext("configItemId", configItemId); diff --git a/applications/product/webapp/facility/WEB-INF/actions/shipment/EditShipment.groovy b/applications/product/webapp/facility/WEB-INF/actions/shipment/EditShipment.groovy index a6e5372aaa..7afbd43673 100644 --- a/applications/product/webapp/facility/WEB-INF/actions/shipment/EditShipment.groovy +++ b/applications/product/webapp/facility/WEB-INF/actions/shipment/EditShipment.groovy @@ -18,7 +18,7 @@ */ import org.ofbiz.entity.condition.* -import org.ofbiz.widget.html.HtmlFormWrapper +import org.ofbiz.widget.renderer.html.HtmlFormWrapper shipmentId = parameters.shipmentId; shipment = from("Shipment").where("shipmentId", shipmentId).queryOne(); diff --git a/applications/product/webapp/facility/WEB-INF/actions/shipment/EditShipmentPlan.groovy b/applications/product/webapp/facility/WEB-INF/actions/shipment/EditShipmentPlan.groovy index d5288c6acb..aa1733525c 100644 --- a/applications/product/webapp/facility/WEB-INF/actions/shipment/EditShipmentPlan.groovy +++ b/applications/product/webapp/facility/WEB-INF/actions/shipment/EditShipmentPlan.groovy @@ -17,7 +17,7 @@ * under the License. */ -import org.ofbiz.widget.html.*; +import org.ofbiz.widget.renderer.html.HtmlFormWrapper; import org.ofbiz.entity.condition.EntityCondition; shipmentId = request.getParameter("shipmentId"); diff --git a/framework/common/src/org/ofbiz/common/email/EmailServices.java b/framework/common/src/org/ofbiz/common/email/EmailServices.java index 475a8f185d..477eb089b7 100644 --- a/framework/common/src/org/ofbiz/common/email/EmailServices.java +++ b/framework/common/src/org/ofbiz/common/email/EmailServices.java @@ -73,9 +73,9 @@ import org.ofbiz.service.LocalDispatcher; import org.ofbiz.service.ServiceUtil; import org.ofbiz.service.mail.MimeMessageWrapper; import org.ofbiz.webapp.view.ApacheFopWorker; -import org.ofbiz.widget.fo.FoScreenRenderer; -import org.ofbiz.widget.html.HtmlScreenRenderer; -import org.ofbiz.widget.screen.ScreenRenderer; +import org.ofbiz.widget.renderer.fo.FoScreenRenderer; +import org.ofbiz.widget.renderer.html.HtmlScreenRenderer; +import org.ofbiz.widget.renderer.ScreenRenderer; import org.xml.sax.SAXException; import com.sun.mail.smtp.SMTPAddressFailedException; diff --git a/framework/common/webcommon/WEB-INF/handlers-controller.xml b/framework/common/webcommon/WEB-INF/handlers-controller.xml index 23802a7ee7..eb083c3df5 100644 --- a/framework/common/webcommon/WEB-INF/handlers-controller.xml +++ b/framework/common/webcommon/WEB-INF/handlers-controller.xml @@ -35,11 +35,11 @@ under the License. - - - - - + + + + + diff --git a/framework/common/widget/PortalPageScreens.xml b/framework/common/widget/PortalPageScreens.xml index 17a7a08637..0c2c16c739 100644 --- a/framework/common/widget/PortalPageScreens.xml +++ b/framework/common/widget/PortalPageScreens.xml @@ -94,7 +94,7 @@ under the License. - + diff --git a/framework/resources/templates/web.xml b/framework/resources/templates/web.xml index 2ea774700b..3e672cb4d5 100644 --- a/framework/resources/templates/web.xml +++ b/framework/resources/templates/web.xml @@ -26,7 +26,7 @@ widgetVerbose false - Enable widget boundary comments. See org.ofbiz.widget.ModelWidget.widgetBoundaryCommentsEnabled(). + Enable widget boundary comments. See org.ofbiz.widget.model.ModelWidget.widgetBoundaryCommentsEnabled(). --> diff --git a/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ArtifactInfoFactory.java b/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ArtifactInfoFactory.java index b82da97b3f..c64cdae2c4 100644 --- a/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ArtifactInfoFactory.java +++ b/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ArtifactInfoFactory.java @@ -42,12 +42,13 @@ import org.ofbiz.base.util.FileUtil; import org.ofbiz.base.util.GeneralException; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.base.util.cache.UtilCache; +import org.ofbiz.entity.Delegator; +import org.ofbiz.entity.DelegatorFactory; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.config.model.DelegatorElement; import org.ofbiz.entity.config.model.EntityConfig; import org.ofbiz.entity.model.ModelEntity; import org.ofbiz.entity.model.ModelReader; -import org.ofbiz.entity.*; import org.ofbiz.service.DispatchContext; import org.ofbiz.service.GenericServiceException; import org.ofbiz.service.LocalDispatcher; @@ -57,10 +58,10 @@ import org.ofbiz.service.eca.ServiceEcaRule; import org.ofbiz.webapp.control.ConfigXMLReader; import org.ofbiz.webapp.control.ConfigXMLReader.ControllerConfig; import org.ofbiz.webapp.control.WebAppConfigurationException; -import org.ofbiz.widget.form.FormFactory; -import org.ofbiz.widget.form.ModelForm; -import org.ofbiz.widget.screen.ModelScreen; -import org.ofbiz.widget.screen.ScreenFactory; +import org.ofbiz.widget.model.FormFactory; +import org.ofbiz.widget.model.ModelForm; +import org.ofbiz.widget.model.ModelScreen; +import org.ofbiz.widget.model.ScreenFactory; import org.xml.sax.SAXException; public class ArtifactInfoFactory { diff --git a/framework/webtools/src/org/ofbiz/webtools/artifactinfo/FormWidgetArtifactInfo.java b/framework/webtools/src/org/ofbiz/webtools/artifactinfo/FormWidgetArtifactInfo.java index 7828dd3db8..46f0f9303a 100644 --- a/framework/webtools/src/org/ofbiz/webtools/artifactinfo/FormWidgetArtifactInfo.java +++ b/framework/webtools/src/org/ofbiz/webtools/artifactinfo/FormWidgetArtifactInfo.java @@ -33,7 +33,7 @@ import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilURL; import org.ofbiz.widget.artifact.ArtifactInfoContext; import org.ofbiz.widget.artifact.ArtifactInfoGatherer; -import org.ofbiz.widget.form.ModelForm; +import org.ofbiz.widget.model.ModelForm; import org.xml.sax.SAXException; /** diff --git a/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ScreenWidgetArtifactInfo.java b/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ScreenWidgetArtifactInfo.java index f3ee2024f7..2c2544fc7a 100644 --- a/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ScreenWidgetArtifactInfo.java +++ b/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ScreenWidgetArtifactInfo.java @@ -35,7 +35,7 @@ import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilURL; import org.ofbiz.widget.artifact.ArtifactInfoContext; import org.ofbiz.widget.artifact.ArtifactInfoGatherer; -import org.ofbiz.widget.screen.ModelScreen; +import org.ofbiz.widget.model.ModelScreen; import org.xml.sax.SAXException; /** diff --git a/framework/webtools/src/org/ofbiz/webtools/print/FoPrintServerEvents.java b/framework/webtools/src/org/ofbiz/webtools/print/FoPrintServerEvents.java index cdc032e4a8..53d6a26a0f 100644 --- a/framework/webtools/src/org/ofbiz/webtools/print/FoPrintServerEvents.java +++ b/framework/webtools/src/org/ofbiz/webtools/print/FoPrintServerEvents.java @@ -36,8 +36,8 @@ import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.entity.GenericValue; import org.ofbiz.entity.GenericEntityException; -import org.ofbiz.widget.screen.ScreenRenderer; -import org.ofbiz.widget.html.HtmlScreenRenderer; +import org.ofbiz.widget.renderer.ScreenRenderer; +import org.ofbiz.widget.renderer.html.HtmlScreenRenderer; /** * FoPrintServerEvents diff --git a/framework/widget/config/freemarkerTransforms.properties b/framework/widget/config/freemarkerTransforms.properties index 82b64b86d7..5b783e24a5 100644 --- a/framework/widget/config/freemarkerTransforms.properties +++ b/framework/widget/config/freemarkerTransforms.properties @@ -21,4 +21,4 @@ # entries are in the form: key=transform name, property=transform class name -menuWrap=org.ofbiz.widget.menu.MenuWrapTransform +menuWrap=org.ofbiz.widget.renderer.MenuWrapTransform diff --git a/framework/widget/src/org/ofbiz/widget/WidgetFactory.java b/framework/widget/src/org/ofbiz/widget/WidgetFactory.java index 5b9f591989..a6f1cc2f31 100644 --- a/framework/widget/src/org/ofbiz/widget/WidgetFactory.java +++ b/framework/widget/src/org/ofbiz/widget/WidgetFactory.java @@ -29,9 +29,9 @@ import java.util.concurrent.ConcurrentHashMap; import org.ofbiz.base.util.Assert; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilGenerics; -import org.ofbiz.widget.screen.IterateSectionWidget; -import org.ofbiz.widget.screen.ModelScreen; -import org.ofbiz.widget.screen.ModelScreenWidget; +import org.ofbiz.widget.model.IterateSectionWidget; +import org.ofbiz.widget.model.ModelScreen; +import org.ofbiz.widget.model.ModelScreenWidget; import org.w3c.dom.Element; /** diff --git a/framework/widget/src/org/ofbiz/widget/WidgetWorker.java b/framework/widget/src/org/ofbiz/widget/WidgetWorker.java index 093288d0b8..18a7be35a2 100644 --- a/framework/widget/src/org/ofbiz/widget/WidgetWorker.java +++ b/framework/widget/src/org/ofbiz/widget/WidgetWorker.java @@ -39,8 +39,8 @@ import org.ofbiz.webapp.control.ConfigXMLReader; import org.ofbiz.webapp.control.RequestHandler; import org.ofbiz.webapp.control.WebAppConfigurationException; import org.ofbiz.webapp.taglib.ContentUrlTag; -import org.ofbiz.widget.form.ModelForm; -import org.ofbiz.widget.form.ModelFormField; +import org.ofbiz.widget.model.ModelForm; +import org.ofbiz.widget.model.ModelFormField; public final class WidgetWorker { diff --git a/framework/widget/src/org/ofbiz/widget/artifact/ArtifactInfoGatherer.java b/framework/widget/src/org/ofbiz/widget/artifact/ArtifactInfoGatherer.java index 4bfde5a162..a8fb7ee554 100644 --- a/framework/widget/src/org/ofbiz/widget/artifact/ArtifactInfoGatherer.java +++ b/framework/widget/src/org/ofbiz/widget/artifact/ArtifactInfoGatherer.java @@ -23,83 +23,83 @@ import java.util.Set; import org.ofbiz.base.util.GeneralException; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.webapp.control.ConfigXMLReader; -import org.ofbiz.widget.AbstractModelAction.EntityAnd; -import org.ofbiz.widget.AbstractModelAction.EntityCondition; -import org.ofbiz.widget.AbstractModelAction.EntityOne; -import org.ofbiz.widget.AbstractModelAction.GetRelated; -import org.ofbiz.widget.AbstractModelAction.GetRelatedOne; -import org.ofbiz.widget.AbstractModelAction.PropertyMap; -import org.ofbiz.widget.AbstractModelAction.PropertyToField; -import org.ofbiz.widget.AbstractModelAction.Script; -import org.ofbiz.widget.AbstractModelAction.Service; -import org.ofbiz.widget.AbstractModelAction.SetField; -import org.ofbiz.widget.ModelAction; -import org.ofbiz.widget.ModelActionVisitor; -import org.ofbiz.widget.ModelFieldVisitor; -import org.ofbiz.widget.ModelWidgetVisitor; -import org.ofbiz.widget.form.FieldInfo; -import org.ofbiz.widget.form.ModelForm; -import org.ofbiz.widget.form.ModelForm.AltTarget; -import org.ofbiz.widget.form.ModelForm.AutoFieldsEntity; -import org.ofbiz.widget.form.ModelForm.AutoFieldsService; -import org.ofbiz.widget.form.ModelFormAction; -import org.ofbiz.widget.form.ModelFormAction.CallParentActions; -import org.ofbiz.widget.form.ModelFormField; -import org.ofbiz.widget.form.ModelFormField.CheckField; -import org.ofbiz.widget.form.ModelFormField.ContainerField; -import org.ofbiz.widget.form.ModelFormField.DateFindField; -import org.ofbiz.widget.form.ModelFormField.DateTimeField; -import org.ofbiz.widget.form.ModelFormField.DisplayEntityField; -import org.ofbiz.widget.form.ModelFormField.DisplayField; -import org.ofbiz.widget.form.ModelFormField.DropDownField; -import org.ofbiz.widget.form.ModelFormField.FieldInfoWithOptions; -import org.ofbiz.widget.form.ModelFormField.FileField; -import org.ofbiz.widget.form.ModelFormField.HiddenField; -import org.ofbiz.widget.form.ModelFormField.HyperlinkField; -import org.ofbiz.widget.form.ModelFormField.IgnoredField; -import org.ofbiz.widget.form.ModelFormField.ImageField; -import org.ofbiz.widget.form.ModelFormField.LookupField; -import org.ofbiz.widget.form.ModelFormField.PasswordField; -import org.ofbiz.widget.form.ModelFormField.RadioField; -import org.ofbiz.widget.form.ModelFormField.RangeFindField; -import org.ofbiz.widget.form.ModelFormField.ResetField; -import org.ofbiz.widget.form.ModelFormField.SubmitField; -import org.ofbiz.widget.form.ModelFormField.TextField; -import org.ofbiz.widget.form.ModelFormField.TextFindField; -import org.ofbiz.widget.form.ModelFormField.TextareaField; -import org.ofbiz.widget.menu.ModelMenu; -import org.ofbiz.widget.menu.ModelMenuAction; -import org.ofbiz.widget.menu.ModelMenuItem; -import org.ofbiz.widget.screen.HtmlWidget; -import org.ofbiz.widget.screen.HtmlWidget.HtmlTemplate; -import org.ofbiz.widget.screen.HtmlWidget.HtmlTemplateDecorator; -import org.ofbiz.widget.screen.HtmlWidget.HtmlTemplateDecoratorSection; -import org.ofbiz.widget.screen.IterateSectionWidget; -import org.ofbiz.widget.screen.ModelScreen; -import org.ofbiz.widget.screen.ModelScreenWidget; -import org.ofbiz.widget.screen.ModelScreenWidget.Column; -import org.ofbiz.widget.screen.ModelScreenWidget.ColumnContainer; -import org.ofbiz.widget.screen.ModelScreenWidget.Container; -import org.ofbiz.widget.screen.ModelScreenWidget.Content; -import org.ofbiz.widget.screen.ModelScreenWidget.DecoratorScreen; -import org.ofbiz.widget.screen.ModelScreenWidget.DecoratorSection; -import org.ofbiz.widget.screen.ModelScreenWidget.DecoratorSectionInclude; -import org.ofbiz.widget.screen.ModelScreenWidget.Form; -import org.ofbiz.widget.screen.ModelScreenWidget.HorizontalSeparator; -import org.ofbiz.widget.screen.ModelScreenWidget.ScreenImage; -import org.ofbiz.widget.screen.ModelScreenWidget.IncludeScreen; -import org.ofbiz.widget.screen.ModelScreenWidget.Label; -import org.ofbiz.widget.screen.ModelScreenWidget.ScreenLink; -import org.ofbiz.widget.screen.ModelScreenWidget.Menu; -import org.ofbiz.widget.screen.ModelScreenWidget.PlatformSpecific; -import org.ofbiz.widget.screen.ModelScreenWidget.PortalPage; -import org.ofbiz.widget.screen.ModelScreenWidget.Screenlet; -import org.ofbiz.widget.screen.ModelScreenWidget.Section; -import org.ofbiz.widget.screen.ModelScreenWidget.Tree; -import org.ofbiz.widget.tree.ModelTree; -import org.ofbiz.widget.tree.ModelTree.ModelNode; -import org.ofbiz.widget.tree.ModelTree.ModelNode.ModelSubNode; -import org.ofbiz.widget.tree.ModelTreeAction; +import org.ofbiz.widget.model.AbstractModelAction.EntityAnd; +import org.ofbiz.widget.model.AbstractModelAction.EntityCondition; +import org.ofbiz.widget.model.AbstractModelAction.EntityOne; +import org.ofbiz.widget.model.AbstractModelAction.GetRelated; +import org.ofbiz.widget.model.AbstractModelAction.GetRelatedOne; +import org.ofbiz.widget.model.AbstractModelAction.PropertyMap; +import org.ofbiz.widget.model.AbstractModelAction.PropertyToField; +import org.ofbiz.widget.model.AbstractModelAction.Script; +import org.ofbiz.widget.model.AbstractModelAction.Service; +import org.ofbiz.widget.model.AbstractModelAction.SetField; +import org.ofbiz.widget.model.FieldInfo; +import org.ofbiz.widget.model.HtmlWidget; +import org.ofbiz.widget.model.HtmlWidget.HtmlTemplate; +import org.ofbiz.widget.model.HtmlWidget.HtmlTemplateDecorator; +import org.ofbiz.widget.model.HtmlWidget.HtmlTemplateDecoratorSection; +import org.ofbiz.widget.model.IterateSectionWidget; +import org.ofbiz.widget.model.ModelAction; +import org.ofbiz.widget.model.ModelActionVisitor; +import org.ofbiz.widget.model.ModelFieldVisitor; +import org.ofbiz.widget.model.ModelForm; +import org.ofbiz.widget.model.ModelForm.AltTarget; +import org.ofbiz.widget.model.ModelForm.AutoFieldsEntity; +import org.ofbiz.widget.model.ModelForm.AutoFieldsService; +import org.ofbiz.widget.model.ModelFormAction; +import org.ofbiz.widget.model.ModelFormAction.CallParentActions; +import org.ofbiz.widget.model.ModelFormField; +import org.ofbiz.widget.model.ModelFormField.CheckField; +import org.ofbiz.widget.model.ModelFormField.ContainerField; +import org.ofbiz.widget.model.ModelFormField.DateFindField; +import org.ofbiz.widget.model.ModelFormField.DateTimeField; +import org.ofbiz.widget.model.ModelFormField.DisplayEntityField; +import org.ofbiz.widget.model.ModelFormField.DisplayField; +import org.ofbiz.widget.model.ModelFormField.DropDownField; +import org.ofbiz.widget.model.ModelFormField.FieldInfoWithOptions; +import org.ofbiz.widget.model.ModelFormField.FileField; +import org.ofbiz.widget.model.ModelFormField.HiddenField; +import org.ofbiz.widget.model.ModelFormField.HyperlinkField; +import org.ofbiz.widget.model.ModelFormField.IgnoredField; +import org.ofbiz.widget.model.ModelFormField.ImageField; +import org.ofbiz.widget.model.ModelFormField.LookupField; +import org.ofbiz.widget.model.ModelFormField.PasswordField; +import org.ofbiz.widget.model.ModelFormField.RadioField; +import org.ofbiz.widget.model.ModelFormField.RangeFindField; +import org.ofbiz.widget.model.ModelFormField.ResetField; +import org.ofbiz.widget.model.ModelFormField.SubmitField; +import org.ofbiz.widget.model.ModelFormField.TextField; +import org.ofbiz.widget.model.ModelFormField.TextFindField; +import org.ofbiz.widget.model.ModelFormField.TextareaField; +import org.ofbiz.widget.model.ModelMenu; +import org.ofbiz.widget.model.ModelMenuAction; +import org.ofbiz.widget.model.ModelMenuItem; +import org.ofbiz.widget.model.ModelScreen; +import org.ofbiz.widget.model.ModelScreenWidget; +import org.ofbiz.widget.model.ModelScreenWidget.Column; +import org.ofbiz.widget.model.ModelScreenWidget.ColumnContainer; +import org.ofbiz.widget.model.ModelScreenWidget.Container; +import org.ofbiz.widget.model.ModelScreenWidget.Content; +import org.ofbiz.widget.model.ModelScreenWidget.DecoratorScreen; +import org.ofbiz.widget.model.ModelScreenWidget.DecoratorSection; +import org.ofbiz.widget.model.ModelScreenWidget.DecoratorSectionInclude; +import org.ofbiz.widget.model.ModelScreenWidget.Form; +import org.ofbiz.widget.model.ModelScreenWidget.HorizontalSeparator; +import org.ofbiz.widget.model.ModelScreenWidget.IncludeScreen; +import org.ofbiz.widget.model.ModelScreenWidget.Label; +import org.ofbiz.widget.model.ModelScreenWidget.Menu; +import org.ofbiz.widget.model.ModelScreenWidget.PlatformSpecific; +import org.ofbiz.widget.model.ModelScreenWidget.PortalPage; +import org.ofbiz.widget.model.ModelScreenWidget.ScreenImage; +import org.ofbiz.widget.model.ModelScreenWidget.ScreenLink; +import org.ofbiz.widget.model.ModelScreenWidget.Screenlet; +import org.ofbiz.widget.model.ModelScreenWidget.Section; +import org.ofbiz.widget.model.ModelScreenWidget.Tree; +import org.ofbiz.widget.model.ModelTree; +import org.ofbiz.widget.model.ModelTree.ModelNode; +import org.ofbiz.widget.model.ModelTree.ModelNode.ModelSubNode; +import org.ofbiz.widget.model.ModelTreeAction; +import org.ofbiz.widget.model.ModelWidgetVisitor; /** * An object that gathers artifact information from screen widgets. diff --git a/framework/widget/src/org/ofbiz/widget/ContentWorkerInterface.java b/framework/widget/src/org/ofbiz/widget/content/ContentWorkerInterface.java similarity index 97% rename from framework/widget/src/org/ofbiz/widget/ContentWorkerInterface.java rename to framework/widget/src/org/ofbiz/widget/content/ContentWorkerInterface.java index cceb618479..b83f6dbdd2 100644 --- a/framework/widget/src/org/ofbiz/widget/ContentWorkerInterface.java +++ b/framework/widget/src/org/ofbiz/widget/content/ContentWorkerInterface.java @@ -1,48 +1,48 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget; - -import java.io.IOException; -import java.util.List; -import java.util.Locale; -import java.util.Map; - -import org.ofbiz.base.util.GeneralException; -import org.ofbiz.entity.Delegator; -import org.ofbiz.entity.GenericEntityException; -import org.ofbiz.entity.GenericValue; -import org.ofbiz.service.LocalDispatcher; - -/** - * ContentWorkerInterface - */ -public interface ContentWorkerInterface { - - // helper methods - public GenericValue getCurrentContentExt(Delegator delegator, List> trail, GenericValue userLogin, Map ctx, Boolean nullThruDatesOnly, String contentAssocPredicateId) throws GeneralException; - public GenericValue getWebSitePublishPointExt(Delegator delegator, String contentId, boolean ignoreCache) throws GenericEntityException; - public String getMimeTypeIdExt(Delegator delegator, GenericValue view, Map ctx); - - // new rendering methods - public void renderContentAsTextExt(LocalDispatcher dispatcher, Delegator delegator, String contentId, Appendable out, Map templateContext, Locale locale, String mimeTypeId, boolean cache) throws GeneralException, IOException; - public String renderContentAsTextExt(LocalDispatcher dispatcher, Delegator delegator, String contentId, Map templateContext, Locale locale, String mimeTypeId, boolean cache) throws GeneralException, IOException; - - public void renderSubContentAsTextExt(LocalDispatcher dispatcher, Delegator delegator, String contentId, Appendable out, String mapKey, Map templateContext, Locale locale, String mimeTypeId, boolean cache) throws GeneralException, IOException; - public String renderSubContentAsTextExt(LocalDispatcher dispatcher, Delegator delegator, String contentId, String mapKey, Map templateContext, Locale locale, String mimeTypeId, boolean cache) throws GeneralException, IOException; -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.content; + +import java.io.IOException; +import java.util.List; +import java.util.Locale; +import java.util.Map; + +import org.ofbiz.base.util.GeneralException; +import org.ofbiz.entity.Delegator; +import org.ofbiz.entity.GenericEntityException; +import org.ofbiz.entity.GenericValue; +import org.ofbiz.service.LocalDispatcher; + +/** + * ContentWorkerInterface + */ +public interface ContentWorkerInterface { + + // helper methods + public GenericValue getCurrentContentExt(Delegator delegator, List> trail, GenericValue userLogin, Map ctx, Boolean nullThruDatesOnly, String contentAssocPredicateId) throws GeneralException; + public GenericValue getWebSitePublishPointExt(Delegator delegator, String contentId, boolean ignoreCache) throws GenericEntityException; + public String getMimeTypeIdExt(Delegator delegator, GenericValue view, Map ctx); + + // new rendering methods + public void renderContentAsTextExt(LocalDispatcher dispatcher, Delegator delegator, String contentId, Appendable out, Map templateContext, Locale locale, String mimeTypeId, boolean cache) throws GeneralException, IOException; + public String renderContentAsTextExt(LocalDispatcher dispatcher, Delegator delegator, String contentId, Map templateContext, Locale locale, String mimeTypeId, boolean cache) throws GeneralException, IOException; + + public void renderSubContentAsTextExt(LocalDispatcher dispatcher, Delegator delegator, String contentId, Appendable out, String mapKey, Map templateContext, Locale locale, String mimeTypeId, boolean cache) throws GeneralException, IOException; + public String renderSubContentAsTextExt(LocalDispatcher dispatcher, Delegator delegator, String contentId, String mapKey, Map templateContext, Locale locale, String mimeTypeId, boolean cache) throws GeneralException, IOException; +} diff --git a/framework/widget/src/org/ofbiz/widget/DataResourceWorkerInterface.java b/framework/widget/src/org/ofbiz/widget/content/DataResourceWorkerInterface.java similarity index 95% rename from framework/widget/src/org/ofbiz/widget/DataResourceWorkerInterface.java rename to framework/widget/src/org/ofbiz/widget/content/DataResourceWorkerInterface.java index 155ace3657..e0c505e3df 100644 --- a/framework/widget/src/org/ofbiz/widget/DataResourceWorkerInterface.java +++ b/framework/widget/src/org/ofbiz/widget/content/DataResourceWorkerInterface.java @@ -1,37 +1,37 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget; - -import java.io.IOException; -import java.util.Locale; -import java.util.Map; - -import org.ofbiz.base.util.GeneralException; -import org.ofbiz.entity.Delegator; - -/** - * ContentWorkerInterface - */ -public interface DataResourceWorkerInterface { - public String renderDataResourceAsTextExt(Delegator delegator, String dataResourceId, Map templateContext, - Locale locale, String targetMimeTypeId, boolean cache) throws GeneralException, IOException; - - public void renderDataResourceAsTextExt(Delegator delegator, String dataResourceId, Appendable out, Map templateContext, - Locale locale, String targetMimeTypeId, boolean cache) throws GeneralException, IOException; -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.content; + +import java.io.IOException; +import java.util.Locale; +import java.util.Map; + +import org.ofbiz.base.util.GeneralException; +import org.ofbiz.entity.Delegator; + +/** + * ContentWorkerInterface + */ +public interface DataResourceWorkerInterface { + public String renderDataResourceAsTextExt(Delegator delegator, String dataResourceId, Map templateContext, + Locale locale, String targetMimeTypeId, boolean cache) throws GeneralException, IOException; + + public void renderDataResourceAsTextExt(Delegator delegator, String dataResourceId, Appendable out, Map templateContext, + Locale locale, String targetMimeTypeId, boolean cache) throws GeneralException, IOException; +} diff --git a/framework/widget/src/org/ofbiz/widget/WidgetContentWorker.java b/framework/widget/src/org/ofbiz/widget/content/WidgetContentWorker.java similarity index 96% rename from framework/widget/src/org/ofbiz/widget/WidgetContentWorker.java rename to framework/widget/src/org/ofbiz/widget/content/WidgetContentWorker.java index c094d19699..edea2cfa25 100644 --- a/framework/widget/src/org/ofbiz/widget/WidgetContentWorker.java +++ b/framework/widget/src/org/ofbiz/widget/content/WidgetContentWorker.java @@ -1,42 +1,42 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget; - -import org.ofbiz.base.util.Debug; - -/** - * WidgetContentWorker Class - */ -public class WidgetContentWorker { - public static final String module = WidgetContentWorker.class.getName(); - public static ContentWorkerInterface contentWorker = null; - static { - try { - ClassLoader loader = Thread.currentThread().getContextClassLoader(); - // note: loadClass is necessary for these since this class doesn't know anything about them at compile time - contentWorker = (ContentWorkerInterface) loader.loadClass("org.ofbiz.content.content.ContentWorker").newInstance(); - } catch (ClassNotFoundException e) { - Debug.logError(e, "Could not pre-initialize dynamically loaded class: ", module); - } catch (IllegalAccessException e) { - Debug.logError(e, "Could not pre-initialize dynamically loaded class: ", module); - } catch (InstantiationException e) { - Debug.logError(e, "Could not pre-initialize dynamically loaded class: ", module); - } - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.content; + +import org.ofbiz.base.util.Debug; + +/** + * WidgetContentWorker Class + */ +public class WidgetContentWorker { + public static final String module = WidgetContentWorker.class.getName(); + public static ContentWorkerInterface contentWorker = null; + static { + try { + ClassLoader loader = Thread.currentThread().getContextClassLoader(); + // note: loadClass is necessary for these since this class doesn't know anything about them at compile time + contentWorker = (ContentWorkerInterface) loader.loadClass("org.ofbiz.content.content.ContentWorker").newInstance(); + } catch (ClassNotFoundException e) { + Debug.logError(e, "Could not pre-initialize dynamically loaded class: ", module); + } catch (IllegalAccessException e) { + Debug.logError(e, "Could not pre-initialize dynamically loaded class: ", module); + } catch (InstantiationException e) { + Debug.logError(e, "Could not pre-initialize dynamically loaded class: ", module); + } + } +} diff --git a/framework/widget/src/org/ofbiz/widget/WidgetDataResourceWorker.java b/framework/widget/src/org/ofbiz/widget/content/WidgetDataResourceWorker.java similarity index 96% rename from framework/widget/src/org/ofbiz/widget/WidgetDataResourceWorker.java rename to framework/widget/src/org/ofbiz/widget/content/WidgetDataResourceWorker.java index d19f42790a..afe2418dbd 100644 --- a/framework/widget/src/org/ofbiz/widget/WidgetDataResourceWorker.java +++ b/framework/widget/src/org/ofbiz/widget/content/WidgetDataResourceWorker.java @@ -1,42 +1,42 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget; - -import org.ofbiz.base.util.Debug; - -/** - * WidgetContentWorker Class - */ -public class WidgetDataResourceWorker { - public static final String module = WidgetDataResourceWorker.class.getName(); - public static DataResourceWorkerInterface dataresourceWorker = null; - static { - try { - ClassLoader loader = Thread.currentThread().getContextClassLoader(); - // note: loadClass is necessary for these since this class doesn't know anything about them at compile time - dataresourceWorker = (DataResourceWorkerInterface) loader.loadClass("org.ofbiz.content.data.DataResourceWorker").newInstance(); - } catch (ClassNotFoundException e) { - Debug.logError(e, "Could not pre-initialize dynamically loaded class: ", module); - } catch (IllegalAccessException e) { - Debug.logError(e, "Could not pre-initialize dynamically loaded class: ", module); - } catch (InstantiationException e) { - Debug.logError(e, "Could not pre-initialize dynamically loaded class: ", module); - } - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.content; + +import org.ofbiz.base.util.Debug; + +/** + * WidgetContentWorker Class + */ +public class WidgetDataResourceWorker { + public static final String module = WidgetDataResourceWorker.class.getName(); + public static DataResourceWorkerInterface dataresourceWorker = null; + static { + try { + ClassLoader loader = Thread.currentThread().getContextClassLoader(); + // note: loadClass is necessary for these since this class doesn't know anything about them at compile time + dataresourceWorker = (DataResourceWorkerInterface) loader.loadClass("org.ofbiz.content.data.DataResourceWorker").newInstance(); + } catch (ClassNotFoundException e) { + Debug.logError(e, "Could not pre-initialize dynamically loaded class: ", module); + } catch (IllegalAccessException e) { + Debug.logError(e, "Could not pre-initialize dynamically loaded class: ", module); + } catch (InstantiationException e) { + Debug.logError(e, "Could not pre-initialize dynamically loaded class: ", module); + } + } +} diff --git a/framework/widget/src/org/ofbiz/widget/AbstractModelAction.java b/framework/widget/src/org/ofbiz/widget/model/AbstractModelAction.java similarity index 97% rename from framework/widget/src/org/ofbiz/widget/AbstractModelAction.java rename to framework/widget/src/org/ofbiz/widget/model/AbstractModelAction.java index 0aacb3e2df..7ec655bc9a 100644 --- a/framework/widget/src/org/ofbiz/widget/AbstractModelAction.java +++ b/framework/widget/src/org/ofbiz/widget/model/AbstractModelAction.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. *******************************************************************************/ -package org.ofbiz.widget; +package org.ofbiz.widget.model; import java.io.Serializable; import java.text.MessageFormat; @@ -58,7 +58,7 @@ import org.ofbiz.minilang.method.MethodContext; import org.ofbiz.service.DispatchContext; import org.ofbiz.service.GenericServiceException; import org.ofbiz.service.ModelService; -import org.ofbiz.widget.xml.XmlWidgetActionVisitor; +import org.ofbiz.widget.WidgetWorker; import org.w3c.dom.Element; /** diff --git a/framework/widget/src/org/ofbiz/widget/AbstractModelCondition.java b/framework/widget/src/org/ofbiz/widget/model/AbstractModelCondition.java similarity index 97% rename from framework/widget/src/org/ofbiz/widget/AbstractModelCondition.java rename to framework/widget/src/org/ofbiz/widget/model/AbstractModelCondition.java index 7cb74b3cfa..d752f0b830 100644 --- a/framework/widget/src/org/ofbiz/widget/AbstractModelCondition.java +++ b/framework/widget/src/org/ofbiz/widget/model/AbstractModelCondition.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. *******************************************************************************/ -package org.ofbiz.widget; +package org.ofbiz.widget.model; import java.io.Serializable; import java.lang.reflect.Method; @@ -50,7 +50,6 @@ import org.ofbiz.service.GenericServiceException; import org.ofbiz.service.LocalDispatcher; import org.ofbiz.service.ModelService; import org.ofbiz.service.ServiceUtil; -import org.ofbiz.widget.xml.*; import org.w3c.dom.Element; /** diff --git a/framework/widget/src/org/ofbiz/widget/CommonWidgetModels.java b/framework/widget/src/org/ofbiz/widget/model/CommonWidgetModels.java similarity index 97% rename from framework/widget/src/org/ofbiz/widget/CommonWidgetModels.java rename to framework/widget/src/org/ofbiz/widget/model/CommonWidgetModels.java index dfd9f879f4..b538397835 100644 --- a/framework/widget/src/org/ofbiz/widget/CommonWidgetModels.java +++ b/framework/widget/src/org/ofbiz/widget/model/CommonWidgetModels.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. *******************************************************************************/ -package org.ofbiz.widget; +package org.ofbiz.widget.model; import java.math.BigDecimal; import java.text.DateFormat; diff --git a/framework/widget/src/org/ofbiz/widget/form/FieldInfo.java b/framework/widget/src/org/ofbiz/widget/model/FieldInfo.java similarity index 95% rename from framework/widget/src/org/ofbiz/widget/form/FieldInfo.java rename to framework/widget/src/org/ofbiz/widget/model/FieldInfo.java index dcb8ea305e..7bc47b3b36 100644 --- a/framework/widget/src/org/ofbiz/widget/form/FieldInfo.java +++ b/framework/widget/src/org/ofbiz/widget/model/FieldInfo.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. *******************************************************************************/ -package org.ofbiz.widget.form; +package org.ofbiz.widget.model; import java.io.IOException; import java.util.Collections; @@ -24,8 +24,7 @@ import java.util.HashMap; import java.util.Map; import org.ofbiz.base.util.Debug; -import org.ofbiz.widget.ModelFieldVisitor; -import org.ofbiz.widget.xml.XmlWidgetFieldVisitor; +import org.ofbiz.widget.renderer.FormStringRenderer; import org.w3c.dom.Element; /** diff --git a/framework/widget/src/org/ofbiz/widget/form/FormFactory.java b/framework/widget/src/org/ofbiz/widget/model/FormFactory.java similarity index 97% rename from framework/widget/src/org/ofbiz/widget/form/FormFactory.java rename to framework/widget/src/org/ofbiz/widget/model/FormFactory.java index 0729275664..a9ba4ade92 100644 --- a/framework/widget/src/org/ofbiz/widget/form/FormFactory.java +++ b/framework/widget/src/org/ofbiz/widget/model/FormFactory.java @@ -1,131 +1,131 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget.form; - -import java.io.IOException; -import java.net.URL; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletRequest; -import javax.xml.parsers.ParserConfigurationException; - -import org.ofbiz.base.location.FlexibleLocation; -import org.ofbiz.base.util.UtilHttp; -import org.ofbiz.base.util.UtilXml; -import org.ofbiz.base.util.cache.UtilCache; -import org.ofbiz.entity.Delegator; -import org.ofbiz.entity.model.ModelReader; -import org.ofbiz.service.DispatchContext; -import org.ofbiz.service.LocalDispatcher; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.xml.sax.SAXException; - - -/** - * Widget Library - Form factory class - */ -public class FormFactory { - - public static final String module = FormFactory.class.getName(); - private static final UtilCache formLocationCache = UtilCache.createUtilCache("widget.form.locationResource", 0, 0, false); - private static final UtilCache formWebappCache = UtilCache.createUtilCache("widget.form.webappResource", 0, 0, false); - - public static Map getFormsFromLocation(String resourceName, ModelReader entityModelReader, DispatchContext dispatchContext) - throws IOException, SAXException, ParserConfigurationException { - URL formFileUrl = FlexibleLocation.resolveLocation(resourceName); - Document formFileDoc = UtilXml.readXmlDocument(formFileUrl, true, true); - return readFormDocument(formFileDoc, entityModelReader, dispatchContext, resourceName); - } - - public static ModelForm getFormFromLocation(String resourceName, String formName, ModelReader entityModelReader, DispatchContext dispatchContext) - throws IOException, SAXException, ParserConfigurationException { - StringBuilder sb = new StringBuilder(dispatchContext.getDelegator().getDelegatorName()); - sb.append(":").append(resourceName).append("#").append(formName); - String cacheKey = sb.toString(); - ModelForm modelForm = formLocationCache.get(cacheKey); - if (modelForm == null) { - URL formFileUrl = FlexibleLocation.resolveLocation(resourceName); - Document formFileDoc = UtilXml.readXmlDocument(formFileUrl, true, true); - if (formFileDoc == null) { - throw new IllegalArgumentException("Could not find resource [" + resourceName + "]"); - } - modelForm = createModelForm(formFileDoc, entityModelReader, dispatchContext, resourceName, formName); - modelForm = formLocationCache.putIfAbsentAndGet(cacheKey, modelForm); - } - if (modelForm == null) { - throw new IllegalArgumentException("Could not find form with name [" + formName + "] in class resource [" + resourceName + "]"); - } - return modelForm; - } - - public static ModelForm getFormFromWebappContext(String resourceName, String formName, HttpServletRequest request) - throws IOException, SAXException, ParserConfigurationException { - String webappName = UtilHttp.getApplicationName(request); - String cacheKey = webappName + "::" + resourceName + "::" + formName; - ModelForm modelForm = formWebappCache.get(cacheKey); - if (modelForm == null) { - ServletContext servletContext = (ServletContext) request.getAttribute("servletContext"); - Delegator delegator = (Delegator) request.getAttribute("delegator"); - LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher"); - URL formFileUrl = servletContext.getResource(resourceName); - Document formFileDoc = UtilXml.readXmlDocument(formFileUrl, true, true); - Element formElement = UtilXml.firstChildElement(formFileDoc.getDocumentElement(), "form", "name", formName); - modelForm = new ModelForm(formElement, resourceName, delegator.getModelReader(), dispatcher.getDispatchContext()); - modelForm = formWebappCache.putIfAbsentAndGet(cacheKey, modelForm); - } - if (modelForm == null) { - throw new IllegalArgumentException("Could not find form with name [" + formName + "] in webapp resource [" + resourceName + "] in the webapp [" + webappName + "]"); - } - return modelForm; - } - - public static Map readFormDocument(Document formFileDoc, ModelReader entityModelReader, DispatchContext dispatchContext, String formLocation) { - Map modelFormMap = new HashMap(); - if (formFileDoc != null) { - // read document and construct ModelForm for each form element - Element rootElement = formFileDoc.getDocumentElement(); - List formElements = UtilXml.childElementList(rootElement, "form"); - for (Element formElement : formElements) { - String formName = formElement.getAttribute("name"); - String cacheKey = formLocation + "#" + formName; - ModelForm modelForm = formLocationCache.get(cacheKey); - if (modelForm == null) { - modelForm = createModelForm(formElement, entityModelReader, dispatchContext, formLocation, formName); - modelForm = formLocationCache.putIfAbsentAndGet(cacheKey, modelForm); - } - modelFormMap.put(formName, modelForm); - } - } - return modelFormMap; - } - - public static ModelForm createModelForm(Document formFileDoc, ModelReader entityModelReader, DispatchContext dispatchContext, String formLocation, String formName) { - Element formElement = UtilXml.firstChildElement(formFileDoc.getDocumentElement(), "form", "name", formName); - return createModelForm(formElement, entityModelReader, dispatchContext, formLocation, formName); - } - - public static ModelForm createModelForm(Element formElement, ModelReader entityModelReader, DispatchContext dispatchContext, String formLocation, String formName) { - ModelForm modelForm = new ModelForm(formElement, formLocation, entityModelReader, dispatchContext); - return modelForm; - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.model; + +import java.io.IOException; +import java.net.URL; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import javax.xml.parsers.ParserConfigurationException; + +import org.ofbiz.base.location.FlexibleLocation; +import org.ofbiz.base.util.UtilHttp; +import org.ofbiz.base.util.UtilXml; +import org.ofbiz.base.util.cache.UtilCache; +import org.ofbiz.entity.Delegator; +import org.ofbiz.entity.model.ModelReader; +import org.ofbiz.service.DispatchContext; +import org.ofbiz.service.LocalDispatcher; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.xml.sax.SAXException; + + +/** + * Widget Library - Form factory class + */ +public class FormFactory { + + public static final String module = FormFactory.class.getName(); + private static final UtilCache formLocationCache = UtilCache.createUtilCache("widget.form.locationResource", 0, 0, false); + private static final UtilCache formWebappCache = UtilCache.createUtilCache("widget.form.webappResource", 0, 0, false); + + public static Map getFormsFromLocation(String resourceName, ModelReader entityModelReader, DispatchContext dispatchContext) + throws IOException, SAXException, ParserConfigurationException { + URL formFileUrl = FlexibleLocation.resolveLocation(resourceName); + Document formFileDoc = UtilXml.readXmlDocument(formFileUrl, true, true); + return readFormDocument(formFileDoc, entityModelReader, dispatchContext, resourceName); + } + + public static ModelForm getFormFromLocation(String resourceName, String formName, ModelReader entityModelReader, DispatchContext dispatchContext) + throws IOException, SAXException, ParserConfigurationException { + StringBuilder sb = new StringBuilder(dispatchContext.getDelegator().getDelegatorName()); + sb.append(":").append(resourceName).append("#").append(formName); + String cacheKey = sb.toString(); + ModelForm modelForm = formLocationCache.get(cacheKey); + if (modelForm == null) { + URL formFileUrl = FlexibleLocation.resolveLocation(resourceName); + Document formFileDoc = UtilXml.readXmlDocument(formFileUrl, true, true); + if (formFileDoc == null) { + throw new IllegalArgumentException("Could not find resource [" + resourceName + "]"); + } + modelForm = createModelForm(formFileDoc, entityModelReader, dispatchContext, resourceName, formName); + modelForm = formLocationCache.putIfAbsentAndGet(cacheKey, modelForm); + } + if (modelForm == null) { + throw new IllegalArgumentException("Could not find form with name [" + formName + "] in class resource [" + resourceName + "]"); + } + return modelForm; + } + + public static ModelForm getFormFromWebappContext(String resourceName, String formName, HttpServletRequest request) + throws IOException, SAXException, ParserConfigurationException { + String webappName = UtilHttp.getApplicationName(request); + String cacheKey = webappName + "::" + resourceName + "::" + formName; + ModelForm modelForm = formWebappCache.get(cacheKey); + if (modelForm == null) { + ServletContext servletContext = (ServletContext) request.getAttribute("servletContext"); + Delegator delegator = (Delegator) request.getAttribute("delegator"); + LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher"); + URL formFileUrl = servletContext.getResource(resourceName); + Document formFileDoc = UtilXml.readXmlDocument(formFileUrl, true, true); + Element formElement = UtilXml.firstChildElement(formFileDoc.getDocumentElement(), "form", "name", formName); + modelForm = new ModelForm(formElement, resourceName, delegator.getModelReader(), dispatcher.getDispatchContext()); + modelForm = formWebappCache.putIfAbsentAndGet(cacheKey, modelForm); + } + if (modelForm == null) { + throw new IllegalArgumentException("Could not find form with name [" + formName + "] in webapp resource [" + resourceName + "] in the webapp [" + webappName + "]"); + } + return modelForm; + } + + public static Map readFormDocument(Document formFileDoc, ModelReader entityModelReader, DispatchContext dispatchContext, String formLocation) { + Map modelFormMap = new HashMap(); + if (formFileDoc != null) { + // read document and construct ModelForm for each form element + Element rootElement = formFileDoc.getDocumentElement(); + List formElements = UtilXml.childElementList(rootElement, "form"); + for (Element formElement : formElements) { + String formName = formElement.getAttribute("name"); + String cacheKey = formLocation + "#" + formName; + ModelForm modelForm = formLocationCache.get(cacheKey); + if (modelForm == null) { + modelForm = createModelForm(formElement, entityModelReader, dispatchContext, formLocation, formName); + modelForm = formLocationCache.putIfAbsentAndGet(cacheKey, modelForm); + } + modelFormMap.put(formName, modelForm); + } + } + return modelFormMap; + } + + public static ModelForm createModelForm(Document formFileDoc, ModelReader entityModelReader, DispatchContext dispatchContext, String formLocation, String formName) { + Element formElement = UtilXml.firstChildElement(formFileDoc.getDocumentElement(), "form", "name", formName); + return createModelForm(formElement, entityModelReader, dispatchContext, formLocation, formName); + } + + public static ModelForm createModelForm(Element formElement, ModelReader entityModelReader, DispatchContext dispatchContext, String formLocation, String formName) { + ModelForm modelForm = new ModelForm(formElement, formLocation, entityModelReader, dispatchContext); + return modelForm; + } +} diff --git a/framework/widget/src/org/ofbiz/widget/screen/HtmlWidget.java b/framework/widget/src/org/ofbiz/widget/model/HtmlWidget.java similarity index 96% rename from framework/widget/src/org/ofbiz/widget/screen/HtmlWidget.java rename to framework/widget/src/org/ofbiz/widget/model/HtmlWidget.java index c74cb2bf60..66bb671e66 100644 --- a/framework/widget/src/org/ofbiz/widget/screen/HtmlWidget.java +++ b/framework/widget/src/org/ofbiz/widget/model/HtmlWidget.java @@ -1,312 +1,311 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget.screen; - -import java.io.IOException; -import java.net.MalformedURLException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.GeneralException; -import org.ofbiz.base.util.StringUtil; -import org.ofbiz.base.util.UtilCodec; -import org.ofbiz.base.util.UtilGenerics; -import org.ofbiz.base.util.UtilValidate; -import org.ofbiz.base.util.UtilXml; -import org.ofbiz.base.util.cache.UtilCache; -import org.ofbiz.base.util.collections.MapStack; -import org.ofbiz.base.util.string.FlexibleStringExpander; -import org.ofbiz.base.util.template.FreeMarkerWorker; -import org.ofbiz.widget.ModelWidget; -import org.ofbiz.widget.ModelWidgetVisitor; -import org.ofbiz.widget.html.HtmlWidgetRenderer; -import org.w3c.dom.Element; - -import freemarker.ext.beans.BeansWrapper; -import freemarker.ext.beans.CollectionModel; -import freemarker.ext.beans.StringModel; -import freemarker.template.Configuration; -import freemarker.template.Template; -import freemarker.template.TemplateException; -import freemarker.template.TemplateModel; -import freemarker.template.TemplateModelException; -import freemarker.template.Version; - -/** - * Widget Library - Screen model HTML class. - */ -@SuppressWarnings("serial") -public class HtmlWidget extends ModelScreenWidget { - public static final String module = HtmlWidget.class.getName(); - - private static final UtilCache specialTemplateCache = UtilCache.createUtilCache("widget.screen.template.ftl.general", 0, 0, false); - protected static Configuration specialConfig = FreeMarkerWorker.makeConfiguration(new ExtendedWrapper(FreeMarkerWorker.version)); - - // not sure if this is the best way to get FTL to use my fancy MapModel derivative, but should work at least... - public static class ExtendedWrapper extends BeansWrapper { - public ExtendedWrapper(Version version) { - super(version); - } - - @Override - public TemplateModel wrap(Object object) throws TemplateModelException { - // This StringHtmlWrapperForFtl option seems to be the best option - // and handles most things without causing too many problems - if (object instanceof String) { - return new StringHtmlWrapperForFtl((String) object, this); - } else if (object instanceof Collection && !(object instanceof Map)) { - // An additional wrapper to ensure ${aCollection} is properly encoded for html - return new CollectionHtmlWrapperForFtl((Collection) object, this); - } - return super.wrap(object); - } - } - - public static class StringHtmlWrapperForFtl extends StringModel { - public StringHtmlWrapperForFtl(String str, BeansWrapper wrapper) { - super(str, wrapper); - } - @Override - public String getAsString() { - return UtilCodec.getEncoder("html").encode(super.getAsString()); - } - } - - public static class CollectionHtmlWrapperForFtl extends CollectionModel { - - public CollectionHtmlWrapperForFtl(Collection collection, BeansWrapper wrapper) { - super(collection, wrapper); - } - - @Override - public String getAsString() { - return UtilCodec.getEncoder("html").encode(super.getAsString()); - } - - } - - // End Static, begin class section - - private final List subWidgets; - - public HtmlWidget(ModelScreen modelScreen, Element htmlElement) { - super(modelScreen, htmlElement); - List childElementList = UtilXml.childElementList(htmlElement); - if (childElementList.isEmpty()) { - this.subWidgets = Collections.emptyList(); - } else { - List subWidgets = new ArrayList(childElementList.size()); - for (Element childElement : childElementList) { - if ("html-template".equals(childElement.getNodeName())) { - subWidgets.add(new HtmlTemplate(modelScreen, childElement)); - } else if ("html-template-decorator".equals(childElement.getNodeName())) { - subWidgets.add(new HtmlTemplateDecorator(modelScreen, childElement)); - } else { - throw new IllegalArgumentException("Tag not supported under the platform-specific -> html tag with name: " - + childElement.getNodeName()); - } - } - this.subWidgets = Collections.unmodifiableList(subWidgets); - } - } - - public List getSubWidgets() { - return subWidgets; - } - - @Override - public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException, IOException { - for (ModelScreenWidget subWidget : subWidgets) { - subWidget.renderWidgetString(writer, context, screenStringRenderer); - } - } - - public static void renderHtmlTemplate(Appendable writer, FlexibleStringExpander locationExdr, Map context) { - String location = locationExdr.expandString(context); - //Debug.logInfo("Rendering template at location [" + location + "] with context: \n" + context, module); - - if (UtilValidate.isEmpty(location)) { - throw new IllegalArgumentException("Template location is empty"); - } - - if (location.endsWith(".ftl")) { - try { - Map parameters = UtilGenerics.checkMap(context.get("parameters")); - boolean insertWidgetBoundaryComments = ModelWidget.widgetBoundaryCommentsEnabled(parameters); - if (insertWidgetBoundaryComments) { - writer.append(HtmlWidgetRenderer.formatBoundaryComment("Begin", "Template", location)); - } - - //FreeMarkerWorker.renderTemplateAtLocation(location, context, writer); - Template template = null; - if (location.endsWith(".fo.ftl")) { // FOP can't render correctly escaped characters - template = FreeMarkerWorker.getTemplate(location); - } else { - template = FreeMarkerWorker.getTemplate(location, specialTemplateCache, specialConfig); - } - FreeMarkerWorker.renderTemplate(template, context, writer); - - if (insertWidgetBoundaryComments) { - writer.append(HtmlWidgetRenderer.formatBoundaryComment("End", "Template", location)); - } - } catch (IllegalArgumentException e) { - String errMsg = "Error rendering included template at location [" + location + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - writeError(writer, errMsg); - } catch (MalformedURLException e) { - String errMsg = "Error rendering included template at location [" + location + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - writeError(writer, errMsg); - } catch (TemplateException e) { - String errMsg = "Error rendering included template at location [" + location + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - writeError(writer, errMsg); - } catch (IOException e) { - String errMsg = "Error rendering included template at location [" + location + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - writeError(writer, errMsg); - } - } else { - throw new IllegalArgumentException("Rendering not yet supported for the template at location: " + location); - } - } - - // TODO: We can make this more fancy, but for now this is very functional - public static void writeError(Appendable writer, String message) { - try { - writer.append(message); - } catch (IOException e) { - } - } - - public static class HtmlTemplate extends ModelScreenWidget { - protected FlexibleStringExpander locationExdr; - - public HtmlTemplate(ModelScreen modelScreen, Element htmlTemplateElement) { - super(modelScreen, htmlTemplateElement); - this.locationExdr = FlexibleStringExpander.getInstance(htmlTemplateElement.getAttribute("location")); - } - - public String getLocation(Map context) { - return locationExdr.expandString(context); - } - - @Override - public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) { - renderHtmlTemplate(writer, this.locationExdr, context); - } - - @Override - public void accept(ModelWidgetVisitor visitor) throws Exception { - visitor.visit(this); - } - - public FlexibleStringExpander getLocationExdr() { - return locationExdr; - } - } - - public static class HtmlTemplateDecorator extends ModelScreenWidget { - protected FlexibleStringExpander locationExdr; - protected Map sectionMap = new HashMap(); - - public HtmlTemplateDecorator(ModelScreen modelScreen, Element htmlTemplateDecoratorElement) { - super(modelScreen, htmlTemplateDecoratorElement); - this.locationExdr = FlexibleStringExpander.getInstance(htmlTemplateDecoratorElement.getAttribute("location")); - - List htmlTemplateDecoratorSectionElementList = UtilXml.childElementList(htmlTemplateDecoratorElement, "html-template-decorator-section"); - for (Element htmlTemplateDecoratorSectionElement: htmlTemplateDecoratorSectionElementList) { - String name = htmlTemplateDecoratorSectionElement.getAttribute("name"); - this.sectionMap.put(name, new HtmlTemplateDecoratorSection(modelScreen, htmlTemplateDecoratorSectionElement)); - } - } - - @Override - public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) { - // isolate the scope - MapStack contextMs; - if (!(context instanceof MapStack)) { - contextMs = MapStack.create(context); - context = contextMs; - } else { - contextMs = UtilGenerics.cast(context); - } - - // create a standAloneStack, basically a "save point" for this SectionsRenderer, and make a new "screens" object just for it so it is isolated and doesn't follow the stack down - MapStack standAloneStack = contextMs.standAloneChildStack(); - standAloneStack.put("screens", new ScreenRenderer(writer, standAloneStack, screenStringRenderer)); - SectionsRenderer sections = new SectionsRenderer(this.sectionMap, standAloneStack, writer, screenStringRenderer); - - // put the sectionMap in the context, make sure it is in the sub-scope, ie after calling push on the MapStack - contextMs.push(); - context.put("sections", sections); - - renderHtmlTemplate(writer, this.locationExdr, context); - contextMs.pop(); - } - - @Override - public void accept(ModelWidgetVisitor visitor) throws Exception { - visitor.visit(this); - } - - public FlexibleStringExpander getLocationExdr() { - return locationExdr; - } - - public Map getSectionMap() { - return sectionMap; - } - } - - public static class HtmlTemplateDecoratorSection extends ModelScreenWidget { - protected List subWidgets; - - public HtmlTemplateDecoratorSection(ModelScreen modelScreen, Element htmlTemplateDecoratorSectionElement) { - super(modelScreen, htmlTemplateDecoratorSectionElement); - List subElementList = UtilXml.childElementList(htmlTemplateDecoratorSectionElement); - this.subWidgets = ModelScreenWidget.readSubWidgets(getModelScreen(), subElementList); - } - - @Override - public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException, IOException { - // render sub-widgets - renderSubWidgetsString(this.subWidgets, writer, context, screenStringRenderer); - } - - @Override - public void accept(ModelWidgetVisitor visitor) throws Exception { - visitor.visit(this); - } - - public List getSubWidgets() { - return subWidgets; - } - } - - @Override - public void accept(ModelWidgetVisitor visitor) throws Exception { - visitor.visit(this); - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.model; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.GeneralException; +import org.ofbiz.base.util.UtilCodec; +import org.ofbiz.base.util.UtilGenerics; +import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.base.util.UtilXml; +import org.ofbiz.base.util.cache.UtilCache; +import org.ofbiz.base.util.collections.MapStack; +import org.ofbiz.base.util.string.FlexibleStringExpander; +import org.ofbiz.base.util.template.FreeMarkerWorker; +import org.ofbiz.widget.renderer.ScreenRenderer; +import org.ofbiz.widget.renderer.ScreenStringRenderer; +import org.ofbiz.widget.renderer.html.HtmlWidgetRenderer; +import org.w3c.dom.Element; + +import freemarker.ext.beans.BeansWrapper; +import freemarker.ext.beans.CollectionModel; +import freemarker.ext.beans.StringModel; +import freemarker.template.Configuration; +import freemarker.template.Template; +import freemarker.template.TemplateException; +import freemarker.template.TemplateModel; +import freemarker.template.TemplateModelException; +import freemarker.template.Version; + +/** + * Widget Library - Screen model HTML class. + */ +@SuppressWarnings("serial") +public class HtmlWidget extends ModelScreenWidget { + public static final String module = HtmlWidget.class.getName(); + + private static final UtilCache specialTemplateCache = UtilCache.createUtilCache("widget.screen.template.ftl.general", 0, 0, false); + protected static Configuration specialConfig = FreeMarkerWorker.makeConfiguration(new ExtendedWrapper(FreeMarkerWorker.version)); + + // not sure if this is the best way to get FTL to use my fancy MapModel derivative, but should work at least... + public static class ExtendedWrapper extends BeansWrapper { + public ExtendedWrapper(Version version) { + super(version); + } + + @Override + public TemplateModel wrap(Object object) throws TemplateModelException { + // This StringHtmlWrapperForFtl option seems to be the best option + // and handles most things without causing too many problems + if (object instanceof String) { + return new StringHtmlWrapperForFtl((String) object, this); + } else if (object instanceof Collection && !(object instanceof Map)) { + // An additional wrapper to ensure ${aCollection} is properly encoded for html + return new CollectionHtmlWrapperForFtl((Collection) object, this); + } + return super.wrap(object); + } + } + + public static class StringHtmlWrapperForFtl extends StringModel { + public StringHtmlWrapperForFtl(String str, BeansWrapper wrapper) { + super(str, wrapper); + } + @Override + public String getAsString() { + return UtilCodec.getEncoder("html").encode(super.getAsString()); + } + } + + public static class CollectionHtmlWrapperForFtl extends CollectionModel { + + public CollectionHtmlWrapperForFtl(Collection collection, BeansWrapper wrapper) { + super(collection, wrapper); + } + + @Override + public String getAsString() { + return UtilCodec.getEncoder("html").encode(super.getAsString()); + } + + } + + // End Static, begin class section + + private final List subWidgets; + + public HtmlWidget(ModelScreen modelScreen, Element htmlElement) { + super(modelScreen, htmlElement); + List childElementList = UtilXml.childElementList(htmlElement); + if (childElementList.isEmpty()) { + this.subWidgets = Collections.emptyList(); + } else { + List subWidgets = new ArrayList(childElementList.size()); + for (Element childElement : childElementList) { + if ("html-template".equals(childElement.getNodeName())) { + subWidgets.add(new HtmlTemplate(modelScreen, childElement)); + } else if ("html-template-decorator".equals(childElement.getNodeName())) { + subWidgets.add(new HtmlTemplateDecorator(modelScreen, childElement)); + } else { + throw new IllegalArgumentException("Tag not supported under the platform-specific -> html tag with name: " + + childElement.getNodeName()); + } + } + this.subWidgets = Collections.unmodifiableList(subWidgets); + } + } + + public List getSubWidgets() { + return subWidgets; + } + + @Override + public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException, IOException { + for (ModelScreenWidget subWidget : subWidgets) { + subWidget.renderWidgetString(writer, context, screenStringRenderer); + } + } + + public static void renderHtmlTemplate(Appendable writer, FlexibleStringExpander locationExdr, Map context) { + String location = locationExdr.expandString(context); + //Debug.logInfo("Rendering template at location [" + location + "] with context: \n" + context, module); + + if (UtilValidate.isEmpty(location)) { + throw new IllegalArgumentException("Template location is empty"); + } + + if (location.endsWith(".ftl")) { + try { + Map parameters = UtilGenerics.checkMap(context.get("parameters")); + boolean insertWidgetBoundaryComments = ModelWidget.widgetBoundaryCommentsEnabled(parameters); + if (insertWidgetBoundaryComments) { + writer.append(HtmlWidgetRenderer.formatBoundaryComment("Begin", "Template", location)); + } + + //FreeMarkerWorker.renderTemplateAtLocation(location, context, writer); + Template template = null; + if (location.endsWith(".fo.ftl")) { // FOP can't render correctly escaped characters + template = FreeMarkerWorker.getTemplate(location); + } else { + template = FreeMarkerWorker.getTemplate(location, specialTemplateCache, specialConfig); + } + FreeMarkerWorker.renderTemplate(template, context, writer); + + if (insertWidgetBoundaryComments) { + writer.append(HtmlWidgetRenderer.formatBoundaryComment("End", "Template", location)); + } + } catch (IllegalArgumentException e) { + String errMsg = "Error rendering included template at location [" + location + "]: " + e.toString(); + Debug.logError(e, errMsg, module); + writeError(writer, errMsg); + } catch (MalformedURLException e) { + String errMsg = "Error rendering included template at location [" + location + "]: " + e.toString(); + Debug.logError(e, errMsg, module); + writeError(writer, errMsg); + } catch (TemplateException e) { + String errMsg = "Error rendering included template at location [" + location + "]: " + e.toString(); + Debug.logError(e, errMsg, module); + writeError(writer, errMsg); + } catch (IOException e) { + String errMsg = "Error rendering included template at location [" + location + "]: " + e.toString(); + Debug.logError(e, errMsg, module); + writeError(writer, errMsg); + } + } else { + throw new IllegalArgumentException("Rendering not yet supported for the template at location: " + location); + } + } + + // TODO: We can make this more fancy, but for now this is very functional + public static void writeError(Appendable writer, String message) { + try { + writer.append(message); + } catch (IOException e) { + } + } + + public static class HtmlTemplate extends ModelScreenWidget { + protected FlexibleStringExpander locationExdr; + + public HtmlTemplate(ModelScreen modelScreen, Element htmlTemplateElement) { + super(modelScreen, htmlTemplateElement); + this.locationExdr = FlexibleStringExpander.getInstance(htmlTemplateElement.getAttribute("location")); + } + + public String getLocation(Map context) { + return locationExdr.expandString(context); + } + + @Override + public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) { + renderHtmlTemplate(writer, this.locationExdr, context); + } + + @Override + public void accept(ModelWidgetVisitor visitor) throws Exception { + visitor.visit(this); + } + + public FlexibleStringExpander getLocationExdr() { + return locationExdr; + } + } + + public static class HtmlTemplateDecorator extends ModelScreenWidget { + protected FlexibleStringExpander locationExdr; + protected Map sectionMap = new HashMap(); + + public HtmlTemplateDecorator(ModelScreen modelScreen, Element htmlTemplateDecoratorElement) { + super(modelScreen, htmlTemplateDecoratorElement); + this.locationExdr = FlexibleStringExpander.getInstance(htmlTemplateDecoratorElement.getAttribute("location")); + + List htmlTemplateDecoratorSectionElementList = UtilXml.childElementList(htmlTemplateDecoratorElement, "html-template-decorator-section"); + for (Element htmlTemplateDecoratorSectionElement: htmlTemplateDecoratorSectionElementList) { + String name = htmlTemplateDecoratorSectionElement.getAttribute("name"); + this.sectionMap.put(name, new HtmlTemplateDecoratorSection(modelScreen, htmlTemplateDecoratorSectionElement)); + } + } + + @Override + public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) { + // isolate the scope + MapStack contextMs; + if (!(context instanceof MapStack)) { + contextMs = MapStack.create(context); + context = contextMs; + } else { + contextMs = UtilGenerics.cast(context); + } + + // create a standAloneStack, basically a "save point" for this SectionsRenderer, and make a new "screens" object just for it so it is isolated and doesn't follow the stack down + MapStack standAloneStack = contextMs.standAloneChildStack(); + standAloneStack.put("screens", new ScreenRenderer(writer, standAloneStack, screenStringRenderer)); + SectionsRenderer sections = new SectionsRenderer(this.sectionMap, standAloneStack, writer, screenStringRenderer); + + // put the sectionMap in the context, make sure it is in the sub-scope, ie after calling push on the MapStack + contextMs.push(); + context.put("sections", sections); + + renderHtmlTemplate(writer, this.locationExdr, context); + contextMs.pop(); + } + + @Override + public void accept(ModelWidgetVisitor visitor) throws Exception { + visitor.visit(this); + } + + public FlexibleStringExpander getLocationExdr() { + return locationExdr; + } + + public Map getSectionMap() { + return sectionMap; + } + } + + public static class HtmlTemplateDecoratorSection extends ModelScreenWidget { + protected List subWidgets; + + public HtmlTemplateDecoratorSection(ModelScreen modelScreen, Element htmlTemplateDecoratorSectionElement) { + super(modelScreen, htmlTemplateDecoratorSectionElement); + List subElementList = UtilXml.childElementList(htmlTemplateDecoratorSectionElement); + this.subWidgets = ModelScreenWidget.readSubWidgets(getModelScreen(), subElementList); + } + + @Override + public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException, IOException { + // render sub-widgets + renderSubWidgetsString(this.subWidgets, writer, context, screenStringRenderer); + } + + @Override + public void accept(ModelWidgetVisitor visitor) throws Exception { + visitor.visit(this); + } + + public List getSubWidgets() { + return subWidgets; + } + } + + @Override + public void accept(ModelWidgetVisitor visitor) throws Exception { + visitor.visit(this); + } +} diff --git a/framework/widget/src/org/ofbiz/widget/screen/IterateSectionWidget.java b/framework/widget/src/org/ofbiz/widget/model/IterateSectionWidget.java similarity index 97% rename from framework/widget/src/org/ofbiz/widget/screen/IterateSectionWidget.java rename to framework/widget/src/org/ofbiz/widget/model/IterateSectionWidget.java index 3ae2fce323..670ca9b524 100644 --- a/framework/widget/src/org/ofbiz/widget/screen/IterateSectionWidget.java +++ b/framework/widget/src/org/ofbiz/widget/model/IterateSectionWidget.java @@ -1,387 +1,387 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget.screen; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; - -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.GeneralException; -import org.ofbiz.base.util.UtilGenerics; -import org.ofbiz.base.util.UtilHttp; -import org.ofbiz.base.util.UtilMisc; -import org.ofbiz.base.util.UtilProperties; -import org.ofbiz.base.util.UtilValidate; -import org.ofbiz.base.util.UtilXml; -import org.ofbiz.base.util.collections.FlexibleMapAccessor; -import org.ofbiz.base.util.collections.MapStack; -import org.ofbiz.base.util.string.FlexibleStringExpander; -import org.ofbiz.webapp.control.RequestHandler; -import org.ofbiz.widget.ModelWidgetVisitor; -import org.ofbiz.widget.WidgetWorker; -import org.w3c.dom.Element; - - -/** - * Widget Library - Screen model HTML class - */ -@SuppressWarnings("serial") -public class IterateSectionWidget extends ModelScreenWidget { - - public static final String module = IterateSectionWidget.class.getName(); - public static int DEFAULT_PAGE_SIZE = 5; - public static int MAX_PAGE_SIZE = 10000; - - private final List sectionList; - private final FlexibleMapAccessor listNameExdr; - private final FlexibleStringExpander entryNameExdr; - private final FlexibleStringExpander keyNameExdr; - private final FlexibleStringExpander paginateTarget; - private final FlexibleStringExpander paginate; - private final int viewSize; - - public IterateSectionWidget(ModelScreen modelScreen, Element iterateSectionElement) { - super(modelScreen, iterateSectionElement); - String listName = iterateSectionElement.getAttribute("list"); - if (listName.isEmpty()) { - listName = iterateSectionElement.getAttribute("list-name"); - } - this.listNameExdr = FlexibleMapAccessor.getInstance(listName); - String entryName = iterateSectionElement.getAttribute("entry"); - if (entryName.isEmpty()) { - entryName = iterateSectionElement.getAttribute("entry-name"); - } - this.entryNameExdr = FlexibleStringExpander.getInstance(entryName); - String keyName = iterateSectionElement.getAttribute("key"); - if (keyName.isEmpty()) { - keyName = iterateSectionElement.getAttribute("key-name"); - } - this.keyNameExdr = FlexibleStringExpander.getInstance(keyName); - this.paginateTarget = FlexibleStringExpander.getInstance(iterateSectionElement.getAttribute("paginate-target")); - this.paginate = FlexibleStringExpander.getInstance(iterateSectionElement.getAttribute("paginate")); - int viewSize = DEFAULT_PAGE_SIZE; - String viewSizeStr = iterateSectionElement.getAttribute("view-size"); - if (!viewSizeStr.isEmpty()) { - viewSize = Integer.parseInt(viewSizeStr); - } - this.viewSize = viewSize; - List childElementList = UtilXml.childElementList(iterateSectionElement); - if (childElementList.isEmpty()) { - this.sectionList = Collections.emptyList(); - } else { - List sectionList = new ArrayList(childElementList.size()); - for (Element sectionElement: childElementList) { - ModelScreenWidget.Section section = new ModelScreenWidget.Section(modelScreen, sectionElement, false); - sectionList.add(section); - } - this.sectionList = Collections.unmodifiableList(sectionList); - } - } - - public List getSectionList() { - return sectionList; - } - - @Override - public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException, IOException { - int viewIndex = 0; - int viewSize = this.viewSize; - int lowIndex = -1; - int highIndex = -1; - int listSize = 0; - int actualPageSize = 0; - - boolean isEntrySet = false; - // create a standAloneStack, basically a "save point" for this SectionsRenderer, and make a new "screens" object just for it so it is isolated and doesn't follow the stack down - MapStack contextMs = MapStack.create(context); - - String entryName = this.entryNameExdr.expandString(context); - String keyName = this.keyNameExdr.expandString(context); - Object obj = listNameExdr.get(context); - if (obj == null) { - Debug.logError("No object found for listName:" + listNameExdr.toString(), module); - return; - } - List theList = null; - if (obj instanceof Map) { - Set> entrySet = UtilGenerics.>cast(obj).entrySet(); - Object [] a = entrySet.toArray(); - theList = Arrays.asList(a); - isEntrySet = true; - } else if (obj instanceof List) { - theList = (List)obj; - } else { - Debug.logError("Object not list or map type", module); - return; - } - listSize = theList.size(); - WidgetWorker.incrementPaginatorNumber(context); - int startPageNumber = WidgetWorker.getPaginatorNumber(context); - - if (getPaginate(context)) { - try { - Map params = UtilGenerics.cast(context.get("parameters")); - String viewIndexString = params.get("VIEW_INDEX" + "_" + WidgetWorker.getPaginatorNumber(context)); - String viewSizeString = params.get("VIEW_SIZE" + "_" + WidgetWorker.getPaginatorNumber(context)); - viewIndex = Integer.parseInt(viewIndexString); - viewSize = Integer.parseInt(viewSizeString); - } catch (Exception e) { - try { - viewIndex = ((Integer) context.get("viewIndex")).intValue(); - } catch (Exception e2) { - viewIndex = 0; - } - } - context.put("viewIndex", Integer.valueOf(viewIndex)); - lowIndex = viewIndex * viewSize; - highIndex = (viewIndex + 1) * viewSize; - } else { - viewIndex = 0; - viewSize = MAX_PAGE_SIZE; - lowIndex = 0; - highIndex = MAX_PAGE_SIZE; - } - Iterator iter = theList.iterator(); - int itemIndex = -1; - int iterateIndex = 0; - while (iter.hasNext()) { - itemIndex++; - if (itemIndex >= highIndex) { - break; - } - Object item = iter.next(); - if (itemIndex < lowIndex) { - continue; - } - if (isEntrySet) { - Map.Entry entry = UtilGenerics.cast(item); - contextMs.put(entryName, entry.getValue()); - contextMs.put(keyName, entry.getKey()); - } else { - contextMs.put(entryName, item); - } - contextMs.put("itemIndex", Integer.valueOf(itemIndex)); - - if (iterateIndex < listSize) { - contextMs.put("iterateId",String.valueOf(entryName+iterateIndex)); - iterateIndex++; - } - for (ModelScreenWidget.Section section: this.sectionList) { - section.renderWidgetString(writer, contextMs, screenStringRenderer); - } - } - - if ((itemIndex + 1) < highIndex) { - highIndex = itemIndex + 1; - } - actualPageSize = highIndex - lowIndex; - if (getPaginate(context)) { - try { - Integer lastPageNumber = null; - Map globalCtx = UtilGenerics.checkMap(context.get("globalContext")); - if (globalCtx != null) { - lastPageNumber = (Integer)globalCtx.get("PAGINATOR_NUMBER"); - globalCtx.put("PAGINATOR_NUMBER", Integer.valueOf(startPageNumber)); - } - renderNextPrev(writer, context, listSize, actualPageSize); - if (globalCtx != null) { - globalCtx.put("PAGINATOR_NUMBER", lastPageNumber); - } - } catch (IOException e) { - Debug.logError(e, module); - throw new RuntimeException(e.getMessage()); - } - } - - } - /* - * @return - */ - public String getPaginateTarget(Map context) { - return this.paginateTarget.expandString(context); - } - - public boolean getPaginate(Map context) { - if (!this.paginate.isEmpty() && UtilValidate.isNotEmpty(this.paginate.expandString(context))) { - return Boolean.valueOf(this.paginate.expandString(context)).booleanValue(); - } else { - return true; - } - } - - public int getViewSize() { - return viewSize; - } - - public void renderNextPrev(Appendable writer, Map context, int listSize, int actualPageSize) throws IOException { - String targetService = this.getPaginateTarget(context); - if (targetService == null) { - targetService = "${targetService}"; - } - - Map inputFields = UtilGenerics.checkMap(context.get("requestParameters")); - Map queryStringMap = UtilGenerics.toMap(context.get("queryStringMap")); - if (UtilValidate.isNotEmpty(queryStringMap)) { - inputFields.putAll(queryStringMap); - } - - String queryString = UtilHttp.urlEncodeArgs(inputFields); - int paginatorNumber = WidgetWorker.getPaginatorNumber(context); - queryString = UtilHttp.stripViewParamsFromQueryString(queryString, "" + paginatorNumber); - - - - - if (UtilValidate.isEmpty(targetService)) { - Debug.logWarning("TargetService is empty.", module); - return; - } - - int viewIndex = -1; - try { - viewIndex = ((Integer) context.get("viewIndex")).intValue(); - } catch (Exception e) { - viewIndex = 0; - } - - int viewSize = -1; - try { - viewSize = ((Integer) context.get("viewSize")).intValue(); - } catch (Exception e) { - viewSize = this.getViewSize(); - } - - - /* - int highIndex = -1; - try { - highIndex = modelForm.getHighIndex(); - } catch (Exception e) { - highIndex = 0; - } - - int lowIndex = -1; - try { - lowIndex = modelForm.getLowIndex(); - } catch (Exception e) { - lowIndex = 0; - } - */ - - int lowIndex = viewIndex * viewSize; - int highIndex = (viewIndex + 1) * viewSize; - // if this is all there seems to be (if listSize < 0, then size is unknown) - if (actualPageSize >= listSize && listSize > 0) { - return; - } - - HttpServletRequest request = (HttpServletRequest) context.get("request"); - HttpServletResponse response = (HttpServletResponse) context.get("response"); - - ServletContext ctx = (ServletContext) request.getAttribute("servletContext"); - RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_"); - - writer.append("\n"); - writer.append(" \n"); - writer.append(" \n"); - writer.append(" \n"); - writer.append("
\n"); - writer.append(" \n"); - if (viewIndex > 0) { - writer.append(" [").append(previous).append("]\n"); - - } - if (listSize > 0) { - Map messageMap = UtilMisc.toMap("lowCount", Integer.valueOf(lowIndex + 1), "highCount", Integer.valueOf(lowIndex + actualPageSize), "total", Integer.valueOf(listSize)); - String commonDisplaying = UtilProperties.getMessage("CommonUiLabels", "CommonDisplaying", messageMap, (Locale) context.get("locale")); - writer.append(" ").append(commonDisplaying).append(" \n"); - } - if (highIndex < listSize) { - writer.append(" [").append(next).append("]\n"); - - } - writer.append(" \n"); - writer.append("
\n"); - - } - - @Override - public void accept(ModelWidgetVisitor visitor) throws Exception { - visitor.visit(this); - } - - public FlexibleMapAccessor getListNameExdr() { - return listNameExdr; - } - - public FlexibleStringExpander getEntryNameExdr() { - return entryNameExdr; - } - - public FlexibleStringExpander getKeyNameExdr() { - return keyNameExdr; - } - - public FlexibleStringExpander getPaginateTarget() { - return paginateTarget; - } - - public FlexibleStringExpander getPaginate() { - return paginate; - } - -} - - +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.model; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; + +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.GeneralException; +import org.ofbiz.base.util.UtilGenerics; +import org.ofbiz.base.util.UtilHttp; +import org.ofbiz.base.util.UtilMisc; +import org.ofbiz.base.util.UtilProperties; +import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.base.util.UtilXml; +import org.ofbiz.base.util.collections.FlexibleMapAccessor; +import org.ofbiz.base.util.collections.MapStack; +import org.ofbiz.base.util.string.FlexibleStringExpander; +import org.ofbiz.webapp.control.RequestHandler; +import org.ofbiz.widget.WidgetWorker; +import org.ofbiz.widget.renderer.ScreenStringRenderer; +import org.w3c.dom.Element; + + +/** + * Widget Library - Screen model HTML class + */ +@SuppressWarnings("serial") +public class IterateSectionWidget extends ModelScreenWidget { + + public static final String module = IterateSectionWidget.class.getName(); + public static int DEFAULT_PAGE_SIZE = 5; + public static int MAX_PAGE_SIZE = 10000; + + private final List sectionList; + private final FlexibleMapAccessor listNameExdr; + private final FlexibleStringExpander entryNameExdr; + private final FlexibleStringExpander keyNameExdr; + private final FlexibleStringExpander paginateTarget; + private final FlexibleStringExpander paginate; + private final int viewSize; + + public IterateSectionWidget(ModelScreen modelScreen, Element iterateSectionElement) { + super(modelScreen, iterateSectionElement); + String listName = iterateSectionElement.getAttribute("list"); + if (listName.isEmpty()) { + listName = iterateSectionElement.getAttribute("list-name"); + } + this.listNameExdr = FlexibleMapAccessor.getInstance(listName); + String entryName = iterateSectionElement.getAttribute("entry"); + if (entryName.isEmpty()) { + entryName = iterateSectionElement.getAttribute("entry-name"); + } + this.entryNameExdr = FlexibleStringExpander.getInstance(entryName); + String keyName = iterateSectionElement.getAttribute("key"); + if (keyName.isEmpty()) { + keyName = iterateSectionElement.getAttribute("key-name"); + } + this.keyNameExdr = FlexibleStringExpander.getInstance(keyName); + this.paginateTarget = FlexibleStringExpander.getInstance(iterateSectionElement.getAttribute("paginate-target")); + this.paginate = FlexibleStringExpander.getInstance(iterateSectionElement.getAttribute("paginate")); + int viewSize = DEFAULT_PAGE_SIZE; + String viewSizeStr = iterateSectionElement.getAttribute("view-size"); + if (!viewSizeStr.isEmpty()) { + viewSize = Integer.parseInt(viewSizeStr); + } + this.viewSize = viewSize; + List childElementList = UtilXml.childElementList(iterateSectionElement); + if (childElementList.isEmpty()) { + this.sectionList = Collections.emptyList(); + } else { + List sectionList = new ArrayList(childElementList.size()); + for (Element sectionElement: childElementList) { + ModelScreenWidget.Section section = new ModelScreenWidget.Section(modelScreen, sectionElement, false); + sectionList.add(section); + } + this.sectionList = Collections.unmodifiableList(sectionList); + } + } + + public List getSectionList() { + return sectionList; + } + + @Override + public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException, IOException { + int viewIndex = 0; + int viewSize = this.viewSize; + int lowIndex = -1; + int highIndex = -1; + int listSize = 0; + int actualPageSize = 0; + + boolean isEntrySet = false; + // create a standAloneStack, basically a "save point" for this SectionsRenderer, and make a new "screens" object just for it so it is isolated and doesn't follow the stack down + MapStack contextMs = MapStack.create(context); + + String entryName = this.entryNameExdr.expandString(context); + String keyName = this.keyNameExdr.expandString(context); + Object obj = listNameExdr.get(context); + if (obj == null) { + Debug.logError("No object found for listName:" + listNameExdr.toString(), module); + return; + } + List theList = null; + if (obj instanceof Map) { + Set> entrySet = UtilGenerics.>cast(obj).entrySet(); + Object [] a = entrySet.toArray(); + theList = Arrays.asList(a); + isEntrySet = true; + } else if (obj instanceof List) { + theList = (List)obj; + } else { + Debug.logError("Object not list or map type", module); + return; + } + listSize = theList.size(); + WidgetWorker.incrementPaginatorNumber(context); + int startPageNumber = WidgetWorker.getPaginatorNumber(context); + + if (getPaginate(context)) { + try { + Map params = UtilGenerics.cast(context.get("parameters")); + String viewIndexString = params.get("VIEW_INDEX" + "_" + WidgetWorker.getPaginatorNumber(context)); + String viewSizeString = params.get("VIEW_SIZE" + "_" + WidgetWorker.getPaginatorNumber(context)); + viewIndex = Integer.parseInt(viewIndexString); + viewSize = Integer.parseInt(viewSizeString); + } catch (Exception e) { + try { + viewIndex = ((Integer) context.get("viewIndex")).intValue(); + } catch (Exception e2) { + viewIndex = 0; + } + } + context.put("viewIndex", Integer.valueOf(viewIndex)); + lowIndex = viewIndex * viewSize; + highIndex = (viewIndex + 1) * viewSize; + } else { + viewIndex = 0; + viewSize = MAX_PAGE_SIZE; + lowIndex = 0; + highIndex = MAX_PAGE_SIZE; + } + Iterator iter = theList.iterator(); + int itemIndex = -1; + int iterateIndex = 0; + while (iter.hasNext()) { + itemIndex++; + if (itemIndex >= highIndex) { + break; + } + Object item = iter.next(); + if (itemIndex < lowIndex) { + continue; + } + if (isEntrySet) { + Map.Entry entry = UtilGenerics.cast(item); + contextMs.put(entryName, entry.getValue()); + contextMs.put(keyName, entry.getKey()); + } else { + contextMs.put(entryName, item); + } + contextMs.put("itemIndex", Integer.valueOf(itemIndex)); + + if (iterateIndex < listSize) { + contextMs.put("iterateId",String.valueOf(entryName+iterateIndex)); + iterateIndex++; + } + for (ModelScreenWidget.Section section: this.sectionList) { + section.renderWidgetString(writer, contextMs, screenStringRenderer); + } + } + + if ((itemIndex + 1) < highIndex) { + highIndex = itemIndex + 1; + } + actualPageSize = highIndex - lowIndex; + if (getPaginate(context)) { + try { + Integer lastPageNumber = null; + Map globalCtx = UtilGenerics.checkMap(context.get("globalContext")); + if (globalCtx != null) { + lastPageNumber = (Integer)globalCtx.get("PAGINATOR_NUMBER"); + globalCtx.put("PAGINATOR_NUMBER", Integer.valueOf(startPageNumber)); + } + renderNextPrev(writer, context, listSize, actualPageSize); + if (globalCtx != null) { + globalCtx.put("PAGINATOR_NUMBER", lastPageNumber); + } + } catch (IOException e) { + Debug.logError(e, module); + throw new RuntimeException(e.getMessage()); + } + } + + } + /* + * @return + */ + public String getPaginateTarget(Map context) { + return this.paginateTarget.expandString(context); + } + + public boolean getPaginate(Map context) { + if (!this.paginate.isEmpty() && UtilValidate.isNotEmpty(this.paginate.expandString(context))) { + return Boolean.valueOf(this.paginate.expandString(context)).booleanValue(); + } else { + return true; + } + } + + public int getViewSize() { + return viewSize; + } + + public void renderNextPrev(Appendable writer, Map context, int listSize, int actualPageSize) throws IOException { + String targetService = this.getPaginateTarget(context); + if (targetService == null) { + targetService = "${targetService}"; + } + + Map inputFields = UtilGenerics.checkMap(context.get("requestParameters")); + Map queryStringMap = UtilGenerics.toMap(context.get("queryStringMap")); + if (UtilValidate.isNotEmpty(queryStringMap)) { + inputFields.putAll(queryStringMap); + } + + String queryString = UtilHttp.urlEncodeArgs(inputFields); + int paginatorNumber = WidgetWorker.getPaginatorNumber(context); + queryString = UtilHttp.stripViewParamsFromQueryString(queryString, "" + paginatorNumber); + + + + + if (UtilValidate.isEmpty(targetService)) { + Debug.logWarning("TargetService is empty.", module); + return; + } + + int viewIndex = -1; + try { + viewIndex = ((Integer) context.get("viewIndex")).intValue(); + } catch (Exception e) { + viewIndex = 0; + } + + int viewSize = -1; + try { + viewSize = ((Integer) context.get("viewSize")).intValue(); + } catch (Exception e) { + viewSize = this.getViewSize(); + } + + + /* + int highIndex = -1; + try { + highIndex = modelForm.getHighIndex(); + } catch (Exception e) { + highIndex = 0; + } + + int lowIndex = -1; + try { + lowIndex = modelForm.getLowIndex(); + } catch (Exception e) { + lowIndex = 0; + } + */ + + int lowIndex = viewIndex * viewSize; + int highIndex = (viewIndex + 1) * viewSize; + // if this is all there seems to be (if listSize < 0, then size is unknown) + if (actualPageSize >= listSize && listSize > 0) { + return; + } + + HttpServletRequest request = (HttpServletRequest) context.get("request"); + HttpServletResponse response = (HttpServletResponse) context.get("response"); + + ServletContext ctx = (ServletContext) request.getAttribute("servletContext"); + RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_"); + + writer.append("\n"); + writer.append(" \n"); + writer.append(" \n"); + writer.append(" \n"); + writer.append("
\n"); + writer.append(" \n"); + if (viewIndex > 0) { + writer.append(" [").append(previous).append("]\n"); + + } + if (listSize > 0) { + Map messageMap = UtilMisc.toMap("lowCount", Integer.valueOf(lowIndex + 1), "highCount", Integer.valueOf(lowIndex + actualPageSize), "total", Integer.valueOf(listSize)); + String commonDisplaying = UtilProperties.getMessage("CommonUiLabels", "CommonDisplaying", messageMap, (Locale) context.get("locale")); + writer.append(" ").append(commonDisplaying).append(" \n"); + } + if (highIndex < listSize) { + writer.append(" [").append(next).append("]\n"); + + } + writer.append(" \n"); + writer.append("
\n"); + + } + + @Override + public void accept(ModelWidgetVisitor visitor) throws Exception { + visitor.visit(this); + } + + public FlexibleMapAccessor getListNameExdr() { + return listNameExdr; + } + + public FlexibleStringExpander getEntryNameExdr() { + return entryNameExdr; + } + + public FlexibleStringExpander getKeyNameExdr() { + return keyNameExdr; + } + + public FlexibleStringExpander getPaginateTarget() { + return paginateTarget; + } + + public FlexibleStringExpander getPaginate() { + return paginate; + } + +} + + diff --git a/framework/widget/src/org/ofbiz/widget/menu/MenuFactory.java b/framework/widget/src/org/ofbiz/widget/model/MenuFactory.java similarity index 97% rename from framework/widget/src/org/ofbiz/widget/menu/MenuFactory.java rename to framework/widget/src/org/ofbiz/widget/model/MenuFactory.java index 472d6883a1..c30ac37ac4 100644 --- a/framework/widget/src/org/ofbiz/widget/menu/MenuFactory.java +++ b/framework/widget/src/org/ofbiz/widget/model/MenuFactory.java @@ -1,118 +1,118 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget.menu; - -import java.io.IOException; -import java.net.URL; -import java.util.HashMap; -import java.util.Map; - -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletRequest; -import javax.xml.parsers.ParserConfigurationException; - -import org.ofbiz.base.location.FlexibleLocation; -import org.ofbiz.base.util.UtilHttp; -import org.ofbiz.base.util.UtilValidate; -import org.ofbiz.base.util.UtilXml; -import org.ofbiz.base.util.cache.UtilCache; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.xml.sax.SAXException; - - -/** - * Widget Library - Menu factory class - */ -public class MenuFactory { - - public static final String module = MenuFactory.class.getName(); - - public static final UtilCache> menuWebappCache = UtilCache.createUtilCache("widget.menu.webappResource", 0, 0, false); - public static final UtilCache> menuLocationCache = UtilCache.createUtilCache("widget.menu.locationResource", 0, 0, false); - - public static ModelMenu getMenuFromWebappContext(String resourceName, String menuName, HttpServletRequest request) - throws IOException, SAXException, ParserConfigurationException { - String webappName = UtilHttp.getApplicationName(request); - String cacheKey = webappName + "::" + resourceName; - - Map modelMenuMap = menuWebappCache.get(cacheKey); - if (modelMenuMap == null) { - synchronized (MenuFactory.class) { - modelMenuMap = menuWebappCache.get(cacheKey); - if (modelMenuMap == null) { - ServletContext servletContext = (ServletContext) request.getAttribute("servletContext"); - - URL menuFileUrl = servletContext.getResource(resourceName); - Document menuFileDoc = UtilXml.readXmlDocument(menuFileUrl, true, true); - modelMenuMap = readMenuDocument(menuFileDoc, cacheKey); - menuWebappCache.put(cacheKey, modelMenuMap); - } - } - } - - if (UtilValidate.isEmpty(modelMenuMap)) { - throw new IllegalArgumentException("Could not find menu file in webapp resource [" + resourceName + "] in the webapp [" + webappName + "]"); - } - - ModelMenu modelMenu = modelMenuMap.get(menuName); - if (modelMenu == null) { - throw new IllegalArgumentException("Could not find menu with name [" + menuName + "] in webapp resource [" + resourceName + "] in the webapp [" + webappName + "]"); - } - return modelMenu; - } - - public static Map readMenuDocument(Document menuFileDoc, String menuLocation) { - Map modelMenuMap = new HashMap(); - if (menuFileDoc != null) { - // read document and construct ModelMenu for each menu element - Element rootElement = menuFileDoc.getDocumentElement(); - for (Element menuElement: UtilXml.childElementList(rootElement, "menu")){ - ModelMenu modelMenu = new ModelMenu(menuElement, menuLocation); - modelMenuMap.put(modelMenu.getName(), modelMenu); - } - } - return modelMenuMap; - } - - public static ModelMenu getMenuFromLocation(String resourceName, String menuName) throws IOException, SAXException, ParserConfigurationException { - Map modelMenuMap = menuLocationCache.get(resourceName); - if (modelMenuMap == null) { - synchronized (MenuFactory.class) { - modelMenuMap = menuLocationCache.get(resourceName); - if (modelMenuMap == null) { - URL menuFileUrl = FlexibleLocation.resolveLocation(resourceName); - Document menuFileDoc = UtilXml.readXmlDocument(menuFileUrl, true, true); - modelMenuMap = readMenuDocument(menuFileDoc, resourceName); - menuLocationCache.put(resourceName, modelMenuMap); - } - } - } - - if (UtilValidate.isEmpty(modelMenuMap)) { - throw new IllegalArgumentException("Could not find menu file in location [" + resourceName + "]"); - } - - ModelMenu modelMenu = modelMenuMap.get(menuName); - if (modelMenu == null) { - throw new IllegalArgumentException("Could not find menu with name [" + menuName + "] in location [" + resourceName + "]"); - } - return modelMenu; - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.model; + +import java.io.IOException; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import javax.xml.parsers.ParserConfigurationException; + +import org.ofbiz.base.location.FlexibleLocation; +import org.ofbiz.base.util.UtilHttp; +import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.base.util.UtilXml; +import org.ofbiz.base.util.cache.UtilCache; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.xml.sax.SAXException; + + +/** + * Widget Library - Menu factory class + */ +public class MenuFactory { + + public static final String module = MenuFactory.class.getName(); + + public static final UtilCache> menuWebappCache = UtilCache.createUtilCache("widget.menu.webappResource", 0, 0, false); + public static final UtilCache> menuLocationCache = UtilCache.createUtilCache("widget.menu.locationResource", 0, 0, false); + + public static ModelMenu getMenuFromWebappContext(String resourceName, String menuName, HttpServletRequest request) + throws IOException, SAXException, ParserConfigurationException { + String webappName = UtilHttp.getApplicationName(request); + String cacheKey = webappName + "::" + resourceName; + + Map modelMenuMap = menuWebappCache.get(cacheKey); + if (modelMenuMap == null) { + synchronized (MenuFactory.class) { + modelMenuMap = menuWebappCache.get(cacheKey); + if (modelMenuMap == null) { + ServletContext servletContext = (ServletContext) request.getAttribute("servletContext"); + + URL menuFileUrl = servletContext.getResource(resourceName); + Document menuFileDoc = UtilXml.readXmlDocument(menuFileUrl, true, true); + modelMenuMap = readMenuDocument(menuFileDoc, cacheKey); + menuWebappCache.put(cacheKey, modelMenuMap); + } + } + } + + if (UtilValidate.isEmpty(modelMenuMap)) { + throw new IllegalArgumentException("Could not find menu file in webapp resource [" + resourceName + "] in the webapp [" + webappName + "]"); + } + + ModelMenu modelMenu = modelMenuMap.get(menuName); + if (modelMenu == null) { + throw new IllegalArgumentException("Could not find menu with name [" + menuName + "] in webapp resource [" + resourceName + "] in the webapp [" + webappName + "]"); + } + return modelMenu; + } + + public static Map readMenuDocument(Document menuFileDoc, String menuLocation) { + Map modelMenuMap = new HashMap(); + if (menuFileDoc != null) { + // read document and construct ModelMenu for each menu element + Element rootElement = menuFileDoc.getDocumentElement(); + for (Element menuElement: UtilXml.childElementList(rootElement, "menu")){ + ModelMenu modelMenu = new ModelMenu(menuElement, menuLocation); + modelMenuMap.put(modelMenu.getName(), modelMenu); + } + } + return modelMenuMap; + } + + public static ModelMenu getMenuFromLocation(String resourceName, String menuName) throws IOException, SAXException, ParserConfigurationException { + Map modelMenuMap = menuLocationCache.get(resourceName); + if (modelMenuMap == null) { + synchronized (MenuFactory.class) { + modelMenuMap = menuLocationCache.get(resourceName); + if (modelMenuMap == null) { + URL menuFileUrl = FlexibleLocation.resolveLocation(resourceName); + Document menuFileDoc = UtilXml.readXmlDocument(menuFileUrl, true, true); + modelMenuMap = readMenuDocument(menuFileDoc, resourceName); + menuLocationCache.put(resourceName, modelMenuMap); + } + } + } + + if (UtilValidate.isEmpty(modelMenuMap)) { + throw new IllegalArgumentException("Could not find menu file in location [" + resourceName + "]"); + } + + ModelMenu modelMenu = modelMenuMap.get(menuName); + if (modelMenu == null) { + throw new IllegalArgumentException("Could not find menu with name [" + menuName + "] in location [" + resourceName + "]"); + } + return modelMenu; + } +} diff --git a/framework/widget/src/org/ofbiz/widget/ModelAction.java b/framework/widget/src/org/ofbiz/widget/model/ModelAction.java similarity index 95% rename from framework/widget/src/org/ofbiz/widget/ModelAction.java rename to framework/widget/src/org/ofbiz/widget/model/ModelAction.java index 19977a2998..65036867bd 100644 --- a/framework/widget/src/org/ofbiz/widget/ModelAction.java +++ b/framework/widget/src/org/ofbiz/widget/model/ModelAction.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. *******************************************************************************/ -package org.ofbiz.widget; +package org.ofbiz.widget.model; import java.util.Map; diff --git a/framework/widget/src/org/ofbiz/widget/ModelActionVisitor.java b/framework/widget/src/org/ofbiz/widget/model/ModelActionVisitor.java similarity index 91% rename from framework/widget/src/org/ofbiz/widget/ModelActionVisitor.java rename to framework/widget/src/org/ofbiz/widget/model/ModelActionVisitor.java index 28c039ca8b..84085a5714 100644 --- a/framework/widget/src/org/ofbiz/widget/ModelActionVisitor.java +++ b/framework/widget/src/org/ofbiz/widget/model/ModelActionVisitor.java @@ -16,11 +16,7 @@ * specific language governing permissions and limitations * under the License. *******************************************************************************/ -package org.ofbiz.widget; - -import org.ofbiz.widget.form.ModelFormAction; -import org.ofbiz.widget.menu.ModelMenuAction; -import org.ofbiz.widget.tree.ModelTreeAction; +package org.ofbiz.widget.model; /** * A ModelAction visitor. diff --git a/framework/widget/src/org/ofbiz/widget/ModelCondition.java b/framework/widget/src/org/ofbiz/widget/model/ModelCondition.java similarity index 94% rename from framework/widget/src/org/ofbiz/widget/ModelCondition.java rename to framework/widget/src/org/ofbiz/widget/model/ModelCondition.java index b829fdbe07..b7f6ff9218 100644 --- a/framework/widget/src/org/ofbiz/widget/ModelCondition.java +++ b/framework/widget/src/org/ofbiz/widget/model/ModelCondition.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. *******************************************************************************/ -package org.ofbiz.widget; +package org.ofbiz.widget.model; import java.util.Map; diff --git a/framework/widget/src/org/ofbiz/widget/ModelConditionFactory.java b/framework/widget/src/org/ofbiz/widget/model/ModelConditionFactory.java similarity index 96% rename from framework/widget/src/org/ofbiz/widget/ModelConditionFactory.java rename to framework/widget/src/org/ofbiz/widget/model/ModelConditionFactory.java index 0857f52626..e47799d47d 100644 --- a/framework/widget/src/org/ofbiz/widget/ModelConditionFactory.java +++ b/framework/widget/src/org/ofbiz/widget/model/ModelConditionFactory.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. *******************************************************************************/ -package org.ofbiz.widget; +package org.ofbiz.widget.model; import org.w3c.dom.Element; diff --git a/framework/widget/src/org/ofbiz/widget/ModelConditionVisitor.java b/framework/widget/src/org/ofbiz/widget/model/ModelConditionVisitor.java similarity index 67% rename from framework/widget/src/org/ofbiz/widget/ModelConditionVisitor.java rename to framework/widget/src/org/ofbiz/widget/model/ModelConditionVisitor.java index 7bc968462a..a60dd392e9 100644 --- a/framework/widget/src/org/ofbiz/widget/ModelConditionVisitor.java +++ b/framework/widget/src/org/ofbiz/widget/model/ModelConditionVisitor.java @@ -16,23 +16,21 @@ * specific language governing permissions and limitations * under the License. *******************************************************************************/ -package org.ofbiz.widget; +package org.ofbiz.widget.model; -import org.ofbiz.widget.AbstractModelCondition.And; -import org.ofbiz.widget.AbstractModelCondition.IfCompare; -import org.ofbiz.widget.AbstractModelCondition.IfCompareField; -import org.ofbiz.widget.AbstractModelCondition.IfEmpty; -import org.ofbiz.widget.AbstractModelCondition.IfEntityPermission; -import org.ofbiz.widget.AbstractModelCondition.IfHasPermission; -import org.ofbiz.widget.AbstractModelCondition.IfRegexp; -import org.ofbiz.widget.AbstractModelCondition.IfServicePermission; -import org.ofbiz.widget.AbstractModelCondition.IfValidateMethod; -import org.ofbiz.widget.AbstractModelCondition.Not; -import org.ofbiz.widget.AbstractModelCondition.Or; -import org.ofbiz.widget.AbstractModelCondition.Xor; -import org.ofbiz.widget.menu.ModelMenuCondition; -import org.ofbiz.widget.screen.ModelScreenCondition.IfEmptySection; -import org.ofbiz.widget.tree.ModelTreeCondition; +import org.ofbiz.widget.model.AbstractModelCondition.And; +import org.ofbiz.widget.model.AbstractModelCondition.IfCompare; +import org.ofbiz.widget.model.AbstractModelCondition.IfCompareField; +import org.ofbiz.widget.model.AbstractModelCondition.IfEmpty; +import org.ofbiz.widget.model.AbstractModelCondition.IfEntityPermission; +import org.ofbiz.widget.model.AbstractModelCondition.IfHasPermission; +import org.ofbiz.widget.model.AbstractModelCondition.IfRegexp; +import org.ofbiz.widget.model.AbstractModelCondition.IfServicePermission; +import org.ofbiz.widget.model.AbstractModelCondition.IfValidateMethod; +import org.ofbiz.widget.model.AbstractModelCondition.Not; +import org.ofbiz.widget.model.AbstractModelCondition.Or; +import org.ofbiz.widget.model.AbstractModelCondition.Xor; +import org.ofbiz.widget.model.ModelScreenCondition.IfEmptySection; /** * A ModelCondition visitor. diff --git a/framework/widget/src/org/ofbiz/widget/ModelFieldVisitor.java b/framework/widget/src/org/ofbiz/widget/model/ModelFieldVisitor.java similarity index 63% rename from framework/widget/src/org/ofbiz/widget/ModelFieldVisitor.java rename to framework/widget/src/org/ofbiz/widget/model/ModelFieldVisitor.java index bf06bf78fb..753971ba7a 100644 --- a/framework/widget/src/org/ofbiz/widget/ModelFieldVisitor.java +++ b/framework/widget/src/org/ofbiz/widget/model/ModelFieldVisitor.java @@ -16,29 +16,29 @@ * specific language governing permissions and limitations * under the License. *******************************************************************************/ -package org.ofbiz.widget; +package org.ofbiz.widget.model; -import org.ofbiz.widget.form.ModelFormField.CheckField; -import org.ofbiz.widget.form.ModelFormField.ContainerField; -import org.ofbiz.widget.form.ModelFormField.DateFindField; -import org.ofbiz.widget.form.ModelFormField.DateTimeField; -import org.ofbiz.widget.form.ModelFormField.DisplayEntityField; -import org.ofbiz.widget.form.ModelFormField.DisplayField; -import org.ofbiz.widget.form.ModelFormField.DropDownField; -import org.ofbiz.widget.form.ModelFormField.FileField; -import org.ofbiz.widget.form.ModelFormField.HiddenField; -import org.ofbiz.widget.form.ModelFormField.HyperlinkField; -import org.ofbiz.widget.form.ModelFormField.IgnoredField; -import org.ofbiz.widget.form.ModelFormField.ImageField; -import org.ofbiz.widget.form.ModelFormField.LookupField; -import org.ofbiz.widget.form.ModelFormField.PasswordField; -import org.ofbiz.widget.form.ModelFormField.RadioField; -import org.ofbiz.widget.form.ModelFormField.RangeFindField; -import org.ofbiz.widget.form.ModelFormField.ResetField; -import org.ofbiz.widget.form.ModelFormField.SubmitField; -import org.ofbiz.widget.form.ModelFormField.TextField; -import org.ofbiz.widget.form.ModelFormField.TextFindField; -import org.ofbiz.widget.form.ModelFormField.TextareaField; +import org.ofbiz.widget.model.ModelFormField.CheckField; +import org.ofbiz.widget.model.ModelFormField.ContainerField; +import org.ofbiz.widget.model.ModelFormField.DateFindField; +import org.ofbiz.widget.model.ModelFormField.DateTimeField; +import org.ofbiz.widget.model.ModelFormField.DisplayEntityField; +import org.ofbiz.widget.model.ModelFormField.DisplayField; +import org.ofbiz.widget.model.ModelFormField.DropDownField; +import org.ofbiz.widget.model.ModelFormField.FileField; +import org.ofbiz.widget.model.ModelFormField.HiddenField; +import org.ofbiz.widget.model.ModelFormField.HyperlinkField; +import org.ofbiz.widget.model.ModelFormField.IgnoredField; +import org.ofbiz.widget.model.ModelFormField.ImageField; +import org.ofbiz.widget.model.ModelFormField.LookupField; +import org.ofbiz.widget.model.ModelFormField.PasswordField; +import org.ofbiz.widget.model.ModelFormField.RadioField; +import org.ofbiz.widget.model.ModelFormField.RangeFindField; +import org.ofbiz.widget.model.ModelFormField.ResetField; +import org.ofbiz.widget.model.ModelFormField.SubmitField; +import org.ofbiz.widget.model.ModelFormField.TextField; +import org.ofbiz.widget.model.ModelFormField.TextFindField; +import org.ofbiz.widget.model.ModelFormField.TextareaField; /** * A ModelFormField visitor. diff --git a/framework/widget/src/org/ofbiz/widget/form/ModelForm.java b/framework/widget/src/org/ofbiz/widget/model/ModelForm.java similarity index 97% rename from framework/widget/src/org/ofbiz/widget/form/ModelForm.java rename to framework/widget/src/org/ofbiz/widget/model/ModelForm.java index 41f981dd41..73b87bb169 100644 --- a/framework/widget/src/org/ofbiz/widget/form/ModelForm.java +++ b/framework/widget/src/org/ofbiz/widget/model/ModelForm.java @@ -1,1858 +1,1854 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget.form; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.atomic.AtomicInteger; - -import org.ofbiz.base.util.BshUtil; -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.StringUtil; -import org.ofbiz.base.util.UtilCodec; -import org.ofbiz.base.util.UtilGenerics; -import org.ofbiz.base.util.UtilProperties; -import org.ofbiz.base.util.UtilValidate; -import org.ofbiz.base.util.UtilXml; -import org.ofbiz.base.util.collections.FlexibleMapAccessor; -import org.ofbiz.base.util.string.FlexibleStringExpander; -import org.ofbiz.entity.GenericEntityException; -import org.ofbiz.entity.model.ModelEntity; -import org.ofbiz.entity.model.ModelField; -import org.ofbiz.entity.model.ModelReader; -import org.ofbiz.service.DispatchContext; -import org.ofbiz.service.GenericServiceException; -import org.ofbiz.service.ModelParam; -import org.ofbiz.service.ModelService; -import org.ofbiz.widget.AbstractModelAction; -import org.ofbiz.widget.CommonWidgetModels; -import org.ofbiz.widget.ModelAction; -import org.ofbiz.widget.ModelWidget; -import org.ofbiz.widget.ModelWidgetVisitor; -import org.ofbiz.widget.WidgetWorker; -import org.w3c.dom.Element; - -import bsh.EvalError; -import bsh.Interpreter; - -/** - * Models the <form> element. - * - * @see widget-form.xsd - */ -@SuppressWarnings("serial") -public class ModelForm extends ModelWidget { - - /* - * ----------------------------------------------------------------------- * - * DEVELOPERS PLEASE READ - * ----------------------------------------------------------------------- * - * - * This model is intended to be a read-only data structure that represents - * an XML element. Outside of object construction, the class should not - * have any behaviors. All behavior should be contained in model visitors. - * - * Instances of this class will be shared by multiple threads - therefore - * it is immutable. DO NOT CHANGE THE OBJECT'S STATE AT RUN TIME! - * - * BE VERY CAREFUL when implementing "extends" - parent form collections - * must be added to child collections, not replace them. In other words, - * do not assign parent collection fields to child collection fields. - * - */ - - public static final String module = ModelForm.class.getName(); - public static final String DEFAULT_FORM_RESULT_LIST_NAME = "defaultFormResultList"; - /** Pagination settings and defaults. */ - public static int DEFAULT_PAGE_SIZE = 10; - public static int MAX_PAGE_SIZE = 10000; - public static String DEFAULT_PAG_INDEX_FIELD = "viewIndex"; - public static String DEFAULT_PAG_SIZE_FIELD = "viewSize"; - public static String DEFAULT_PAG_STYLE = "nav-pager"; - public static String DEFAULT_PAG_FIRST_STYLE = "nav-first"; - public static String DEFAULT_PAG_PREV_STYLE = "nav-previous"; - public static String DEFAULT_PAG_NEXT_STYLE = "nav-next"; - public static String DEFAULT_PAG_LAST_STYLE = "nav-last"; - /** Sort field default styles. */ - public static String DEFAULT_SORT_FIELD_STYLE = "sort-order"; - public static String DEFAULT_SORT_FIELD_ASC_STYLE = "sort-order-asc"; - public static String DEFAULT_SORT_FIELD_DESC_STYLE = "sort-order-desc"; - private final List actions; - private final List altRowStyles; - private final List altTargets; - private final List autoFieldsEntities; - private final List autoFieldsServices; - private final boolean clientAutocompleteFields; - private final String containerId; - private final String containerStyle; - private final String defaultEntityName; - /** This field group will be the "catch-all" group for fields that are not - * included in an explicit field-group. - */ - private final FieldGroup defaultFieldGroup; - private final FlexibleMapAccessor> defaultMapName; - private final String defaultRequiredFieldStyle; - private final String defaultServiceName; - private final String defaultSortFieldAscStyle; - private final String defaultSortFieldDescStyle; - private final String defaultSortFieldStyle; - private final String defaultTableStyle; - private final String defaultTitleAreaStyle; - private final String defaultTitleStyle; - private final String defaultTooltipStyle; - private final int defaultViewSize; - private final String defaultWidgetAreaStyle; - private final String defaultWidgetStyle; - private final String evenRowStyle; - /** This is a list of FieldGroups in the order they were created. - * Can also include Banner objects. - */ - private final List fieldGroupList; - /** This Map is keyed with the field name and has a FieldGroup for the value. - * Can also include Banner objects. - */ - private final Map fieldGroupMap; - /** This List will contain one copy of each field for each field name in the order - * they were encountered in the service, entity, or form definition; field definitions - * with constraints will also be in this list but may appear multiple times for the same - * field name. - * - * When rendering the form the order in this list should be following and it should not be - * necessary to use the Map. The Map is used when loading the form definition to keep the - * list clean and implement the override features for field definitions. - */ - private final List fieldList; - private final String focusFieldName; - private final String formLocation; - private final String formTitleAreaStyle; - private final String formWidgetAreaStyle; - private final boolean groupColumns; - private final String headerRowStyle; - private final boolean hideHeader; - private final String itemIndexSeparator; - private final List lastOrderFields; - private final String listEntryName; - private final String listName; - private final List multiSubmitFields; - private final String oddRowStyle; - /** On Paginate areas to be updated. */ - private final List onPaginateUpdateAreas; - /** On Sort Column areas to be updated. */ - private final List onSortColumnUpdateAreas; - /** On Submit areas to be updated. */ - private final List onSubmitUpdateAreas; - private final FlexibleStringExpander overrideListSize; - private final FlexibleStringExpander paginate; - private final FlexibleStringExpander paginateFirstLabel; - private final FlexibleStringExpander paginateIndexField; - private final FlexibleStringExpander paginateLastLabel; - private final FlexibleStringExpander paginateNextLabel; - private final FlexibleStringExpander paginatePreviousLabel; - private final FlexibleStringExpander paginateSizeField; - private final String paginateStyle; - private final FlexibleStringExpander paginateTarget; - private final String paginateTargetAnchor; - private final FlexibleStringExpander paginateViewSizeLabel; - private final ModelForm parentModelForm; - private final List rowActions; - private final FlexibleStringExpander rowCountExdr; - private final boolean separateColumns; - private final boolean skipEnd; - private final boolean skipStart; - private final String sortFieldParameterName; - private final List sortOrderFields; - private final FlexibleStringExpander target; - private final String targetType; - private final FlexibleStringExpander targetWindowExdr; - private final String title; - private final String tooltip; - private final String type; - private final boolean useRowSubmit; - /** Keeps track of conditional fields to help ensure that only one is rendered - */ - private final Set useWhenFields; - - /** XML Constructor */ - public ModelForm(Element formElement, String formLocation, ModelReader entityModelReader, DispatchContext dispatchContext) { - super(formElement); - this.formLocation = formLocation; - parentModelForm = getParentForm(formElement, entityModelReader, dispatchContext); - int defaultViewSizeInt = DEFAULT_PAGE_SIZE; - String viewSize = formElement.getAttribute("view-size"); - if (viewSize.isEmpty()) { - if (parentModelForm != null) { - defaultViewSizeInt = parentModelForm.defaultViewSize; - } else { - defaultViewSizeInt = UtilProperties.getPropertyAsInteger("widget.properties", "widget.form.defaultViewSize", - defaultViewSizeInt); - } - } else { - try { - defaultViewSizeInt = Integer.valueOf(viewSize); - } catch (NumberFormatException e) { - } - } - this.defaultViewSize = defaultViewSizeInt; - String type = formElement.getAttribute("type"); - if (type.isEmpty() && parentModelForm != null) { - type = parentModelForm.type; - } - this.type = type; - FlexibleStringExpander target = FlexibleStringExpander.getInstance(formElement.getAttribute("target")); - if (target.isEmpty() && parentModelForm != null) { - target = parentModelForm.target; - } - this.target = target; - String containerId = formElement.getAttribute("id"); - if (containerId.isEmpty() && parentModelForm != null) { - containerId = parentModelForm.containerId; - } - this.containerId = containerId; - String containerStyle = formElement.getAttribute("style"); - if (containerStyle.isEmpty() && parentModelForm != null) { - containerStyle = parentModelForm.containerStyle; - } - this.containerStyle = containerStyle; - String title = formElement.getAttribute("title"); - if (title.isEmpty() && parentModelForm != null) { - title = parentModelForm.title; - } - this.title = title; - String tooltip = formElement.getAttribute("tooltip"); - if (tooltip.isEmpty() && parentModelForm != null) { - tooltip = parentModelForm.tooltip; - } - this.tooltip = tooltip; - String listName = formElement.getAttribute("list-name"); - if (listName.isEmpty()) { - if (parentModelForm != null) { - listName = parentModelForm.listName; - } else { - listName = DEFAULT_FORM_RESULT_LIST_NAME; - } - } - this.listName = listName; - String listEntryName = formElement.getAttribute("list-entry-name"); - if (listEntryName.isEmpty() && parentModelForm != null) { - listEntryName = parentModelForm.listEntryName; - } - this.listEntryName = listEntryName; - String defaultEntityName = formElement.getAttribute("default-entity-name"); - if (defaultEntityName.isEmpty() && parentModelForm != null) { - defaultEntityName = parentModelForm.defaultEntityName; - } - this.defaultEntityName = defaultEntityName; - String defaultServiceName = formElement.getAttribute("default-service-name"); - if (defaultServiceName.isEmpty() && parentModelForm != null) { - defaultServiceName = parentModelForm.defaultServiceName; - } - this.defaultServiceName = defaultServiceName; - String formTitleAreaStyle = formElement.getAttribute("form-title-area-style"); - if (formTitleAreaStyle.isEmpty() && parentModelForm != null) { - formTitleAreaStyle = parentModelForm.formTitleAreaStyle; - } - this.formTitleAreaStyle = formTitleAreaStyle; - String formWidgetAreaStyle = formElement.getAttribute("form-widget-area-style"); - if (formWidgetAreaStyle.isEmpty() && parentModelForm != null) { - formWidgetAreaStyle = parentModelForm.formWidgetAreaStyle; - } - this.formWidgetAreaStyle = formWidgetAreaStyle; - String defaultTitleAreaStyle = formElement.getAttribute("default-title-area-style"); - if (defaultTitleAreaStyle.isEmpty() && parentModelForm != null) { - defaultTitleAreaStyle = parentModelForm.defaultTitleAreaStyle; - } - this.defaultTitleAreaStyle = defaultTitleAreaStyle; - String defaultWidgetAreaStyle = formElement.getAttribute("default-widget-area-style"); - if (defaultWidgetAreaStyle.isEmpty() && parentModelForm != null) { - defaultWidgetAreaStyle = parentModelForm.defaultWidgetAreaStyle; - } - this.defaultWidgetAreaStyle = defaultWidgetAreaStyle; - String oddRowStyle = formElement.getAttribute("odd-row-style"); - if (oddRowStyle.isEmpty() && parentModelForm != null) { - oddRowStyle = parentModelForm.oddRowStyle; - } - this.oddRowStyle = oddRowStyle; - String evenRowStyle = formElement.getAttribute("even-row-style"); - if (evenRowStyle.isEmpty() && parentModelForm != null) { - evenRowStyle = parentModelForm.evenRowStyle; - } - this.evenRowStyle = evenRowStyle; - String defaultTableStyle = formElement.getAttribute("default-table-style"); - if (defaultTableStyle.isEmpty() && parentModelForm != null) { - defaultTableStyle = parentModelForm.defaultTableStyle; - } - this.defaultTableStyle = defaultTableStyle; - String headerRowStyle = formElement.getAttribute("header-row-style"); - if (headerRowStyle.isEmpty() && parentModelForm != null) { - headerRowStyle = parentModelForm.headerRowStyle; - } - this.headerRowStyle = headerRowStyle; - String defaultTitleStyle = formElement.getAttribute("default-title-style"); - if (defaultTitleStyle.isEmpty() && parentModelForm != null) { - defaultTitleStyle = parentModelForm.defaultTitleStyle; - } - this.defaultTitleStyle = defaultTitleStyle; - String defaultWidgetStyle = formElement.getAttribute("default-widget-style"); - if (defaultWidgetStyle.isEmpty() && parentModelForm != null) { - defaultWidgetStyle = parentModelForm.defaultWidgetStyle; - } - this.defaultWidgetStyle = defaultWidgetStyle; - String defaultTooltipStyle = formElement.getAttribute("default-tooltip-style"); - if (defaultTooltipStyle.isEmpty() && parentModelForm != null) { - defaultTooltipStyle = parentModelForm.defaultTooltipStyle; - } - this.defaultTooltipStyle = defaultTooltipStyle; - String itemIndexSeparator = formElement.getAttribute("item-index-separator"); - if (itemIndexSeparator.isEmpty() && parentModelForm != null) { - itemIndexSeparator = parentModelForm.itemIndexSeparator; - } - this.itemIndexSeparator = itemIndexSeparator; - String separateColumns = formElement.getAttribute("separate-columns"); - if (separateColumns.isEmpty() && parentModelForm != null) { - this.separateColumns = parentModelForm.separateColumns; - } else { - this.separateColumns = "true".equals(separateColumns); - } - String groupColumns = formElement.getAttribute("group-columns"); - if (groupColumns.isEmpty() && parentModelForm != null) { - this.groupColumns = parentModelForm.groupColumns; - } else { - this.groupColumns = !"false".equals(groupColumns); - } - String targetType = formElement.getAttribute("target-type"); - if (targetType.isEmpty() && parentModelForm != null) { - targetType = parentModelForm.targetType; - } - this.targetType = targetType; - FlexibleMapAccessor> defaultMapName = FlexibleMapAccessor.getInstance(formElement - .getAttribute("default-map-name")); - if (defaultMapName.isEmpty() && parentModelForm != null) { - defaultMapName = parentModelForm.defaultMapName; - } - this.defaultMapName = defaultMapName; - FlexibleStringExpander targetWindowExdr = FlexibleStringExpander.getInstance(formElement.getAttribute("target-window")); - if (targetWindowExdr.isEmpty() && parentModelForm != null) { - targetWindowExdr = parentModelForm.targetWindowExdr; - } - this.targetWindowExdr = targetWindowExdr; - String hideHeader = formElement.getAttribute("hide-header"); - if (hideHeader.isEmpty() && parentModelForm != null) { - this.hideHeader = parentModelForm.hideHeader; - } else { - this.hideHeader = "true".equals(hideHeader); - } - String clientAutocompleteFields = formElement.getAttribute("client-autocomplete-fields"); - if (clientAutocompleteFields.isEmpty() && parentModelForm != null) { - this.clientAutocompleteFields = parentModelForm.clientAutocompleteFields; - } else { - this.clientAutocompleteFields = !"false".equals(formElement.getAttribute("client-autocomplete-fields")); - } - FlexibleStringExpander paginateTarget = FlexibleStringExpander.getInstance(formElement.getAttribute("paginate-target")); - if (paginateTarget.isEmpty() && parentModelForm != null) { - paginateTarget = parentModelForm.paginateTarget; - } - this.paginateTarget = paginateTarget; - ArrayList altTargets = new ArrayList(); - if (parentModelForm != null) { - altTargets.addAll(parentModelForm.altTargets); - } - for (Element altTargetElement : UtilXml.childElementList(formElement, "alt-target")) { - altTargets.add(new AltTarget(altTargetElement)); - } - altTargets.trimToSize(); - this.altTargets = Collections.unmodifiableList(altTargets); - ArrayList actions = new ArrayList(); - if (parentModelForm != null) { - actions.addAll(parentModelForm.actions); - } - Element actionsElement = UtilXml.firstChildElement(formElement, "actions"); - if (actionsElement != null) { - actions.addAll(ModelFormAction.readSubActions(this, actionsElement)); - } - actions.trimToSize(); - this.actions = Collections.unmodifiableList(actions); - ArrayList rowActions = new ArrayList(); - if (parentModelForm != null) { - rowActions.addAll(parentModelForm.rowActions); - } - Element rowActionsElement = UtilXml.firstChildElement(formElement, "row-actions"); - if (rowActionsElement != null) { - rowActions.addAll(ModelFormAction.readSubActions(this, rowActionsElement)); - } - rowActions.trimToSize(); - this.rowActions = Collections.unmodifiableList(rowActions); - ArrayList onPaginateUpdateAreas = new ArrayList(); - ArrayList onSubmitUpdateAreas = new ArrayList(); - ArrayList onSortColumnUpdateAreas = new ArrayList(); - if (parentModelForm != null) { - onPaginateUpdateAreas.addAll(parentModelForm.onPaginateUpdateAreas); - onSubmitUpdateAreas.addAll(parentModelForm.onSubmitUpdateAreas); - onSortColumnUpdateAreas.addAll(parentModelForm.onSortColumnUpdateAreas); - } - for (Element updateAreaElement : UtilXml.childElementList(formElement, "on-event-update-area")) { - UpdateArea updateArea = new UpdateArea(updateAreaElement, defaultServiceName, defaultEntityName); - if ("paginate".equals(updateArea.getEventType())) { - int index = onPaginateUpdateAreas.indexOf(updateArea); - if (index != -1) { - if (!updateArea.areaTarget.isEmpty()) { - onPaginateUpdateAreas.set(index, updateArea); - } else { - // blank target indicates a removing override - onPaginateUpdateAreas.remove(index); - } - } else { - onPaginateUpdateAreas.add(updateArea); - } - } else if ("submit".equals(updateArea.getEventType())) { - int index = onSubmitUpdateAreas.indexOf(updateArea); - if (index != -1) { - onSubmitUpdateAreas.set(index, updateArea); - } else { - onSubmitUpdateAreas.add(updateArea); - } - } else if ("sort-column".equals(updateArea.getEventType())) { - int index = onSortColumnUpdateAreas.indexOf(updateArea); - if (index != -1) { - if (!updateArea.areaTarget.isEmpty()) { - onSortColumnUpdateAreas.set(index, updateArea); - } else { - // blank target indicates a removing override - onSortColumnUpdateAreas.remove(index); - } - } else { - onSortColumnUpdateAreas.add(updateArea); - } - } - } - onPaginateUpdateAreas.trimToSize(); - this.onPaginateUpdateAreas = Collections.unmodifiableList(onPaginateUpdateAreas); - onSubmitUpdateAreas.trimToSize(); - this.onSubmitUpdateAreas = Collections.unmodifiableList(onSubmitUpdateAreas); - onSortColumnUpdateAreas.trimToSize(); - this.onSortColumnUpdateAreas = Collections.unmodifiableList(onSortColumnUpdateAreas); - ArrayList altRowStyles = new ArrayList(); - if (parentModelForm != null) { - altRowStyles.addAll(parentModelForm.altRowStyles); - } - for (Element altRowStyleElement : UtilXml.childElementList(formElement, "alt-row-style")) { - AltRowStyle altRowStyle = new AltRowStyle(altRowStyleElement); - altRowStyles.add(altRowStyle); - } - altRowStyles.trimToSize(); - this.altRowStyles = Collections.unmodifiableList(altRowStyles); - Set useWhenFields = new HashSet(); - if (parentModelForm != null) { - useWhenFields.addAll(parentModelForm.useWhenFields); - } - ArrayList fieldBuilderList = new ArrayList(); - Map fieldBuilderMap = new HashMap(); - if (parentModelForm != null) { - // Create this fieldList/Map from clones of parentModelForm's - for (ModelFormField parentChildField : parentModelForm.fieldList) { - ModelFormFieldBuilder builder = new ModelFormFieldBuilder(parentChildField); - builder.setModelForm(this); - fieldBuilderList.add(builder); - fieldBuilderMap.put(builder.getName(), builder); - } - } - Map fieldGroupMap = new HashMap(); - if (parentModelForm != null) { - fieldGroupMap.putAll(parentModelForm.fieldGroupMap); - } - ArrayList fieldGroupList = new ArrayList(); - if (parentModelForm != null) { - fieldGroupList.addAll(parentModelForm.fieldGroupList); - } - ArrayList lastOrderFields = new ArrayList(); - if (parentModelForm != null) { - lastOrderFields.addAll(parentModelForm.lastOrderFields); - } - String sortFieldParameterName = formElement.getAttribute("sort-field-parameter-name"); - if (sortFieldParameterName.isEmpty() && parentModelForm != null) { - this.sortFieldParameterName = parentModelForm.targetType; - } else { - this.sortFieldParameterName = "sortField"; - } - String defaultRequiredFieldStyle = formElement.getAttribute("default-required-field-style"); - if (defaultRequiredFieldStyle.isEmpty() && parentModelForm != null) { - defaultRequiredFieldStyle = parentModelForm.defaultRequiredFieldStyle; - } - this.defaultRequiredFieldStyle = defaultRequiredFieldStyle; - String defaultSortFieldStyle = formElement.getAttribute("default-sort-field-style"); - if (defaultSortFieldStyle.isEmpty() && parentModelForm != null) { - this.defaultSortFieldStyle = parentModelForm.defaultSortFieldStyle; - } else { - this.defaultSortFieldStyle = DEFAULT_SORT_FIELD_STYLE; - } - String defaultSortFieldAscStyle = formElement.getAttribute("default-sort-field-asc-style"); - if (defaultSortFieldAscStyle.isEmpty() && parentModelForm != null) { - this.defaultSortFieldAscStyle = parentModelForm.defaultSortFieldAscStyle; - } else { - this.defaultSortFieldAscStyle = DEFAULT_SORT_FIELD_ASC_STYLE; - } - String defaultSortFieldDescStyle = formElement.getAttribute("default-sort-field-desc-style"); - if (defaultSortFieldDescStyle.isEmpty() && parentModelForm != null) { - this.defaultSortFieldDescStyle = parentModelForm.defaultSortFieldDescStyle; - } else { - this.defaultSortFieldDescStyle = DEFAULT_SORT_FIELD_DESC_STYLE; - } - String paginateTargetAnchor = formElement.getAttribute("paginate-target-anchor"); - if (paginateTargetAnchor.isEmpty() && parentModelForm != null) { - paginateTargetAnchor = parentModelForm.paginateTargetAnchor; - } - this.paginateTargetAnchor = paginateTargetAnchor; - FlexibleStringExpander paginateIndexField = FlexibleStringExpander.getInstance(formElement - .getAttribute("paginate-index-field")); - if (paginateIndexField.isEmpty() && parentModelForm != null) { - paginateIndexField = parentModelForm.paginateIndexField; - } - this.paginateIndexField = paginateIndexField; - FlexibleStringExpander paginateSizeField = FlexibleStringExpander.getInstance(formElement - .getAttribute("paginate-size-field")); - if (paginateSizeField.isEmpty() && parentModelForm != null) { - paginateSizeField = parentModelForm.paginateSizeField; - } - this.paginateSizeField = paginateSizeField; - FlexibleStringExpander overrideListSize = FlexibleStringExpander.getInstance(formElement - .getAttribute("override-list-size")); - if (overrideListSize.isEmpty() && parentModelForm != null) { - overrideListSize = parentModelForm.overrideListSize; - } - this.overrideListSize = overrideListSize; - FlexibleStringExpander paginateFirstLabel = FlexibleStringExpander.getInstance(formElement - .getAttribute("paginate-first-label")); - if (paginateFirstLabel.isEmpty() && parentModelForm != null) { - paginateFirstLabel = parentModelForm.paginateFirstLabel; - } - this.paginateFirstLabel = paginateFirstLabel; - FlexibleStringExpander paginatePreviousLabel = FlexibleStringExpander.getInstance(formElement - .getAttribute("paginate-previous-label")); - if (paginatePreviousLabel.isEmpty() && parentModelForm != null) { - paginatePreviousLabel = parentModelForm.paginatePreviousLabel; - } - this.paginatePreviousLabel = paginatePreviousLabel; - FlexibleStringExpander paginateNextLabel = FlexibleStringExpander.getInstance(formElement - .getAttribute("paginate-next-label")); - if (paginateNextLabel.isEmpty() && parentModelForm != null) { - paginateNextLabel = parentModelForm.paginateNextLabel; - } - this.paginateNextLabel = paginateNextLabel; - FlexibleStringExpander paginateLastLabel = FlexibleStringExpander.getInstance(formElement - .getAttribute("paginate-last-label")); - if (paginateLastLabel.isEmpty() && parentModelForm != null) { - paginateLastLabel = parentModelForm.paginateLastLabel; - } - this.paginateLastLabel = paginateLastLabel; - FlexibleStringExpander paginateViewSizeLabel = FlexibleStringExpander.getInstance(formElement - .getAttribute("paginate-viewsize-label")); - if (paginateViewSizeLabel.isEmpty() && parentModelForm != null) { - paginateViewSizeLabel = parentModelForm.paginateViewSizeLabel; - } - this.paginateViewSizeLabel = paginateViewSizeLabel; - String paginateStyle = formElement.getAttribute("paginate-style"); - if (paginateStyle.isEmpty() && parentModelForm != null) { - this.paginateStyle = parentModelForm.paginateStyle; - } else { - this.paginateStyle = DEFAULT_PAG_STYLE; - } - FlexibleStringExpander paginate = FlexibleStringExpander.getInstance(formElement.getAttribute("paginate")); - if (paginate.isEmpty() && parentModelForm != null) { - paginate = parentModelForm.paginate; - } - this.paginate = paginate; - String skipStart = formElement.getAttribute("skip-start"); - if (skipStart.isEmpty() && parentModelForm != null) { - this.skipStart = parentModelForm.skipStart; - } else { - this.skipStart = "true".equals(skipStart); - } - String skipEnd = formElement.getAttribute("skip-end"); - if (skipEnd.isEmpty() && parentModelForm != null) { - this.skipEnd = parentModelForm.skipEnd; - } else { - this.skipEnd = "true".equals(skipEnd); - } - String useRowSubmit = formElement.getAttribute("use-row-submit"); - if (useRowSubmit.isEmpty() && parentModelForm != null) { - this.useRowSubmit = parentModelForm.useRowSubmit; - } else { - this.useRowSubmit = "true".equals(useRowSubmit); - } - FlexibleStringExpander rowCountExdr = FlexibleStringExpander.getInstance(formElement.getAttribute("row-count")); - if (rowCountExdr.isEmpty() && parentModelForm != null) { - rowCountExdr = parentModelForm.rowCountExdr; - } - this.rowCountExdr = paginate; - ArrayList multiSubmitBuilders = new ArrayList(); - ArrayList autoFieldsServices = new ArrayList(); - ArrayList autoFieldsEntities = new ArrayList(); - ArrayList sortOrderFields = new ArrayList(); - this.defaultFieldGroup = new FieldGroup(null, this, sortOrderFields, fieldGroupMap); - for (Element autoFieldsServiceElement : UtilXml.childElementList(formElement, "auto-fields-service")) { - AutoFieldsService autoFieldsService = new AutoFieldsService(autoFieldsServiceElement); - autoFieldsServices.add(autoFieldsService); - addAutoFieldsFromService(autoFieldsService, entityModelReader, dispatchContext, useWhenFields, fieldBuilderList, fieldBuilderMap); - } - for (Element autoFieldsEntityElement : UtilXml.childElementList(formElement, "auto-fields-entity")) { - AutoFieldsEntity autoFieldsEntity = new AutoFieldsEntity(autoFieldsEntityElement); - autoFieldsEntities.add(autoFieldsEntity); - addAutoFieldsFromEntity(autoFieldsEntity, entityModelReader, useWhenFields, fieldBuilderList, fieldBuilderMap); - } - String thisType = this.getType(); - for (Element fieldElement : UtilXml.childElementList(formElement, "field")) { - ModelFormFieldBuilder builder = new ModelFormFieldBuilder(fieldElement, this, entityModelReader, dispatchContext); - FieldInfo fieldInfo = builder.getFieldInfo(); - if (thisType.equals("multi") && fieldInfo instanceof ModelFormField.SubmitField) { - multiSubmitBuilders.add(builder); - } else { - addUpdateField(builder, useWhenFields, fieldBuilderList, fieldBuilderMap); - } - } - // get the sort-order - Element sortOrderElement = UtilXml.firstChildElement(formElement, "sort-order"); - if (sortOrderElement != null) { - FieldGroup lastFieldGroup = new FieldGroup(null, this, sortOrderFields, fieldGroupMap); - fieldGroupList.add(lastFieldGroup); - // read in sort-field - for (Element sortFieldElement : UtilXml.childElementList(sortOrderElement)) { - String tagName = sortFieldElement.getTagName(); - if (tagName.equals("sort-field")) { - String fieldName = sortFieldElement.getAttribute("name"); - String position = sortFieldElement.getAttribute("position"); - sortOrderFields.add(new SortField(fieldName, position)); - fieldGroupMap.put(fieldName, lastFieldGroup); - } else if (tagName.equals("last-field")) { - String fieldName = sortFieldElement.getAttribute("name"); - fieldGroupMap.put(fieldName, lastFieldGroup); - lastOrderFields.add(fieldName); - } else if (tagName.equals("banner")) { - Banner thisBanner = new Banner(sortFieldElement); - fieldGroupList.add(thisBanner); - lastFieldGroup = new FieldGroup(null, this, sortOrderFields, fieldGroupMap); - fieldGroupList.add(lastFieldGroup); - } else if (tagName.equals("field-group")) { - FieldGroup thisFieldGroup = new FieldGroup(sortFieldElement, this, sortOrderFields, fieldGroupMap); - fieldGroupList.add(thisFieldGroup); - lastFieldGroup = new FieldGroup(null, this, sortOrderFields, fieldGroupMap); - fieldGroupList.add(lastFieldGroup); - } - } - } - if (sortOrderFields.size() > 0) { - ArrayList sortedFields = new ArrayList(); - for (SortField sortField : sortOrderFields) { - String fieldName = sortField.getFieldName(); - if (UtilValidate.isEmpty(fieldName)) { - continue; - } - // get all fields with the given name from the existing list and put them in the sorted list - Iterator fieldIter = fieldBuilderList.iterator(); - while (fieldIter.hasNext()) { - ModelFormFieldBuilder builder = fieldIter.next(); - if (fieldName.equals(builder.getName())) { - // matched the name; remove from the original last and add to the sorted list - if (UtilValidate.isNotEmpty(sortField.getPosition())) { - builder.setPosition(sortField.getPosition()); - } - fieldIter.remove(); - sortedFields.add(builder); - } - } - } - // now add all of the rest of the fields from fieldList, ie those that were not explicitly listed in the sort order - sortedFields.addAll(fieldBuilderList); - // sortedFields all done, set fieldList - fieldBuilderList = sortedFields; - } - if (UtilValidate.isNotEmpty(lastOrderFields)) { - List lastedFields = new LinkedList(); - for (String fieldName : lastOrderFields) { - if (UtilValidate.isEmpty(fieldName)) { - continue; - } - // get all fields with the given name from the existing list and put them in the lasted list - Iterator fieldIter = fieldBuilderList.iterator(); - while (fieldIter.hasNext()) { - ModelFormFieldBuilder builder = fieldIter.next(); - if (fieldName.equals(builder.getName())) { - // matched the name; remove from the original last and add to the lasted list - fieldIter.remove(); - lastedFields.add(builder); - } - } - } - //now put all lastedFields at the field list end - fieldBuilderList.addAll(lastedFields); - } - List fieldList = new ArrayList(fieldBuilderList.size()); - for (ModelFormFieldBuilder builder : fieldBuilderList) { - fieldList.add(builder.build()); - } - this.fieldList = Collections.unmodifiableList(fieldList); - List multiSubmitFields = new ArrayList(multiSubmitBuilders.size()); - for (ModelFormFieldBuilder builder : multiSubmitBuilders) { - multiSubmitFields.add(builder.build()); - } - this.multiSubmitFields = Collections.unmodifiableList(multiSubmitFields); - this.useWhenFields = Collections.unmodifiableSet(useWhenFields); - this.fieldGroupMap = Collections.unmodifiableMap(fieldGroupMap); - fieldGroupList.trimToSize(); - this.fieldGroupList = Collections.unmodifiableList(fieldGroupList); - lastOrderFields.trimToSize(); - this.lastOrderFields = Collections.unmodifiableList(lastOrderFields); - autoFieldsServices.trimToSize(); - this.autoFieldsServices = Collections.unmodifiableList(autoFieldsServices); - autoFieldsEntities.trimToSize(); - this.autoFieldsEntities = Collections.unmodifiableList(autoFieldsEntities); - sortOrderFields.trimToSize(); - this.sortOrderFields = Collections.unmodifiableList(sortOrderFields); - String focusFieldName = formElement.getAttribute("focus-field-name"); - if (focusFieldName.isEmpty() && parentModelForm != null) { - focusFieldName = parentModelForm.focusFieldName; - } - this.focusFieldName = focusFieldName; - } - - @Override - public void accept(ModelWidgetVisitor visitor) throws Exception { - visitor.visit(this); - } - - private void addAutoFieldsFromEntity(AutoFieldsEntity autoFieldsEntity, ModelReader entityModelReader, - Set useWhenFields, List fieldBuilderList, Map fieldBuilderMap) { - // read entity def and auto-create fields - ModelEntity modelEntity = null; - try { - modelEntity = entityModelReader.getModelEntity(autoFieldsEntity.entityName); - } catch (GenericEntityException e) { - Debug.logError(e, module); - } - if (modelEntity == null) { - throw new IllegalArgumentException("Error finding Entity with name " + autoFieldsEntity.entityName - + " for auto-fields-entity in a form widget"); - } - Iterator modelFieldIter = modelEntity.getFieldsIterator(); - while (modelFieldIter.hasNext()) { - ModelField modelField = modelFieldIter.next(); - if (modelField.getIsAutoCreatedInternal()) { - // don't ever auto-add these, should only be added if explicitly referenced - continue; - } - ModelFormFieldBuilder builder = new ModelFormFieldBuilder(); - builder.setModelForm(this); - builder.setName(modelField.getName()); - builder.setEntityName(modelEntity.getEntityName()); - builder.setFieldName(modelField.getName()); - builder.induceFieldInfoFromEntityField(modelEntity, modelField, autoFieldsEntity.defaultFieldType); - builder.setPosition(autoFieldsEntity.defaultPosition); - if (UtilValidate.isNotEmpty(autoFieldsEntity.mapName)) { - builder.setMapName(autoFieldsEntity.mapName); - } - addUpdateField(builder, useWhenFields, fieldBuilderList, fieldBuilderMap); - } - } - - private void addAutoFieldsFromService(AutoFieldsService autoFieldsService, ModelReader entityModelReader, - DispatchContext dispatchContext, Set useWhenFields, List fieldBuilderList, - Map fieldBuilderMap) { - // read service def and auto-create fields - ModelService modelService = null; - try { - modelService = dispatchContext.getModelService(autoFieldsService.serviceName); - } catch (GenericServiceException e) { - String errmsg = "Error finding Service with name " + autoFieldsService.serviceName - + " for auto-fields-service in a form widget"; - Debug.logError(e, errmsg, module); - throw new IllegalArgumentException(errmsg); - } - for (ModelParam modelParam : modelService.getInModelParamList()) { - if (modelParam.internal) { - // skip auto params that the service engine populates... - continue; - } - if (modelParam.formDisplay) { - if (UtilValidate.isNotEmpty(modelParam.entityName) && UtilValidate.isNotEmpty(modelParam.fieldName)) { - ModelEntity modelEntity; - try { - modelEntity = entityModelReader.getModelEntity(modelParam.entityName); - if (modelEntity != null) { - ModelField modelField = modelEntity.getField(modelParam.fieldName); - if (modelField != null) { - // okay, populate using the entity field info... - ModelFormFieldBuilder builder = new ModelFormFieldBuilder(); - builder.setModelForm(this); - builder.setName(modelField.getName()); - builder.setEntityName(modelEntity.getEntityName()); - builder.setFieldName(modelField.getName()); - builder.induceFieldInfoFromEntityField(modelEntity, modelField, autoFieldsService.defaultFieldType); - if (UtilValidate.isNotEmpty(autoFieldsService.mapName)) { - builder.setMapName(autoFieldsService.mapName); - } - builder.setRequiredField(!modelParam.optional); - addUpdateField(builder, useWhenFields, fieldBuilderList, fieldBuilderMap); - // continue to skip creating based on service param - continue; - } - } - } catch (GenericEntityException e) { - Debug.logError(e, module); - } - } - ModelFormFieldBuilder builder = new ModelFormFieldBuilder(); - builder.setModelForm(this); - builder.setName(modelParam.name); - builder.setServiceName(modelService.name); - builder.setAttributeName(modelParam.name); - builder.setTitle(modelParam.formLabel); - builder.setRequiredField(!modelParam.optional); - builder.induceFieldInfoFromServiceParam(modelService, modelParam, autoFieldsService.defaultFieldType); - builder.setPosition(autoFieldsService.defaultPosition); - if (UtilValidate.isNotEmpty(autoFieldsService.mapName)) { - builder.setMapName(autoFieldsService.mapName); - } - addUpdateField(builder, useWhenFields, fieldBuilderList, fieldBuilderMap); - } - } - } - - private void addUpdateField(ModelFormFieldBuilder builder, Set useWhenFields, - List fieldBuilderList, Map fieldBuilderMap) { - if (!builder.getUseWhen().isEmpty() || useWhenFields.contains(builder.getName())) { - useWhenFields.add(builder.getName()); - // is a conditional field, add to the List but don't worry about the Map - //for adding to list, see if there is another field with that name in the list and if so, put it before that one - boolean inserted = false; - for (int i = 0; i < fieldBuilderList.size(); i++) { - ModelFormFieldBuilder curField = fieldBuilderList.get(i); - if (curField.getName() != null && curField.getName().equals(builder.getName())) { - fieldBuilderList.add(i, builder); - inserted = true; - break; - } - } - if (!inserted) { - fieldBuilderList.add(builder); - } - return; - } else { - // not a conditional field, see if a named field exists in Map - ModelFormFieldBuilder existingField = fieldBuilderMap.get(builder.getName()); - if (existingField != null) { - // does exist, update the field by doing a merge/override - existingField.mergeOverrideModelFormField(builder); - } else { - // does not exist, add to List and Map - fieldBuilderList.add(builder); - fieldBuilderMap.put(builder.getName(), builder); - } - } - } - - public List getActions() { - return actions; - } - - public List getAltRowStyles() { - return altRowStyles; - } - - public List getAltTargets() { - return altTargets; - } - - public List getAutoFieldsEntities() { - return autoFieldsEntities; - } - - public List getAutoFieldsServices() { - return autoFieldsServices; - } - - public Interpreter getBshInterpreter(Map context) throws EvalError { - Interpreter bsh = (Interpreter) context.get("bshInterpreter"); - if (bsh == null) { - bsh = BshUtil.makeInterpreter(context); - context.put("bshInterpreter", bsh); - } - return bsh; - } - - @Override - public String getBoundaryCommentName() { - return formLocation + "#" + getName(); - } - - public boolean getClientAutocompleteFields() { - return this.clientAutocompleteFields; - } - - public String getContainerId() { - // use the name if there is no id - if (UtilValidate.isNotEmpty(this.containerId)) { - return this.containerId; - } else { - return this.getName(); - } - } - - public String getContainerStyle() { - return this.containerStyle; - } - - public String getDefaultEntityName() { - return this.defaultEntityName; - } - - public FieldGroup getDefaultFieldGroup() { - return defaultFieldGroup; - } - - public Map getDefaultMap(Map context) { - return this.defaultMapName.get(context); - } - - public String getDefaultMapName() { - return this.defaultMapName.getOriginalName(); - } - - public String getDefaultRequiredFieldStyle() { - return this.defaultRequiredFieldStyle; - } - - public String getDefaultServiceName() { - return this.defaultServiceName; - } - - public String getDefaultSortFieldAscStyle() { - return this.defaultSortFieldAscStyle; - } - - public String getDefaultSortFieldDescStyle() { - return this.defaultSortFieldDescStyle; - } - - public String getDefaultSortFieldStyle() { - return this.defaultSortFieldStyle; - } - - public String getDefaultTableStyle() { - return this.defaultTableStyle; - } - - public String getDefaultTitleAreaStyle() { - return this.defaultTitleAreaStyle; - } - - public String getDefaultTitleStyle() { - return this.defaultTitleStyle; - } - - public String getDefaultTooltipStyle() { - return this.defaultTooltipStyle; - } - - public int getDefaultViewSize() { - return defaultViewSize; - } - - public String getDefaultWidgetAreaStyle() { - return this.defaultWidgetAreaStyle; - } - - public String getDefaultWidgetStyle() { - return this.defaultWidgetStyle; - } - - public String getEvenRowStyle() { - return this.evenRowStyle; - } - - public List getFieldGroupList() { - return fieldGroupList; - } - - public Map getFieldGroupMap() { - return fieldGroupMap; - } - - public List getFieldList() { - return fieldList; - } - - public String getFocusFieldName() { - return focusFieldName; - } - - public String getFormLocation() { - return this.formLocation; - } - - public String getFormTitleAreaStyle() { - return this.formTitleAreaStyle; - } - - public String getFormWidgetAreaStyle() { - return this.formWidgetAreaStyle; - } - - public String getHeaderRowStyle() { - return this.headerRowStyle; - } - - public boolean getHideHeader() { - return this.hideHeader; - } - - public String getItemIndexSeparator() { - if (UtilValidate.isNotEmpty(this.itemIndexSeparator)) { - return this.itemIndexSeparator; - } else { - return "_o_"; - } - } - - public List getLastOrderFields() { - return lastOrderFields; - } - - public String getListEntryName() { - return this.listEntryName; - } - - public String getListName() { - return this.listName; - } - - public String getMultiPaginateIndexField(Map context) { - String field = this.paginateIndexField.expandString(context); - if (UtilValidate.isEmpty(field)) { - field = DEFAULT_PAG_INDEX_FIELD; - } - // append the paginator number - field = field + "_" + WidgetWorker.getPaginatorNumber(context); - return field; - } - - public String getMultiPaginateSizeField(Map context) { - String field = this.paginateSizeField.expandString(context); - if (UtilValidate.isEmpty(field)) { - field = DEFAULT_PAG_SIZE_FIELD; - } - // append the paginator number - field = field + "_" + WidgetWorker.getPaginatorNumber(context); - return field; - } - - public List getMultiSubmitFields() { - return this.multiSubmitFields; - } - - public String getOddRowStyle() { - return this.oddRowStyle; - } - - public List getOnPaginateUpdateAreas() { - return this.onPaginateUpdateAreas; - } - - public List getOnSortColumnUpdateAreas() { - return this.onSortColumnUpdateAreas; - } - - /* Returns the list of ModelForm.UpdateArea objects. - */ - public List getOnSubmitUpdateAreas() { - return this.onSubmitUpdateAreas; - } - - public String getOverrideListSize() { - return overrideListSize.getOriginal(); - } - - public int getOverrideListSize(Map context) { - int listSize = 0; - if (!this.overrideListSize.isEmpty()) { - String size = this.overrideListSize.expandString(context); - try { - size = size.replaceAll("[^0-9.]", ""); - listSize = Integer.parseInt(size); - } catch (NumberFormatException e) { - Debug.logError(e, "Error getting override list size from value " + size, module); - } - } - return listSize; - } - - public String getPaginate() { - return paginate.getOriginal(); - } - - public boolean getPaginate(Map context) { - String paginate = this.paginate.expandString(context); - if (!paginate.isEmpty()) { - return Boolean.valueOf(paginate).booleanValue(); - } else { - return true; - } - } - - public String getPaginateFirstLabel() { - return paginateFirstLabel.getOriginal(); - } - - public String getPaginateFirstLabel(Map context) { - Locale locale = (Locale) context.get("locale"); - String field = this.paginateFirstLabel.expandString(context); - if (UtilValidate.isEmpty(field)) { - field = UtilProperties.getMessage("CommonUiLabels", "CommonFirst", locale); - } - return field; - } - - public String getPaginateFirstStyle() { - return DEFAULT_PAG_FIRST_STYLE; - } - - public String getPaginateIndexField() { - return paginateIndexField.getOriginal(); - } - - public String getPaginateIndexField(Map context) { - String field = this.paginateIndexField.expandString(context); - if (field.isEmpty()) { - return DEFAULT_PAG_INDEX_FIELD; - } - return field; - } - - public String getPaginateLastLabel() { - return paginateLastLabel.getOriginal(); - } - - public String getPaginateLastLabel(Map context) { - Locale locale = (Locale) context.get("locale"); - String field = this.paginateLastLabel.expandString(context); - if (UtilValidate.isEmpty(field)) { - field = UtilProperties.getMessage("CommonUiLabels", "CommonLast", locale); - } - return field; - } - - public String getPaginateLastStyle() { - return DEFAULT_PAG_LAST_STYLE; - } - - public String getPaginateNextLabel() { - return paginateNextLabel.getOriginal(); - } - - public String getPaginateNextLabel(Map context) { - String field = this.paginateNextLabel.expandString(context); - if (field.isEmpty()) { - Locale locale = (Locale) context.get("locale"); - return UtilProperties.getMessage("CommonUiLabels", "CommonNext", locale); - } - return field; - } - - public String getPaginateNextStyle() { - return DEFAULT_PAG_NEXT_STYLE; - } - - public String getPaginatePreviousLabel() { - return paginatePreviousLabel.getOriginal(); - } - - public String getPaginatePreviousLabel(Map context) { - String field = this.paginatePreviousLabel.expandString(context); - if (field.isEmpty()) { - Locale locale = (Locale) context.get("locale"); - field = UtilProperties.getMessage("CommonUiLabels", "CommonPrevious", locale); - } - return field; - } - - public String getPaginatePreviousStyle() { - return DEFAULT_PAG_PREV_STYLE; - } - - public String getPaginateSizeField() { - return paginateSizeField.getOriginal(); - } - - public String getPaginateSizeField(Map context) { - String field = this.paginateSizeField.expandString(context); - if (field.isEmpty()) { - return DEFAULT_PAG_SIZE_FIELD; - } - return field; - } - - public String getPaginateStyle() { - return this.paginateStyle; - } - - public String getPaginateTarget() { - return paginateTarget.getOriginal(); - } - - public String getPaginateTarget(Map context) { - String targ = this.paginateTarget.expandString(context); - if (targ.isEmpty()) { - Map parameters = UtilGenerics.cast(context.get("parameters")); - if (parameters != null && parameters.containsKey("targetRequestUri")) { - targ = (String) parameters.get("targetRequestUri"); - } - } - return targ; - } - - public String getPaginateTargetAnchor() { - return this.paginateTargetAnchor; - } - - public String getPaginateViewSizeLabel() { - return paginateViewSizeLabel.getOriginal(); - } - - public String getPaginateViewSizeLabel(Map context) { - String field = this.paginateViewSizeLabel.expandString(context); - if (field.isEmpty()) { - Locale locale = (Locale) context.get("locale"); - return UtilProperties.getMessage("CommonUiLabels", "CommonItemsPerPage", locale); - } - return field; - } - - private ModelForm getParentForm(Element formElement, ModelReader entityModelReader, DispatchContext dispatchContext) { - ModelForm parent = null; - String parentResource = formElement.getAttribute("extends-resource"); - String parentForm = formElement.getAttribute("extends"); - if (parentForm.length() > 0) { - // check if we have a resource name (part of the string before the ?) - if (parentResource.length() > 0) { - try { - parent = FormFactory.getFormFromLocation(parentResource, parentForm, entityModelReader, dispatchContext); - } catch (Exception e) { - Debug.logError(e, "Failed to load parent form definition '" + parentForm + "' at resource '" + parentResource - + "'", module); - } - } else if (!parentForm.equals(formElement.getAttribute("name"))) { - // try to find a form definition in the same file - Element rootElement = formElement.getOwnerDocument().getDocumentElement(); - List formElements = UtilXml.childElementList(rootElement, "form"); - //Uncomment below to add support for abstract forms - //formElements.addAll(UtilXml.childElementList(rootElement, "abstract-form")); - for (Element formElementEntry : formElements) { - if (formElementEntry.getAttribute("name").equals(parentForm)) { - parent = new ModelForm(formElementEntry, parentResource, entityModelReader, dispatchContext); - break; - } - } - if (parent == null) { - Debug.logError("Failed to find parent form definition '" + parentForm + "' in same document.", module); - } - } else { - Debug.logError("Recursive form definition found for '" + formElement.getAttribute("name") + ".'", module); - } - } - return parent; - } - - public String getParentFormLocation() { - return this.parentModelForm == null ? null : this.parentModelForm.getFormLocation(); - } - - public String getParentFormName() { - return this.parentModelForm == null ? null : this.parentModelForm.getName(); - } - - public ModelForm getParentModelForm() { - return parentModelForm; - } - - public String getPassedRowCount(Map context) { - return rowCountExdr.expandString(context); - } - - public List getRowActions() { - return rowActions; - } - - public String getRowCount() { - return rowCountExdr.getOriginal(); - } - - public boolean getSeparateColumns() { - return this.separateColumns; - } - - public boolean getSkipEnd() { - return this.skipEnd; - } - - public boolean getSkipStart() { - return this.skipStart; - } - - public String getSortField(Map context) { - String value = null; - try { - value = (String) context.get(this.sortFieldParameterName); - if (value == null) { - Map parameters = UtilGenerics.cast(context.get("parameters")); - if (parameters != null) { - value = parameters.get(this.sortFieldParameterName); - } - } - } catch (Exception e) { - Debug.logWarning(e, "Error getting sortField: " + e.toString(), module); - } - return value; - } - - public String getSortFieldParameterName() { - return this.sortFieldParameterName; - } - - public List getSortOrderFields() { - return sortOrderFields; - } - - /** - * iterate through alt-row-styles list to see if should be used, then add style - * @return The style for item row - */ - public String getStyleAltRowStyle(Map context) { - String styles = ""; - try { - // use the same Interpreter (ie with the same context setup) for all evals - Interpreter bsh = this.getBshInterpreter(context); - for (AltRowStyle altRowStyle : this.altRowStyles) { - Object retVal = bsh.eval(StringUtil.convertOperatorSubstitutions(altRowStyle.useWhen)); - // retVal should be a Boolean, if not something weird is up... - if (retVal instanceof Boolean) { - Boolean boolVal = (Boolean) retVal; - if (boolVal.booleanValue()) { - styles += altRowStyle.style; - } - } else { - throw new IllegalArgumentException("Return value from style condition eval was not a Boolean: " - + retVal.getClass().getName() + " [" + retVal + "] of form " + getName()); - } - } - } catch (EvalError e) { - String errmsg = "Error evaluating BeanShell style conditions on form " + getName(); - Debug.logError(e, errmsg, module); - throw new IllegalArgumentException(errmsg); - } - return styles; - } - - public String getTarget() { - return target.getOriginal(); - } - - /** iterate through altTargets list to see if any should be used, if not return original target - * @return The target for this Form - */ - public String getTarget(Map context, String targetType) { - Map expanderContext = context; - UtilCodec.SimpleEncoder simpleEncoder = (UtilCodec.SimpleEncoder) context.get("simpleEncoder"); - if (simpleEncoder != null) { - expanderContext = UtilCodec.HtmlEncodingMapWrapper.getHtmlEncodingMapWrapper(context, simpleEncoder); - } - try { - // use the same Interpreter (ie with the same context setup) for all evals - Interpreter bsh = this.getBshInterpreter(context); - for (AltTarget altTarget : this.altTargets) { - String useWhen = FlexibleStringExpander.expandString(altTarget.useWhen, context); - Object retVal = bsh.eval(StringUtil.convertOperatorSubstitutions(useWhen)); - boolean condTrue = false; - // retVal should be a Boolean, if not something weird is up... - if (retVal instanceof Boolean) { - Boolean boolVal = (Boolean) retVal; - condTrue = boolVal.booleanValue(); - } else { - throw new IllegalArgumentException("Return value from target condition eval was not a Boolean: " - + retVal.getClass().getName() + " [" + retVal + "] of form " + getName()); - } - - if (condTrue && !targetType.equals("inter-app")) { - return altTarget.targetExdr.expandString(expanderContext); - } - } - } catch (EvalError e) { - String errmsg = "Error evaluating BeanShell target conditions on form " + getName(); - Debug.logError(e, errmsg, module); - throw new IllegalArgumentException(errmsg); - } - return target.expandString(expanderContext); - } - - public String getTargetType() { - return this.targetType; - } - - public String getTargetWindow() { - return targetWindowExdr.getOriginal(); - } - - public String getTargetWindow(Map context) { - return this.targetWindowExdr.expandString(context); - } - - public String getTitle() { - return this.title; - } - - public String getTooltip() { - return this.tooltip; - } - - public String getType() { - return this.type; - } - - public boolean getUseRowSubmit() { - return this.useRowSubmit; - } - - public Set getUseWhenFields() { - return useWhenFields; - } - public boolean getGroupColumns() { - return groupColumns; - } - - public boolean isOverridenListSize() { - return !this.overrideListSize.isEmpty(); - } - - public void runFormActions(Map context) { - AbstractModelAction.runSubActions(this.actions, context); - } - - public static class AltRowStyle { - public final String useWhen; - public final String style; - - public AltRowStyle(Element altRowStyleElement) { - this.useWhen = altRowStyleElement.getAttribute("use-when"); - this.style = altRowStyleElement.getAttribute("style"); - } - } - - public static class AltTarget { - public final String useWhen; - public final FlexibleStringExpander targetExdr; - - public AltTarget(Element altTargetElement) { - this.useWhen = altTargetElement.getAttribute("use-when"); - this.targetExdr = FlexibleStringExpander.getInstance(altTargetElement.getAttribute("target")); - } - - @Override - public boolean equals(Object obj) { - return obj instanceof AltTarget && obj.hashCode() == this.hashCode(); - } - - @Override - public int hashCode() { - return useWhen.hashCode(); - } - } - - public static class AutoFieldsEntity { - public final String entityName; - public final String mapName; - public final String defaultFieldType; - public final int defaultPosition; - - public AutoFieldsEntity(Element element) { - this.entityName = element.getAttribute("entity-name"); - this.mapName = element.getAttribute("map-name"); - this.defaultFieldType = element.getAttribute("default-field-type"); - String positionStr = element.getAttribute("default-position"); - int position = 1; - try { - if (UtilValidate.isNotEmpty(positionStr)) { - position = Integer.valueOf(positionStr); - } - } catch (Exception e) { - Debug.logError(e, "Could not convert position attribute of the field element to an integer: [" + positionStr - + "], using the default of the form renderer", module); - } - this.defaultPosition = position; - } - } - - public static class AutoFieldsService { - public final String serviceName; - public final String mapName; - public final String defaultFieldType; - public final int defaultPosition; - - public AutoFieldsService(Element element) { - this.serviceName = element.getAttribute("service-name"); - this.mapName = element.getAttribute("map-name"); - this.defaultFieldType = element.getAttribute("default-field-type"); - String positionStr = element.getAttribute("default-position"); - int position = 1; - try { - if (UtilValidate.isNotEmpty(positionStr)) { - position = Integer.valueOf(positionStr); - } - } catch (Exception e) { - Debug.logError(e, "Could not convert position attribute of the field element to an integer: [" + positionStr - + "], using the default of the form renderer", module); - } - this.defaultPosition = position; - } - } - - public static class Banner implements FieldGroupBase { - public final FlexibleStringExpander style; - public final FlexibleStringExpander text; - public final FlexibleStringExpander textStyle; - public final FlexibleStringExpander leftText; - public final FlexibleStringExpander leftTextStyle; - public final FlexibleStringExpander rightText; - public final FlexibleStringExpander rightTextStyle; - - public Banner(Element sortOrderElement) { - this.style = FlexibleStringExpander.getInstance(sortOrderElement.getAttribute("style")); - this.text = FlexibleStringExpander.getInstance(sortOrderElement.getAttribute("text")); - this.textStyle = FlexibleStringExpander.getInstance(sortOrderElement.getAttribute("text-style")); - this.leftText = FlexibleStringExpander.getInstance(sortOrderElement.getAttribute("left-text")); - this.leftTextStyle = FlexibleStringExpander.getInstance(sortOrderElement.getAttribute("left-text-style")); - this.rightText = FlexibleStringExpander.getInstance(sortOrderElement.getAttribute("right-text")); - this.rightTextStyle = FlexibleStringExpander.getInstance(sortOrderElement.getAttribute("right-text-style")); - } - - public String getLeftText(Map context) { - return this.leftText.expandString(context); - } - - public String getLeftTextStyle(Map context) { - return this.leftTextStyle.expandString(context); - } - - public String getRightText(Map context) { - return this.rightText.expandString(context); - } - - public String getRightTextStyle(Map context) { - return this.rightTextStyle.expandString(context); - } - - public String getStyle(Map context) { - return this.style.expandString(context); - } - - public String getText(Map context) { - return this.text.expandString(context); - } - - public String getTextStyle(Map context) { - return this.textStyle.expandString(context); - } - - public void renderString(Appendable writer, Map context, FormStringRenderer formStringRenderer) - throws IOException { - formStringRenderer.renderBanner(writer, context, this); - } - } - - public static class FieldGroup implements FieldGroupBase { - private static AtomicInteger baseSeqNo = new AtomicInteger(0); - private static final String baseId = "_G"; - private final String id; - private final String style; - private final String title; - private final boolean collapsible; - private final boolean initiallyCollapsed; - private final ModelForm modelForm; - - public FieldGroup(Element sortOrderElement, ModelForm modelForm, List sortOrderFields, - Map fieldGroupMap) { - this.modelForm = modelForm; - String id; - String style = ""; - String title = ""; - boolean collapsible = false; - boolean initiallyCollapsed = false; - if (sortOrderElement != null) { - id = sortOrderElement.getAttribute("id"); - if (id.isEmpty()) { - String lastGroupId = baseId + baseSeqNo.getAndIncrement() + "_"; - id = lastGroupId; - } - style = sortOrderElement.getAttribute("style"); - title = sortOrderElement.getAttribute("title"); - collapsible = "true".equals(sortOrderElement.getAttribute("collapsible")); - initiallyCollapsed = "true".equals(sortOrderElement.getAttribute("initially-collapsed")); - if (initiallyCollapsed) { - collapsible = true; - } - for (Element sortFieldElement : UtilXml.childElementList(sortOrderElement, "sort-field")) { - sortOrderFields.add(new SortField(sortFieldElement.getAttribute("name"), sortFieldElement - .getAttribute("position"))); - fieldGroupMap.put(sortFieldElement.getAttribute("name"), this); - } - } else { - String lastGroupId = baseId + baseSeqNo.getAndIncrement() + "_"; - id = lastGroupId; - } - this.id = id; - this.style = style; - this.title = title; - this.collapsible = collapsible; - this.initiallyCollapsed = initiallyCollapsed; - } - - public Boolean collapsible() { - return this.collapsible; - } - - public String getId() { - return this.id; - } - - public String getStyle() { - return this.style; - } - - public String getTitle() { - return this.title; - } - - public Boolean initiallyCollapsed() { - return this.initiallyCollapsed; - } - - public void renderEndString(Appendable writer, Map context, FormStringRenderer formStringRenderer) - throws IOException { - formStringRenderer.renderFormatSingleWrapperClose(writer, context, modelForm); - if (!modelForm.fieldGroupList.isEmpty()) { - if (shouldUse(context)) { - formStringRenderer.renderFieldGroupClose(writer, context, this); - } - } - } - - public void renderStartString(Appendable writer, Map context, FormStringRenderer formStringRenderer) - throws IOException { - if (!modelForm.fieldGroupList.isEmpty()) { - if (shouldUse(context)) { - formStringRenderer.renderFieldGroupOpen(writer, context, this); - } - } - formStringRenderer.renderFormatSingleWrapperOpen(writer, context, modelForm); - } - - public boolean shouldUse(Map context) { - for (String fieldName : modelForm.fieldGroupMap.keySet()) { - FieldGroupBase group = modelForm.fieldGroupMap.get(fieldName); - if (group instanceof FieldGroup) { - FieldGroup fieldgroup = (FieldGroup) group; - if (this.id.equals(fieldgroup.getId())) { - for (ModelFormField modelField : modelForm.fieldList) { - if (fieldName.equals(modelField.getName()) && modelField.shouldUse(context)) { - return true; - } - } - } - } - } - return false; - } - } - - public static interface FieldGroupBase { - } - - public static class SortField { - private final String fieldName; - private final Integer position; - - public SortField(String name) { - this(name, null); - } - - public SortField(String name, String position) { - this.fieldName = name; - if (UtilValidate.isNotEmpty(position)) { - Integer posParam = null; - try { - posParam = Integer.valueOf(position); - } catch (Exception e) {/* just ignore the exception*/ - } - this.position = posParam; - } else { - this.position = null; - } - } - - public String getFieldName() { - return this.fieldName; - } - - public Integer getPosition() { - return this.position; - } - } - - /** The UpdateArea class implements the <on-event-update-area> - * elements used in form widgets. - */ - public static class UpdateArea { - private final String eventType; - private final String areaId; - private final String areaTarget; - private final String defaultServiceName; - private final String defaultEntityName; - private final CommonWidgetModels.AutoEntityParameters autoEntityParameters; - private final CommonWidgetModels.AutoServiceParameters autoServiceParameters; - private final List parameterList; - - public UpdateArea(Element updateAreaElement) { - this(updateAreaElement, null, null); - } - - /** XML constructor. - * @param updateAreaElement The <on-xxx-update-area> - * XML element. - */ - public UpdateArea(Element updateAreaElement, String defaultServiceName, String defaultEntityName) { - this.eventType = updateAreaElement.getAttribute("event-type"); - this.areaId = updateAreaElement.getAttribute("area-id"); - this.areaTarget = updateAreaElement.getAttribute("area-target"); - this.defaultServiceName = defaultServiceName; - this.defaultEntityName = defaultEntityName; - List parameterElementList = UtilXml.childElementList(updateAreaElement, "parameter"); - if (parameterElementList.isEmpty()) { - this.parameterList = Collections.emptyList(); - } else { - List parameterList = new ArrayList(parameterElementList.size()); - for (Element parameterElement : parameterElementList) { - parameterList.add(new CommonWidgetModels.Parameter(parameterElement)); - } - this.parameterList = Collections.unmodifiableList(parameterList); - } - Element autoServiceParamsElement = UtilXml.firstChildElement(updateAreaElement, "auto-parameters-service"); - if (autoServiceParamsElement != null) { - this.autoServiceParameters = new CommonWidgetModels.AutoServiceParameters(autoServiceParamsElement); - } else { - this.autoServiceParameters = null; - } - Element autoEntityParamsElement = UtilXml.firstChildElement(updateAreaElement, "auto-parameters-entity"); - if (autoEntityParamsElement != null) { - this.autoEntityParameters = new CommonWidgetModels.AutoEntityParameters(autoEntityParamsElement); - } else { - this.autoEntityParameters = null; - } - } - - /** String constructor. - * @param areaId The id of the widget element to be updated - * @param areaTarget The target URL called to update the area - */ - public UpdateArea(String eventType, String areaId, String areaTarget) { - this.eventType = eventType; - this.areaId = areaId; - this.areaTarget = areaTarget; - this.defaultServiceName = null; - this.defaultEntityName = null; - this.parameterList = Collections.emptyList(); - this.autoServiceParameters = null; - this.autoEntityParameters = null; - } - - @Override - public boolean equals(Object obj) { - return obj instanceof UpdateArea && obj.hashCode() == this.hashCode(); - } - - public String getAreaId() { - return areaId; - } - - public String getAreaTarget(Map context) { - return FlexibleStringExpander.expandString(areaTarget, context); - } - - public String getEventType() { - return eventType; - } - - public Map getParameterMap(Map context) { - Map fullParameterMap = new HashMap(); - if (autoServiceParameters != null) { - fullParameterMap.putAll(autoServiceParameters.getParametersMap(context, defaultServiceName)); - } - if (autoEntityParameters != null) { - fullParameterMap.putAll(autoEntityParameters.getParametersMap(context, defaultEntityName)); - } - for (CommonWidgetModels.Parameter parameter : this.parameterList) { - fullParameterMap.put(parameter.getName(), parameter.getValue(context)); - } - - return fullParameterMap; - } - - @Override - public int hashCode() { - return areaId.hashCode(); - } - - public String getAreaTarget() { - return areaTarget; - } - - public String getDefaultServiceName() { - return defaultServiceName; - } - - public String getDefaultEntityName() { - return defaultEntityName; - } - - public CommonWidgetModels.AutoEntityParameters getAutoEntityParameters() { - return autoEntityParameters; - } - - public CommonWidgetModels.AutoServiceParameters getAutoServiceParameters() { - return autoServiceParameters; - } - - public List getParameterList() { - return parameterList; - } - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.model; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.atomic.AtomicInteger; + +import org.ofbiz.base.util.BshUtil; +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.StringUtil; +import org.ofbiz.base.util.UtilCodec; +import org.ofbiz.base.util.UtilGenerics; +import org.ofbiz.base.util.UtilProperties; +import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.base.util.UtilXml; +import org.ofbiz.base.util.collections.FlexibleMapAccessor; +import org.ofbiz.base.util.string.FlexibleStringExpander; +import org.ofbiz.entity.GenericEntityException; +import org.ofbiz.entity.model.ModelEntity; +import org.ofbiz.entity.model.ModelField; +import org.ofbiz.entity.model.ModelReader; +import org.ofbiz.service.DispatchContext; +import org.ofbiz.service.GenericServiceException; +import org.ofbiz.service.ModelParam; +import org.ofbiz.service.ModelService; +import org.ofbiz.widget.WidgetWorker; +import org.ofbiz.widget.renderer.FormStringRenderer; +import org.w3c.dom.Element; + +import bsh.EvalError; +import bsh.Interpreter; + +/** + * Models the <form> element. + * + * @see widget-form.xsd + */ +@SuppressWarnings("serial") +public class ModelForm extends ModelWidget { + + /* + * ----------------------------------------------------------------------- * + * DEVELOPERS PLEASE READ + * ----------------------------------------------------------------------- * + * + * This model is intended to be a read-only data structure that represents + * an XML element. Outside of object construction, the class should not + * have any behaviors. All behavior should be contained in model visitors. + * + * Instances of this class will be shared by multiple threads - therefore + * it is immutable. DO NOT CHANGE THE OBJECT'S STATE AT RUN TIME! + * + * BE VERY CAREFUL when implementing "extends" - parent form collections + * must be added to child collections, not replace them. In other words, + * do not assign parent collection fields to child collection fields. + * + */ + + public static final String module = ModelForm.class.getName(); + public static final String DEFAULT_FORM_RESULT_LIST_NAME = "defaultFormResultList"; + /** Pagination settings and defaults. */ + public static int DEFAULT_PAGE_SIZE = 10; + public static int MAX_PAGE_SIZE = 10000; + public static String DEFAULT_PAG_INDEX_FIELD = "viewIndex"; + public static String DEFAULT_PAG_SIZE_FIELD = "viewSize"; + public static String DEFAULT_PAG_STYLE = "nav-pager"; + public static String DEFAULT_PAG_FIRST_STYLE = "nav-first"; + public static String DEFAULT_PAG_PREV_STYLE = "nav-previous"; + public static String DEFAULT_PAG_NEXT_STYLE = "nav-next"; + public static String DEFAULT_PAG_LAST_STYLE = "nav-last"; + /** Sort field default styles. */ + public static String DEFAULT_SORT_FIELD_STYLE = "sort-order"; + public static String DEFAULT_SORT_FIELD_ASC_STYLE = "sort-order-asc"; + public static String DEFAULT_SORT_FIELD_DESC_STYLE = "sort-order-desc"; + private final List actions; + private final List altRowStyles; + private final List altTargets; + private final List autoFieldsEntities; + private final List autoFieldsServices; + private final boolean clientAutocompleteFields; + private final String containerId; + private final String containerStyle; + private final String defaultEntityName; + /** This field group will be the "catch-all" group for fields that are not + * included in an explicit field-group. + */ + private final FieldGroup defaultFieldGroup; + private final FlexibleMapAccessor> defaultMapName; + private final String defaultRequiredFieldStyle; + private final String defaultServiceName; + private final String defaultSortFieldAscStyle; + private final String defaultSortFieldDescStyle; + private final String defaultSortFieldStyle; + private final String defaultTableStyle; + private final String defaultTitleAreaStyle; + private final String defaultTitleStyle; + private final String defaultTooltipStyle; + private final int defaultViewSize; + private final String defaultWidgetAreaStyle; + private final String defaultWidgetStyle; + private final String evenRowStyle; + /** This is a list of FieldGroups in the order they were created. + * Can also include Banner objects. + */ + private final List fieldGroupList; + /** This Map is keyed with the field name and has a FieldGroup for the value. + * Can also include Banner objects. + */ + private final Map fieldGroupMap; + /** This List will contain one copy of each field for each field name in the order + * they were encountered in the service, entity, or form definition; field definitions + * with constraints will also be in this list but may appear multiple times for the same + * field name. + * + * When rendering the form the order in this list should be following and it should not be + * necessary to use the Map. The Map is used when loading the form definition to keep the + * list clean and implement the override features for field definitions. + */ + private final List fieldList; + private final String focusFieldName; + private final String formLocation; + private final String formTitleAreaStyle; + private final String formWidgetAreaStyle; + private final boolean groupColumns; + private final String headerRowStyle; + private final boolean hideHeader; + private final String itemIndexSeparator; + private final List lastOrderFields; + private final String listEntryName; + private final String listName; + private final List multiSubmitFields; + private final String oddRowStyle; + /** On Paginate areas to be updated. */ + private final List onPaginateUpdateAreas; + /** On Sort Column areas to be updated. */ + private final List onSortColumnUpdateAreas; + /** On Submit areas to be updated. */ + private final List onSubmitUpdateAreas; + private final FlexibleStringExpander overrideListSize; + private final FlexibleStringExpander paginate; + private final FlexibleStringExpander paginateFirstLabel; + private final FlexibleStringExpander paginateIndexField; + private final FlexibleStringExpander paginateLastLabel; + private final FlexibleStringExpander paginateNextLabel; + private final FlexibleStringExpander paginatePreviousLabel; + private final FlexibleStringExpander paginateSizeField; + private final String paginateStyle; + private final FlexibleStringExpander paginateTarget; + private final String paginateTargetAnchor; + private final FlexibleStringExpander paginateViewSizeLabel; + private final ModelForm parentModelForm; + private final List rowActions; + private final FlexibleStringExpander rowCountExdr; + private final boolean separateColumns; + private final boolean skipEnd; + private final boolean skipStart; + private final String sortFieldParameterName; + private final List sortOrderFields; + private final FlexibleStringExpander target; + private final String targetType; + private final FlexibleStringExpander targetWindowExdr; + private final String title; + private final String tooltip; + private final String type; + private final boolean useRowSubmit; + /** Keeps track of conditional fields to help ensure that only one is rendered + */ + private final Set useWhenFields; + + /** XML Constructor */ + public ModelForm(Element formElement, String formLocation, ModelReader entityModelReader, DispatchContext dispatchContext) { + super(formElement); + this.formLocation = formLocation; + parentModelForm = getParentForm(formElement, entityModelReader, dispatchContext); + int defaultViewSizeInt = DEFAULT_PAGE_SIZE; + String viewSize = formElement.getAttribute("view-size"); + if (viewSize.isEmpty()) { + if (parentModelForm != null) { + defaultViewSizeInt = parentModelForm.defaultViewSize; + } else { + defaultViewSizeInt = UtilProperties.getPropertyAsInteger("widget.properties", "widget.form.defaultViewSize", + defaultViewSizeInt); + } + } else { + try { + defaultViewSizeInt = Integer.valueOf(viewSize); + } catch (NumberFormatException e) { + } + } + this.defaultViewSize = defaultViewSizeInt; + String type = formElement.getAttribute("type"); + if (type.isEmpty() && parentModelForm != null) { + type = parentModelForm.type; + } + this.type = type; + FlexibleStringExpander target = FlexibleStringExpander.getInstance(formElement.getAttribute("target")); + if (target.isEmpty() && parentModelForm != null) { + target = parentModelForm.target; + } + this.target = target; + String containerId = formElement.getAttribute("id"); + if (containerId.isEmpty() && parentModelForm != null) { + containerId = parentModelForm.containerId; + } + this.containerId = containerId; + String containerStyle = formElement.getAttribute("style"); + if (containerStyle.isEmpty() && parentModelForm != null) { + containerStyle = parentModelForm.containerStyle; + } + this.containerStyle = containerStyle; + String title = formElement.getAttribute("title"); + if (title.isEmpty() && parentModelForm != null) { + title = parentModelForm.title; + } + this.title = title; + String tooltip = formElement.getAttribute("tooltip"); + if (tooltip.isEmpty() && parentModelForm != null) { + tooltip = parentModelForm.tooltip; + } + this.tooltip = tooltip; + String listName = formElement.getAttribute("list-name"); + if (listName.isEmpty()) { + if (parentModelForm != null) { + listName = parentModelForm.listName; + } else { + listName = DEFAULT_FORM_RESULT_LIST_NAME; + } + } + this.listName = listName; + String listEntryName = formElement.getAttribute("list-entry-name"); + if (listEntryName.isEmpty() && parentModelForm != null) { + listEntryName = parentModelForm.listEntryName; + } + this.listEntryName = listEntryName; + String defaultEntityName = formElement.getAttribute("default-entity-name"); + if (defaultEntityName.isEmpty() && parentModelForm != null) { + defaultEntityName = parentModelForm.defaultEntityName; + } + this.defaultEntityName = defaultEntityName; + String defaultServiceName = formElement.getAttribute("default-service-name"); + if (defaultServiceName.isEmpty() && parentModelForm != null) { + defaultServiceName = parentModelForm.defaultServiceName; + } + this.defaultServiceName = defaultServiceName; + String formTitleAreaStyle = formElement.getAttribute("form-title-area-style"); + if (formTitleAreaStyle.isEmpty() && parentModelForm != null) { + formTitleAreaStyle = parentModelForm.formTitleAreaStyle; + } + this.formTitleAreaStyle = formTitleAreaStyle; + String formWidgetAreaStyle = formElement.getAttribute("form-widget-area-style"); + if (formWidgetAreaStyle.isEmpty() && parentModelForm != null) { + formWidgetAreaStyle = parentModelForm.formWidgetAreaStyle; + } + this.formWidgetAreaStyle = formWidgetAreaStyle; + String defaultTitleAreaStyle = formElement.getAttribute("default-title-area-style"); + if (defaultTitleAreaStyle.isEmpty() && parentModelForm != null) { + defaultTitleAreaStyle = parentModelForm.defaultTitleAreaStyle; + } + this.defaultTitleAreaStyle = defaultTitleAreaStyle; + String defaultWidgetAreaStyle = formElement.getAttribute("default-widget-area-style"); + if (defaultWidgetAreaStyle.isEmpty() && parentModelForm != null) { + defaultWidgetAreaStyle = parentModelForm.defaultWidgetAreaStyle; + } + this.defaultWidgetAreaStyle = defaultWidgetAreaStyle; + String oddRowStyle = formElement.getAttribute("odd-row-style"); + if (oddRowStyle.isEmpty() && parentModelForm != null) { + oddRowStyle = parentModelForm.oddRowStyle; + } + this.oddRowStyle = oddRowStyle; + String evenRowStyle = formElement.getAttribute("even-row-style"); + if (evenRowStyle.isEmpty() && parentModelForm != null) { + evenRowStyle = parentModelForm.evenRowStyle; + } + this.evenRowStyle = evenRowStyle; + String defaultTableStyle = formElement.getAttribute("default-table-style"); + if (defaultTableStyle.isEmpty() && parentModelForm != null) { + defaultTableStyle = parentModelForm.defaultTableStyle; + } + this.defaultTableStyle = defaultTableStyle; + String headerRowStyle = formElement.getAttribute("header-row-style"); + if (headerRowStyle.isEmpty() && parentModelForm != null) { + headerRowStyle = parentModelForm.headerRowStyle; + } + this.headerRowStyle = headerRowStyle; + String defaultTitleStyle = formElement.getAttribute("default-title-style"); + if (defaultTitleStyle.isEmpty() && parentModelForm != null) { + defaultTitleStyle = parentModelForm.defaultTitleStyle; + } + this.defaultTitleStyle = defaultTitleStyle; + String defaultWidgetStyle = formElement.getAttribute("default-widget-style"); + if (defaultWidgetStyle.isEmpty() && parentModelForm != null) { + defaultWidgetStyle = parentModelForm.defaultWidgetStyle; + } + this.defaultWidgetStyle = defaultWidgetStyle; + String defaultTooltipStyle = formElement.getAttribute("default-tooltip-style"); + if (defaultTooltipStyle.isEmpty() && parentModelForm != null) { + defaultTooltipStyle = parentModelForm.defaultTooltipStyle; + } + this.defaultTooltipStyle = defaultTooltipStyle; + String itemIndexSeparator = formElement.getAttribute("item-index-separator"); + if (itemIndexSeparator.isEmpty() && parentModelForm != null) { + itemIndexSeparator = parentModelForm.itemIndexSeparator; + } + this.itemIndexSeparator = itemIndexSeparator; + String separateColumns = formElement.getAttribute("separate-columns"); + if (separateColumns.isEmpty() && parentModelForm != null) { + this.separateColumns = parentModelForm.separateColumns; + } else { + this.separateColumns = "true".equals(separateColumns); + } + String groupColumns = formElement.getAttribute("group-columns"); + if (groupColumns.isEmpty() && parentModelForm != null) { + this.groupColumns = parentModelForm.groupColumns; + } else { + this.groupColumns = !"false".equals(groupColumns); + } + String targetType = formElement.getAttribute("target-type"); + if (targetType.isEmpty() && parentModelForm != null) { + targetType = parentModelForm.targetType; + } + this.targetType = targetType; + FlexibleMapAccessor> defaultMapName = FlexibleMapAccessor.getInstance(formElement + .getAttribute("default-map-name")); + if (defaultMapName.isEmpty() && parentModelForm != null) { + defaultMapName = parentModelForm.defaultMapName; + } + this.defaultMapName = defaultMapName; + FlexibleStringExpander targetWindowExdr = FlexibleStringExpander.getInstance(formElement.getAttribute("target-window")); + if (targetWindowExdr.isEmpty() && parentModelForm != null) { + targetWindowExdr = parentModelForm.targetWindowExdr; + } + this.targetWindowExdr = targetWindowExdr; + String hideHeader = formElement.getAttribute("hide-header"); + if (hideHeader.isEmpty() && parentModelForm != null) { + this.hideHeader = parentModelForm.hideHeader; + } else { + this.hideHeader = "true".equals(hideHeader); + } + String clientAutocompleteFields = formElement.getAttribute("client-autocomplete-fields"); + if (clientAutocompleteFields.isEmpty() && parentModelForm != null) { + this.clientAutocompleteFields = parentModelForm.clientAutocompleteFields; + } else { + this.clientAutocompleteFields = !"false".equals(formElement.getAttribute("client-autocomplete-fields")); + } + FlexibleStringExpander paginateTarget = FlexibleStringExpander.getInstance(formElement.getAttribute("paginate-target")); + if (paginateTarget.isEmpty() && parentModelForm != null) { + paginateTarget = parentModelForm.paginateTarget; + } + this.paginateTarget = paginateTarget; + ArrayList altTargets = new ArrayList(); + if (parentModelForm != null) { + altTargets.addAll(parentModelForm.altTargets); + } + for (Element altTargetElement : UtilXml.childElementList(formElement, "alt-target")) { + altTargets.add(new AltTarget(altTargetElement)); + } + altTargets.trimToSize(); + this.altTargets = Collections.unmodifiableList(altTargets); + ArrayList actions = new ArrayList(); + if (parentModelForm != null) { + actions.addAll(parentModelForm.actions); + } + Element actionsElement = UtilXml.firstChildElement(formElement, "actions"); + if (actionsElement != null) { + actions.addAll(ModelFormAction.readSubActions(this, actionsElement)); + } + actions.trimToSize(); + this.actions = Collections.unmodifiableList(actions); + ArrayList rowActions = new ArrayList(); + if (parentModelForm != null) { + rowActions.addAll(parentModelForm.rowActions); + } + Element rowActionsElement = UtilXml.firstChildElement(formElement, "row-actions"); + if (rowActionsElement != null) { + rowActions.addAll(ModelFormAction.readSubActions(this, rowActionsElement)); + } + rowActions.trimToSize(); + this.rowActions = Collections.unmodifiableList(rowActions); + ArrayList onPaginateUpdateAreas = new ArrayList(); + ArrayList onSubmitUpdateAreas = new ArrayList(); + ArrayList onSortColumnUpdateAreas = new ArrayList(); + if (parentModelForm != null) { + onPaginateUpdateAreas.addAll(parentModelForm.onPaginateUpdateAreas); + onSubmitUpdateAreas.addAll(parentModelForm.onSubmitUpdateAreas); + onSortColumnUpdateAreas.addAll(parentModelForm.onSortColumnUpdateAreas); + } + for (Element updateAreaElement : UtilXml.childElementList(formElement, "on-event-update-area")) { + UpdateArea updateArea = new UpdateArea(updateAreaElement, defaultServiceName, defaultEntityName); + if ("paginate".equals(updateArea.getEventType())) { + int index = onPaginateUpdateAreas.indexOf(updateArea); + if (index != -1) { + if (!updateArea.areaTarget.isEmpty()) { + onPaginateUpdateAreas.set(index, updateArea); + } else { + // blank target indicates a removing override + onPaginateUpdateAreas.remove(index); + } + } else { + onPaginateUpdateAreas.add(updateArea); + } + } else if ("submit".equals(updateArea.getEventType())) { + int index = onSubmitUpdateAreas.indexOf(updateArea); + if (index != -1) { + onSubmitUpdateAreas.set(index, updateArea); + } else { + onSubmitUpdateAreas.add(updateArea); + } + } else if ("sort-column".equals(updateArea.getEventType())) { + int index = onSortColumnUpdateAreas.indexOf(updateArea); + if (index != -1) { + if (!updateArea.areaTarget.isEmpty()) { + onSortColumnUpdateAreas.set(index, updateArea); + } else { + // blank target indicates a removing override + onSortColumnUpdateAreas.remove(index); + } + } else { + onSortColumnUpdateAreas.add(updateArea); + } + } + } + onPaginateUpdateAreas.trimToSize(); + this.onPaginateUpdateAreas = Collections.unmodifiableList(onPaginateUpdateAreas); + onSubmitUpdateAreas.trimToSize(); + this.onSubmitUpdateAreas = Collections.unmodifiableList(onSubmitUpdateAreas); + onSortColumnUpdateAreas.trimToSize(); + this.onSortColumnUpdateAreas = Collections.unmodifiableList(onSortColumnUpdateAreas); + ArrayList altRowStyles = new ArrayList(); + if (parentModelForm != null) { + altRowStyles.addAll(parentModelForm.altRowStyles); + } + for (Element altRowStyleElement : UtilXml.childElementList(formElement, "alt-row-style")) { + AltRowStyle altRowStyle = new AltRowStyle(altRowStyleElement); + altRowStyles.add(altRowStyle); + } + altRowStyles.trimToSize(); + this.altRowStyles = Collections.unmodifiableList(altRowStyles); + Set useWhenFields = new HashSet(); + if (parentModelForm != null) { + useWhenFields.addAll(parentModelForm.useWhenFields); + } + ArrayList fieldBuilderList = new ArrayList(); + Map fieldBuilderMap = new HashMap(); + if (parentModelForm != null) { + // Create this fieldList/Map from clones of parentModelForm's + for (ModelFormField parentChildField : parentModelForm.fieldList) { + ModelFormFieldBuilder builder = new ModelFormFieldBuilder(parentChildField); + builder.setModelForm(this); + fieldBuilderList.add(builder); + fieldBuilderMap.put(builder.getName(), builder); + } + } + Map fieldGroupMap = new HashMap(); + if (parentModelForm != null) { + fieldGroupMap.putAll(parentModelForm.fieldGroupMap); + } + ArrayList fieldGroupList = new ArrayList(); + if (parentModelForm != null) { + fieldGroupList.addAll(parentModelForm.fieldGroupList); + } + ArrayList lastOrderFields = new ArrayList(); + if (parentModelForm != null) { + lastOrderFields.addAll(parentModelForm.lastOrderFields); + } + String sortFieldParameterName = formElement.getAttribute("sort-field-parameter-name"); + if (sortFieldParameterName.isEmpty() && parentModelForm != null) { + this.sortFieldParameterName = parentModelForm.targetType; + } else { + this.sortFieldParameterName = "sortField"; + } + String defaultRequiredFieldStyle = formElement.getAttribute("default-required-field-style"); + if (defaultRequiredFieldStyle.isEmpty() && parentModelForm != null) { + defaultRequiredFieldStyle = parentModelForm.defaultRequiredFieldStyle; + } + this.defaultRequiredFieldStyle = defaultRequiredFieldStyle; + String defaultSortFieldStyle = formElement.getAttribute("default-sort-field-style"); + if (defaultSortFieldStyle.isEmpty() && parentModelForm != null) { + this.defaultSortFieldStyle = parentModelForm.defaultSortFieldStyle; + } else { + this.defaultSortFieldStyle = DEFAULT_SORT_FIELD_STYLE; + } + String defaultSortFieldAscStyle = formElement.getAttribute("default-sort-field-asc-style"); + if (defaultSortFieldAscStyle.isEmpty() && parentModelForm != null) { + this.defaultSortFieldAscStyle = parentModelForm.defaultSortFieldAscStyle; + } else { + this.defaultSortFieldAscStyle = DEFAULT_SORT_FIELD_ASC_STYLE; + } + String defaultSortFieldDescStyle = formElement.getAttribute("default-sort-field-desc-style"); + if (defaultSortFieldDescStyle.isEmpty() && parentModelForm != null) { + this.defaultSortFieldDescStyle = parentModelForm.defaultSortFieldDescStyle; + } else { + this.defaultSortFieldDescStyle = DEFAULT_SORT_FIELD_DESC_STYLE; + } + String paginateTargetAnchor = formElement.getAttribute("paginate-target-anchor"); + if (paginateTargetAnchor.isEmpty() && parentModelForm != null) { + paginateTargetAnchor = parentModelForm.paginateTargetAnchor; + } + this.paginateTargetAnchor = paginateTargetAnchor; + FlexibleStringExpander paginateIndexField = FlexibleStringExpander.getInstance(formElement + .getAttribute("paginate-index-field")); + if (paginateIndexField.isEmpty() && parentModelForm != null) { + paginateIndexField = parentModelForm.paginateIndexField; + } + this.paginateIndexField = paginateIndexField; + FlexibleStringExpander paginateSizeField = FlexibleStringExpander.getInstance(formElement + .getAttribute("paginate-size-field")); + if (paginateSizeField.isEmpty() && parentModelForm != null) { + paginateSizeField = parentModelForm.paginateSizeField; + } + this.paginateSizeField = paginateSizeField; + FlexibleStringExpander overrideListSize = FlexibleStringExpander.getInstance(formElement + .getAttribute("override-list-size")); + if (overrideListSize.isEmpty() && parentModelForm != null) { + overrideListSize = parentModelForm.overrideListSize; + } + this.overrideListSize = overrideListSize; + FlexibleStringExpander paginateFirstLabel = FlexibleStringExpander.getInstance(formElement + .getAttribute("paginate-first-label")); + if (paginateFirstLabel.isEmpty() && parentModelForm != null) { + paginateFirstLabel = parentModelForm.paginateFirstLabel; + } + this.paginateFirstLabel = paginateFirstLabel; + FlexibleStringExpander paginatePreviousLabel = FlexibleStringExpander.getInstance(formElement + .getAttribute("paginate-previous-label")); + if (paginatePreviousLabel.isEmpty() && parentModelForm != null) { + paginatePreviousLabel = parentModelForm.paginatePreviousLabel; + } + this.paginatePreviousLabel = paginatePreviousLabel; + FlexibleStringExpander paginateNextLabel = FlexibleStringExpander.getInstance(formElement + .getAttribute("paginate-next-label")); + if (paginateNextLabel.isEmpty() && parentModelForm != null) { + paginateNextLabel = parentModelForm.paginateNextLabel; + } + this.paginateNextLabel = paginateNextLabel; + FlexibleStringExpander paginateLastLabel = FlexibleStringExpander.getInstance(formElement + .getAttribute("paginate-last-label")); + if (paginateLastLabel.isEmpty() && parentModelForm != null) { + paginateLastLabel = parentModelForm.paginateLastLabel; + } + this.paginateLastLabel = paginateLastLabel; + FlexibleStringExpander paginateViewSizeLabel = FlexibleStringExpander.getInstance(formElement + .getAttribute("paginate-viewsize-label")); + if (paginateViewSizeLabel.isEmpty() && parentModelForm != null) { + paginateViewSizeLabel = parentModelForm.paginateViewSizeLabel; + } + this.paginateViewSizeLabel = paginateViewSizeLabel; + String paginateStyle = formElement.getAttribute("paginate-style"); + if (paginateStyle.isEmpty() && parentModelForm != null) { + this.paginateStyle = parentModelForm.paginateStyle; + } else { + this.paginateStyle = DEFAULT_PAG_STYLE; + } + FlexibleStringExpander paginate = FlexibleStringExpander.getInstance(formElement.getAttribute("paginate")); + if (paginate.isEmpty() && parentModelForm != null) { + paginate = parentModelForm.paginate; + } + this.paginate = paginate; + String skipStart = formElement.getAttribute("skip-start"); + if (skipStart.isEmpty() && parentModelForm != null) { + this.skipStart = parentModelForm.skipStart; + } else { + this.skipStart = "true".equals(skipStart); + } + String skipEnd = formElement.getAttribute("skip-end"); + if (skipEnd.isEmpty() && parentModelForm != null) { + this.skipEnd = parentModelForm.skipEnd; + } else { + this.skipEnd = "true".equals(skipEnd); + } + String useRowSubmit = formElement.getAttribute("use-row-submit"); + if (useRowSubmit.isEmpty() && parentModelForm != null) { + this.useRowSubmit = parentModelForm.useRowSubmit; + } else { + this.useRowSubmit = "true".equals(useRowSubmit); + } + FlexibleStringExpander rowCountExdr = FlexibleStringExpander.getInstance(formElement.getAttribute("row-count")); + if (rowCountExdr.isEmpty() && parentModelForm != null) { + rowCountExdr = parentModelForm.rowCountExdr; + } + this.rowCountExdr = paginate; + ArrayList multiSubmitBuilders = new ArrayList(); + ArrayList autoFieldsServices = new ArrayList(); + ArrayList autoFieldsEntities = new ArrayList(); + ArrayList sortOrderFields = new ArrayList(); + this.defaultFieldGroup = new FieldGroup(null, this, sortOrderFields, fieldGroupMap); + for (Element autoFieldsServiceElement : UtilXml.childElementList(formElement, "auto-fields-service")) { + AutoFieldsService autoFieldsService = new AutoFieldsService(autoFieldsServiceElement); + autoFieldsServices.add(autoFieldsService); + addAutoFieldsFromService(autoFieldsService, entityModelReader, dispatchContext, useWhenFields, fieldBuilderList, fieldBuilderMap); + } + for (Element autoFieldsEntityElement : UtilXml.childElementList(formElement, "auto-fields-entity")) { + AutoFieldsEntity autoFieldsEntity = new AutoFieldsEntity(autoFieldsEntityElement); + autoFieldsEntities.add(autoFieldsEntity); + addAutoFieldsFromEntity(autoFieldsEntity, entityModelReader, useWhenFields, fieldBuilderList, fieldBuilderMap); + } + String thisType = this.getType(); + for (Element fieldElement : UtilXml.childElementList(formElement, "field")) { + ModelFormFieldBuilder builder = new ModelFormFieldBuilder(fieldElement, this, entityModelReader, dispatchContext); + FieldInfo fieldInfo = builder.getFieldInfo(); + if (thisType.equals("multi") && fieldInfo instanceof ModelFormField.SubmitField) { + multiSubmitBuilders.add(builder); + } else { + addUpdateField(builder, useWhenFields, fieldBuilderList, fieldBuilderMap); + } + } + // get the sort-order + Element sortOrderElement = UtilXml.firstChildElement(formElement, "sort-order"); + if (sortOrderElement != null) { + FieldGroup lastFieldGroup = new FieldGroup(null, this, sortOrderFields, fieldGroupMap); + fieldGroupList.add(lastFieldGroup); + // read in sort-field + for (Element sortFieldElement : UtilXml.childElementList(sortOrderElement)) { + String tagName = sortFieldElement.getTagName(); + if (tagName.equals("sort-field")) { + String fieldName = sortFieldElement.getAttribute("name"); + String position = sortFieldElement.getAttribute("position"); + sortOrderFields.add(new SortField(fieldName, position)); + fieldGroupMap.put(fieldName, lastFieldGroup); + } else if (tagName.equals("last-field")) { + String fieldName = sortFieldElement.getAttribute("name"); + fieldGroupMap.put(fieldName, lastFieldGroup); + lastOrderFields.add(fieldName); + } else if (tagName.equals("banner")) { + Banner thisBanner = new Banner(sortFieldElement); + fieldGroupList.add(thisBanner); + lastFieldGroup = new FieldGroup(null, this, sortOrderFields, fieldGroupMap); + fieldGroupList.add(lastFieldGroup); + } else if (tagName.equals("field-group")) { + FieldGroup thisFieldGroup = new FieldGroup(sortFieldElement, this, sortOrderFields, fieldGroupMap); + fieldGroupList.add(thisFieldGroup); + lastFieldGroup = new FieldGroup(null, this, sortOrderFields, fieldGroupMap); + fieldGroupList.add(lastFieldGroup); + } + } + } + if (sortOrderFields.size() > 0) { + ArrayList sortedFields = new ArrayList(); + for (SortField sortField : sortOrderFields) { + String fieldName = sortField.getFieldName(); + if (UtilValidate.isEmpty(fieldName)) { + continue; + } + // get all fields with the given name from the existing list and put them in the sorted list + Iterator fieldIter = fieldBuilderList.iterator(); + while (fieldIter.hasNext()) { + ModelFormFieldBuilder builder = fieldIter.next(); + if (fieldName.equals(builder.getName())) { + // matched the name; remove from the original last and add to the sorted list + if (UtilValidate.isNotEmpty(sortField.getPosition())) { + builder.setPosition(sortField.getPosition()); + } + fieldIter.remove(); + sortedFields.add(builder); + } + } + } + // now add all of the rest of the fields from fieldList, ie those that were not explicitly listed in the sort order + sortedFields.addAll(fieldBuilderList); + // sortedFields all done, set fieldList + fieldBuilderList = sortedFields; + } + if (UtilValidate.isNotEmpty(lastOrderFields)) { + List lastedFields = new LinkedList(); + for (String fieldName : lastOrderFields) { + if (UtilValidate.isEmpty(fieldName)) { + continue; + } + // get all fields with the given name from the existing list and put them in the lasted list + Iterator fieldIter = fieldBuilderList.iterator(); + while (fieldIter.hasNext()) { + ModelFormFieldBuilder builder = fieldIter.next(); + if (fieldName.equals(builder.getName())) { + // matched the name; remove from the original last and add to the lasted list + fieldIter.remove(); + lastedFields.add(builder); + } + } + } + //now put all lastedFields at the field list end + fieldBuilderList.addAll(lastedFields); + } + List fieldList = new ArrayList(fieldBuilderList.size()); + for (ModelFormFieldBuilder builder : fieldBuilderList) { + fieldList.add(builder.build()); + } + this.fieldList = Collections.unmodifiableList(fieldList); + List multiSubmitFields = new ArrayList(multiSubmitBuilders.size()); + for (ModelFormFieldBuilder builder : multiSubmitBuilders) { + multiSubmitFields.add(builder.build()); + } + this.multiSubmitFields = Collections.unmodifiableList(multiSubmitFields); + this.useWhenFields = Collections.unmodifiableSet(useWhenFields); + this.fieldGroupMap = Collections.unmodifiableMap(fieldGroupMap); + fieldGroupList.trimToSize(); + this.fieldGroupList = Collections.unmodifiableList(fieldGroupList); + lastOrderFields.trimToSize(); + this.lastOrderFields = Collections.unmodifiableList(lastOrderFields); + autoFieldsServices.trimToSize(); + this.autoFieldsServices = Collections.unmodifiableList(autoFieldsServices); + autoFieldsEntities.trimToSize(); + this.autoFieldsEntities = Collections.unmodifiableList(autoFieldsEntities); + sortOrderFields.trimToSize(); + this.sortOrderFields = Collections.unmodifiableList(sortOrderFields); + String focusFieldName = formElement.getAttribute("focus-field-name"); + if (focusFieldName.isEmpty() && parentModelForm != null) { + focusFieldName = parentModelForm.focusFieldName; + } + this.focusFieldName = focusFieldName; + } + + @Override + public void accept(ModelWidgetVisitor visitor) throws Exception { + visitor.visit(this); + } + + private void addAutoFieldsFromEntity(AutoFieldsEntity autoFieldsEntity, ModelReader entityModelReader, + Set useWhenFields, List fieldBuilderList, Map fieldBuilderMap) { + // read entity def and auto-create fields + ModelEntity modelEntity = null; + try { + modelEntity = entityModelReader.getModelEntity(autoFieldsEntity.entityName); + } catch (GenericEntityException e) { + Debug.logError(e, module); + } + if (modelEntity == null) { + throw new IllegalArgumentException("Error finding Entity with name " + autoFieldsEntity.entityName + + " for auto-fields-entity in a form widget"); + } + Iterator modelFieldIter = modelEntity.getFieldsIterator(); + while (modelFieldIter.hasNext()) { + ModelField modelField = modelFieldIter.next(); + if (modelField.getIsAutoCreatedInternal()) { + // don't ever auto-add these, should only be added if explicitly referenced + continue; + } + ModelFormFieldBuilder builder = new ModelFormFieldBuilder(); + builder.setModelForm(this); + builder.setName(modelField.getName()); + builder.setEntityName(modelEntity.getEntityName()); + builder.setFieldName(modelField.getName()); + builder.induceFieldInfoFromEntityField(modelEntity, modelField, autoFieldsEntity.defaultFieldType); + builder.setPosition(autoFieldsEntity.defaultPosition); + if (UtilValidate.isNotEmpty(autoFieldsEntity.mapName)) { + builder.setMapName(autoFieldsEntity.mapName); + } + addUpdateField(builder, useWhenFields, fieldBuilderList, fieldBuilderMap); + } + } + + private void addAutoFieldsFromService(AutoFieldsService autoFieldsService, ModelReader entityModelReader, + DispatchContext dispatchContext, Set useWhenFields, List fieldBuilderList, + Map fieldBuilderMap) { + // read service def and auto-create fields + ModelService modelService = null; + try { + modelService = dispatchContext.getModelService(autoFieldsService.serviceName); + } catch (GenericServiceException e) { + String errmsg = "Error finding Service with name " + autoFieldsService.serviceName + + " for auto-fields-service in a form widget"; + Debug.logError(e, errmsg, module); + throw new IllegalArgumentException(errmsg); + } + for (ModelParam modelParam : modelService.getInModelParamList()) { + if (modelParam.internal) { + // skip auto params that the service engine populates... + continue; + } + if (modelParam.formDisplay) { + if (UtilValidate.isNotEmpty(modelParam.entityName) && UtilValidate.isNotEmpty(modelParam.fieldName)) { + ModelEntity modelEntity; + try { + modelEntity = entityModelReader.getModelEntity(modelParam.entityName); + if (modelEntity != null) { + ModelField modelField = modelEntity.getField(modelParam.fieldName); + if (modelField != null) { + // okay, populate using the entity field info... + ModelFormFieldBuilder builder = new ModelFormFieldBuilder(); + builder.setModelForm(this); + builder.setName(modelField.getName()); + builder.setEntityName(modelEntity.getEntityName()); + builder.setFieldName(modelField.getName()); + builder.induceFieldInfoFromEntityField(modelEntity, modelField, autoFieldsService.defaultFieldType); + if (UtilValidate.isNotEmpty(autoFieldsService.mapName)) { + builder.setMapName(autoFieldsService.mapName); + } + builder.setRequiredField(!modelParam.optional); + addUpdateField(builder, useWhenFields, fieldBuilderList, fieldBuilderMap); + // continue to skip creating based on service param + continue; + } + } + } catch (GenericEntityException e) { + Debug.logError(e, module); + } + } + ModelFormFieldBuilder builder = new ModelFormFieldBuilder(); + builder.setModelForm(this); + builder.setName(modelParam.name); + builder.setServiceName(modelService.name); + builder.setAttributeName(modelParam.name); + builder.setTitle(modelParam.formLabel); + builder.setRequiredField(!modelParam.optional); + builder.induceFieldInfoFromServiceParam(modelService, modelParam, autoFieldsService.defaultFieldType); + builder.setPosition(autoFieldsService.defaultPosition); + if (UtilValidate.isNotEmpty(autoFieldsService.mapName)) { + builder.setMapName(autoFieldsService.mapName); + } + addUpdateField(builder, useWhenFields, fieldBuilderList, fieldBuilderMap); + } + } + } + + private void addUpdateField(ModelFormFieldBuilder builder, Set useWhenFields, + List fieldBuilderList, Map fieldBuilderMap) { + if (!builder.getUseWhen().isEmpty() || useWhenFields.contains(builder.getName())) { + useWhenFields.add(builder.getName()); + // is a conditional field, add to the List but don't worry about the Map + //for adding to list, see if there is another field with that name in the list and if so, put it before that one + boolean inserted = false; + for (int i = 0; i < fieldBuilderList.size(); i++) { + ModelFormFieldBuilder curField = fieldBuilderList.get(i); + if (curField.getName() != null && curField.getName().equals(builder.getName())) { + fieldBuilderList.add(i, builder); + inserted = true; + break; + } + } + if (!inserted) { + fieldBuilderList.add(builder); + } + return; + } else { + // not a conditional field, see if a named field exists in Map + ModelFormFieldBuilder existingField = fieldBuilderMap.get(builder.getName()); + if (existingField != null) { + // does exist, update the field by doing a merge/override + existingField.mergeOverrideModelFormField(builder); + } else { + // does not exist, add to List and Map + fieldBuilderList.add(builder); + fieldBuilderMap.put(builder.getName(), builder); + } + } + } + + public List getActions() { + return actions; + } + + public List getAltRowStyles() { + return altRowStyles; + } + + public List getAltTargets() { + return altTargets; + } + + public List getAutoFieldsEntities() { + return autoFieldsEntities; + } + + public List getAutoFieldsServices() { + return autoFieldsServices; + } + + public Interpreter getBshInterpreter(Map context) throws EvalError { + Interpreter bsh = (Interpreter) context.get("bshInterpreter"); + if (bsh == null) { + bsh = BshUtil.makeInterpreter(context); + context.put("bshInterpreter", bsh); + } + return bsh; + } + + @Override + public String getBoundaryCommentName() { + return formLocation + "#" + getName(); + } + + public boolean getClientAutocompleteFields() { + return this.clientAutocompleteFields; + } + + public String getContainerId() { + // use the name if there is no id + if (UtilValidate.isNotEmpty(this.containerId)) { + return this.containerId; + } else { + return this.getName(); + } + } + + public String getContainerStyle() { + return this.containerStyle; + } + + public String getDefaultEntityName() { + return this.defaultEntityName; + } + + public FieldGroup getDefaultFieldGroup() { + return defaultFieldGroup; + } + + public Map getDefaultMap(Map context) { + return this.defaultMapName.get(context); + } + + public String getDefaultMapName() { + return this.defaultMapName.getOriginalName(); + } + + public String getDefaultRequiredFieldStyle() { + return this.defaultRequiredFieldStyle; + } + + public String getDefaultServiceName() { + return this.defaultServiceName; + } + + public String getDefaultSortFieldAscStyle() { + return this.defaultSortFieldAscStyle; + } + + public String getDefaultSortFieldDescStyle() { + return this.defaultSortFieldDescStyle; + } + + public String getDefaultSortFieldStyle() { + return this.defaultSortFieldStyle; + } + + public String getDefaultTableStyle() { + return this.defaultTableStyle; + } + + public String getDefaultTitleAreaStyle() { + return this.defaultTitleAreaStyle; + } + + public String getDefaultTitleStyle() { + return this.defaultTitleStyle; + } + + public String getDefaultTooltipStyle() { + return this.defaultTooltipStyle; + } + + public int getDefaultViewSize() { + return defaultViewSize; + } + + public String getDefaultWidgetAreaStyle() { + return this.defaultWidgetAreaStyle; + } + + public String getDefaultWidgetStyle() { + return this.defaultWidgetStyle; + } + + public String getEvenRowStyle() { + return this.evenRowStyle; + } + + public List getFieldGroupList() { + return fieldGroupList; + } + + public Map getFieldGroupMap() { + return fieldGroupMap; + } + + public List getFieldList() { + return fieldList; + } + + public String getFocusFieldName() { + return focusFieldName; + } + + public String getFormLocation() { + return this.formLocation; + } + + public String getFormTitleAreaStyle() { + return this.formTitleAreaStyle; + } + + public String getFormWidgetAreaStyle() { + return this.formWidgetAreaStyle; + } + + public String getHeaderRowStyle() { + return this.headerRowStyle; + } + + public boolean getHideHeader() { + return this.hideHeader; + } + + public String getItemIndexSeparator() { + if (UtilValidate.isNotEmpty(this.itemIndexSeparator)) { + return this.itemIndexSeparator; + } else { + return "_o_"; + } + } + + public List getLastOrderFields() { + return lastOrderFields; + } + + public String getListEntryName() { + return this.listEntryName; + } + + public String getListName() { + return this.listName; + } + + public String getMultiPaginateIndexField(Map context) { + String field = this.paginateIndexField.expandString(context); + if (UtilValidate.isEmpty(field)) { + field = DEFAULT_PAG_INDEX_FIELD; + } + // append the paginator number + field = field + "_" + WidgetWorker.getPaginatorNumber(context); + return field; + } + + public String getMultiPaginateSizeField(Map context) { + String field = this.paginateSizeField.expandString(context); + if (UtilValidate.isEmpty(field)) { + field = DEFAULT_PAG_SIZE_FIELD; + } + // append the paginator number + field = field + "_" + WidgetWorker.getPaginatorNumber(context); + return field; + } + + public List getMultiSubmitFields() { + return this.multiSubmitFields; + } + + public String getOddRowStyle() { + return this.oddRowStyle; + } + + public List getOnPaginateUpdateAreas() { + return this.onPaginateUpdateAreas; + } + + public List getOnSortColumnUpdateAreas() { + return this.onSortColumnUpdateAreas; + } + + /* Returns the list of ModelForm.UpdateArea objects. + */ + public List getOnSubmitUpdateAreas() { + return this.onSubmitUpdateAreas; + } + + public String getOverrideListSize() { + return overrideListSize.getOriginal(); + } + + public int getOverrideListSize(Map context) { + int listSize = 0; + if (!this.overrideListSize.isEmpty()) { + String size = this.overrideListSize.expandString(context); + try { + size = size.replaceAll("[^0-9.]", ""); + listSize = Integer.parseInt(size); + } catch (NumberFormatException e) { + Debug.logError(e, "Error getting override list size from value " + size, module); + } + } + return listSize; + } + + public String getPaginate() { + return paginate.getOriginal(); + } + + public boolean getPaginate(Map context) { + String paginate = this.paginate.expandString(context); + if (!paginate.isEmpty()) { + return Boolean.valueOf(paginate).booleanValue(); + } else { + return true; + } + } + + public String getPaginateFirstLabel() { + return paginateFirstLabel.getOriginal(); + } + + public String getPaginateFirstLabel(Map context) { + Locale locale = (Locale) context.get("locale"); + String field = this.paginateFirstLabel.expandString(context); + if (UtilValidate.isEmpty(field)) { + field = UtilProperties.getMessage("CommonUiLabels", "CommonFirst", locale); + } + return field; + } + + public String getPaginateFirstStyle() { + return DEFAULT_PAG_FIRST_STYLE; + } + + public String getPaginateIndexField() { + return paginateIndexField.getOriginal(); + } + + public String getPaginateIndexField(Map context) { + String field = this.paginateIndexField.expandString(context); + if (field.isEmpty()) { + return DEFAULT_PAG_INDEX_FIELD; + } + return field; + } + + public String getPaginateLastLabel() { + return paginateLastLabel.getOriginal(); + } + + public String getPaginateLastLabel(Map context) { + Locale locale = (Locale) context.get("locale"); + String field = this.paginateLastLabel.expandString(context); + if (UtilValidate.isEmpty(field)) { + field = UtilProperties.getMessage("CommonUiLabels", "CommonLast", locale); + } + return field; + } + + public String getPaginateLastStyle() { + return DEFAULT_PAG_LAST_STYLE; + } + + public String getPaginateNextLabel() { + return paginateNextLabel.getOriginal(); + } + + public String getPaginateNextLabel(Map context) { + String field = this.paginateNextLabel.expandString(context); + if (field.isEmpty()) { + Locale locale = (Locale) context.get("locale"); + return UtilProperties.getMessage("CommonUiLabels", "CommonNext", locale); + } + return field; + } + + public String getPaginateNextStyle() { + return DEFAULT_PAG_NEXT_STYLE; + } + + public String getPaginatePreviousLabel() { + return paginatePreviousLabel.getOriginal(); + } + + public String getPaginatePreviousLabel(Map context) { + String field = this.paginatePreviousLabel.expandString(context); + if (field.isEmpty()) { + Locale locale = (Locale) context.get("locale"); + field = UtilProperties.getMessage("CommonUiLabels", "CommonPrevious", locale); + } + return field; + } + + public String getPaginatePreviousStyle() { + return DEFAULT_PAG_PREV_STYLE; + } + + public String getPaginateSizeField() { + return paginateSizeField.getOriginal(); + } + + public String getPaginateSizeField(Map context) { + String field = this.paginateSizeField.expandString(context); + if (field.isEmpty()) { + return DEFAULT_PAG_SIZE_FIELD; + } + return field; + } + + public String getPaginateStyle() { + return this.paginateStyle; + } + + public String getPaginateTarget() { + return paginateTarget.getOriginal(); + } + + public String getPaginateTarget(Map context) { + String targ = this.paginateTarget.expandString(context); + if (targ.isEmpty()) { + Map parameters = UtilGenerics.cast(context.get("parameters")); + if (parameters != null && parameters.containsKey("targetRequestUri")) { + targ = (String) parameters.get("targetRequestUri"); + } + } + return targ; + } + + public String getPaginateTargetAnchor() { + return this.paginateTargetAnchor; + } + + public String getPaginateViewSizeLabel() { + return paginateViewSizeLabel.getOriginal(); + } + + public String getPaginateViewSizeLabel(Map context) { + String field = this.paginateViewSizeLabel.expandString(context); + if (field.isEmpty()) { + Locale locale = (Locale) context.get("locale"); + return UtilProperties.getMessage("CommonUiLabels", "CommonItemsPerPage", locale); + } + return field; + } + + private ModelForm getParentForm(Element formElement, ModelReader entityModelReader, DispatchContext dispatchContext) { + ModelForm parent = null; + String parentResource = formElement.getAttribute("extends-resource"); + String parentForm = formElement.getAttribute("extends"); + if (parentForm.length() > 0) { + // check if we have a resource name (part of the string before the ?) + if (parentResource.length() > 0) { + try { + parent = FormFactory.getFormFromLocation(parentResource, parentForm, entityModelReader, dispatchContext); + } catch (Exception e) { + Debug.logError(e, "Failed to load parent form definition '" + parentForm + "' at resource '" + parentResource + + "'", module); + } + } else if (!parentForm.equals(formElement.getAttribute("name"))) { + // try to find a form definition in the same file + Element rootElement = formElement.getOwnerDocument().getDocumentElement(); + List formElements = UtilXml.childElementList(rootElement, "form"); + //Uncomment below to add support for abstract forms + //formElements.addAll(UtilXml.childElementList(rootElement, "abstract-form")); + for (Element formElementEntry : formElements) { + if (formElementEntry.getAttribute("name").equals(parentForm)) { + parent = new ModelForm(formElementEntry, parentResource, entityModelReader, dispatchContext); + break; + } + } + if (parent == null) { + Debug.logError("Failed to find parent form definition '" + parentForm + "' in same document.", module); + } + } else { + Debug.logError("Recursive form definition found for '" + formElement.getAttribute("name") + ".'", module); + } + } + return parent; + } + + public String getParentFormLocation() { + return this.parentModelForm == null ? null : this.parentModelForm.getFormLocation(); + } + + public String getParentFormName() { + return this.parentModelForm == null ? null : this.parentModelForm.getName(); + } + + public ModelForm getParentModelForm() { + return parentModelForm; + } + + public String getPassedRowCount(Map context) { + return rowCountExdr.expandString(context); + } + + public List getRowActions() { + return rowActions; + } + + public String getRowCount() { + return rowCountExdr.getOriginal(); + } + + public boolean getSeparateColumns() { + return this.separateColumns; + } + + public boolean getSkipEnd() { + return this.skipEnd; + } + + public boolean getSkipStart() { + return this.skipStart; + } + + public String getSortField(Map context) { + String value = null; + try { + value = (String) context.get(this.sortFieldParameterName); + if (value == null) { + Map parameters = UtilGenerics.cast(context.get("parameters")); + if (parameters != null) { + value = parameters.get(this.sortFieldParameterName); + } + } + } catch (Exception e) { + Debug.logWarning(e, "Error getting sortField: " + e.toString(), module); + } + return value; + } + + public String getSortFieldParameterName() { + return this.sortFieldParameterName; + } + + public List getSortOrderFields() { + return sortOrderFields; + } + + /** + * iterate through alt-row-styles list to see if should be used, then add style + * @return The style for item row + */ + public String getStyleAltRowStyle(Map context) { + String styles = ""; + try { + // use the same Interpreter (ie with the same context setup) for all evals + Interpreter bsh = this.getBshInterpreter(context); + for (AltRowStyle altRowStyle : this.altRowStyles) { + Object retVal = bsh.eval(StringUtil.convertOperatorSubstitutions(altRowStyle.useWhen)); + // retVal should be a Boolean, if not something weird is up... + if (retVal instanceof Boolean) { + Boolean boolVal = (Boolean) retVal; + if (boolVal.booleanValue()) { + styles += altRowStyle.style; + } + } else { + throw new IllegalArgumentException("Return value from style condition eval was not a Boolean: " + + retVal.getClass().getName() + " [" + retVal + "] of form " + getName()); + } + } + } catch (EvalError e) { + String errmsg = "Error evaluating BeanShell style conditions on form " + getName(); + Debug.logError(e, errmsg, module); + throw new IllegalArgumentException(errmsg); + } + return styles; + } + + public String getTarget() { + return target.getOriginal(); + } + + /** iterate through altTargets list to see if any should be used, if not return original target + * @return The target for this Form + */ + public String getTarget(Map context, String targetType) { + Map expanderContext = context; + UtilCodec.SimpleEncoder simpleEncoder = (UtilCodec.SimpleEncoder) context.get("simpleEncoder"); + if (simpleEncoder != null) { + expanderContext = UtilCodec.HtmlEncodingMapWrapper.getHtmlEncodingMapWrapper(context, simpleEncoder); + } + try { + // use the same Interpreter (ie with the same context setup) for all evals + Interpreter bsh = this.getBshInterpreter(context); + for (AltTarget altTarget : this.altTargets) { + String useWhen = FlexibleStringExpander.expandString(altTarget.useWhen, context); + Object retVal = bsh.eval(StringUtil.convertOperatorSubstitutions(useWhen)); + boolean condTrue = false; + // retVal should be a Boolean, if not something weird is up... + if (retVal instanceof Boolean) { + Boolean boolVal = (Boolean) retVal; + condTrue = boolVal.booleanValue(); + } else { + throw new IllegalArgumentException("Return value from target condition eval was not a Boolean: " + + retVal.getClass().getName() + " [" + retVal + "] of form " + getName()); + } + + if (condTrue && !targetType.equals("inter-app")) { + return altTarget.targetExdr.expandString(expanderContext); + } + } + } catch (EvalError e) { + String errmsg = "Error evaluating BeanShell target conditions on form " + getName(); + Debug.logError(e, errmsg, module); + throw new IllegalArgumentException(errmsg); + } + return target.expandString(expanderContext); + } + + public String getTargetType() { + return this.targetType; + } + + public String getTargetWindow() { + return targetWindowExdr.getOriginal(); + } + + public String getTargetWindow(Map context) { + return this.targetWindowExdr.expandString(context); + } + + public String getTitle() { + return this.title; + } + + public String getTooltip() { + return this.tooltip; + } + + public String getType() { + return this.type; + } + + public boolean getUseRowSubmit() { + return this.useRowSubmit; + } + + public Set getUseWhenFields() { + return useWhenFields; + } + public boolean getGroupColumns() { + return groupColumns; + } + + public boolean isOverridenListSize() { + return !this.overrideListSize.isEmpty(); + } + + public void runFormActions(Map context) { + AbstractModelAction.runSubActions(this.actions, context); + } + + public static class AltRowStyle { + public final String useWhen; + public final String style; + + public AltRowStyle(Element altRowStyleElement) { + this.useWhen = altRowStyleElement.getAttribute("use-when"); + this.style = altRowStyleElement.getAttribute("style"); + } + } + + public static class AltTarget { + public final String useWhen; + public final FlexibleStringExpander targetExdr; + + public AltTarget(Element altTargetElement) { + this.useWhen = altTargetElement.getAttribute("use-when"); + this.targetExdr = FlexibleStringExpander.getInstance(altTargetElement.getAttribute("target")); + } + + @Override + public boolean equals(Object obj) { + return obj instanceof AltTarget && obj.hashCode() == this.hashCode(); + } + + @Override + public int hashCode() { + return useWhen.hashCode(); + } + } + + public static class AutoFieldsEntity { + public final String entityName; + public final String mapName; + public final String defaultFieldType; + public final int defaultPosition; + + public AutoFieldsEntity(Element element) { + this.entityName = element.getAttribute("entity-name"); + this.mapName = element.getAttribute("map-name"); + this.defaultFieldType = element.getAttribute("default-field-type"); + String positionStr = element.getAttribute("default-position"); + int position = 1; + try { + if (UtilValidate.isNotEmpty(positionStr)) { + position = Integer.valueOf(positionStr); + } + } catch (Exception e) { + Debug.logError(e, "Could not convert position attribute of the field element to an integer: [" + positionStr + + "], using the default of the form renderer", module); + } + this.defaultPosition = position; + } + } + + public static class AutoFieldsService { + public final String serviceName; + public final String mapName; + public final String defaultFieldType; + public final int defaultPosition; + + public AutoFieldsService(Element element) { + this.serviceName = element.getAttribute("service-name"); + this.mapName = element.getAttribute("map-name"); + this.defaultFieldType = element.getAttribute("default-field-type"); + String positionStr = element.getAttribute("default-position"); + int position = 1; + try { + if (UtilValidate.isNotEmpty(positionStr)) { + position = Integer.valueOf(positionStr); + } + } catch (Exception e) { + Debug.logError(e, "Could not convert position attribute of the field element to an integer: [" + positionStr + + "], using the default of the form renderer", module); + } + this.defaultPosition = position; + } + } + + public static class Banner implements FieldGroupBase { + public final FlexibleStringExpander style; + public final FlexibleStringExpander text; + public final FlexibleStringExpander textStyle; + public final FlexibleStringExpander leftText; + public final FlexibleStringExpander leftTextStyle; + public final FlexibleStringExpander rightText; + public final FlexibleStringExpander rightTextStyle; + + public Banner(Element sortOrderElement) { + this.style = FlexibleStringExpander.getInstance(sortOrderElement.getAttribute("style")); + this.text = FlexibleStringExpander.getInstance(sortOrderElement.getAttribute("text")); + this.textStyle = FlexibleStringExpander.getInstance(sortOrderElement.getAttribute("text-style")); + this.leftText = FlexibleStringExpander.getInstance(sortOrderElement.getAttribute("left-text")); + this.leftTextStyle = FlexibleStringExpander.getInstance(sortOrderElement.getAttribute("left-text-style")); + this.rightText = FlexibleStringExpander.getInstance(sortOrderElement.getAttribute("right-text")); + this.rightTextStyle = FlexibleStringExpander.getInstance(sortOrderElement.getAttribute("right-text-style")); + } + + public String getLeftText(Map context) { + return this.leftText.expandString(context); + } + + public String getLeftTextStyle(Map context) { + return this.leftTextStyle.expandString(context); + } + + public String getRightText(Map context) { + return this.rightText.expandString(context); + } + + public String getRightTextStyle(Map context) { + return this.rightTextStyle.expandString(context); + } + + public String getStyle(Map context) { + return this.style.expandString(context); + } + + public String getText(Map context) { + return this.text.expandString(context); + } + + public String getTextStyle(Map context) { + return this.textStyle.expandString(context); + } + + public void renderString(Appendable writer, Map context, FormStringRenderer formStringRenderer) + throws IOException { + formStringRenderer.renderBanner(writer, context, this); + } + } + + public static class FieldGroup implements FieldGroupBase { + private static AtomicInteger baseSeqNo = new AtomicInteger(0); + private static final String baseId = "_G"; + private final String id; + private final String style; + private final String title; + private final boolean collapsible; + private final boolean initiallyCollapsed; + private final ModelForm modelForm; + + public FieldGroup(Element sortOrderElement, ModelForm modelForm, List sortOrderFields, + Map fieldGroupMap) { + this.modelForm = modelForm; + String id; + String style = ""; + String title = ""; + boolean collapsible = false; + boolean initiallyCollapsed = false; + if (sortOrderElement != null) { + id = sortOrderElement.getAttribute("id"); + if (id.isEmpty()) { + String lastGroupId = baseId + baseSeqNo.getAndIncrement() + "_"; + id = lastGroupId; + } + style = sortOrderElement.getAttribute("style"); + title = sortOrderElement.getAttribute("title"); + collapsible = "true".equals(sortOrderElement.getAttribute("collapsible")); + initiallyCollapsed = "true".equals(sortOrderElement.getAttribute("initially-collapsed")); + if (initiallyCollapsed) { + collapsible = true; + } + for (Element sortFieldElement : UtilXml.childElementList(sortOrderElement, "sort-field")) { + sortOrderFields.add(new SortField(sortFieldElement.getAttribute("name"), sortFieldElement + .getAttribute("position"))); + fieldGroupMap.put(sortFieldElement.getAttribute("name"), this); + } + } else { + String lastGroupId = baseId + baseSeqNo.getAndIncrement() + "_"; + id = lastGroupId; + } + this.id = id; + this.style = style; + this.title = title; + this.collapsible = collapsible; + this.initiallyCollapsed = initiallyCollapsed; + } + + public Boolean collapsible() { + return this.collapsible; + } + + public String getId() { + return this.id; + } + + public String getStyle() { + return this.style; + } + + public String getTitle() { + return this.title; + } + + public Boolean initiallyCollapsed() { + return this.initiallyCollapsed; + } + + public void renderEndString(Appendable writer, Map context, FormStringRenderer formStringRenderer) + throws IOException { + formStringRenderer.renderFormatSingleWrapperClose(writer, context, modelForm); + if (!modelForm.fieldGroupList.isEmpty()) { + if (shouldUse(context)) { + formStringRenderer.renderFieldGroupClose(writer, context, this); + } + } + } + + public void renderStartString(Appendable writer, Map context, FormStringRenderer formStringRenderer) + throws IOException { + if (!modelForm.fieldGroupList.isEmpty()) { + if (shouldUse(context)) { + formStringRenderer.renderFieldGroupOpen(writer, context, this); + } + } + formStringRenderer.renderFormatSingleWrapperOpen(writer, context, modelForm); + } + + public boolean shouldUse(Map context) { + for (String fieldName : modelForm.fieldGroupMap.keySet()) { + FieldGroupBase group = modelForm.fieldGroupMap.get(fieldName); + if (group instanceof FieldGroup) { + FieldGroup fieldgroup = (FieldGroup) group; + if (this.id.equals(fieldgroup.getId())) { + for (ModelFormField modelField : modelForm.fieldList) { + if (fieldName.equals(modelField.getName()) && modelField.shouldUse(context)) { + return true; + } + } + } + } + } + return false; + } + } + + public static interface FieldGroupBase { + } + + public static class SortField { + private final String fieldName; + private final Integer position; + + public SortField(String name) { + this(name, null); + } + + public SortField(String name, String position) { + this.fieldName = name; + if (UtilValidate.isNotEmpty(position)) { + Integer posParam = null; + try { + posParam = Integer.valueOf(position); + } catch (Exception e) {/* just ignore the exception*/ + } + this.position = posParam; + } else { + this.position = null; + } + } + + public String getFieldName() { + return this.fieldName; + } + + public Integer getPosition() { + return this.position; + } + } + + /** The UpdateArea class implements the <on-event-update-area> + * elements used in form widgets. + */ + public static class UpdateArea { + private final String eventType; + private final String areaId; + private final String areaTarget; + private final String defaultServiceName; + private final String defaultEntityName; + private final CommonWidgetModels.AutoEntityParameters autoEntityParameters; + private final CommonWidgetModels.AutoServiceParameters autoServiceParameters; + private final List parameterList; + + public UpdateArea(Element updateAreaElement) { + this(updateAreaElement, null, null); + } + + /** XML constructor. + * @param updateAreaElement The <on-xxx-update-area> + * XML element. + */ + public UpdateArea(Element updateAreaElement, String defaultServiceName, String defaultEntityName) { + this.eventType = updateAreaElement.getAttribute("event-type"); + this.areaId = updateAreaElement.getAttribute("area-id"); + this.areaTarget = updateAreaElement.getAttribute("area-target"); + this.defaultServiceName = defaultServiceName; + this.defaultEntityName = defaultEntityName; + List parameterElementList = UtilXml.childElementList(updateAreaElement, "parameter"); + if (parameterElementList.isEmpty()) { + this.parameterList = Collections.emptyList(); + } else { + List parameterList = new ArrayList(parameterElementList.size()); + for (Element parameterElement : parameterElementList) { + parameterList.add(new CommonWidgetModels.Parameter(parameterElement)); + } + this.parameterList = Collections.unmodifiableList(parameterList); + } + Element autoServiceParamsElement = UtilXml.firstChildElement(updateAreaElement, "auto-parameters-service"); + if (autoServiceParamsElement != null) { + this.autoServiceParameters = new CommonWidgetModels.AutoServiceParameters(autoServiceParamsElement); + } else { + this.autoServiceParameters = null; + } + Element autoEntityParamsElement = UtilXml.firstChildElement(updateAreaElement, "auto-parameters-entity"); + if (autoEntityParamsElement != null) { + this.autoEntityParameters = new CommonWidgetModels.AutoEntityParameters(autoEntityParamsElement); + } else { + this.autoEntityParameters = null; + } + } + + /** String constructor. + * @param areaId The id of the widget element to be updated + * @param areaTarget The target URL called to update the area + */ + public UpdateArea(String eventType, String areaId, String areaTarget) { + this.eventType = eventType; + this.areaId = areaId; + this.areaTarget = areaTarget; + this.defaultServiceName = null; + this.defaultEntityName = null; + this.parameterList = Collections.emptyList(); + this.autoServiceParameters = null; + this.autoEntityParameters = null; + } + + @Override + public boolean equals(Object obj) { + return obj instanceof UpdateArea && obj.hashCode() == this.hashCode(); + } + + public String getAreaId() { + return areaId; + } + + public String getAreaTarget(Map context) { + return FlexibleStringExpander.expandString(areaTarget, context); + } + + public String getEventType() { + return eventType; + } + + public Map getParameterMap(Map context) { + Map fullParameterMap = new HashMap(); + if (autoServiceParameters != null) { + fullParameterMap.putAll(autoServiceParameters.getParametersMap(context, defaultServiceName)); + } + if (autoEntityParameters != null) { + fullParameterMap.putAll(autoEntityParameters.getParametersMap(context, defaultEntityName)); + } + for (CommonWidgetModels.Parameter parameter : this.parameterList) { + fullParameterMap.put(parameter.getName(), parameter.getValue(context)); + } + + return fullParameterMap; + } + + @Override + public int hashCode() { + return areaId.hashCode(); + } + + public String getAreaTarget() { + return areaTarget; + } + + public String getDefaultServiceName() { + return defaultServiceName; + } + + public String getDefaultEntityName() { + return defaultEntityName; + } + + public CommonWidgetModels.AutoEntityParameters getAutoEntityParameters() { + return autoEntityParameters; + } + + public CommonWidgetModels.AutoServiceParameters getAutoServiceParameters() { + return autoServiceParameters; + } + + public List getParameterList() { + return parameterList; + } + } +} diff --git a/framework/widget/src/org/ofbiz/widget/form/ModelFormAction.java b/framework/widget/src/org/ofbiz/widget/model/ModelFormAction.java similarity index 97% rename from framework/widget/src/org/ofbiz/widget/form/ModelFormAction.java rename to framework/widget/src/org/ofbiz/widget/model/ModelFormAction.java index 29a0879441..46c60c539b 100644 --- a/framework/widget/src/org/ofbiz/widget/form/ModelFormAction.java +++ b/framework/widget/src/org/ofbiz/widget/model/ModelFormAction.java @@ -1,275 +1,272 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget.form; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.ListIterator; -import java.util.Map; -import java.util.regex.PatternSyntaxException; - -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.UtilGenerics; -import org.ofbiz.base.util.UtilValidate; -import org.ofbiz.base.util.UtilXml; -import org.ofbiz.base.util.collections.FlexibleMapAccessor; -import org.ofbiz.base.util.string.FlexibleStringExpander; -import org.ofbiz.entity.finder.EntityFinderUtil; -import org.ofbiz.service.GenericServiceException; -import org.ofbiz.service.ModelService; -import org.ofbiz.widget.AbstractModelAction; -import org.ofbiz.widget.ModelAction; -import org.ofbiz.widget.ModelActionVisitor; -import org.ofbiz.widget.WidgetWorker; -import org.w3c.dom.Element; - -/** - * Abstract form action. - */ -public abstract class ModelFormAction { - - public static final String module = ModelFormAction.class.getName(); - - public static List readSubActions(ModelForm modelForm, Element parentElement) { - List actionElementList = UtilXml.childElementList(parentElement); - List actions = new ArrayList(actionElementList.size()); - for (Element actionElement : UtilXml.childElementList(parentElement)) { - if ("service".equals(actionElement.getNodeName())) { - actions.add(new Service(modelForm, actionElement)); - } else if ("entity-and".equals(actionElement.getNodeName()) || "entity-condition".equals(actionElement.getNodeName()) - || "get-related".equals(actionElement.getNodeName())) { - if (!actionElement.hasAttribute("list")) { - String listName = modelForm.getListName(); - if (UtilValidate.isEmpty(listName)) { - listName = ModelForm.DEFAULT_FORM_RESULT_LIST_NAME; - } - actionElement.setAttribute("list", listName); - } - actions.add(AbstractModelAction.newInstance(modelForm, actionElement)); - } else if ("call-parent-actions".equals(actionElement.getNodeName())) { - actions.add(new CallParentActions(modelForm, actionElement)); - } else { - actions.add(AbstractModelAction.newInstance(modelForm, actionElement)); - } - } - return Collections.unmodifiableList(actions); - } - - /** - * Models the <call-parent-actions> element. - * - * @see widget-form.xsd - */ - @SuppressWarnings("serial") - public static class CallParentActions extends AbstractModelAction { - private final ActionsKind kind;; - private final ModelForm modelForm; - - public CallParentActions(ModelForm modelForm, Element callParentActionsElement) { - super(modelForm, callParentActionsElement); - String parentName = callParentActionsElement.getParentNode().getNodeName(); - if ("actions".equals(parentName)) { - kind = ActionsKind.ACTIONS; - } else if ("row-actions".equals(parentName)) { - kind = ActionsKind.ROW_ACTIONS; - } else { - throw new IllegalArgumentException("Action element not supported for call-parent-actions : " + parentName); - } - ModelForm parentModel = modelForm.getParentModelForm(); - if (parentModel == null) { - throw new IllegalArgumentException("call-parent-actions can only be used with form extending another form"); - } - this.modelForm = modelForm; - } - - @Override - public void accept(ModelActionVisitor visitor) throws Exception { - visitor.visit(this); - } - - @Override - public void runAction(Map context) { - ModelForm parentModel = modelForm.getParentModelForm(); - switch (kind) { - case ACTIONS: - parentModel.runFormActions(context); - break; - case ROW_ACTIONS: - AbstractModelAction.runSubActions(parentModel.getRowActions(), context); - break; - } - } - - protected static enum ActionsKind { - ACTIONS, ROW_ACTIONS - } - } - - /** - * Models the <service> element. - * - * @see widget-form.xsd - */ - @SuppressWarnings("serial") - public static class Service extends AbstractModelAction { - private final FlexibleStringExpander autoFieldMapExdr; - private final Map, Object> fieldMap; - private final boolean ignoreError; - private final FlexibleStringExpander resultMapListNameExdr; - private final FlexibleMapAccessor> resultMapNameAcsr; - private final FlexibleStringExpander serviceNameExdr; - - public Service(ModelForm modelForm, Element serviceElement) { - super(modelForm, serviceElement); - this.serviceNameExdr = FlexibleStringExpander.getInstance(serviceElement.getAttribute("service-name")); - this.resultMapNameAcsr = FlexibleMapAccessor.getInstance(serviceElement.getAttribute("result-map")); - this.autoFieldMapExdr = FlexibleStringExpander.getInstance(serviceElement.getAttribute("auto-field-map")); - FlexibleStringExpander resultMapListNameExdr = FlexibleStringExpander.getInstance(""); - if (UtilValidate.isEmpty(serviceElement.getAttribute("result-map-list")) - && UtilValidate.isEmpty(serviceElement.getAttribute("result-map-list-name"))) { - if (UtilValidate.isEmpty(serviceElement.getAttribute("result-map-list-iterator")) - && UtilValidate.isEmpty(serviceElement.getAttribute("result-map-list-iterator-name"))) { - String lstNm = modelForm.getListName(); - if (UtilValidate.isEmpty(lstNm)) { - lstNm = ModelForm.DEFAULT_FORM_RESULT_LIST_NAME; - } - resultMapListNameExdr = FlexibleStringExpander.getInstance(lstNm); - } else { - // this is deprecated, but support it for now anyway - resultMapListNameExdr = FlexibleStringExpander.getInstance(serviceElement - .getAttribute("result-map-list-iterator")); - if (resultMapListNameExdr.isEmpty()) - resultMapListNameExdr = FlexibleStringExpander.getInstance(serviceElement - .getAttribute("result-map-list-iterator-name")); - } - } else { - resultMapListNameExdr = FlexibleStringExpander.getInstance(serviceElement.getAttribute("result-map-list")); - if (resultMapListNameExdr.isEmpty()) - resultMapListNameExdr = FlexibleStringExpander.getInstance(serviceElement - .getAttribute("result-map-list-name")); - } - this.resultMapListNameExdr = resultMapListNameExdr; - this.fieldMap = EntityFinderUtil.makeFieldMap(serviceElement); - this.ignoreError = "true".equals(serviceElement.getAttribute("ignore-error")); - } - - @Override - public void accept(ModelActionVisitor visitor) throws Exception { - visitor.visit(this); - } - - public String getServiceName() { - return serviceNameExdr.getOriginal(); - } - - @Override - public void runAction(Map context) { - String serviceNameExpanded = this.serviceNameExdr.expandString(context); - if (UtilValidate.isEmpty(serviceNameExpanded)) { - throw new IllegalArgumentException("Service name was empty, expanded from: " + this.serviceNameExdr.getOriginal()); - } - String autoFieldMapString = this.autoFieldMapExdr.expandString(context); - boolean autoFieldMapBool = !"false".equals(autoFieldMapString); - try { - Map serviceContext = null; - if (autoFieldMapBool) { - if (!"true".equals(autoFieldMapString)) { - Map autoFieldMap = UtilGenerics.checkMap(context.get(autoFieldMapString)); - serviceContext = WidgetWorker.getDispatcher(context).getDispatchContext() - .makeValidContext(serviceNameExpanded, ModelService.IN_PARAM, autoFieldMap); - } else { - serviceContext = WidgetWorker.getDispatcher(context).getDispatchContext() - .makeValidContext(serviceNameExpanded, ModelService.IN_PARAM, context); - } - } else { - serviceContext = new HashMap(); - } - if (this.fieldMap != null) { - EntityFinderUtil.expandFieldMapToContext(this.fieldMap, context, serviceContext); - } - Map result = null; - if (this.ignoreError) { - result = WidgetWorker.getDispatcher(context).runSync(serviceNameExpanded, serviceContext, -1, true); - } else { - result = WidgetWorker.getDispatcher(context).runSync(serviceNameExpanded, serviceContext); - } - if (!this.resultMapNameAcsr.isEmpty()) { - this.resultMapNameAcsr.put(context, result); - String queryString = (String) result.get("queryString"); - context.put("queryString", queryString); - context.put("queryStringMap", result.get("queryStringMap")); - if (UtilValidate.isNotEmpty(queryString)) { - try { - String queryStringEncoded = queryString.replaceAll("&", "%26"); - context.put("queryStringEncoded", queryStringEncoded); - } catch (PatternSyntaxException e) { - - } - } - } else { - context.putAll(result); - } - String listName = resultMapListNameExdr.expandString(context); - Object listObj = result.get(listName); - if (listObj != null) { - if (!(listObj instanceof List) && !(listObj instanceof ListIterator)) { - throw new IllegalArgumentException("Error in form [" + this.getModelWidget().getName() - + "] calling service with name [" + serviceNameExpanded - + "]: the result that is supposed to be a List or ListIterator and is not."); - } - context.put("listName", listName); - context.put(listName, listObj); - } - } catch (GenericServiceException e) { - String errMsg = "Error in form [" + this.getModelWidget().getName() + "] calling service with name [" - + serviceNameExpanded + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - if (!this.ignoreError) { - throw new IllegalArgumentException(errMsg); - } - } - } - - public FlexibleStringExpander getAutoFieldMapExdr() { - return autoFieldMapExdr; - } - - public Map, Object> getFieldMap() { - return fieldMap; - } - - public boolean getIgnoreError() { - return ignoreError; - } - - public FlexibleStringExpander getResultMapListNameExdr() { - return resultMapListNameExdr; - } - - public FlexibleMapAccessor> getResultMapNameAcsr() { - return resultMapNameAcsr; - } - - public FlexibleStringExpander getServiceNameExdr() { - return serviceNameExdr; - } - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.model; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.ListIterator; +import java.util.Map; +import java.util.regex.PatternSyntaxException; + +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilGenerics; +import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.base.util.UtilXml; +import org.ofbiz.base.util.collections.FlexibleMapAccessor; +import org.ofbiz.base.util.string.FlexibleStringExpander; +import org.ofbiz.entity.finder.EntityFinderUtil; +import org.ofbiz.service.GenericServiceException; +import org.ofbiz.service.ModelService; +import org.ofbiz.widget.WidgetWorker; +import org.w3c.dom.Element; + +/** + * Abstract form action. + */ +public abstract class ModelFormAction { + + public static final String module = ModelFormAction.class.getName(); + + public static List readSubActions(ModelForm modelForm, Element parentElement) { + List actionElementList = UtilXml.childElementList(parentElement); + List actions = new ArrayList(actionElementList.size()); + for (Element actionElement : UtilXml.childElementList(parentElement)) { + if ("service".equals(actionElement.getNodeName())) { + actions.add(new Service(modelForm, actionElement)); + } else if ("entity-and".equals(actionElement.getNodeName()) || "entity-condition".equals(actionElement.getNodeName()) + || "get-related".equals(actionElement.getNodeName())) { + if (!actionElement.hasAttribute("list")) { + String listName = modelForm.getListName(); + if (UtilValidate.isEmpty(listName)) { + listName = ModelForm.DEFAULT_FORM_RESULT_LIST_NAME; + } + actionElement.setAttribute("list", listName); + } + actions.add(AbstractModelAction.newInstance(modelForm, actionElement)); + } else if ("call-parent-actions".equals(actionElement.getNodeName())) { + actions.add(new CallParentActions(modelForm, actionElement)); + } else { + actions.add(AbstractModelAction.newInstance(modelForm, actionElement)); + } + } + return Collections.unmodifiableList(actions); + } + + /** + * Models the <call-parent-actions> element. + * + * @see widget-form.xsd + */ + @SuppressWarnings("serial") + public static class CallParentActions extends AbstractModelAction { + private final ActionsKind kind;; + private final ModelForm modelForm; + + public CallParentActions(ModelForm modelForm, Element callParentActionsElement) { + super(modelForm, callParentActionsElement); + String parentName = callParentActionsElement.getParentNode().getNodeName(); + if ("actions".equals(parentName)) { + kind = ActionsKind.ACTIONS; + } else if ("row-actions".equals(parentName)) { + kind = ActionsKind.ROW_ACTIONS; + } else { + throw new IllegalArgumentException("Action element not supported for call-parent-actions : " + parentName); + } + ModelForm parentModel = modelForm.getParentModelForm(); + if (parentModel == null) { + throw new IllegalArgumentException("call-parent-actions can only be used with form extending another form"); + } + this.modelForm = modelForm; + } + + @Override + public void accept(ModelActionVisitor visitor) throws Exception { + visitor.visit(this); + } + + @Override + public void runAction(Map context) { + ModelForm parentModel = modelForm.getParentModelForm(); + switch (kind) { + case ACTIONS: + parentModel.runFormActions(context); + break; + case ROW_ACTIONS: + AbstractModelAction.runSubActions(parentModel.getRowActions(), context); + break; + } + } + + protected static enum ActionsKind { + ACTIONS, ROW_ACTIONS + } + } + + /** + * Models the <service> element. + * + * @see widget-form.xsd + */ + @SuppressWarnings("serial") + public static class Service extends AbstractModelAction { + private final FlexibleStringExpander autoFieldMapExdr; + private final Map, Object> fieldMap; + private final boolean ignoreError; + private final FlexibleStringExpander resultMapListNameExdr; + private final FlexibleMapAccessor> resultMapNameAcsr; + private final FlexibleStringExpander serviceNameExdr; + + public Service(ModelForm modelForm, Element serviceElement) { + super(modelForm, serviceElement); + this.serviceNameExdr = FlexibleStringExpander.getInstance(serviceElement.getAttribute("service-name")); + this.resultMapNameAcsr = FlexibleMapAccessor.getInstance(serviceElement.getAttribute("result-map")); + this.autoFieldMapExdr = FlexibleStringExpander.getInstance(serviceElement.getAttribute("auto-field-map")); + FlexibleStringExpander resultMapListNameExdr = FlexibleStringExpander.getInstance(""); + if (UtilValidate.isEmpty(serviceElement.getAttribute("result-map-list")) + && UtilValidate.isEmpty(serviceElement.getAttribute("result-map-list-name"))) { + if (UtilValidate.isEmpty(serviceElement.getAttribute("result-map-list-iterator")) + && UtilValidate.isEmpty(serviceElement.getAttribute("result-map-list-iterator-name"))) { + String lstNm = modelForm.getListName(); + if (UtilValidate.isEmpty(lstNm)) { + lstNm = ModelForm.DEFAULT_FORM_RESULT_LIST_NAME; + } + resultMapListNameExdr = FlexibleStringExpander.getInstance(lstNm); + } else { + // this is deprecated, but support it for now anyway + resultMapListNameExdr = FlexibleStringExpander.getInstance(serviceElement + .getAttribute("result-map-list-iterator")); + if (resultMapListNameExdr.isEmpty()) + resultMapListNameExdr = FlexibleStringExpander.getInstance(serviceElement + .getAttribute("result-map-list-iterator-name")); + } + } else { + resultMapListNameExdr = FlexibleStringExpander.getInstance(serviceElement.getAttribute("result-map-list")); + if (resultMapListNameExdr.isEmpty()) + resultMapListNameExdr = FlexibleStringExpander.getInstance(serviceElement + .getAttribute("result-map-list-name")); + } + this.resultMapListNameExdr = resultMapListNameExdr; + this.fieldMap = EntityFinderUtil.makeFieldMap(serviceElement); + this.ignoreError = "true".equals(serviceElement.getAttribute("ignore-error")); + } + + @Override + public void accept(ModelActionVisitor visitor) throws Exception { + visitor.visit(this); + } + + public String getServiceName() { + return serviceNameExdr.getOriginal(); + } + + @Override + public void runAction(Map context) { + String serviceNameExpanded = this.serviceNameExdr.expandString(context); + if (UtilValidate.isEmpty(serviceNameExpanded)) { + throw new IllegalArgumentException("Service name was empty, expanded from: " + this.serviceNameExdr.getOriginal()); + } + String autoFieldMapString = this.autoFieldMapExdr.expandString(context); + boolean autoFieldMapBool = !"false".equals(autoFieldMapString); + try { + Map serviceContext = null; + if (autoFieldMapBool) { + if (!"true".equals(autoFieldMapString)) { + Map autoFieldMap = UtilGenerics.checkMap(context.get(autoFieldMapString)); + serviceContext = WidgetWorker.getDispatcher(context).getDispatchContext() + .makeValidContext(serviceNameExpanded, ModelService.IN_PARAM, autoFieldMap); + } else { + serviceContext = WidgetWorker.getDispatcher(context).getDispatchContext() + .makeValidContext(serviceNameExpanded, ModelService.IN_PARAM, context); + } + } else { + serviceContext = new HashMap(); + } + if (this.fieldMap != null) { + EntityFinderUtil.expandFieldMapToContext(this.fieldMap, context, serviceContext); + } + Map result = null; + if (this.ignoreError) { + result = WidgetWorker.getDispatcher(context).runSync(serviceNameExpanded, serviceContext, -1, true); + } else { + result = WidgetWorker.getDispatcher(context).runSync(serviceNameExpanded, serviceContext); + } + if (!this.resultMapNameAcsr.isEmpty()) { + this.resultMapNameAcsr.put(context, result); + String queryString = (String) result.get("queryString"); + context.put("queryString", queryString); + context.put("queryStringMap", result.get("queryStringMap")); + if (UtilValidate.isNotEmpty(queryString)) { + try { + String queryStringEncoded = queryString.replaceAll("&", "%26"); + context.put("queryStringEncoded", queryStringEncoded); + } catch (PatternSyntaxException e) { + + } + } + } else { + context.putAll(result); + } + String listName = resultMapListNameExdr.expandString(context); + Object listObj = result.get(listName); + if (listObj != null) { + if (!(listObj instanceof List) && !(listObj instanceof ListIterator)) { + throw new IllegalArgumentException("Error in form [" + this.getModelWidget().getName() + + "] calling service with name [" + serviceNameExpanded + + "]: the result that is supposed to be a List or ListIterator and is not."); + } + context.put("listName", listName); + context.put(listName, listObj); + } + } catch (GenericServiceException e) { + String errMsg = "Error in form [" + this.getModelWidget().getName() + "] calling service with name [" + + serviceNameExpanded + "]: " + e.toString(); + Debug.logError(e, errMsg, module); + if (!this.ignoreError) { + throw new IllegalArgumentException(errMsg); + } + } + } + + public FlexibleStringExpander getAutoFieldMapExdr() { + return autoFieldMapExdr; + } + + public Map, Object> getFieldMap() { + return fieldMap; + } + + public boolean getIgnoreError() { + return ignoreError; + } + + public FlexibleStringExpander getResultMapListNameExdr() { + return resultMapListNameExdr; + } + + public FlexibleMapAccessor> getResultMapNameAcsr() { + return resultMapNameAcsr; + } + + public FlexibleStringExpander getServiceNameExdr() { + return serviceNameExdr; + } + } +} diff --git a/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java b/framework/widget/src/org/ofbiz/widget/model/ModelFormField.java similarity index 97% rename from framework/widget/src/org/ofbiz/widget/form/ModelFormField.java rename to framework/widget/src/org/ofbiz/widget/model/ModelFormField.java index f9d3ddd15c..4e6f3c67cb 100644 --- a/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java +++ b/framework/widget/src/org/ofbiz/widget/model/ModelFormField.java @@ -1,3802 +1,3806 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget.form; - -import java.io.IOException; -import java.math.BigDecimal; -import java.sql.Timestamp; -import java.text.DateFormat; -import java.text.NumberFormat; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.StringTokenizer; -import java.util.TimeZone; - -import org.ofbiz.base.conversion.ConversionException; -import org.ofbiz.base.conversion.DateTimeConverters; -import org.ofbiz.base.conversion.DateTimeConverters.StringToTimestamp; -import org.ofbiz.base.util.BshUtil; -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.GeneralException; -import org.ofbiz.base.util.ObjectType; -import org.ofbiz.base.util.StringUtil; -import org.ofbiz.base.util.UtilCodec; -import org.ofbiz.base.util.UtilDateTime; -import org.ofbiz.base.util.UtilFormatOut; -import org.ofbiz.base.util.UtilGenerics; -import org.ofbiz.base.util.UtilMisc; -import org.ofbiz.base.util.UtilProperties; -import org.ofbiz.base.util.UtilValidate; -import org.ofbiz.base.util.UtilXml; -import org.ofbiz.base.util.collections.FlexibleMapAccessor; -import org.ofbiz.base.util.collections.MapStack; -import org.ofbiz.base.util.string.FlexibleStringExpander; -import org.ofbiz.entity.Delegator; -import org.ofbiz.entity.GenericEntity; -import org.ofbiz.entity.GenericEntityException; -import org.ofbiz.entity.GenericValue; -import org.ofbiz.entity.condition.EntityCondition; -import org.ofbiz.entity.finder.EntityFinderUtil; -import org.ofbiz.entity.model.ModelEntity; -import org.ofbiz.entity.util.EntityUtil; -import org.ofbiz.widget.CommonWidgetModels.*; -import org.ofbiz.widget.ModelFieldVisitor; -import org.ofbiz.widget.WidgetWorker; -import org.ofbiz.widget.form.ModelForm.UpdateArea; -import org.w3c.dom.Element; - -import bsh.EvalError; -import bsh.Interpreter; - -/** - * Models the <field> element. - * - * @see widget-form.xsd - */ -public class ModelFormField { - - /* - * ----------------------------------------------------------------------- * - * DEVELOPERS PLEASE READ - * ----------------------------------------------------------------------- * - * - * This model is intended to be a read-only data structure that represents - * an XML element. Outside of object construction, the class should not - * have any behaviors. All behavior should be contained in model visitors. - * - * Instances of this class will be shared by multiple threads - therefore - * it is immutable. DO NOT CHANGE THE OBJECT'S STATE AT RUN TIME! - * - */ - - public static final String module = ModelFormField.class.getName(); - - public static ModelFormField from(ModelFormFieldBuilder builder) { - return new ModelFormField(builder); - } - - private final FlexibleStringExpander action; - private final String attributeName; - private final boolean encodeOutput; - private final String entityName; - private final FlexibleMapAccessor entryAcsr; - private final String event; - private final FieldInfo fieldInfo; - private final String fieldName; - private final String headerLink; - private final String headerLinkStyle; - private final String idName; - private final FlexibleMapAccessor> mapAcsr; - private final ModelForm modelForm; - private final String name; - private final List onChangeUpdateAreas; - private final List onClickUpdateAreas; - private final String parameterName; - private final Integer position; - private final String redWhen; - private final Boolean requiredField; - private final String requiredFieldStyle; - private final boolean separateColumn; - private final String serviceName; - private final Boolean sortField; - private final String sortFieldAscStyle; - private final String sortFieldDescStyle; - private final String sortFieldHelpText; - private final String sortFieldStyle; - private final FlexibleStringExpander title; - private final String titleAreaStyle; - private final String titleStyle; - private final FlexibleStringExpander tooltip; - private final String tooltipStyle; - private final FlexibleStringExpander useWhen; - private final String widgetAreaStyle; - private final String widgetStyle; - - private ModelFormField(ModelFormFieldBuilder builder) { - this.action = builder.getAction(); - this.attributeName = builder.getAttributeName(); - this.encodeOutput = builder.getEncodeOutput(); - this.entityName = builder.getEntityName(); - this.entryAcsr = builder.getEntryAcsr(); - this.event = builder.getEvent(); - if (builder.getFieldInfo() != null) { - this.fieldInfo = builder.getFieldInfo().copy(this); - } else { - this.fieldInfo = null; - } - this.fieldName = builder.getFieldName(); - this.headerLink = builder.getHeaderLink(); - this.headerLinkStyle = builder.getHeaderLinkStyle(); - this.idName = builder.getIdName(); - this.mapAcsr = builder.getMapAcsr(); - this.modelForm = builder.getModelForm(); - this.name = builder.getName(); - if (builder.getOnChangeUpdateAreas().isEmpty()) { - this.onChangeUpdateAreas = Collections.emptyList(); - } else { - this.onChangeUpdateAreas = Collections.unmodifiableList(new ArrayList(builder.getOnChangeUpdateAreas())); - } - if (builder.getOnClickUpdateAreas().isEmpty()) { - this.onClickUpdateAreas = Collections.emptyList(); - } else { - this.onClickUpdateAreas = Collections.unmodifiableList(new ArrayList(builder.getOnClickUpdateAreas())); - } - this.parameterName = builder.getParameterName(); - this.position = builder.getPosition(); - this.redWhen = builder.getRedWhen(); - this.requiredField = builder.getRequiredField(); - this.requiredFieldStyle = builder.getRequiredFieldStyle(); - this.separateColumn = builder.getSeparateColumn(); - this.serviceName = builder.getServiceName(); - this.sortField = builder.getSortField(); - this.sortFieldAscStyle = builder.getSortFieldAscStyle(); - this.sortFieldDescStyle = builder.getSortFieldDescStyle(); - this.sortFieldHelpText = builder.getSortFieldHelpText(); - this.sortFieldStyle = builder.getSortFieldStyle(); - this.title = builder.getTitle(); - this.titleAreaStyle = builder.getTitleAreaStyle(); - this.titleStyle = builder.getTitleStyle(); - this.tooltip = builder.getTooltip(); - this.tooltipStyle = builder.getTooltipStyle(); - this.useWhen = builder.getUseWhen(); - this.widgetAreaStyle = builder.getWidgetAreaStyle(); - this.widgetStyle = builder.getWidgetStyle(); - } - - public FlexibleStringExpander getAction() { - return action; - } - - public String getAction(Map context) { - if (UtilValidate.isNotEmpty(this.action)) - return action.expandString(context); - return null; - } - - /** - * Gets the name of the Service Attribute (aka Parameter) that corresponds - * with this field. This can be used to get additional information about the field. - * Use the getServiceName() method to get the Entity name that the field is in. - * - * @return returns the name of the Service Attribute - */ - public String getAttributeName() { - if (UtilValidate.isNotEmpty(this.attributeName)) - return this.attributeName; - return this.name; - } - - public String getCurrentContainerId(Map context) { - ModelForm modelForm = this.getModelForm(); - String idName = FlexibleStringExpander.expandString(this.getIdName(), context); - - if (modelForm != null) { - Integer itemIndex = (Integer) context.get("itemIndex"); - if ("list".equals(modelForm.getType()) || "multi".equals(modelForm.getType())) { - if (itemIndex != null) { - return idName + modelForm.getItemIndexSeparator() + itemIndex.intValue(); - } - } - } - return idName; - } - - public boolean getEncodeOutput() { - return this.encodeOutput; - } - - public String getEntityName() { - if (UtilValidate.isNotEmpty(this.entityName)) - return this.entityName; - return this.modelForm.getDefaultEntityName(); - } - - /** - * Gets the entry from the context that corresponds to this field; if this - * form is being rendered in an error condition (ie isError in the context - * is true) then the value will be retrieved from the parameters Map in - * the context. - * - * @param context the context - * @return returns the entry from the context that corresponds to this field - */ - public String getEntry(Map context) { - return this.getEntry(context, ""); - } - - public String getEntry(Map context, String defaultValue) { - Boolean isError = (Boolean) context.get("isError"); - Boolean useRequestParameters = (Boolean) context.get("useRequestParameters"); - - Locale locale = (Locale) context.get("locale"); - if (locale == null) - locale = Locale.getDefault(); - TimeZone timeZone = (TimeZone) context.get("timeZone"); - if (timeZone == null) - timeZone = TimeZone.getDefault(); - - String returnValue; - - // if useRequestParameters is TRUE then parameters will always be used, if FALSE then parameters will never be used - // if isError is TRUE and useRequestParameters is not FALSE (ie is null or TRUE) then parameters will be used - if ((Boolean.TRUE.equals(isError) && !Boolean.FALSE.equals(useRequestParameters)) - || (Boolean.TRUE.equals(useRequestParameters))) { - //Debug.logInfo("Getting entry, isError true so getting from parameters for field " + this.getName() + " of form " + this.modelForm.getName(), module); - Map parameters = UtilGenerics.checkMap(context.get("parameters"), String.class, Object.class); - String parameterName = this.getParameterName(context); - if (parameters != null && parameters.get(parameterName) != null) { - Object parameterValue = parameters.get(parameterName); - if (parameterValue instanceof String) { - returnValue = (String) parameterValue; - } else { - // we might want to do something else here in the future, but for now this is probably best - Debug.logWarning("Found a non-String parameter value for field [" + this.getModelForm().getName() + "." - + this.getFieldName() + "]", module); - returnValue = defaultValue; - } - } else { - returnValue = defaultValue; - } - } else { - //Debug.logInfo("Getting entry, isError false so getting from Map in context for field " + this.getName() + " of form " + this.modelForm.getName(), module); - Map dataMap = this.getMap(context); - boolean dataMapIsContext = false; - if (dataMap == null) { - //Debug.logInfo("Getting entry, no Map found with name " + this.getMapName() + ", using context for field " + this.getName() + " of form " + this.modelForm.getName(), module); - dataMap = context; - dataMapIsContext = true; - } - Object retVal = null; - if (UtilValidate.isNotEmpty(this.entryAcsr)) { - if (dataMap instanceof GenericEntity) { - GenericEntity genEnt = (GenericEntity) dataMap; - if (genEnt.getModelEntity().isField(this.entryAcsr.getOriginalName())) { - retVal = genEnt.get(this.entryAcsr.getOriginalName(), locale); - } else { - //TODO: this may never come up, but if necessary use the FlexibleStringExander to eval the name first: String evaled = this.entryAcsr - } - } else { - retVal = this.entryAcsr.get(dataMap, locale); - } - } else { - // if no entry name was specified, use the field's name - if (dataMap.containsKey(this.name)) { - retVal = dataMap.get(this.name); - } - } - - // this is a special case to fill in fields during a create by default from parameters passed in - if (dataMapIsContext && retVal == null && !Boolean.FALSE.equals(useRequestParameters)) { - Map parameters = UtilGenerics.checkMap(context.get("parameters")); - if (parameters != null) { - if (UtilValidate.isNotEmpty(this.entryAcsr)) - retVal = this.entryAcsr.get(parameters); - else - retVal = parameters.get(this.name); - } - } - - if (retVal != null) { - // format string based on the user's locale and time zone - if (retVal instanceof Double || retVal instanceof Float || retVal instanceof BigDecimal) { - NumberFormat nf = NumberFormat.getInstance(locale); - nf.setMaximumFractionDigits(10); - return nf.format(retVal); - } else if (retVal instanceof java.sql.Date) { - DateFormat df = UtilDateTime.toDateFormat(UtilDateTime.DATE_FORMAT, timeZone, null); - return df.format((java.util.Date) retVal); - } else if (retVal instanceof java.sql.Time) { - DateFormat df = UtilDateTime.toTimeFormat(UtilDateTime.TIME_FORMAT, timeZone, null); - return df.format((java.util.Date) retVal); - } else if (retVal instanceof java.sql.Timestamp) { - DateFormat df = UtilDateTime.toDateTimeFormat(UtilDateTime.DATE_TIME_FORMAT, timeZone, null); - return df.format((java.util.Date) retVal); - } else if (retVal instanceof java.util.Date) { - DateFormat df = UtilDateTime.toDateTimeFormat("EEE MMM dd hh:mm:ss z yyyy", timeZone, null); - return df.format((java.util.Date) retVal); - } else { - returnValue = retVal.toString(); - } - } else { - returnValue = defaultValue; - } - } - - if (this.getEncodeOutput() && returnValue != null) { - UtilCodec.SimpleEncoder simpleEncoder = (UtilCodec.SimpleEncoder) context.get("simpleEncoder"); - if (simpleEncoder != null) - returnValue = simpleEncoder.encode(returnValue); - } - return returnValue; - } - - public FlexibleMapAccessor getEntryAcsr() { - return entryAcsr; - } - - public String getEntryName() { - if (UtilValidate.isNotEmpty(this.entryAcsr)) - return this.entryAcsr.getOriginalName(); - return this.name; - } - - public String getEvent() { - return event; - } - - public FieldInfo getFieldInfo() { - return fieldInfo; - } - - /** - * Gets the name of the Entity Field that corresponds - * with this field. This can be used to get additional information about the field. - * Use the getEntityName() method to get the Entity name that the field is in. - * - * @return return the name of the Entity Field that corresponds with this field - */ - public String getFieldName() { - if (UtilValidate.isNotEmpty(this.fieldName)) - return this.fieldName; - return this.name; - } - - public String getHeaderLink() { - return headerLink; - } - - public String getHeaderLinkStyle() { - return headerLinkStyle; - } - - public String getIdName() { - if (UtilValidate.isNotEmpty(idName)) - return idName; - return this.modelForm.getName() + "_" + this.getFieldName(); - } - - public Map getMap(Map context) { - if (UtilValidate.isEmpty(this.mapAcsr)) - return this.modelForm.getDefaultMap(context); //Debug.logInfo("Getting Map from default of the form because of no mapAcsr for field " + this.getName(), module); - - // Debug.logInfo("Getting Map from mapAcsr for field " + this.getName() + ", map-name=" + mapAcsr.getOriginalName() + ", context type=" + context.getClass().toString(), module); - Map result = null; - try { - result = mapAcsr.get(context); - } catch (java.lang.ClassCastException e) { - String errMsg = "Got an unexpected object type (not a Map) for map-name [" + mapAcsr.getOriginalName() - + "] in field with name [" + this.getName() + "]: " + e.getMessage(); - Debug.logError(errMsg, module); - throw new ClassCastException(errMsg); - } - return result; - } - - public FlexibleMapAccessor> getMapAcsr() { - return mapAcsr; - } - - /** Get the name of the Map in the form context that contains the entry, - * available from the getEntryName() method. This entry is used to - * pre-populate the field widget when not in an error condition. In an - * error condition the parameter name is used to get the value from the - * parameters Map. - * - * @return returns the name of the Map in the form context that contains the entry - */ - public String getMapName() { - if (UtilValidate.isNotEmpty(this.mapAcsr)) - return this.mapAcsr.getOriginalName(); - return this.modelForm.getDefaultMapName(); - } - - public ModelForm getModelForm() { - return modelForm; - } - - public String getName() { - return name; - } - - public List getOnChangeUpdateAreas() { - return onChangeUpdateAreas; - } - - public List getOnClickUpdateAreas() { - return onClickUpdateAreas; - } - - public String getParameterName() { - return parameterName; - } - - /** - * Get the name to use for the parameter for this field in the form interpreter. - * For HTML forms this is the request parameter name. - * - * @return returns the name to use for the parameter for this field in the form interpreter - */ - public String getParameterName(Map context) { - String baseName; - if (UtilValidate.isNotEmpty(this.parameterName)) - baseName = this.parameterName; - else - baseName = this.name; - - Integer itemIndex = (Integer) context.get("itemIndex"); - if (itemIndex != null && "multi".equals(this.modelForm.getType())) { - return baseName + this.modelForm.getItemIndexSeparator() + itemIndex.intValue(); - } else { - return baseName; - } - } - - public int getPosition() { - if (this.position == null) - return 1; - return position.intValue(); - } - - public String getRedWhen() { - return redWhen; - } - - public boolean getRequiredField() { - return this.requiredField != null ? this.requiredField : false; - } - - public String getRequiredFieldStyle() { - if (UtilValidate.isNotEmpty(this.requiredFieldStyle)) - return this.requiredFieldStyle; - return this.modelForm.getDefaultRequiredFieldStyle(); - } - - public boolean getSeparateColumn() { - return this.separateColumn; - } - - public String getServiceName() { - if (UtilValidate.isNotEmpty(this.serviceName)) - return this.serviceName; - return this.modelForm.getDefaultServiceName(); - } - - public Boolean getSortField() { - return sortField; - } - - public String getSortFieldAscStyle() { - return sortFieldAscStyle; - } - - public String getSortFieldDescStyle() { - return sortFieldDescStyle; - } - - public String getSortFieldHelpText() { - return sortFieldHelpText; - } - - public String getSortFieldHelpText(Map context) { - return FlexibleStringExpander.expandString(this.sortFieldHelpText, context); - } - - public String getSortFieldStyle() { - if (UtilValidate.isNotEmpty(this.sortFieldStyle)) - return this.sortFieldStyle; - return this.modelForm.getDefaultSortFieldStyle(); - } - - public String getSortFieldStyleAsc() { - if (UtilValidate.isNotEmpty(this.sortFieldAscStyle)) - return this.sortFieldAscStyle; - return this.modelForm.getDefaultSortFieldAscStyle(); - } - - public String getSortFieldStyleDesc() { - if (UtilValidate.isNotEmpty(this.sortFieldDescStyle)) - return this.sortFieldDescStyle; - return this.modelForm.getDefaultSortFieldDescStyle(); - } - - public FlexibleStringExpander getTitle() { - return title; - } - - public String getTitle(Map context) { - if (UtilValidate.isNotEmpty(this.title)) - return title.expandString(context); - - // create a title from the name of this field; expecting a Java method/field style name, ie productName or productCategoryId - if (UtilValidate.isEmpty(this.name)) - return ""; // this should never happen, ie name is required - - // search for a localized label for the field's name - Map uiLabelMap = UtilGenerics.checkMap(context.get("uiLabelMap")); - if (uiLabelMap != null) { - String titleFieldName = "FormFieldTitle_" + this.name; - String localizedName = uiLabelMap.get(titleFieldName); - if (!localizedName.equals(titleFieldName)) { - return localizedName; - } - } else { - Debug.logWarning("Could not find uiLabelMap in context while rendering form " + this.modelForm.getName(), module); - } - - // create a title from the name of this field; expecting a Java method/field style name, ie productName or productCategoryId - StringBuilder autoTitlewriter = new StringBuilder(); - - // always use upper case first letter... - autoTitlewriter.append(Character.toUpperCase(this.name.charAt(0))); - - // just put spaces before the upper case letters - for (int i = 1; i < this.name.length(); i++) { - char curChar = this.name.charAt(i); - if (Character.isUpperCase(curChar)) { - autoTitlewriter.append(' '); - } - autoTitlewriter.append(curChar); - } - - return autoTitlewriter.toString(); - } - - public String getTitleAreaStyle() { - if (UtilValidate.isNotEmpty(this.titleAreaStyle)) - return this.titleAreaStyle; - return this.modelForm.getDefaultTitleAreaStyle(); - } - - public String getTitleStyle() { - if (UtilValidate.isNotEmpty(this.titleStyle)) - return this.titleStyle; - return this.modelForm.getDefaultTitleStyle(); - } - - public FlexibleStringExpander getTooltip() { - return tooltip; - } - - public String getTooltip(Map context) { - String tooltipString = ""; - if (UtilValidate.isNotEmpty(tooltip)) - tooltipString = tooltip.expandString(context); - if (this.getEncodeOutput()) { - UtilCodec.SimpleEncoder simpleEncoder = (UtilCodec.SimpleEncoder) context.get("simpleEncoder"); - if (simpleEncoder != null) - tooltipString = simpleEncoder.encode(tooltipString); - } - return tooltipString; - } - - public String getTooltipStyle() { - if (UtilValidate.isNotEmpty(this.tooltipStyle)) - return this.tooltipStyle; - return this.modelForm.getDefaultTooltipStyle(); - } - - public FlexibleStringExpander getUseWhen() { - return useWhen; - } - - public String getUseWhen(Map context) { - if (UtilValidate.isNotEmpty(this.useWhen)) - return this.useWhen.expandString(context); - return ""; - } - - public String getWidgetAreaStyle() { - if (UtilValidate.isNotEmpty(this.widgetAreaStyle)) - return this.widgetAreaStyle; - return this.modelForm.getDefaultWidgetAreaStyle(); - } - - public String getWidgetStyle() { - if (UtilValidate.isNotEmpty(this.widgetStyle)) - return this.widgetStyle; - return this.modelForm.getDefaultWidgetStyle(); - } - - /** - * Checks if field is a row submit field. - */ - public boolean isRowSubmit() { - if (!"multi".equals(getModelForm().getType())) - return false; - if (getFieldInfo().getFieldType() != FieldInfo.CHECK) - return false; - if (!CheckField.ROW_SUBMIT_FIELD_NAME.equals(getName())) - return false; - return true; - } - - public boolean isSortField() { - return this.sortField != null && this.sortField.booleanValue(); - } - - public boolean isUseWhenEmpty() { - if (this.useWhen == null) { - return true; - } - - return this.useWhen.isEmpty(); - } - - public void renderFieldString(Appendable writer, Map context, FormStringRenderer formStringRenderer) - throws IOException { - this.fieldInfo.renderFieldString(writer, context, formStringRenderer); - } - - /** - * the widget/interaction part will be red if the date value is - * before-now (for ex. thruDate), after-now (for ex. fromDate), or by-name (if the - * field's name or entry-name or fromDate or thruDate the corresponding - * action will be done); only applicable when the field is a timestamp - * - * @param context the context - * @return true if the field should be read otherwise false - */ - public boolean shouldBeRed(Map context) { - // red-when (never | before-now | after-now | by-name) "by-name" - - String redCondition = this.redWhen; - - if ("never".equals(redCondition)) - return false; - - // for performance resaons we check this first, most fields will be eliminated here and the valueOfs will not be necessary - if (UtilValidate.isEmpty(redCondition) || "by-name".equals(redCondition)) { - if ("fromDate".equals(this.name) || (this.entryAcsr != null && "fromDate".equals(this.entryAcsr.getOriginalName()))) { - redCondition = "after-now"; - } else if ("thruDate".equals(this.name) - || (this.entryAcsr != null && "thruDate".equals(this.entryAcsr.getOriginalName()))) { - redCondition = "before-now"; - } else { - return false; - } - } - - boolean isBeforeNow = false; - if ("before-now".equals(redCondition)) { - isBeforeNow = true; - } else if ("after-now".equals(redCondition)) { - isBeforeNow = false; - } else { - return false; - } - - java.sql.Date dateVal = null; - java.sql.Time timeVal = null; - java.sql.Timestamp timestampVal = null; - - //now before going on, check to see if the current entry is a valid date and/or time and get the value - String value = this.getEntry(context, null); - try { - timestampVal = java.sql.Timestamp.valueOf(value); - } catch (Exception e) { - // okay, not a timestamp... - } - - if (timestampVal == null) { - try { - dateVal = java.sql.Date.valueOf(value); - } catch (Exception e) { - // okay, not a date... - } - } - - if (timestampVal == null && dateVal == null) { - try { - timeVal = java.sql.Time.valueOf(value); - } catch (Exception e) { - // okay, not a time... - } - } - - if (timestampVal == null && dateVal == null && timeVal == null) { - return false; - } - - long nowMillis = System.currentTimeMillis(); - if (timestampVal != null) { - java.sql.Timestamp nowStamp = new java.sql.Timestamp(nowMillis); - if (!timestampVal.equals(nowStamp)) { - if (isBeforeNow) { - if (timestampVal.before(nowStamp)) { - return true; - } - } else { - if (timestampVal.after(nowStamp)) { - return true; - } - } - } - } else if (dateVal != null) { - java.sql.Date nowDate = new java.sql.Date(nowMillis); - if (!dateVal.equals(nowDate)) { - if (isBeforeNow) { - if (dateVal.before(nowDate)) { - return true; - } - } else { - if (dateVal.after(nowDate)) { - return true; - } - } - } - } else if (timeVal != null) { - java.sql.Time nowTime = new java.sql.Time(nowMillis); - if (!timeVal.equals(nowTime)) { - if (isBeforeNow) { - if (timeVal.before(nowTime)) { - return true; - } - } else { - if (timeVal.after(nowTime)) { - return true; - } - } - } - } - - return false; - } - - public boolean shouldUse(Map context) { - String useWhenStr = this.getUseWhen(context); - if (UtilValidate.isEmpty(useWhenStr)) - return true; - - try { - Interpreter bsh = this.modelForm.getBshInterpreter(context); - Object retVal = bsh.eval(StringUtil.convertOperatorSubstitutions(useWhenStr)); - boolean condTrue = false; - // retVal should be a Boolean, if not something weird is up... - if (retVal instanceof Boolean) { - Boolean boolVal = (Boolean) retVal; - condTrue = boolVal.booleanValue(); - } else { - throw new IllegalArgumentException("Return value from use-when condition eval was not a Boolean: " - + (retVal != null ? retVal.getClass().getName() : "null") + " [" + retVal + "] on the field " + this.name - + " of form " + this.modelForm.getName()); - } - - return condTrue; - } catch (EvalError e) { - String errMsg = "Error evaluating BeanShell use-when condition [" + useWhenStr + "] on the field " + this.name - + " of form " + this.modelForm.getName() + ": " + e.toString(); - Debug.logError(e, errMsg, module); - //Debug.logError("For use-when eval error context is: " + context, module); - throw new IllegalArgumentException(errMsg); - } - } - - /** - * Models the <auto-complete> element. - * - * @see widget-form.xsd - */ - public static class AutoComplete { - private final String autoSelect; - private final String choices; - private final String frequency; - private final String fullSearch; - private final String ignoreCase; - private final String minChars; - private final String partialChars; - private final String partialSearch; - - public AutoComplete(Element element) { - this.autoSelect = element.getAttribute("auto-select"); - this.frequency = element.getAttribute("frequency"); - this.minChars = element.getAttribute("min-chars"); - this.choices = element.getAttribute("choices"); - this.partialSearch = element.getAttribute("partial-search"); - this.partialChars = element.getAttribute("partial-chars"); - this.ignoreCase = element.getAttribute("ignore-case"); - this.fullSearch = element.getAttribute("full-search"); - } - - public String getAutoSelect() { - return this.autoSelect; - } - - public String getChoices() { - return this.choices; - } - - public String getFrequency() { - return this.frequency; - } - - public String getFullSearch() { - return this.fullSearch; - } - - public String getIgnoreCase() { - return this.ignoreCase; - } - - public String getMinChars() { - return this.minChars; - } - - public String getPartialChars() { - return this.partialChars; - } - - public String getPartialSearch() { - return this.partialSearch; - } - } - - /** - * Models the <check> element. - * - * @see widget-form.xsd - */ - public static class CheckField extends FieldInfoWithOptions { - public final static String ROW_SUBMIT_FIELD_NAME = "_rowSubmit"; - private final FlexibleStringExpander allChecked; - - private CheckField(CheckField original, ModelFormField modelFormField) { - super(original, modelFormField); - this.allChecked = original.allChecked; - } - - public CheckField(Element element, ModelFormField modelFormField) { - super(element, modelFormField); - allChecked = FlexibleStringExpander.getInstance(element.getAttribute("all-checked")); - } - - public CheckField(int fieldSource, ModelFormField modelFormField) { - super(fieldSource, FieldInfo.CHECK, modelFormField); - this.allChecked = FlexibleStringExpander.getInstance(""); - } - - public CheckField(ModelFormField modelFormField) { - super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.CHECK, modelFormField); - this.allChecked = FlexibleStringExpander.getInstance(""); - } - - @Override - public void accept(ModelFieldVisitor visitor) throws Exception { - visitor.visit(this); - } - - @Override - public FieldInfo copy(ModelFormField modelFormField) { - return new CheckField(this, modelFormField); - } - - public FlexibleStringExpander getAllChecked() { - return allChecked; - } - - public Boolean isAllChecked(Map context) { - String allCheckedStr = this.allChecked.expandString(context); - if (!allCheckedStr.isEmpty()) - return Boolean.valueOf("true".equals(allCheckedStr)); - else - return null; - } - - @Override - public void renderFieldString(Appendable writer, Map context, FormStringRenderer formStringRenderer) - throws IOException { - formStringRenderer.renderCheckField(writer, context, this); - } - } - - /** - * Models the <container> element. - * - * @see widget-form.xsd - */ - public static class ContainerField extends FieldInfo { - - private ContainerField(ContainerField original, ModelFormField modelFormField) { - super(original.getFieldSource(), original.getFieldType(), modelFormField); - } - - public ContainerField(Element element, ModelFormField modelFormField) { - super(element, modelFormField); - } - - public ContainerField(int fieldSource, int fieldType, ModelFormField modelFormField) { - super(fieldSource, fieldType, modelFormField); - } - - @Override - public void accept(ModelFieldVisitor visitor) throws Exception { - visitor.visit(this); - } - - @Override - public FieldInfo copy(ModelFormField modelFormField) { - return new ContainerField(this, modelFormField); - } - - @Override - public void renderFieldString(Appendable writer, Map context, FormStringRenderer formStringRenderer) - throws IOException { - formStringRenderer.renderContainerFindField(writer, context, this); - } - } - - /** - * Models the <date-find> element. - * - * @see widget-form.xsd - */ - public static class DateFindField extends DateTimeField { - private final String defaultOptionFrom; - private final String defaultOptionThru; - - private DateFindField(DateFindField original, ModelFormField modelFormField) { - super(original, modelFormField); - this.defaultOptionFrom = original.defaultOptionFrom; - this.defaultOptionThru = original.defaultOptionThru; - } - - public DateFindField(Element element, ModelFormField modelFormField) { - super(element, modelFormField); - this.defaultOptionFrom = element.getAttribute("default-option-from"); - this.defaultOptionThru = element.getAttribute("default-option-thru"); - } - - public DateFindField(int fieldSource, ModelFormField modelFormField) { - super(fieldSource, modelFormField); - this.defaultOptionFrom = "greaterThanEqualTo"; - this.defaultOptionThru = "lessThanEqualTo"; - } - - public DateFindField(int fieldSource, String type) { - super(fieldSource, type); - this.defaultOptionFrom = "greaterThanEqualTo"; - this.defaultOptionThru = "lessThanEqualTo"; - } - - @Override - public void accept(ModelFieldVisitor visitor) throws Exception { - visitor.visit(this); - } - - @Override - public FieldInfo copy(ModelFormField modelFormField) { - return new DateFindField(this, modelFormField); - } - - public String getDefaultOptionFrom() { - return this.defaultOptionFrom; - } - - public String getDefaultOptionThru() { - return this.defaultOptionThru; - } - - @Override - public void renderFieldString(Appendable writer, Map context, FormStringRenderer formStringRenderer) - throws IOException { - formStringRenderer.renderDateFindField(writer, context, this); - } - } - - /** - * Models the <date-time> element. - * - * @see widget-form.xsd - */ - public static class DateTimeField extends FieldInfo { - private final String clock; - private final FlexibleStringExpander defaultValue; - private final String inputMethod; - private final String mask; - private final String step; - private final String type; - - protected DateTimeField(DateTimeField original, ModelFormField modelFormField) { - super(original.getFieldSource(), original.getFieldType(), modelFormField); - this.defaultValue = original.defaultValue; - this.type = original.type; - this.inputMethod = original.inputMethod; - this.clock = original.clock; - this.mask = original.mask; - this.step = original.step; - } - - public DateTimeField(Element element, ModelFormField modelFormField) { - super(element, modelFormField); - this.defaultValue = FlexibleStringExpander.getInstance(element.getAttribute("default-value")); - this.type = element.getAttribute("type"); - this.inputMethod = element.getAttribute("input-method"); - this.clock = element.getAttribute("clock"); - this.mask = element.getAttribute("mask"); - String step = element.getAttribute("step"); - if (step.isEmpty()) { - step = "1"; - } - this.step = step; - } - - public DateTimeField(int fieldSource, ModelFormField modelFormField) { - super(fieldSource, FieldInfo.DATE_TIME, modelFormField); - this.defaultValue = FlexibleStringExpander.getInstance(""); - this.type = ""; - this.inputMethod = ""; - this.clock = ""; - this.mask = ""; - this.step = "1"; - } - - public DateTimeField(int fieldSource, String type) { - super(fieldSource, FieldInfo.DATE_TIME, null); - this.defaultValue = FlexibleStringExpander.getInstance(""); - this.type = type; - this.inputMethod = ""; - this.clock = ""; - this.mask = ""; - this.step = "1"; - } - - public DateTimeField(ModelFormField modelFormField) { - super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.DATE_TIME, modelFormField); - this.defaultValue = FlexibleStringExpander.getInstance(""); - this.type = ""; - this.inputMethod = ""; - this.clock = ""; - this.mask = ""; - this.step = "1"; - } - - @Override - public void accept(ModelFieldVisitor visitor) throws Exception { - visitor.visit(this); - } - - @Override - public FieldInfo copy(ModelFormField modelFormField) { - return new DateTimeField(this, modelFormField); - } - - public String getClock() { - return this.clock; - } - - /** - * Returns the default-value if specified, otherwise the current date, time or timestamp - * - * @param context Context Map - * @return Default value string for date-time - */ - public String getDefaultDateTimeString(Map context) { - if (UtilValidate.isNotEmpty(this.defaultValue)) - return this.getDefaultValue(context); - - if ("date".equals(this.type)) - return (new java.sql.Date(System.currentTimeMillis())).toString(); - else if ("time".equals(this.type)) - return (new java.sql.Time(System.currentTimeMillis())).toString(); - else - return UtilDateTime.nowTimestamp().toString(); - } - - public FlexibleStringExpander getDefaultValue() { - return defaultValue; - } - - public String getDefaultValue(Map context) { - if (this.defaultValue != null) { - return this.defaultValue.expandString(context); - } else { - return ""; - } - } - - public String getInputMethod() { - return this.inputMethod; - } - - public String getMask() { - return this.mask; - } - - public String getStep() { - return this.step; - } - - public String getType() { - return type; - } - - @Override - public void renderFieldString(Appendable writer, Map context, FormStringRenderer formStringRenderer) - throws IOException { - formStringRenderer.renderDateTimeField(writer, context, this); - } - } - - /** - * Models the <display-entity> element. - * - * @see widget-form.xsd - */ - public static class DisplayEntityField extends DisplayField { - private final boolean cache; - private final String entityName; - private final String keyFieldName; - private final SubHyperlink subHyperlink; - - private DisplayEntityField(DisplayEntityField original, ModelFormField modelFormField) { - super(original, modelFormField); - this.cache = original.cache; - this.entityName = original.entityName; - this.keyFieldName = original.keyFieldName; - if (original.subHyperlink != null) { - this.subHyperlink = new SubHyperlink(original.subHyperlink, modelFormField); - } else { - this.subHyperlink = null; - } - } - - public DisplayEntityField(Element element, ModelFormField modelFormField) { - super(element, modelFormField); - this.cache = !"false".equals(element.getAttribute("cache")); - this.entityName = element.getAttribute("entity-name"); - this.keyFieldName = element.getAttribute("key-field-name"); - Element subHyperlinkElement = UtilXml.firstChildElement(element, "sub-hyperlink"); - if (subHyperlinkElement != null) { - this.subHyperlink = new SubHyperlink(subHyperlinkElement, modelFormField); - } else { - this.subHyperlink = null; - } - } - - public DisplayEntityField(int fieldSource, ModelFormField modelFormField) { - super(fieldSource, FieldInfo.DISPLAY_ENTITY, modelFormField); - this.cache = true; - this.entityName = ""; - this.keyFieldName = ""; - this.subHyperlink = null; - } - - public DisplayEntityField(ModelFormField modelFormField) { - super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.DISPLAY_ENTITY, modelFormField); - this.cache = true; - this.entityName = ""; - this.keyFieldName = ""; - this.subHyperlink = null; - } - - @Override - public void accept(ModelFieldVisitor visitor) throws Exception { - visitor.visit(this); - } - - @Override - public FieldInfo copy(ModelFormField modelFormField) { - return new DisplayEntityField(this, modelFormField); - } - - public boolean getCache() { - return cache; - } - - @Override - public String getDescription(Map context) { - Locale locale = UtilMisc.ensureLocale(context.get("locale")); - - // rather than using the context to expand the string, lookup the given entity and use it to expand the string - GenericValue value = null; - String fieldKey = this.keyFieldName; - if (UtilValidate.isEmpty(fieldKey)) - fieldKey = getModelFormField().fieldName; - - Delegator delegator = WidgetWorker.getDelegator(context); - String fieldValue = getModelFormField().getEntry(context); - try { - value = delegator.findOne(this.entityName, this.cache, fieldKey, fieldValue); - } catch (GenericEntityException e) { - String errMsg = "Error getting value from the database for display of field [" + getModelFormField().getName() - + "] on form [" + getModelFormField().modelForm.getName() + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - throw new IllegalArgumentException(errMsg); - } - - String retVal = null; - if (value != null) { - // expanding ${} stuff, passing locale explicitly to expand value string because it won't be found in the Entity - MapStack localContext = MapStack.create(context); - // Rendering code might try to modify the GenericEntity instance, - // so we make a copy of it. - Map genericEntityClone = UtilGenerics.cast(value.clone()); - localContext.push(genericEntityClone); - - // expand with the new localContext, which is locale aware - retVal = this.getDescription().expandString(localContext, locale); - } - // try to get the entry for the field if description doesn't expand to anything - if (UtilValidate.isEmpty(retVal)) - retVal = fieldValue; - if (UtilValidate.isEmpty(retVal)) - retVal = ""; - return retVal; - } - - public String getEntityName() { - return entityName; - } - - public String getKeyFieldName() { - return keyFieldName; - } - - public SubHyperlink getSubHyperlink() { - return this.subHyperlink; - } - } - - /** - * Models the <display> element. - * - * @see widget-form.xsd - */ - public static class DisplayField extends FieldInfo { - private final boolean alsoHidden; - private final FlexibleStringExpander currency; - private final FlexibleStringExpander date; - private final FlexibleStringExpander defaultValue; - private final FlexibleStringExpander description; - private final FlexibleStringExpander imageLocation; - private final InPlaceEditor inPlaceEditor; - private final String size; // maximum number of characters to display - private final String type; // matches type of field, currently text or currency - - protected DisplayField(DisplayField original, ModelFormField modelFormField) { - super(original.getFieldSource(), original.getFieldType(), modelFormField); - this.alsoHidden = original.alsoHidden; - this.currency = original.currency; - this.date = original.date; - this.defaultValue = original.defaultValue; - this.description = original.description; - this.imageLocation = original.imageLocation; - this.inPlaceEditor = original.inPlaceEditor; - this.size = original.size; - this.type = original.type; - } - - public DisplayField(Element element, ModelFormField modelFormField) { - super(element, modelFormField); - this.alsoHidden = !"false".equals(element.getAttribute("also-hidden")); - this.currency = FlexibleStringExpander.getInstance(element.getAttribute("currency")); - this.date = FlexibleStringExpander.getInstance(element.getAttribute("date")); - this.defaultValue = FlexibleStringExpander.getInstance(element.getAttribute("default-value")); - this.description = FlexibleStringExpander.getInstance(element.getAttribute("description")); - this.imageLocation = FlexibleStringExpander.getInstance(element.getAttribute("image-location")); - Element inPlaceEditorElement = UtilXml.firstChildElement(element, "in-place-editor"); - if (inPlaceEditorElement != null) { - this.inPlaceEditor = new InPlaceEditor(inPlaceEditorElement); - } else { - this.inPlaceEditor = null; - } - this.size = element.getAttribute("size"); - this.type = element.getAttribute("type"); - } - - public DisplayField(int fieldSource, int fieldType, ModelFormField modelFormField) { - super(fieldSource, fieldType, modelFormField); - this.alsoHidden = true; - this.currency = FlexibleStringExpander.getInstance(""); - this.date = FlexibleStringExpander.getInstance(""); - this.defaultValue = FlexibleStringExpander.getInstance(""); - this.description = FlexibleStringExpander.getInstance(""); - this.imageLocation = FlexibleStringExpander.getInstance(""); - this.inPlaceEditor = null; - this.size = ""; - this.type = ""; - } - - public DisplayField(int fieldSource, ModelFormField modelFormField) { - super(fieldSource, FieldInfo.DISPLAY, modelFormField); - this.alsoHidden = true; - this.currency = FlexibleStringExpander.getInstance(""); - this.date = FlexibleStringExpander.getInstance(""); - this.defaultValue = FlexibleStringExpander.getInstance(""); - this.description = FlexibleStringExpander.getInstance(""); - this.imageLocation = FlexibleStringExpander.getInstance(""); - this.inPlaceEditor = null; - this.size = ""; - this.type = ""; - } - - public DisplayField(ModelFormField modelFormField) { - super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.DISPLAY, modelFormField); - this.alsoHidden = true; - this.currency = FlexibleStringExpander.getInstance(""); - this.date = FlexibleStringExpander.getInstance(""); - this.defaultValue = FlexibleStringExpander.getInstance(""); - this.description = FlexibleStringExpander.getInstance(""); - this.imageLocation = FlexibleStringExpander.getInstance(""); - this.inPlaceEditor = null; - this.size = ""; - this.type = ""; - } - - @Override - public void accept(ModelFieldVisitor visitor) throws Exception { - visitor.visit(this); - } - - @Override - public FieldInfo copy(ModelFormField modelFormField) { - return new DisplayField(this, modelFormField); - } - - public boolean getAlsoHidden() { - return alsoHidden; - } - - public FlexibleStringExpander getCurrency() { - return currency; - } - - public FlexibleStringExpander getDate() { - return date; - } - - public FlexibleStringExpander getDefaultValue() { - return defaultValue; - } - - public String getDefaultValue(Map context) { - if (this.defaultValue != null) { - return this.defaultValue.expandString(context); - } else { - return ""; - } - } - - public FlexibleStringExpander getDescription() { - return description; - } - - public String getDescription(Map context) { - String retVal = null; - if (UtilValidate.isNotEmpty(this.description)) - retVal = this.description.expandString(context); - else - retVal = getModelFormField().getEntry(context); - - if (UtilValidate.isEmpty(retVal)) { - retVal = this.getDefaultValue(context); - } else if ("currency".equals(type)) { - retVal = retVal.replaceAll(" ", " "); // FIXME : encoding currency is a problem for some locale, we should not have any   in retVal other case may arise in future... - Locale locale = (Locale) context.get("locale"); - if (locale == null) - locale = Locale.getDefault(); - String isoCode = null; - if (UtilValidate.isNotEmpty(this.currency)) - isoCode = this.currency.expandString(context); - - try { - BigDecimal parsedRetVal = (BigDecimal) ObjectType.simpleTypeConvert(retVal, "BigDecimal", null, null, locale, - true); - retVal = UtilFormatOut.formatCurrency(parsedRetVal, isoCode, locale, 10); // we set the max to 10 digits as an hack to not round numbers in the ui - } catch (GeneralException e) { - String errMsg = "Error formatting currency value [" + retVal + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - throw new IllegalArgumentException(errMsg); - } - } else if ("date".equals(this.type) && retVal.length() > 10) { - Locale locale = (Locale) context.get("locale"); - if (locale == null) { - locale = Locale.getDefault(); - } - - StringToTimestamp stringToTimestamp = new DateTimeConverters.StringToTimestamp(); - Timestamp timestamp = null; - try { - timestamp = stringToTimestamp.convert(retVal); - Date date = new Date(timestamp.getTime()); - - DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.SHORT, locale); - retVal = dateFormatter.format(date); - } catch (ConversionException e) { - String errMsg = "Error formatting date using default instead [" + retVal + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - // create default date value from timestamp string - retVal = retVal.substring(0, 10); - } - - } else if ("date-time".equals(this.type) && retVal.length() > 16) { - Locale locale = (Locale) context.get("locale"); - TimeZone timeZone = (TimeZone) context.get("timeZone"); - if (locale == null) { - locale = Locale.getDefault(); - } - if (timeZone == null) { - timeZone = TimeZone.getDefault(); - } - - StringToTimestamp stringToTimestamp = new DateTimeConverters.StringToTimestamp(); - Timestamp timestamp = null; - try { - timestamp = stringToTimestamp.convert(retVal); - Date date = new Date(timestamp.getTime()); - - DateFormat dateFormatter = UtilDateTime.toDateTimeFormat(null, timeZone, locale); - retVal = dateFormatter.format(date); - } catch (ConversionException e) { - String errMsg = "Error formatting date/time using default instead [" + retVal + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - // create default date/time value from timestamp string - retVal = retVal.substring(0, 16); - } - } else if ("accounting-number".equals(this.type)) { - Locale locale = (Locale) context.get("locale"); - if (locale == null) { - locale = Locale.getDefault(); - } - try { - Double parsedRetVal = (Double) ObjectType.simpleTypeConvert(retVal, "Double", null, locale, false); - String template = UtilProperties.getPropertyValue("arithmetic", "accounting-number.format", - "#,##0.00;(#,##0.00)"); - retVal = UtilFormatOut.formatDecimalNumber(parsedRetVal.doubleValue(), template, locale); - } catch (GeneralException e) { - String errMsg = "Error formatting number [" + retVal + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - throw new IllegalArgumentException(errMsg); - } - } - if (UtilValidate.isNotEmpty(this.description) && retVal != null && this.getModelFormField().getEncodeOutput()) { - UtilCodec.SimpleEncoder simpleEncoder = (UtilCodec.SimpleEncoder) context.get("simpleEncoder"); - if (simpleEncoder != null) { - retVal = simpleEncoder.encode(retVal); - } - } - return retVal; - } - - public FlexibleStringExpander getImageLocation() { - return imageLocation; - } - - public String getImageLocation(Map context) { - if (this.imageLocation != null) - return this.imageLocation.expandString(context); - return ""; - } - - public InPlaceEditor getInPlaceEditor() { - return this.inPlaceEditor; - } - - public String getSize() { - return this.size; - } - - public String getType() { - return this.type; - } - - @Override - public void renderFieldString(Appendable writer, Map context, FormStringRenderer formStringRenderer) - throws IOException { - formStringRenderer.renderDisplayField(writer, context, this); - } - } - - /** - * Models the <drop-down> element. - * - * @see widget-form.xsd - */ - public static class DropDownField extends FieldInfoWithOptions { - private final boolean allowEmpty; - private final boolean allowMulti; - private final AutoComplete autoComplete; - private final String current; - private final FlexibleStringExpander currentDescription; - private final int otherFieldSize; - private final String size; - private final SubHyperlink subHyperlink; - private final String textSize; - - private DropDownField(DropDownField original, ModelFormField modelFormField) { - super(original, modelFormField); - this.allowEmpty = original.allowEmpty; - this.allowMulti = original.allowMulti; - this.autoComplete = original.autoComplete; - this.current = original.current; - this.currentDescription = original.currentDescription; - this.otherFieldSize = original.otherFieldSize; - this.size = original.size; - if (original.subHyperlink != null) { - this.subHyperlink = new SubHyperlink(original.subHyperlink, modelFormField); - } else { - this.subHyperlink = null; - } - this.textSize = original.textSize; - } - - public DropDownField(Element element, ModelFormField modelFormField) { - super(element, modelFormField); - this.allowEmpty = "true".equals(element.getAttribute("allow-empty")); - this.allowMulti = "true".equals(element.getAttribute("allow-multiple")); - Element autoCompleteElement = UtilXml.firstChildElement(element, "auto-complete"); - if (autoCompleteElement != null) { - this.autoComplete = new AutoComplete(autoCompleteElement); - } else { - this.autoComplete = null; - } - this.current = element.getAttribute("current"); - this.currentDescription = FlexibleStringExpander.getInstance(element.getAttribute("current-description")); - int otherFieldSize = 0; - String sizeStr = element.getAttribute("other-field-size"); - if (!sizeStr.isEmpty()) { - try { - otherFieldSize = Integer.parseInt(sizeStr); - } catch (Exception e) { - Debug.logError("Could not parse the size value of the text element: [" + sizeStr - + "], setting to the default of 0", module); - } - } - this.otherFieldSize = otherFieldSize; - String size = element.getAttribute("size"); - if (size.isEmpty()) { - size = "1"; - } - this.size = size; - Element subHyperlinkElement = UtilXml.firstChildElement(element, "sub-hyperlink"); - if (subHyperlinkElement != null) { - this.subHyperlink = new SubHyperlink(subHyperlinkElement, this.getModelFormField()); - } else { - this.subHyperlink = null; - } - String textSize = element.getAttribute("text-size"); - if (textSize.isEmpty()) { - textSize = "0"; - } - this.textSize = textSize; - } - - public DropDownField(int fieldSource, List optionSources) { - super(fieldSource, FieldInfo.DROP_DOWN, optionSources); - this.allowEmpty = false; - this.allowMulti = false; - this.autoComplete = null; - this.current = ""; - this.currentDescription = FlexibleStringExpander.getInstance(""); - this.otherFieldSize = 0; - this.size = "1"; - this.subHyperlink = null; - this.textSize = "0"; - } - - public DropDownField(int fieldSource, ModelFormField modelFormField) { - super(fieldSource, FieldInfo.DROP_DOWN, modelFormField); - this.allowEmpty = false; - this.allowMulti = false; - this.autoComplete = null; - this.current = ""; - this.currentDescription = FlexibleStringExpander.getInstance(""); - this.otherFieldSize = 0; - this.size = "1"; - this.subHyperlink = null; - this.textSize = "0"; - } - - public DropDownField(ModelFormField modelFormField) { - super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.DROP_DOWN, modelFormField); - this.allowEmpty = false; - this.allowMulti = false; - this.autoComplete = null; - this.current = ""; - this.currentDescription = FlexibleStringExpander.getInstance(""); - this.otherFieldSize = 0; - this.size = "1"; - this.subHyperlink = null; - this.textSize = "0"; - } - - @Override - public void accept(ModelFieldVisitor visitor) throws Exception { - visitor.visit(this); - } - - @Override - public FieldInfo copy(ModelFormField modelFormField) { - return new DropDownField(this, modelFormField); - } - - public boolean getAllowMulti() { - return allowMulti; - } - - public AutoComplete getAutoComplete() { - return this.autoComplete; - } - - public String getCurrent() { - if (UtilValidate.isEmpty(this.current)) - return "first-in-list"; - return this.current; - } - - public FlexibleStringExpander getCurrentDescription() { - return currentDescription; - } - - public String getCurrentDescription(Map context) { - if (this.currentDescription == null) - return null; - return this.currentDescription.expandString(context); - } - - public int getOtherFieldSize() { - return this.otherFieldSize; - } - - /** - * Get the name to use for the parameter for this field in the form interpreter. - * For HTML forms this is the request parameter name. - * @param context the context - * @return returns the name to use for the parameter for this field in the form interpreter. - */ - public String getParameterNameOther(Map context) { - String baseName; - if (UtilValidate.isNotEmpty(getModelFormField().parameterName)) - baseName = getModelFormField().parameterName; - else - baseName = getModelFormField().name; - - baseName += "_OTHER"; - Integer itemIndex = (Integer) context.get("itemIndex"); - if (itemIndex != null && "multi".equals(getModelFormField().modelForm.getType())) { - return baseName + getModelFormField().modelForm.getItemIndexSeparator() + itemIndex.intValue(); - } else { - return baseName; - } - } - - public String getSize() { - return this.size; - } - - public SubHyperlink getSubHyperlink() { - return this.subHyperlink; - } - - public String getTextSize() { - return this.textSize; - } - - public boolean getAllowEmpty() { - return this.allowEmpty; - } - - public boolean getAllowMultiple() { - return this.allowMulti; - } - - @Override - public void renderFieldString(Appendable writer, Map context, FormStringRenderer formStringRenderer) - throws IOException { - formStringRenderer.renderDropDownField(writer, context, this); - } - } - - /** - * Models the <entity-options> element. - * - * @see widget-form.xsd - */ - public static class EntityOptions extends OptionSource { - private final boolean cache; - private final List constraintList; - private final FlexibleStringExpander description; - private final String entityName; - private final String filterByDate; - private final String keyFieldName; - private final List orderByList; - - public EntityOptions(Element entityOptionsElement, ModelFormField modelFormField) { - super(modelFormField); - this.cache = !"false".equals(entityOptionsElement.getAttribute("cache")); - List constraintElements = UtilXml.childElementList(entityOptionsElement, "entity-constraint"); - if (!constraintElements.isEmpty()) { - List constraintList = new ArrayList( - constraintElements.size()); - for (Element constraintElement : constraintElements) { - constraintList.add(new EntityFinderUtil.ConditionExpr(constraintElement)); - } - this.constraintList = Collections.unmodifiableList(constraintList); - } else { - this.constraintList = Collections.emptyList(); - } - this.description = FlexibleStringExpander.getInstance(entityOptionsElement.getAttribute("description")); - this.entityName = entityOptionsElement.getAttribute("entity-name"); - this.filterByDate = entityOptionsElement.getAttribute("filter-by-date"); - this.keyFieldName = entityOptionsElement.getAttribute("key-field-name"); - List orderByElements = UtilXml.childElementList(entityOptionsElement, "entity-order-by"); - if (!orderByElements.isEmpty()) { - List orderByList = new ArrayList(orderByElements.size()); - for (Element orderByElement : orderByElements) { - orderByList.add(orderByElement.getAttribute("field-name")); - } - this.orderByList = Collections.unmodifiableList(orderByList); - } else { - this.orderByList = Collections.emptyList(); - } - } - - private EntityOptions(EntityOptions original, ModelFormField modelFormField) { - super(modelFormField); - this.cache = original.cache; - this.constraintList = original.constraintList; - this.description = original.description; - this.entityName = original.entityName; - this.filterByDate = original.filterByDate; - this.keyFieldName = original.keyFieldName; - this.orderByList = original.orderByList; - } - - public EntityOptions(ModelFormField modelFormField) { - super(modelFormField); - this.cache = true; - this.constraintList = Collections.emptyList(); - this.description = FlexibleStringExpander.getInstance(""); - this.entityName = ""; - this.filterByDate = ""; - this.keyFieldName = ""; - this.orderByList = Collections.emptyList(); - } - - @Override - public void addOptionValues(List optionValues, Map context, Delegator delegator) { - // first expand any conditions that need expanding based on the current context - EntityCondition findCondition = null; - if (UtilValidate.isNotEmpty(this.constraintList)) { - List expandedConditionList = new LinkedList(); - for (EntityFinderUtil.Condition condition : constraintList) { - ModelEntity modelEntity = delegator.getModelEntity(this.entityName); - if (modelEntity == null) { - throw new IllegalArgumentException("Error in entity-options: could not find entity [" + this.entityName - + "]"); - } - EntityCondition createdCondition = condition.createCondition(context, modelEntity, - delegator.getModelFieldTypeReader(modelEntity)); - if (createdCondition != null) { - expandedConditionList.add(createdCondition); - } - } - findCondition = EntityCondition.makeCondition(expandedConditionList); - } - - try { - Locale locale = UtilMisc.ensureLocale(context.get("locale")); - - List values = null; - values = delegator.findList(this.entityName, findCondition, null, this.orderByList, null, this.cache); - - // filter-by-date if requested - if ("true".equals(this.filterByDate)) { - values = EntityUtil.filterByDate(values, true); - } else if (!"false".equals(this.filterByDate)) { - // not explicitly true or false, check to see if has fromDate and thruDate, if so do the filter - ModelEntity modelEntity = delegator.getModelEntity(this.entityName); - if (modelEntity != null && modelEntity.isField("fromDate") && modelEntity.isField("thruDate")) { - values = EntityUtil.filterByDate(values, true); - } - } - - for (GenericValue value : values) { - // add key and description with string expansion, ie expanding ${} stuff, passing locale explicitly to expand value string because it won't be found in the Entity - MapStack localContext = MapStack.create(context); - // Rendering code might try to modify the GenericEntity instance, - // so we make a copy of it. - Map genericEntityClone = UtilGenerics.cast(value.clone()); - localContext.push(genericEntityClone); - - // expand with the new localContext, which is locale aware - String optionDesc = this.description.expandString(localContext, locale); - - Object keyFieldObject = value.get(this.getKeyFieldName()); - if (keyFieldObject == null) { - throw new IllegalArgumentException( - "The entity-options identifier (from key-name attribute, or default to the field name) [" - + this.getKeyFieldName() + "], may not be a valid key field name for the entity [" - + this.entityName + "]."); - } - String keyFieldValue = keyFieldObject.toString(); - optionValues.add(new OptionValue(keyFieldValue, optionDesc)); - } - } catch (GenericEntityException e) { - Debug.logError(e, "Error getting entity options in form", module); - } - } - - @Override - public OptionSource copy(ModelFormField modelFormField) { - return new EntityOptions(this, modelFormField); - } - - public boolean getCache() { - return cache; - } - - public List getConstraintList() { - return constraintList; - } - - public FlexibleStringExpander getDescription() { - return description; - } - - public String getEntityName() { - return entityName; - } - - public String getFilterByDate() { - return filterByDate; - } - - public String getKeyFieldName() { - if (UtilValidate.isNotEmpty(this.keyFieldName)) - return this.keyFieldName; - return getModelFormField().getFieldName(); // get the modelFormField fieldName - } - - public List getOrderByList() { - return orderByList; - } - } - - public static abstract class FieldInfoWithOptions extends FieldInfo { - - public static String getDescriptionForOptionKey(String key, List allOptionValues) { - if (UtilValidate.isEmpty(key)) - return ""; - - if (UtilValidate.isEmpty(allOptionValues)) - return key; - - for (OptionValue optionValue : allOptionValues) { - if (key.equals(optionValue.getKey())) { - return optionValue.getDescription(); - } - } - - // if we get here we didn't find a match, just return the key - return key; - } - - private final FlexibleStringExpander noCurrentSelectedKey; - private final List optionSources; - - public FieldInfoWithOptions(Element element, ModelFormField modelFormField) { - super(element, modelFormField); - this.noCurrentSelectedKey = FlexibleStringExpander.getInstance(element.getAttribute("no-current-selected-key")); - // read all option and entity-options sub-elements, maintaining order - ArrayList optionSources = new ArrayList(); - List childElements = UtilXml.childElementList(element); - if (childElements.size() > 0) { - for (Element childElement : childElements) { - if ("option".equals(childElement.getTagName())) { - optionSources.add(new SingleOption(childElement, modelFormField)); - } else if ("list-options".equals(childElement.getTagName())) { - optionSources.add(new ListOptions(childElement, modelFormField)); - } else if ("entity-options".equals(childElement.getTagName())) { - optionSources.add(new EntityOptions(childElement, modelFormField)); - } - } - } else { - // this must be added or the multi-form select box options would not show up - optionSources.add(new SingleOption("Y", " ", modelFormField)); - } - optionSources.trimToSize(); - this.optionSources = Collections.unmodifiableList(optionSources); - } - - // Copy constructor. - protected FieldInfoWithOptions(FieldInfoWithOptions original, ModelFormField modelFormField) { - super(original.getFieldSource(), original.getFieldType(), modelFormField); - this.noCurrentSelectedKey = original.noCurrentSelectedKey; - if (original.optionSources.isEmpty()) { - this.optionSources = original.optionSources; - } else { - List optionSources = new ArrayList(original.optionSources.size()); - for (OptionSource source : original.optionSources) { - optionSources.add(source.copy(modelFormField)); - } - this.optionSources = Collections.unmodifiableList(optionSources); - } - } - - protected FieldInfoWithOptions(int fieldSource, int fieldType, List optionSources) { - super(fieldSource, fieldType, null); - this.noCurrentSelectedKey = FlexibleStringExpander.getInstance(""); - this.optionSources = Collections.unmodifiableList(new ArrayList(optionSources)); - } - - public FieldInfoWithOptions(int fieldSource, int fieldType, ModelFormField modelFormField) { - super(fieldSource, fieldType, modelFormField); - this.noCurrentSelectedKey = FlexibleStringExpander.getInstance(""); - this.optionSources = Collections.emptyList(); - } - - public List getAllOptionValues(Map context, Delegator delegator) { - List optionValues = new LinkedList(); - for (OptionSource optionSource : this.optionSources) { - optionSource.addOptionValues(optionValues, context, delegator); - } - return optionValues; - } - - public FlexibleStringExpander getNoCurrentSelectedKey() { - return noCurrentSelectedKey; - } - - public String getNoCurrentSelectedKey(Map context) { - return this.noCurrentSelectedKey.expandString(context); - } - - public List getOptionSources() { - return optionSources; - } - } - - /** - * Models the <file> element. - * - * @see widget-form.xsd - */ - public static class FileField extends TextField { - - public FileField(Element element, ModelFormField modelFormField) { - super(element, modelFormField); - } - - private FileField(FileField original, ModelFormField modelFormField) { - super(original, modelFormField); - } - - public FileField(int fieldSource, ModelFormField modelFormField) { - super(fieldSource, modelFormField); - } - - @Override - public void accept(ModelFieldVisitor visitor) throws Exception { - visitor.visit(this); - } - - @Override - public FieldInfo copy(ModelFormField modelFormField) { - return new FileField(this, modelFormField); - } - - @Override - public void renderFieldString(Appendable writer, Map context, FormStringRenderer formStringRenderer) - throws IOException { - formStringRenderer.renderFileField(writer, context, this); - } - } - - /** - * Models the <hidden> element. - * - * @see widget-form.xsd - */ - public static class HiddenField extends FieldInfo { - private final FlexibleStringExpander value; - - public HiddenField(Element element, ModelFormField modelFormField) { - super(element, modelFormField); - this.value = FlexibleStringExpander.getInstance(element.getAttribute("value")); - } - - private HiddenField(HiddenField original, ModelFormField modelFormField) { - super(original.getFieldSource(), original.getFieldType(), modelFormField); - this.value = original.value; - } - - public HiddenField(int fieldSource, ModelFormField modelFormField) { - super(fieldSource, FieldInfo.HIDDEN, modelFormField); - this.value = FlexibleStringExpander.getInstance(""); - } - - public HiddenField(ModelFormField modelFormField) { - super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.HIDDEN, modelFormField); - this.value = FlexibleStringExpander.getInstance(""); - } - - @Override - public void accept(ModelFieldVisitor visitor) throws Exception { - visitor.visit(this); - } - - @Override - public FieldInfo copy(ModelFormField modelFormField) { - return new HiddenField(this, modelFormField); - } - - public FlexibleStringExpander getValue() { - return value; - } - - public String getValue(Map context) { - if (UtilValidate.isNotEmpty(this.value)) { - String valueEnc = this.value.expandString(context); - UtilCodec.SimpleEncoder simpleEncoder = (UtilCodec.SimpleEncoder) context.get("simpleEncoder"); - if (simpleEncoder != null) { - valueEnc = simpleEncoder.encode(valueEnc); - } - return valueEnc; - } else { - return getModelFormField().getEntry(context); - } - } - - @Override - public void renderFieldString(Appendable writer, Map context, FormStringRenderer formStringRenderer) - throws IOException { - formStringRenderer.renderHiddenField(writer, context, this); - } - } - - /** - * Models the <hyperlink> element. - * - * @see widget-form.xsd - */ - public static class HyperlinkField extends FieldInfo { - - private final boolean alsoHidden; - private final FlexibleStringExpander confirmationMsgExdr; - private final FlexibleStringExpander description; - private final boolean requestConfirmation; - private final Link link; - public HyperlinkField(Element element, ModelFormField modelFormField) { - super(element, modelFormField); - this.alsoHidden = !"false".equals(element.getAttribute("also-hidden")); - this.confirmationMsgExdr = FlexibleStringExpander.getInstance(element.getAttribute("confirmation-message")); - this.description = FlexibleStringExpander.getInstance(element.getAttribute("description")); - this.requestConfirmation = "true".equals(element.getAttribute("request-confirmation")); - this.link = new Link(element); - } - - private HyperlinkField(HyperlinkField original, ModelFormField modelFormField) { - super(original.getFieldSource(), original.getFieldType(), modelFormField); - this.alsoHidden = original.alsoHidden; - this.confirmationMsgExdr = original.confirmationMsgExdr; - this.description = original.description; - this.requestConfirmation = original.requestConfirmation; - this.link = original.link; - } - - @Override - public void accept(ModelFieldVisitor visitor) throws Exception { - visitor.visit(this); - } - - @Override - public FieldInfo copy(ModelFormField modelFormField) { - return new HyperlinkField(this, modelFormField); - } - - public boolean getAlsoHidden() { - return this.alsoHidden; - } - - public String getConfirmation(Map context) { - String message = getConfirmationMsg(context); - if (UtilValidate.isNotEmpty(message)) - return message; - if (getRequestConfirmation()) { - String defaultMessage = UtilProperties.getPropertyValue("general", "default.confirmation.message", - "${uiLabelMap.CommonConfirm}"); - return FlexibleStringExpander.expandString(defaultMessage, context); - } - return ""; - } - - public String getAlternate(Map context) { - if (link.getImage() != null) { - return link.getImage().getAlt(context); - } - return ""; - } - - public String getImageTitle(Map context) { - if (link.getImage() != null) { - return link.getImage().getTitleExdr().expandString(context); - } - return ""; - } - - public String getImageLocation(Map context) { - if (link.getImage() != null) { - return link.getImage().getSrc(context); - } - return ""; - } - - public String getConfirmationMsg(Map context) { - return this.confirmationMsgExdr.expandString(context); - } - - public FlexibleStringExpander getConfirmationMsgExdr() { - return confirmationMsgExdr; - } - - public FlexibleStringExpander getDescription() { - return description; - } - - public String getDescription(Map context) { - return this.description.expandString(context); - } - - public boolean getRequestConfirmation() { - return this.requestConfirmation; - } - - public Link getLink() { - return link; - } - - public AutoEntityParameters getAutoEntityParameters() { - return link.getAutoEntityParameters(); - } - - public AutoServiceParameters getAutoServiceParameters() { - return link.getAutoServiceParameters(); - } - - public boolean getEncode() { - return link.getEncode(); - } - - public boolean getFullPath() { - return link.getFullPath(); - } - - public String getHeight() { - return link.getHeight(); - } - - public String getId(Map context) { - return link.getId(context); - } - - public FlexibleStringExpander getIdExdr() { - return link.getIdExdr(); - } - - public Image getImage() { - return link.getImage(); - } - - public String getLinkType() { - return link.getLinkType(); - } - - public String getName() { - return link.getName(); - } - - public String getName(Map context) { - return link.getName(context); - } - - public FlexibleStringExpander getNameExdr() { - return link.getNameExdr(); - } - - public List getParameterList() { - return link.getParameterList(); - } - - public Map getParameterMap(Map context) { - return link.getParameterMap(context); - } - - public String getPrefix(Map context) { - return link.getPrefix(context); - } - - public FlexibleStringExpander getPrefixExdr() { - return link.getPrefixExdr(); - } - - public boolean getSecure() { - return link.getSecure(); - } - - public Integer getSize() { - return link.getSize(); - } - - public String getStyle(Map context) { - return link.getStyle(context); - } - - public FlexibleStringExpander getStyleExdr() { - return link.getStyleExdr(); - } - - public String getTarget(Map context) { - return link.getTarget(context); - } - - public FlexibleStringExpander getTargetExdr() { - return link.getTargetExdr(); - } - - public String getTargetWindow(Map context) { - return link.getTargetWindow(context); - } - - public FlexibleStringExpander getTargetWindowExdr() { - return link.getTargetWindowExdr(); - } - - public String getText(Map context) { - return link.getText(context); - } - - public FlexibleStringExpander getTextExdr() { - return link.getTextExdr(); - } - - public String getUrlMode() { - return link.getUrlMode(); - } - - public String getWidth() { - return link.getWidth(); - } - - @Override - public void renderFieldString(Appendable writer, Map context, FormStringRenderer formStringRenderer) - throws IOException { - formStringRenderer.renderHyperlinkField(writer, context, this); - } - } - - /** - * Models the <ignored> element. - * - * @see widget-form.xsd - */ - public static class IgnoredField extends FieldInfo { - - public IgnoredField(Element element, ModelFormField modelFormField) { - super(element, modelFormField); - } - - private IgnoredField(IgnoredField original, ModelFormField modelFormField) { - super(original.getFieldSource(), original.getFieldType(), modelFormField); - } - - public IgnoredField(int fieldSource, ModelFormField modelFormField) { - super(fieldSource, FieldInfo.IGNORED, modelFormField); - } - - public IgnoredField(ModelFormField modelFormField) { - super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.IGNORED, modelFormField); - } - - @Override - public void accept(ModelFieldVisitor visitor) throws Exception { - visitor.visit(this); - } - - @Override - public FieldInfo copy(ModelFormField modelFormField) { - return new IgnoredField(this, modelFormField); - } - - @Override - public void renderFieldString(Appendable writer, Map context, FormStringRenderer formStringRenderer) - throws IOException { - formStringRenderer.renderIgnoredField(writer, context, this); - } - } - - /** - * Models the <image> element. - * - * @see widget-form.xsd - */ - public static class ImageField extends FieldInfo { - private final FlexibleStringExpander alternate; - private final FlexibleStringExpander defaultValue; - private final FlexibleStringExpander description; - private final FlexibleStringExpander style; - private final SubHyperlink subHyperlink; - private final FlexibleStringExpander value; - - public ImageField(Element element, ModelFormField modelFormField) { - super(element, modelFormField); - this.alternate = FlexibleStringExpander.getInstance(element.getAttribute("alternate")); - this.defaultValue = FlexibleStringExpander.getInstance(element.getAttribute("default-value")); - this.description = FlexibleStringExpander.getInstance(element.getAttribute("description")); - this.style = FlexibleStringExpander.getInstance(element.getAttribute("style")); - Element subHyperlinkElement = UtilXml.firstChildElement(element, "sub-hyperlink"); - if (subHyperlinkElement != null) { - this.subHyperlink = new SubHyperlink(subHyperlinkElement, modelFormField); - } else { - this.subHyperlink = null; - } - this.value = FlexibleStringExpander.getInstance(element.getAttribute("value")); - } - - public ImageField(ImageField original, ModelFormField modelFormField) { - super(original.getFieldSource(), original.getFieldType(), modelFormField); - this.alternate = original.alternate; - this.defaultValue = original.defaultValue; - this.description = original.description; - this.style = original.style; - if (original.subHyperlink != null) { - this.subHyperlink = new SubHyperlink(original.subHyperlink, modelFormField); - } else { - this.subHyperlink = null; - } - this.value = original.value; - } - - public ImageField(int fieldSource, ModelFormField modelFormField) { - super(fieldSource, FieldInfo.IMAGE, modelFormField); - this.alternate = FlexibleStringExpander.getInstance(""); - this.defaultValue = FlexibleStringExpander.getInstance(""); - this.description = FlexibleStringExpander.getInstance(""); - this.style = FlexibleStringExpander.getInstance(""); - this.subHyperlink = null; - this.value = FlexibleStringExpander.getInstance(""); - } - - public ImageField(ModelFormField modelFormField) { - this(FieldInfo.SOURCE_EXPLICIT, modelFormField); - } - - @Override - public void accept(ModelFieldVisitor visitor) throws Exception { - visitor.visit(this); - } - - @Override - public FieldInfo copy(ModelFormField modelFormField) { - return new ImageField(this, modelFormField); - } - - public FlexibleStringExpander getAlternate() { - return alternate; - } - - public String getAlternate(Map context) { - if (UtilValidate.isNotEmpty(this.alternate)) - return this.alternate.expandString(context); - return ""; - } - - public FlexibleStringExpander getDefaultValue() { - return defaultValue; - } - - public String getDefaultValue(Map context) { - if (this.defaultValue != null) { - return this.defaultValue.expandString(context); - } else { - return ""; - } - } - - public FlexibleStringExpander getDescription() { - return description; - } - - public String getDescription(Map context) { - if (UtilValidate.isNotEmpty(this.description)) - return this.description.expandString(context); - return ""; - } - - public FlexibleStringExpander getStyle() { - return style; - } - - public String getStyle(Map context) { - if (UtilValidate.isNotEmpty(this.style)) - return this.style.expandString(context); - return ""; - } - - public SubHyperlink getSubHyperlink() { - return this.subHyperlink; - } - - public FlexibleStringExpander getValue() { - return value; - } - - public String getValue(Map context) { - if (UtilValidate.isNotEmpty(this.value)) - return this.value.expandString(context); - return getModelFormField().getEntry(context); - } - - @Override - public void renderFieldString(Appendable writer, Map context, FormStringRenderer formStringRenderer) - throws IOException { - formStringRenderer.renderImageField(writer, context, this); - } - } - - /** - * Models the <in-place-editor> element. - * - * @see widget-form.xsd - */ - public static class InPlaceEditor { - private final String cancelControl; - private final String cancelText; - private final String clickToEditText; - private final String cols; - private final Map, Object> fieldMap; - private final String fieldPostCreation; - private final String formClassName; - private final String highlightColor; - private final String highlightEndColor; - private final String hoverClassName; - private final String htmlResponse; - private final String loadingClassName; - private final String loadingText; - private final String okControl; - private final String okText; - private final String paramName; - private final String rows; - private final String savingClassName; - private final String savingText; - private final String submitOnBlur; - private final String textAfterControls; - private final String textBeforeControls; - private final String textBetweenControls; - private final String updateAfterRequestCall; - private final FlexibleStringExpander url; - - public InPlaceEditor(Element element) { - this.cancelControl = element.getAttribute("cancel-control"); - this.cancelText = element.getAttribute("cancel-text"); - this.clickToEditText = element.getAttribute("click-to-edit-text"); - this.fieldPostCreation = element.getAttribute("field-post-creation"); - this.formClassName = element.getAttribute("form-class-name"); - this.highlightColor = element.getAttribute("highlight-color"); - this.highlightEndColor = element.getAttribute("highlight-end-color"); - this.hoverClassName = element.getAttribute("hover-class-name"); - this.htmlResponse = element.getAttribute("html-response"); - this.loadingClassName = element.getAttribute("loading-class-name"); - this.loadingText = element.getAttribute("loading-text"); - this.okControl = element.getAttribute("ok-control"); - this.okText = element.getAttribute("ok-text"); - this.paramName = element.getAttribute("param-name"); - this.savingClassName = element.getAttribute("saving-class-name"); - this.savingText = element.getAttribute("saving-text"); - this.submitOnBlur = element.getAttribute("submit-on-blur"); - this.textBeforeControls = element.getAttribute("text-before-controls"); - this.textAfterControls = element.getAttribute("text-after-controls"); - this.textBetweenControls = element.getAttribute("text-between-controls"); - this.updateAfterRequestCall = element.getAttribute("update-after-request-call"); - Element simpleElement = UtilXml.firstChildElement(element, "simple-editor"); - if (simpleElement != null) { - this.rows = simpleElement.getAttribute("rows"); - this.cols = simpleElement.getAttribute("cols"); - } else { - this.rows = ""; - this.cols = ""; - } - this.fieldMap = EntityFinderUtil.makeFieldMap(element); - this.url = FlexibleStringExpander.getInstance(element.getAttribute("url")); - } - - public String getCancelControl() { - return this.cancelControl; - } - - public String getCancelText() { - return this.cancelText; - } - - public String getClickToEditText() { - return this.clickToEditText; - } - - public String getCols() { - return this.cols; - } - - public Map, Object> getFieldMap() { - return fieldMap; - } - - public Map getFieldMap(Map context) { - Map inPlaceEditorContext = new HashMap(); - EntityFinderUtil.expandFieldMapToContext(this.fieldMap, context, inPlaceEditorContext); - return inPlaceEditorContext; - } - - public String getFieldPostCreation() { - return this.fieldPostCreation; - } - - public String getFormClassName() { - return this.formClassName; - } - - public String getHighlightColor() { - return this.highlightColor; - } - - public String getHighlightEndColor() { - return this.highlightEndColor; - } - - public String getHoverClassName() { - return this.hoverClassName; - } - - public String getHtmlResponse() { - return this.htmlResponse; - } - - public String getLoadingClassName() { - return this.loadingClassName; - } - - public String getLoadingText() { - return this.loadingText; - } - - public String getOkControl() { - return this.okControl; - } - - public String getOkText() { - return this.okText; - } - - public String getParamName() { - return this.paramName; - } - - public String getRows() { - return this.rows; - } - - public String getSavingClassName() { - return this.savingClassName; - } - - public String getSavingText() { - return this.savingText; - } - - public String getSubmitOnBlur() { - return this.submitOnBlur; - } - - public String getTextAfterControls() { - return this.textAfterControls; - } - - public String getTextBeforeControls() { - return this.textBeforeControls; - } - - public String getTextBetweenControls() { - return this.textBetweenControls; - } - - public String getUpdateAfterRequestCall() { - return this.updateAfterRequestCall; - } - - public FlexibleStringExpander getUrl() { - return url; - } - - public String getUrl(Map context) { - if (this.url != null) { - return this.url.expandString(context); - } else { - return ""; - } - } - } - - /** - * Models the <list-options> element. - * - * @see widget-form.xsd - */ - public static class ListOptions extends OptionSource { - private final FlexibleStringExpander description; - private final FlexibleMapAccessor keyAcsr; - private final FlexibleMapAccessor> listAcsr; - private final String listEntryName; - - public ListOptions(Element optionElement, ModelFormField modelFormField) { - super(modelFormField); - this.listEntryName = optionElement.getAttribute("list-entry-name"); - this.keyAcsr = FlexibleMapAccessor.getInstance(optionElement.getAttribute("key-name")); - this.listAcsr = FlexibleMapAccessor.getInstance(optionElement.getAttribute("list-name")); - this.description = FlexibleStringExpander.getInstance(optionElement.getAttribute("description")); - } - - private ListOptions(ListOptions original, ModelFormField modelFormField) { - super(modelFormField); - this.listAcsr = original.listAcsr; - this.listEntryName = original.listEntryName; - this.keyAcsr = original.keyAcsr; - this.description = original.description; - } - - public ListOptions(String listName, String listEntryName, String keyName, String description, - ModelFormField modelFormField) { - super(modelFormField); - this.listAcsr = FlexibleMapAccessor.getInstance(listName); - this.listEntryName = listEntryName; - this.keyAcsr = FlexibleMapAccessor.getInstance(keyName); - this.description = FlexibleStringExpander.getInstance(description); - } - - @Override - public void addOptionValues(List optionValues, Map context, Delegator delegator) { - List dataList = UtilGenerics.checkList(this.listAcsr.get(context)); - if (dataList != null && dataList.size() != 0) { - for (Object data : dataList) { - Map localContext = new HashMap(); - localContext.putAll(context); - if (UtilValidate.isNotEmpty(this.listEntryName)) { - localContext.put(this.listEntryName, data); - } else { - Map dataMap = UtilGenerics.checkMap(data); - localContext.putAll(dataMap); - } - Object keyObj = keyAcsr.get(localContext); - String key = null; - if (keyObj instanceof String) { - key = (String) keyObj; - } else { - try { - key = (String) ObjectType.simpleTypeConvert(keyObj, "String", null, null); - } catch (GeneralException e) { - String errMsg = "Could not convert field value for the field: [" + this.keyAcsr.toString() - + "] to String for the value [" + keyObj + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - } - } - optionValues.add(new OptionValue(key, description.expandString(localContext))); - } - } - } - - @Override - public OptionSource copy(ModelFormField modelFormField) { - return new ListOptions(this, modelFormField); - } - - public FlexibleStringExpander getDescription() { - return description; - } - - public FlexibleMapAccessor getKeyAcsr() { - return keyAcsr; - } - - public FlexibleMapAccessor> getListAcsr() { - return listAcsr; - } - - public String getListEntryName() { - return listEntryName; - } - } - - /** - * Models the <lookup> element. - * - * @see widget-form.xsd - */ - public static class LookupField extends TextField { - private final String descriptionFieldName; - private final String fadeBackground; - private final FlexibleStringExpander formName; - private final String initiallyCollapsed; - private final String lookupHeight; - private final String lookupPosition; - private final String lookupPresentation; - private final String lookupWidth; - private final String showDescription; - private final String targetParameter; - - public LookupField(Element element, ModelFormField modelFormField) { - super(element, modelFormField); - this.descriptionFieldName = element.getAttribute("description-field-name"); - this.fadeBackground = element.getAttribute("fade-background"); - this.formName = FlexibleStringExpander.getInstance(element.getAttribute("target-form-name")); - this.initiallyCollapsed = element.getAttribute("initially-collapsed"); - this.lookupHeight = element.getAttribute("height"); - this.lookupPosition = element.getAttribute("position"); - this.lookupPresentation = element.getAttribute("presentation"); - this.lookupWidth = element.getAttribute("width"); - this.showDescription = element.getAttribute("show-description"); - this.targetParameter = element.getAttribute("target-parameter"); - } - - public LookupField(int fieldSource, ModelFormField modelFormField) { - super(fieldSource, modelFormField); - this.descriptionFieldName = ""; - this.fadeBackground = ""; - this.formName = FlexibleStringExpander.getInstance(""); - this.initiallyCollapsed = ""; - this.lookupHeight = ""; - this.lookupPosition = ""; - this.lookupPresentation = ""; - this.lookupWidth = ""; - this.showDescription = ""; - this.targetParameter = ""; - } - - public LookupField(LookupField original, ModelFormField modelFormField) { - super(original, modelFormField); - this.descriptionFieldName = original.descriptionFieldName; - this.fadeBackground = original.fadeBackground; - this.formName = original.formName; - this.initiallyCollapsed = original.initiallyCollapsed; - this.lookupHeight = original.lookupHeight; - this.lookupPosition = original.lookupPosition; - this.lookupPresentation = original.lookupPresentation; - this.lookupWidth = original.lookupWidth; - this.showDescription = original.showDescription; - this.targetParameter = original.targetParameter; - } - - @Override - public void accept(ModelFieldVisitor visitor) throws Exception { - visitor.visit(this); - } - - @Override - public FieldInfo copy(ModelFormField modelFormField) { - return new LookupField(this, modelFormField); - } - - public String getDescriptionFieldName() { - return this.descriptionFieldName; - } - - public String getFadeBackground() { - return this.fadeBackground; - } - - public FlexibleStringExpander getFormName() { - return formName; - } - - public String getFormName(Map context) { - return this.formName.expandString(context); - } - - //initially-collapsed status - public boolean getInitiallyCollapsed() { - return "true".equals(this.initiallyCollapsed); - } - - public String getLookupHeight() { - return this.lookupHeight; - } - - public String getLookupPosition() { - return this.lookupPosition; - } - - public String getLookupPresentation() { - return this.lookupPresentation; - } - - public String getLookupWidth() { - return this.lookupWidth; - } - - public Boolean getShowDescription() { - return UtilValidate.isEmpty(this.showDescription) ? null : "true".equals(this.showDescription); - } - - public String getTargetParameter() { - return targetParameter; - } - - public List getTargetParameterList() { - List paramList = new LinkedList(); - if (UtilValidate.isNotEmpty(this.targetParameter)) { - StringTokenizer stk = new StringTokenizer(this.targetParameter, ", "); - while (stk.hasMoreTokens()) { - paramList.add(stk.nextToken()); - } - } - return paramList; - } - - @Override - public void renderFieldString(Appendable writer, Map context, FormStringRenderer formStringRenderer) - throws IOException { - formStringRenderer.renderLookupField(writer, context, this); - } - } - - public static abstract class OptionSource { - - private final ModelFormField modelFormField; - - protected OptionSource(ModelFormField modelFormField) { - this.modelFormField = modelFormField; - } - - public abstract void addOptionValues(List optionValues, Map context, Delegator delegator); - - public abstract OptionSource copy(ModelFormField modelFormField); - - public ModelFormField getModelFormField() { - return modelFormField; - } - } - - public static class OptionValue { - private final String description; - private final String key; - - public OptionValue(String key, String description) { - this.key = key; - this.description = description; - } - - public String getDescription() { - return description; - } - - public String getKey() { - return key; - } - } - - /** - * Models the <password> element. - * - * @see widget-form.xsd - */ - public static class PasswordField extends TextField { - - public PasswordField(Element element, ModelFormField modelFormField) { - super(element, modelFormField); - } - - public PasswordField(int fieldSource, ModelFormField modelFormField) { - super(fieldSource, modelFormField); - } - - private PasswordField(PasswordField original, ModelFormField modelFormField) { - super(original, modelFormField); - } - - @Override - public void accept(ModelFieldVisitor visitor) throws Exception { - visitor.visit(this); - } - - @Override - public FieldInfo copy(ModelFormField modelFormField) { - return new PasswordField(this, modelFormField); - } - - @Override - public void renderFieldString(Appendable writer, Map context, FormStringRenderer formStringRenderer) - throws IOException { - formStringRenderer.renderPasswordField(writer, context, this); - } - } - - /** - * Models the <radio> element. - * - * @see widget-form.xsd - */ - public static class RadioField extends FieldInfoWithOptions { - - public RadioField(Element element, ModelFormField modelFormField) { - super(element, modelFormField); - } - - public RadioField(int fieldSource, ModelFormField modelFormField) { - super(fieldSource, FieldInfo.RADIO, modelFormField); - } - - public RadioField(ModelFormField modelFormField) { - super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.RADIO, modelFormField); - } - - private RadioField(RadioField original, ModelFormField modelFormField) { - super(original, modelFormField); - } - - @Override - public void accept(ModelFieldVisitor visitor) throws Exception { - visitor.visit(this); - } - - @Override - public FieldInfo copy(ModelFormField modelFormField) { - return new RadioField(this, modelFormField); - } - - @Override - public void renderFieldString(Appendable writer, Map context, FormStringRenderer formStringRenderer) - throws IOException { - formStringRenderer.renderRadioField(writer, context, this); - } - } - - /** - * Models the <range-find> element. - * - * @see widget-form.xsd - */ - public static class RangeFindField extends TextField { - private final String defaultOptionFrom; - private final String defaultOptionThru; - - public RangeFindField(Element element, ModelFormField modelFormField) { - super(element, modelFormField); - this.defaultOptionFrom = element.getAttribute("default-option-from"); - this.defaultOptionThru = element.getAttribute("default-option-thru"); - } - - public RangeFindField(int fieldSource, int size, ModelFormField modelFormField) { - super(fieldSource, size, null, modelFormField); - this.defaultOptionFrom = "greaterThanEqualTo"; - this.defaultOptionThru = "lessThanEqualTo"; - } - - private RangeFindField(RangeFindField original, ModelFormField modelFormField) { - super(original, modelFormField); - this.defaultOptionFrom = original.defaultOptionFrom; - this.defaultOptionThru = original.defaultOptionThru; - } - - @Override - public void accept(ModelFieldVisitor visitor) throws Exception { - visitor.visit(this); - } - - @Override - public FieldInfo copy(ModelFormField modelFormField) { - return new RangeFindField(this, modelFormField); - } - - public String getDefaultOptionFrom() { - return this.defaultOptionFrom; - } - - public String getDefaultOptionThru() { - return this.defaultOptionThru; - } - - @Override - public void renderFieldString(Appendable writer, Map context, FormStringRenderer formStringRenderer) - throws IOException { - formStringRenderer.renderRangeFindField(writer, context, this); - } - } - - /** - * Models the <reset> element. - * - * @see widget-form.xsd - */ - public static class ResetField extends FieldInfo { - - public ResetField(Element element, ModelFormField modelFormField) { - super(element, modelFormField); - } - - public ResetField(int fieldSource, ModelFormField modelFormField) { - super(fieldSource, FieldInfo.RESET, modelFormField); - } - - public ResetField(ModelFormField modelFormField) { - super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.RESET, modelFormField); - } - - private ResetField(ResetField original, ModelFormField modelFormField) { - super(original.getFieldSource(), original.getFieldType(), modelFormField); - } - - @Override - public void accept(ModelFieldVisitor visitor) throws Exception { - visitor.visit(this); - } - - @Override - public FieldInfo copy(ModelFormField modelFormField) { - return new ResetField(this, modelFormField); - } - - @Override - public void renderFieldString(Appendable writer, Map context, FormStringRenderer formStringRenderer) - throws IOException { - formStringRenderer.renderResetField(writer, context, this); - } - } - - /** - * Models the <option> element. - * - * @see widget-form.xsd - */ - public static class SingleOption extends OptionSource { - private final FlexibleStringExpander description; - private final FlexibleStringExpander key; - - public SingleOption(Element optionElement, ModelFormField modelFormField) { - super(modelFormField); - this.key = FlexibleStringExpander.getInstance(optionElement.getAttribute("key")); - this.description = FlexibleStringExpander.getInstance(UtilXml.checkEmpty(optionElement.getAttribute("description"), - optionElement.getAttribute("key"))); - } - - private SingleOption(SingleOption original, ModelFormField modelFormField) { - super(modelFormField); - this.key = original.key; - this.description = original.description; - } - - public SingleOption(String key, String description, ModelFormField modelFormField) { - super(modelFormField); - this.key = FlexibleStringExpander.getInstance(key); - this.description = FlexibleStringExpander.getInstance(UtilXml.checkEmpty(description, key)); - } - - @Override - public void addOptionValues(List optionValues, Map context, Delegator delegator) { - optionValues.add(new OptionValue(key.expandString(context), description.expandString(context))); - } - - @Override - public OptionSource copy(ModelFormField modelFormField) { - return new SingleOption(this, modelFormField); - } - - public FlexibleStringExpander getDescription() { - return description; - } - - public FlexibleStringExpander getKey() { - return key; - } - } - - /** - * Models the <sub-hyperlink> element. - * - * @see widget-form.xsd - */ - public static class SubHyperlink { - private final FlexibleStringExpander description; - private final FlexibleStringExpander useWhen; - private final Link link; - private final ModelFormField modelFormField; - - public SubHyperlink(Element element, ModelFormField modelFormField) { - this.description = FlexibleStringExpander.getInstance(element.getAttribute("description")); - this.useWhen = FlexibleStringExpander.getInstance(element.getAttribute("use-when")); - this.link = new Link(element); - this.modelFormField = modelFormField; - } - - public SubHyperlink(SubHyperlink original, ModelFormField modelFormField) { - this.description = original.description; - this.useWhen = original.useWhen; - this.link = original.link; - this.modelFormField = modelFormField; - } - - public AutoEntityParameters getAutoEntityParameters() { - return link.getAutoEntityParameters(); - } - - public AutoServiceParameters getAutoServiceParameters() { - return link.getAutoServiceParameters(); - } - - public boolean getEncode() { - return link.getEncode(); - } - - public boolean getFullPath() { - return link.getFullPath(); - } - - public String getHeight() { - return link.getHeight(); - } - - public String getId(Map context) { - return link.getId(context); - } - - public FlexibleStringExpander getIdExdr() { - return link.getIdExdr(); - } - - public Image getImage() { - return link.getImage(); - } - - public String getLinkType() { - return link.getLinkType(); - } - - public String getName() { - return link.getName(); - } - - public String getName(Map context) { - return link.getName(context); - } - - public FlexibleStringExpander getNameExdr() { - return link.getNameExdr(); - } - - public List getParameterList() { - return link.getParameterList(); - } - - public Map getParameterMap(Map context) { - return link.getParameterMap(context); - } - - public String getPrefix(Map context) { - return link.getPrefix(context); - } - - public FlexibleStringExpander getPrefixExdr() { - return link.getPrefixExdr(); - } - - public boolean getSecure() { - return link.getSecure(); - } - - public Integer getSize() { - return link.getSize(); - } - - public String getStyle(Map context) { - return link.getStyle(context); - } - - public FlexibleStringExpander getStyleExdr() { - return link.getStyleExdr(); - } - - public String getTarget(Map context) { - return link.getTarget(context); - } - - public FlexibleStringExpander getTargetExdr() { - return link.getTargetExdr(); - } - - public String getTargetWindow(Map context) { - return link.getTargetWindow(context); - } - - public FlexibleStringExpander getTargetWindowExdr() { - return link.getTargetWindowExdr(); - } - - public String getText(Map context) { - return link.getText(context); - } - - public FlexibleStringExpander getTextExdr() { - return link.getTextExdr(); - } - - public String getUrlMode() { - return link.getUrlMode(); - } - - public String getWidth() { - return link.getWidth(); - } - - public FlexibleStringExpander getDescription() { - return description; - } - - public String getDescription(Map context) { - return description.expandString(context); - } - - public FlexibleStringExpander getUseWhen() { - return useWhen; - } - - public Link getLink() { - return link; - } - - public String getUseWhen(Map context) { - return this.useWhen.expandString(context); - } - - public ModelFormField getModelFormField() { - return modelFormField; - } - - public boolean shouldUse(Map context) { - boolean shouldUse = true; - String useWhen = this.getUseWhen(context); - if (UtilValidate.isNotEmpty(useWhen)) { - try { - Interpreter bsh = (Interpreter) context.get("bshInterpreter"); - if (bsh == null) { - bsh = BshUtil.makeInterpreter(context); - context.put("bshInterpreter", bsh); - } - - Object retVal = bsh.eval(StringUtil.convertOperatorSubstitutions(useWhen)); - - // retVal should be a Boolean, if not something weird is up... - if (retVal instanceof Boolean) { - Boolean boolVal = (Boolean) retVal; - shouldUse = boolVal.booleanValue(); - } else { - throw new IllegalArgumentException("Return value from target condition eval was not a Boolean: " - + retVal.getClass().getName() + " [" + retVal + "]"); - } - } catch (EvalError e) { - String errmsg = "Error evaluating BeanShell target conditions"; - Debug.logError(e, errmsg, module); - throw new IllegalArgumentException(errmsg); - } - } - return shouldUse; - } - } - - /** - * Models the <submit> element. - * - * @see widget-form.xsd - */ - public static class SubmitField extends FieldInfo { - private final FlexibleStringExpander backgroundSubmitRefreshTargetExdr; - private final String buttonType; - private final FlexibleStringExpander confirmationMsgExdr; - private final FlexibleStringExpander imageLocation; - private final boolean requestConfirmation; - - public SubmitField(Element element, ModelFormField modelFormField) { - super(element, modelFormField); - this.backgroundSubmitRefreshTargetExdr = FlexibleStringExpander.getInstance(element - .getAttribute("background-submit-refresh-target")); - this.buttonType = element.getAttribute("button-type"); - this.confirmationMsgExdr = FlexibleStringExpander.getInstance(element.getAttribute("confirmation-message")); - this.imageLocation = FlexibleStringExpander.getInstance(element.getAttribute("image-location")); - this.requestConfirmation = "true".equals(element.getAttribute("request-confirmation")); - } - - public SubmitField(int fieldInfo, ModelFormField modelFormField) { - super(fieldInfo, FieldInfo.SUBMIT, modelFormField); - this.backgroundSubmitRefreshTargetExdr = FlexibleStringExpander.getInstance(""); - this.buttonType = ""; - this.confirmationMsgExdr = FlexibleStringExpander.getInstance(""); - this.imageLocation = FlexibleStringExpander.getInstance(""); - this.requestConfirmation = false; - } - - public SubmitField(ModelFormField modelFormField) { - this(FieldInfo.SOURCE_EXPLICIT, modelFormField); - } - - private SubmitField(SubmitField original, ModelFormField modelFormField) { - super(original.getFieldSource(), original.getFieldType(), modelFormField); - this.buttonType = original.buttonType; - this.imageLocation = original.imageLocation; - this.backgroundSubmitRefreshTargetExdr = original.backgroundSubmitRefreshTargetExdr; - this.requestConfirmation = original.requestConfirmation; - this.confirmationMsgExdr = original.confirmationMsgExdr; - } - - @Override - public void accept(ModelFieldVisitor visitor) throws Exception { - visitor.visit(this); - } - - @Override - public FieldInfo copy(ModelFormField modelFormField) { - return new SubmitField(this, modelFormField); - } - - public String getBackgroundSubmitRefreshTarget(Map context) { - return this.backgroundSubmitRefreshTargetExdr.expandString(context); - } - - public FlexibleStringExpander getBackgroundSubmitRefreshTargetExdr() { - return backgroundSubmitRefreshTargetExdr; - } - - public String getButtonType() { - return buttonType; - } - - public String getConfirmation(Map context) { - String message = getConfirmationMsg(context); - if (UtilValidate.isNotEmpty(message)) - return message; - else if (getRequestConfirmation()) { - String defaultMessage = UtilProperties.getPropertyValue("general", "default.confirmation.message", - "${uiLabelMap.CommonConfirm}"); - return FlexibleStringExpander.expandString(defaultMessage, context); - } - return ""; - } - - public String getConfirmationMsg(Map context) { - return this.confirmationMsgExdr.expandString(context); - } - - public FlexibleStringExpander getConfirmationMsgExdr() { - return confirmationMsgExdr; - } - - public FlexibleStringExpander getImageLocation() { - return imageLocation; - } - - public String getImageLocation(Map context) { - return this.imageLocation.expandString(context); - } - - public boolean getRequestConfirmation() { - return this.requestConfirmation; - } - - @Override - public void renderFieldString(Appendable writer, Map context, FormStringRenderer formStringRenderer) - throws IOException { - formStringRenderer.renderSubmitField(writer, context, this); - } - } - - /** - * Models the <textarea> element. - * - * @see widget-form.xsd - */ - public static class TextareaField extends FieldInfo { - private final int cols; - private final FlexibleStringExpander defaultValue; - private final boolean readOnly; - private final int rows; - private final FlexibleStringExpander visualEditorButtons; - private final boolean visualEditorEnable; - - public TextareaField(Element element, ModelFormField modelFormField) { - super(element, modelFormField); - int cols = 60; - String colsStr = element.getAttribute("cols"); - if (!colsStr.isEmpty()) { - try { - cols = Integer.parseInt(colsStr); - } catch (Exception e) { - if (UtilValidate.isNotEmpty(colsStr)) { - Debug.logError("Could not parse the size value of the text element: [" + colsStr - + "], setting to default of " + cols, module); - } - } - } - this.cols = cols; - this.defaultValue = FlexibleStringExpander.getInstance(element.getAttribute("default-value")); - this.readOnly = "true".equals(element.getAttribute("read-only")); - int rows = 2; - String rowsStr = element.getAttribute("rows"); - if (!rowsStr.isEmpty()) { - try { - rows = Integer.parseInt(rowsStr); - } catch (Exception e) { - if (UtilValidate.isNotEmpty(rowsStr)) { - Debug.logError("Could not parse the size value of the text element: [" + rowsStr - + "], setting to default of " + rows, module); - } - } - } - this.rows = rows; - this.visualEditorButtons = FlexibleStringExpander.getInstance(element.getAttribute("visual-editor-buttons")); - this.visualEditorEnable = "true".equals(element.getAttribute("visual-editor-enable")); - } - - public TextareaField(int fieldSource, ModelFormField modelFormField) { - super(fieldSource, FieldInfo.TEXTAREA, modelFormField); - this.cols = 60; - this.defaultValue = FlexibleStringExpander.getInstance(""); - this.readOnly = false; - this.rows = 2; - this.visualEditorButtons = FlexibleStringExpander.getInstance(""); - this.visualEditorEnable = false; - } - - public TextareaField(ModelFormField modelFormField) { - this(FieldInfo.SOURCE_EXPLICIT, modelFormField); - } - - private TextareaField(TextareaField original, ModelFormField modelFormField) { - super(original.getFieldSource(), original.getFieldType(), modelFormField); - this.defaultValue = original.defaultValue; - this.visualEditorEnable = original.visualEditorEnable; - this.visualEditorButtons = original.visualEditorButtons; - this.readOnly = original.readOnly; - this.cols = original.cols; - this.rows = original.rows; - } - - @Override - public void accept(ModelFieldVisitor visitor) throws Exception { - visitor.visit(this); - } - - @Override - public FieldInfo copy(ModelFormField modelFormField) { - return new TextareaField(this, modelFormField); - } - - public int getCols() { - return cols; - } - - public FlexibleStringExpander getDefaultValue() { - return defaultValue; - } - - public String getDefaultValue(Map context) { - if (this.defaultValue != null) { - return this.defaultValue.expandString(context); - } else { - return ""; - } - } - - public int getRows() { - return rows; - } - - public FlexibleStringExpander getVisualEditorButtons() { - return visualEditorButtons; - } - - public String getVisualEditorButtons(Map context) { - return this.visualEditorButtons.expandString(context); - } - - public boolean getVisualEditorEnable() { - return this.visualEditorEnable; - } - - public boolean isReadOnly() { - return readOnly; - } - - @Override - public void renderFieldString(Appendable writer, Map context, FormStringRenderer formStringRenderer) - throws IOException { - formStringRenderer.renderTextareaField(writer, context, this); - } - } - - /** - * Models the <text> element. - * - * @see widget-form.xsd - */ - public static class TextField extends FieldInfo { - private final boolean clientAutocompleteField; - private final FlexibleStringExpander defaultValue; - private final boolean disabled; - private final String mask; - private final Integer maxlength; - private final FlexibleStringExpander placeholder; - private final boolean readonly; - private final int size; - private final SubHyperlink subHyperlink; - - public TextField(Element element, ModelFormField modelFormField) { - super(element, modelFormField); - this.clientAutocompleteField = !"false".equals(element.getAttribute("client-autocomplete-field")); - this.defaultValue = FlexibleStringExpander.getInstance(element.getAttribute("default-value")); - this.disabled = "true".equals(element.getAttribute("disabled")); - this.mask = element.getAttribute("mask"); - Integer maxlength = null; - String maxlengthStr = element.getAttribute("maxlength"); - if (!maxlengthStr.isEmpty()) { - try { - maxlength = Integer.valueOf(maxlengthStr); - } catch (Exception e) { - Debug.logError("Could not parse the max-length value of the text element: [" + maxlengthStr - + "], setting to null; default of no maxlength will be used", module); - } - } - this.maxlength = maxlength; - this.placeholder = FlexibleStringExpander.getInstance(element.getAttribute("placeholder")); - this.readonly = "true".equals(element.getAttribute("read-only")); - int size = 25; - String sizeStr = element.getAttribute("size"); - if (!sizeStr.isEmpty()) { - try { - size = Integer.parseInt(sizeStr); - } catch (Exception e) { - Debug.logError("Could not parse the size value of the text element: [" + sizeStr - + "], setting to the default of " + size, module); - } - } - this.size = size; - Element subHyperlinkElement = UtilXml.firstChildElement(element, "sub-hyperlink"); - if (subHyperlinkElement != null) { - this.subHyperlink = new SubHyperlink(subHyperlinkElement, this.getModelFormField()); - } else { - this.subHyperlink = null; - } - } - - protected TextField(int fieldSource, int size, Integer maxlength, ModelFormField modelFormField) { - super(fieldSource, FieldInfo.TEXT, modelFormField); - this.clientAutocompleteField = true; - this.defaultValue = FlexibleStringExpander.getInstance(""); - this.disabled = false; - this.mask = ""; - this.maxlength = maxlength; - this.placeholder = FlexibleStringExpander.getInstance(""); - this.readonly = false; - this.size = size; - this.subHyperlink = null; - } - - private TextField(int fieldSource, int fieldType, ModelFormField modelFormField) { - super(fieldSource, fieldType, modelFormField); - this.clientAutocompleteField = true; - this.defaultValue = FlexibleStringExpander.getInstance(""); - this.disabled = false; - this.mask = ""; - this.maxlength = null; - this.placeholder = FlexibleStringExpander.getInstance(""); - this.readonly = false; - this.size = 25; - this.subHyperlink = null; - } - - public TextField(int fieldSource, ModelFormField modelFormField) { - this(fieldSource, FieldInfo.TEXT, modelFormField); - } - - public TextField(ModelFormField modelFormField) { - this(FieldInfo.SOURCE_EXPLICIT, FieldInfo.TEXT, modelFormField); - } - - protected TextField(TextField original, ModelFormField modelFormField) { - super(original.getFieldSource(), original.getFieldType(), modelFormField); - this.clientAutocompleteField = original.clientAutocompleteField; - this.defaultValue = original.defaultValue; - this.mask = original.mask; - this.placeholder = original.placeholder; - this.size = original.size; - this.maxlength = original.maxlength; - this.disabled = original.disabled; - this.readonly = original.readonly; - if (original.subHyperlink != null) { - this.subHyperlink = new SubHyperlink(original.subHyperlink, modelFormField); - } else { - this.subHyperlink = null; - } - } - - @Override - public void accept(ModelFieldVisitor visitor) throws Exception { - visitor.visit(this); - } - - @Override - public FieldInfo copy(ModelFormField modelFormField) { - return new TextField(this, modelFormField); - } - - public boolean getClientAutocompleteField() { - return this.clientAutocompleteField; - } - - public FlexibleStringExpander getDefaultValue() { - return defaultValue; - } - - public String getDefaultValue(Map context) { - if (this.defaultValue != null) { - return this.defaultValue.expandString(context); - } else { - return ""; - } - } - - public boolean getDisabled() { - return this.disabled; - } - - public String getMask() { - return this.mask; - } - - public Integer getMaxlength() { - return maxlength; - } - - public FlexibleStringExpander getPlaceholder() { - return placeholder; - } - - public String getPlaceholder(Map context) { - return this.placeholder.expandString(context); - } - - public boolean getReadonly() { - return this.readonly; - } - - public int getSize() { - return size; - } - - public SubHyperlink getSubHyperlink() { - return this.subHyperlink; - } - - @Override - public void renderFieldString(Appendable writer, Map context, FormStringRenderer formStringRenderer) - throws IOException { - formStringRenderer.renderTextField(writer, context, this); - } - } - - /** - * Models the <text-find> element. - * - * @see widget-form.xsd - */ - public static class TextFindField extends TextField { - private final String defaultOption; - private final boolean hideIgnoreCase; - private final boolean hideOptions; - private final boolean ignoreCase; - - public TextFindField(Element element, ModelFormField modelFormField) { - super(element, modelFormField); - if (element.hasAttribute("default-option")) { - this.defaultOption = element.getAttribute("default-option"); - } else { - this.defaultOption = UtilProperties.getPropertyValue("widget", "widget.form.defaultTextFindOption", "contains"); - } - this.hideIgnoreCase = "true".equals(element.getAttribute("hide-options")) - || "ignore-case".equals(element.getAttribute("hide-options")) ? true : false; - this.hideOptions = "true".equals(element.getAttribute("hide-options")) - || "options".equals(element.getAttribute("hide-options")) ? true : false; - this.ignoreCase = "true".equals(element.getAttribute("ignore-case")); - } - - public TextFindField(int fieldSource, int size, Integer maxlength, ModelFormField modelFormField) { - super(fieldSource, size, maxlength, modelFormField); - this.defaultOption = UtilProperties.getPropertyValue("widget", "widget.form.defaultTextFindOption", "contains"); - this.hideIgnoreCase = false; - this.hideOptions = false; - this.ignoreCase = true; - } - - public TextFindField(int fieldSource, ModelFormField modelFormField) { - super(fieldSource, modelFormField); - this.defaultOption = UtilProperties.getPropertyValue("widget", "widget.form.defaultTextFindOption", "contains"); - this.hideIgnoreCase = false; - this.hideOptions = false; - this.ignoreCase = true; - } - - private TextFindField(TextFindField original, ModelFormField modelFormField) { - super(original, modelFormField); - this.ignoreCase = original.ignoreCase; - this.hideIgnoreCase = original.hideIgnoreCase; - this.defaultOption = original.defaultOption; - this.hideOptions = original.hideOptions; - } - - @Override - public void accept(ModelFieldVisitor visitor) throws Exception { - visitor.visit(this); - } - - @Override - public FieldInfo copy(ModelFormField modelFormField) { - return new TextFindField(this, modelFormField); - } - - public String getDefaultOption() { - return this.defaultOption; - } - - public boolean getHideIgnoreCase() { - return this.hideIgnoreCase; - } - - public boolean getHideOptions() { - return this.hideOptions; - } - - public boolean getIgnoreCase() { - return this.ignoreCase; - } - - @Override - public void renderFieldString(Appendable writer, Map context, FormStringRenderer formStringRenderer) - throws IOException { - formStringRenderer.renderTextFindField(writer, context, this); - } - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.model; + +import java.io.IOException; +import java.math.BigDecimal; +import java.sql.Timestamp; +import java.text.DateFormat; +import java.text.NumberFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.StringTokenizer; +import java.util.TimeZone; + +import org.ofbiz.base.conversion.ConversionException; +import org.ofbiz.base.conversion.DateTimeConverters; +import org.ofbiz.base.conversion.DateTimeConverters.StringToTimestamp; +import org.ofbiz.base.util.BshUtil; +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.GeneralException; +import org.ofbiz.base.util.ObjectType; +import org.ofbiz.base.util.StringUtil; +import org.ofbiz.base.util.UtilCodec; +import org.ofbiz.base.util.UtilDateTime; +import org.ofbiz.base.util.UtilFormatOut; +import org.ofbiz.base.util.UtilGenerics; +import org.ofbiz.base.util.UtilMisc; +import org.ofbiz.base.util.UtilProperties; +import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.base.util.UtilXml; +import org.ofbiz.base.util.collections.FlexibleMapAccessor; +import org.ofbiz.base.util.collections.MapStack; +import org.ofbiz.base.util.string.FlexibleStringExpander; +import org.ofbiz.entity.Delegator; +import org.ofbiz.entity.GenericEntity; +import org.ofbiz.entity.GenericEntityException; +import org.ofbiz.entity.GenericValue; +import org.ofbiz.entity.condition.EntityCondition; +import org.ofbiz.entity.finder.EntityFinderUtil; +import org.ofbiz.entity.model.ModelEntity; +import org.ofbiz.entity.util.EntityUtil; +import org.ofbiz.widget.WidgetWorker; +import org.ofbiz.widget.model.CommonWidgetModels.AutoEntityParameters; +import org.ofbiz.widget.model.CommonWidgetModels.AutoServiceParameters; +import org.ofbiz.widget.model.CommonWidgetModels.Image; +import org.ofbiz.widget.model.CommonWidgetModels.Link; +import org.ofbiz.widget.model.CommonWidgetModels.Parameter; +import org.ofbiz.widget.model.ModelForm.UpdateArea; +import org.ofbiz.widget.renderer.FormStringRenderer; +import org.w3c.dom.Element; + +import bsh.EvalError; +import bsh.Interpreter; + +/** + * Models the <field> element. + * + * @see widget-form.xsd + */ +public class ModelFormField { + + /* + * ----------------------------------------------------------------------- * + * DEVELOPERS PLEASE READ + * ----------------------------------------------------------------------- * + * + * This model is intended to be a read-only data structure that represents + * an XML element. Outside of object construction, the class should not + * have any behaviors. All behavior should be contained in model visitors. + * + * Instances of this class will be shared by multiple threads - therefore + * it is immutable. DO NOT CHANGE THE OBJECT'S STATE AT RUN TIME! + * + */ + + public static final String module = ModelFormField.class.getName(); + + public static ModelFormField from(ModelFormFieldBuilder builder) { + return new ModelFormField(builder); + } + + private final FlexibleStringExpander action; + private final String attributeName; + private final boolean encodeOutput; + private final String entityName; + private final FlexibleMapAccessor entryAcsr; + private final String event; + private final FieldInfo fieldInfo; + private final String fieldName; + private final String headerLink; + private final String headerLinkStyle; + private final String idName; + private final FlexibleMapAccessor> mapAcsr; + private final ModelForm modelForm; + private final String name; + private final List onChangeUpdateAreas; + private final List onClickUpdateAreas; + private final String parameterName; + private final Integer position; + private final String redWhen; + private final Boolean requiredField; + private final String requiredFieldStyle; + private final boolean separateColumn; + private final String serviceName; + private final Boolean sortField; + private final String sortFieldAscStyle; + private final String sortFieldDescStyle; + private final String sortFieldHelpText; + private final String sortFieldStyle; + private final FlexibleStringExpander title; + private final String titleAreaStyle; + private final String titleStyle; + private final FlexibleStringExpander tooltip; + private final String tooltipStyle; + private final FlexibleStringExpander useWhen; + private final String widgetAreaStyle; + private final String widgetStyle; + + private ModelFormField(ModelFormFieldBuilder builder) { + this.action = builder.getAction(); + this.attributeName = builder.getAttributeName(); + this.encodeOutput = builder.getEncodeOutput(); + this.entityName = builder.getEntityName(); + this.entryAcsr = builder.getEntryAcsr(); + this.event = builder.getEvent(); + if (builder.getFieldInfo() != null) { + this.fieldInfo = builder.getFieldInfo().copy(this); + } else { + this.fieldInfo = null; + } + this.fieldName = builder.getFieldName(); + this.headerLink = builder.getHeaderLink(); + this.headerLinkStyle = builder.getHeaderLinkStyle(); + this.idName = builder.getIdName(); + this.mapAcsr = builder.getMapAcsr(); + this.modelForm = builder.getModelForm(); + this.name = builder.getName(); + if (builder.getOnChangeUpdateAreas().isEmpty()) { + this.onChangeUpdateAreas = Collections.emptyList(); + } else { + this.onChangeUpdateAreas = Collections.unmodifiableList(new ArrayList(builder.getOnChangeUpdateAreas())); + } + if (builder.getOnClickUpdateAreas().isEmpty()) { + this.onClickUpdateAreas = Collections.emptyList(); + } else { + this.onClickUpdateAreas = Collections.unmodifiableList(new ArrayList(builder.getOnClickUpdateAreas())); + } + this.parameterName = builder.getParameterName(); + this.position = builder.getPosition(); + this.redWhen = builder.getRedWhen(); + this.requiredField = builder.getRequiredField(); + this.requiredFieldStyle = builder.getRequiredFieldStyle(); + this.separateColumn = builder.getSeparateColumn(); + this.serviceName = builder.getServiceName(); + this.sortField = builder.getSortField(); + this.sortFieldAscStyle = builder.getSortFieldAscStyle(); + this.sortFieldDescStyle = builder.getSortFieldDescStyle(); + this.sortFieldHelpText = builder.getSortFieldHelpText(); + this.sortFieldStyle = builder.getSortFieldStyle(); + this.title = builder.getTitle(); + this.titleAreaStyle = builder.getTitleAreaStyle(); + this.titleStyle = builder.getTitleStyle(); + this.tooltip = builder.getTooltip(); + this.tooltipStyle = builder.getTooltipStyle(); + this.useWhen = builder.getUseWhen(); + this.widgetAreaStyle = builder.getWidgetAreaStyle(); + this.widgetStyle = builder.getWidgetStyle(); + } + + public FlexibleStringExpander getAction() { + return action; + } + + public String getAction(Map context) { + if (UtilValidate.isNotEmpty(this.action)) + return action.expandString(context); + return null; + } + + /** + * Gets the name of the Service Attribute (aka Parameter) that corresponds + * with this field. This can be used to get additional information about the field. + * Use the getServiceName() method to get the Entity name that the field is in. + * + * @return returns the name of the Service Attribute + */ + public String getAttributeName() { + if (UtilValidate.isNotEmpty(this.attributeName)) + return this.attributeName; + return this.name; + } + + public String getCurrentContainerId(Map context) { + ModelForm modelForm = this.getModelForm(); + String idName = FlexibleStringExpander.expandString(this.getIdName(), context); + + if (modelForm != null) { + Integer itemIndex = (Integer) context.get("itemIndex"); + if ("list".equals(modelForm.getType()) || "multi".equals(modelForm.getType())) { + if (itemIndex != null) { + return idName + modelForm.getItemIndexSeparator() + itemIndex.intValue(); + } + } + } + return idName; + } + + public boolean getEncodeOutput() { + return this.encodeOutput; + } + + public String getEntityName() { + if (UtilValidate.isNotEmpty(this.entityName)) + return this.entityName; + return this.modelForm.getDefaultEntityName(); + } + + /** + * Gets the entry from the context that corresponds to this field; if this + * form is being rendered in an error condition (ie isError in the context + * is true) then the value will be retrieved from the parameters Map in + * the context. + * + * @param context the context + * @return returns the entry from the context that corresponds to this field + */ + public String getEntry(Map context) { + return this.getEntry(context, ""); + } + + public String getEntry(Map context, String defaultValue) { + Boolean isError = (Boolean) context.get("isError"); + Boolean useRequestParameters = (Boolean) context.get("useRequestParameters"); + + Locale locale = (Locale) context.get("locale"); + if (locale == null) + locale = Locale.getDefault(); + TimeZone timeZone = (TimeZone) context.get("timeZone"); + if (timeZone == null) + timeZone = TimeZone.getDefault(); + + String returnValue; + + // if useRequestParameters is TRUE then parameters will always be used, if FALSE then parameters will never be used + // if isError is TRUE and useRequestParameters is not FALSE (ie is null or TRUE) then parameters will be used + if ((Boolean.TRUE.equals(isError) && !Boolean.FALSE.equals(useRequestParameters)) + || (Boolean.TRUE.equals(useRequestParameters))) { + //Debug.logInfo("Getting entry, isError true so getting from parameters for field " + this.getName() + " of form " + this.modelForm.getName(), module); + Map parameters = UtilGenerics.checkMap(context.get("parameters"), String.class, Object.class); + String parameterName = this.getParameterName(context); + if (parameters != null && parameters.get(parameterName) != null) { + Object parameterValue = parameters.get(parameterName); + if (parameterValue instanceof String) { + returnValue = (String) parameterValue; + } else { + // we might want to do something else here in the future, but for now this is probably best + Debug.logWarning("Found a non-String parameter value for field [" + this.getModelForm().getName() + "." + + this.getFieldName() + "]", module); + returnValue = defaultValue; + } + } else { + returnValue = defaultValue; + } + } else { + //Debug.logInfo("Getting entry, isError false so getting from Map in context for field " + this.getName() + " of form " + this.modelForm.getName(), module); + Map dataMap = this.getMap(context); + boolean dataMapIsContext = false; + if (dataMap == null) { + //Debug.logInfo("Getting entry, no Map found with name " + this.getMapName() + ", using context for field " + this.getName() + " of form " + this.modelForm.getName(), module); + dataMap = context; + dataMapIsContext = true; + } + Object retVal = null; + if (UtilValidate.isNotEmpty(this.entryAcsr)) { + if (dataMap instanceof GenericEntity) { + GenericEntity genEnt = (GenericEntity) dataMap; + if (genEnt.getModelEntity().isField(this.entryAcsr.getOriginalName())) { + retVal = genEnt.get(this.entryAcsr.getOriginalName(), locale); + } else { + //TODO: this may never come up, but if necessary use the FlexibleStringExander to eval the name first: String evaled = this.entryAcsr + } + } else { + retVal = this.entryAcsr.get(dataMap, locale); + } + } else { + // if no entry name was specified, use the field's name + if (dataMap.containsKey(this.name)) { + retVal = dataMap.get(this.name); + } + } + + // this is a special case to fill in fields during a create by default from parameters passed in + if (dataMapIsContext && retVal == null && !Boolean.FALSE.equals(useRequestParameters)) { + Map parameters = UtilGenerics.checkMap(context.get("parameters")); + if (parameters != null) { + if (UtilValidate.isNotEmpty(this.entryAcsr)) + retVal = this.entryAcsr.get(parameters); + else + retVal = parameters.get(this.name); + } + } + + if (retVal != null) { + // format string based on the user's locale and time zone + if (retVal instanceof Double || retVal instanceof Float || retVal instanceof BigDecimal) { + NumberFormat nf = NumberFormat.getInstance(locale); + nf.setMaximumFractionDigits(10); + return nf.format(retVal); + } else if (retVal instanceof java.sql.Date) { + DateFormat df = UtilDateTime.toDateFormat(UtilDateTime.DATE_FORMAT, timeZone, null); + return df.format((java.util.Date) retVal); + } else if (retVal instanceof java.sql.Time) { + DateFormat df = UtilDateTime.toTimeFormat(UtilDateTime.TIME_FORMAT, timeZone, null); + return df.format((java.util.Date) retVal); + } else if (retVal instanceof java.sql.Timestamp) { + DateFormat df = UtilDateTime.toDateTimeFormat(UtilDateTime.DATE_TIME_FORMAT, timeZone, null); + return df.format((java.util.Date) retVal); + } else if (retVal instanceof java.util.Date) { + DateFormat df = UtilDateTime.toDateTimeFormat("EEE MMM dd hh:mm:ss z yyyy", timeZone, null); + return df.format((java.util.Date) retVal); + } else { + returnValue = retVal.toString(); + } + } else { + returnValue = defaultValue; + } + } + + if (this.getEncodeOutput() && returnValue != null) { + UtilCodec.SimpleEncoder simpleEncoder = (UtilCodec.SimpleEncoder) context.get("simpleEncoder"); + if (simpleEncoder != null) + returnValue = simpleEncoder.encode(returnValue); + } + return returnValue; + } + + public FlexibleMapAccessor getEntryAcsr() { + return entryAcsr; + } + + public String getEntryName() { + if (UtilValidate.isNotEmpty(this.entryAcsr)) + return this.entryAcsr.getOriginalName(); + return this.name; + } + + public String getEvent() { + return event; + } + + public FieldInfo getFieldInfo() { + return fieldInfo; + } + + /** + * Gets the name of the Entity Field that corresponds + * with this field. This can be used to get additional information about the field. + * Use the getEntityName() method to get the Entity name that the field is in. + * + * @return return the name of the Entity Field that corresponds with this field + */ + public String getFieldName() { + if (UtilValidate.isNotEmpty(this.fieldName)) + return this.fieldName; + return this.name; + } + + public String getHeaderLink() { + return headerLink; + } + + public String getHeaderLinkStyle() { + return headerLinkStyle; + } + + public String getIdName() { + if (UtilValidate.isNotEmpty(idName)) + return idName; + return this.modelForm.getName() + "_" + this.getFieldName(); + } + + public Map getMap(Map context) { + if (UtilValidate.isEmpty(this.mapAcsr)) + return this.modelForm.getDefaultMap(context); //Debug.logInfo("Getting Map from default of the form because of no mapAcsr for field " + this.getName(), module); + + // Debug.logInfo("Getting Map from mapAcsr for field " + this.getName() + ", map-name=" + mapAcsr.getOriginalName() + ", context type=" + context.getClass().toString(), module); + Map result = null; + try { + result = mapAcsr.get(context); + } catch (java.lang.ClassCastException e) { + String errMsg = "Got an unexpected object type (not a Map) for map-name [" + mapAcsr.getOriginalName() + + "] in field with name [" + this.getName() + "]: " + e.getMessage(); + Debug.logError(errMsg, module); + throw new ClassCastException(errMsg); + } + return result; + } + + public FlexibleMapAccessor> getMapAcsr() { + return mapAcsr; + } + + /** Get the name of the Map in the form context that contains the entry, + * available from the getEntryName() method. This entry is used to + * pre-populate the field widget when not in an error condition. In an + * error condition the parameter name is used to get the value from the + * parameters Map. + * + * @return returns the name of the Map in the form context that contains the entry + */ + public String getMapName() { + if (UtilValidate.isNotEmpty(this.mapAcsr)) + return this.mapAcsr.getOriginalName(); + return this.modelForm.getDefaultMapName(); + } + + public ModelForm getModelForm() { + return modelForm; + } + + public String getName() { + return name; + } + + public List getOnChangeUpdateAreas() { + return onChangeUpdateAreas; + } + + public List getOnClickUpdateAreas() { + return onClickUpdateAreas; + } + + public String getParameterName() { + return parameterName; + } + + /** + * Get the name to use for the parameter for this field in the form interpreter. + * For HTML forms this is the request parameter name. + * + * @return returns the name to use for the parameter for this field in the form interpreter + */ + public String getParameterName(Map context) { + String baseName; + if (UtilValidate.isNotEmpty(this.parameterName)) + baseName = this.parameterName; + else + baseName = this.name; + + Integer itemIndex = (Integer) context.get("itemIndex"); + if (itemIndex != null && "multi".equals(this.modelForm.getType())) { + return baseName + this.modelForm.getItemIndexSeparator() + itemIndex.intValue(); + } else { + return baseName; + } + } + + public int getPosition() { + if (this.position == null) + return 1; + return position.intValue(); + } + + public String getRedWhen() { + return redWhen; + } + + public boolean getRequiredField() { + return this.requiredField != null ? this.requiredField : false; + } + + public String getRequiredFieldStyle() { + if (UtilValidate.isNotEmpty(this.requiredFieldStyle)) + return this.requiredFieldStyle; + return this.modelForm.getDefaultRequiredFieldStyle(); + } + + public boolean getSeparateColumn() { + return this.separateColumn; + } + + public String getServiceName() { + if (UtilValidate.isNotEmpty(this.serviceName)) + return this.serviceName; + return this.modelForm.getDefaultServiceName(); + } + + public Boolean getSortField() { + return sortField; + } + + public String getSortFieldAscStyle() { + return sortFieldAscStyle; + } + + public String getSortFieldDescStyle() { + return sortFieldDescStyle; + } + + public String getSortFieldHelpText() { + return sortFieldHelpText; + } + + public String getSortFieldHelpText(Map context) { + return FlexibleStringExpander.expandString(this.sortFieldHelpText, context); + } + + public String getSortFieldStyle() { + if (UtilValidate.isNotEmpty(this.sortFieldStyle)) + return this.sortFieldStyle; + return this.modelForm.getDefaultSortFieldStyle(); + } + + public String getSortFieldStyleAsc() { + if (UtilValidate.isNotEmpty(this.sortFieldAscStyle)) + return this.sortFieldAscStyle; + return this.modelForm.getDefaultSortFieldAscStyle(); + } + + public String getSortFieldStyleDesc() { + if (UtilValidate.isNotEmpty(this.sortFieldDescStyle)) + return this.sortFieldDescStyle; + return this.modelForm.getDefaultSortFieldDescStyle(); + } + + public FlexibleStringExpander getTitle() { + return title; + } + + public String getTitle(Map context) { + if (UtilValidate.isNotEmpty(this.title)) + return title.expandString(context); + + // create a title from the name of this field; expecting a Java method/field style name, ie productName or productCategoryId + if (UtilValidate.isEmpty(this.name)) + return ""; // this should never happen, ie name is required + + // search for a localized label for the field's name + Map uiLabelMap = UtilGenerics.checkMap(context.get("uiLabelMap")); + if (uiLabelMap != null) { + String titleFieldName = "FormFieldTitle_" + this.name; + String localizedName = uiLabelMap.get(titleFieldName); + if (!localizedName.equals(titleFieldName)) { + return localizedName; + } + } else { + Debug.logWarning("Could not find uiLabelMap in context while rendering form " + this.modelForm.getName(), module); + } + + // create a title from the name of this field; expecting a Java method/field style name, ie productName or productCategoryId + StringBuilder autoTitlewriter = new StringBuilder(); + + // always use upper case first letter... + autoTitlewriter.append(Character.toUpperCase(this.name.charAt(0))); + + // just put spaces before the upper case letters + for (int i = 1; i < this.name.length(); i++) { + char curChar = this.name.charAt(i); + if (Character.isUpperCase(curChar)) { + autoTitlewriter.append(' '); + } + autoTitlewriter.append(curChar); + } + + return autoTitlewriter.toString(); + } + + public String getTitleAreaStyle() { + if (UtilValidate.isNotEmpty(this.titleAreaStyle)) + return this.titleAreaStyle; + return this.modelForm.getDefaultTitleAreaStyle(); + } + + public String getTitleStyle() { + if (UtilValidate.isNotEmpty(this.titleStyle)) + return this.titleStyle; + return this.modelForm.getDefaultTitleStyle(); + } + + public FlexibleStringExpander getTooltip() { + return tooltip; + } + + public String getTooltip(Map context) { + String tooltipString = ""; + if (UtilValidate.isNotEmpty(tooltip)) + tooltipString = tooltip.expandString(context); + if (this.getEncodeOutput()) { + UtilCodec.SimpleEncoder simpleEncoder = (UtilCodec.SimpleEncoder) context.get("simpleEncoder"); + if (simpleEncoder != null) + tooltipString = simpleEncoder.encode(tooltipString); + } + return tooltipString; + } + + public String getTooltipStyle() { + if (UtilValidate.isNotEmpty(this.tooltipStyle)) + return this.tooltipStyle; + return this.modelForm.getDefaultTooltipStyle(); + } + + public FlexibleStringExpander getUseWhen() { + return useWhen; + } + + public String getUseWhen(Map context) { + if (UtilValidate.isNotEmpty(this.useWhen)) + return this.useWhen.expandString(context); + return ""; + } + + public String getWidgetAreaStyle() { + if (UtilValidate.isNotEmpty(this.widgetAreaStyle)) + return this.widgetAreaStyle; + return this.modelForm.getDefaultWidgetAreaStyle(); + } + + public String getWidgetStyle() { + if (UtilValidate.isNotEmpty(this.widgetStyle)) + return this.widgetStyle; + return this.modelForm.getDefaultWidgetStyle(); + } + + /** + * Checks if field is a row submit field. + */ + public boolean isRowSubmit() { + if (!"multi".equals(getModelForm().getType())) + return false; + if (getFieldInfo().getFieldType() != FieldInfo.CHECK) + return false; + if (!CheckField.ROW_SUBMIT_FIELD_NAME.equals(getName())) + return false; + return true; + } + + public boolean isSortField() { + return this.sortField != null && this.sortField.booleanValue(); + } + + public boolean isUseWhenEmpty() { + if (this.useWhen == null) { + return true; + } + + return this.useWhen.isEmpty(); + } + + public void renderFieldString(Appendable writer, Map context, FormStringRenderer formStringRenderer) + throws IOException { + this.fieldInfo.renderFieldString(writer, context, formStringRenderer); + } + + /** + * the widget/interaction part will be red if the date value is + * before-now (for ex. thruDate), after-now (for ex. fromDate), or by-name (if the + * field's name or entry-name or fromDate or thruDate the corresponding + * action will be done); only applicable when the field is a timestamp + * + * @param context the context + * @return true if the field should be read otherwise false + */ + public boolean shouldBeRed(Map context) { + // red-when (never | before-now | after-now | by-name) "by-name" + + String redCondition = this.redWhen; + + if ("never".equals(redCondition)) + return false; + + // for performance resaons we check this first, most fields will be eliminated here and the valueOfs will not be necessary + if (UtilValidate.isEmpty(redCondition) || "by-name".equals(redCondition)) { + if ("fromDate".equals(this.name) || (this.entryAcsr != null && "fromDate".equals(this.entryAcsr.getOriginalName()))) { + redCondition = "after-now"; + } else if ("thruDate".equals(this.name) + || (this.entryAcsr != null && "thruDate".equals(this.entryAcsr.getOriginalName()))) { + redCondition = "before-now"; + } else { + return false; + } + } + + boolean isBeforeNow = false; + if ("before-now".equals(redCondition)) { + isBeforeNow = true; + } else if ("after-now".equals(redCondition)) { + isBeforeNow = false; + } else { + return false; + } + + java.sql.Date dateVal = null; + java.sql.Time timeVal = null; + java.sql.Timestamp timestampVal = null; + + //now before going on, check to see if the current entry is a valid date and/or time and get the value + String value = this.getEntry(context, null); + try { + timestampVal = java.sql.Timestamp.valueOf(value); + } catch (Exception e) { + // okay, not a timestamp... + } + + if (timestampVal == null) { + try { + dateVal = java.sql.Date.valueOf(value); + } catch (Exception e) { + // okay, not a date... + } + } + + if (timestampVal == null && dateVal == null) { + try { + timeVal = java.sql.Time.valueOf(value); + } catch (Exception e) { + // okay, not a time... + } + } + + if (timestampVal == null && dateVal == null && timeVal == null) { + return false; + } + + long nowMillis = System.currentTimeMillis(); + if (timestampVal != null) { + java.sql.Timestamp nowStamp = new java.sql.Timestamp(nowMillis); + if (!timestampVal.equals(nowStamp)) { + if (isBeforeNow) { + if (timestampVal.before(nowStamp)) { + return true; + } + } else { + if (timestampVal.after(nowStamp)) { + return true; + } + } + } + } else if (dateVal != null) { + java.sql.Date nowDate = new java.sql.Date(nowMillis); + if (!dateVal.equals(nowDate)) { + if (isBeforeNow) { + if (dateVal.before(nowDate)) { + return true; + } + } else { + if (dateVal.after(nowDate)) { + return true; + } + } + } + } else if (timeVal != null) { + java.sql.Time nowTime = new java.sql.Time(nowMillis); + if (!timeVal.equals(nowTime)) { + if (isBeforeNow) { + if (timeVal.before(nowTime)) { + return true; + } + } else { + if (timeVal.after(nowTime)) { + return true; + } + } + } + } + + return false; + } + + public boolean shouldUse(Map context) { + String useWhenStr = this.getUseWhen(context); + if (UtilValidate.isEmpty(useWhenStr)) + return true; + + try { + Interpreter bsh = this.modelForm.getBshInterpreter(context); + Object retVal = bsh.eval(StringUtil.convertOperatorSubstitutions(useWhenStr)); + boolean condTrue = false; + // retVal should be a Boolean, if not something weird is up... + if (retVal instanceof Boolean) { + Boolean boolVal = (Boolean) retVal; + condTrue = boolVal.booleanValue(); + } else { + throw new IllegalArgumentException("Return value from use-when condition eval was not a Boolean: " + + (retVal != null ? retVal.getClass().getName() : "null") + " [" + retVal + "] on the field " + this.name + + " of form " + this.modelForm.getName()); + } + + return condTrue; + } catch (EvalError e) { + String errMsg = "Error evaluating BeanShell use-when condition [" + useWhenStr + "] on the field " + this.name + + " of form " + this.modelForm.getName() + ": " + e.toString(); + Debug.logError(e, errMsg, module); + //Debug.logError("For use-when eval error context is: " + context, module); + throw new IllegalArgumentException(errMsg); + } + } + + /** + * Models the <auto-complete> element. + * + * @see widget-form.xsd + */ + public static class AutoComplete { + private final String autoSelect; + private final String choices; + private final String frequency; + private final String fullSearch; + private final String ignoreCase; + private final String minChars; + private final String partialChars; + private final String partialSearch; + + public AutoComplete(Element element) { + this.autoSelect = element.getAttribute("auto-select"); + this.frequency = element.getAttribute("frequency"); + this.minChars = element.getAttribute("min-chars"); + this.choices = element.getAttribute("choices"); + this.partialSearch = element.getAttribute("partial-search"); + this.partialChars = element.getAttribute("partial-chars"); + this.ignoreCase = element.getAttribute("ignore-case"); + this.fullSearch = element.getAttribute("full-search"); + } + + public String getAutoSelect() { + return this.autoSelect; + } + + public String getChoices() { + return this.choices; + } + + public String getFrequency() { + return this.frequency; + } + + public String getFullSearch() { + return this.fullSearch; + } + + public String getIgnoreCase() { + return this.ignoreCase; + } + + public String getMinChars() { + return this.minChars; + } + + public String getPartialChars() { + return this.partialChars; + } + + public String getPartialSearch() { + return this.partialSearch; + } + } + + /** + * Models the <check> element. + * + * @see widget-form.xsd + */ + public static class CheckField extends FieldInfoWithOptions { + public final static String ROW_SUBMIT_FIELD_NAME = "_rowSubmit"; + private final FlexibleStringExpander allChecked; + + private CheckField(CheckField original, ModelFormField modelFormField) { + super(original, modelFormField); + this.allChecked = original.allChecked; + } + + public CheckField(Element element, ModelFormField modelFormField) { + super(element, modelFormField); + allChecked = FlexibleStringExpander.getInstance(element.getAttribute("all-checked")); + } + + public CheckField(int fieldSource, ModelFormField modelFormField) { + super(fieldSource, FieldInfo.CHECK, modelFormField); + this.allChecked = FlexibleStringExpander.getInstance(""); + } + + public CheckField(ModelFormField modelFormField) { + super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.CHECK, modelFormField); + this.allChecked = FlexibleStringExpander.getInstance(""); + } + + @Override + public void accept(ModelFieldVisitor visitor) throws Exception { + visitor.visit(this); + } + + @Override + public FieldInfo copy(ModelFormField modelFormField) { + return new CheckField(this, modelFormField); + } + + public FlexibleStringExpander getAllChecked() { + return allChecked; + } + + public Boolean isAllChecked(Map context) { + String allCheckedStr = this.allChecked.expandString(context); + if (!allCheckedStr.isEmpty()) + return Boolean.valueOf("true".equals(allCheckedStr)); + else + return null; + } + + @Override + public void renderFieldString(Appendable writer, Map context, FormStringRenderer formStringRenderer) + throws IOException { + formStringRenderer.renderCheckField(writer, context, this); + } + } + + /** + * Models the <container> element. + * + * @see widget-form.xsd + */ + public static class ContainerField extends FieldInfo { + + private ContainerField(ContainerField original, ModelFormField modelFormField) { + super(original.getFieldSource(), original.getFieldType(), modelFormField); + } + + public ContainerField(Element element, ModelFormField modelFormField) { + super(element, modelFormField); + } + + public ContainerField(int fieldSource, int fieldType, ModelFormField modelFormField) { + super(fieldSource, fieldType, modelFormField); + } + + @Override + public void accept(ModelFieldVisitor visitor) throws Exception { + visitor.visit(this); + } + + @Override + public FieldInfo copy(ModelFormField modelFormField) { + return new ContainerField(this, modelFormField); + } + + @Override + public void renderFieldString(Appendable writer, Map context, FormStringRenderer formStringRenderer) + throws IOException { + formStringRenderer.renderContainerFindField(writer, context, this); + } + } + + /** + * Models the <date-find> element. + * + * @see widget-form.xsd + */ + public static class DateFindField extends DateTimeField { + private final String defaultOptionFrom; + private final String defaultOptionThru; + + private DateFindField(DateFindField original, ModelFormField modelFormField) { + super(original, modelFormField); + this.defaultOptionFrom = original.defaultOptionFrom; + this.defaultOptionThru = original.defaultOptionThru; + } + + public DateFindField(Element element, ModelFormField modelFormField) { + super(element, modelFormField); + this.defaultOptionFrom = element.getAttribute("default-option-from"); + this.defaultOptionThru = element.getAttribute("default-option-thru"); + } + + public DateFindField(int fieldSource, ModelFormField modelFormField) { + super(fieldSource, modelFormField); + this.defaultOptionFrom = "greaterThanEqualTo"; + this.defaultOptionThru = "lessThanEqualTo"; + } + + public DateFindField(int fieldSource, String type) { + super(fieldSource, type); + this.defaultOptionFrom = "greaterThanEqualTo"; + this.defaultOptionThru = "lessThanEqualTo"; + } + + @Override + public void accept(ModelFieldVisitor visitor) throws Exception { + visitor.visit(this); + } + + @Override + public FieldInfo copy(ModelFormField modelFormField) { + return new DateFindField(this, modelFormField); + } + + public String getDefaultOptionFrom() { + return this.defaultOptionFrom; + } + + public String getDefaultOptionThru() { + return this.defaultOptionThru; + } + + @Override + public void renderFieldString(Appendable writer, Map context, FormStringRenderer formStringRenderer) + throws IOException { + formStringRenderer.renderDateFindField(writer, context, this); + } + } + + /** + * Models the <date-time> element. + * + * @see widget-form.xsd + */ + public static class DateTimeField extends FieldInfo { + private final String clock; + private final FlexibleStringExpander defaultValue; + private final String inputMethod; + private final String mask; + private final String step; + private final String type; + + protected DateTimeField(DateTimeField original, ModelFormField modelFormField) { + super(original.getFieldSource(), original.getFieldType(), modelFormField); + this.defaultValue = original.defaultValue; + this.type = original.type; + this.inputMethod = original.inputMethod; + this.clock = original.clock; + this.mask = original.mask; + this.step = original.step; + } + + public DateTimeField(Element element, ModelFormField modelFormField) { + super(element, modelFormField); + this.defaultValue = FlexibleStringExpander.getInstance(element.getAttribute("default-value")); + this.type = element.getAttribute("type"); + this.inputMethod = element.getAttribute("input-method"); + this.clock = element.getAttribute("clock"); + this.mask = element.getAttribute("mask"); + String step = element.getAttribute("step"); + if (step.isEmpty()) { + step = "1"; + } + this.step = step; + } + + public DateTimeField(int fieldSource, ModelFormField modelFormField) { + super(fieldSource, FieldInfo.DATE_TIME, modelFormField); + this.defaultValue = FlexibleStringExpander.getInstance(""); + this.type = ""; + this.inputMethod = ""; + this.clock = ""; + this.mask = ""; + this.step = "1"; + } + + public DateTimeField(int fieldSource, String type) { + super(fieldSource, FieldInfo.DATE_TIME, null); + this.defaultValue = FlexibleStringExpander.getInstance(""); + this.type = type; + this.inputMethod = ""; + this.clock = ""; + this.mask = ""; + this.step = "1"; + } + + public DateTimeField(ModelFormField modelFormField) { + super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.DATE_TIME, modelFormField); + this.defaultValue = FlexibleStringExpander.getInstance(""); + this.type = ""; + this.inputMethod = ""; + this.clock = ""; + this.mask = ""; + this.step = "1"; + } + + @Override + public void accept(ModelFieldVisitor visitor) throws Exception { + visitor.visit(this); + } + + @Override + public FieldInfo copy(ModelFormField modelFormField) { + return new DateTimeField(this, modelFormField); + } + + public String getClock() { + return this.clock; + } + + /** + * Returns the default-value if specified, otherwise the current date, time or timestamp + * + * @param context Context Map + * @return Default value string for date-time + */ + public String getDefaultDateTimeString(Map context) { + if (UtilValidate.isNotEmpty(this.defaultValue)) + return this.getDefaultValue(context); + + if ("date".equals(this.type)) + return (new java.sql.Date(System.currentTimeMillis())).toString(); + else if ("time".equals(this.type)) + return (new java.sql.Time(System.currentTimeMillis())).toString(); + else + return UtilDateTime.nowTimestamp().toString(); + } + + public FlexibleStringExpander getDefaultValue() { + return defaultValue; + } + + public String getDefaultValue(Map context) { + if (this.defaultValue != null) { + return this.defaultValue.expandString(context); + } else { + return ""; + } + } + + public String getInputMethod() { + return this.inputMethod; + } + + public String getMask() { + return this.mask; + } + + public String getStep() { + return this.step; + } + + public String getType() { + return type; + } + + @Override + public void renderFieldString(Appendable writer, Map context, FormStringRenderer formStringRenderer) + throws IOException { + formStringRenderer.renderDateTimeField(writer, context, this); + } + } + + /** + * Models the <display-entity> element. + * + * @see widget-form.xsd + */ + public static class DisplayEntityField extends DisplayField { + private final boolean cache; + private final String entityName; + private final String keyFieldName; + private final SubHyperlink subHyperlink; + + private DisplayEntityField(DisplayEntityField original, ModelFormField modelFormField) { + super(original, modelFormField); + this.cache = original.cache; + this.entityName = original.entityName; + this.keyFieldName = original.keyFieldName; + if (original.subHyperlink != null) { + this.subHyperlink = new SubHyperlink(original.subHyperlink, modelFormField); + } else { + this.subHyperlink = null; + } + } + + public DisplayEntityField(Element element, ModelFormField modelFormField) { + super(element, modelFormField); + this.cache = !"false".equals(element.getAttribute("cache")); + this.entityName = element.getAttribute("entity-name"); + this.keyFieldName = element.getAttribute("key-field-name"); + Element subHyperlinkElement = UtilXml.firstChildElement(element, "sub-hyperlink"); + if (subHyperlinkElement != null) { + this.subHyperlink = new SubHyperlink(subHyperlinkElement, modelFormField); + } else { + this.subHyperlink = null; + } + } + + public DisplayEntityField(int fieldSource, ModelFormField modelFormField) { + super(fieldSource, FieldInfo.DISPLAY_ENTITY, modelFormField); + this.cache = true; + this.entityName = ""; + this.keyFieldName = ""; + this.subHyperlink = null; + } + + public DisplayEntityField(ModelFormField modelFormField) { + super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.DISPLAY_ENTITY, modelFormField); + this.cache = true; + this.entityName = ""; + this.keyFieldName = ""; + this.subHyperlink = null; + } + + @Override + public void accept(ModelFieldVisitor visitor) throws Exception { + visitor.visit(this); + } + + @Override + public FieldInfo copy(ModelFormField modelFormField) { + return new DisplayEntityField(this, modelFormField); + } + + public boolean getCache() { + return cache; + } + + @Override + public String getDescription(Map context) { + Locale locale = UtilMisc.ensureLocale(context.get("locale")); + + // rather than using the context to expand the string, lookup the given entity and use it to expand the string + GenericValue value = null; + String fieldKey = this.keyFieldName; + if (UtilValidate.isEmpty(fieldKey)) + fieldKey = getModelFormField().fieldName; + + Delegator delegator = WidgetWorker.getDelegator(context); + String fieldValue = getModelFormField().getEntry(context); + try { + value = delegator.findOne(this.entityName, this.cache, fieldKey, fieldValue); + } catch (GenericEntityException e) { + String errMsg = "Error getting value from the database for display of field [" + getModelFormField().getName() + + "] on form [" + getModelFormField().modelForm.getName() + "]: " + e.toString(); + Debug.logError(e, errMsg, module); + throw new IllegalArgumentException(errMsg); + } + + String retVal = null; + if (value != null) { + // expanding ${} stuff, passing locale explicitly to expand value string because it won't be found in the Entity + MapStack localContext = MapStack.create(context); + // Rendering code might try to modify the GenericEntity instance, + // so we make a copy of it. + Map genericEntityClone = UtilGenerics.cast(value.clone()); + localContext.push(genericEntityClone); + + // expand with the new localContext, which is locale aware + retVal = this.getDescription().expandString(localContext, locale); + } + // try to get the entry for the field if description doesn't expand to anything + if (UtilValidate.isEmpty(retVal)) + retVal = fieldValue; + if (UtilValidate.isEmpty(retVal)) + retVal = ""; + return retVal; + } + + public String getEntityName() { + return entityName; + } + + public String getKeyFieldName() { + return keyFieldName; + } + + public SubHyperlink getSubHyperlink() { + return this.subHyperlink; + } + } + + /** + * Models the <display> element. + * + * @see widget-form.xsd + */ + public static class DisplayField extends FieldInfo { + private final boolean alsoHidden; + private final FlexibleStringExpander currency; + private final FlexibleStringExpander date; + private final FlexibleStringExpander defaultValue; + private final FlexibleStringExpander description; + private final FlexibleStringExpander imageLocation; + private final InPlaceEditor inPlaceEditor; + private final String size; // maximum number of characters to display + private final String type; // matches type of field, currently text or currency + + protected DisplayField(DisplayField original, ModelFormField modelFormField) { + super(original.getFieldSource(), original.getFieldType(), modelFormField); + this.alsoHidden = original.alsoHidden; + this.currency = original.currency; + this.date = original.date; + this.defaultValue = original.defaultValue; + this.description = original.description; + this.imageLocation = original.imageLocation; + this.inPlaceEditor = original.inPlaceEditor; + this.size = original.size; + this.type = original.type; + } + + public DisplayField(Element element, ModelFormField modelFormField) { + super(element, modelFormField); + this.alsoHidden = !"false".equals(element.getAttribute("also-hidden")); + this.currency = FlexibleStringExpander.getInstance(element.getAttribute("currency")); + this.date = FlexibleStringExpander.getInstance(element.getAttribute("date")); + this.defaultValue = FlexibleStringExpander.getInstance(element.getAttribute("default-value")); + this.description = FlexibleStringExpander.getInstance(element.getAttribute("description")); + this.imageLocation = FlexibleStringExpander.getInstance(element.getAttribute("image-location")); + Element inPlaceEditorElement = UtilXml.firstChildElement(element, "in-place-editor"); + if (inPlaceEditorElement != null) { + this.inPlaceEditor = new InPlaceEditor(inPlaceEditorElement); + } else { + this.inPlaceEditor = null; + } + this.size = element.getAttribute("size"); + this.type = element.getAttribute("type"); + } + + public DisplayField(int fieldSource, int fieldType, ModelFormField modelFormField) { + super(fieldSource, fieldType, modelFormField); + this.alsoHidden = true; + this.currency = FlexibleStringExpander.getInstance(""); + this.date = FlexibleStringExpander.getInstance(""); + this.defaultValue = FlexibleStringExpander.getInstance(""); + this.description = FlexibleStringExpander.getInstance(""); + this.imageLocation = FlexibleStringExpander.getInstance(""); + this.inPlaceEditor = null; + this.size = ""; + this.type = ""; + } + + public DisplayField(int fieldSource, ModelFormField modelFormField) { + super(fieldSource, FieldInfo.DISPLAY, modelFormField); + this.alsoHidden = true; + this.currency = FlexibleStringExpander.getInstance(""); + this.date = FlexibleStringExpander.getInstance(""); + this.defaultValue = FlexibleStringExpander.getInstance(""); + this.description = FlexibleStringExpander.getInstance(""); + this.imageLocation = FlexibleStringExpander.getInstance(""); + this.inPlaceEditor = null; + this.size = ""; + this.type = ""; + } + + public DisplayField(ModelFormField modelFormField) { + super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.DISPLAY, modelFormField); + this.alsoHidden = true; + this.currency = FlexibleStringExpander.getInstance(""); + this.date = FlexibleStringExpander.getInstance(""); + this.defaultValue = FlexibleStringExpander.getInstance(""); + this.description = FlexibleStringExpander.getInstance(""); + this.imageLocation = FlexibleStringExpander.getInstance(""); + this.inPlaceEditor = null; + this.size = ""; + this.type = ""; + } + + @Override + public void accept(ModelFieldVisitor visitor) throws Exception { + visitor.visit(this); + } + + @Override + public FieldInfo copy(ModelFormField modelFormField) { + return new DisplayField(this, modelFormField); + } + + public boolean getAlsoHidden() { + return alsoHidden; + } + + public FlexibleStringExpander getCurrency() { + return currency; + } + + public FlexibleStringExpander getDate() { + return date; + } + + public FlexibleStringExpander getDefaultValue() { + return defaultValue; + } + + public String getDefaultValue(Map context) { + if (this.defaultValue != null) { + return this.defaultValue.expandString(context); + } else { + return ""; + } + } + + public FlexibleStringExpander getDescription() { + return description; + } + + public String getDescription(Map context) { + String retVal = null; + if (UtilValidate.isNotEmpty(this.description)) + retVal = this.description.expandString(context); + else + retVal = getModelFormField().getEntry(context); + + if (UtilValidate.isEmpty(retVal)) { + retVal = this.getDefaultValue(context); + } else if ("currency".equals(type)) { + retVal = retVal.replaceAll(" ", " "); // FIXME : encoding currency is a problem for some locale, we should not have any   in retVal other case may arise in future... + Locale locale = (Locale) context.get("locale"); + if (locale == null) + locale = Locale.getDefault(); + String isoCode = null; + if (UtilValidate.isNotEmpty(this.currency)) + isoCode = this.currency.expandString(context); + + try { + BigDecimal parsedRetVal = (BigDecimal) ObjectType.simpleTypeConvert(retVal, "BigDecimal", null, null, locale, + true); + retVal = UtilFormatOut.formatCurrency(parsedRetVal, isoCode, locale, 10); // we set the max to 10 digits as an hack to not round numbers in the ui + } catch (GeneralException e) { + String errMsg = "Error formatting currency value [" + retVal + "]: " + e.toString(); + Debug.logError(e, errMsg, module); + throw new IllegalArgumentException(errMsg); + } + } else if ("date".equals(this.type) && retVal.length() > 10) { + Locale locale = (Locale) context.get("locale"); + if (locale == null) { + locale = Locale.getDefault(); + } + + StringToTimestamp stringToTimestamp = new DateTimeConverters.StringToTimestamp(); + Timestamp timestamp = null; + try { + timestamp = stringToTimestamp.convert(retVal); + Date date = new Date(timestamp.getTime()); + + DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.SHORT, locale); + retVal = dateFormatter.format(date); + } catch (ConversionException e) { + String errMsg = "Error formatting date using default instead [" + retVal + "]: " + e.toString(); + Debug.logError(e, errMsg, module); + // create default date value from timestamp string + retVal = retVal.substring(0, 10); + } + + } else if ("date-time".equals(this.type) && retVal.length() > 16) { + Locale locale = (Locale) context.get("locale"); + TimeZone timeZone = (TimeZone) context.get("timeZone"); + if (locale == null) { + locale = Locale.getDefault(); + } + if (timeZone == null) { + timeZone = TimeZone.getDefault(); + } + + StringToTimestamp stringToTimestamp = new DateTimeConverters.StringToTimestamp(); + Timestamp timestamp = null; + try { + timestamp = stringToTimestamp.convert(retVal); + Date date = new Date(timestamp.getTime()); + + DateFormat dateFormatter = UtilDateTime.toDateTimeFormat(null, timeZone, locale); + retVal = dateFormatter.format(date); + } catch (ConversionException e) { + String errMsg = "Error formatting date/time using default instead [" + retVal + "]: " + e.toString(); + Debug.logError(e, errMsg, module); + // create default date/time value from timestamp string + retVal = retVal.substring(0, 16); + } + } else if ("accounting-number".equals(this.type)) { + Locale locale = (Locale) context.get("locale"); + if (locale == null) { + locale = Locale.getDefault(); + } + try { + Double parsedRetVal = (Double) ObjectType.simpleTypeConvert(retVal, "Double", null, locale, false); + String template = UtilProperties.getPropertyValue("arithmetic", "accounting-number.format", + "#,##0.00;(#,##0.00)"); + retVal = UtilFormatOut.formatDecimalNumber(parsedRetVal.doubleValue(), template, locale); + } catch (GeneralException e) { + String errMsg = "Error formatting number [" + retVal + "]: " + e.toString(); + Debug.logError(e, errMsg, module); + throw new IllegalArgumentException(errMsg); + } + } + if (UtilValidate.isNotEmpty(this.description) && retVal != null && this.getModelFormField().getEncodeOutput()) { + UtilCodec.SimpleEncoder simpleEncoder = (UtilCodec.SimpleEncoder) context.get("simpleEncoder"); + if (simpleEncoder != null) { + retVal = simpleEncoder.encode(retVal); + } + } + return retVal; + } + + public FlexibleStringExpander getImageLocation() { + return imageLocation; + } + + public String getImageLocation(Map context) { + if (this.imageLocation != null) + return this.imageLocation.expandString(context); + return ""; + } + + public InPlaceEditor getInPlaceEditor() { + return this.inPlaceEditor; + } + + public String getSize() { + return this.size; + } + + public String getType() { + return this.type; + } + + @Override + public void renderFieldString(Appendable writer, Map context, FormStringRenderer formStringRenderer) + throws IOException { + formStringRenderer.renderDisplayField(writer, context, this); + } + } + + /** + * Models the <drop-down> element. + * + * @see widget-form.xsd + */ + public static class DropDownField extends FieldInfoWithOptions { + private final boolean allowEmpty; + private final boolean allowMulti; + private final AutoComplete autoComplete; + private final String current; + private final FlexibleStringExpander currentDescription; + private final int otherFieldSize; + private final String size; + private final SubHyperlink subHyperlink; + private final String textSize; + + private DropDownField(DropDownField original, ModelFormField modelFormField) { + super(original, modelFormField); + this.allowEmpty = original.allowEmpty; + this.allowMulti = original.allowMulti; + this.autoComplete = original.autoComplete; + this.current = original.current; + this.currentDescription = original.currentDescription; + this.otherFieldSize = original.otherFieldSize; + this.size = original.size; + if (original.subHyperlink != null) { + this.subHyperlink = new SubHyperlink(original.subHyperlink, modelFormField); + } else { + this.subHyperlink = null; + } + this.textSize = original.textSize; + } + + public DropDownField(Element element, ModelFormField modelFormField) { + super(element, modelFormField); + this.allowEmpty = "true".equals(element.getAttribute("allow-empty")); + this.allowMulti = "true".equals(element.getAttribute("allow-multiple")); + Element autoCompleteElement = UtilXml.firstChildElement(element, "auto-complete"); + if (autoCompleteElement != null) { + this.autoComplete = new AutoComplete(autoCompleteElement); + } else { + this.autoComplete = null; + } + this.current = element.getAttribute("current"); + this.currentDescription = FlexibleStringExpander.getInstance(element.getAttribute("current-description")); + int otherFieldSize = 0; + String sizeStr = element.getAttribute("other-field-size"); + if (!sizeStr.isEmpty()) { + try { + otherFieldSize = Integer.parseInt(sizeStr); + } catch (Exception e) { + Debug.logError("Could not parse the size value of the text element: [" + sizeStr + + "], setting to the default of 0", module); + } + } + this.otherFieldSize = otherFieldSize; + String size = element.getAttribute("size"); + if (size.isEmpty()) { + size = "1"; + } + this.size = size; + Element subHyperlinkElement = UtilXml.firstChildElement(element, "sub-hyperlink"); + if (subHyperlinkElement != null) { + this.subHyperlink = new SubHyperlink(subHyperlinkElement, this.getModelFormField()); + } else { + this.subHyperlink = null; + } + String textSize = element.getAttribute("text-size"); + if (textSize.isEmpty()) { + textSize = "0"; + } + this.textSize = textSize; + } + + public DropDownField(int fieldSource, List optionSources) { + super(fieldSource, FieldInfo.DROP_DOWN, optionSources); + this.allowEmpty = false; + this.allowMulti = false; + this.autoComplete = null; + this.current = ""; + this.currentDescription = FlexibleStringExpander.getInstance(""); + this.otherFieldSize = 0; + this.size = "1"; + this.subHyperlink = null; + this.textSize = "0"; + } + + public DropDownField(int fieldSource, ModelFormField modelFormField) { + super(fieldSource, FieldInfo.DROP_DOWN, modelFormField); + this.allowEmpty = false; + this.allowMulti = false; + this.autoComplete = null; + this.current = ""; + this.currentDescription = FlexibleStringExpander.getInstance(""); + this.otherFieldSize = 0; + this.size = "1"; + this.subHyperlink = null; + this.textSize = "0"; + } + + public DropDownField(ModelFormField modelFormField) { + super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.DROP_DOWN, modelFormField); + this.allowEmpty = false; + this.allowMulti = false; + this.autoComplete = null; + this.current = ""; + this.currentDescription = FlexibleStringExpander.getInstance(""); + this.otherFieldSize = 0; + this.size = "1"; + this.subHyperlink = null; + this.textSize = "0"; + } + + @Override + public void accept(ModelFieldVisitor visitor) throws Exception { + visitor.visit(this); + } + + @Override + public FieldInfo copy(ModelFormField modelFormField) { + return new DropDownField(this, modelFormField); + } + + public boolean getAllowMulti() { + return allowMulti; + } + + public AutoComplete getAutoComplete() { + return this.autoComplete; + } + + public String getCurrent() { + if (UtilValidate.isEmpty(this.current)) + return "first-in-list"; + return this.current; + } + + public FlexibleStringExpander getCurrentDescription() { + return currentDescription; + } + + public String getCurrentDescription(Map context) { + if (this.currentDescription == null) + return null; + return this.currentDescription.expandString(context); + } + + public int getOtherFieldSize() { + return this.otherFieldSize; + } + + /** + * Get the name to use for the parameter for this field in the form interpreter. + * For HTML forms this is the request parameter name. + * @param context the context + * @return returns the name to use for the parameter for this field in the form interpreter. + */ + public String getParameterNameOther(Map context) { + String baseName; + if (UtilValidate.isNotEmpty(getModelFormField().parameterName)) + baseName = getModelFormField().parameterName; + else + baseName = getModelFormField().name; + + baseName += "_OTHER"; + Integer itemIndex = (Integer) context.get("itemIndex"); + if (itemIndex != null && "multi".equals(getModelFormField().modelForm.getType())) { + return baseName + getModelFormField().modelForm.getItemIndexSeparator() + itemIndex.intValue(); + } else { + return baseName; + } + } + + public String getSize() { + return this.size; + } + + public SubHyperlink getSubHyperlink() { + return this.subHyperlink; + } + + public String getTextSize() { + return this.textSize; + } + + public boolean getAllowEmpty() { + return this.allowEmpty; + } + + public boolean getAllowMultiple() { + return this.allowMulti; + } + + @Override + public void renderFieldString(Appendable writer, Map context, FormStringRenderer formStringRenderer) + throws IOException { + formStringRenderer.renderDropDownField(writer, context, this); + } + } + + /** + * Models the <entity-options> element. + * + * @see widget-form.xsd + */ + public static class EntityOptions extends OptionSource { + private final boolean cache; + private final List constraintList; + private final FlexibleStringExpander description; + private final String entityName; + private final String filterByDate; + private final String keyFieldName; + private final List orderByList; + + public EntityOptions(Element entityOptionsElement, ModelFormField modelFormField) { + super(modelFormField); + this.cache = !"false".equals(entityOptionsElement.getAttribute("cache")); + List constraintElements = UtilXml.childElementList(entityOptionsElement, "entity-constraint"); + if (!constraintElements.isEmpty()) { + List constraintList = new ArrayList( + constraintElements.size()); + for (Element constraintElement : constraintElements) { + constraintList.add(new EntityFinderUtil.ConditionExpr(constraintElement)); + } + this.constraintList = Collections.unmodifiableList(constraintList); + } else { + this.constraintList = Collections.emptyList(); + } + this.description = FlexibleStringExpander.getInstance(entityOptionsElement.getAttribute("description")); + this.entityName = entityOptionsElement.getAttribute("entity-name"); + this.filterByDate = entityOptionsElement.getAttribute("filter-by-date"); + this.keyFieldName = entityOptionsElement.getAttribute("key-field-name"); + List orderByElements = UtilXml.childElementList(entityOptionsElement, "entity-order-by"); + if (!orderByElements.isEmpty()) { + List orderByList = new ArrayList(orderByElements.size()); + for (Element orderByElement : orderByElements) { + orderByList.add(orderByElement.getAttribute("field-name")); + } + this.orderByList = Collections.unmodifiableList(orderByList); + } else { + this.orderByList = Collections.emptyList(); + } + } + + private EntityOptions(EntityOptions original, ModelFormField modelFormField) { + super(modelFormField); + this.cache = original.cache; + this.constraintList = original.constraintList; + this.description = original.description; + this.entityName = original.entityName; + this.filterByDate = original.filterByDate; + this.keyFieldName = original.keyFieldName; + this.orderByList = original.orderByList; + } + + public EntityOptions(ModelFormField modelFormField) { + super(modelFormField); + this.cache = true; + this.constraintList = Collections.emptyList(); + this.description = FlexibleStringExpander.getInstance(""); + this.entityName = ""; + this.filterByDate = ""; + this.keyFieldName = ""; + this.orderByList = Collections.emptyList(); + } + + @Override + public void addOptionValues(List optionValues, Map context, Delegator delegator) { + // first expand any conditions that need expanding based on the current context + EntityCondition findCondition = null; + if (UtilValidate.isNotEmpty(this.constraintList)) { + List expandedConditionList = new LinkedList(); + for (EntityFinderUtil.Condition condition : constraintList) { + ModelEntity modelEntity = delegator.getModelEntity(this.entityName); + if (modelEntity == null) { + throw new IllegalArgumentException("Error in entity-options: could not find entity [" + this.entityName + + "]"); + } + EntityCondition createdCondition = condition.createCondition(context, modelEntity, + delegator.getModelFieldTypeReader(modelEntity)); + if (createdCondition != null) { + expandedConditionList.add(createdCondition); + } + } + findCondition = EntityCondition.makeCondition(expandedConditionList); + } + + try { + Locale locale = UtilMisc.ensureLocale(context.get("locale")); + + List values = null; + values = delegator.findList(this.entityName, findCondition, null, this.orderByList, null, this.cache); + + // filter-by-date if requested + if ("true".equals(this.filterByDate)) { + values = EntityUtil.filterByDate(values, true); + } else if (!"false".equals(this.filterByDate)) { + // not explicitly true or false, check to see if has fromDate and thruDate, if so do the filter + ModelEntity modelEntity = delegator.getModelEntity(this.entityName); + if (modelEntity != null && modelEntity.isField("fromDate") && modelEntity.isField("thruDate")) { + values = EntityUtil.filterByDate(values, true); + } + } + + for (GenericValue value : values) { + // add key and description with string expansion, ie expanding ${} stuff, passing locale explicitly to expand value string because it won't be found in the Entity + MapStack localContext = MapStack.create(context); + // Rendering code might try to modify the GenericEntity instance, + // so we make a copy of it. + Map genericEntityClone = UtilGenerics.cast(value.clone()); + localContext.push(genericEntityClone); + + // expand with the new localContext, which is locale aware + String optionDesc = this.description.expandString(localContext, locale); + + Object keyFieldObject = value.get(this.getKeyFieldName()); + if (keyFieldObject == null) { + throw new IllegalArgumentException( + "The entity-options identifier (from key-name attribute, or default to the field name) [" + + this.getKeyFieldName() + "], may not be a valid key field name for the entity [" + + this.entityName + "]."); + } + String keyFieldValue = keyFieldObject.toString(); + optionValues.add(new OptionValue(keyFieldValue, optionDesc)); + } + } catch (GenericEntityException e) { + Debug.logError(e, "Error getting entity options in form", module); + } + } + + @Override + public OptionSource copy(ModelFormField modelFormField) { + return new EntityOptions(this, modelFormField); + } + + public boolean getCache() { + return cache; + } + + public List getConstraintList() { + return constraintList; + } + + public FlexibleStringExpander getDescription() { + return description; + } + + public String getEntityName() { + return entityName; + } + + public String getFilterByDate() { + return filterByDate; + } + + public String getKeyFieldName() { + if (UtilValidate.isNotEmpty(this.keyFieldName)) + return this.keyFieldName; + return getModelFormField().getFieldName(); // get the modelFormField fieldName + } + + public List getOrderByList() { + return orderByList; + } + } + + public static abstract class FieldInfoWithOptions extends FieldInfo { + + public static String getDescriptionForOptionKey(String key, List allOptionValues) { + if (UtilValidate.isEmpty(key)) + return ""; + + if (UtilValidate.isEmpty(allOptionValues)) + return key; + + for (OptionValue optionValue : allOptionValues) { + if (key.equals(optionValue.getKey())) { + return optionValue.getDescription(); + } + } + + // if we get here we didn't find a match, just return the key + return key; + } + + private final FlexibleStringExpander noCurrentSelectedKey; + private final List optionSources; + + public FieldInfoWithOptions(Element element, ModelFormField modelFormField) { + super(element, modelFormField); + this.noCurrentSelectedKey = FlexibleStringExpander.getInstance(element.getAttribute("no-current-selected-key")); + // read all option and entity-options sub-elements, maintaining order + ArrayList optionSources = new ArrayList(); + List childElements = UtilXml.childElementList(element); + if (childElements.size() > 0) { + for (Element childElement : childElements) { + if ("option".equals(childElement.getTagName())) { + optionSources.add(new SingleOption(childElement, modelFormField)); + } else if ("list-options".equals(childElement.getTagName())) { + optionSources.add(new ListOptions(childElement, modelFormField)); + } else if ("entity-options".equals(childElement.getTagName())) { + optionSources.add(new EntityOptions(childElement, modelFormField)); + } + } + } else { + // this must be added or the multi-form select box options would not show up + optionSources.add(new SingleOption("Y", " ", modelFormField)); + } + optionSources.trimToSize(); + this.optionSources = Collections.unmodifiableList(optionSources); + } + + // Copy constructor. + protected FieldInfoWithOptions(FieldInfoWithOptions original, ModelFormField modelFormField) { + super(original.getFieldSource(), original.getFieldType(), modelFormField); + this.noCurrentSelectedKey = original.noCurrentSelectedKey; + if (original.optionSources.isEmpty()) { + this.optionSources = original.optionSources; + } else { + List optionSources = new ArrayList(original.optionSources.size()); + for (OptionSource source : original.optionSources) { + optionSources.add(source.copy(modelFormField)); + } + this.optionSources = Collections.unmodifiableList(optionSources); + } + } + + protected FieldInfoWithOptions(int fieldSource, int fieldType, List optionSources) { + super(fieldSource, fieldType, null); + this.noCurrentSelectedKey = FlexibleStringExpander.getInstance(""); + this.optionSources = Collections.unmodifiableList(new ArrayList(optionSources)); + } + + public FieldInfoWithOptions(int fieldSource, int fieldType, ModelFormField modelFormField) { + super(fieldSource, fieldType, modelFormField); + this.noCurrentSelectedKey = FlexibleStringExpander.getInstance(""); + this.optionSources = Collections.emptyList(); + } + + public List getAllOptionValues(Map context, Delegator delegator) { + List optionValues = new LinkedList(); + for (OptionSource optionSource : this.optionSources) { + optionSource.addOptionValues(optionValues, context, delegator); + } + return optionValues; + } + + public FlexibleStringExpander getNoCurrentSelectedKey() { + return noCurrentSelectedKey; + } + + public String getNoCurrentSelectedKey(Map context) { + return this.noCurrentSelectedKey.expandString(context); + } + + public List getOptionSources() { + return optionSources; + } + } + + /** + * Models the <file> element. + * + * @see widget-form.xsd + */ + public static class FileField extends TextField { + + public FileField(Element element, ModelFormField modelFormField) { + super(element, modelFormField); + } + + private FileField(FileField original, ModelFormField modelFormField) { + super(original, modelFormField); + } + + public FileField(int fieldSource, ModelFormField modelFormField) { + super(fieldSource, modelFormField); + } + + @Override + public void accept(ModelFieldVisitor visitor) throws Exception { + visitor.visit(this); + } + + @Override + public FieldInfo copy(ModelFormField modelFormField) { + return new FileField(this, modelFormField); + } + + @Override + public void renderFieldString(Appendable writer, Map context, FormStringRenderer formStringRenderer) + throws IOException { + formStringRenderer.renderFileField(writer, context, this); + } + } + + /** + * Models the <hidden> element. + * + * @see widget-form.xsd + */ + public static class HiddenField extends FieldInfo { + private final FlexibleStringExpander value; + + public HiddenField(Element element, ModelFormField modelFormField) { + super(element, modelFormField); + this.value = FlexibleStringExpander.getInstance(element.getAttribute("value")); + } + + private HiddenField(HiddenField original, ModelFormField modelFormField) { + super(original.getFieldSource(), original.getFieldType(), modelFormField); + this.value = original.value; + } + + public HiddenField(int fieldSource, ModelFormField modelFormField) { + super(fieldSource, FieldInfo.HIDDEN, modelFormField); + this.value = FlexibleStringExpander.getInstance(""); + } + + public HiddenField(ModelFormField modelFormField) { + super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.HIDDEN, modelFormField); + this.value = FlexibleStringExpander.getInstance(""); + } + + @Override + public void accept(ModelFieldVisitor visitor) throws Exception { + visitor.visit(this); + } + + @Override + public FieldInfo copy(ModelFormField modelFormField) { + return new HiddenField(this, modelFormField); + } + + public FlexibleStringExpander getValue() { + return value; + } + + public String getValue(Map context) { + if (UtilValidate.isNotEmpty(this.value)) { + String valueEnc = this.value.expandString(context); + UtilCodec.SimpleEncoder simpleEncoder = (UtilCodec.SimpleEncoder) context.get("simpleEncoder"); + if (simpleEncoder != null) { + valueEnc = simpleEncoder.encode(valueEnc); + } + return valueEnc; + } else { + return getModelFormField().getEntry(context); + } + } + + @Override + public void renderFieldString(Appendable writer, Map context, FormStringRenderer formStringRenderer) + throws IOException { + formStringRenderer.renderHiddenField(writer, context, this); + } + } + + /** + * Models the <hyperlink> element. + * + * @see widget-form.xsd + */ + public static class HyperlinkField extends FieldInfo { + + private final boolean alsoHidden; + private final FlexibleStringExpander confirmationMsgExdr; + private final FlexibleStringExpander description; + private final boolean requestConfirmation; + private final Link link; + public HyperlinkField(Element element, ModelFormField modelFormField) { + super(element, modelFormField); + this.alsoHidden = !"false".equals(element.getAttribute("also-hidden")); + this.confirmationMsgExdr = FlexibleStringExpander.getInstance(element.getAttribute("confirmation-message")); + this.description = FlexibleStringExpander.getInstance(element.getAttribute("description")); + this.requestConfirmation = "true".equals(element.getAttribute("request-confirmation")); + this.link = new Link(element); + } + + private HyperlinkField(HyperlinkField original, ModelFormField modelFormField) { + super(original.getFieldSource(), original.getFieldType(), modelFormField); + this.alsoHidden = original.alsoHidden; + this.confirmationMsgExdr = original.confirmationMsgExdr; + this.description = original.description; + this.requestConfirmation = original.requestConfirmation; + this.link = original.link; + } + + @Override + public void accept(ModelFieldVisitor visitor) throws Exception { + visitor.visit(this); + } + + @Override + public FieldInfo copy(ModelFormField modelFormField) { + return new HyperlinkField(this, modelFormField); + } + + public boolean getAlsoHidden() { + return this.alsoHidden; + } + + public String getConfirmation(Map context) { + String message = getConfirmationMsg(context); + if (UtilValidate.isNotEmpty(message)) + return message; + if (getRequestConfirmation()) { + String defaultMessage = UtilProperties.getPropertyValue("general", "default.confirmation.message", + "${uiLabelMap.CommonConfirm}"); + return FlexibleStringExpander.expandString(defaultMessage, context); + } + return ""; + } + + public String getAlternate(Map context) { + if (link.getImage() != null) { + return link.getImage().getAlt(context); + } + return ""; + } + + public String getImageTitle(Map context) { + if (link.getImage() != null) { + return link.getImage().getTitleExdr().expandString(context); + } + return ""; + } + + public String getImageLocation(Map context) { + if (link.getImage() != null) { + return link.getImage().getSrc(context); + } + return ""; + } + + public String getConfirmationMsg(Map context) { + return this.confirmationMsgExdr.expandString(context); + } + + public FlexibleStringExpander getConfirmationMsgExdr() { + return confirmationMsgExdr; + } + + public FlexibleStringExpander getDescription() { + return description; + } + + public String getDescription(Map context) { + return this.description.expandString(context); + } + + public boolean getRequestConfirmation() { + return this.requestConfirmation; + } + + public Link getLink() { + return link; + } + + public AutoEntityParameters getAutoEntityParameters() { + return link.getAutoEntityParameters(); + } + + public AutoServiceParameters getAutoServiceParameters() { + return link.getAutoServiceParameters(); + } + + public boolean getEncode() { + return link.getEncode(); + } + + public boolean getFullPath() { + return link.getFullPath(); + } + + public String getHeight() { + return link.getHeight(); + } + + public String getId(Map context) { + return link.getId(context); + } + + public FlexibleStringExpander getIdExdr() { + return link.getIdExdr(); + } + + public Image getImage() { + return link.getImage(); + } + + public String getLinkType() { + return link.getLinkType(); + } + + public String getName() { + return link.getName(); + } + + public String getName(Map context) { + return link.getName(context); + } + + public FlexibleStringExpander getNameExdr() { + return link.getNameExdr(); + } + + public List getParameterList() { + return link.getParameterList(); + } + + public Map getParameterMap(Map context) { + return link.getParameterMap(context); + } + + public String getPrefix(Map context) { + return link.getPrefix(context); + } + + public FlexibleStringExpander getPrefixExdr() { + return link.getPrefixExdr(); + } + + public boolean getSecure() { + return link.getSecure(); + } + + public Integer getSize() { + return link.getSize(); + } + + public String getStyle(Map context) { + return link.getStyle(context); + } + + public FlexibleStringExpander getStyleExdr() { + return link.getStyleExdr(); + } + + public String getTarget(Map context) { + return link.getTarget(context); + } + + public FlexibleStringExpander getTargetExdr() { + return link.getTargetExdr(); + } + + public String getTargetWindow(Map context) { + return link.getTargetWindow(context); + } + + public FlexibleStringExpander getTargetWindowExdr() { + return link.getTargetWindowExdr(); + } + + public String getText(Map context) { + return link.getText(context); + } + + public FlexibleStringExpander getTextExdr() { + return link.getTextExdr(); + } + + public String getUrlMode() { + return link.getUrlMode(); + } + + public String getWidth() { + return link.getWidth(); + } + + @Override + public void renderFieldString(Appendable writer, Map context, FormStringRenderer formStringRenderer) + throws IOException { + formStringRenderer.renderHyperlinkField(writer, context, this); + } + } + + /** + * Models the <ignored> element. + * + * @see widget-form.xsd + */ + public static class IgnoredField extends FieldInfo { + + public IgnoredField(Element element, ModelFormField modelFormField) { + super(element, modelFormField); + } + + private IgnoredField(IgnoredField original, ModelFormField modelFormField) { + super(original.getFieldSource(), original.getFieldType(), modelFormField); + } + + public IgnoredField(int fieldSource, ModelFormField modelFormField) { + super(fieldSource, FieldInfo.IGNORED, modelFormField); + } + + public IgnoredField(ModelFormField modelFormField) { + super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.IGNORED, modelFormField); + } + + @Override + public void accept(ModelFieldVisitor visitor) throws Exception { + visitor.visit(this); + } + + @Override + public FieldInfo copy(ModelFormField modelFormField) { + return new IgnoredField(this, modelFormField); + } + + @Override + public void renderFieldString(Appendable writer, Map context, FormStringRenderer formStringRenderer) + throws IOException { + formStringRenderer.renderIgnoredField(writer, context, this); + } + } + + /** + * Models the <image> element. + * + * @see widget-form.xsd + */ + public static class ImageField extends FieldInfo { + private final FlexibleStringExpander alternate; + private final FlexibleStringExpander defaultValue; + private final FlexibleStringExpander description; + private final FlexibleStringExpander style; + private final SubHyperlink subHyperlink; + private final FlexibleStringExpander value; + + public ImageField(Element element, ModelFormField modelFormField) { + super(element, modelFormField); + this.alternate = FlexibleStringExpander.getInstance(element.getAttribute("alternate")); + this.defaultValue = FlexibleStringExpander.getInstance(element.getAttribute("default-value")); + this.description = FlexibleStringExpander.getInstance(element.getAttribute("description")); + this.style = FlexibleStringExpander.getInstance(element.getAttribute("style")); + Element subHyperlinkElement = UtilXml.firstChildElement(element, "sub-hyperlink"); + if (subHyperlinkElement != null) { + this.subHyperlink = new SubHyperlink(subHyperlinkElement, modelFormField); + } else { + this.subHyperlink = null; + } + this.value = FlexibleStringExpander.getInstance(element.getAttribute("value")); + } + + public ImageField(ImageField original, ModelFormField modelFormField) { + super(original.getFieldSource(), original.getFieldType(), modelFormField); + this.alternate = original.alternate; + this.defaultValue = original.defaultValue; + this.description = original.description; + this.style = original.style; + if (original.subHyperlink != null) { + this.subHyperlink = new SubHyperlink(original.subHyperlink, modelFormField); + } else { + this.subHyperlink = null; + } + this.value = original.value; + } + + public ImageField(int fieldSource, ModelFormField modelFormField) { + super(fieldSource, FieldInfo.IMAGE, modelFormField); + this.alternate = FlexibleStringExpander.getInstance(""); + this.defaultValue = FlexibleStringExpander.getInstance(""); + this.description = FlexibleStringExpander.getInstance(""); + this.style = FlexibleStringExpander.getInstance(""); + this.subHyperlink = null; + this.value = FlexibleStringExpander.getInstance(""); + } + + public ImageField(ModelFormField modelFormField) { + this(FieldInfo.SOURCE_EXPLICIT, modelFormField); + } + + @Override + public void accept(ModelFieldVisitor visitor) throws Exception { + visitor.visit(this); + } + + @Override + public FieldInfo copy(ModelFormField modelFormField) { + return new ImageField(this, modelFormField); + } + + public FlexibleStringExpander getAlternate() { + return alternate; + } + + public String getAlternate(Map context) { + if (UtilValidate.isNotEmpty(this.alternate)) + return this.alternate.expandString(context); + return ""; + } + + public FlexibleStringExpander getDefaultValue() { + return defaultValue; + } + + public String getDefaultValue(Map context) { + if (this.defaultValue != null) { + return this.defaultValue.expandString(context); + } else { + return ""; + } + } + + public FlexibleStringExpander getDescription() { + return description; + } + + public String getDescription(Map context) { + if (UtilValidate.isNotEmpty(this.description)) + return this.description.expandString(context); + return ""; + } + + public FlexibleStringExpander getStyle() { + return style; + } + + public String getStyle(Map context) { + if (UtilValidate.isNotEmpty(this.style)) + return this.style.expandString(context); + return ""; + } + + public SubHyperlink getSubHyperlink() { + return this.subHyperlink; + } + + public FlexibleStringExpander getValue() { + return value; + } + + public String getValue(Map context) { + if (UtilValidate.isNotEmpty(this.value)) + return this.value.expandString(context); + return getModelFormField().getEntry(context); + } + + @Override + public void renderFieldString(Appendable writer, Map context, FormStringRenderer formStringRenderer) + throws IOException { + formStringRenderer.renderImageField(writer, context, this); + } + } + + /** + * Models the <in-place-editor> element. + * + * @see widget-form.xsd + */ + public static class InPlaceEditor { + private final String cancelControl; + private final String cancelText; + private final String clickToEditText; + private final String cols; + private final Map, Object> fieldMap; + private final String fieldPostCreation; + private final String formClassName; + private final String highlightColor; + private final String highlightEndColor; + private final String hoverClassName; + private final String htmlResponse; + private final String loadingClassName; + private final String loadingText; + private final String okControl; + private final String okText; + private final String paramName; + private final String rows; + private final String savingClassName; + private final String savingText; + private final String submitOnBlur; + private final String textAfterControls; + private final String textBeforeControls; + private final String textBetweenControls; + private final String updateAfterRequestCall; + private final FlexibleStringExpander url; + + public InPlaceEditor(Element element) { + this.cancelControl = element.getAttribute("cancel-control"); + this.cancelText = element.getAttribute("cancel-text"); + this.clickToEditText = element.getAttribute("click-to-edit-text"); + this.fieldPostCreation = element.getAttribute("field-post-creation"); + this.formClassName = element.getAttribute("form-class-name"); + this.highlightColor = element.getAttribute("highlight-color"); + this.highlightEndColor = element.getAttribute("highlight-end-color"); + this.hoverClassName = element.getAttribute("hover-class-name"); + this.htmlResponse = element.getAttribute("html-response"); + this.loadingClassName = element.getAttribute("loading-class-name"); + this.loadingText = element.getAttribute("loading-text"); + this.okControl = element.getAttribute("ok-control"); + this.okText = element.getAttribute("ok-text"); + this.paramName = element.getAttribute("param-name"); + this.savingClassName = element.getAttribute("saving-class-name"); + this.savingText = element.getAttribute("saving-text"); + this.submitOnBlur = element.getAttribute("submit-on-blur"); + this.textBeforeControls = element.getAttribute("text-before-controls"); + this.textAfterControls = element.getAttribute("text-after-controls"); + this.textBetweenControls = element.getAttribute("text-between-controls"); + this.updateAfterRequestCall = element.getAttribute("update-after-request-call"); + Element simpleElement = UtilXml.firstChildElement(element, "simple-editor"); + if (simpleElement != null) { + this.rows = simpleElement.getAttribute("rows"); + this.cols = simpleElement.getAttribute("cols"); + } else { + this.rows = ""; + this.cols = ""; + } + this.fieldMap = EntityFinderUtil.makeFieldMap(element); + this.url = FlexibleStringExpander.getInstance(element.getAttribute("url")); + } + + public String getCancelControl() { + return this.cancelControl; + } + + public String getCancelText() { + return this.cancelText; + } + + public String getClickToEditText() { + return this.clickToEditText; + } + + public String getCols() { + return this.cols; + } + + public Map, Object> getFieldMap() { + return fieldMap; + } + + public Map getFieldMap(Map context) { + Map inPlaceEditorContext = new HashMap(); + EntityFinderUtil.expandFieldMapToContext(this.fieldMap, context, inPlaceEditorContext); + return inPlaceEditorContext; + } + + public String getFieldPostCreation() { + return this.fieldPostCreation; + } + + public String getFormClassName() { + return this.formClassName; + } + + public String getHighlightColor() { + return this.highlightColor; + } + + public String getHighlightEndColor() { + return this.highlightEndColor; + } + + public String getHoverClassName() { + return this.hoverClassName; + } + + public String getHtmlResponse() { + return this.htmlResponse; + } + + public String getLoadingClassName() { + return this.loadingClassName; + } + + public String getLoadingText() { + return this.loadingText; + } + + public String getOkControl() { + return this.okControl; + } + + public String getOkText() { + return this.okText; + } + + public String getParamName() { + return this.paramName; + } + + public String getRows() { + return this.rows; + } + + public String getSavingClassName() { + return this.savingClassName; + } + + public String getSavingText() { + return this.savingText; + } + + public String getSubmitOnBlur() { + return this.submitOnBlur; + } + + public String getTextAfterControls() { + return this.textAfterControls; + } + + public String getTextBeforeControls() { + return this.textBeforeControls; + } + + public String getTextBetweenControls() { + return this.textBetweenControls; + } + + public String getUpdateAfterRequestCall() { + return this.updateAfterRequestCall; + } + + public FlexibleStringExpander getUrl() { + return url; + } + + public String getUrl(Map context) { + if (this.url != null) { + return this.url.expandString(context); + } else { + return ""; + } + } + } + + /** + * Models the <list-options> element. + * + * @see widget-form.xsd + */ + public static class ListOptions extends OptionSource { + private final FlexibleStringExpander description; + private final FlexibleMapAccessor keyAcsr; + private final FlexibleMapAccessor> listAcsr; + private final String listEntryName; + + public ListOptions(Element optionElement, ModelFormField modelFormField) { + super(modelFormField); + this.listEntryName = optionElement.getAttribute("list-entry-name"); + this.keyAcsr = FlexibleMapAccessor.getInstance(optionElement.getAttribute("key-name")); + this.listAcsr = FlexibleMapAccessor.getInstance(optionElement.getAttribute("list-name")); + this.description = FlexibleStringExpander.getInstance(optionElement.getAttribute("description")); + } + + private ListOptions(ListOptions original, ModelFormField modelFormField) { + super(modelFormField); + this.listAcsr = original.listAcsr; + this.listEntryName = original.listEntryName; + this.keyAcsr = original.keyAcsr; + this.description = original.description; + } + + public ListOptions(String listName, String listEntryName, String keyName, String description, + ModelFormField modelFormField) { + super(modelFormField); + this.listAcsr = FlexibleMapAccessor.getInstance(listName); + this.listEntryName = listEntryName; + this.keyAcsr = FlexibleMapAccessor.getInstance(keyName); + this.description = FlexibleStringExpander.getInstance(description); + } + + @Override + public void addOptionValues(List optionValues, Map context, Delegator delegator) { + List dataList = UtilGenerics.checkList(this.listAcsr.get(context)); + if (dataList != null && dataList.size() != 0) { + for (Object data : dataList) { + Map localContext = new HashMap(); + localContext.putAll(context); + if (UtilValidate.isNotEmpty(this.listEntryName)) { + localContext.put(this.listEntryName, data); + } else { + Map dataMap = UtilGenerics.checkMap(data); + localContext.putAll(dataMap); + } + Object keyObj = keyAcsr.get(localContext); + String key = null; + if (keyObj instanceof String) { + key = (String) keyObj; + } else { + try { + key = (String) ObjectType.simpleTypeConvert(keyObj, "String", null, null); + } catch (GeneralException e) { + String errMsg = "Could not convert field value for the field: [" + this.keyAcsr.toString() + + "] to String for the value [" + keyObj + "]: " + e.toString(); + Debug.logError(e, errMsg, module); + } + } + optionValues.add(new OptionValue(key, description.expandString(localContext))); + } + } + } + + @Override + public OptionSource copy(ModelFormField modelFormField) { + return new ListOptions(this, modelFormField); + } + + public FlexibleStringExpander getDescription() { + return description; + } + + public FlexibleMapAccessor getKeyAcsr() { + return keyAcsr; + } + + public FlexibleMapAccessor> getListAcsr() { + return listAcsr; + } + + public String getListEntryName() { + return listEntryName; + } + } + + /** + * Models the <lookup> element. + * + * @see widget-form.xsd + */ + public static class LookupField extends TextField { + private final String descriptionFieldName; + private final String fadeBackground; + private final FlexibleStringExpander formName; + private final String initiallyCollapsed; + private final String lookupHeight; + private final String lookupPosition; + private final String lookupPresentation; + private final String lookupWidth; + private final String showDescription; + private final String targetParameter; + + public LookupField(Element element, ModelFormField modelFormField) { + super(element, modelFormField); + this.descriptionFieldName = element.getAttribute("description-field-name"); + this.fadeBackground = element.getAttribute("fade-background"); + this.formName = FlexibleStringExpander.getInstance(element.getAttribute("target-form-name")); + this.initiallyCollapsed = element.getAttribute("initially-collapsed"); + this.lookupHeight = element.getAttribute("height"); + this.lookupPosition = element.getAttribute("position"); + this.lookupPresentation = element.getAttribute("presentation"); + this.lookupWidth = element.getAttribute("width"); + this.showDescription = element.getAttribute("show-description"); + this.targetParameter = element.getAttribute("target-parameter"); + } + + public LookupField(int fieldSource, ModelFormField modelFormField) { + super(fieldSource, modelFormField); + this.descriptionFieldName = ""; + this.fadeBackground = ""; + this.formName = FlexibleStringExpander.getInstance(""); + this.initiallyCollapsed = ""; + this.lookupHeight = ""; + this.lookupPosition = ""; + this.lookupPresentation = ""; + this.lookupWidth = ""; + this.showDescription = ""; + this.targetParameter = ""; + } + + public LookupField(LookupField original, ModelFormField modelFormField) { + super(original, modelFormField); + this.descriptionFieldName = original.descriptionFieldName; + this.fadeBackground = original.fadeBackground; + this.formName = original.formName; + this.initiallyCollapsed = original.initiallyCollapsed; + this.lookupHeight = original.lookupHeight; + this.lookupPosition = original.lookupPosition; + this.lookupPresentation = original.lookupPresentation; + this.lookupWidth = original.lookupWidth; + this.showDescription = original.showDescription; + this.targetParameter = original.targetParameter; + } + + @Override + public void accept(ModelFieldVisitor visitor) throws Exception { + visitor.visit(this); + } + + @Override + public FieldInfo copy(ModelFormField modelFormField) { + return new LookupField(this, modelFormField); + } + + public String getDescriptionFieldName() { + return this.descriptionFieldName; + } + + public String getFadeBackground() { + return this.fadeBackground; + } + + public FlexibleStringExpander getFormName() { + return formName; + } + + public String getFormName(Map context) { + return this.formName.expandString(context); + } + + //initially-collapsed status + public boolean getInitiallyCollapsed() { + return "true".equals(this.initiallyCollapsed); + } + + public String getLookupHeight() { + return this.lookupHeight; + } + + public String getLookupPosition() { + return this.lookupPosition; + } + + public String getLookupPresentation() { + return this.lookupPresentation; + } + + public String getLookupWidth() { + return this.lookupWidth; + } + + public Boolean getShowDescription() { + return UtilValidate.isEmpty(this.showDescription) ? null : "true".equals(this.showDescription); + } + + public String getTargetParameter() { + return targetParameter; + } + + public List getTargetParameterList() { + List paramList = new LinkedList(); + if (UtilValidate.isNotEmpty(this.targetParameter)) { + StringTokenizer stk = new StringTokenizer(this.targetParameter, ", "); + while (stk.hasMoreTokens()) { + paramList.add(stk.nextToken()); + } + } + return paramList; + } + + @Override + public void renderFieldString(Appendable writer, Map context, FormStringRenderer formStringRenderer) + throws IOException { + formStringRenderer.renderLookupField(writer, context, this); + } + } + + public static abstract class OptionSource { + + private final ModelFormField modelFormField; + + protected OptionSource(ModelFormField modelFormField) { + this.modelFormField = modelFormField; + } + + public abstract void addOptionValues(List optionValues, Map context, Delegator delegator); + + public abstract OptionSource copy(ModelFormField modelFormField); + + public ModelFormField getModelFormField() { + return modelFormField; + } + } + + public static class OptionValue { + private final String description; + private final String key; + + public OptionValue(String key, String description) { + this.key = key; + this.description = description; + } + + public String getDescription() { + return description; + } + + public String getKey() { + return key; + } + } + + /** + * Models the <password> element. + * + * @see widget-form.xsd + */ + public static class PasswordField extends TextField { + + public PasswordField(Element element, ModelFormField modelFormField) { + super(element, modelFormField); + } + + public PasswordField(int fieldSource, ModelFormField modelFormField) { + super(fieldSource, modelFormField); + } + + private PasswordField(PasswordField original, ModelFormField modelFormField) { + super(original, modelFormField); + } + + @Override + public void accept(ModelFieldVisitor visitor) throws Exception { + visitor.visit(this); + } + + @Override + public FieldInfo copy(ModelFormField modelFormField) { + return new PasswordField(this, modelFormField); + } + + @Override + public void renderFieldString(Appendable writer, Map context, FormStringRenderer formStringRenderer) + throws IOException { + formStringRenderer.renderPasswordField(writer, context, this); + } + } + + /** + * Models the <radio> element. + * + * @see widget-form.xsd + */ + public static class RadioField extends FieldInfoWithOptions { + + public RadioField(Element element, ModelFormField modelFormField) { + super(element, modelFormField); + } + + public RadioField(int fieldSource, ModelFormField modelFormField) { + super(fieldSource, FieldInfo.RADIO, modelFormField); + } + + public RadioField(ModelFormField modelFormField) { + super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.RADIO, modelFormField); + } + + private RadioField(RadioField original, ModelFormField modelFormField) { + super(original, modelFormField); + } + + @Override + public void accept(ModelFieldVisitor visitor) throws Exception { + visitor.visit(this); + } + + @Override + public FieldInfo copy(ModelFormField modelFormField) { + return new RadioField(this, modelFormField); + } + + @Override + public void renderFieldString(Appendable writer, Map context, FormStringRenderer formStringRenderer) + throws IOException { + formStringRenderer.renderRadioField(writer, context, this); + } + } + + /** + * Models the <range-find> element. + * + * @see widget-form.xsd + */ + public static class RangeFindField extends TextField { + private final String defaultOptionFrom; + private final String defaultOptionThru; + + public RangeFindField(Element element, ModelFormField modelFormField) { + super(element, modelFormField); + this.defaultOptionFrom = element.getAttribute("default-option-from"); + this.defaultOptionThru = element.getAttribute("default-option-thru"); + } + + public RangeFindField(int fieldSource, int size, ModelFormField modelFormField) { + super(fieldSource, size, null, modelFormField); + this.defaultOptionFrom = "greaterThanEqualTo"; + this.defaultOptionThru = "lessThanEqualTo"; + } + + private RangeFindField(RangeFindField original, ModelFormField modelFormField) { + super(original, modelFormField); + this.defaultOptionFrom = original.defaultOptionFrom; + this.defaultOptionThru = original.defaultOptionThru; + } + + @Override + public void accept(ModelFieldVisitor visitor) throws Exception { + visitor.visit(this); + } + + @Override + public FieldInfo copy(ModelFormField modelFormField) { + return new RangeFindField(this, modelFormField); + } + + public String getDefaultOptionFrom() { + return this.defaultOptionFrom; + } + + public String getDefaultOptionThru() { + return this.defaultOptionThru; + } + + @Override + public void renderFieldString(Appendable writer, Map context, FormStringRenderer formStringRenderer) + throws IOException { + formStringRenderer.renderRangeFindField(writer, context, this); + } + } + + /** + * Models the <reset> element. + * + * @see widget-form.xsd + */ + public static class ResetField extends FieldInfo { + + public ResetField(Element element, ModelFormField modelFormField) { + super(element, modelFormField); + } + + public ResetField(int fieldSource, ModelFormField modelFormField) { + super(fieldSource, FieldInfo.RESET, modelFormField); + } + + public ResetField(ModelFormField modelFormField) { + super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.RESET, modelFormField); + } + + private ResetField(ResetField original, ModelFormField modelFormField) { + super(original.getFieldSource(), original.getFieldType(), modelFormField); + } + + @Override + public void accept(ModelFieldVisitor visitor) throws Exception { + visitor.visit(this); + } + + @Override + public FieldInfo copy(ModelFormField modelFormField) { + return new ResetField(this, modelFormField); + } + + @Override + public void renderFieldString(Appendable writer, Map context, FormStringRenderer formStringRenderer) + throws IOException { + formStringRenderer.renderResetField(writer, context, this); + } + } + + /** + * Models the <option> element. + * + * @see widget-form.xsd + */ + public static class SingleOption extends OptionSource { + private final FlexibleStringExpander description; + private final FlexibleStringExpander key; + + public SingleOption(Element optionElement, ModelFormField modelFormField) { + super(modelFormField); + this.key = FlexibleStringExpander.getInstance(optionElement.getAttribute("key")); + this.description = FlexibleStringExpander.getInstance(UtilXml.checkEmpty(optionElement.getAttribute("description"), + optionElement.getAttribute("key"))); + } + + private SingleOption(SingleOption original, ModelFormField modelFormField) { + super(modelFormField); + this.key = original.key; + this.description = original.description; + } + + public SingleOption(String key, String description, ModelFormField modelFormField) { + super(modelFormField); + this.key = FlexibleStringExpander.getInstance(key); + this.description = FlexibleStringExpander.getInstance(UtilXml.checkEmpty(description, key)); + } + + @Override + public void addOptionValues(List optionValues, Map context, Delegator delegator) { + optionValues.add(new OptionValue(key.expandString(context), description.expandString(context))); + } + + @Override + public OptionSource copy(ModelFormField modelFormField) { + return new SingleOption(this, modelFormField); + } + + public FlexibleStringExpander getDescription() { + return description; + } + + public FlexibleStringExpander getKey() { + return key; + } + } + + /** + * Models the <sub-hyperlink> element. + * + * @see widget-form.xsd + */ + public static class SubHyperlink { + private final FlexibleStringExpander description; + private final FlexibleStringExpander useWhen; + private final Link link; + private final ModelFormField modelFormField; + + public SubHyperlink(Element element, ModelFormField modelFormField) { + this.description = FlexibleStringExpander.getInstance(element.getAttribute("description")); + this.useWhen = FlexibleStringExpander.getInstance(element.getAttribute("use-when")); + this.link = new Link(element); + this.modelFormField = modelFormField; + } + + public SubHyperlink(SubHyperlink original, ModelFormField modelFormField) { + this.description = original.description; + this.useWhen = original.useWhen; + this.link = original.link; + this.modelFormField = modelFormField; + } + + public AutoEntityParameters getAutoEntityParameters() { + return link.getAutoEntityParameters(); + } + + public AutoServiceParameters getAutoServiceParameters() { + return link.getAutoServiceParameters(); + } + + public boolean getEncode() { + return link.getEncode(); + } + + public boolean getFullPath() { + return link.getFullPath(); + } + + public String getHeight() { + return link.getHeight(); + } + + public String getId(Map context) { + return link.getId(context); + } + + public FlexibleStringExpander getIdExdr() { + return link.getIdExdr(); + } + + public Image getImage() { + return link.getImage(); + } + + public String getLinkType() { + return link.getLinkType(); + } + + public String getName() { + return link.getName(); + } + + public String getName(Map context) { + return link.getName(context); + } + + public FlexibleStringExpander getNameExdr() { + return link.getNameExdr(); + } + + public List getParameterList() { + return link.getParameterList(); + } + + public Map getParameterMap(Map context) { + return link.getParameterMap(context); + } + + public String getPrefix(Map context) { + return link.getPrefix(context); + } + + public FlexibleStringExpander getPrefixExdr() { + return link.getPrefixExdr(); + } + + public boolean getSecure() { + return link.getSecure(); + } + + public Integer getSize() { + return link.getSize(); + } + + public String getStyle(Map context) { + return link.getStyle(context); + } + + public FlexibleStringExpander getStyleExdr() { + return link.getStyleExdr(); + } + + public String getTarget(Map context) { + return link.getTarget(context); + } + + public FlexibleStringExpander getTargetExdr() { + return link.getTargetExdr(); + } + + public String getTargetWindow(Map context) { + return link.getTargetWindow(context); + } + + public FlexibleStringExpander getTargetWindowExdr() { + return link.getTargetWindowExdr(); + } + + public String getText(Map context) { + return link.getText(context); + } + + public FlexibleStringExpander getTextExdr() { + return link.getTextExdr(); + } + + public String getUrlMode() { + return link.getUrlMode(); + } + + public String getWidth() { + return link.getWidth(); + } + + public FlexibleStringExpander getDescription() { + return description; + } + + public String getDescription(Map context) { + return description.expandString(context); + } + + public FlexibleStringExpander getUseWhen() { + return useWhen; + } + + public Link getLink() { + return link; + } + + public String getUseWhen(Map context) { + return this.useWhen.expandString(context); + } + + public ModelFormField getModelFormField() { + return modelFormField; + } + + public boolean shouldUse(Map context) { + boolean shouldUse = true; + String useWhen = this.getUseWhen(context); + if (UtilValidate.isNotEmpty(useWhen)) { + try { + Interpreter bsh = (Interpreter) context.get("bshInterpreter"); + if (bsh == null) { + bsh = BshUtil.makeInterpreter(context); + context.put("bshInterpreter", bsh); + } + + Object retVal = bsh.eval(StringUtil.convertOperatorSubstitutions(useWhen)); + + // retVal should be a Boolean, if not something weird is up... + if (retVal instanceof Boolean) { + Boolean boolVal = (Boolean) retVal; + shouldUse = boolVal.booleanValue(); + } else { + throw new IllegalArgumentException("Return value from target condition eval was not a Boolean: " + + retVal.getClass().getName() + " [" + retVal + "]"); + } + } catch (EvalError e) { + String errmsg = "Error evaluating BeanShell target conditions"; + Debug.logError(e, errmsg, module); + throw new IllegalArgumentException(errmsg); + } + } + return shouldUse; + } + } + + /** + * Models the <submit> element. + * + * @see widget-form.xsd + */ + public static class SubmitField extends FieldInfo { + private final FlexibleStringExpander backgroundSubmitRefreshTargetExdr; + private final String buttonType; + private final FlexibleStringExpander confirmationMsgExdr; + private final FlexibleStringExpander imageLocation; + private final boolean requestConfirmation; + + public SubmitField(Element element, ModelFormField modelFormField) { + super(element, modelFormField); + this.backgroundSubmitRefreshTargetExdr = FlexibleStringExpander.getInstance(element + .getAttribute("background-submit-refresh-target")); + this.buttonType = element.getAttribute("button-type"); + this.confirmationMsgExdr = FlexibleStringExpander.getInstance(element.getAttribute("confirmation-message")); + this.imageLocation = FlexibleStringExpander.getInstance(element.getAttribute("image-location")); + this.requestConfirmation = "true".equals(element.getAttribute("request-confirmation")); + } + + public SubmitField(int fieldInfo, ModelFormField modelFormField) { + super(fieldInfo, FieldInfo.SUBMIT, modelFormField); + this.backgroundSubmitRefreshTargetExdr = FlexibleStringExpander.getInstance(""); + this.buttonType = ""; + this.confirmationMsgExdr = FlexibleStringExpander.getInstance(""); + this.imageLocation = FlexibleStringExpander.getInstance(""); + this.requestConfirmation = false; + } + + public SubmitField(ModelFormField modelFormField) { + this(FieldInfo.SOURCE_EXPLICIT, modelFormField); + } + + private SubmitField(SubmitField original, ModelFormField modelFormField) { + super(original.getFieldSource(), original.getFieldType(), modelFormField); + this.buttonType = original.buttonType; + this.imageLocation = original.imageLocation; + this.backgroundSubmitRefreshTargetExdr = original.backgroundSubmitRefreshTargetExdr; + this.requestConfirmation = original.requestConfirmation; + this.confirmationMsgExdr = original.confirmationMsgExdr; + } + + @Override + public void accept(ModelFieldVisitor visitor) throws Exception { + visitor.visit(this); + } + + @Override + public FieldInfo copy(ModelFormField modelFormField) { + return new SubmitField(this, modelFormField); + } + + public String getBackgroundSubmitRefreshTarget(Map context) { + return this.backgroundSubmitRefreshTargetExdr.expandString(context); + } + + public FlexibleStringExpander getBackgroundSubmitRefreshTargetExdr() { + return backgroundSubmitRefreshTargetExdr; + } + + public String getButtonType() { + return buttonType; + } + + public String getConfirmation(Map context) { + String message = getConfirmationMsg(context); + if (UtilValidate.isNotEmpty(message)) + return message; + else if (getRequestConfirmation()) { + String defaultMessage = UtilProperties.getPropertyValue("general", "default.confirmation.message", + "${uiLabelMap.CommonConfirm}"); + return FlexibleStringExpander.expandString(defaultMessage, context); + } + return ""; + } + + public String getConfirmationMsg(Map context) { + return this.confirmationMsgExdr.expandString(context); + } + + public FlexibleStringExpander getConfirmationMsgExdr() { + return confirmationMsgExdr; + } + + public FlexibleStringExpander getImageLocation() { + return imageLocation; + } + + public String getImageLocation(Map context) { + return this.imageLocation.expandString(context); + } + + public boolean getRequestConfirmation() { + return this.requestConfirmation; + } + + @Override + public void renderFieldString(Appendable writer, Map context, FormStringRenderer formStringRenderer) + throws IOException { + formStringRenderer.renderSubmitField(writer, context, this); + } + } + + /** + * Models the <textarea> element. + * + * @see widget-form.xsd + */ + public static class TextareaField extends FieldInfo { + private final int cols; + private final FlexibleStringExpander defaultValue; + private final boolean readOnly; + private final int rows; + private final FlexibleStringExpander visualEditorButtons; + private final boolean visualEditorEnable; + + public TextareaField(Element element, ModelFormField modelFormField) { + super(element, modelFormField); + int cols = 60; + String colsStr = element.getAttribute("cols"); + if (!colsStr.isEmpty()) { + try { + cols = Integer.parseInt(colsStr); + } catch (Exception e) { + if (UtilValidate.isNotEmpty(colsStr)) { + Debug.logError("Could not parse the size value of the text element: [" + colsStr + + "], setting to default of " + cols, module); + } + } + } + this.cols = cols; + this.defaultValue = FlexibleStringExpander.getInstance(element.getAttribute("default-value")); + this.readOnly = "true".equals(element.getAttribute("read-only")); + int rows = 2; + String rowsStr = element.getAttribute("rows"); + if (!rowsStr.isEmpty()) { + try { + rows = Integer.parseInt(rowsStr); + } catch (Exception e) { + if (UtilValidate.isNotEmpty(rowsStr)) { + Debug.logError("Could not parse the size value of the text element: [" + rowsStr + + "], setting to default of " + rows, module); + } + } + } + this.rows = rows; + this.visualEditorButtons = FlexibleStringExpander.getInstance(element.getAttribute("visual-editor-buttons")); + this.visualEditorEnable = "true".equals(element.getAttribute("visual-editor-enable")); + } + + public TextareaField(int fieldSource, ModelFormField modelFormField) { + super(fieldSource, FieldInfo.TEXTAREA, modelFormField); + this.cols = 60; + this.defaultValue = FlexibleStringExpander.getInstance(""); + this.readOnly = false; + this.rows = 2; + this.visualEditorButtons = FlexibleStringExpander.getInstance(""); + this.visualEditorEnable = false; + } + + public TextareaField(ModelFormField modelFormField) { + this(FieldInfo.SOURCE_EXPLICIT, modelFormField); + } + + private TextareaField(TextareaField original, ModelFormField modelFormField) { + super(original.getFieldSource(), original.getFieldType(), modelFormField); + this.defaultValue = original.defaultValue; + this.visualEditorEnable = original.visualEditorEnable; + this.visualEditorButtons = original.visualEditorButtons; + this.readOnly = original.readOnly; + this.cols = original.cols; + this.rows = original.rows; + } + + @Override + public void accept(ModelFieldVisitor visitor) throws Exception { + visitor.visit(this); + } + + @Override + public FieldInfo copy(ModelFormField modelFormField) { + return new TextareaField(this, modelFormField); + } + + public int getCols() { + return cols; + } + + public FlexibleStringExpander getDefaultValue() { + return defaultValue; + } + + public String getDefaultValue(Map context) { + if (this.defaultValue != null) { + return this.defaultValue.expandString(context); + } else { + return ""; + } + } + + public int getRows() { + return rows; + } + + public FlexibleStringExpander getVisualEditorButtons() { + return visualEditorButtons; + } + + public String getVisualEditorButtons(Map context) { + return this.visualEditorButtons.expandString(context); + } + + public boolean getVisualEditorEnable() { + return this.visualEditorEnable; + } + + public boolean isReadOnly() { + return readOnly; + } + + @Override + public void renderFieldString(Appendable writer, Map context, FormStringRenderer formStringRenderer) + throws IOException { + formStringRenderer.renderTextareaField(writer, context, this); + } + } + + /** + * Models the <text> element. + * + * @see widget-form.xsd + */ + public static class TextField extends FieldInfo { + private final boolean clientAutocompleteField; + private final FlexibleStringExpander defaultValue; + private final boolean disabled; + private final String mask; + private final Integer maxlength; + private final FlexibleStringExpander placeholder; + private final boolean readonly; + private final int size; + private final SubHyperlink subHyperlink; + + public TextField(Element element, ModelFormField modelFormField) { + super(element, modelFormField); + this.clientAutocompleteField = !"false".equals(element.getAttribute("client-autocomplete-field")); + this.defaultValue = FlexibleStringExpander.getInstance(element.getAttribute("default-value")); + this.disabled = "true".equals(element.getAttribute("disabled")); + this.mask = element.getAttribute("mask"); + Integer maxlength = null; + String maxlengthStr = element.getAttribute("maxlength"); + if (!maxlengthStr.isEmpty()) { + try { + maxlength = Integer.valueOf(maxlengthStr); + } catch (Exception e) { + Debug.logError("Could not parse the max-length value of the text element: [" + maxlengthStr + + "], setting to null; default of no maxlength will be used", module); + } + } + this.maxlength = maxlength; + this.placeholder = FlexibleStringExpander.getInstance(element.getAttribute("placeholder")); + this.readonly = "true".equals(element.getAttribute("read-only")); + int size = 25; + String sizeStr = element.getAttribute("size"); + if (!sizeStr.isEmpty()) { + try { + size = Integer.parseInt(sizeStr); + } catch (Exception e) { + Debug.logError("Could not parse the size value of the text element: [" + sizeStr + + "], setting to the default of " + size, module); + } + } + this.size = size; + Element subHyperlinkElement = UtilXml.firstChildElement(element, "sub-hyperlink"); + if (subHyperlinkElement != null) { + this.subHyperlink = new SubHyperlink(subHyperlinkElement, this.getModelFormField()); + } else { + this.subHyperlink = null; + } + } + + protected TextField(int fieldSource, int size, Integer maxlength, ModelFormField modelFormField) { + super(fieldSource, FieldInfo.TEXT, modelFormField); + this.clientAutocompleteField = true; + this.defaultValue = FlexibleStringExpander.getInstance(""); + this.disabled = false; + this.mask = ""; + this.maxlength = maxlength; + this.placeholder = FlexibleStringExpander.getInstance(""); + this.readonly = false; + this.size = size; + this.subHyperlink = null; + } + + private TextField(int fieldSource, int fieldType, ModelFormField modelFormField) { + super(fieldSource, fieldType, modelFormField); + this.clientAutocompleteField = true; + this.defaultValue = FlexibleStringExpander.getInstance(""); + this.disabled = false; + this.mask = ""; + this.maxlength = null; + this.placeholder = FlexibleStringExpander.getInstance(""); + this.readonly = false; + this.size = 25; + this.subHyperlink = null; + } + + public TextField(int fieldSource, ModelFormField modelFormField) { + this(fieldSource, FieldInfo.TEXT, modelFormField); + } + + public TextField(ModelFormField modelFormField) { + this(FieldInfo.SOURCE_EXPLICIT, FieldInfo.TEXT, modelFormField); + } + + protected TextField(TextField original, ModelFormField modelFormField) { + super(original.getFieldSource(), original.getFieldType(), modelFormField); + this.clientAutocompleteField = original.clientAutocompleteField; + this.defaultValue = original.defaultValue; + this.mask = original.mask; + this.placeholder = original.placeholder; + this.size = original.size; + this.maxlength = original.maxlength; + this.disabled = original.disabled; + this.readonly = original.readonly; + if (original.subHyperlink != null) { + this.subHyperlink = new SubHyperlink(original.subHyperlink, modelFormField); + } else { + this.subHyperlink = null; + } + } + + @Override + public void accept(ModelFieldVisitor visitor) throws Exception { + visitor.visit(this); + } + + @Override + public FieldInfo copy(ModelFormField modelFormField) { + return new TextField(this, modelFormField); + } + + public boolean getClientAutocompleteField() { + return this.clientAutocompleteField; + } + + public FlexibleStringExpander getDefaultValue() { + return defaultValue; + } + + public String getDefaultValue(Map context) { + if (this.defaultValue != null) { + return this.defaultValue.expandString(context); + } else { + return ""; + } + } + + public boolean getDisabled() { + return this.disabled; + } + + public String getMask() { + return this.mask; + } + + public Integer getMaxlength() { + return maxlength; + } + + public FlexibleStringExpander getPlaceholder() { + return placeholder; + } + + public String getPlaceholder(Map context) { + return this.placeholder.expandString(context); + } + + public boolean getReadonly() { + return this.readonly; + } + + public int getSize() { + return size; + } + + public SubHyperlink getSubHyperlink() { + return this.subHyperlink; + } + + @Override + public void renderFieldString(Appendable writer, Map context, FormStringRenderer formStringRenderer) + throws IOException { + formStringRenderer.renderTextField(writer, context, this); + } + } + + /** + * Models the <text-find> element. + * + * @see widget-form.xsd + */ + public static class TextFindField extends TextField { + private final String defaultOption; + private final boolean hideIgnoreCase; + private final boolean hideOptions; + private final boolean ignoreCase; + + public TextFindField(Element element, ModelFormField modelFormField) { + super(element, modelFormField); + if (element.hasAttribute("default-option")) { + this.defaultOption = element.getAttribute("default-option"); + } else { + this.defaultOption = UtilProperties.getPropertyValue("widget", "widget.form.defaultTextFindOption", "contains"); + } + this.hideIgnoreCase = "true".equals(element.getAttribute("hide-options")) + || "ignore-case".equals(element.getAttribute("hide-options")) ? true : false; + this.hideOptions = "true".equals(element.getAttribute("hide-options")) + || "options".equals(element.getAttribute("hide-options")) ? true : false; + this.ignoreCase = "true".equals(element.getAttribute("ignore-case")); + } + + public TextFindField(int fieldSource, int size, Integer maxlength, ModelFormField modelFormField) { + super(fieldSource, size, maxlength, modelFormField); + this.defaultOption = UtilProperties.getPropertyValue("widget", "widget.form.defaultTextFindOption", "contains"); + this.hideIgnoreCase = false; + this.hideOptions = false; + this.ignoreCase = true; + } + + public TextFindField(int fieldSource, ModelFormField modelFormField) { + super(fieldSource, modelFormField); + this.defaultOption = UtilProperties.getPropertyValue("widget", "widget.form.defaultTextFindOption", "contains"); + this.hideIgnoreCase = false; + this.hideOptions = false; + this.ignoreCase = true; + } + + private TextFindField(TextFindField original, ModelFormField modelFormField) { + super(original, modelFormField); + this.ignoreCase = original.ignoreCase; + this.hideIgnoreCase = original.hideIgnoreCase; + this.defaultOption = original.defaultOption; + this.hideOptions = original.hideOptions; + } + + @Override + public void accept(ModelFieldVisitor visitor) throws Exception { + visitor.visit(this); + } + + @Override + public FieldInfo copy(ModelFormField modelFormField) { + return new TextFindField(this, modelFormField); + } + + public String getDefaultOption() { + return this.defaultOption; + } + + public boolean getHideIgnoreCase() { + return this.hideIgnoreCase; + } + + public boolean getHideOptions() { + return this.hideOptions; + } + + public boolean getIgnoreCase() { + return this.ignoreCase; + } + + @Override + public void renderFieldString(Appendable writer, Map context, FormStringRenderer formStringRenderer) + throws IOException { + formStringRenderer.renderTextFindField(writer, context, this); + } + } +} diff --git a/framework/widget/src/org/ofbiz/widget/form/ModelFormFieldBuilder.java b/framework/widget/src/org/ofbiz/widget/model/ModelFormFieldBuilder.java similarity index 94% rename from framework/widget/src/org/ofbiz/widget/form/ModelFormFieldBuilder.java rename to framework/widget/src/org/ofbiz/widget/model/ModelFormFieldBuilder.java index e77d8d5db5..be52bd77ad 100644 --- a/framework/widget/src/org/ofbiz/widget/form/ModelFormFieldBuilder.java +++ b/framework/widget/src/org/ofbiz/widget/model/ModelFormFieldBuilder.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. *******************************************************************************/ -package org.ofbiz.widget.form; +package org.ofbiz.widget.model; import java.util.ArrayList; import java.util.List; @@ -35,29 +35,29 @@ import org.ofbiz.service.DispatchContext; import org.ofbiz.service.GenericServiceException; import org.ofbiz.service.ModelParam; import org.ofbiz.service.ModelService; -import org.ofbiz.widget.form.ModelForm.UpdateArea; -import org.ofbiz.widget.form.ModelFormField.CheckField; -import org.ofbiz.widget.form.ModelFormField.ContainerField; -import org.ofbiz.widget.form.ModelFormField.DateFindField; -import org.ofbiz.widget.form.ModelFormField.DateTimeField; -import org.ofbiz.widget.form.ModelFormField.DisplayEntityField; -import org.ofbiz.widget.form.ModelFormField.DisplayField; -import org.ofbiz.widget.form.ModelFormField.DropDownField; -import org.ofbiz.widget.form.ModelFormField.FileField; -import org.ofbiz.widget.form.ModelFormField.HiddenField; -import org.ofbiz.widget.form.ModelFormField.HyperlinkField; -import org.ofbiz.widget.form.ModelFormField.IgnoredField; -import org.ofbiz.widget.form.ModelFormField.ImageField; -import org.ofbiz.widget.form.ModelFormField.LookupField; -import org.ofbiz.widget.form.ModelFormField.OptionSource; -import org.ofbiz.widget.form.ModelFormField.PasswordField; -import org.ofbiz.widget.form.ModelFormField.RadioField; -import org.ofbiz.widget.form.ModelFormField.RangeFindField; -import org.ofbiz.widget.form.ModelFormField.ResetField; -import org.ofbiz.widget.form.ModelFormField.SubmitField; -import org.ofbiz.widget.form.ModelFormField.TextField; -import org.ofbiz.widget.form.ModelFormField.TextFindField; -import org.ofbiz.widget.form.ModelFormField.TextareaField; +import org.ofbiz.widget.model.ModelForm.UpdateArea; +import org.ofbiz.widget.model.ModelFormField.CheckField; +import org.ofbiz.widget.model.ModelFormField.ContainerField; +import org.ofbiz.widget.model.ModelFormField.DateFindField; +import org.ofbiz.widget.model.ModelFormField.DateTimeField; +import org.ofbiz.widget.model.ModelFormField.DisplayEntityField; +import org.ofbiz.widget.model.ModelFormField.DisplayField; +import org.ofbiz.widget.model.ModelFormField.DropDownField; +import org.ofbiz.widget.model.ModelFormField.FileField; +import org.ofbiz.widget.model.ModelFormField.HiddenField; +import org.ofbiz.widget.model.ModelFormField.HyperlinkField; +import org.ofbiz.widget.model.ModelFormField.IgnoredField; +import org.ofbiz.widget.model.ModelFormField.ImageField; +import org.ofbiz.widget.model.ModelFormField.LookupField; +import org.ofbiz.widget.model.ModelFormField.OptionSource; +import org.ofbiz.widget.model.ModelFormField.PasswordField; +import org.ofbiz.widget.model.ModelFormField.RadioField; +import org.ofbiz.widget.model.ModelFormField.RangeFindField; +import org.ofbiz.widget.model.ModelFormField.ResetField; +import org.ofbiz.widget.model.ModelFormField.SubmitField; +import org.ofbiz.widget.model.ModelFormField.TextField; +import org.ofbiz.widget.model.ModelFormField.TextFindField; +import org.ofbiz.widget.model.ModelFormField.TextareaField; import org.w3c.dom.Element; /** diff --git a/framework/widget/src/org/ofbiz/widget/menu/ModelMenu.java b/framework/widget/src/org/ofbiz/widget/model/ModelMenu.java similarity index 97% rename from framework/widget/src/org/ofbiz/widget/menu/ModelMenu.java rename to framework/widget/src/org/ofbiz/widget/model/ModelMenu.java index 44fc162a59..7d98c208b3 100644 --- a/framework/widget/src/org/ofbiz/widget/menu/ModelMenu.java +++ b/framework/widget/src/org/ofbiz/widget/model/ModelMenu.java @@ -1,536 +1,534 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget.menu; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.UtilValidate; -import org.ofbiz.base.util.UtilXml; -import org.ofbiz.base.util.collections.FlexibleMapAccessor; -import org.ofbiz.base.util.string.FlexibleStringExpander; -import org.ofbiz.widget.ModelWidget; -import org.ofbiz.widget.*; -import org.ofbiz.widget.ModelWidgetVisitor; -import org.w3c.dom.Element; - -/** - * Models the <menu> element. - * - * @see widget-menu.xsd - */ -@SuppressWarnings("serial") -public class ModelMenu extends ModelWidget { - - /* - * ----------------------------------------------------------------------- * - * DEVELOPERS PLEASE READ - * ----------------------------------------------------------------------- * - * - * This model is intended to be a read-only data structure that represents - * an XML element. Outside of object construction, the class should not - * have any behaviors. - * - * Instances of this class will be shared by multiple threads - therefore - * it is immutable. DO NOT CHANGE THE OBJECT'S STATE AT RUN TIME! - * - */ - - public static final String module = ModelMenu.class.getName(); - - private final List actions; - private final String defaultAlign; - private final String defaultAlignStyle; - private final FlexibleStringExpander defaultAssociatedContentId; - private final String defaultCellWidth; - private final String defaultDisabledTitleStyle; - private final String defaultEntityName; - private final Boolean defaultHideIfSelected; - private final String defaultMenuItemName; - private final String defaultPermissionEntityAction; - private final String defaultPermissionOperation; - private final String defaultSelectedStyle; - private final String defaultTitleStyle; - private final String defaultTooltipStyle; - private final String defaultWidgetStyle; - private final FlexibleStringExpander extraIndex; - private final String fillStyle; - private final String id; - private final FlexibleStringExpander menuContainerStyleExdr; - /** This List will contain one copy of each item for each item name in the order - * they were encountered in the service, entity, or menu definition; item definitions - * with constraints will also be in this list but may appear multiple times for the same - * item name. - * - * When rendering the menu the order in this list should be following and it should not be - * necessary to use the Map. The Map is used when loading the menu definition to keep the - * list clean and implement the override features for item definitions. - */ - private final List menuItemList; - /** This Map is keyed with the item name and has a ModelMenuItem for the value; items - * with conditions will not be put in this Map so item definition overrides for items - * with conditions is not possible. - */ - private final Map menuItemMap; - private final String menuLocation; - private final String menuWidth; - private final String orientation; - private final ModelMenu parentMenu; - private final FlexibleMapAccessor selectedMenuItemContextFieldName; - private final String target; - private final FlexibleStringExpander title; - private final String tooltip; - private final String type; - - /** XML Constructor */ - public ModelMenu(Element menuElement, String menuLocation) { - super(menuElement); - ArrayList actions = new ArrayList(); - String defaultAlign = ""; - String defaultAlignStyle = ""; - FlexibleStringExpander defaultAssociatedContentId = FlexibleStringExpander.getInstance(""); - String defaultCellWidth = ""; - String defaultDisabledTitleStyle = ""; - String defaultEntityName = ""; - Boolean defaultHideIfSelected = Boolean.FALSE; - String defaultMenuItemName = ""; - String defaultPermissionEntityAction = ""; - String defaultPermissionOperation = ""; - String defaultSelectedStyle = ""; - String defaultTitleStyle = ""; - String defaultTooltipStyle = ""; - String defaultWidgetStyle = ""; - FlexibleStringExpander extraIndex = FlexibleStringExpander.getInstance(""); - String fillStyle = ""; - String id = ""; - FlexibleStringExpander menuContainerStyleExdr = FlexibleStringExpander.getInstance(""); - ArrayList menuItemList = new ArrayList(); - Map menuItemMap = new HashMap(); - String menuWidth = ""; - String orientation = "horizontal"; - FlexibleMapAccessor selectedMenuItemContextFieldName = FlexibleMapAccessor.getInstance(""); - String target = ""; - FlexibleStringExpander title = FlexibleStringExpander.getInstance(""); - String tooltip = ""; - String type = ""; - // check if there is a parent menu to inherit from - ModelMenu parent = null; - String parentResource = menuElement.getAttribute("extends-resource"); - String parentMenu = menuElement.getAttribute("extends"); - if (!parentMenu.isEmpty()) { - if (!parentResource.isEmpty()) { - try { - parent = MenuFactory.getMenuFromLocation(parentResource, parentMenu); - } catch (Exception e) { - Debug.logError(e, "Failed to load parent menu definition '" + parentMenu + "' at resource '" + parentResource - + "'", module); - } - } else { - parentResource = menuLocation; - // try to find a menu definition in the same file - Element rootElement = menuElement.getOwnerDocument().getDocumentElement(); - List menuElements = UtilXml.childElementList(rootElement, "menu"); - for (Element menuElementEntry : menuElements) { - if (menuElementEntry.getAttribute("name").equals(parentMenu)) { - parent = new ModelMenu(menuElementEntry, parentResource); - break; - } - } - if (parent == null) { - Debug.logError("Failed to find parent menu definition '" + parentMenu + "' in same document.", module); - } - } - if (parent != null) { - type = parent.type; - target = parent.target; - id = parent.id; - title = parent.title; - tooltip = parent.tooltip; - defaultEntityName = parent.defaultEntityName; - defaultTitleStyle = parent.defaultTitleStyle; - defaultSelectedStyle = parent.defaultSelectedStyle; - defaultWidgetStyle = parent.defaultWidgetStyle; - defaultTooltipStyle = parent.defaultTooltipStyle; - defaultMenuItemName = parent.defaultMenuItemName; - menuItemList.addAll(parent.menuItemList); - menuItemMap.putAll(parent.menuItemMap); - defaultPermissionOperation = parent.defaultPermissionOperation; - defaultPermissionEntityAction = parent.defaultPermissionEntityAction; - defaultAssociatedContentId = parent.defaultAssociatedContentId; - defaultHideIfSelected = parent.defaultHideIfSelected; - orientation = parent.orientation; - menuWidth = parent.menuWidth; - defaultCellWidth = parent.defaultCellWidth; - defaultDisabledTitleStyle = parent.defaultDisabledTitleStyle; - defaultAlign = parent.defaultAlign; - defaultAlignStyle = parent.defaultAlignStyle; - fillStyle = parent.fillStyle; - extraIndex = parent.extraIndex; - selectedMenuItemContextFieldName = parent.selectedMenuItemContextFieldName; - menuContainerStyleExdr = parent.menuContainerStyleExdr; - if (parent.actions != null) { - actions.addAll(parent.actions); - } - } - } - if (!menuElement.getAttribute("type").isEmpty()) - type = menuElement.getAttribute("type"); - if (!menuElement.getAttribute("target").isEmpty()) - target = menuElement.getAttribute("target"); - if (!menuElement.getAttribute("id").isEmpty()) - id = menuElement.getAttribute("id"); - if (!menuElement.getAttribute("title").isEmpty()) - title = FlexibleStringExpander.getInstance(menuElement.getAttribute("title")); - if (!menuElement.getAttribute("tooltip").isEmpty()) - tooltip = menuElement.getAttribute("tooltip"); - if (!menuElement.getAttribute("default-entity-name").isEmpty()) - defaultEntityName = menuElement.getAttribute("default-entity-name"); - if (!menuElement.getAttribute("default-title-style").isEmpty()) - defaultTitleStyle = menuElement.getAttribute("default-title-style"); - if (!menuElement.getAttribute("default-selected-style").isEmpty()) - defaultSelectedStyle = menuElement.getAttribute("default-selected-style"); - if (!menuElement.getAttribute("default-widget-style").isEmpty()) - defaultWidgetStyle = menuElement.getAttribute("default-widget-style"); - if (!menuElement.getAttribute("default-tooltip-style").isEmpty()) - defaultTooltipStyle = menuElement.getAttribute("default-tooltip-style"); - if (!menuElement.getAttribute("default-menu-item-name").isEmpty()) - defaultMenuItemName = menuElement.getAttribute("default-menu-item-name"); - if (!menuElement.getAttribute("default-permission-operation").isEmpty()) - defaultPermissionOperation = menuElement.getAttribute("default-permission-operation"); - if (!menuElement.getAttribute("default-permission-entity-action").isEmpty()) - defaultPermissionEntityAction = menuElement.getAttribute("default-permission-entity-action"); - if (!menuElement.getAttribute("default-associated-content-id").isEmpty()) - defaultAssociatedContentId = FlexibleStringExpander.getInstance(menuElement - .getAttribute("default-associated-content-id")); - if (!menuElement.getAttribute("orientation").isEmpty()) - orientation = menuElement.getAttribute("orientation"); - if (!menuElement.getAttribute("menu-width").isEmpty()) - menuWidth = menuElement.getAttribute("menu-width"); - if (!menuElement.getAttribute("default-cell-width").isEmpty()) - defaultCellWidth = menuElement.getAttribute("default-cell-width"); - if (!menuElement.getAttribute("default-hide-if-selected").isEmpty()) - defaultHideIfSelected = "true".equals(menuElement.getAttribute("default-hide-if-selected").isEmpty()); - if (!menuElement.getAttribute("default-disabled-title-style").isEmpty()) - defaultDisabledTitleStyle = menuElement.getAttribute("default-disabled-title-style"); - if (!menuElement.getAttribute("selected-menuitem-context-field-name").isEmpty()) - selectedMenuItemContextFieldName = FlexibleMapAccessor.getInstance(menuElement - .getAttribute("selected-menuitem-context-field-name")); - if (!menuElement.getAttribute("menu-container-style").isEmpty()) - menuContainerStyleExdr = FlexibleStringExpander.getInstance(menuElement.getAttribute("menu-container-style")); - if (!menuElement.getAttribute("default-align").isEmpty()) - defaultAlign = menuElement.getAttribute("default-align"); - if (!menuElement.getAttribute("default-align-style").isEmpty()) - defaultAlignStyle = menuElement.getAttribute("default-align-style"); - if (!menuElement.getAttribute("fill-style").isEmpty()) - fillStyle = menuElement.getAttribute("fill-style"); - if (!menuElement.getAttribute("extra-index").isEmpty()) - extraIndex = FlexibleStringExpander.getInstance(menuElement.getAttribute("extra-index")); - // read all actions under the "actions" element - Element actionsElement = UtilXml.firstChildElement(menuElement, "actions"); - if (actionsElement != null) { - actions.addAll(ModelMenuAction.readSubActions(this, actionsElement)); - } - actions.trimToSize(); - this.actions = Collections.unmodifiableList(actions); - this.defaultAlign = defaultAlign; - this.defaultAlignStyle = defaultAlignStyle; - this.defaultAssociatedContentId = defaultAssociatedContentId; - this.defaultCellWidth = defaultCellWidth; - this.defaultDisabledTitleStyle = defaultDisabledTitleStyle; - this.defaultEntityName = defaultEntityName; - this.defaultHideIfSelected = defaultHideIfSelected; - this.defaultMenuItemName = defaultMenuItemName; - this.defaultPermissionEntityAction = defaultPermissionEntityAction; - this.defaultPermissionOperation = defaultPermissionOperation; - this.defaultSelectedStyle = defaultSelectedStyle; - this.defaultTitleStyle = defaultTitleStyle; - this.defaultTooltipStyle = defaultTooltipStyle; - this.defaultWidgetStyle = defaultWidgetStyle; - this.extraIndex = extraIndex; - this.fillStyle = fillStyle; - this.id = id; - this.menuContainerStyleExdr = menuContainerStyleExdr; - List itemElements = UtilXml.childElementList(menuElement, "menu-item"); - for (Element itemElement : itemElements) { - ModelMenuItem modelMenuItem = new ModelMenuItem(itemElement, this); - addUpdateMenuItem(modelMenuItem, menuItemList, menuItemMap); - } - menuItemList.trimToSize(); - this.menuItemList = Collections.unmodifiableList(menuItemList); - this.menuItemMap = Collections.unmodifiableMap(menuItemMap); - this.menuLocation = menuLocation; - this.menuWidth = menuWidth; - this.orientation = orientation; - this.parentMenu = parent; - this.selectedMenuItemContextFieldName = selectedMenuItemContextFieldName; - this.target = target; - this.title = title; - this.tooltip = tooltip; - this.type = type; - } - - @Override - public void accept(ModelWidgetVisitor visitor) throws Exception { - visitor.visit(this); - } - - /** - * add/override modelMenuItem using the menuItemList and menuItemMap - * - */ - private void addUpdateMenuItem(ModelMenuItem modelMenuItem, List menuItemList, - Map menuItemMap) { - ModelMenuItem existingMenuItem = menuItemMap.get(modelMenuItem.getName()); - if (existingMenuItem != null) { - // does exist, update the item by doing a merge/override - ModelMenuItem mergedMenuItem = existingMenuItem.mergeOverrideModelMenuItem(modelMenuItem); - int existingItemIndex = menuItemList.indexOf(existingMenuItem); - menuItemList.set(existingItemIndex, mergedMenuItem); - menuItemMap.put(modelMenuItem.getName(), mergedMenuItem); - } else { - // does not exist, add to Map - menuItemList.add(modelMenuItem); - menuItemMap.put(modelMenuItem.getName(), modelMenuItem); - } - } - - public List getActions() { - return actions; - } - - @Override - public String getBoundaryCommentName() { - return menuLocation + "#" + getName(); - } - - public String getCurrentMenuName(Map context) { - return getName(); - } - - public String getDefaultAlign() { - return this.defaultAlign; - } - - public String getDefaultAlignStyle() { - return this.defaultAlignStyle; - } - - public FlexibleStringExpander getDefaultAssociatedContentId() { - return defaultAssociatedContentId; - } - - public String getDefaultAssociatedContentId(Map context) { - return defaultAssociatedContentId.expandString(context); - } - - public String getDefaultCellWidth() { - return this.defaultCellWidth; - } - - public String getDefaultDisabledTitleStyle() { - return this.defaultDisabledTitleStyle; - } - - public String getDefaultEntityName() { - return this.defaultEntityName; - } - - public Boolean getDefaultHideIfSelected() { - return this.defaultHideIfSelected; - } - - public String getDefaultMenuItemName() { - return this.defaultMenuItemName; - } - - public String getDefaultPermissionEntityAction() { - return this.defaultPermissionEntityAction; - } - - public String getDefaultPermissionOperation() { - return this.defaultPermissionOperation; - } - - public String getDefaultSelectedStyle() { - return this.defaultSelectedStyle; - } - - public String getDefaultTitleStyle() { - return this.defaultTitleStyle; - } - - public String getDefaultTooltipStyle() { - return this.defaultTooltipStyle; - } - - public String getDefaultWidgetStyle() { - return this.defaultWidgetStyle; - } - - public FlexibleStringExpander getExtraIndex() { - return extraIndex; - } - - public String getExtraIndex(Map context) { - try { - return extraIndex.expandString(context); - } catch (Exception ex) { - return ""; - } - } - - public String getFillStyle() { - return this.fillStyle; - } - - public String getId() { - return this.id; - } - - public String getMenuContainerStyle(Map context) { - return menuContainerStyleExdr.expandString(context); - } - - public FlexibleStringExpander getMenuContainerStyleExdr() { - return menuContainerStyleExdr; - } - - public List getMenuItemList() { - return menuItemList; - } - - public Map getMenuItemMap() { - return menuItemMap; - } - - public String getMenuLocation() { - return menuLocation; - } - - public String getMenuWidth() { - return this.menuWidth; - } - - public ModelMenuItem getModelMenuItemByName(String name) { - return this.menuItemMap.get(name); - } - - public String getOrientation() { - return this.orientation; - } - - public ModelMenu getParentMenu() { - return parentMenu; - } - - public FlexibleMapAccessor getSelectedMenuItemContextFieldName() { - return selectedMenuItemContextFieldName; - } - - public String getSelectedMenuItemContextFieldName(Map context) { - String menuItemName = this.selectedMenuItemContextFieldName.get(context); - if (UtilValidate.isEmpty(menuItemName)) { - return this.defaultMenuItemName; - } - return menuItemName; - } - - public String getTarget() { - return target; - } - - public FlexibleStringExpander getTitle() { - return title; - } - - public String getTitle(Map context) { - return title.expandString(context); - } - - public String getTooltip() { - return this.tooltip; - } - - public String getType() { - return this.type; - } - - public int renderedMenuItemCount(Map context) { - int count = 0; - for (ModelMenuItem item : this.menuItemList) { - if (item.shouldBeRendered(context)) - count++; - } - return count; - } - - /** - * Renders this menu to a String, i.e. in a text format, as defined with the - * MenuStringRenderer implementation. - * - * @param writer The Writer that the menu text will be written to - * @param context Map containing the menu context; the following are - * reserved words in this context: parameters (Map), isError (Boolean), - * itemIndex (Integer, for lists only, otherwise null), bshInterpreter, - * menuName (String, optional alternate name for menu, defaults to the - * value of the name attribute) - * @param menuStringRenderer An implementation of the MenuStringRenderer - * interface that is responsible for the actual text generation for - * different menu elements; implementing you own makes it possible to - * use the same menu definitions for many types of menu UIs - */ - public void renderMenuString(Appendable writer, Map context, MenuStringRenderer menuStringRenderer) - throws IOException { - AbstractModelAction.runSubActions(this.actions, context); - if ("simple".equals(this.type)) { - this.renderSimpleMenuString(writer, context, menuStringRenderer); - } else { - throw new IllegalArgumentException("The type " + this.getType() + " is not supported for menu with name " - + this.getName()); - } - } - - public void renderSimpleMenuString(Appendable writer, Map context, MenuStringRenderer menuStringRenderer) - throws IOException { - // render menu open - menuStringRenderer.renderMenuOpen(writer, context, this); - - // render formatting wrapper open - menuStringRenderer.renderFormatSimpleWrapperOpen(writer, context, this); - - // render each menuItem row, except hidden & ignored rows - for (ModelMenuItem item : this.menuItemList) { - item.renderMenuItemString(writer, context, menuStringRenderer); - } - // render formatting wrapper close - menuStringRenderer.renderFormatSimpleWrapperClose(writer, context, this); - - // render menu close - menuStringRenderer.renderMenuClose(writer, context, this); - } - - public void runActions(Map context) { - AbstractModelAction.runSubActions(this.actions, context); - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.model; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.base.util.UtilXml; +import org.ofbiz.base.util.collections.FlexibleMapAccessor; +import org.ofbiz.base.util.string.FlexibleStringExpander; +import org.ofbiz.widget.renderer.MenuStringRenderer; +import org.w3c.dom.Element; + +/** + * Models the <menu> element. + * + * @see widget-menu.xsd + */ +@SuppressWarnings("serial") +public class ModelMenu extends ModelWidget { + + /* + * ----------------------------------------------------------------------- * + * DEVELOPERS PLEASE READ + * ----------------------------------------------------------------------- * + * + * This model is intended to be a read-only data structure that represents + * an XML element. Outside of object construction, the class should not + * have any behaviors. + * + * Instances of this class will be shared by multiple threads - therefore + * it is immutable. DO NOT CHANGE THE OBJECT'S STATE AT RUN TIME! + * + */ + + public static final String module = ModelMenu.class.getName(); + + private final List actions; + private final String defaultAlign; + private final String defaultAlignStyle; + private final FlexibleStringExpander defaultAssociatedContentId; + private final String defaultCellWidth; + private final String defaultDisabledTitleStyle; + private final String defaultEntityName; + private final Boolean defaultHideIfSelected; + private final String defaultMenuItemName; + private final String defaultPermissionEntityAction; + private final String defaultPermissionOperation; + private final String defaultSelectedStyle; + private final String defaultTitleStyle; + private final String defaultTooltipStyle; + private final String defaultWidgetStyle; + private final FlexibleStringExpander extraIndex; + private final String fillStyle; + private final String id; + private final FlexibleStringExpander menuContainerStyleExdr; + /** This List will contain one copy of each item for each item name in the order + * they were encountered in the service, entity, or menu definition; item definitions + * with constraints will also be in this list but may appear multiple times for the same + * item name. + * + * When rendering the menu the order in this list should be following and it should not be + * necessary to use the Map. The Map is used when loading the menu definition to keep the + * list clean and implement the override features for item definitions. + */ + private final List menuItemList; + /** This Map is keyed with the item name and has a ModelMenuItem for the value; items + * with conditions will not be put in this Map so item definition overrides for items + * with conditions is not possible. + */ + private final Map menuItemMap; + private final String menuLocation; + private final String menuWidth; + private final String orientation; + private final ModelMenu parentMenu; + private final FlexibleMapAccessor selectedMenuItemContextFieldName; + private final String target; + private final FlexibleStringExpander title; + private final String tooltip; + private final String type; + + /** XML Constructor */ + public ModelMenu(Element menuElement, String menuLocation) { + super(menuElement); + ArrayList actions = new ArrayList(); + String defaultAlign = ""; + String defaultAlignStyle = ""; + FlexibleStringExpander defaultAssociatedContentId = FlexibleStringExpander.getInstance(""); + String defaultCellWidth = ""; + String defaultDisabledTitleStyle = ""; + String defaultEntityName = ""; + Boolean defaultHideIfSelected = Boolean.FALSE; + String defaultMenuItemName = ""; + String defaultPermissionEntityAction = ""; + String defaultPermissionOperation = ""; + String defaultSelectedStyle = ""; + String defaultTitleStyle = ""; + String defaultTooltipStyle = ""; + String defaultWidgetStyle = ""; + FlexibleStringExpander extraIndex = FlexibleStringExpander.getInstance(""); + String fillStyle = ""; + String id = ""; + FlexibleStringExpander menuContainerStyleExdr = FlexibleStringExpander.getInstance(""); + ArrayList menuItemList = new ArrayList(); + Map menuItemMap = new HashMap(); + String menuWidth = ""; + String orientation = "horizontal"; + FlexibleMapAccessor selectedMenuItemContextFieldName = FlexibleMapAccessor.getInstance(""); + String target = ""; + FlexibleStringExpander title = FlexibleStringExpander.getInstance(""); + String tooltip = ""; + String type = ""; + // check if there is a parent menu to inherit from + ModelMenu parent = null; + String parentResource = menuElement.getAttribute("extends-resource"); + String parentMenu = menuElement.getAttribute("extends"); + if (!parentMenu.isEmpty()) { + if (!parentResource.isEmpty()) { + try { + parent = MenuFactory.getMenuFromLocation(parentResource, parentMenu); + } catch (Exception e) { + Debug.logError(e, "Failed to load parent menu definition '" + parentMenu + "' at resource '" + parentResource + + "'", module); + } + } else { + parentResource = menuLocation; + // try to find a menu definition in the same file + Element rootElement = menuElement.getOwnerDocument().getDocumentElement(); + List menuElements = UtilXml.childElementList(rootElement, "menu"); + for (Element menuElementEntry : menuElements) { + if (menuElementEntry.getAttribute("name").equals(parentMenu)) { + parent = new ModelMenu(menuElementEntry, parentResource); + break; + } + } + if (parent == null) { + Debug.logError("Failed to find parent menu definition '" + parentMenu + "' in same document.", module); + } + } + if (parent != null) { + type = parent.type; + target = parent.target; + id = parent.id; + title = parent.title; + tooltip = parent.tooltip; + defaultEntityName = parent.defaultEntityName; + defaultTitleStyle = parent.defaultTitleStyle; + defaultSelectedStyle = parent.defaultSelectedStyle; + defaultWidgetStyle = parent.defaultWidgetStyle; + defaultTooltipStyle = parent.defaultTooltipStyle; + defaultMenuItemName = parent.defaultMenuItemName; + menuItemList.addAll(parent.menuItemList); + menuItemMap.putAll(parent.menuItemMap); + defaultPermissionOperation = parent.defaultPermissionOperation; + defaultPermissionEntityAction = parent.defaultPermissionEntityAction; + defaultAssociatedContentId = parent.defaultAssociatedContentId; + defaultHideIfSelected = parent.defaultHideIfSelected; + orientation = parent.orientation; + menuWidth = parent.menuWidth; + defaultCellWidth = parent.defaultCellWidth; + defaultDisabledTitleStyle = parent.defaultDisabledTitleStyle; + defaultAlign = parent.defaultAlign; + defaultAlignStyle = parent.defaultAlignStyle; + fillStyle = parent.fillStyle; + extraIndex = parent.extraIndex; + selectedMenuItemContextFieldName = parent.selectedMenuItemContextFieldName; + menuContainerStyleExdr = parent.menuContainerStyleExdr; + if (parent.actions != null) { + actions.addAll(parent.actions); + } + } + } + if (!menuElement.getAttribute("type").isEmpty()) + type = menuElement.getAttribute("type"); + if (!menuElement.getAttribute("target").isEmpty()) + target = menuElement.getAttribute("target"); + if (!menuElement.getAttribute("id").isEmpty()) + id = menuElement.getAttribute("id"); + if (!menuElement.getAttribute("title").isEmpty()) + title = FlexibleStringExpander.getInstance(menuElement.getAttribute("title")); + if (!menuElement.getAttribute("tooltip").isEmpty()) + tooltip = menuElement.getAttribute("tooltip"); + if (!menuElement.getAttribute("default-entity-name").isEmpty()) + defaultEntityName = menuElement.getAttribute("default-entity-name"); + if (!menuElement.getAttribute("default-title-style").isEmpty()) + defaultTitleStyle = menuElement.getAttribute("default-title-style"); + if (!menuElement.getAttribute("default-selected-style").isEmpty()) + defaultSelectedStyle = menuElement.getAttribute("default-selected-style"); + if (!menuElement.getAttribute("default-widget-style").isEmpty()) + defaultWidgetStyle = menuElement.getAttribute("default-widget-style"); + if (!menuElement.getAttribute("default-tooltip-style").isEmpty()) + defaultTooltipStyle = menuElement.getAttribute("default-tooltip-style"); + if (!menuElement.getAttribute("default-menu-item-name").isEmpty()) + defaultMenuItemName = menuElement.getAttribute("default-menu-item-name"); + if (!menuElement.getAttribute("default-permission-operation").isEmpty()) + defaultPermissionOperation = menuElement.getAttribute("default-permission-operation"); + if (!menuElement.getAttribute("default-permission-entity-action").isEmpty()) + defaultPermissionEntityAction = menuElement.getAttribute("default-permission-entity-action"); + if (!menuElement.getAttribute("default-associated-content-id").isEmpty()) + defaultAssociatedContentId = FlexibleStringExpander.getInstance(menuElement + .getAttribute("default-associated-content-id")); + if (!menuElement.getAttribute("orientation").isEmpty()) + orientation = menuElement.getAttribute("orientation"); + if (!menuElement.getAttribute("menu-width").isEmpty()) + menuWidth = menuElement.getAttribute("menu-width"); + if (!menuElement.getAttribute("default-cell-width").isEmpty()) + defaultCellWidth = menuElement.getAttribute("default-cell-width"); + if (!menuElement.getAttribute("default-hide-if-selected").isEmpty()) + defaultHideIfSelected = "true".equals(menuElement.getAttribute("default-hide-if-selected").isEmpty()); + if (!menuElement.getAttribute("default-disabled-title-style").isEmpty()) + defaultDisabledTitleStyle = menuElement.getAttribute("default-disabled-title-style"); + if (!menuElement.getAttribute("selected-menuitem-context-field-name").isEmpty()) + selectedMenuItemContextFieldName = FlexibleMapAccessor.getInstance(menuElement + .getAttribute("selected-menuitem-context-field-name")); + if (!menuElement.getAttribute("menu-container-style").isEmpty()) + menuContainerStyleExdr = FlexibleStringExpander.getInstance(menuElement.getAttribute("menu-container-style")); + if (!menuElement.getAttribute("default-align").isEmpty()) + defaultAlign = menuElement.getAttribute("default-align"); + if (!menuElement.getAttribute("default-align-style").isEmpty()) + defaultAlignStyle = menuElement.getAttribute("default-align-style"); + if (!menuElement.getAttribute("fill-style").isEmpty()) + fillStyle = menuElement.getAttribute("fill-style"); + if (!menuElement.getAttribute("extra-index").isEmpty()) + extraIndex = FlexibleStringExpander.getInstance(menuElement.getAttribute("extra-index")); + // read all actions under the "actions" element + Element actionsElement = UtilXml.firstChildElement(menuElement, "actions"); + if (actionsElement != null) { + actions.addAll(ModelMenuAction.readSubActions(this, actionsElement)); + } + actions.trimToSize(); + this.actions = Collections.unmodifiableList(actions); + this.defaultAlign = defaultAlign; + this.defaultAlignStyle = defaultAlignStyle; + this.defaultAssociatedContentId = defaultAssociatedContentId; + this.defaultCellWidth = defaultCellWidth; + this.defaultDisabledTitleStyle = defaultDisabledTitleStyle; + this.defaultEntityName = defaultEntityName; + this.defaultHideIfSelected = defaultHideIfSelected; + this.defaultMenuItemName = defaultMenuItemName; + this.defaultPermissionEntityAction = defaultPermissionEntityAction; + this.defaultPermissionOperation = defaultPermissionOperation; + this.defaultSelectedStyle = defaultSelectedStyle; + this.defaultTitleStyle = defaultTitleStyle; + this.defaultTooltipStyle = defaultTooltipStyle; + this.defaultWidgetStyle = defaultWidgetStyle; + this.extraIndex = extraIndex; + this.fillStyle = fillStyle; + this.id = id; + this.menuContainerStyleExdr = menuContainerStyleExdr; + List itemElements = UtilXml.childElementList(menuElement, "menu-item"); + for (Element itemElement : itemElements) { + ModelMenuItem modelMenuItem = new ModelMenuItem(itemElement, this); + addUpdateMenuItem(modelMenuItem, menuItemList, menuItemMap); + } + menuItemList.trimToSize(); + this.menuItemList = Collections.unmodifiableList(menuItemList); + this.menuItemMap = Collections.unmodifiableMap(menuItemMap); + this.menuLocation = menuLocation; + this.menuWidth = menuWidth; + this.orientation = orientation; + this.parentMenu = parent; + this.selectedMenuItemContextFieldName = selectedMenuItemContextFieldName; + this.target = target; + this.title = title; + this.tooltip = tooltip; + this.type = type; + } + + @Override + public void accept(ModelWidgetVisitor visitor) throws Exception { + visitor.visit(this); + } + + /** + * add/override modelMenuItem using the menuItemList and menuItemMap + * + */ + private void addUpdateMenuItem(ModelMenuItem modelMenuItem, List menuItemList, + Map menuItemMap) { + ModelMenuItem existingMenuItem = menuItemMap.get(modelMenuItem.getName()); + if (existingMenuItem != null) { + // does exist, update the item by doing a merge/override + ModelMenuItem mergedMenuItem = existingMenuItem.mergeOverrideModelMenuItem(modelMenuItem); + int existingItemIndex = menuItemList.indexOf(existingMenuItem); + menuItemList.set(existingItemIndex, mergedMenuItem); + menuItemMap.put(modelMenuItem.getName(), mergedMenuItem); + } else { + // does not exist, add to Map + menuItemList.add(modelMenuItem); + menuItemMap.put(modelMenuItem.getName(), modelMenuItem); + } + } + + public List getActions() { + return actions; + } + + @Override + public String getBoundaryCommentName() { + return menuLocation + "#" + getName(); + } + + public String getCurrentMenuName(Map context) { + return getName(); + } + + public String getDefaultAlign() { + return this.defaultAlign; + } + + public String getDefaultAlignStyle() { + return this.defaultAlignStyle; + } + + public FlexibleStringExpander getDefaultAssociatedContentId() { + return defaultAssociatedContentId; + } + + public String getDefaultAssociatedContentId(Map context) { + return defaultAssociatedContentId.expandString(context); + } + + public String getDefaultCellWidth() { + return this.defaultCellWidth; + } + + public String getDefaultDisabledTitleStyle() { + return this.defaultDisabledTitleStyle; + } + + public String getDefaultEntityName() { + return this.defaultEntityName; + } + + public Boolean getDefaultHideIfSelected() { + return this.defaultHideIfSelected; + } + + public String getDefaultMenuItemName() { + return this.defaultMenuItemName; + } + + public String getDefaultPermissionEntityAction() { + return this.defaultPermissionEntityAction; + } + + public String getDefaultPermissionOperation() { + return this.defaultPermissionOperation; + } + + public String getDefaultSelectedStyle() { + return this.defaultSelectedStyle; + } + + public String getDefaultTitleStyle() { + return this.defaultTitleStyle; + } + + public String getDefaultTooltipStyle() { + return this.defaultTooltipStyle; + } + + public String getDefaultWidgetStyle() { + return this.defaultWidgetStyle; + } + + public FlexibleStringExpander getExtraIndex() { + return extraIndex; + } + + public String getExtraIndex(Map context) { + try { + return extraIndex.expandString(context); + } catch (Exception ex) { + return ""; + } + } + + public String getFillStyle() { + return this.fillStyle; + } + + public String getId() { + return this.id; + } + + public String getMenuContainerStyle(Map context) { + return menuContainerStyleExdr.expandString(context); + } + + public FlexibleStringExpander getMenuContainerStyleExdr() { + return menuContainerStyleExdr; + } + + public List getMenuItemList() { + return menuItemList; + } + + public Map getMenuItemMap() { + return menuItemMap; + } + + public String getMenuLocation() { + return menuLocation; + } + + public String getMenuWidth() { + return this.menuWidth; + } + + public ModelMenuItem getModelMenuItemByName(String name) { + return this.menuItemMap.get(name); + } + + public String getOrientation() { + return this.orientation; + } + + public ModelMenu getParentMenu() { + return parentMenu; + } + + public FlexibleMapAccessor getSelectedMenuItemContextFieldName() { + return selectedMenuItemContextFieldName; + } + + public String getSelectedMenuItemContextFieldName(Map context) { + String menuItemName = this.selectedMenuItemContextFieldName.get(context); + if (UtilValidate.isEmpty(menuItemName)) { + return this.defaultMenuItemName; + } + return menuItemName; + } + + public String getTarget() { + return target; + } + + public FlexibleStringExpander getTitle() { + return title; + } + + public String getTitle(Map context) { + return title.expandString(context); + } + + public String getTooltip() { + return this.tooltip; + } + + public String getType() { + return this.type; + } + + public int renderedMenuItemCount(Map context) { + int count = 0; + for (ModelMenuItem item : this.menuItemList) { + if (item.shouldBeRendered(context)) + count++; + } + return count; + } + + /** + * Renders this menu to a String, i.e. in a text format, as defined with the + * MenuStringRenderer implementation. + * + * @param writer The Writer that the menu text will be written to + * @param context Map containing the menu context; the following are + * reserved words in this context: parameters (Map), isError (Boolean), + * itemIndex (Integer, for lists only, otherwise null), bshInterpreter, + * menuName (String, optional alternate name for menu, defaults to the + * value of the name attribute) + * @param menuStringRenderer An implementation of the MenuStringRenderer + * interface that is responsible for the actual text generation for + * different menu elements; implementing you own makes it possible to + * use the same menu definitions for many types of menu UIs + */ + public void renderMenuString(Appendable writer, Map context, MenuStringRenderer menuStringRenderer) + throws IOException { + AbstractModelAction.runSubActions(this.actions, context); + if ("simple".equals(this.type)) { + this.renderSimpleMenuString(writer, context, menuStringRenderer); + } else { + throw new IllegalArgumentException("The type " + this.getType() + " is not supported for menu with name " + + this.getName()); + } + } + + public void renderSimpleMenuString(Appendable writer, Map context, MenuStringRenderer menuStringRenderer) + throws IOException { + // render menu open + menuStringRenderer.renderMenuOpen(writer, context, this); + + // render formatting wrapper open + menuStringRenderer.renderFormatSimpleWrapperOpen(writer, context, this); + + // render each menuItem row, except hidden & ignored rows + for (ModelMenuItem item : this.menuItemList) { + item.renderMenuItemString(writer, context, menuStringRenderer); + } + // render formatting wrapper close + menuStringRenderer.renderFormatSimpleWrapperClose(writer, context, this); + + // render menu close + menuStringRenderer.renderMenuClose(writer, context, this); + } + + public void runActions(Map context) { + AbstractModelAction.runSubActions(this.actions, context); + } +} diff --git a/framework/widget/src/org/ofbiz/widget/menu/ModelMenuAction.java b/framework/widget/src/org/ofbiz/widget/model/ModelMenuAction.java similarity index 97% rename from framework/widget/src/org/ofbiz/widget/menu/ModelMenuAction.java rename to framework/widget/src/org/ofbiz/widget/model/ModelMenuAction.java index 31e3ae4d10..735172409a 100644 --- a/framework/widget/src/org/ofbiz/widget/menu/ModelMenuAction.java +++ b/framework/widget/src/org/ofbiz/widget/model/ModelMenuAction.java @@ -1,234 +1,232 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget.menu; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.TimeZone; - -import javax.servlet.ServletContext; -import javax.servlet.http.HttpSession; - -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.GeneralException; -import org.ofbiz.base.util.ObjectType; -import org.ofbiz.base.util.UtilGenerics; -import org.ofbiz.base.util.UtilValidate; -import org.ofbiz.base.util.UtilXml; -import org.ofbiz.base.util.collections.FlexibleMapAccessor; -import org.ofbiz.base.util.string.FlexibleStringExpander; -import org.ofbiz.widget.ModelActionVisitor; -import org.ofbiz.widget.*; -import org.w3c.dom.Element; - -/** - * Abstract menu action. - */ -public abstract class ModelMenuAction { - - public static final String module = ModelMenuAction.class.getName(); - - public static List readSubActions(ModelMenu modelMenu, Element parentElement) { - List actionElementList = UtilXml.childElementList(parentElement); - List actions = new ArrayList(actionElementList.size()); - for (Element actionElement : actionElementList) { - if ("set".equals(actionElement.getNodeName())) { - actions.add(new SetField(modelMenu, actionElement)); - } else { - actions.add(AbstractModelAction.newInstance(modelMenu, actionElement)); - } - } - return Collections.unmodifiableList(actions); - } - - /** - * Models the <set> element. - * - * @see widget-common.xsd - */ - @SuppressWarnings("serial") - public static class SetField extends AbstractModelAction { - private final FlexibleMapAccessor field; - private final FlexibleMapAccessor fromField; - private final FlexibleStringExpander valueExdr; - private final FlexibleStringExpander defaultExdr; - private final FlexibleStringExpander globalExdr; - private final String type; - private final String toScope; - private final String fromScope; - - public SetField(ModelMenu modelMenu, Element setElement) { - super (modelMenu, setElement); - this.field = FlexibleMapAccessor.getInstance(setElement.getAttribute("field")); - this.fromField = FlexibleMapAccessor.getInstance(setElement.getAttribute("from-field")); - this.valueExdr = FlexibleStringExpander.getInstance(setElement.getAttribute("value")); - this.defaultExdr = UtilValidate.isNotEmpty(setElement.getAttribute("default-value")) ? FlexibleStringExpander.getInstance(setElement.getAttribute("default-value")) : null; - this.globalExdr = FlexibleStringExpander.getInstance(setElement.getAttribute("global")); - this.type = setElement.getAttribute("type"); - this.toScope = setElement.getAttribute("to-scope"); - this.fromScope = setElement.getAttribute("from-scope"); - if (!this.fromField.isEmpty() && !this.valueExdr.isEmpty()) { - throw new IllegalArgumentException("Cannot specify a from-field [" + setElement.getAttribute("from-field") + "] and a value [" + setElement.getAttribute("value") + "] on the set action in a screen widget"); - } - } - - @SuppressWarnings("rawtypes") - @Override - public void runAction(Map context) { - String globalStr = this.globalExdr.expandString(context); - // default to false - boolean global = "true".equals(globalStr); - - Object newValue = null; - if (this.fromScope != null && this.fromScope.equals("user")) { - if (!this.fromField.isEmpty()) { - String originalName = this.fromField.getOriginalName(); - String currentWidgetTrail = (String)context.get("_WIDGETTRAIL_"); - String newKey = currentWidgetTrail + "|" + originalName; - HttpSession session = (HttpSession)context.get("session"); - newValue = session.getAttribute(newKey); - if (Debug.verboseOn()) Debug.logVerbose("In user getting value for field from [" + this.fromField.getOriginalName() + "]: " + newValue, module); - } else if (!this.valueExdr.isEmpty()) { - newValue = this.valueExdr.expandString(context); - } - - } else if (this.fromScope != null && this.fromScope.equals("application")) { - if (!this.fromField.isEmpty()) { - String originalName = this.fromField.getOriginalName(); - String currentWidgetTrail = (String)context.get("_WIDGETTRAIL_"); - String newKey = currentWidgetTrail + "|" + originalName; - ServletContext servletContext = (ServletContext)context.get("application"); - newValue = servletContext.getAttribute(newKey); - if (Debug.verboseOn()) Debug.logVerbose("In application getting value for field from [" + this.fromField.getOriginalName() + "]: " + newValue, module); - } else if (!this.valueExdr.isEmpty()) { - newValue = this.valueExdr.expandString(context); - } - - } else { - if (!this.fromField.isEmpty()) { - newValue = this.fromField.get(context); - if (Debug.verboseOn()) Debug.logVerbose("In screen getting value for field from [" + this.fromField.getOriginalName() + "]: " + newValue, module); - } else if (!this.valueExdr.isEmpty()) { - newValue = this.valueExdr.expandString(context); - } - } - - // If newValue is still empty, use the default value - if (this.defaultExdr != null) { - if (ObjectType.isEmpty(newValue)) { - newValue = this.defaultExdr.expandString(context); - } - } - - if (UtilValidate.isNotEmpty(this.type)) { - if ("NewMap".equals(this.type)) { - newValue = new HashMap(); - } else if ("NewList".equals(this.type)) { - newValue = new LinkedList(); - } else { - try { - newValue = ObjectType.simpleTypeConvert(newValue, this.type, null, (TimeZone) context.get("timeZone"), (Locale) context.get("locale"), true); - } catch (GeneralException e) { - String errMsg = "Could not convert field value for the field: [" + this.field.getOriginalName() + "] to the [" + this.type + "] type for the value [" + newValue + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - throw new IllegalArgumentException(errMsg); - } - } - } - if (this.toScope != null && this.toScope.equals("user")) { - String originalName = this.field.getOriginalName(); - String currentWidgetTrail = (String)context.get("_WIDGETTRAIL_"); - String newKey = currentWidgetTrail + "|" + originalName; - HttpSession session = (HttpSession)context.get("session"); - session.setAttribute(newKey, newValue); - if (Debug.verboseOn()) Debug.logVerbose("In user setting value for field from [" + this.field.getOriginalName() + "]: " + newValue, module); - - } else if (this.toScope != null && this.toScope.equals("application")) { - String originalName = this.field.getOriginalName(); - String currentWidgetTrail = (String)context.get("_WIDGETTRAIL_"); - String newKey = currentWidgetTrail + "|" + originalName; - ServletContext servletContext = (ServletContext)context.get("application"); - servletContext.setAttribute(newKey, newValue); - if (Debug.verboseOn()) Debug.logVerbose("In application setting value for field from [" + this.field.getOriginalName() + "]: " + newValue, module); - - } else { - if (Debug.verboseOn()) Debug.logVerbose("In screen setting field [" + this.field.getOriginalName() + "] to value: " + newValue, module); - this.field.put(context, newValue); - } - - if (global) { - Map globalCtx = UtilGenerics.checkMap(context.get("globalContext")); - if (globalCtx != null) { - this.field.put(globalCtx, newValue); - } - } - - // this is a hack for backward compatibility with the JPublish page object - Map page = UtilGenerics.checkMap(context.get("page")); - if (page != null) { - this.field.put(page, newValue); - } - } - - @Override - public void accept(ModelActionVisitor visitor) throws Exception { - visitor.visit(this); - } - - public FlexibleMapAccessor getField() { - return field; - } - - public FlexibleMapAccessor getFromField() { - return fromField; - } - - public FlexibleStringExpander getValueExdr() { - return valueExdr; - } - - public FlexibleStringExpander getDefaultExdr() { - return defaultExdr; - } - - public FlexibleStringExpander getGlobalExdr() { - return globalExdr; - } - - public String getType() { - return type; - } - - public String getToScope() { - return toScope; - } - - public String getFromScope() { - return fromScope; - } - } -} - - - +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.model; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.TimeZone; + +import javax.servlet.ServletContext; +import javax.servlet.http.HttpSession; + +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.GeneralException; +import org.ofbiz.base.util.ObjectType; +import org.ofbiz.base.util.UtilGenerics; +import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.base.util.UtilXml; +import org.ofbiz.base.util.collections.FlexibleMapAccessor; +import org.ofbiz.base.util.string.FlexibleStringExpander; +import org.w3c.dom.Element; + +/** + * Abstract menu action. + */ +public abstract class ModelMenuAction { + + public static final String module = ModelMenuAction.class.getName(); + + public static List readSubActions(ModelMenu modelMenu, Element parentElement) { + List actionElementList = UtilXml.childElementList(parentElement); + List actions = new ArrayList(actionElementList.size()); + for (Element actionElement : actionElementList) { + if ("set".equals(actionElement.getNodeName())) { + actions.add(new SetField(modelMenu, actionElement)); + } else { + actions.add(AbstractModelAction.newInstance(modelMenu, actionElement)); + } + } + return Collections.unmodifiableList(actions); + } + + /** + * Models the <set> element. + * + * @see widget-common.xsd + */ + @SuppressWarnings("serial") + public static class SetField extends AbstractModelAction { + private final FlexibleMapAccessor field; + private final FlexibleMapAccessor fromField; + private final FlexibleStringExpander valueExdr; + private final FlexibleStringExpander defaultExdr; + private final FlexibleStringExpander globalExdr; + private final String type; + private final String toScope; + private final String fromScope; + + public SetField(ModelMenu modelMenu, Element setElement) { + super (modelMenu, setElement); + this.field = FlexibleMapAccessor.getInstance(setElement.getAttribute("field")); + this.fromField = FlexibleMapAccessor.getInstance(setElement.getAttribute("from-field")); + this.valueExdr = FlexibleStringExpander.getInstance(setElement.getAttribute("value")); + this.defaultExdr = UtilValidate.isNotEmpty(setElement.getAttribute("default-value")) ? FlexibleStringExpander.getInstance(setElement.getAttribute("default-value")) : null; + this.globalExdr = FlexibleStringExpander.getInstance(setElement.getAttribute("global")); + this.type = setElement.getAttribute("type"); + this.toScope = setElement.getAttribute("to-scope"); + this.fromScope = setElement.getAttribute("from-scope"); + if (!this.fromField.isEmpty() && !this.valueExdr.isEmpty()) { + throw new IllegalArgumentException("Cannot specify a from-field [" + setElement.getAttribute("from-field") + "] and a value [" + setElement.getAttribute("value") + "] on the set action in a screen widget"); + } + } + + @SuppressWarnings("rawtypes") + @Override + public void runAction(Map context) { + String globalStr = this.globalExdr.expandString(context); + // default to false + boolean global = "true".equals(globalStr); + + Object newValue = null; + if (this.fromScope != null && this.fromScope.equals("user")) { + if (!this.fromField.isEmpty()) { + String originalName = this.fromField.getOriginalName(); + String currentWidgetTrail = (String)context.get("_WIDGETTRAIL_"); + String newKey = currentWidgetTrail + "|" + originalName; + HttpSession session = (HttpSession)context.get("session"); + newValue = session.getAttribute(newKey); + if (Debug.verboseOn()) Debug.logVerbose("In user getting value for field from [" + this.fromField.getOriginalName() + "]: " + newValue, module); + } else if (!this.valueExdr.isEmpty()) { + newValue = this.valueExdr.expandString(context); + } + + } else if (this.fromScope != null && this.fromScope.equals("application")) { + if (!this.fromField.isEmpty()) { + String originalName = this.fromField.getOriginalName(); + String currentWidgetTrail = (String)context.get("_WIDGETTRAIL_"); + String newKey = currentWidgetTrail + "|" + originalName; + ServletContext servletContext = (ServletContext)context.get("application"); + newValue = servletContext.getAttribute(newKey); + if (Debug.verboseOn()) Debug.logVerbose("In application getting value for field from [" + this.fromField.getOriginalName() + "]: " + newValue, module); + } else if (!this.valueExdr.isEmpty()) { + newValue = this.valueExdr.expandString(context); + } + + } else { + if (!this.fromField.isEmpty()) { + newValue = this.fromField.get(context); + if (Debug.verboseOn()) Debug.logVerbose("In screen getting value for field from [" + this.fromField.getOriginalName() + "]: " + newValue, module); + } else if (!this.valueExdr.isEmpty()) { + newValue = this.valueExdr.expandString(context); + } + } + + // If newValue is still empty, use the default value + if (this.defaultExdr != null) { + if (ObjectType.isEmpty(newValue)) { + newValue = this.defaultExdr.expandString(context); + } + } + + if (UtilValidate.isNotEmpty(this.type)) { + if ("NewMap".equals(this.type)) { + newValue = new HashMap(); + } else if ("NewList".equals(this.type)) { + newValue = new LinkedList(); + } else { + try { + newValue = ObjectType.simpleTypeConvert(newValue, this.type, null, (TimeZone) context.get("timeZone"), (Locale) context.get("locale"), true); + } catch (GeneralException e) { + String errMsg = "Could not convert field value for the field: [" + this.field.getOriginalName() + "] to the [" + this.type + "] type for the value [" + newValue + "]: " + e.toString(); + Debug.logError(e, errMsg, module); + throw new IllegalArgumentException(errMsg); + } + } + } + if (this.toScope != null && this.toScope.equals("user")) { + String originalName = this.field.getOriginalName(); + String currentWidgetTrail = (String)context.get("_WIDGETTRAIL_"); + String newKey = currentWidgetTrail + "|" + originalName; + HttpSession session = (HttpSession)context.get("session"); + session.setAttribute(newKey, newValue); + if (Debug.verboseOn()) Debug.logVerbose("In user setting value for field from [" + this.field.getOriginalName() + "]: " + newValue, module); + + } else if (this.toScope != null && this.toScope.equals("application")) { + String originalName = this.field.getOriginalName(); + String currentWidgetTrail = (String)context.get("_WIDGETTRAIL_"); + String newKey = currentWidgetTrail + "|" + originalName; + ServletContext servletContext = (ServletContext)context.get("application"); + servletContext.setAttribute(newKey, newValue); + if (Debug.verboseOn()) Debug.logVerbose("In application setting value for field from [" + this.field.getOriginalName() + "]: " + newValue, module); + + } else { + if (Debug.verboseOn()) Debug.logVerbose("In screen setting field [" + this.field.getOriginalName() + "] to value: " + newValue, module); + this.field.put(context, newValue); + } + + if (global) { + Map globalCtx = UtilGenerics.checkMap(context.get("globalContext")); + if (globalCtx != null) { + this.field.put(globalCtx, newValue); + } + } + + // this is a hack for backward compatibility with the JPublish page object + Map page = UtilGenerics.checkMap(context.get("page")); + if (page != null) { + this.field.put(page, newValue); + } + } + + @Override + public void accept(ModelActionVisitor visitor) throws Exception { + visitor.visit(this); + } + + public FlexibleMapAccessor getField() { + return field; + } + + public FlexibleMapAccessor getFromField() { + return fromField; + } + + public FlexibleStringExpander getValueExdr() { + return valueExdr; + } + + public FlexibleStringExpander getDefaultExdr() { + return defaultExdr; + } + + public FlexibleStringExpander getGlobalExdr() { + return globalExdr; + } + + public String getType() { + return type; + } + + public String getToScope() { + return toScope; + } + + public String getFromScope() { + return fromScope; + } + } +} + + + diff --git a/framework/widget/src/org/ofbiz/widget/menu/ModelMenuCondition.java b/framework/widget/src/org/ofbiz/widget/model/ModelMenuCondition.java similarity index 95% rename from framework/widget/src/org/ofbiz/widget/menu/ModelMenuCondition.java rename to framework/widget/src/org/ofbiz/widget/model/ModelMenuCondition.java index bd0e9f1c26..b9aec8c647 100644 --- a/framework/widget/src/org/ofbiz/widget/menu/ModelMenuCondition.java +++ b/framework/widget/src/org/ofbiz/widget/model/ModelMenuCondition.java @@ -1,70 +1,68 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget.menu; - -import org.ofbiz.base.util.string.FlexibleStringExpander; -import org.ofbiz.widget.AbstractModelCondition; -import org.ofbiz.widget.ModelCondition; -import org.w3c.dom.Element; - -/** - * Models the <condition> element. - * - * @see widget-menu.xsd - */ -public final class ModelMenuCondition { - - /* - * ----------------------------------------------------------------------- * - * DEVELOPERS PLEASE READ - * ----------------------------------------------------------------------- * - * - * This model is intended to be a read-only data structure that represents - * an XML element. Outside of object construction, the class should not - * have any behaviors. - * - * Instances of this class will be shared by multiple threads - therefore - * it is immutable. DO NOT CHANGE THE OBJECT'S STATE AT RUN TIME! - * - */ - - public static final String module = ModelMenuCondition.class.getName(); - - private final FlexibleStringExpander passStyleExdr; - private final FlexibleStringExpander failStyleExdr; - private final ModelCondition condition; - - public ModelMenuCondition(ModelMenuItem modelMenuItem, Element conditionElement) { - this.passStyleExdr = FlexibleStringExpander.getInstance(conditionElement.getAttribute("pass-style")); - this.failStyleExdr = FlexibleStringExpander.getInstance(conditionElement.getAttribute("disabled-style")); - this.condition = AbstractModelCondition.DEFAULT_CONDITION_FACTORY.newInstance(modelMenuItem, conditionElement); - } - - public ModelCondition getCondition() { - return condition; - } - - public FlexibleStringExpander getFailStyleExdr() { - return failStyleExdr; - } - - public FlexibleStringExpander getPassStyleExdr() { - return passStyleExdr; - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.model; + +import org.ofbiz.base.util.string.FlexibleStringExpander; +import org.w3c.dom.Element; + +/** + * Models the <condition> element. + * + * @see widget-menu.xsd + */ +public final class ModelMenuCondition { + + /* + * ----------------------------------------------------------------------- * + * DEVELOPERS PLEASE READ + * ----------------------------------------------------------------------- * + * + * This model is intended to be a read-only data structure that represents + * an XML element. Outside of object construction, the class should not + * have any behaviors. + * + * Instances of this class will be shared by multiple threads - therefore + * it is immutable. DO NOT CHANGE THE OBJECT'S STATE AT RUN TIME! + * + */ + + public static final String module = ModelMenuCondition.class.getName(); + + private final FlexibleStringExpander passStyleExdr; + private final FlexibleStringExpander failStyleExdr; + private final ModelCondition condition; + + public ModelMenuCondition(ModelMenuItem modelMenuItem, Element conditionElement) { + this.passStyleExdr = FlexibleStringExpander.getInstance(conditionElement.getAttribute("pass-style")); + this.failStyleExdr = FlexibleStringExpander.getInstance(conditionElement.getAttribute("disabled-style")); + this.condition = AbstractModelCondition.DEFAULT_CONDITION_FACTORY.newInstance(modelMenuItem, conditionElement); + } + + public ModelCondition getCondition() { + return condition; + } + + public FlexibleStringExpander getFailStyleExdr() { + return failStyleExdr; + } + + public FlexibleStringExpander getPassStyleExdr() { + return passStyleExdr; + } +} diff --git a/framework/widget/src/org/ofbiz/widget/menu/ModelMenuItem.java b/framework/widget/src/org/ofbiz/widget/model/ModelMenuItem.java similarity index 95% rename from framework/widget/src/org/ofbiz/widget/menu/ModelMenuItem.java rename to framework/widget/src/org/ofbiz/widget/model/ModelMenuItem.java index 2ddc1e4255..2ee5b5a751 100644 --- a/framework/widget/src/org/ofbiz/widget/menu/ModelMenuItem.java +++ b/framework/widget/src/org/ofbiz/widget/model/ModelMenuItem.java @@ -1,672 +1,669 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget.menu; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; - -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.UtilValidate; -import org.ofbiz.base.util.UtilXml; -import org.ofbiz.base.util.string.FlexibleStringExpander; -import org.ofbiz.entity.GenericValue; -import org.ofbiz.widget.AbstractModelAction; -import org.ofbiz.widget.CommonWidgetModels.AutoEntityParameters; -import org.ofbiz.widget.CommonWidgetModels.AutoServiceParameters; -import org.ofbiz.widget.CommonWidgetModels.Image; -import org.ofbiz.widget.CommonWidgetModels.Link; -import org.ofbiz.widget.CommonWidgetModels.Parameter; -import org.ofbiz.widget.ModelAction; -import org.ofbiz.widget.ModelWidget; -import org.ofbiz.widget.ModelWidgetVisitor; -import org.ofbiz.widget.PortalPageWorker; -import org.w3c.dom.Element; - -/** - * Models the <menu-item> element. - * - * @see widget-menu.xsd - */ -@SuppressWarnings("serial") -public class ModelMenuItem extends ModelWidget { - - /* - * ----------------------------------------------------------------------- * - * DEVELOPERS PLEASE READ - * ----------------------------------------------------------------------- * - * - * This model is intended to be a read-only data structure that represents - * an XML element. Outside of object construction, the class should not - * have any behaviors. - * - * Instances of this class will be shared by multiple threads - therefore - * it is immutable. DO NOT CHANGE THE OBJECT'S STATE AT RUN TIME! - * - */ - - public static final String module = ModelMenuItem.class.getName(); - - private final List actions; - private final String align; - private final String alignStyle; - private final FlexibleStringExpander associatedContentId; - private final String cellWidth; - private final ModelMenuCondition condition; - private final String disabledTitleStyle; - private final String disableIfEmpty; - private final String entityName; - private final Boolean hideIfSelected; - private final MenuLink link; - private final List menuItemList; - private final ModelMenu modelMenu; - private final String overrideName; - private final ModelMenuItem parentMenuItem; - private final FlexibleStringExpander parentPortalPageId; - private final Integer position; - private final String selectedStyle; - private final String subMenu; - private final FlexibleStringExpander title; - private final String titleStyle; - private final FlexibleStringExpander tooltip; - private final String tooltipStyle; - private final String widgetStyle; - - // ===== CONSTRUCTORS ===== - - public ModelMenuItem(Element menuItemElement, ModelMenu modelMenu) { - this(menuItemElement, modelMenu, null); - } - - private ModelMenuItem(Element menuItemElement, ModelMenu modelMenu, ModelMenuItem parentMenuItem) { - super(menuItemElement); - this.modelMenu = modelMenu; - this.parentMenuItem = parentMenuItem; - this.entityName = menuItemElement.getAttribute("entity-name"); - this.title = FlexibleStringExpander.getInstance(menuItemElement.getAttribute("title")); - this.tooltip = FlexibleStringExpander.getInstance(menuItemElement.getAttribute("tooltip")); - this.parentPortalPageId = FlexibleStringExpander.getInstance(menuItemElement.getAttribute("parent-portal-page-value")); - this.titleStyle = menuItemElement.getAttribute("title-style"); - this.disabledTitleStyle = menuItemElement.getAttribute("disabled-title-style"); - this.widgetStyle = menuItemElement.getAttribute("widget-style"); - this.tooltipStyle = menuItemElement.getAttribute("tooltip-style"); - this.selectedStyle = menuItemElement.getAttribute("selected-style"); - String hideIfSelected = menuItemElement.getAttribute("hide-if-selected"); - if (!hideIfSelected.isEmpty()) - if (hideIfSelected.equalsIgnoreCase("true")) - this.hideIfSelected = Boolean.TRUE; - else - this.hideIfSelected = Boolean.FALSE; - else - this.hideIfSelected = null; - this.disableIfEmpty = menuItemElement.getAttribute("disable-if-empty"); - this.align = menuItemElement.getAttribute("align"); - this.alignStyle = menuItemElement.getAttribute("align-style"); - Integer position = null; - String positionStr = menuItemElement.getAttribute("position"); - if (!positionStr.isEmpty()) { - try { - position = Integer.valueOf(positionStr); - } catch (Exception e) { - Debug.logError(e, "Could not convert position attribute of the field element to an integer: [" + positionStr - + "], using the default of the menu renderer", module); - position = null; - } - } - this.position = position; - this.associatedContentId = FlexibleStringExpander.getInstance(menuItemElement.getAttribute("associated-content-id")); - this.cellWidth = menuItemElement.getAttribute("cell-width"); - this.subMenu = menuItemElement.getAttribute("sub-menu"); - Element linkElement = UtilXml.firstChildElement(menuItemElement, "link"); - if (linkElement != null) { - this.link = new MenuLink(linkElement, this); - } else { - this.link = null; - } - // read in add item defs, add/override one by one using the menuItemList and menuItemMap - List itemElements = UtilXml.childElementList(menuItemElement, "menu-item"); - if (!itemElements.isEmpty()) { - ArrayList menuItemList = new ArrayList(); - Map menuItemMap = new HashMap(); - for (Element itemElement : itemElements) { - ModelMenuItem modelMenuItem = new ModelMenuItem(itemElement, modelMenu, this); - addUpdateMenuItem(modelMenuItem, menuItemList, menuItemMap); - } - menuItemList.trimToSize(); - this.menuItemList = Collections.unmodifiableList(menuItemList); - } else { - this.menuItemList = Collections.emptyList(); - } - // read condition under the "condition" element - Element conditionElement = UtilXml.firstChildElement(menuItemElement, "condition"); - if (conditionElement != null) { - conditionElement = UtilXml.firstChildElement(conditionElement); - this.condition = new ModelMenuCondition(this, conditionElement); - } else { - this.condition = null; - } - // read all actions under the "actions" element - Element actionsElement = UtilXml.firstChildElement(conditionElement, "actions"); - if (actionsElement != null) { - this.actions = AbstractModelAction.readSubActions(this, actionsElement); - } else { - this.actions = Collections.emptyList(); - } - this.overrideName = ""; - } - - // Portal constructor - private ModelMenuItem(GenericValue portalPage, ModelMenuItem parentMenuItem, Locale locale) { - super(portalPage.getString("portalPageId")); - this.actions = Collections.emptyList(); - this.align = ""; - this.alignStyle = ""; - this.associatedContentId = FlexibleStringExpander.getInstance(""); - this.cellWidth = ""; - this.condition = null; - this.disabledTitleStyle = ""; - this.disableIfEmpty = ""; - this.entityName = ""; - this.hideIfSelected = null; - this.menuItemList = Collections.emptyList(); - this.overrideName = ""; - this.parentMenuItem = null; - this.parentPortalPageId = FlexibleStringExpander.getInstance(portalPage.getString("parentPortalPageId")); - this.position = null; - this.selectedStyle = ""; - this.subMenu = ""; - this.title = FlexibleStringExpander.getInstance((String) portalPage.get("portalPageName", locale)); - this.titleStyle = ""; - this.tooltip = FlexibleStringExpander.getInstance(""); - this.tooltipStyle = ""; - this.widgetStyle = ""; - this.link = new MenuLink(portalPage, parentMenuItem, locale); - this.modelMenu = parentMenuItem.modelMenu; - } - - // Merge constructor - private ModelMenuItem(ModelMenuItem existingMenuItem, ModelMenuItem overrideMenuItem) { - super(existingMenuItem.getName()); - this.modelMenu = existingMenuItem.modelMenu; - if (UtilValidate.isNotEmpty(overrideMenuItem.getName())) { - this.overrideName = overrideMenuItem.getName(); - } else { - this.overrideName = existingMenuItem.getName(); - } - if (UtilValidate.isNotEmpty(overrideMenuItem.entityName)) { - this.entityName = overrideMenuItem.entityName; - } else { - this.entityName = existingMenuItem.entityName; - } - if (UtilValidate.isNotEmpty(overrideMenuItem.parentPortalPageId)) { - this.parentPortalPageId = overrideMenuItem.parentPortalPageId; - } else { - this.parentPortalPageId = existingMenuItem.parentPortalPageId; - } - if (UtilValidate.isNotEmpty(overrideMenuItem.title)) { - this.title = overrideMenuItem.title; - } else { - this.title = existingMenuItem.title; - } - if (UtilValidate.isNotEmpty(overrideMenuItem.tooltip)) { - this.tooltip = overrideMenuItem.tooltip; - } else { - this.tooltip = existingMenuItem.tooltip; - } - if (UtilValidate.isNotEmpty(overrideMenuItem.titleStyle)) { - this.titleStyle = overrideMenuItem.titleStyle; - } else { - this.titleStyle = existingMenuItem.titleStyle; - } - if (UtilValidate.isNotEmpty(overrideMenuItem.selectedStyle)) { - this.selectedStyle = overrideMenuItem.selectedStyle; - } else { - this.selectedStyle = existingMenuItem.selectedStyle; - } - if (UtilValidate.isNotEmpty(overrideMenuItem.widgetStyle)) { - this.widgetStyle = overrideMenuItem.widgetStyle; - } else { - this.widgetStyle = existingMenuItem.widgetStyle; - } - if (overrideMenuItem.position != null) { - this.position = overrideMenuItem.position; - } else { - this.position = existingMenuItem.position; - } - this.actions = existingMenuItem.actions; - this.align = existingMenuItem.align; - this.alignStyle = existingMenuItem.alignStyle; - this.associatedContentId = existingMenuItem.associatedContentId; - this.cellWidth = existingMenuItem.cellWidth; - this.condition = existingMenuItem.condition; - this.disabledTitleStyle = existingMenuItem.disabledTitleStyle; - this.disableIfEmpty = existingMenuItem.disableIfEmpty; - this.hideIfSelected = existingMenuItem.hideIfSelected; - this.menuItemList = existingMenuItem.menuItemList; - this.parentMenuItem = existingMenuItem.parentMenuItem; - this.subMenu = existingMenuItem.subMenu; - this.tooltipStyle = existingMenuItem.tooltipStyle; - this.link = existingMenuItem.link; - } - - @Override - public void accept(ModelWidgetVisitor visitor) throws Exception { - visitor.visit(this); - } - - private void addUpdateMenuItem(ModelMenuItem modelMenuItem, List menuItemList, - Map menuItemMap) { - ModelMenuItem existingMenuItem = menuItemMap.get(modelMenuItem.getName()); - if (existingMenuItem != null) { - // does exist, update the item by doing a merge/override - ModelMenuItem mergedMenuItem = existingMenuItem.mergeOverrideModelMenuItem(modelMenuItem); - int existingItemIndex = menuItemList.indexOf(existingMenuItem); - menuItemList.set(existingItemIndex, mergedMenuItem); - menuItemMap.put(modelMenuItem.getName(), mergedMenuItem); - } else { - // does not exist, add to List and Map - menuItemList.add(modelMenuItem); - menuItemMap.put(modelMenuItem.getName(), modelMenuItem); - } - } - - public List getActions() { - return actions; - } - - public String getAlign() { - if (!this.align.isEmpty()) { - return this.align; - } else if (parentMenuItem != null) { - return parentMenuItem.getAlign(); - } else { - return this.modelMenu.getDefaultAlign(); - } - } - - public String getAlignStyle() { - if (!this.alignStyle.isEmpty()) { - return this.alignStyle; - } else if (parentMenuItem != null) { - return parentMenuItem.getAlignStyle(); - } else { - return this.modelMenu.getDefaultAlignStyle(); - } - } - - public FlexibleStringExpander getAssociatedContentId() { - return associatedContentId; - } - - public String getAssociatedContentId(Map context) { - String retStr = null; - if (this.associatedContentId != null) { - retStr = associatedContentId.expandString(context); - } - if (retStr.isEmpty()) { - retStr = this.modelMenu.getDefaultAssociatedContentId(context); - } - return retStr; - } - - public String getCellWidth() { - if (!this.cellWidth.isEmpty()) { - return this.cellWidth; - } else { - return this.modelMenu.getDefaultCellWidth(); - } - } - - public ModelMenuCondition getCondition() { - return condition; - } - - public String getDisabledTitleStyle() { - if (!this.disabledTitleStyle.isEmpty()) { - return this.disabledTitleStyle; - } else if (parentMenuItem != null) { - return parentMenuItem.getDisabledTitleStyle(); - } else { - return this.modelMenu.getDefaultDisabledTitleStyle(); - } - } - - public String getDisableIfEmpty() { - return this.disableIfEmpty; - } - - public String getEntityName() { - if (!this.entityName.isEmpty()) { - return this.entityName; - } else if (parentMenuItem != null) { - return parentMenuItem.getEntityName(); - } else { - return this.modelMenu.getDefaultEntityName(); - } - } - - public Boolean getHideIfSelected() { - if (hideIfSelected != null) { - return this.hideIfSelected; - } else { - return this.modelMenu.getDefaultHideIfSelected(); - } - } - - public MenuLink getLink() { - return this.link; - } - - public List getMenuItemList() { - return menuItemList; - } - - public ModelMenu getModelMenu() { - return modelMenu; - } - - @Override - public String getName() { - if (!this.overrideName.isEmpty()) { - return this.overrideName; - } - return super.getName(); - } - - public String getOverrideName() { - return overrideName; - } - - public ModelMenuItem getParentMenuItem() { - return parentMenuItem; - } - - public FlexibleStringExpander getParentPortalPageId() { - return parentPortalPageId; - } - - public String getParentPortalPageId(Map context) { - return this.parentPortalPageId.expandString(context); - } - - public int getPosition() { - if (this.position == null) { - return 1; - } else { - return position.intValue(); - } - } - - public String getSelectedStyle() { - if (!this.selectedStyle.isEmpty()) { - return this.selectedStyle; - } else if (parentMenuItem != null) { - return parentMenuItem.getSelectedStyle(); - } else { - return this.modelMenu.getDefaultSelectedStyle(); - } - } - - public String getSubMenu() { - return subMenu; - } - - public FlexibleStringExpander getTitle() { - return title; - } - - public String getTitle(Map context) { - return title.expandString(context); - } - - public String getTitleStyle() { - if (!this.titleStyle.isEmpty()) { - return this.titleStyle; - } else if (parentMenuItem != null) { - return parentMenuItem.getTitleStyle(); - } else { - return this.modelMenu.getDefaultTitleStyle(); - } - } - - public FlexibleStringExpander getTooltip() { - return tooltip; - } - - public String getTooltip(Map context) { - if (UtilValidate.isNotEmpty(tooltip)) { - return tooltip.expandString(context); - } else { - return ""; - } - } - - public String getTooltipStyle() { - if (!this.tooltipStyle.isEmpty()) { - return this.tooltipStyle; - } else if (parentMenuItem != null) { - return parentMenuItem.getTooltipStyle(); - } else { - return this.modelMenu.getDefaultTooltipStyle(); - } - } - - public String getWidgetStyle() { - if (!this.widgetStyle.isEmpty()) { - return this.widgetStyle; - } else if (parentMenuItem != null) { - return parentMenuItem.getWidgetStyle(); - } else { - return this.modelMenu.getDefaultWidgetStyle(); - } - } - - public boolean isSelected(Map context) { - return getName().equals(modelMenu.getSelectedMenuItemContextFieldName(context)); - } - - public ModelMenuItem mergeOverrideModelMenuItem(ModelMenuItem overrideMenuItem) { - return new ModelMenuItem(this, overrideMenuItem); - } - - public void renderMenuItemString(Appendable writer, Map context, MenuStringRenderer menuStringRenderer) - throws IOException { - if (shouldBeRendered(context)) { - AbstractModelAction.runSubActions(actions, context); - String parentPortalPageId = getParentPortalPageId(context); - if (UtilValidate.isNotEmpty(parentPortalPageId)) { - List portalPages = PortalPageWorker.getPortalPages(parentPortalPageId, context); - if (UtilValidate.isNotEmpty(portalPages)) { - Locale locale = (Locale) context.get("locale"); - for (GenericValue portalPage : portalPages) { - if (UtilValidate.isNotEmpty(portalPage.getString("portalPageName"))) { - ModelMenuItem localItem = new ModelMenuItem(portalPage, this, locale); - menuStringRenderer.renderMenuItem(writer, context, localItem); - } - } - } - } else { - menuStringRenderer.renderMenuItem(writer, context, this); - } - } - } - - public boolean shouldBeRendered(Map context) { - if (this.condition != null) { - return this.condition.getCondition().eval(context); - } - return true; - } - - public static class MenuLink { - private final ModelMenuItem linkMenuItem; - private final Link link; - - public MenuLink(Element linkElement, ModelMenuItem parentMenuItem) { - this.linkMenuItem = parentMenuItem; - if (linkElement.getAttribute("text").isEmpty()) { - linkElement.setAttribute("text", parentMenuItem.getTitle().getOriginal()); - } - if (linkElement.getAttribute("style").isEmpty()) { - linkElement.setAttribute("style", parentMenuItem.getWidgetStyle()); - } - this.link = new Link(linkElement); - } - - public MenuLink(GenericValue portalPage, ModelMenuItem parentMenuItem, Locale locale) { - this.linkMenuItem = parentMenuItem; - ArrayList parameterList = new ArrayList(); - if (parentMenuItem.link != null) { - parameterList.addAll(parentMenuItem.link.getParameterList()); - } - parameterList.add(new Parameter("portalPageId", portalPage.getString("portalPageId"), false)); - parameterList.add(new Parameter("parentPortalPageId", portalPage.getString("parentPortalPageId"), false)); - String target = "showPortalPage"; - if (parentMenuItem.link != null) { - target= ""; - } - this.link = new Link(portalPage, parameterList, target, locale); - } - - public AutoEntityParameters getAutoEntityParameters() { - return link.getAutoEntityParameters(); - } - - public AutoServiceParameters getAutoServiceParameters() { - return link.getAutoServiceParameters(); - } - - public boolean getEncode() { - return link.getEncode(); - } - - public boolean getFullPath() { - return link.getFullPath(); - } - - public String getHeight() { - return link.getHeight(); - } - - public String getId(Map context) { - return link.getId(context); - } - - public FlexibleStringExpander getIdExdr() { - return link.getIdExdr(); - } - - public Image getImage() { - return link.getImage(); - } - - public String getLinkType() { - return link.getLinkType(); - } - - public String getName() { - return link.getName(); - } - - public String getName(Map context) { - return link.getName(context); - } - - public FlexibleStringExpander getNameExdr() { - return link.getNameExdr(); - } - - public List getParameterList() { - return link.getParameterList(); - } - - public Map getParameterMap(Map context) { - return link.getParameterMap(context); - } - - public String getPrefix(Map context) { - return link.getPrefix(context); - } - - public FlexibleStringExpander getPrefixExdr() { - return link.getPrefixExdr(); - } - - public boolean getSecure() { - return link.getSecure(); - } - - public String getStyle(Map context) { - return link.getStyle(context); - } - - public FlexibleStringExpander getStyleExdr() { - return link.getStyleExdr(); - } - - public String getTarget(Map context) { - return link.getTarget(context); - } - - public FlexibleStringExpander getTargetExdr() { - return link.getTargetExdr(); - } - - public String getTargetWindow(Map context) { - return link.getTargetWindow(context); - } - - public FlexibleStringExpander getTargetWindowExdr() { - return link.getTargetWindowExdr(); - } - - public String getText(Map context) { - return link.getText(context); - } - - public FlexibleStringExpander getTextExdr() { - return link.getTextExdr(); - } - - public String getUrlMode() { - return link.getUrlMode(); - } - - public String getWidth() { - return link.getWidth(); - } - - public ModelMenuItem getLinkMenuItem() { - return linkMenuItem; - } - - public Link getLink() { - return link; - } - - public void renderLinkString(Appendable writer, Map context, MenuStringRenderer menuStringRenderer) - throws IOException { - menuStringRenderer.renderLink(writer, context, this); - } - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.model; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; + +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.base.util.UtilXml; +import org.ofbiz.base.util.string.FlexibleStringExpander; +import org.ofbiz.entity.GenericValue; +import org.ofbiz.widget.model.CommonWidgetModels.AutoEntityParameters; +import org.ofbiz.widget.model.CommonWidgetModels.AutoServiceParameters; +import org.ofbiz.widget.model.CommonWidgetModels.Image; +import org.ofbiz.widget.model.CommonWidgetModels.Link; +import org.ofbiz.widget.model.CommonWidgetModels.Parameter; +import org.ofbiz.widget.portal.PortalPageWorker; +import org.ofbiz.widget.renderer.MenuStringRenderer; +import org.w3c.dom.Element; + +/** + * Models the <menu-item> element. + * + * @see widget-menu.xsd + */ +@SuppressWarnings("serial") +public class ModelMenuItem extends ModelWidget { + + /* + * ----------------------------------------------------------------------- * + * DEVELOPERS PLEASE READ + * ----------------------------------------------------------------------- * + * + * This model is intended to be a read-only data structure that represents + * an XML element. Outside of object construction, the class should not + * have any behaviors. + * + * Instances of this class will be shared by multiple threads - therefore + * it is immutable. DO NOT CHANGE THE OBJECT'S STATE AT RUN TIME! + * + */ + + public static final String module = ModelMenuItem.class.getName(); + + private final List actions; + private final String align; + private final String alignStyle; + private final FlexibleStringExpander associatedContentId; + private final String cellWidth; + private final ModelMenuCondition condition; + private final String disabledTitleStyle; + private final String disableIfEmpty; + private final String entityName; + private final Boolean hideIfSelected; + private final MenuLink link; + private final List menuItemList; + private final ModelMenu modelMenu; + private final String overrideName; + private final ModelMenuItem parentMenuItem; + private final FlexibleStringExpander parentPortalPageId; + private final Integer position; + private final String selectedStyle; + private final String subMenu; + private final FlexibleStringExpander title; + private final String titleStyle; + private final FlexibleStringExpander tooltip; + private final String tooltipStyle; + private final String widgetStyle; + + // ===== CONSTRUCTORS ===== + + public ModelMenuItem(Element menuItemElement, ModelMenu modelMenu) { + this(menuItemElement, modelMenu, null); + } + + private ModelMenuItem(Element menuItemElement, ModelMenu modelMenu, ModelMenuItem parentMenuItem) { + super(menuItemElement); + this.modelMenu = modelMenu; + this.parentMenuItem = parentMenuItem; + this.entityName = menuItemElement.getAttribute("entity-name"); + this.title = FlexibleStringExpander.getInstance(menuItemElement.getAttribute("title")); + this.tooltip = FlexibleStringExpander.getInstance(menuItemElement.getAttribute("tooltip")); + this.parentPortalPageId = FlexibleStringExpander.getInstance(menuItemElement.getAttribute("parent-portal-page-value")); + this.titleStyle = menuItemElement.getAttribute("title-style"); + this.disabledTitleStyle = menuItemElement.getAttribute("disabled-title-style"); + this.widgetStyle = menuItemElement.getAttribute("widget-style"); + this.tooltipStyle = menuItemElement.getAttribute("tooltip-style"); + this.selectedStyle = menuItemElement.getAttribute("selected-style"); + String hideIfSelected = menuItemElement.getAttribute("hide-if-selected"); + if (!hideIfSelected.isEmpty()) + if (hideIfSelected.equalsIgnoreCase("true")) + this.hideIfSelected = Boolean.TRUE; + else + this.hideIfSelected = Boolean.FALSE; + else + this.hideIfSelected = null; + this.disableIfEmpty = menuItemElement.getAttribute("disable-if-empty"); + this.align = menuItemElement.getAttribute("align"); + this.alignStyle = menuItemElement.getAttribute("align-style"); + Integer position = null; + String positionStr = menuItemElement.getAttribute("position"); + if (!positionStr.isEmpty()) { + try { + position = Integer.valueOf(positionStr); + } catch (Exception e) { + Debug.logError(e, "Could not convert position attribute of the field element to an integer: [" + positionStr + + "], using the default of the menu renderer", module); + position = null; + } + } + this.position = position; + this.associatedContentId = FlexibleStringExpander.getInstance(menuItemElement.getAttribute("associated-content-id")); + this.cellWidth = menuItemElement.getAttribute("cell-width"); + this.subMenu = menuItemElement.getAttribute("sub-menu"); + Element linkElement = UtilXml.firstChildElement(menuItemElement, "link"); + if (linkElement != null) { + this.link = new MenuLink(linkElement, this); + } else { + this.link = null; + } + // read in add item defs, add/override one by one using the menuItemList and menuItemMap + List itemElements = UtilXml.childElementList(menuItemElement, "menu-item"); + if (!itemElements.isEmpty()) { + ArrayList menuItemList = new ArrayList(); + Map menuItemMap = new HashMap(); + for (Element itemElement : itemElements) { + ModelMenuItem modelMenuItem = new ModelMenuItem(itemElement, modelMenu, this); + addUpdateMenuItem(modelMenuItem, menuItemList, menuItemMap); + } + menuItemList.trimToSize(); + this.menuItemList = Collections.unmodifiableList(menuItemList); + } else { + this.menuItemList = Collections.emptyList(); + } + // read condition under the "condition" element + Element conditionElement = UtilXml.firstChildElement(menuItemElement, "condition"); + if (conditionElement != null) { + conditionElement = UtilXml.firstChildElement(conditionElement); + this.condition = new ModelMenuCondition(this, conditionElement); + } else { + this.condition = null; + } + // read all actions under the "actions" element + Element actionsElement = UtilXml.firstChildElement(conditionElement, "actions"); + if (actionsElement != null) { + this.actions = AbstractModelAction.readSubActions(this, actionsElement); + } else { + this.actions = Collections.emptyList(); + } + this.overrideName = ""; + } + + // Portal constructor + private ModelMenuItem(GenericValue portalPage, ModelMenuItem parentMenuItem, Locale locale) { + super(portalPage.getString("portalPageId")); + this.actions = Collections.emptyList(); + this.align = ""; + this.alignStyle = ""; + this.associatedContentId = FlexibleStringExpander.getInstance(""); + this.cellWidth = ""; + this.condition = null; + this.disabledTitleStyle = ""; + this.disableIfEmpty = ""; + this.entityName = ""; + this.hideIfSelected = null; + this.menuItemList = Collections.emptyList(); + this.overrideName = ""; + this.parentMenuItem = null; + this.parentPortalPageId = FlexibleStringExpander.getInstance(portalPage.getString("parentPortalPageId")); + this.position = null; + this.selectedStyle = ""; + this.subMenu = ""; + this.title = FlexibleStringExpander.getInstance((String) portalPage.get("portalPageName", locale)); + this.titleStyle = ""; + this.tooltip = FlexibleStringExpander.getInstance(""); + this.tooltipStyle = ""; + this.widgetStyle = ""; + this.link = new MenuLink(portalPage, parentMenuItem, locale); + this.modelMenu = parentMenuItem.modelMenu; + } + + // Merge constructor + private ModelMenuItem(ModelMenuItem existingMenuItem, ModelMenuItem overrideMenuItem) { + super(existingMenuItem.getName()); + this.modelMenu = existingMenuItem.modelMenu; + if (UtilValidate.isNotEmpty(overrideMenuItem.getName())) { + this.overrideName = overrideMenuItem.getName(); + } else { + this.overrideName = existingMenuItem.getName(); + } + if (UtilValidate.isNotEmpty(overrideMenuItem.entityName)) { + this.entityName = overrideMenuItem.entityName; + } else { + this.entityName = existingMenuItem.entityName; + } + if (UtilValidate.isNotEmpty(overrideMenuItem.parentPortalPageId)) { + this.parentPortalPageId = overrideMenuItem.parentPortalPageId; + } else { + this.parentPortalPageId = existingMenuItem.parentPortalPageId; + } + if (UtilValidate.isNotEmpty(overrideMenuItem.title)) { + this.title = overrideMenuItem.title; + } else { + this.title = existingMenuItem.title; + } + if (UtilValidate.isNotEmpty(overrideMenuItem.tooltip)) { + this.tooltip = overrideMenuItem.tooltip; + } else { + this.tooltip = existingMenuItem.tooltip; + } + if (UtilValidate.isNotEmpty(overrideMenuItem.titleStyle)) { + this.titleStyle = overrideMenuItem.titleStyle; + } else { + this.titleStyle = existingMenuItem.titleStyle; + } + if (UtilValidate.isNotEmpty(overrideMenuItem.selectedStyle)) { + this.selectedStyle = overrideMenuItem.selectedStyle; + } else { + this.selectedStyle = existingMenuItem.selectedStyle; + } + if (UtilValidate.isNotEmpty(overrideMenuItem.widgetStyle)) { + this.widgetStyle = overrideMenuItem.widgetStyle; + } else { + this.widgetStyle = existingMenuItem.widgetStyle; + } + if (overrideMenuItem.position != null) { + this.position = overrideMenuItem.position; + } else { + this.position = existingMenuItem.position; + } + this.actions = existingMenuItem.actions; + this.align = existingMenuItem.align; + this.alignStyle = existingMenuItem.alignStyle; + this.associatedContentId = existingMenuItem.associatedContentId; + this.cellWidth = existingMenuItem.cellWidth; + this.condition = existingMenuItem.condition; + this.disabledTitleStyle = existingMenuItem.disabledTitleStyle; + this.disableIfEmpty = existingMenuItem.disableIfEmpty; + this.hideIfSelected = existingMenuItem.hideIfSelected; + this.menuItemList = existingMenuItem.menuItemList; + this.parentMenuItem = existingMenuItem.parentMenuItem; + this.subMenu = existingMenuItem.subMenu; + this.tooltipStyle = existingMenuItem.tooltipStyle; + this.link = existingMenuItem.link; + } + + @Override + public void accept(ModelWidgetVisitor visitor) throws Exception { + visitor.visit(this); + } + + private void addUpdateMenuItem(ModelMenuItem modelMenuItem, List menuItemList, + Map menuItemMap) { + ModelMenuItem existingMenuItem = menuItemMap.get(modelMenuItem.getName()); + if (existingMenuItem != null) { + // does exist, update the item by doing a merge/override + ModelMenuItem mergedMenuItem = existingMenuItem.mergeOverrideModelMenuItem(modelMenuItem); + int existingItemIndex = menuItemList.indexOf(existingMenuItem); + menuItemList.set(existingItemIndex, mergedMenuItem); + menuItemMap.put(modelMenuItem.getName(), mergedMenuItem); + } else { + // does not exist, add to List and Map + menuItemList.add(modelMenuItem); + menuItemMap.put(modelMenuItem.getName(), modelMenuItem); + } + } + + public List getActions() { + return actions; + } + + public String getAlign() { + if (!this.align.isEmpty()) { + return this.align; + } else if (parentMenuItem != null) { + return parentMenuItem.getAlign(); + } else { + return this.modelMenu.getDefaultAlign(); + } + } + + public String getAlignStyle() { + if (!this.alignStyle.isEmpty()) { + return this.alignStyle; + } else if (parentMenuItem != null) { + return parentMenuItem.getAlignStyle(); + } else { + return this.modelMenu.getDefaultAlignStyle(); + } + } + + public FlexibleStringExpander getAssociatedContentId() { + return associatedContentId; + } + + public String getAssociatedContentId(Map context) { + String retStr = null; + if (this.associatedContentId != null) { + retStr = associatedContentId.expandString(context); + } + if (retStr.isEmpty()) { + retStr = this.modelMenu.getDefaultAssociatedContentId(context); + } + return retStr; + } + + public String getCellWidth() { + if (!this.cellWidth.isEmpty()) { + return this.cellWidth; + } else { + return this.modelMenu.getDefaultCellWidth(); + } + } + + public ModelMenuCondition getCondition() { + return condition; + } + + public String getDisabledTitleStyle() { + if (!this.disabledTitleStyle.isEmpty()) { + return this.disabledTitleStyle; + } else if (parentMenuItem != null) { + return parentMenuItem.getDisabledTitleStyle(); + } else { + return this.modelMenu.getDefaultDisabledTitleStyle(); + } + } + + public String getDisableIfEmpty() { + return this.disableIfEmpty; + } + + public String getEntityName() { + if (!this.entityName.isEmpty()) { + return this.entityName; + } else if (parentMenuItem != null) { + return parentMenuItem.getEntityName(); + } else { + return this.modelMenu.getDefaultEntityName(); + } + } + + public Boolean getHideIfSelected() { + if (hideIfSelected != null) { + return this.hideIfSelected; + } else { + return this.modelMenu.getDefaultHideIfSelected(); + } + } + + public MenuLink getLink() { + return this.link; + } + + public List getMenuItemList() { + return menuItemList; + } + + public ModelMenu getModelMenu() { + return modelMenu; + } + + @Override + public String getName() { + if (!this.overrideName.isEmpty()) { + return this.overrideName; + } + return super.getName(); + } + + public String getOverrideName() { + return overrideName; + } + + public ModelMenuItem getParentMenuItem() { + return parentMenuItem; + } + + public FlexibleStringExpander getParentPortalPageId() { + return parentPortalPageId; + } + + public String getParentPortalPageId(Map context) { + return this.parentPortalPageId.expandString(context); + } + + public int getPosition() { + if (this.position == null) { + return 1; + } else { + return position.intValue(); + } + } + + public String getSelectedStyle() { + if (!this.selectedStyle.isEmpty()) { + return this.selectedStyle; + } else if (parentMenuItem != null) { + return parentMenuItem.getSelectedStyle(); + } else { + return this.modelMenu.getDefaultSelectedStyle(); + } + } + + public String getSubMenu() { + return subMenu; + } + + public FlexibleStringExpander getTitle() { + return title; + } + + public String getTitle(Map context) { + return title.expandString(context); + } + + public String getTitleStyle() { + if (!this.titleStyle.isEmpty()) { + return this.titleStyle; + } else if (parentMenuItem != null) { + return parentMenuItem.getTitleStyle(); + } else { + return this.modelMenu.getDefaultTitleStyle(); + } + } + + public FlexibleStringExpander getTooltip() { + return tooltip; + } + + public String getTooltip(Map context) { + if (UtilValidate.isNotEmpty(tooltip)) { + return tooltip.expandString(context); + } else { + return ""; + } + } + + public String getTooltipStyle() { + if (!this.tooltipStyle.isEmpty()) { + return this.tooltipStyle; + } else if (parentMenuItem != null) { + return parentMenuItem.getTooltipStyle(); + } else { + return this.modelMenu.getDefaultTooltipStyle(); + } + } + + public String getWidgetStyle() { + if (!this.widgetStyle.isEmpty()) { + return this.widgetStyle; + } else if (parentMenuItem != null) { + return parentMenuItem.getWidgetStyle(); + } else { + return this.modelMenu.getDefaultWidgetStyle(); + } + } + + public boolean isSelected(Map context) { + return getName().equals(modelMenu.getSelectedMenuItemContextFieldName(context)); + } + + public ModelMenuItem mergeOverrideModelMenuItem(ModelMenuItem overrideMenuItem) { + return new ModelMenuItem(this, overrideMenuItem); + } + + public void renderMenuItemString(Appendable writer, Map context, MenuStringRenderer menuStringRenderer) + throws IOException { + if (shouldBeRendered(context)) { + AbstractModelAction.runSubActions(actions, context); + String parentPortalPageId = getParentPortalPageId(context); + if (UtilValidate.isNotEmpty(parentPortalPageId)) { + List portalPages = PortalPageWorker.getPortalPages(parentPortalPageId, context); + if (UtilValidate.isNotEmpty(portalPages)) { + Locale locale = (Locale) context.get("locale"); + for (GenericValue portalPage : portalPages) { + if (UtilValidate.isNotEmpty(portalPage.getString("portalPageName"))) { + ModelMenuItem localItem = new ModelMenuItem(portalPage, this, locale); + menuStringRenderer.renderMenuItem(writer, context, localItem); + } + } + } + } else { + menuStringRenderer.renderMenuItem(writer, context, this); + } + } + } + + public boolean shouldBeRendered(Map context) { + if (this.condition != null) { + return this.condition.getCondition().eval(context); + } + return true; + } + + public static class MenuLink { + private final ModelMenuItem linkMenuItem; + private final Link link; + + public MenuLink(Element linkElement, ModelMenuItem parentMenuItem) { + this.linkMenuItem = parentMenuItem; + if (linkElement.getAttribute("text").isEmpty()) { + linkElement.setAttribute("text", parentMenuItem.getTitle().getOriginal()); + } + if (linkElement.getAttribute("style").isEmpty()) { + linkElement.setAttribute("style", parentMenuItem.getWidgetStyle()); + } + this.link = new Link(linkElement); + } + + public MenuLink(GenericValue portalPage, ModelMenuItem parentMenuItem, Locale locale) { + this.linkMenuItem = parentMenuItem; + ArrayList parameterList = new ArrayList(); + if (parentMenuItem.link != null) { + parameterList.addAll(parentMenuItem.link.getParameterList()); + } + parameterList.add(new Parameter("portalPageId", portalPage.getString("portalPageId"), false)); + parameterList.add(new Parameter("parentPortalPageId", portalPage.getString("parentPortalPageId"), false)); + String target = "showPortalPage"; + if (parentMenuItem.link != null) { + target= ""; + } + this.link = new Link(portalPage, parameterList, target, locale); + } + + public AutoEntityParameters getAutoEntityParameters() { + return link.getAutoEntityParameters(); + } + + public AutoServiceParameters getAutoServiceParameters() { + return link.getAutoServiceParameters(); + } + + public boolean getEncode() { + return link.getEncode(); + } + + public boolean getFullPath() { + return link.getFullPath(); + } + + public String getHeight() { + return link.getHeight(); + } + + public String getId(Map context) { + return link.getId(context); + } + + public FlexibleStringExpander getIdExdr() { + return link.getIdExdr(); + } + + public Image getImage() { + return link.getImage(); + } + + public String getLinkType() { + return link.getLinkType(); + } + + public String getName() { + return link.getName(); + } + + public String getName(Map context) { + return link.getName(context); + } + + public FlexibleStringExpander getNameExdr() { + return link.getNameExdr(); + } + + public List getParameterList() { + return link.getParameterList(); + } + + public Map getParameterMap(Map context) { + return link.getParameterMap(context); + } + + public String getPrefix(Map context) { + return link.getPrefix(context); + } + + public FlexibleStringExpander getPrefixExdr() { + return link.getPrefixExdr(); + } + + public boolean getSecure() { + return link.getSecure(); + } + + public String getStyle(Map context) { + return link.getStyle(context); + } + + public FlexibleStringExpander getStyleExdr() { + return link.getStyleExdr(); + } + + public String getTarget(Map context) { + return link.getTarget(context); + } + + public FlexibleStringExpander getTargetExdr() { + return link.getTargetExdr(); + } + + public String getTargetWindow(Map context) { + return link.getTargetWindow(context); + } + + public FlexibleStringExpander getTargetWindowExdr() { + return link.getTargetWindowExdr(); + } + + public String getText(Map context) { + return link.getText(context); + } + + public FlexibleStringExpander getTextExdr() { + return link.getTextExdr(); + } + + public String getUrlMode() { + return link.getUrlMode(); + } + + public String getWidth() { + return link.getWidth(); + } + + public ModelMenuItem getLinkMenuItem() { + return linkMenuItem; + } + + public Link getLink() { + return link; + } + + public void renderLinkString(Appendable writer, Map context, MenuStringRenderer menuStringRenderer) + throws IOException { + menuStringRenderer.renderLink(writer, context, this); + } + } +} diff --git a/framework/widget/src/org/ofbiz/widget/screen/ModelScreen.java b/framework/widget/src/org/ofbiz/widget/model/ModelScreen.java similarity index 96% rename from framework/widget/src/org/ofbiz/widget/screen/ModelScreen.java rename to framework/widget/src/org/ofbiz/widget/model/ModelScreen.java index ba51445e2d..0058a3c082 100644 --- a/framework/widget/src/org/ofbiz/widget/screen/ModelScreen.java +++ b/framework/widget/src/org/ofbiz/widget/model/ModelScreen.java @@ -1,194 +1,194 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget.screen; - -import java.util.Map; - -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.UtilGenerics; -import org.ofbiz.base.util.UtilValidate; -import org.ofbiz.base.util.UtilXml; -import org.ofbiz.base.util.string.FlexibleStringExpander; -import org.ofbiz.entity.Delegator; -import org.ofbiz.entity.GenericEntity; -import org.ofbiz.entity.GenericEntityException; -import org.ofbiz.entity.transaction.TransactionUtil; -import org.ofbiz.service.LocalDispatcher; -import org.ofbiz.widget.ModelWidget; -import org.ofbiz.widget.ModelWidgetVisitor; -import org.w3c.dom.Element; - -/** - * Widget Library - Screen model class - */ -@SuppressWarnings("serial") -public class ModelScreen extends ModelWidget { - - public static final String module = ModelScreen.class.getName(); - - private final String sourceLocation; - private final FlexibleStringExpander transactionTimeoutExdr; - private final Map modelScreenMap; - private final boolean useTransaction; - private final boolean useCache; - private final ModelScreenWidget.Section section; - - /** XML Constructor */ - public ModelScreen(Element screenElement, Map modelScreenMap, String sourceLocation) { - super(screenElement); - this.sourceLocation = sourceLocation; - this.transactionTimeoutExdr = FlexibleStringExpander.getInstance(screenElement.getAttribute("transaction-timeout")); - this.modelScreenMap = modelScreenMap; - this.useTransaction = "true".equals(screenElement.getAttribute("use-transaction")); - this.useCache = "true".equals(screenElement.getAttribute("use-cache")); - - // read in the section, which will read all sub-widgets too - Element sectionElement = UtilXml.firstChildElement(screenElement, "section"); - if (sectionElement == null) { - throw new IllegalArgumentException("No section found for the screen definition with name: " + getName()); - } - this.section = new ModelScreenWidget.Section(this, sectionElement, true); - } - - @Override - public void accept(ModelWidgetVisitor visitor) throws Exception { - visitor.visit(this); - } - - public String getTransactionTimeout() { - return transactionTimeoutExdr.getOriginal(); - } - - public Map getModelScreenMap() { - return modelScreenMap; - } - - public boolean getUseTransaction() { - return useTransaction; - } - - public boolean getUseCache() { - return useCache; - } - - public ModelScreenWidget.Section getSection() { - return section; - } - - public String getSourceLocation() { - return sourceLocation; - } - - /** - * Renders this screen to a String, i.e. in a text format, as defined with the - * ScreenStringRenderer implementation. - * - * @param writer The Writer that the screen text will be written to - * @param context Map containing the screen context; the following are - * reserved words in this context: - * - parameters (contains any special initial parameters coming in) - * - userLogin (if a user is logged in) - * - autoUserLogin (if a user is automatically logged in, ie no password has been entered) - * - formStringRenderer - * - request, response, session, application (special case, only in HTML contexts, etc) - * - delegator, dispatcher, security - * - null (represents a null field value for entity operations) - * - sections (used for decorators to reference the sections to be decorated and render them) - * @param screenStringRenderer An implementation of the ScreenStringRenderer - * interface that is responsible for the actual text generation for - * different screen elements; implementing your own makes it possible to - * use the same screen definitions for many types of screen UIs - */ - public void renderScreenString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) throws ScreenRenderException { - // make sure the "nullField" object is in there for entity ops - context.put("nullField", GenericEntity.NULL_FIELD); - - // wrap the whole screen rendering in a transaction, should improve performance in querying and such - Map parameters = UtilGenerics.cast(context.get("parameters")); - boolean beganTransaction = false; - int transactionTimeout = -1; - if (parameters != null) { - String transactionTimeoutPar = parameters.get("TRANSACTION_TIMEOUT"); - if (transactionTimeoutPar != null) { - try { - transactionTimeout = Integer.parseInt(transactionTimeoutPar); - } catch (NumberFormatException nfe) { - String msg = "TRANSACTION_TIMEOUT parameter for screen [" + this.sourceLocation + "#" + getName() + "] is invalid and it will be ignored: " + nfe.toString(); - Debug.logWarning(msg, module); - } - } - } - - if (transactionTimeout < 0 && !transactionTimeoutExdr.isEmpty()) { - // no TRANSACTION_TIMEOUT parameter, check screen attribute - String transactionTimeoutStr = transactionTimeoutExdr.expandString(context); - if (UtilValidate.isNotEmpty(transactionTimeoutStr)) { - try { - transactionTimeout = Integer.parseInt(transactionTimeoutStr); - } catch (NumberFormatException e) { - Debug.logWarning(e, "Could not parse transaction-timeout value, original=[" + transactionTimeoutExdr + "], expanded=[" + transactionTimeoutStr + "]", module); - } - } - } - - try { - // If transaction timeout is not present (i.e. is equal to -1), the default transaction timeout is used - // If transaction timeout is present, use it to start the transaction - // If transaction timeout is set to zero, no transaction is started - if (useTransaction) { - if (transactionTimeout < 0) { - beganTransaction = TransactionUtil.begin(); - } - if (transactionTimeout > 0) { - beganTransaction = TransactionUtil.begin(transactionTimeout); - } - } - - // render the screen, starting with the top-level section - this.section.renderWidgetString(writer, context, screenStringRenderer); - TransactionUtil.commit(beganTransaction); - } catch (Exception e) { - String errMsg = "Error rendering screen [" + this.sourceLocation + "#" + getName() + "]: " + e.toString(); - Debug.logError(errMsg + ". Rolling back transaction.", module); - try { - // only rollback the transaction if we started one... - TransactionUtil.rollback(beganTransaction, errMsg, e); - } catch (GenericEntityException e2) { - Debug.logError(e2, "Could not rollback transaction: " + e2.toString(), module); - } - - // throw nested exception, don't need to log details here: Debug.logError(e, errMsg, module); - - // after rolling back, rethrow the exception - throw new ScreenRenderException(errMsg, e); - } - } - - public LocalDispatcher getDispatcher(Map context) { - LocalDispatcher dispatcher = (LocalDispatcher) context.get("dispatcher"); - return dispatcher; - } - - public Delegator getDelegator(Map context) { - Delegator delegator = (Delegator) context.get("delegator"); - return delegator; - } -} - - +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.model; + +import java.util.Map; + +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilGenerics; +import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.base.util.UtilXml; +import org.ofbiz.base.util.string.FlexibleStringExpander; +import org.ofbiz.entity.Delegator; +import org.ofbiz.entity.GenericEntity; +import org.ofbiz.entity.GenericEntityException; +import org.ofbiz.entity.transaction.TransactionUtil; +import org.ofbiz.service.LocalDispatcher; +import org.ofbiz.widget.renderer.ScreenRenderException; +import org.ofbiz.widget.renderer.ScreenStringRenderer; +import org.w3c.dom.Element; + +/** + * Widget Library - Screen model class + */ +@SuppressWarnings("serial") +public class ModelScreen extends ModelWidget { + + public static final String module = ModelScreen.class.getName(); + + private final String sourceLocation; + private final FlexibleStringExpander transactionTimeoutExdr; + private final Map modelScreenMap; + private final boolean useTransaction; + private final boolean useCache; + private final ModelScreenWidget.Section section; + + /** XML Constructor */ + public ModelScreen(Element screenElement, Map modelScreenMap, String sourceLocation) { + super(screenElement); + this.sourceLocation = sourceLocation; + this.transactionTimeoutExdr = FlexibleStringExpander.getInstance(screenElement.getAttribute("transaction-timeout")); + this.modelScreenMap = modelScreenMap; + this.useTransaction = "true".equals(screenElement.getAttribute("use-transaction")); + this.useCache = "true".equals(screenElement.getAttribute("use-cache")); + + // read in the section, which will read all sub-widgets too + Element sectionElement = UtilXml.firstChildElement(screenElement, "section"); + if (sectionElement == null) { + throw new IllegalArgumentException("No section found for the screen definition with name: " + getName()); + } + this.section = new ModelScreenWidget.Section(this, sectionElement, true); + } + + @Override + public void accept(ModelWidgetVisitor visitor) throws Exception { + visitor.visit(this); + } + + public String getTransactionTimeout() { + return transactionTimeoutExdr.getOriginal(); + } + + public Map getModelScreenMap() { + return modelScreenMap; + } + + public boolean getUseTransaction() { + return useTransaction; + } + + public boolean getUseCache() { + return useCache; + } + + public ModelScreenWidget.Section getSection() { + return section; + } + + public String getSourceLocation() { + return sourceLocation; + } + + /** + * Renders this screen to a String, i.e. in a text format, as defined with the + * ScreenStringRenderer implementation. + * + * @param writer The Writer that the screen text will be written to + * @param context Map containing the screen context; the following are + * reserved words in this context: + * - parameters (contains any special initial parameters coming in) + * - userLogin (if a user is logged in) + * - autoUserLogin (if a user is automatically logged in, ie no password has been entered) + * - formStringRenderer + * - request, response, session, application (special case, only in HTML contexts, etc) + * - delegator, dispatcher, security + * - null (represents a null field value for entity operations) + * - sections (used for decorators to reference the sections to be decorated and render them) + * @param screenStringRenderer An implementation of the ScreenStringRenderer + * interface that is responsible for the actual text generation for + * different screen elements; implementing your own makes it possible to + * use the same screen definitions for many types of screen UIs + */ + public void renderScreenString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) throws ScreenRenderException { + // make sure the "nullField" object is in there for entity ops + context.put("nullField", GenericEntity.NULL_FIELD); + + // wrap the whole screen rendering in a transaction, should improve performance in querying and such + Map parameters = UtilGenerics.cast(context.get("parameters")); + boolean beganTransaction = false; + int transactionTimeout = -1; + if (parameters != null) { + String transactionTimeoutPar = parameters.get("TRANSACTION_TIMEOUT"); + if (transactionTimeoutPar != null) { + try { + transactionTimeout = Integer.parseInt(transactionTimeoutPar); + } catch (NumberFormatException nfe) { + String msg = "TRANSACTION_TIMEOUT parameter for screen [" + this.sourceLocation + "#" + getName() + "] is invalid and it will be ignored: " + nfe.toString(); + Debug.logWarning(msg, module); + } + } + } + + if (transactionTimeout < 0 && !transactionTimeoutExdr.isEmpty()) { + // no TRANSACTION_TIMEOUT parameter, check screen attribute + String transactionTimeoutStr = transactionTimeoutExdr.expandString(context); + if (UtilValidate.isNotEmpty(transactionTimeoutStr)) { + try { + transactionTimeout = Integer.parseInt(transactionTimeoutStr); + } catch (NumberFormatException e) { + Debug.logWarning(e, "Could not parse transaction-timeout value, original=[" + transactionTimeoutExdr + "], expanded=[" + transactionTimeoutStr + "]", module); + } + } + } + + try { + // If transaction timeout is not present (i.e. is equal to -1), the default transaction timeout is used + // If transaction timeout is present, use it to start the transaction + // If transaction timeout is set to zero, no transaction is started + if (useTransaction) { + if (transactionTimeout < 0) { + beganTransaction = TransactionUtil.begin(); + } + if (transactionTimeout > 0) { + beganTransaction = TransactionUtil.begin(transactionTimeout); + } + } + + // render the screen, starting with the top-level section + this.section.renderWidgetString(writer, context, screenStringRenderer); + TransactionUtil.commit(beganTransaction); + } catch (Exception e) { + String errMsg = "Error rendering screen [" + this.sourceLocation + "#" + getName() + "]: " + e.toString(); + Debug.logError(errMsg + ". Rolling back transaction.", module); + try { + // only rollback the transaction if we started one... + TransactionUtil.rollback(beganTransaction, errMsg, e); + } catch (GenericEntityException e2) { + Debug.logError(e2, "Could not rollback transaction: " + e2.toString(), module); + } + + // throw nested exception, don't need to log details here: Debug.logError(e, errMsg, module); + + // after rolling back, rethrow the exception + throw new ScreenRenderException(errMsg, e); + } + } + + public LocalDispatcher getDispatcher(Map context) { + LocalDispatcher dispatcher = (LocalDispatcher) context.get("dispatcher"); + return dispatcher; + } + + public Delegator getDelegator(Map context) { + Delegator delegator = (Delegator) context.get("delegator"); + return delegator; + } +} + + diff --git a/framework/widget/src/org/ofbiz/widget/screen/ModelScreenCondition.java b/framework/widget/src/org/ofbiz/widget/model/ModelScreenCondition.java similarity index 88% rename from framework/widget/src/org/ofbiz/widget/screen/ModelScreenCondition.java rename to framework/widget/src/org/ofbiz/widget/model/ModelScreenCondition.java index fb1227a8ec..8926f985d0 100644 --- a/framework/widget/src/org/ofbiz/widget/screen/ModelScreenCondition.java +++ b/framework/widget/src/org/ofbiz/widget/model/ModelScreenCondition.java @@ -1,96 +1,96 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget.screen; - -import java.util.Map; - -import org.ofbiz.base.util.UtilGenerics; -import org.ofbiz.base.util.string.FlexibleStringExpander; -import org.ofbiz.widget.AbstractModelCondition; -import org.ofbiz.widget.AbstractModelCondition.DefaultConditionFactory; -import org.ofbiz.widget.ModelCondition; -import org.ofbiz.widget.ModelConditionFactory; -import org.ofbiz.widget.ModelConditionVisitor; -import org.ofbiz.widget.ModelWidget; -import org.w3c.dom.Element; - -/** - * Models the <condition> element. - * - * @see widget-screen.xsd - */ -@SuppressWarnings("serial") -public final class ModelScreenCondition { - - /* - * ----------------------------------------------------------------------- * - * DEVELOPERS PLEASE READ - * ----------------------------------------------------------------------- * - * - * This model is intended to be a read-only data structure that represents - * an XML element. Outside of object construction, the class should not - * have any behaviors. - * - * Instances of this class will be shared by multiple threads - therefore - * it is immutable. DO NOT CHANGE THE OBJECT'S STATE AT RUN TIME! - * - */ - - public static final String module = ModelScreenCondition.class.getName(); - public static final ModelConditionFactory SCREEN_CONDITION_FACTORY = new ScreenConditionFactory(); - - public static class IfEmptySection extends AbstractModelCondition { - private final FlexibleStringExpander sectionExdr; - - private IfEmptySection(ModelConditionFactory factory, ModelWidget modelWidget, Element condElement) { - super (factory, modelWidget, condElement); - this.sectionExdr = FlexibleStringExpander.getInstance(condElement.getAttribute("section-name")); - } - - @Override - public void accept(ModelConditionVisitor visitor) throws Exception { - visitor.visit(this); - } - - @Override - public boolean eval(Map context) { - Map sectionsMap = UtilGenerics.toMap(context.get("sections")); - return !sectionsMap.containsKey(this.sectionExdr.expandString(context)); - } - - public FlexibleStringExpander getSectionExdr() { - return sectionExdr; - } - } - - private static class ScreenConditionFactory extends DefaultConditionFactory { - - @Override - public ModelCondition newInstance(ModelWidget modelWidget, Element conditionElement) { - if (conditionElement == null) { - return DefaultConditionFactory.TRUE; - } - if ("if-empty-section".equals(conditionElement.getNodeName())) { - return new IfEmptySection(this, modelWidget, conditionElement); - } else { - return super.newInstance(this, modelWidget,conditionElement); - } - } - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.model; + +import java.util.Map; + +import org.ofbiz.base.util.UtilGenerics; +import org.ofbiz.base.util.string.FlexibleStringExpander; +import org.ofbiz.widget.model.AbstractModelCondition; +import org.ofbiz.widget.model.AbstractModelCondition.DefaultConditionFactory; +import org.ofbiz.widget.model.ModelCondition; +import org.ofbiz.widget.model.ModelConditionFactory; +import org.ofbiz.widget.model.ModelConditionVisitor; +import org.ofbiz.widget.model.ModelWidget; +import org.w3c.dom.Element; + +/** + * Models the <condition> element. + * + * @see widget-screen.xsd + */ +@SuppressWarnings("serial") +public final class ModelScreenCondition { + + /* + * ----------------------------------------------------------------------- * + * DEVELOPERS PLEASE READ + * ----------------------------------------------------------------------- * + * + * This model is intended to be a read-only data structure that represents + * an XML element. Outside of object construction, the class should not + * have any behaviors. + * + * Instances of this class will be shared by multiple threads - therefore + * it is immutable. DO NOT CHANGE THE OBJECT'S STATE AT RUN TIME! + * + */ + + public static final String module = ModelScreenCondition.class.getName(); + public static final ModelConditionFactory SCREEN_CONDITION_FACTORY = new ScreenConditionFactory(); + + public static class IfEmptySection extends AbstractModelCondition { + private final FlexibleStringExpander sectionExdr; + + private IfEmptySection(ModelConditionFactory factory, ModelWidget modelWidget, Element condElement) { + super (factory, modelWidget, condElement); + this.sectionExdr = FlexibleStringExpander.getInstance(condElement.getAttribute("section-name")); + } + + @Override + public void accept(ModelConditionVisitor visitor) throws Exception { + visitor.visit(this); + } + + @Override + public boolean eval(Map context) { + Map sectionsMap = UtilGenerics.toMap(context.get("sections")); + return !sectionsMap.containsKey(this.sectionExdr.expandString(context)); + } + + public FlexibleStringExpander getSectionExdr() { + return sectionExdr; + } + } + + private static class ScreenConditionFactory extends DefaultConditionFactory { + + @Override + public ModelCondition newInstance(ModelWidget modelWidget, Element conditionElement) { + if (conditionElement == null) { + return DefaultConditionFactory.TRUE; + } + if ("if-empty-section".equals(conditionElement.getNodeName())) { + return new IfEmptySection(this, modelWidget, conditionElement); + } else { + return super.newInstance(this, modelWidget,conditionElement); + } + } + } +} diff --git a/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java b/framework/widget/src/org/ofbiz/widget/model/ModelScreenWidget.java similarity index 96% rename from framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java rename to framework/widget/src/org/ofbiz/widget/model/ModelScreenWidget.java index 4214aea313..f5d1949635 100644 --- a/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java +++ b/framework/widget/src/org/ofbiz/widget/model/ModelScreenWidget.java @@ -1,1966 +1,1957 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget.screen; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.ListIterator; -import java.util.Map; -import java.util.Set; - -import javax.xml.parsers.ParserConfigurationException; - -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.GeneralException; -import org.ofbiz.base.util.UtilCodec; -import org.ofbiz.base.util.UtilGenerics; -import org.ofbiz.base.util.UtilXml; -import org.ofbiz.base.util.collections.MapStack; -import org.ofbiz.base.util.string.FlexibleStringExpander; -import org.ofbiz.entity.Delegator; -import org.ofbiz.entity.GenericEntityException; -import org.ofbiz.entity.GenericValue; -import org.ofbiz.entity.util.EntityQuery; -import org.ofbiz.widget.AbstractModelAction; -import org.ofbiz.widget.CommonWidgetModels.*; -import org.ofbiz.widget.CommonWidgetModels.AutoEntityParameters; -import org.ofbiz.widget.CommonWidgetModels.AutoServiceParameters; -import org.ofbiz.widget.CommonWidgetModels.Image; -import org.ofbiz.widget.CommonWidgetModels.Parameter; -import org.ofbiz.widget.ModelAction; -import org.ofbiz.widget.ModelCondition; -import org.ofbiz.widget.ModelWidget; -import org.ofbiz.widget.ModelWidgetVisitor; -import org.ofbiz.widget.PortalPageWorker; -import org.ofbiz.widget.WidgetFactory; -import org.ofbiz.widget.form.FormFactory; -import org.ofbiz.widget.form.FormRenderer; -import org.ofbiz.widget.form.FormStringRenderer; -import org.ofbiz.widget.form.ModelForm; -import org.ofbiz.widget.menu.MenuFactory; -import org.ofbiz.widget.menu.MenuStringRenderer; -import org.ofbiz.widget.menu.ModelMenu; -import org.ofbiz.widget.tree.ModelTree; -import org.ofbiz.widget.tree.TreeFactory; -import org.ofbiz.widget.tree.TreeStringRenderer; -import org.w3c.dom.Element; -import org.xml.sax.SAXException; - - -/** - * Widget Library - Screen model class - */ -@SuppressWarnings("serial") -public abstract class ModelScreenWidget extends ModelWidget { - public static final String module = ModelScreenWidget.class.getName(); - - private final ModelScreen modelScreen; - - public ModelScreenWidget(ModelScreen modelScreen, Element widgetElement) { - super(widgetElement); - this.modelScreen = modelScreen; - if (Debug.verboseOn()) Debug.logVerbose("Reading Screen sub-widget with name: " + widgetElement.getNodeName(), module); - } - - public abstract void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException, IOException; - - protected static List readSubWidgets(ModelScreen modelScreen, List subElementList) { - if (subElementList.isEmpty()) { - return Collections.emptyList(); - } - List subWidgets = new ArrayList(subElementList.size()); - for (Element subElement: subElementList) { - subWidgets.add(WidgetFactory.getModelScreenWidget(modelScreen, subElement)); - } - return Collections.unmodifiableList(subWidgets); - } - - protected static void renderSubWidgetsString(List subWidgets, Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException, IOException { - if (subWidgets == null) { - return; - } - for (ModelScreenWidget subWidget: subWidgets) { - if (Debug.verboseOn()) Debug.logVerbose("Rendering screen " + subWidget.getModelScreen().getName() + "; widget class is " + subWidget.getClass().getName(), module); - - // render the sub-widget itself - subWidget.renderWidgetString(writer, context, screenStringRenderer); - } - } - - public ModelScreen getModelScreen() { - return this.modelScreen; - } - - public static final class SectionsRenderer implements Map { - private final Map sectionMap; - private final ScreenStringRenderer screenStringRenderer; - private final Map context; - private final Appendable writer; - - public SectionsRenderer(Map sectionMap, Map context, Appendable writer, - ScreenStringRenderer screenStringRenderer) { - Map localMap = new HashMap(); - localMap.putAll(sectionMap); - this.sectionMap = Collections.unmodifiableMap(localMap); - this.context = context; - this.writer = writer; - this.screenStringRenderer = screenStringRenderer; - } - - /** This is a lot like the ScreenRenderer class and returns an empty String so it can be used more easily with FreeMarker */ - public String render(String sectionName) throws GeneralException, IOException { - ModelScreenWidget section = sectionMap.get(sectionName); - // if no section by that name, write nothing - if (section != null) { - section.renderWidgetString(this.writer, this.context, this.screenStringRenderer); - } - return ""; - } - - @Override - public int size() { - return sectionMap.size(); - } - - @Override - public boolean isEmpty() { - return sectionMap.isEmpty(); - } - - @Override - public boolean containsKey(Object key) { - return sectionMap.containsKey(key); - } - - @Override - public boolean containsValue(Object value) { - return sectionMap.containsValue(value); - } - - @Override - public ModelScreenWidget get(Object key) { - return sectionMap.get(key); - } - - @Override - public ModelScreenWidget put(String key, ModelScreenWidget value) { - return sectionMap.put(key, value); - } - - @Override - public ModelScreenWidget remove(Object key) { - return sectionMap.remove(key); - } - - @Override - public void clear() { - sectionMap.clear(); - } - - @Override - public Set keySet() { - return sectionMap.keySet(); - } - - @Override - public Collection values() { - return sectionMap.values(); - } - - @Override - public Set> entrySet() { - return sectionMap.entrySet(); - } - - @Override - public boolean equals(Object o) { - return sectionMap.equals(o); - } - - @Override - public int hashCode() { - return sectionMap.hashCode(); - } - - @Override - public void putAll(Map m) { - sectionMap.putAll(m); - } - } - - public static final class Section extends ModelScreenWidget { - public static final String TAG_NAME = "section"; - private final ModelCondition condition; - private final List actions; - private final List subWidgets; - private final List failWidgets; - private final boolean isMainSection; - - public Section(ModelScreen modelScreen, Element sectionElement) { - this(modelScreen, sectionElement, false); - } - - public Section(ModelScreen modelScreen, Element sectionElement, boolean isMainSection) { - super(modelScreen, sectionElement); - - // read condition under the "condition" element - Element conditionElement = UtilXml.firstChildElement(sectionElement, "condition"); - if (conditionElement != null) { - conditionElement = UtilXml.firstChildElement(conditionElement); - this.condition = ModelScreenCondition.SCREEN_CONDITION_FACTORY.newInstance(modelScreen, conditionElement); - } else { - this.condition = null; - } - - // read all actions under the "actions" element - Element actionsElement = UtilXml.firstChildElement(sectionElement, "actions"); - if (actionsElement != null) { - this.actions = AbstractModelAction.readSubActions(modelScreen, actionsElement); - } else { - this.actions = Collections.emptyList(); - } - - // read sub-widgets - Element widgetsElement = UtilXml.firstChildElement(sectionElement, "widgets"); - if (widgetsElement != null) { - List subElementList = UtilXml.childElementList(widgetsElement); - this.subWidgets = ModelScreenWidget.readSubWidgets(getModelScreen(), subElementList); - } else { - this.subWidgets = Collections.emptyList(); - } - - // read fail-widgets - Element failWidgetsElement = UtilXml.firstChildElement(sectionElement, "fail-widgets"); - if (failWidgetsElement != null) { - List failElementList = UtilXml.childElementList(failWidgetsElement); - this.failWidgets = ModelScreenWidget.readSubWidgets(getModelScreen(), failElementList); - } else { - this.failWidgets = Collections.emptyList(); - } - this.isMainSection = isMainSection; - } - - @Override - public void accept(ModelWidgetVisitor visitor) throws Exception { - visitor.visit(this); - } - - @Override - public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException, IOException { - // check the condition, if there is one - boolean condTrue = true; - if (this.condition != null) { - if (!this.condition.eval(context)) { - condTrue = false; - } - } - - // if condition does not exist or evals to true run actions and render widgets, otherwise render fail-widgets - if (condTrue) { - // run the actions only if true - AbstractModelAction.runSubActions(this.actions, context); - - try { - // section by definition do not themselves do anything, so this method will generally do nothing, but we'll call it anyway - screenStringRenderer.renderSectionBegin(writer, context, this); - - // render sub-widgets - renderSubWidgetsString(this.subWidgets, writer, context, screenStringRenderer); - - screenStringRenderer.renderSectionEnd(writer, context, this); - } catch (IOException e) { - String errMsg = "Error rendering widgets section [" + getName() + "] in screen named [" + getModelScreen().getName() + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - throw new RuntimeException(errMsg); - } - } else { - try { - // section by definition do not themselves do anything, so this method will generally do nothing, but we'll call it anyway - screenStringRenderer.renderSectionBegin(writer, context, this); - - // render sub-widgets - renderSubWidgetsString(this.failWidgets, writer, context, screenStringRenderer); - - screenStringRenderer.renderSectionEnd(writer, context, this); - } catch (IOException e) { - String errMsg = "Error rendering fail-widgets section [" + this.getName() + "] in screen named [" + getModelScreen().getName() + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - throw new RuntimeException(errMsg); - } - } - - } - - @Override - public String getBoundaryCommentName() { - if (isMainSection) { - return getModelScreen().getSourceLocation() + "#" + getModelScreen().getName(); - } else { - return getName(); - } - } - - public List getActions() { - return actions; - } - - public List getSubWidgets() { - return subWidgets; - } - - public List getFailWidgets() { - return failWidgets; - } - - public boolean isMainSection() { - return isMainSection; - } - - public ModelCondition getCondition() { - return condition; - } - } - - public static final class ColumnContainer extends ModelScreenWidget { - public static final String TAG_NAME = "column-container"; - private final FlexibleStringExpander idExdr; - private final FlexibleStringExpander styleExdr; - private final List columns; - - public ColumnContainer(ModelScreen modelScreen, Element containerElement) { - super(modelScreen, containerElement); - this.idExdr = FlexibleStringExpander.getInstance(containerElement.getAttribute("id")); - this.styleExdr = FlexibleStringExpander.getInstance(containerElement.getAttribute("style")); - List subElementList = UtilXml.childElementList(containerElement, "column"); - List columns = new ArrayList(subElementList.size()); - for (Element element : subElementList) { - columns.add(new Column(modelScreen, element)); - } - this.columns = Collections.unmodifiableList(columns); - } - - @Override - public void accept(ModelWidgetVisitor visitor) throws Exception { - visitor.visit(this); - } - - @Override - public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException, IOException { - try { - screenStringRenderer.renderColumnContainer(writer, context, this); - } catch (IOException e) { - String errMsg = "Error rendering container in screen named [" + getModelScreen().getName() + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - throw new RuntimeException(errMsg); - } - } - - public List getColumns() { - return this.columns; - } - - public String getId(Map context) { - return this.idExdr.expandString(context); - } - - public String getStyle(Map context) { - return this.styleExdr.expandString(context); - } - - public FlexibleStringExpander getIdExdr() { - return idExdr; - } - - public FlexibleStringExpander getStyleExdr() { - return styleExdr; - } - } - - public static final class Column extends ModelWidget { - private final FlexibleStringExpander idExdr; - private final FlexibleStringExpander styleExdr; - private final List subWidgets; - - public Column(ModelScreen modelScreen, Element columnElement) { - super(columnElement); - this.idExdr = FlexibleStringExpander.getInstance(columnElement.getAttribute("id")); - this.styleExdr = FlexibleStringExpander.getInstance(columnElement.getAttribute("style")); - List subElementList = UtilXml.childElementList(columnElement); - this.subWidgets = Collections.unmodifiableList(readSubWidgets(modelScreen, subElementList)); - } - - public List getSubWidgets() { - return this.subWidgets; - } - - public String getId(Map context) { - return this.idExdr.expandString(context); - } - - public String getStyle(Map context) { - return this.styleExdr.expandString(context); - } - - @Override - public void accept(ModelWidgetVisitor visitor) throws Exception { - visitor.visit(this); - } - - public FlexibleStringExpander getIdExdr() { - return idExdr; - } - - public FlexibleStringExpander getStyleExdr() { - return styleExdr; - } - } - - public static final class Container extends ModelScreenWidget { - public static final String TAG_NAME = "container"; - private final FlexibleStringExpander idExdr; - private final FlexibleStringExpander styleExdr; - private final FlexibleStringExpander autoUpdateTargetExdr; - private final FlexibleStringExpander autoUpdateInterval; - private final List subWidgets; - - public Container(ModelScreen modelScreen, Element containerElement) { - super(modelScreen, containerElement); - this.idExdr = FlexibleStringExpander.getInstance(containerElement.getAttribute("id")); - this.styleExdr = FlexibleStringExpander.getInstance(containerElement.getAttribute("style")); - this.autoUpdateTargetExdr = FlexibleStringExpander.getInstance(containerElement.getAttribute("auto-update-target")); - String autoUpdateInterval = containerElement.getAttribute("auto-update-interval"); - if (autoUpdateInterval.isEmpty()) { - autoUpdateInterval = "2"; - } - this.autoUpdateInterval = FlexibleStringExpander.getInstance(autoUpdateInterval); - // read sub-widgets - List subElementList = UtilXml.childElementList(containerElement); - this.subWidgets = ModelScreenWidget.readSubWidgets(getModelScreen(), subElementList); - } - - @Override - public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException, IOException { - try { - screenStringRenderer.renderContainerBegin(writer, context, this); - - // render sub-widgets - renderSubWidgetsString(this.subWidgets, writer, context, screenStringRenderer); - - screenStringRenderer.renderContainerEnd(writer, context, this); - } catch (IOException e) { - String errMsg = "Error rendering container in screen named [" + getModelScreen().getName() + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - throw new RuntimeException(errMsg); - } - } - - public String getId(Map context) { - return this.idExdr.expandString(context); - } - - public String getStyle(Map context) { - return this.styleExdr.expandString(context); - } - - public String getAutoUpdateTargetExdr(Map context) { - return this.autoUpdateTargetExdr.expandString(context); - } - - public String getAutoUpdateInterval(Map context) { - return this.autoUpdateInterval.expandString(context); - } - - public List getSubWidgets() { - return subWidgets; - } - - @Override - public void accept(ModelWidgetVisitor visitor) throws Exception { - visitor.visit(this); - } - - public FlexibleStringExpander getIdExdr() { - return idExdr; - } - - public FlexibleStringExpander getStyleExdr() { - return styleExdr; - } - - public FlexibleStringExpander getAutoUpdateTargetExdr() { - return autoUpdateTargetExdr; - } - - public FlexibleStringExpander getAutoUpdateInterval() { - return autoUpdateInterval; - } - } - - public static final class Screenlet extends ModelScreenWidget { - public static final String TAG_NAME = "screenlet"; - private final FlexibleStringExpander idExdr; - private final FlexibleStringExpander titleExdr; - private final Menu navigationMenu; - private final Menu tabMenu; - private final Form navigationForm; - private final boolean collapsible; - private final FlexibleStringExpander initiallyCollapsed; - private final boolean saveCollapsed; - private final boolean padded; - private final List subWidgets; - - public Screenlet(ModelScreen modelScreen, Element screenletElement) { - super(modelScreen, screenletElement); - this.idExdr = FlexibleStringExpander.getInstance(screenletElement.getAttribute("id")); - boolean collapsible = "true".equals(screenletElement.getAttribute("collapsible")); - this.initiallyCollapsed = FlexibleStringExpander.getInstance(screenletElement.getAttribute("initially-collapsed")); - if ("true".equals(this.initiallyCollapsed.getOriginal())) { - collapsible = true; - } - this.collapsible = collapsible; - // By default, for a collapsible screenlet, the collapsed/expanded status must be saved - this.saveCollapsed = !("false".equals(screenletElement.getAttribute("save-collapsed"))); - - boolean padded = !"false".equals(screenletElement.getAttribute("padded")); - if (this.collapsible && getName().isEmpty() && idExdr.isEmpty()) { - throw new IllegalArgumentException("Collapsible screenlets must have a name or id [" + getModelScreen().getName() + "]"); - } - this.titleExdr = FlexibleStringExpander.getInstance(screenletElement.getAttribute("title")); - List subElementList = UtilXml.childElementList(screenletElement); - // Make a copy of the unmodifiable List so we can modify it. - ArrayList subWidgets = new ArrayList(ModelScreenWidget.readSubWidgets(getModelScreen(), subElementList)); - Menu navigationMenu = null; - String navMenuName = screenletElement.getAttribute("navigation-menu-name"); - if (!navMenuName.isEmpty()) { - for (ModelWidget subWidget : subWidgets) { - if (navMenuName.equals(subWidget.getName()) && subWidget instanceof Menu) { - navigationMenu = (Menu) subWidget; - subWidgets.remove(subWidget); - break; - } - } - } - this.navigationMenu = navigationMenu; - Menu tabMenu = null; - String tabMenuName = screenletElement.getAttribute("tab-menu-name"); - if (!tabMenuName.isEmpty()) { - for (ModelWidget subWidget : subWidgets) { - if (tabMenuName.equals(subWidget.getName()) && subWidget instanceof Menu) { - tabMenu = (Menu) subWidget; - subWidgets.remove(subWidget); - break; - } - } - } - this.tabMenu = tabMenu; - Form navigationForm = null; - String formName = screenletElement.getAttribute("navigation-form-name"); - if (!formName.isEmpty() && this.navigationMenu == null) { - for (ModelWidget subWidget : subWidgets) { - if (formName.equals(subWidget.getName()) && subWidget instanceof Form) { - navigationForm = (Form) subWidget; - padded = false; - break; - } - } - } - this.subWidgets = Collections.unmodifiableList(subWidgets); - this.navigationForm = navigationForm; - this.padded = padded; - } - - @Override - public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException, IOException { - boolean collapsed = getInitiallyCollapsed(context); - if (this.collapsible) { - String preferenceKey = getPreferenceKey(context) + "_collapsed"; - Map requestParameters = UtilGenerics.checkMap(context.get("requestParameters")); - if (requestParameters != null) { - String collapsedParam = (String) requestParameters.get(preferenceKey); - collapsed = "true".equals(collapsedParam); - } - } - try { - screenStringRenderer.renderScreenletBegin(writer, context, collapsed, this); - for (ModelScreenWidget subWidget : this.subWidgets) { - screenStringRenderer.renderScreenletSubWidget(writer, context, subWidget, this); - } - screenStringRenderer.renderScreenletEnd(writer, context, this); - } catch (IOException e) { - String errMsg = "Error rendering screenlet in screen named [" + getModelScreen().getName() + "]: "; - Debug.logError(e, errMsg, module); - throw new RuntimeException(errMsg + e); - } - } - - public boolean collapsible() { - return this.collapsible; - } - - //initially-collapsed status, which may be overriden by user preference - public boolean getInitiallyCollapsed(Map context) { - String screenletId = this.getId(context) + "_collapsed"; - Map userPreferences = UtilGenerics.checkMap(context.get("userPreferences")); - if (userPreferences != null && userPreferences.containsKey(screenletId)) { - return Boolean.valueOf((String)userPreferences.get(screenletId)).booleanValue() ; - } - - return "true".equals(this.initiallyCollapsed.expand(context)); - } - - public boolean saveCollapsed() { - return this.saveCollapsed; - } - public boolean padded() { - return this.padded; - } - - public String getPreferenceKey(Map context) { - String name = this.idExdr.expandString(context); - if (name.isEmpty()) { - name = "screenlet" + "_" + Integer.toHexString(hashCode()); - } - return name; - } - - public String getId(Map context) { - return this.idExdr.expandString(context); - } - - public List getSubWidgets() { - return subWidgets; - } - - public String getTitle(Map context) { - String title = this.titleExdr.expandString(context); - UtilCodec.SimpleEncoder simpleEncoder = (UtilCodec.SimpleEncoder) context.get("simpleEncoder"); - if (simpleEncoder != null) { - title = simpleEncoder.encode(title); - } - return title; - } - - public Menu getNavigationMenu() { - return this.navigationMenu; - } - - public Form getNavigationForm() { - return this.navigationForm; - } - - public Menu getTabMenu() { - return this.tabMenu; - } - - @Override - public void accept(ModelWidgetVisitor visitor) throws Exception { - visitor.visit(this); - } - - public FlexibleStringExpander getIdExdr() { - return idExdr; - } - - public FlexibleStringExpander getTitleExdr() { - return titleExdr; - } - - public boolean getCollapsible() { - return collapsible; - } - - public FlexibleStringExpander getInitiallyCollapsed() { - return initiallyCollapsed; - } - - public boolean getSaveCollapsed() { - return saveCollapsed; - } - - public boolean getPadded() { - return padded; - } - } - - public static final class HorizontalSeparator extends ModelScreenWidget { - public static final String TAG_NAME = "horizontal-separator"; - private final FlexibleStringExpander idExdr; - private final FlexibleStringExpander styleExdr; - - public HorizontalSeparator(ModelScreen modelScreen, Element separatorElement) { - super(modelScreen, separatorElement); - this.idExdr = FlexibleStringExpander.getInstance(separatorElement.getAttribute("id")); - this.styleExdr = FlexibleStringExpander.getInstance(separatorElement.getAttribute("style")); - } - - @Override - public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException, IOException { - screenStringRenderer.renderHorizontalSeparator(writer, context, this); - } - - public String getId(Map context) { - return this.idExdr.expandString(context); - } - - public String getStyle(Map context) { - return this.styleExdr.expandString(context); - } - - @Override - public void accept(ModelWidgetVisitor visitor) throws Exception { - visitor.visit(this); - } - - public FlexibleStringExpander getIdExdr() { - return idExdr; - } - - public FlexibleStringExpander getStyleExdr() { - return styleExdr; - } - } - - public static final class IncludeScreen extends ModelScreenWidget { - public static final String TAG_NAME = "include-screen"; - private final FlexibleStringExpander nameExdr; - private final FlexibleStringExpander locationExdr; - private final FlexibleStringExpander shareScopeExdr; - - public IncludeScreen(ModelScreen modelScreen, Element includeScreenElement) { - super(modelScreen, includeScreenElement); - this.nameExdr = FlexibleStringExpander.getInstance(includeScreenElement.getAttribute("name")); - this.locationExdr = FlexibleStringExpander.getInstance(includeScreenElement.getAttribute("location")); - this.shareScopeExdr = FlexibleStringExpander.getInstance(includeScreenElement.getAttribute("share-scope")); - } - - @Override - public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException, IOException { - // if we are not sharing the scope, protect it using the MapStack - boolean protectScope = !shareScope(context); - if (protectScope) { - if (!(context instanceof MapStack)) { - context = MapStack.create(context); - } - - UtilGenerics.>cast(context).push(); - - // build the widgetpath - List widgetTrail = UtilGenerics.toList(context.get("_WIDGETTRAIL_")); - if (widgetTrail == null) { - widgetTrail = new LinkedList(); - } - - String thisName = nameExdr.expandString(context); - widgetTrail.add(thisName); - context.put("_WIDGETTRAIL_", widgetTrail); - } - - // don't need the renderer here, will just pass this on down to another screen call; screenStringRenderer.renderContainerBegin(writer, context, this); - String name = this.getName(context); - String location = this.getLocation(context); - - if (name.isEmpty()) { - if (Debug.verboseOn()) Debug.logVerbose("In the include-screen tag the screen name was empty, ignoring include; in screen [" + getModelScreen().getName() + "]", module); - return; - } - - ScreenFactory.renderReferencedScreen(name, location, this, writer, context, screenStringRenderer); - - if (protectScope) { - UtilGenerics.>cast(context).pop(); - } - } - - public String getName(Map context) { - return this.nameExdr.expandString(context); - } - - public String getLocation(Map context) { - return this.locationExdr.expandString(context); - } - - public boolean shareScope(Map context) { - String shareScopeString = this.shareScopeExdr.expandString(context); - // defaults to false, so anything but true is false - return "true".equals(shareScopeString); - } - - @Override - public void accept(ModelWidgetVisitor visitor) throws Exception { - visitor.visit(this); - } - - public FlexibleStringExpander getNameExdr() { - return nameExdr; - } - - public FlexibleStringExpander getLocationExdr() { - return locationExdr; - } - - public FlexibleStringExpander getShareScopeExdr() { - return shareScopeExdr; - } - } - - public static final class DecoratorScreen extends ModelScreenWidget { - public static final String TAG_NAME = "decorator-screen"; - private final FlexibleStringExpander nameExdr; - private final FlexibleStringExpander locationExdr; - private final Map sectionMap; - - public DecoratorScreen(ModelScreen modelScreen, Element decoratorScreenElement) { - super(modelScreen, decoratorScreenElement); - this.nameExdr = FlexibleStringExpander.getInstance(decoratorScreenElement.getAttribute("name")); - this.locationExdr = FlexibleStringExpander.getInstance(decoratorScreenElement.getAttribute("location")); - Map sectionMap = new HashMap(); - List decoratorSectionElementList = UtilXml.childElementList(decoratorScreenElement, "decorator-section"); - for (Element decoratorSectionElement: decoratorSectionElementList) { - DecoratorSection decoratorSection = new DecoratorSection(modelScreen, decoratorSectionElement); - sectionMap.put(decoratorSection.getName(), decoratorSection); - } - this.sectionMap = Collections.unmodifiableMap(sectionMap); - } - - @Override - @SuppressWarnings("unchecked") - public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException, IOException { - // isolate the scope - if (!(context instanceof MapStack)) { - context = MapStack.create(context); - } - - MapStack contextMs = (MapStack) context; - - // create a standAloneStack, basically a "save point" for this SectionsRenderer, and make a new "screens" object just for it so it is isolated and doesn't follow the stack down - MapStack standAloneStack = contextMs.standAloneChildStack(); - standAloneStack.put("screens", new ScreenRenderer(writer, standAloneStack, screenStringRenderer)); - SectionsRenderer sections = new SectionsRenderer(this.sectionMap, standAloneStack, writer, screenStringRenderer); - - // put the sectionMap in the context, make sure it is in the sub-scope, ie after calling push on the MapStack - contextMs.push(); - context.put("sections", sections); - - String name = this.getName(context); - String location = this.getLocation(context); - - ScreenFactory.renderReferencedScreen(name, location, this, writer, context, screenStringRenderer); - - contextMs.pop(); - } - - public String getName(Map context) { - return this.nameExdr.expandString(context); - } - - public String getLocation(Map context) { - return this.locationExdr.expandString(context); - } - - public Map getSectionMap() { - return sectionMap; - } - - @Override - public void accept(ModelWidgetVisitor visitor) throws Exception { - visitor.visit(this); - } - - public FlexibleStringExpander getNameExdr() { - return nameExdr; - } - - public FlexibleStringExpander getLocationExdr() { - return locationExdr; - } - - } - - public static final class DecoratorSection extends ModelScreenWidget { - public static final String TAG_NAME = "decorator-section"; - private final List subWidgets; - - public DecoratorSection(ModelScreen modelScreen, Element decoratorSectionElement) { - super(modelScreen, decoratorSectionElement); - // read sub-widgets - List subElementList = UtilXml.childElementList(decoratorSectionElement); - this.subWidgets = ModelScreenWidget.readSubWidgets(getModelScreen(), subElementList); - } - - @Override - public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException, IOException { - // render sub-widgets - renderSubWidgetsString(this.subWidgets, writer, context, screenStringRenderer); - } - - public List getSubWidgets() { - return subWidgets; - } - - @Override - public void accept(ModelWidgetVisitor visitor) throws Exception { - visitor.visit(this); - } - } - - public static final class DecoratorSectionInclude extends ModelScreenWidget { - public static final String TAG_NAME = "decorator-section-include"; - - public DecoratorSectionInclude(ModelScreen modelScreen, Element decoratorSectionElement) { - super(modelScreen, decoratorSectionElement); - } - - @Override - public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException, IOException { - Map preRenderedContent = UtilGenerics.checkMap(context.get("preRenderedContent")); - if (preRenderedContent != null && preRenderedContent.containsKey(getName())) { - try { - writer.append((String) preRenderedContent.get(getName())); - } catch (IOException e) { - String errMsg = "Error rendering pre-rendered content in screen named [" + getModelScreen().getName() + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - throw new RuntimeException(errMsg); - } - } else { - SectionsRenderer sections = (SectionsRenderer) context.get("sections"); - // for now if sections is null, just log a warning; may be permissible to make the screen for flexible - if (sections == null) { - Debug.logWarning("In decorator-section-include could not find sections object in the context, not rendering section with name [" + getName() + "]", module); - } else { - sections.render(getName()); - } - } - } - - @Override - public void accept(ModelWidgetVisitor visitor) throws Exception { - visitor.visit(this); - } - } - - public static final class Label extends ModelScreenWidget { - public static final String TAG_NAME = "label"; - private final FlexibleStringExpander textExdr; - private final FlexibleStringExpander idExdr; - private final FlexibleStringExpander styleExdr; - - public Label(ModelScreen modelScreen, Element labelElement) { - super(modelScreen, labelElement); - - // put the text attribute first, then the pcdata under the element, if both are there of course - String textAttr = labelElement.getAttribute("text"); - String pcdata = UtilXml.elementValue(labelElement); - if (pcdata == null) { - pcdata = ""; - } - this.textExdr = FlexibleStringExpander.getInstance(textAttr + pcdata); - - this.idExdr = FlexibleStringExpander.getInstance(labelElement.getAttribute("id")); - this.styleExdr = FlexibleStringExpander.getInstance(labelElement.getAttribute("style")); - } - - @Override - public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) { - try { - screenStringRenderer.renderLabel(writer, context, this); - } catch (IOException e) { - String errMsg = "Error rendering label in screen named [" + getModelScreen().getName() + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - throw new RuntimeException(errMsg); - } - } - - public String getText(Map context) { - String text = this.textExdr.expandString(context); - // FIXME: Encoding should be done by the renderer, not by the model. - UtilCodec.SimpleEncoder simpleEncoder = (UtilCodec.SimpleEncoder) context.get("simpleEncoder"); - if (simpleEncoder != null) { - text = simpleEncoder.encode(text); - } - return text; - } - - public String getId(Map context) { - return this.idExdr.expandString(context); - } - - public String getStyle(Map context) { - return this.styleExdr.expandString(context); - } - - @Override - public void accept(ModelWidgetVisitor visitor) throws Exception { - visitor.visit(this); - } - - public FlexibleStringExpander getTextExdr() { - return textExdr; - } - - public FlexibleStringExpander getIdExdr() { - return idExdr; - } - - public FlexibleStringExpander getStyleExdr() { - return styleExdr; - } - } - - public static final class Form extends ModelScreenWidget { - public static final String TAG_NAME = "include-form"; - private final FlexibleStringExpander nameExdr; - private final FlexibleStringExpander locationExdr; - private final FlexibleStringExpander shareScopeExdr; - - public Form(ModelScreen modelScreen, Element formElement) { - super(modelScreen, formElement); - this.nameExdr = FlexibleStringExpander.getInstance(formElement.getAttribute("name")); - this.locationExdr = FlexibleStringExpander.getInstance(formElement.getAttribute("location")); - this.shareScopeExdr = FlexibleStringExpander.getInstance(formElement.getAttribute("share-scope")); - } - - @Override - public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) { - // Output format might not support forms, so make form rendering optional. - FormStringRenderer formStringRenderer = (FormStringRenderer) context.get("formStringRenderer"); - if (formStringRenderer == null) { - Debug.logVerbose("FormStringRenderer instance not found in rendering context, form not rendered.", module); - return; - } - boolean protectScope = !shareScope(context); - if (protectScope) { - if (!(context instanceof MapStack)) { - context = MapStack.create(context); - } - UtilGenerics.>cast(context).push(); - } - ModelForm modelForm = getModelForm(context); - FormRenderer renderer = new FormRenderer(modelForm, formStringRenderer); - try { - renderer.render(writer, context); - } catch (Exception e) { - String errMsg = "Error rendering included form named [" + getName() + "] at location [" + this.getLocation(context) + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - throw new RuntimeException(errMsg + e); - } - - if (protectScope) { - UtilGenerics.>cast(context).pop(); - } - } - - public ModelForm getModelForm(Map context) { - ModelForm modelForm = null; - String name = this.getName(context); - String location = this.getLocation(context); - try { - modelForm = FormFactory.getFormFromLocation(location, name, getModelScreen().getDelegator(context).getModelReader(), getModelScreen().getDispatcher(context).getDispatchContext()); - } catch (Exception e) { - String errMsg = "Error rendering included form named [" + name + "] at location [" + location + "]: "; - Debug.logError(e, errMsg, module); - throw new RuntimeException(errMsg + e); - } - return modelForm; - } - - public String getName(Map context) { - return this.nameExdr.expandString(context); - } - - public String getLocation() { - return locationExdr.getOriginal(); - } - - public String getLocation(Map context) { - return this.locationExdr.expandString(context); - } - - public boolean shareScope(Map context) { - String shareScopeString = this.shareScopeExdr.expandString(context); - // defaults to false, so anything but true is false - return "true".equals(shareScopeString); - } - - @Override - public void accept(ModelWidgetVisitor visitor) throws Exception { - visitor.visit(this); - } - - public FlexibleStringExpander getNameExdr() { - return nameExdr; - } - - public FlexibleStringExpander getLocationExdr() { - return locationExdr; - } - - public FlexibleStringExpander getShareScopeExdr() { - return shareScopeExdr; - } - - } - - public static final class Tree extends ModelScreenWidget { - public static final String TAG_NAME = "include-tree"; - private final FlexibleStringExpander nameExdr; - private final FlexibleStringExpander locationExdr; - private final FlexibleStringExpander shareScopeExdr; - - public Tree(ModelScreen modelScreen, Element treeElement) { - super(modelScreen, treeElement); - this.nameExdr = FlexibleStringExpander.getInstance(treeElement.getAttribute("name")); - this.locationExdr = FlexibleStringExpander.getInstance(treeElement.getAttribute("location")); - this.shareScopeExdr = FlexibleStringExpander.getInstance(treeElement.getAttribute("share-scope")); - } - - @Override - public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException, IOException { - // Output format might not support trees, so make tree rendering optional. - TreeStringRenderer treeStringRenderer = (TreeStringRenderer) context.get("treeStringRenderer"); - if (treeStringRenderer == null) { - Debug.logVerbose("TreeStringRenderer instance not found in rendering context, tree not rendered.", module); - return; - } - boolean protectScope = !shareScope(context); - if (protectScope) { - if (!(context instanceof MapStack)) { - context = MapStack.create(context); - } - UtilGenerics.>cast(context).push(); - } - - String name = this.getName(context); - String location = this.getLocation(context); - ModelTree modelTree = null; - try { - modelTree = TreeFactory.getTreeFromLocation(this.getLocation(context), this.getName(context), getModelScreen().getDelegator(context), getModelScreen().getDispatcher(context)); - } catch (IOException e) { - String errMsg = "Error rendering included tree named [" + name + "] at location [" + location + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - throw new RuntimeException(errMsg); - } catch (SAXException e) { - String errMsg = "Error rendering included tree named [" + name + "] at location [" + location + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - throw new RuntimeException(errMsg); - } catch (ParserConfigurationException e) { - String errMsg = "Error rendering included tree named [" + name + "] at location [" + location + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - throw new RuntimeException(errMsg); - } - modelTree.renderTreeString(writer, context, treeStringRenderer); - if (protectScope) { - UtilGenerics.>cast(context).pop(); - } - } - - public String getName(Map context) { - return this.nameExdr.expandString(context); - } - - public String getLocation(Map context) { - return this.locationExdr.expandString(context); - } - - public boolean shareScope(Map context) { - String shareScopeString = this.shareScopeExdr.expandString(context); - // defaults to false, so anything but true is false - return "true".equals(shareScopeString); - } - - @Override - public void accept(ModelWidgetVisitor visitor) throws Exception { - visitor.visit(this); - } - - public FlexibleStringExpander getLocationExdr() { - return locationExdr; - } - - public FlexibleStringExpander getShareScopeExdr() { - return shareScopeExdr; - } - } - - public static final class PlatformSpecific extends ModelScreenWidget { - public static final String TAG_NAME = "platform-specific"; - private final Map subWidgets; - - public PlatformSpecific(ModelScreen modelScreen, Element platformSpecificElement) { - super(modelScreen, platformSpecificElement); - Map subWidgets = new HashMap(); - List childElements = UtilXml.childElementList(platformSpecificElement); - if (childElements != null) { - for (Element childElement: childElements) { - if ("html".equals(childElement.getNodeName())) { - subWidgets.put("html", new HtmlWidget(modelScreen, childElement)); - } else if ("xsl-fo".equals(childElement.getNodeName())) { - subWidgets.put("xsl-fo", new HtmlWidget(modelScreen, childElement)); - } else if ("xml".equals(childElement.getNodeName())) { - subWidgets.put("xml", new HtmlWidget(modelScreen, childElement)); - } else { - throw new IllegalArgumentException("Tag not supported under the platform-specific tag with name: " + childElement.getNodeName()); - } - } - } - this.subWidgets = Collections.unmodifiableMap(subWidgets); - } - - @Override - public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException, IOException { - ModelScreenWidget subWidget = null; - subWidget = subWidgets.get(screenStringRenderer.getRendererName()); - if (subWidget == null) { - // This is here for backward compatibility - Debug.logWarning("In platform-dependent could not find template for " + screenStringRenderer.getRendererName() + ", using the one for html.", module); - subWidget = subWidgets.get("html"); - } - if (subWidget != null) { - subWidget.renderWidgetString(writer, context, screenStringRenderer); - } - } - - @Override - public void accept(ModelWidgetVisitor visitor) throws Exception { - visitor.visit(this); - } - - public Map getSubWidgets() { - return subWidgets; - } - } - - public static final class Content extends ModelScreenWidget { - public static final String TAG_NAME = "content"; - - private final FlexibleStringExpander contentId; - private final FlexibleStringExpander editRequest; - private final FlexibleStringExpander editContainerStyle; - private final FlexibleStringExpander enableEditName; - private final boolean xmlEscape; - private final FlexibleStringExpander dataResourceId; - private final String width; - private final String height; - private final String border; - - public Content(ModelScreen modelScreen, Element subContentElement) { - super(modelScreen, subContentElement); - this.contentId = FlexibleStringExpander.getInstance(subContentElement.getAttribute("content-id")); - this.dataResourceId = FlexibleStringExpander.getInstance(subContentElement.getAttribute("dataresource-id")); - this.editRequest = FlexibleStringExpander.getInstance(subContentElement.getAttribute("edit-request")); - this.editContainerStyle = FlexibleStringExpander.getInstance(subContentElement.getAttribute("edit-container-style")); - this.enableEditName = FlexibleStringExpander.getInstance(subContentElement.getAttribute("enable-edit-name")); - this.xmlEscape = "true".equals(subContentElement.getAttribute("xml-escape")); - String width = subContentElement.getAttribute("width"); - if (width.isEmpty()) - width = "60%"; - this.height = subContentElement.getAttribute("height"); - if (this.height.isEmpty()) - width = "400px"; - this.width = width; - this.border = subContentElement.getAttribute("border"); - } - - @Override - public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) { - try { - // pushing the contentId on the context as "contentId" is done - // because many times there will be embedded "subcontent" elements - // that use the syntax: )) { - context = MapStack.create(context); - } - - // This is an important step to make sure that the current contentId is in the context - // as templates that contain "subcontent" elements will expect to find the master - // contentId in the context as "contentId". - UtilGenerics.>cast(context).push(); - context.put("contentId", expandedContentId); - - if (expandedDataResourceId.isEmpty()) { - if (!expandedContentId.isEmpty()) { - content = EntityQuery.use(delegator).from("Content").where("contentId", expandedContentId).cache().queryOne(); - } else { - String errMsg = "contentId is empty."; - Debug.logError(errMsg, module); - return; - } - if (content != null) { - expandedDataResourceId = content.getString("dataResourceId"); - } else { - String errMsg = "Could not find content with contentId [" + expandedContentId + "] "; - Debug.logError(errMsg, module); - throw new RuntimeException(errMsg); - } - } - - GenericValue dataResource = null; - if (!expandedDataResourceId.isEmpty()) { - dataResource = EntityQuery.use(delegator).from("DataResource").where("dataResourceId", expandedDataResourceId).cache().queryOne(); - } - - String mimeTypeId = null; - if (dataResource != null) { - mimeTypeId = dataResource.getString("mimeTypeId"); - } - if (content != null) { - mimeTypeId = content.getString("mimeTypeId"); - } - - if (!(mimeTypeId != null - && ((mimeTypeId.indexOf("application") >= 0) || (mimeTypeId.indexOf("image")) >= 0))) { - screenStringRenderer.renderContentBegin(writer, context, this); - screenStringRenderer.renderContentBody(writer, context, this); - screenStringRenderer.renderContentEnd(writer, context, this); - } - UtilGenerics.>cast(context).pop(); - } catch (IOException e) { - String errMsg = "Error rendering content with contentId [" + getContentId(context) + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - throw new RuntimeException(errMsg); - } catch (GenericEntityException e) { - String errMsg = "Error obtaining content with contentId [" + getContentId(context) + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - throw new RuntimeException(errMsg); - } - - } - - public String getContentId(Map context) { - return this.contentId.expandString(context); - } - - public String getDataResourceId() { - return this.dataResourceId.getOriginal(); - } - - public String getDataResourceId(Map context) { - return this.dataResourceId.expandString(context); - } - - public String getEditRequest(Map context) { - return this.editRequest.expandString(context); - } - - public String getEditContainerStyle(Map context) { - return this.editContainerStyle.expandString(context); - } - - public String getEnableEditName(Map context) { - return this.enableEditName.expandString(context); - } - - public boolean xmlEscape() { - return this.xmlEscape; - } - - public String getWidth() { - return this.width; - } - - public String getHeight() { - return this.height; - } - - public String getBorder() { - return this.border; - } - - @Override - public void accept(ModelWidgetVisitor visitor) throws Exception { - visitor.visit(this); - } - - public FlexibleStringExpander getContentId() { - return contentId; - } - - public FlexibleStringExpander getEditRequest() { - return editRequest; - } - - public FlexibleStringExpander getEditContainerStyle() { - return editContainerStyle; - } - - public FlexibleStringExpander getEnableEditName() { - return enableEditName; - } - } - - public static final class SubContent extends ModelScreenWidget { - public static final String TAG_NAME = "sub-content"; - private final FlexibleStringExpander contentId; - private final FlexibleStringExpander mapKey; - private final FlexibleStringExpander editRequest; - private final FlexibleStringExpander editContainerStyle; - private final FlexibleStringExpander enableEditName; - private final boolean xmlEscape; - - public SubContent(ModelScreen modelScreen, Element subContentElement) { - super(modelScreen, subContentElement); - this.contentId = FlexibleStringExpander.getInstance(subContentElement.getAttribute("content-id")); - String mapKey = subContentElement.getAttribute("map-key"); - if (mapKey.isEmpty()) { - mapKey = subContentElement.getAttribute("assoc-name"); - } - this.mapKey = FlexibleStringExpander.getInstance(mapKey); - this.editRequest = FlexibleStringExpander.getInstance(subContentElement.getAttribute("edit-request")); - this.editContainerStyle = FlexibleStringExpander.getInstance(subContentElement.getAttribute("edit-container-style")); - this.enableEditName = FlexibleStringExpander.getInstance(subContentElement.getAttribute("enable-edit-name")); - this.xmlEscape = "true".equals(subContentElement.getAttribute("xml-escape")); - } - - @Override - public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) { - try { - screenStringRenderer.renderSubContentBegin(writer, context, this); - screenStringRenderer.renderSubContentBody(writer, context, this); - screenStringRenderer.renderSubContentEnd(writer, context, this); - } catch (IOException e) { - String errMsg = "Error rendering subContent with contentId [" + getContentId(context) + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - throw new RuntimeException(errMsg); - } - } - - public String getContentId(Map context) { - return this.contentId.expandString(context); - } - - public String getMapKey(Map context) { - return this.mapKey.expandString(context); - } - - public String getEditRequest(Map context) { - return this.editRequest.expandString(context); - } - - public String getEditContainerStyle(Map context) { - return this.editContainerStyle.expandString(context); - } - - public String getEnableEditName(Map context) { - return this.enableEditName.expandString(context); - } - - public boolean xmlEscape() { - return this.xmlEscape; - } - - @Override - public void accept(ModelWidgetVisitor visitor) throws Exception { - // TODO Auto-generated method stub - - } - } - - public static final class Menu extends ModelScreenWidget { - public static final String TAG_NAME = "include-menu"; - private final FlexibleStringExpander nameExdr; - private final FlexibleStringExpander locationExdr; - - public Menu(ModelScreen modelScreen, Element menuElement) { - super(modelScreen, menuElement); - this.nameExdr = FlexibleStringExpander.getInstance(menuElement.getAttribute("name")); - this.locationExdr = FlexibleStringExpander.getInstance(menuElement.getAttribute("location")); - } - - @Override - public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) throws IOException { - // Output format might not support menus, so make menu rendering optional. - MenuStringRenderer menuStringRenderer = (MenuStringRenderer) context.get("menuStringRenderer"); - if (menuStringRenderer == null) { - Debug.logVerbose("MenuStringRenderer instance not found in rendering context, menu not rendered.", module); - return; - } - ModelMenu modelMenu = getModelMenu(context); - modelMenu.renderMenuString(writer, context, menuStringRenderer); - } - - public ModelMenu getModelMenu(Map context) { - String name = this.getName(context); - String location = this.getLocation(context); - ModelMenu modelMenu = null; - try { - modelMenu = MenuFactory.getMenuFromLocation(location, name); - } catch (Exception e) { - String errMsg = "Error rendering included menu named [" + name + "] at location [" + location + "]: "; - Debug.logError(e, errMsg, module); - throw new RuntimeException(errMsg + e); - } - return modelMenu; - } - - public String getName(Map context) { - return this.nameExdr.expandString(context); - } - - public String getLocation(Map context) { - return this.locationExdr.expandString(context); - } - - @Override - public void accept(ModelWidgetVisitor visitor) throws Exception { - visitor.visit(this); - } - - public FlexibleStringExpander getLocationExdr() { - return locationExdr; - } - } - - public static final class ScreenLink extends ModelScreenWidget { - public static final String TAG_NAME = "link"; - private final Link link; - private final ScreenImage image; - - public ScreenLink(ModelScreen modelScreen, Element linkElement) { - super(modelScreen, linkElement); - this.link = new Link(linkElement); - Element imageElement = UtilXml.firstChildElement(linkElement, "image"); - if (imageElement != null) { - this.image = new ScreenImage(modelScreen, imageElement); - } else { - this.image = null; - } - } - - public String getName() { - return link.getName(); - } - - public String getText(Map context) { - return link.getText(context); - } - - public String getId(Map context) { - return link.getId(context); - } - - public String getStyle(Map context) { - return link.getStyle(context); - } - - public String getTarget(Map context) { - return link.getTarget(context); - } - - public String getName(Map context) { - return link.getName(context); - } - - public String getTargetWindow(Map context) { - return link.getTargetWindow(context); - } - - public String getUrlMode() { - return link.getUrlMode(); - } - - public String getPrefix(Map context) { - return link.getPrefix(context); - } - - public boolean getFullPath() { - return link.getFullPath(); - } - - public boolean getSecure() { - return link.getSecure(); - } - - public boolean getEncode() { - return link.getEncode(); - } - - public ScreenImage getImage() { - return image; - } - - public String getLinkType() { - return link.getLinkType(); - } - - public String getWidth() { - return link.getWidth(); - } - - public String getHeight() { - return link.getHeight(); - } - - public Map getParameterMap(Map context) { - return link.getParameterMap(context); - } - - public FlexibleStringExpander getTextExdr() { - return link.getTextExdr(); - } - - public FlexibleStringExpander getIdExdr() { - return link.getIdExdr(); - } - - public FlexibleStringExpander getStyleExdr() { - return link.getStyleExdr(); - } - - public FlexibleStringExpander getTargetExdr() { - return link.getTargetExdr(); - } - - public FlexibleStringExpander getTargetWindowExdr() { - return link.getTargetWindowExdr(); - } - - public FlexibleStringExpander getPrefixExdr() { - return link.getPrefixExdr(); - } - - public FlexibleStringExpander getNameExdr() { - return link.getNameExdr(); - } - - public List getParameterList() { - return link.getParameterList(); - } - - public AutoServiceParameters getAutoServiceParameters() { - return link.getAutoServiceParameters(); - } - - public AutoEntityParameters getAutoEntityParameters() { - return link.getAutoEntityParameters(); - } - - @Override - public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) { - try { - screenStringRenderer.renderLink(writer, context, this); - } catch (IOException e) { - String errMsg = "Error rendering link with id [" + link.getId(context) + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - throw new RuntimeException(errMsg); - } - } - - @Override - public void accept(ModelWidgetVisitor visitor) throws Exception { - visitor.visit(this); - } - - public Link getLink() { - return link; - } - } - - public static final class ScreenImage extends ModelScreenWidget { - public static final String TAG_NAME = "image"; - private final Image image; - - public String getName() { - return image.getName(); - } - - public String getSrc(Map context) { - return image.getSrc(context); - } - - public String getId(Map context) { - return image.getId(context); - } - - public String getStyle(Map context) { - return image.getStyle(context); - } - - public String getWidth(Map context) { - return image.getWidth(context); - } - - public String getHeight(Map context) { - return image.getHeight(context); - } - - public String getBorder(Map context) { - return image.getBorder(context); - } - - public String getAlt(Map context) { - return image.getAlt(context); - } - - public String getUrlMode() { - return image.getUrlMode(); - } - - public FlexibleStringExpander getSrcExdr() { - return image.getSrcExdr(); - } - - public FlexibleStringExpander getIdExdr() { - return image.getIdExdr(); - } - - public FlexibleStringExpander getStyleExdr() { - return image.getStyleExdr(); - } - - public FlexibleStringExpander getWidthExdr() { - return image.getWidthExdr(); - } - - public FlexibleStringExpander getHeightExdr() { - return image.getHeightExdr(); - } - - public FlexibleStringExpander getBorderExdr() { - return image.getBorderExdr(); - } - - public FlexibleStringExpander getAlt() { - return image.getAlt(); - } - - public ScreenImage(ModelScreen modelScreen, Element imageElement) { - super(modelScreen, imageElement); - this.image = new Image(imageElement); - } - - @Override - public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) { - try { - screenStringRenderer.renderImage(writer, context, this); - } catch (IOException e) { - String errMsg = "Error rendering image with id [" + image.getId(context) + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - throw new RuntimeException(errMsg); - } - } - - @Override - public void accept(ModelWidgetVisitor visitor) throws Exception { - visitor.visit(this); - } - - public Image getImage() { - return image; - } - } - - public static final class PortalPage extends ModelScreenWidget { - public static final String TAG_NAME = "include-portal-page"; - private final FlexibleStringExpander idExdr; - private final FlexibleStringExpander confModeExdr; - private final Boolean usePrivate; - - public PortalPage(ModelScreen modelScreen, Element portalPageElement) { - super(modelScreen, portalPageElement); - this.idExdr = FlexibleStringExpander.getInstance(portalPageElement.getAttribute("id")); - this.confModeExdr = FlexibleStringExpander.getInstance(portalPageElement.getAttribute("conf-mode")); - this.usePrivate = !("false".equals(portalPageElement.getAttribute("use-private"))); - } - - private GenericValue getPortalPageValue(Map context) { - Delegator delegator = (Delegator) context.get("delegator"); - String expandedPortalPageId = getId(context); - GenericValue portalPage = null; - if (!expandedPortalPageId.isEmpty()) { - if (usePrivate) { - portalPage = PortalPageWorker.getPortalPage(expandedPortalPageId, context); - } else { - try { - portalPage = EntityQuery.use(delegator) - .from("PortalPage") - .where("portalPageId", expandedPortalPageId) - .cache().queryOne(); - } catch (GenericEntityException e) { - throw new RuntimeException(e); - } - } - } - if (portalPage == null) { - String errMsg = "Could not find PortalPage with portalPageId [" + expandedPortalPageId + "] "; - Debug.logError(errMsg, module); - throw new RuntimeException(errMsg); - } - return portalPage; - } - - @Override - public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException, IOException { - try { - Delegator delegator = (Delegator) context.get("delegator"); - List portalPageColumns = null; - List portalPagePortlets = null; - List portletAttributes = null; - GenericValue portalPage = getPortalPageValue(context); - String actualPortalPageId = portalPage.getString("portalPageId"); - portalPageColumns = EntityQuery.use(delegator) - .from("PortalPageColumn") - .where("portalPageId", actualPortalPageId) - .orderBy("columnSeqId") - .cache(true) - .queryList(); - - // Renders the portalPage header - screenStringRenderer.renderPortalPageBegin(writer, context, this); - - // First column has no previous column - String prevColumnSeqId = ""; - - // Iterates through the PortalPage columns - ListIterator columnsIterator = portalPageColumns.listIterator(); - while(columnsIterator.hasNext()) { - GenericValue columnValue = columnsIterator.next(); - String columnSeqId = columnValue.getString("columnSeqId"); - - // Renders the portalPageColumn header - screenStringRenderer.renderPortalPageColumnBegin(writer, context, this, columnValue); - - // Get the Portlets located in the current column - portalPagePortlets = EntityQuery.use(delegator) - .from("PortalPagePortletView") - .where("portalPageId", portalPage.getString("portalPageId"), "columnSeqId", columnSeqId) - .orderBy("sequenceNum") - .queryList(); - // First Portlet in a Column has no previous Portlet - String prevPortletId = ""; - String prevPortletSeqId = ""; - - // If this is not the last column, get the next columnSeqId - String nextColumnSeqId = ""; - if (columnsIterator.hasNext()) { - nextColumnSeqId = portalPageColumns.get(columnsIterator.nextIndex()).getString("columnSeqId"); - } - - // Iterates through the Portlets in the Column - ListIterator portletsIterator = portalPagePortlets.listIterator(); - while(portletsIterator.hasNext()) { - GenericValue portletValue = portletsIterator.next(); - - // If not the last portlet in the column, get the next nextPortletId and nextPortletSeqId - String nextPortletId = ""; - String nextPortletSeqId = ""; - if (portletsIterator.hasNext()) { - nextPortletId = portalPagePortlets.get(portletsIterator.nextIndex()).getString("portalPortletId"); - nextPortletSeqId = portalPagePortlets.get(portletsIterator.nextIndex()).getString("portletSeqId"); - } - - // Set info to allow portlet movement in the page - context.put("prevPortletId", prevPortletId); - context.put("prevPortletSeqId", prevPortletSeqId); - context.put("nextPortletId", nextPortletId); - context.put("nextPortletSeqId", nextPortletSeqId); - context.put("prevColumnSeqId", prevColumnSeqId); - context.put("nextColumnSeqId", nextColumnSeqId); - - // Get portlet's attributes - portletAttributes = EntityQuery.use(delegator) - .from("PortletAttribute") - .where("portalPageId", portletValue.get("portalPageId"), "portalPortletId", portletValue.get("portalPortletId"), "portletSeqId", portletValue.get("portletSeqId")) - .queryList(); - - ListIterator attributesIterator = portletAttributes.listIterator(); - while (attributesIterator.hasNext()) { - GenericValue attribute = attributesIterator.next(); - context.put(attribute.getString("attrName"), attribute.getString("attrValue")); - } - - // Renders the portalPagePortlet - screenStringRenderer.renderPortalPagePortletBegin(writer, context, this, portletValue); - screenStringRenderer.renderPortalPagePortletBody(writer, context, this, portletValue); - screenStringRenderer.renderPortalPagePortletEnd(writer, context, this, portletValue); - - // Remove the portlet's attributes so that these are not available for other portlets - while (attributesIterator.hasPrevious()) { - GenericValue attribute = attributesIterator.previous(); - context.remove(attribute.getString("attrName")); - } - - // Uses the actual portlet as prevPortlet for next iteration - prevPortletId = (String) portletValue.get("portalPortletId"); - prevPortletSeqId = (String) portletValue.get("portletSeqId"); - } - // Renders the portalPageColumn footer - screenStringRenderer.renderPortalPageColumnEnd(writer, context, this, columnValue); - - // Uses the actual columnSeqId as prevColumnSeqId for next iteration - prevColumnSeqId = columnSeqId; - } - // Renders the portalPage footer - screenStringRenderer.renderPortalPageEnd(writer, context, this); - } catch (IOException e) { - String errMsg = "Error rendering PortalPage with portalPageId [" + getId(context) + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - throw new RuntimeException(errMsg); - } catch (GenericEntityException e) { - String errMsg = "Error obtaining PortalPage with portalPageId [" + getId(context) + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - throw new RuntimeException(errMsg); - } - } - - public String getId(Map context) { - return this.idExdr.expandString(context); - } - - public String getOriginalPortalPageId(Map context) { - GenericValue portalPage = getPortalPageValue(context); - return portalPage.getString("originalPortalPageId"); - } - - public String getActualPortalPageId(Map context) { - GenericValue portalPage = getPortalPageValue(context); - return portalPage.getString("portalPageId"); - } - - public String getConfMode(Map context) { - return this.confModeExdr.expandString(context); - } - - public String getUsePrivate() { - return Boolean.toString(this.usePrivate); - } - - @Override - public void accept(ModelWidgetVisitor visitor) throws Exception { - visitor.visit(this); - } - - public FlexibleStringExpander getIdExdr() { - return idExdr; - } - - public FlexibleStringExpander getConfModeExdr() { - return confModeExdr; - } - } - -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.model; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.ListIterator; +import java.util.Map; +import java.util.Set; + +import javax.xml.parsers.ParserConfigurationException; + +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.GeneralException; +import org.ofbiz.base.util.UtilCodec; +import org.ofbiz.base.util.UtilGenerics; +import org.ofbiz.base.util.UtilXml; +import org.ofbiz.base.util.collections.MapStack; +import org.ofbiz.base.util.string.FlexibleStringExpander; +import org.ofbiz.entity.Delegator; +import org.ofbiz.entity.GenericEntityException; +import org.ofbiz.entity.GenericValue; +import org.ofbiz.entity.util.EntityQuery; +import org.ofbiz.widget.WidgetFactory; +import org.ofbiz.widget.model.CommonWidgetModels.AutoEntityParameters; +import org.ofbiz.widget.model.CommonWidgetModels.AutoServiceParameters; +import org.ofbiz.widget.model.CommonWidgetModels.Image; +import org.ofbiz.widget.model.CommonWidgetModels.Link; +import org.ofbiz.widget.model.CommonWidgetModels.Parameter; +import org.ofbiz.widget.portal.PortalPageWorker; +import org.ofbiz.widget.renderer.FormRenderer; +import org.ofbiz.widget.renderer.FormStringRenderer; +import org.ofbiz.widget.renderer.MenuStringRenderer; +import org.ofbiz.widget.renderer.ScreenRenderer; +import org.ofbiz.widget.renderer.ScreenStringRenderer; +import org.ofbiz.widget.renderer.TreeStringRenderer; +import org.w3c.dom.Element; +import org.xml.sax.SAXException; + + +/** + * Widget Library - Screen model class + */ +@SuppressWarnings("serial") +public abstract class ModelScreenWidget extends ModelWidget { + public static final String module = ModelScreenWidget.class.getName(); + + private final ModelScreen modelScreen; + + public ModelScreenWidget(ModelScreen modelScreen, Element widgetElement) { + super(widgetElement); + this.modelScreen = modelScreen; + if (Debug.verboseOn()) Debug.logVerbose("Reading Screen sub-widget with name: " + widgetElement.getNodeName(), module); + } + + public abstract void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException, IOException; + + protected static List readSubWidgets(ModelScreen modelScreen, List subElementList) { + if (subElementList.isEmpty()) { + return Collections.emptyList(); + } + List subWidgets = new ArrayList(subElementList.size()); + for (Element subElement: subElementList) { + subWidgets.add(WidgetFactory.getModelScreenWidget(modelScreen, subElement)); + } + return Collections.unmodifiableList(subWidgets); + } + + protected static void renderSubWidgetsString(List subWidgets, Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException, IOException { + if (subWidgets == null) { + return; + } + for (ModelScreenWidget subWidget: subWidgets) { + if (Debug.verboseOn()) Debug.logVerbose("Rendering screen " + subWidget.getModelScreen().getName() + "; widget class is " + subWidget.getClass().getName(), module); + + // render the sub-widget itself + subWidget.renderWidgetString(writer, context, screenStringRenderer); + } + } + + public ModelScreen getModelScreen() { + return this.modelScreen; + } + + public static final class SectionsRenderer implements Map { + private final Map sectionMap; + private final ScreenStringRenderer screenStringRenderer; + private final Map context; + private final Appendable writer; + + public SectionsRenderer(Map sectionMap, Map context, Appendable writer, + ScreenStringRenderer screenStringRenderer) { + Map localMap = new HashMap(); + localMap.putAll(sectionMap); + this.sectionMap = Collections.unmodifiableMap(localMap); + this.context = context; + this.writer = writer; + this.screenStringRenderer = screenStringRenderer; + } + + /** This is a lot like the ScreenRenderer class and returns an empty String so it can be used more easily with FreeMarker */ + public String render(String sectionName) throws GeneralException, IOException { + ModelScreenWidget section = sectionMap.get(sectionName); + // if no section by that name, write nothing + if (section != null) { + section.renderWidgetString(this.writer, this.context, this.screenStringRenderer); + } + return ""; + } + + @Override + public int size() { + return sectionMap.size(); + } + + @Override + public boolean isEmpty() { + return sectionMap.isEmpty(); + } + + @Override + public boolean containsKey(Object key) { + return sectionMap.containsKey(key); + } + + @Override + public boolean containsValue(Object value) { + return sectionMap.containsValue(value); + } + + @Override + public ModelScreenWidget get(Object key) { + return sectionMap.get(key); + } + + @Override + public ModelScreenWidget put(String key, ModelScreenWidget value) { + return sectionMap.put(key, value); + } + + @Override + public ModelScreenWidget remove(Object key) { + return sectionMap.remove(key); + } + + @Override + public void clear() { + sectionMap.clear(); + } + + @Override + public Set keySet() { + return sectionMap.keySet(); + } + + @Override + public Collection values() { + return sectionMap.values(); + } + + @Override + public Set> entrySet() { + return sectionMap.entrySet(); + } + + @Override + public boolean equals(Object o) { + return sectionMap.equals(o); + } + + @Override + public int hashCode() { + return sectionMap.hashCode(); + } + + @Override + public void putAll(Map m) { + sectionMap.putAll(m); + } + } + + public static final class Section extends ModelScreenWidget { + public static final String TAG_NAME = "section"; + private final ModelCondition condition; + private final List actions; + private final List subWidgets; + private final List failWidgets; + private final boolean isMainSection; + + public Section(ModelScreen modelScreen, Element sectionElement) { + this(modelScreen, sectionElement, false); + } + + public Section(ModelScreen modelScreen, Element sectionElement, boolean isMainSection) { + super(modelScreen, sectionElement); + + // read condition under the "condition" element + Element conditionElement = UtilXml.firstChildElement(sectionElement, "condition"); + if (conditionElement != null) { + conditionElement = UtilXml.firstChildElement(conditionElement); + this.condition = ModelScreenCondition.SCREEN_CONDITION_FACTORY.newInstance(modelScreen, conditionElement); + } else { + this.condition = null; + } + + // read all actions under the "actions" element + Element actionsElement = UtilXml.firstChildElement(sectionElement, "actions"); + if (actionsElement != null) { + this.actions = AbstractModelAction.readSubActions(modelScreen, actionsElement); + } else { + this.actions = Collections.emptyList(); + } + + // read sub-widgets + Element widgetsElement = UtilXml.firstChildElement(sectionElement, "widgets"); + if (widgetsElement != null) { + List subElementList = UtilXml.childElementList(widgetsElement); + this.subWidgets = ModelScreenWidget.readSubWidgets(getModelScreen(), subElementList); + } else { + this.subWidgets = Collections.emptyList(); + } + + // read fail-widgets + Element failWidgetsElement = UtilXml.firstChildElement(sectionElement, "fail-widgets"); + if (failWidgetsElement != null) { + List failElementList = UtilXml.childElementList(failWidgetsElement); + this.failWidgets = ModelScreenWidget.readSubWidgets(getModelScreen(), failElementList); + } else { + this.failWidgets = Collections.emptyList(); + } + this.isMainSection = isMainSection; + } + + @Override + public void accept(ModelWidgetVisitor visitor) throws Exception { + visitor.visit(this); + } + + @Override + public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException, IOException { + // check the condition, if there is one + boolean condTrue = true; + if (this.condition != null) { + if (!this.condition.eval(context)) { + condTrue = false; + } + } + + // if condition does not exist or evals to true run actions and render widgets, otherwise render fail-widgets + if (condTrue) { + // run the actions only if true + AbstractModelAction.runSubActions(this.actions, context); + + try { + // section by definition do not themselves do anything, so this method will generally do nothing, but we'll call it anyway + screenStringRenderer.renderSectionBegin(writer, context, this); + + // render sub-widgets + renderSubWidgetsString(this.subWidgets, writer, context, screenStringRenderer); + + screenStringRenderer.renderSectionEnd(writer, context, this); + } catch (IOException e) { + String errMsg = "Error rendering widgets section [" + getName() + "] in screen named [" + getModelScreen().getName() + "]: " + e.toString(); + Debug.logError(e, errMsg, module); + throw new RuntimeException(errMsg); + } + } else { + try { + // section by definition do not themselves do anything, so this method will generally do nothing, but we'll call it anyway + screenStringRenderer.renderSectionBegin(writer, context, this); + + // render sub-widgets + renderSubWidgetsString(this.failWidgets, writer, context, screenStringRenderer); + + screenStringRenderer.renderSectionEnd(writer, context, this); + } catch (IOException e) { + String errMsg = "Error rendering fail-widgets section [" + this.getName() + "] in screen named [" + getModelScreen().getName() + "]: " + e.toString(); + Debug.logError(e, errMsg, module); + throw new RuntimeException(errMsg); + } + } + + } + + @Override + public String getBoundaryCommentName() { + if (isMainSection) { + return getModelScreen().getSourceLocation() + "#" + getModelScreen().getName(); + } else { + return getName(); + } + } + + public List getActions() { + return actions; + } + + public List getSubWidgets() { + return subWidgets; + } + + public List getFailWidgets() { + return failWidgets; + } + + public boolean isMainSection() { + return isMainSection; + } + + public ModelCondition getCondition() { + return condition; + } + } + + public static final class ColumnContainer extends ModelScreenWidget { + public static final String TAG_NAME = "column-container"; + private final FlexibleStringExpander idExdr; + private final FlexibleStringExpander styleExdr; + private final List columns; + + public ColumnContainer(ModelScreen modelScreen, Element containerElement) { + super(modelScreen, containerElement); + this.idExdr = FlexibleStringExpander.getInstance(containerElement.getAttribute("id")); + this.styleExdr = FlexibleStringExpander.getInstance(containerElement.getAttribute("style")); + List subElementList = UtilXml.childElementList(containerElement, "column"); + List columns = new ArrayList(subElementList.size()); + for (Element element : subElementList) { + columns.add(new Column(modelScreen, element)); + } + this.columns = Collections.unmodifiableList(columns); + } + + @Override + public void accept(ModelWidgetVisitor visitor) throws Exception { + visitor.visit(this); + } + + @Override + public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException, IOException { + try { + screenStringRenderer.renderColumnContainer(writer, context, this); + } catch (IOException e) { + String errMsg = "Error rendering container in screen named [" + getModelScreen().getName() + "]: " + e.toString(); + Debug.logError(e, errMsg, module); + throw new RuntimeException(errMsg); + } + } + + public List getColumns() { + return this.columns; + } + + public String getId(Map context) { + return this.idExdr.expandString(context); + } + + public String getStyle(Map context) { + return this.styleExdr.expandString(context); + } + + public FlexibleStringExpander getIdExdr() { + return idExdr; + } + + public FlexibleStringExpander getStyleExdr() { + return styleExdr; + } + } + + public static final class Column extends ModelWidget { + private final FlexibleStringExpander idExdr; + private final FlexibleStringExpander styleExdr; + private final List subWidgets; + + public Column(ModelScreen modelScreen, Element columnElement) { + super(columnElement); + this.idExdr = FlexibleStringExpander.getInstance(columnElement.getAttribute("id")); + this.styleExdr = FlexibleStringExpander.getInstance(columnElement.getAttribute("style")); + List subElementList = UtilXml.childElementList(columnElement); + this.subWidgets = Collections.unmodifiableList(readSubWidgets(modelScreen, subElementList)); + } + + public List getSubWidgets() { + return this.subWidgets; + } + + public String getId(Map context) { + return this.idExdr.expandString(context); + } + + public String getStyle(Map context) { + return this.styleExdr.expandString(context); + } + + @Override + public void accept(ModelWidgetVisitor visitor) throws Exception { + visitor.visit(this); + } + + public FlexibleStringExpander getIdExdr() { + return idExdr; + } + + public FlexibleStringExpander getStyleExdr() { + return styleExdr; + } + } + + public static final class Container extends ModelScreenWidget { + public static final String TAG_NAME = "container"; + private final FlexibleStringExpander idExdr; + private final FlexibleStringExpander styleExdr; + private final FlexibleStringExpander autoUpdateTargetExdr; + private final FlexibleStringExpander autoUpdateInterval; + private final List subWidgets; + + public Container(ModelScreen modelScreen, Element containerElement) { + super(modelScreen, containerElement); + this.idExdr = FlexibleStringExpander.getInstance(containerElement.getAttribute("id")); + this.styleExdr = FlexibleStringExpander.getInstance(containerElement.getAttribute("style")); + this.autoUpdateTargetExdr = FlexibleStringExpander.getInstance(containerElement.getAttribute("auto-update-target")); + String autoUpdateInterval = containerElement.getAttribute("auto-update-interval"); + if (autoUpdateInterval.isEmpty()) { + autoUpdateInterval = "2"; + } + this.autoUpdateInterval = FlexibleStringExpander.getInstance(autoUpdateInterval); + // read sub-widgets + List subElementList = UtilXml.childElementList(containerElement); + this.subWidgets = ModelScreenWidget.readSubWidgets(getModelScreen(), subElementList); + } + + @Override + public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException, IOException { + try { + screenStringRenderer.renderContainerBegin(writer, context, this); + + // render sub-widgets + renderSubWidgetsString(this.subWidgets, writer, context, screenStringRenderer); + + screenStringRenderer.renderContainerEnd(writer, context, this); + } catch (IOException e) { + String errMsg = "Error rendering container in screen named [" + getModelScreen().getName() + "]: " + e.toString(); + Debug.logError(e, errMsg, module); + throw new RuntimeException(errMsg); + } + } + + public String getId(Map context) { + return this.idExdr.expandString(context); + } + + public String getStyle(Map context) { + return this.styleExdr.expandString(context); + } + + public String getAutoUpdateTargetExdr(Map context) { + return this.autoUpdateTargetExdr.expandString(context); + } + + public String getAutoUpdateInterval(Map context) { + return this.autoUpdateInterval.expandString(context); + } + + public List getSubWidgets() { + return subWidgets; + } + + @Override + public void accept(ModelWidgetVisitor visitor) throws Exception { + visitor.visit(this); + } + + public FlexibleStringExpander getIdExdr() { + return idExdr; + } + + public FlexibleStringExpander getStyleExdr() { + return styleExdr; + } + + public FlexibleStringExpander getAutoUpdateTargetExdr() { + return autoUpdateTargetExdr; + } + + public FlexibleStringExpander getAutoUpdateInterval() { + return autoUpdateInterval; + } + } + + public static final class Screenlet extends ModelScreenWidget { + public static final String TAG_NAME = "screenlet"; + private final FlexibleStringExpander idExdr; + private final FlexibleStringExpander titleExdr; + private final Menu navigationMenu; + private final Menu tabMenu; + private final Form navigationForm; + private final boolean collapsible; + private final FlexibleStringExpander initiallyCollapsed; + private final boolean saveCollapsed; + private final boolean padded; + private final List subWidgets; + + public Screenlet(ModelScreen modelScreen, Element screenletElement) { + super(modelScreen, screenletElement); + this.idExdr = FlexibleStringExpander.getInstance(screenletElement.getAttribute("id")); + boolean collapsible = "true".equals(screenletElement.getAttribute("collapsible")); + this.initiallyCollapsed = FlexibleStringExpander.getInstance(screenletElement.getAttribute("initially-collapsed")); + if ("true".equals(this.initiallyCollapsed.getOriginal())) { + collapsible = true; + } + this.collapsible = collapsible; + // By default, for a collapsible screenlet, the collapsed/expanded status must be saved + this.saveCollapsed = !("false".equals(screenletElement.getAttribute("save-collapsed"))); + + boolean padded = !"false".equals(screenletElement.getAttribute("padded")); + if (this.collapsible && getName().isEmpty() && idExdr.isEmpty()) { + throw new IllegalArgumentException("Collapsible screenlets must have a name or id [" + getModelScreen().getName() + "]"); + } + this.titleExdr = FlexibleStringExpander.getInstance(screenletElement.getAttribute("title")); + List subElementList = UtilXml.childElementList(screenletElement); + // Make a copy of the unmodifiable List so we can modify it. + ArrayList subWidgets = new ArrayList(ModelScreenWidget.readSubWidgets(getModelScreen(), subElementList)); + Menu navigationMenu = null; + String navMenuName = screenletElement.getAttribute("navigation-menu-name"); + if (!navMenuName.isEmpty()) { + for (ModelWidget subWidget : subWidgets) { + if (navMenuName.equals(subWidget.getName()) && subWidget instanceof Menu) { + navigationMenu = (Menu) subWidget; + subWidgets.remove(subWidget); + break; + } + } + } + this.navigationMenu = navigationMenu; + Menu tabMenu = null; + String tabMenuName = screenletElement.getAttribute("tab-menu-name"); + if (!tabMenuName.isEmpty()) { + for (ModelWidget subWidget : subWidgets) { + if (tabMenuName.equals(subWidget.getName()) && subWidget instanceof Menu) { + tabMenu = (Menu) subWidget; + subWidgets.remove(subWidget); + break; + } + } + } + this.tabMenu = tabMenu; + Form navigationForm = null; + String formName = screenletElement.getAttribute("navigation-form-name"); + if (!formName.isEmpty() && this.navigationMenu == null) { + for (ModelWidget subWidget : subWidgets) { + if (formName.equals(subWidget.getName()) && subWidget instanceof Form) { + navigationForm = (Form) subWidget; + padded = false; + break; + } + } + } + this.subWidgets = Collections.unmodifiableList(subWidgets); + this.navigationForm = navigationForm; + this.padded = padded; + } + + @Override + public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException, IOException { + boolean collapsed = getInitiallyCollapsed(context); + if (this.collapsible) { + String preferenceKey = getPreferenceKey(context) + "_collapsed"; + Map requestParameters = UtilGenerics.checkMap(context.get("requestParameters")); + if (requestParameters != null) { + String collapsedParam = (String) requestParameters.get(preferenceKey); + collapsed = "true".equals(collapsedParam); + } + } + try { + screenStringRenderer.renderScreenletBegin(writer, context, collapsed, this); + for (ModelScreenWidget subWidget : this.subWidgets) { + screenStringRenderer.renderScreenletSubWidget(writer, context, subWidget, this); + } + screenStringRenderer.renderScreenletEnd(writer, context, this); + } catch (IOException e) { + String errMsg = "Error rendering screenlet in screen named [" + getModelScreen().getName() + "]: "; + Debug.logError(e, errMsg, module); + throw new RuntimeException(errMsg + e); + } + } + + public boolean collapsible() { + return this.collapsible; + } + + //initially-collapsed status, which may be overriden by user preference + public boolean getInitiallyCollapsed(Map context) { + String screenletId = this.getId(context) + "_collapsed"; + Map userPreferences = UtilGenerics.checkMap(context.get("userPreferences")); + if (userPreferences != null && userPreferences.containsKey(screenletId)) { + return Boolean.valueOf((String)userPreferences.get(screenletId)).booleanValue() ; + } + + return "true".equals(this.initiallyCollapsed.expand(context)); + } + + public boolean saveCollapsed() { + return this.saveCollapsed; + } + public boolean padded() { + return this.padded; + } + + public String getPreferenceKey(Map context) { + String name = this.idExdr.expandString(context); + if (name.isEmpty()) { + name = "screenlet" + "_" + Integer.toHexString(hashCode()); + } + return name; + } + + public String getId(Map context) { + return this.idExdr.expandString(context); + } + + public List getSubWidgets() { + return subWidgets; + } + + public String getTitle(Map context) { + String title = this.titleExdr.expandString(context); + UtilCodec.SimpleEncoder simpleEncoder = (UtilCodec.SimpleEncoder) context.get("simpleEncoder"); + if (simpleEncoder != null) { + title = simpleEncoder.encode(title); + } + return title; + } + + public Menu getNavigationMenu() { + return this.navigationMenu; + } + + public Form getNavigationForm() { + return this.navigationForm; + } + + public Menu getTabMenu() { + return this.tabMenu; + } + + @Override + public void accept(ModelWidgetVisitor visitor) throws Exception { + visitor.visit(this); + } + + public FlexibleStringExpander getIdExdr() { + return idExdr; + } + + public FlexibleStringExpander getTitleExdr() { + return titleExdr; + } + + public boolean getCollapsible() { + return collapsible; + } + + public FlexibleStringExpander getInitiallyCollapsed() { + return initiallyCollapsed; + } + + public boolean getSaveCollapsed() { + return saveCollapsed; + } + + public boolean getPadded() { + return padded; + } + } + + public static final class HorizontalSeparator extends ModelScreenWidget { + public static final String TAG_NAME = "horizontal-separator"; + private final FlexibleStringExpander idExdr; + private final FlexibleStringExpander styleExdr; + + public HorizontalSeparator(ModelScreen modelScreen, Element separatorElement) { + super(modelScreen, separatorElement); + this.idExdr = FlexibleStringExpander.getInstance(separatorElement.getAttribute("id")); + this.styleExdr = FlexibleStringExpander.getInstance(separatorElement.getAttribute("style")); + } + + @Override + public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException, IOException { + screenStringRenderer.renderHorizontalSeparator(writer, context, this); + } + + public String getId(Map context) { + return this.idExdr.expandString(context); + } + + public String getStyle(Map context) { + return this.styleExdr.expandString(context); + } + + @Override + public void accept(ModelWidgetVisitor visitor) throws Exception { + visitor.visit(this); + } + + public FlexibleStringExpander getIdExdr() { + return idExdr; + } + + public FlexibleStringExpander getStyleExdr() { + return styleExdr; + } + } + + public static final class IncludeScreen extends ModelScreenWidget { + public static final String TAG_NAME = "include-screen"; + private final FlexibleStringExpander nameExdr; + private final FlexibleStringExpander locationExdr; + private final FlexibleStringExpander shareScopeExdr; + + public IncludeScreen(ModelScreen modelScreen, Element includeScreenElement) { + super(modelScreen, includeScreenElement); + this.nameExdr = FlexibleStringExpander.getInstance(includeScreenElement.getAttribute("name")); + this.locationExdr = FlexibleStringExpander.getInstance(includeScreenElement.getAttribute("location")); + this.shareScopeExdr = FlexibleStringExpander.getInstance(includeScreenElement.getAttribute("share-scope")); + } + + @Override + public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException, IOException { + // if we are not sharing the scope, protect it using the MapStack + boolean protectScope = !shareScope(context); + if (protectScope) { + if (!(context instanceof MapStack)) { + context = MapStack.create(context); + } + + UtilGenerics.>cast(context).push(); + + // build the widgetpath + List widgetTrail = UtilGenerics.toList(context.get("_WIDGETTRAIL_")); + if (widgetTrail == null) { + widgetTrail = new LinkedList(); + } + + String thisName = nameExdr.expandString(context); + widgetTrail.add(thisName); + context.put("_WIDGETTRAIL_", widgetTrail); + } + + // don't need the renderer here, will just pass this on down to another screen call; screenStringRenderer.renderContainerBegin(writer, context, this); + String name = this.getName(context); + String location = this.getLocation(context); + + if (name.isEmpty()) { + if (Debug.verboseOn()) Debug.logVerbose("In the include-screen tag the screen name was empty, ignoring include; in screen [" + getModelScreen().getName() + "]", module); + return; + } + + ScreenFactory.renderReferencedScreen(name, location, this, writer, context, screenStringRenderer); + + if (protectScope) { + UtilGenerics.>cast(context).pop(); + } + } + + public String getName(Map context) { + return this.nameExdr.expandString(context); + } + + public String getLocation(Map context) { + return this.locationExdr.expandString(context); + } + + public boolean shareScope(Map context) { + String shareScopeString = this.shareScopeExdr.expandString(context); + // defaults to false, so anything but true is false + return "true".equals(shareScopeString); + } + + @Override + public void accept(ModelWidgetVisitor visitor) throws Exception { + visitor.visit(this); + } + + public FlexibleStringExpander getNameExdr() { + return nameExdr; + } + + public FlexibleStringExpander getLocationExdr() { + return locationExdr; + } + + public FlexibleStringExpander getShareScopeExdr() { + return shareScopeExdr; + } + } + + public static final class DecoratorScreen extends ModelScreenWidget { + public static final String TAG_NAME = "decorator-screen"; + private final FlexibleStringExpander nameExdr; + private final FlexibleStringExpander locationExdr; + private final Map sectionMap; + + public DecoratorScreen(ModelScreen modelScreen, Element decoratorScreenElement) { + super(modelScreen, decoratorScreenElement); + this.nameExdr = FlexibleStringExpander.getInstance(decoratorScreenElement.getAttribute("name")); + this.locationExdr = FlexibleStringExpander.getInstance(decoratorScreenElement.getAttribute("location")); + Map sectionMap = new HashMap(); + List decoratorSectionElementList = UtilXml.childElementList(decoratorScreenElement, "decorator-section"); + for (Element decoratorSectionElement: decoratorSectionElementList) { + DecoratorSection decoratorSection = new DecoratorSection(modelScreen, decoratorSectionElement); + sectionMap.put(decoratorSection.getName(), decoratorSection); + } + this.sectionMap = Collections.unmodifiableMap(sectionMap); + } + + @Override + @SuppressWarnings("unchecked") + public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException, IOException { + // isolate the scope + if (!(context instanceof MapStack)) { + context = MapStack.create(context); + } + + MapStack contextMs = (MapStack) context; + + // create a standAloneStack, basically a "save point" for this SectionsRenderer, and make a new "screens" object just for it so it is isolated and doesn't follow the stack down + MapStack standAloneStack = contextMs.standAloneChildStack(); + standAloneStack.put("screens", new ScreenRenderer(writer, standAloneStack, screenStringRenderer)); + SectionsRenderer sections = new SectionsRenderer(this.sectionMap, standAloneStack, writer, screenStringRenderer); + + // put the sectionMap in the context, make sure it is in the sub-scope, ie after calling push on the MapStack + contextMs.push(); + context.put("sections", sections); + + String name = this.getName(context); + String location = this.getLocation(context); + + ScreenFactory.renderReferencedScreen(name, location, this, writer, context, screenStringRenderer); + + contextMs.pop(); + } + + public String getName(Map context) { + return this.nameExdr.expandString(context); + } + + public String getLocation(Map context) { + return this.locationExdr.expandString(context); + } + + public Map getSectionMap() { + return sectionMap; + } + + @Override + public void accept(ModelWidgetVisitor visitor) throws Exception { + visitor.visit(this); + } + + public FlexibleStringExpander getNameExdr() { + return nameExdr; + } + + public FlexibleStringExpander getLocationExdr() { + return locationExdr; + } + + } + + public static final class DecoratorSection extends ModelScreenWidget { + public static final String TAG_NAME = "decorator-section"; + private final List subWidgets; + + public DecoratorSection(ModelScreen modelScreen, Element decoratorSectionElement) { + super(modelScreen, decoratorSectionElement); + // read sub-widgets + List subElementList = UtilXml.childElementList(decoratorSectionElement); + this.subWidgets = ModelScreenWidget.readSubWidgets(getModelScreen(), subElementList); + } + + @Override + public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException, IOException { + // render sub-widgets + renderSubWidgetsString(this.subWidgets, writer, context, screenStringRenderer); + } + + public List getSubWidgets() { + return subWidgets; + } + + @Override + public void accept(ModelWidgetVisitor visitor) throws Exception { + visitor.visit(this); + } + } + + public static final class DecoratorSectionInclude extends ModelScreenWidget { + public static final String TAG_NAME = "decorator-section-include"; + + public DecoratorSectionInclude(ModelScreen modelScreen, Element decoratorSectionElement) { + super(modelScreen, decoratorSectionElement); + } + + @Override + public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException, IOException { + Map preRenderedContent = UtilGenerics.checkMap(context.get("preRenderedContent")); + if (preRenderedContent != null && preRenderedContent.containsKey(getName())) { + try { + writer.append((String) preRenderedContent.get(getName())); + } catch (IOException e) { + String errMsg = "Error rendering pre-rendered content in screen named [" + getModelScreen().getName() + "]: " + e.toString(); + Debug.logError(e, errMsg, module); + throw new RuntimeException(errMsg); + } + } else { + SectionsRenderer sections = (SectionsRenderer) context.get("sections"); + // for now if sections is null, just log a warning; may be permissible to make the screen for flexible + if (sections == null) { + Debug.logWarning("In decorator-section-include could not find sections object in the context, not rendering section with name [" + getName() + "]", module); + } else { + sections.render(getName()); + } + } + } + + @Override + public void accept(ModelWidgetVisitor visitor) throws Exception { + visitor.visit(this); + } + } + + public static final class Label extends ModelScreenWidget { + public static final String TAG_NAME = "label"; + private final FlexibleStringExpander textExdr; + private final FlexibleStringExpander idExdr; + private final FlexibleStringExpander styleExdr; + + public Label(ModelScreen modelScreen, Element labelElement) { + super(modelScreen, labelElement); + + // put the text attribute first, then the pcdata under the element, if both are there of course + String textAttr = labelElement.getAttribute("text"); + String pcdata = UtilXml.elementValue(labelElement); + if (pcdata == null) { + pcdata = ""; + } + this.textExdr = FlexibleStringExpander.getInstance(textAttr + pcdata); + + this.idExdr = FlexibleStringExpander.getInstance(labelElement.getAttribute("id")); + this.styleExdr = FlexibleStringExpander.getInstance(labelElement.getAttribute("style")); + } + + @Override + public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) { + try { + screenStringRenderer.renderLabel(writer, context, this); + } catch (IOException e) { + String errMsg = "Error rendering label in screen named [" + getModelScreen().getName() + "]: " + e.toString(); + Debug.logError(e, errMsg, module); + throw new RuntimeException(errMsg); + } + } + + public String getText(Map context) { + String text = this.textExdr.expandString(context); + // FIXME: Encoding should be done by the renderer, not by the model. + UtilCodec.SimpleEncoder simpleEncoder = (UtilCodec.SimpleEncoder) context.get("simpleEncoder"); + if (simpleEncoder != null) { + text = simpleEncoder.encode(text); + } + return text; + } + + public String getId(Map context) { + return this.idExdr.expandString(context); + } + + public String getStyle(Map context) { + return this.styleExdr.expandString(context); + } + + @Override + public void accept(ModelWidgetVisitor visitor) throws Exception { + visitor.visit(this); + } + + public FlexibleStringExpander getTextExdr() { + return textExdr; + } + + public FlexibleStringExpander getIdExdr() { + return idExdr; + } + + public FlexibleStringExpander getStyleExdr() { + return styleExdr; + } + } + + public static final class Form extends ModelScreenWidget { + public static final String TAG_NAME = "include-form"; + private final FlexibleStringExpander nameExdr; + private final FlexibleStringExpander locationExdr; + private final FlexibleStringExpander shareScopeExdr; + + public Form(ModelScreen modelScreen, Element formElement) { + super(modelScreen, formElement); + this.nameExdr = FlexibleStringExpander.getInstance(formElement.getAttribute("name")); + this.locationExdr = FlexibleStringExpander.getInstance(formElement.getAttribute("location")); + this.shareScopeExdr = FlexibleStringExpander.getInstance(formElement.getAttribute("share-scope")); + } + + @Override + public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) { + // Output format might not support forms, so make form rendering optional. + FormStringRenderer formStringRenderer = (FormStringRenderer) context.get("formStringRenderer"); + if (formStringRenderer == null) { + Debug.logVerbose("FormStringRenderer instance not found in rendering context, form not rendered.", module); + return; + } + boolean protectScope = !shareScope(context); + if (protectScope) { + if (!(context instanceof MapStack)) { + context = MapStack.create(context); + } + UtilGenerics.>cast(context).push(); + } + ModelForm modelForm = getModelForm(context); + FormRenderer renderer = new FormRenderer(modelForm, formStringRenderer); + try { + renderer.render(writer, context); + } catch (Exception e) { + String errMsg = "Error rendering included form named [" + getName() + "] at location [" + this.getLocation(context) + "]: " + e.toString(); + Debug.logError(e, errMsg, module); + throw new RuntimeException(errMsg + e); + } + + if (protectScope) { + UtilGenerics.>cast(context).pop(); + } + } + + public ModelForm getModelForm(Map context) { + ModelForm modelForm = null; + String name = this.getName(context); + String location = this.getLocation(context); + try { + modelForm = FormFactory.getFormFromLocation(location, name, getModelScreen().getDelegator(context).getModelReader(), getModelScreen().getDispatcher(context).getDispatchContext()); + } catch (Exception e) { + String errMsg = "Error rendering included form named [" + name + "] at location [" + location + "]: "; + Debug.logError(e, errMsg, module); + throw new RuntimeException(errMsg + e); + } + return modelForm; + } + + public String getName(Map context) { + return this.nameExdr.expandString(context); + } + + public String getLocation() { + return locationExdr.getOriginal(); + } + + public String getLocation(Map context) { + return this.locationExdr.expandString(context); + } + + public boolean shareScope(Map context) { + String shareScopeString = this.shareScopeExdr.expandString(context); + // defaults to false, so anything but true is false + return "true".equals(shareScopeString); + } + + @Override + public void accept(ModelWidgetVisitor visitor) throws Exception { + visitor.visit(this); + } + + public FlexibleStringExpander getNameExdr() { + return nameExdr; + } + + public FlexibleStringExpander getLocationExdr() { + return locationExdr; + } + + public FlexibleStringExpander getShareScopeExdr() { + return shareScopeExdr; + } + + } + + public static final class Tree extends ModelScreenWidget { + public static final String TAG_NAME = "include-tree"; + private final FlexibleStringExpander nameExdr; + private final FlexibleStringExpander locationExdr; + private final FlexibleStringExpander shareScopeExdr; + + public Tree(ModelScreen modelScreen, Element treeElement) { + super(modelScreen, treeElement); + this.nameExdr = FlexibleStringExpander.getInstance(treeElement.getAttribute("name")); + this.locationExdr = FlexibleStringExpander.getInstance(treeElement.getAttribute("location")); + this.shareScopeExdr = FlexibleStringExpander.getInstance(treeElement.getAttribute("share-scope")); + } + + @Override + public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException, IOException { + // Output format might not support trees, so make tree rendering optional. + TreeStringRenderer treeStringRenderer = (TreeStringRenderer) context.get("treeStringRenderer"); + if (treeStringRenderer == null) { + Debug.logVerbose("TreeStringRenderer instance not found in rendering context, tree not rendered.", module); + return; + } + boolean protectScope = !shareScope(context); + if (protectScope) { + if (!(context instanceof MapStack)) { + context = MapStack.create(context); + } + UtilGenerics.>cast(context).push(); + } + + String name = this.getName(context); + String location = this.getLocation(context); + ModelTree modelTree = null; + try { + modelTree = TreeFactory.getTreeFromLocation(this.getLocation(context), this.getName(context), getModelScreen().getDelegator(context), getModelScreen().getDispatcher(context)); + } catch (IOException e) { + String errMsg = "Error rendering included tree named [" + name + "] at location [" + location + "]: " + e.toString(); + Debug.logError(e, errMsg, module); + throw new RuntimeException(errMsg); + } catch (SAXException e) { + String errMsg = "Error rendering included tree named [" + name + "] at location [" + location + "]: " + e.toString(); + Debug.logError(e, errMsg, module); + throw new RuntimeException(errMsg); + } catch (ParserConfigurationException e) { + String errMsg = "Error rendering included tree named [" + name + "] at location [" + location + "]: " + e.toString(); + Debug.logError(e, errMsg, module); + throw new RuntimeException(errMsg); + } + modelTree.renderTreeString(writer, context, treeStringRenderer); + if (protectScope) { + UtilGenerics.>cast(context).pop(); + } + } + + public String getName(Map context) { + return this.nameExdr.expandString(context); + } + + public String getLocation(Map context) { + return this.locationExdr.expandString(context); + } + + public boolean shareScope(Map context) { + String shareScopeString = this.shareScopeExdr.expandString(context); + // defaults to false, so anything but true is false + return "true".equals(shareScopeString); + } + + @Override + public void accept(ModelWidgetVisitor visitor) throws Exception { + visitor.visit(this); + } + + public FlexibleStringExpander getLocationExdr() { + return locationExdr; + } + + public FlexibleStringExpander getShareScopeExdr() { + return shareScopeExdr; + } + } + + public static final class PlatformSpecific extends ModelScreenWidget { + public static final String TAG_NAME = "platform-specific"; + private final Map subWidgets; + + public PlatformSpecific(ModelScreen modelScreen, Element platformSpecificElement) { + super(modelScreen, platformSpecificElement); + Map subWidgets = new HashMap(); + List childElements = UtilXml.childElementList(platformSpecificElement); + if (childElements != null) { + for (Element childElement: childElements) { + if ("html".equals(childElement.getNodeName())) { + subWidgets.put("html", new HtmlWidget(modelScreen, childElement)); + } else if ("xsl-fo".equals(childElement.getNodeName())) { + subWidgets.put("xsl-fo", new HtmlWidget(modelScreen, childElement)); + } else if ("xml".equals(childElement.getNodeName())) { + subWidgets.put("xml", new HtmlWidget(modelScreen, childElement)); + } else { + throw new IllegalArgumentException("Tag not supported under the platform-specific tag with name: " + childElement.getNodeName()); + } + } + } + this.subWidgets = Collections.unmodifiableMap(subWidgets); + } + + @Override + public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException, IOException { + ModelScreenWidget subWidget = null; + subWidget = subWidgets.get(screenStringRenderer.getRendererName()); + if (subWidget == null) { + // This is here for backward compatibility + Debug.logWarning("In platform-dependent could not find template for " + screenStringRenderer.getRendererName() + ", using the one for html.", module); + subWidget = subWidgets.get("html"); + } + if (subWidget != null) { + subWidget.renderWidgetString(writer, context, screenStringRenderer); + } + } + + @Override + public void accept(ModelWidgetVisitor visitor) throws Exception { + visitor.visit(this); + } + + public Map getSubWidgets() { + return subWidgets; + } + } + + public static final class Content extends ModelScreenWidget { + public static final String TAG_NAME = "content"; + + private final FlexibleStringExpander contentId; + private final FlexibleStringExpander editRequest; + private final FlexibleStringExpander editContainerStyle; + private final FlexibleStringExpander enableEditName; + private final boolean xmlEscape; + private final FlexibleStringExpander dataResourceId; + private final String width; + private final String height; + private final String border; + + public Content(ModelScreen modelScreen, Element subContentElement) { + super(modelScreen, subContentElement); + this.contentId = FlexibleStringExpander.getInstance(subContentElement.getAttribute("content-id")); + this.dataResourceId = FlexibleStringExpander.getInstance(subContentElement.getAttribute("dataresource-id")); + this.editRequest = FlexibleStringExpander.getInstance(subContentElement.getAttribute("edit-request")); + this.editContainerStyle = FlexibleStringExpander.getInstance(subContentElement.getAttribute("edit-container-style")); + this.enableEditName = FlexibleStringExpander.getInstance(subContentElement.getAttribute("enable-edit-name")); + this.xmlEscape = "true".equals(subContentElement.getAttribute("xml-escape")); + String width = subContentElement.getAttribute("width"); + if (width.isEmpty()) + width = "60%"; + this.height = subContentElement.getAttribute("height"); + if (this.height.isEmpty()) + width = "400px"; + this.width = width; + this.border = subContentElement.getAttribute("border"); + } + + @Override + public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) { + try { + // pushing the contentId on the context as "contentId" is done + // because many times there will be embedded "subcontent" elements + // that use the syntax: )) { + context = MapStack.create(context); + } + + // This is an important step to make sure that the current contentId is in the context + // as templates that contain "subcontent" elements will expect to find the master + // contentId in the context as "contentId". + UtilGenerics.>cast(context).push(); + context.put("contentId", expandedContentId); + + if (expandedDataResourceId.isEmpty()) { + if (!expandedContentId.isEmpty()) { + content = EntityQuery.use(delegator).from("Content").where("contentId", expandedContentId).cache().queryOne(); + } else { + String errMsg = "contentId is empty."; + Debug.logError(errMsg, module); + return; + } + if (content != null) { + expandedDataResourceId = content.getString("dataResourceId"); + } else { + String errMsg = "Could not find content with contentId [" + expandedContentId + "] "; + Debug.logError(errMsg, module); + throw new RuntimeException(errMsg); + } + } + + GenericValue dataResource = null; + if (!expandedDataResourceId.isEmpty()) { + dataResource = EntityQuery.use(delegator).from("DataResource").where("dataResourceId", expandedDataResourceId).cache().queryOne(); + } + + String mimeTypeId = null; + if (dataResource != null) { + mimeTypeId = dataResource.getString("mimeTypeId"); + } + if (content != null) { + mimeTypeId = content.getString("mimeTypeId"); + } + + if (!(mimeTypeId != null + && ((mimeTypeId.indexOf("application") >= 0) || (mimeTypeId.indexOf("image")) >= 0))) { + screenStringRenderer.renderContentBegin(writer, context, this); + screenStringRenderer.renderContentBody(writer, context, this); + screenStringRenderer.renderContentEnd(writer, context, this); + } + UtilGenerics.>cast(context).pop(); + } catch (IOException e) { + String errMsg = "Error rendering content with contentId [" + getContentId(context) + "]: " + e.toString(); + Debug.logError(e, errMsg, module); + throw new RuntimeException(errMsg); + } catch (GenericEntityException e) { + String errMsg = "Error obtaining content with contentId [" + getContentId(context) + "]: " + e.toString(); + Debug.logError(e, errMsg, module); + throw new RuntimeException(errMsg); + } + + } + + public String getContentId(Map context) { + return this.contentId.expandString(context); + } + + public String getDataResourceId() { + return this.dataResourceId.getOriginal(); + } + + public String getDataResourceId(Map context) { + return this.dataResourceId.expandString(context); + } + + public String getEditRequest(Map context) { + return this.editRequest.expandString(context); + } + + public String getEditContainerStyle(Map context) { + return this.editContainerStyle.expandString(context); + } + + public String getEnableEditName(Map context) { + return this.enableEditName.expandString(context); + } + + public boolean xmlEscape() { + return this.xmlEscape; + } + + public String getWidth() { + return this.width; + } + + public String getHeight() { + return this.height; + } + + public String getBorder() { + return this.border; + } + + @Override + public void accept(ModelWidgetVisitor visitor) throws Exception { + visitor.visit(this); + } + + public FlexibleStringExpander getContentId() { + return contentId; + } + + public FlexibleStringExpander getEditRequest() { + return editRequest; + } + + public FlexibleStringExpander getEditContainerStyle() { + return editContainerStyle; + } + + public FlexibleStringExpander getEnableEditName() { + return enableEditName; + } + } + + public static final class SubContent extends ModelScreenWidget { + public static final String TAG_NAME = "sub-content"; + private final FlexibleStringExpander contentId; + private final FlexibleStringExpander mapKey; + private final FlexibleStringExpander editRequest; + private final FlexibleStringExpander editContainerStyle; + private final FlexibleStringExpander enableEditName; + private final boolean xmlEscape; + + public SubContent(ModelScreen modelScreen, Element subContentElement) { + super(modelScreen, subContentElement); + this.contentId = FlexibleStringExpander.getInstance(subContentElement.getAttribute("content-id")); + String mapKey = subContentElement.getAttribute("map-key"); + if (mapKey.isEmpty()) { + mapKey = subContentElement.getAttribute("assoc-name"); + } + this.mapKey = FlexibleStringExpander.getInstance(mapKey); + this.editRequest = FlexibleStringExpander.getInstance(subContentElement.getAttribute("edit-request")); + this.editContainerStyle = FlexibleStringExpander.getInstance(subContentElement.getAttribute("edit-container-style")); + this.enableEditName = FlexibleStringExpander.getInstance(subContentElement.getAttribute("enable-edit-name")); + this.xmlEscape = "true".equals(subContentElement.getAttribute("xml-escape")); + } + + @Override + public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) { + try { + screenStringRenderer.renderSubContentBegin(writer, context, this); + screenStringRenderer.renderSubContentBody(writer, context, this); + screenStringRenderer.renderSubContentEnd(writer, context, this); + } catch (IOException e) { + String errMsg = "Error rendering subContent with contentId [" + getContentId(context) + "]: " + e.toString(); + Debug.logError(e, errMsg, module); + throw new RuntimeException(errMsg); + } + } + + public String getContentId(Map context) { + return this.contentId.expandString(context); + } + + public String getMapKey(Map context) { + return this.mapKey.expandString(context); + } + + public String getEditRequest(Map context) { + return this.editRequest.expandString(context); + } + + public String getEditContainerStyle(Map context) { + return this.editContainerStyle.expandString(context); + } + + public String getEnableEditName(Map context) { + return this.enableEditName.expandString(context); + } + + public boolean xmlEscape() { + return this.xmlEscape; + } + + @Override + public void accept(ModelWidgetVisitor visitor) throws Exception { + // TODO Auto-generated method stub + + } + } + + public static final class Menu extends ModelScreenWidget { + public static final String TAG_NAME = "include-menu"; + private final FlexibleStringExpander nameExdr; + private final FlexibleStringExpander locationExdr; + + public Menu(ModelScreen modelScreen, Element menuElement) { + super(modelScreen, menuElement); + this.nameExdr = FlexibleStringExpander.getInstance(menuElement.getAttribute("name")); + this.locationExdr = FlexibleStringExpander.getInstance(menuElement.getAttribute("location")); + } + + @Override + public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) throws IOException { + // Output format might not support menus, so make menu rendering optional. + MenuStringRenderer menuStringRenderer = (MenuStringRenderer) context.get("menuStringRenderer"); + if (menuStringRenderer == null) { + Debug.logVerbose("MenuStringRenderer instance not found in rendering context, menu not rendered.", module); + return; + } + ModelMenu modelMenu = getModelMenu(context); + modelMenu.renderMenuString(writer, context, menuStringRenderer); + } + + public ModelMenu getModelMenu(Map context) { + String name = this.getName(context); + String location = this.getLocation(context); + ModelMenu modelMenu = null; + try { + modelMenu = MenuFactory.getMenuFromLocation(location, name); + } catch (Exception e) { + String errMsg = "Error rendering included menu named [" + name + "] at location [" + location + "]: "; + Debug.logError(e, errMsg, module); + throw new RuntimeException(errMsg + e); + } + return modelMenu; + } + + public String getName(Map context) { + return this.nameExdr.expandString(context); + } + + public String getLocation(Map context) { + return this.locationExdr.expandString(context); + } + + @Override + public void accept(ModelWidgetVisitor visitor) throws Exception { + visitor.visit(this); + } + + public FlexibleStringExpander getLocationExdr() { + return locationExdr; + } + } + + public static final class ScreenLink extends ModelScreenWidget { + public static final String TAG_NAME = "link"; + private final Link link; + private final ScreenImage image; + + public ScreenLink(ModelScreen modelScreen, Element linkElement) { + super(modelScreen, linkElement); + this.link = new Link(linkElement); + Element imageElement = UtilXml.firstChildElement(linkElement, "image"); + if (imageElement != null) { + this.image = new ScreenImage(modelScreen, imageElement); + } else { + this.image = null; + } + } + + public String getName() { + return link.getName(); + } + + public String getText(Map context) { + return link.getText(context); + } + + public String getId(Map context) { + return link.getId(context); + } + + public String getStyle(Map context) { + return link.getStyle(context); + } + + public String getTarget(Map context) { + return link.getTarget(context); + } + + public String getName(Map context) { + return link.getName(context); + } + + public String getTargetWindow(Map context) { + return link.getTargetWindow(context); + } + + public String getUrlMode() { + return link.getUrlMode(); + } + + public String getPrefix(Map context) { + return link.getPrefix(context); + } + + public boolean getFullPath() { + return link.getFullPath(); + } + + public boolean getSecure() { + return link.getSecure(); + } + + public boolean getEncode() { + return link.getEncode(); + } + + public ScreenImage getImage() { + return image; + } + + public String getLinkType() { + return link.getLinkType(); + } + + public String getWidth() { + return link.getWidth(); + } + + public String getHeight() { + return link.getHeight(); + } + + public Map getParameterMap(Map context) { + return link.getParameterMap(context); + } + + public FlexibleStringExpander getTextExdr() { + return link.getTextExdr(); + } + + public FlexibleStringExpander getIdExdr() { + return link.getIdExdr(); + } + + public FlexibleStringExpander getStyleExdr() { + return link.getStyleExdr(); + } + + public FlexibleStringExpander getTargetExdr() { + return link.getTargetExdr(); + } + + public FlexibleStringExpander getTargetWindowExdr() { + return link.getTargetWindowExdr(); + } + + public FlexibleStringExpander getPrefixExdr() { + return link.getPrefixExdr(); + } + + public FlexibleStringExpander getNameExdr() { + return link.getNameExdr(); + } + + public List getParameterList() { + return link.getParameterList(); + } + + public AutoServiceParameters getAutoServiceParameters() { + return link.getAutoServiceParameters(); + } + + public AutoEntityParameters getAutoEntityParameters() { + return link.getAutoEntityParameters(); + } + + @Override + public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) { + try { + screenStringRenderer.renderLink(writer, context, this); + } catch (IOException e) { + String errMsg = "Error rendering link with id [" + link.getId(context) + "]: " + e.toString(); + Debug.logError(e, errMsg, module); + throw new RuntimeException(errMsg); + } + } + + @Override + public void accept(ModelWidgetVisitor visitor) throws Exception { + visitor.visit(this); + } + + public Link getLink() { + return link; + } + } + + public static final class ScreenImage extends ModelScreenWidget { + public static final String TAG_NAME = "image"; + private final Image image; + + public String getName() { + return image.getName(); + } + + public String getSrc(Map context) { + return image.getSrc(context); + } + + public String getId(Map context) { + return image.getId(context); + } + + public String getStyle(Map context) { + return image.getStyle(context); + } + + public String getWidth(Map context) { + return image.getWidth(context); + } + + public String getHeight(Map context) { + return image.getHeight(context); + } + + public String getBorder(Map context) { + return image.getBorder(context); + } + + public String getAlt(Map context) { + return image.getAlt(context); + } + + public String getUrlMode() { + return image.getUrlMode(); + } + + public FlexibleStringExpander getSrcExdr() { + return image.getSrcExdr(); + } + + public FlexibleStringExpander getIdExdr() { + return image.getIdExdr(); + } + + public FlexibleStringExpander getStyleExdr() { + return image.getStyleExdr(); + } + + public FlexibleStringExpander getWidthExdr() { + return image.getWidthExdr(); + } + + public FlexibleStringExpander getHeightExdr() { + return image.getHeightExdr(); + } + + public FlexibleStringExpander getBorderExdr() { + return image.getBorderExdr(); + } + + public FlexibleStringExpander getAlt() { + return image.getAlt(); + } + + public ScreenImage(ModelScreen modelScreen, Element imageElement) { + super(modelScreen, imageElement); + this.image = new Image(imageElement); + } + + @Override + public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) { + try { + screenStringRenderer.renderImage(writer, context, this); + } catch (IOException e) { + String errMsg = "Error rendering image with id [" + image.getId(context) + "]: " + e.toString(); + Debug.logError(e, errMsg, module); + throw new RuntimeException(errMsg); + } + } + + @Override + public void accept(ModelWidgetVisitor visitor) throws Exception { + visitor.visit(this); + } + + public Image getImage() { + return image; + } + } + + public static final class PortalPage extends ModelScreenWidget { + public static final String TAG_NAME = "include-portal-page"; + private final FlexibleStringExpander idExdr; + private final FlexibleStringExpander confModeExdr; + private final Boolean usePrivate; + + public PortalPage(ModelScreen modelScreen, Element portalPageElement) { + super(modelScreen, portalPageElement); + this.idExdr = FlexibleStringExpander.getInstance(portalPageElement.getAttribute("id")); + this.confModeExdr = FlexibleStringExpander.getInstance(portalPageElement.getAttribute("conf-mode")); + this.usePrivate = !("false".equals(portalPageElement.getAttribute("use-private"))); + } + + private GenericValue getPortalPageValue(Map context) { + Delegator delegator = (Delegator) context.get("delegator"); + String expandedPortalPageId = getId(context); + GenericValue portalPage = null; + if (!expandedPortalPageId.isEmpty()) { + if (usePrivate) { + portalPage = PortalPageWorker.getPortalPage(expandedPortalPageId, context); + } else { + try { + portalPage = EntityQuery.use(delegator) + .from("PortalPage") + .where("portalPageId", expandedPortalPageId) + .cache().queryOne(); + } catch (GenericEntityException e) { + throw new RuntimeException(e); + } + } + } + if (portalPage == null) { + String errMsg = "Could not find PortalPage with portalPageId [" + expandedPortalPageId + "] "; + Debug.logError(errMsg, module); + throw new RuntimeException(errMsg); + } + return portalPage; + } + + @Override + public void renderWidgetString(Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException, IOException { + try { + Delegator delegator = (Delegator) context.get("delegator"); + List portalPageColumns = null; + List portalPagePortlets = null; + List portletAttributes = null; + GenericValue portalPage = getPortalPageValue(context); + String actualPortalPageId = portalPage.getString("portalPageId"); + portalPageColumns = EntityQuery.use(delegator) + .from("PortalPageColumn") + .where("portalPageId", actualPortalPageId) + .orderBy("columnSeqId") + .cache(true) + .queryList(); + + // Renders the portalPage header + screenStringRenderer.renderPortalPageBegin(writer, context, this); + + // First column has no previous column + String prevColumnSeqId = ""; + + // Iterates through the PortalPage columns + ListIterator columnsIterator = portalPageColumns.listIterator(); + while(columnsIterator.hasNext()) { + GenericValue columnValue = columnsIterator.next(); + String columnSeqId = columnValue.getString("columnSeqId"); + + // Renders the portalPageColumn header + screenStringRenderer.renderPortalPageColumnBegin(writer, context, this, columnValue); + + // Get the Portlets located in the current column + portalPagePortlets = EntityQuery.use(delegator) + .from("PortalPagePortletView") + .where("portalPageId", portalPage.getString("portalPageId"), "columnSeqId", columnSeqId) + .orderBy("sequenceNum") + .queryList(); + // First Portlet in a Column has no previous Portlet + String prevPortletId = ""; + String prevPortletSeqId = ""; + + // If this is not the last column, get the next columnSeqId + String nextColumnSeqId = ""; + if (columnsIterator.hasNext()) { + nextColumnSeqId = portalPageColumns.get(columnsIterator.nextIndex()).getString("columnSeqId"); + } + + // Iterates through the Portlets in the Column + ListIterator portletsIterator = portalPagePortlets.listIterator(); + while(portletsIterator.hasNext()) { + GenericValue portletValue = portletsIterator.next(); + + // If not the last portlet in the column, get the next nextPortletId and nextPortletSeqId + String nextPortletId = ""; + String nextPortletSeqId = ""; + if (portletsIterator.hasNext()) { + nextPortletId = portalPagePortlets.get(portletsIterator.nextIndex()).getString("portalPortletId"); + nextPortletSeqId = portalPagePortlets.get(portletsIterator.nextIndex()).getString("portletSeqId"); + } + + // Set info to allow portlet movement in the page + context.put("prevPortletId", prevPortletId); + context.put("prevPortletSeqId", prevPortletSeqId); + context.put("nextPortletId", nextPortletId); + context.put("nextPortletSeqId", nextPortletSeqId); + context.put("prevColumnSeqId", prevColumnSeqId); + context.put("nextColumnSeqId", nextColumnSeqId); + + // Get portlet's attributes + portletAttributes = EntityQuery.use(delegator) + .from("PortletAttribute") + .where("portalPageId", portletValue.get("portalPageId"), "portalPortletId", portletValue.get("portalPortletId"), "portletSeqId", portletValue.get("portletSeqId")) + .queryList(); + + ListIterator attributesIterator = portletAttributes.listIterator(); + while (attributesIterator.hasNext()) { + GenericValue attribute = attributesIterator.next(); + context.put(attribute.getString("attrName"), attribute.getString("attrValue")); + } + + // Renders the portalPagePortlet + screenStringRenderer.renderPortalPagePortletBegin(writer, context, this, portletValue); + screenStringRenderer.renderPortalPagePortletBody(writer, context, this, portletValue); + screenStringRenderer.renderPortalPagePortletEnd(writer, context, this, portletValue); + + // Remove the portlet's attributes so that these are not available for other portlets + while (attributesIterator.hasPrevious()) { + GenericValue attribute = attributesIterator.previous(); + context.remove(attribute.getString("attrName")); + } + + // Uses the actual portlet as prevPortlet for next iteration + prevPortletId = (String) portletValue.get("portalPortletId"); + prevPortletSeqId = (String) portletValue.get("portletSeqId"); + } + // Renders the portalPageColumn footer + screenStringRenderer.renderPortalPageColumnEnd(writer, context, this, columnValue); + + // Uses the actual columnSeqId as prevColumnSeqId for next iteration + prevColumnSeqId = columnSeqId; + } + // Renders the portalPage footer + screenStringRenderer.renderPortalPageEnd(writer, context, this); + } catch (IOException e) { + String errMsg = "Error rendering PortalPage with portalPageId [" + getId(context) + "]: " + e.toString(); + Debug.logError(e, errMsg, module); + throw new RuntimeException(errMsg); + } catch (GenericEntityException e) { + String errMsg = "Error obtaining PortalPage with portalPageId [" + getId(context) + "]: " + e.toString(); + Debug.logError(e, errMsg, module); + throw new RuntimeException(errMsg); + } + } + + public String getId(Map context) { + return this.idExdr.expandString(context); + } + + public String getOriginalPortalPageId(Map context) { + GenericValue portalPage = getPortalPageValue(context); + return portalPage.getString("originalPortalPageId"); + } + + public String getActualPortalPageId(Map context) { + GenericValue portalPage = getPortalPageValue(context); + return portalPage.getString("portalPageId"); + } + + public String getConfMode(Map context) { + return this.confModeExdr.expandString(context); + } + + public String getUsePrivate() { + return Boolean.toString(this.usePrivate); + } + + @Override + public void accept(ModelWidgetVisitor visitor) throws Exception { + visitor.visit(this); + } + + public FlexibleStringExpander getIdExdr() { + return idExdr; + } + + public FlexibleStringExpander getConfModeExdr() { + return confModeExdr; + } + } + +} diff --git a/framework/widget/src/org/ofbiz/widget/tree/ModelTree.java b/framework/widget/src/org/ofbiz/widget/model/ModelTree.java similarity index 97% rename from framework/widget/src/org/ofbiz/widget/tree/ModelTree.java rename to framework/widget/src/org/ofbiz/widget/model/ModelTree.java index 8c85016e25..9a2bf60070 100644 --- a/framework/widget/src/org/ofbiz/widget/tree/ModelTree.java +++ b/framework/widget/src/org/ofbiz/widget/model/ModelTree.java @@ -1,1139 +1,1135 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget.tree; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.ListIterator; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.xml.parsers.ParserConfigurationException; - -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.GeneralException; -import org.ofbiz.base.util.StringUtil; -import org.ofbiz.base.util.UtilCodec; -import org.ofbiz.base.util.UtilGenerics; -import org.ofbiz.base.util.UtilHttp; -import org.ofbiz.base.util.UtilValidate; -import org.ofbiz.base.util.UtilXml; -import org.ofbiz.base.util.collections.MapStack; -import org.ofbiz.base.util.string.FlexibleStringExpander; -import org.ofbiz.entity.Delegator; -import org.ofbiz.entity.GenericEntityException; -import org.ofbiz.entity.GenericValue; -import org.ofbiz.entity.model.ModelEntity; -import org.ofbiz.entity.model.ModelField; -import org.ofbiz.entity.util.EntityListIterator; -import org.ofbiz.entity.util.EntityQuery; -import org.ofbiz.widget.ModelWidget; -import org.ofbiz.widget.*; -import org.ofbiz.widget.ModelWidgetVisitor; -import org.ofbiz.widget.WidgetWorker; -import org.ofbiz.widget.CommonWidgetModels.Parameter; -import org.ofbiz.widget.screen.ModelScreen; -import org.ofbiz.widget.screen.ScreenFactory; -import org.ofbiz.widget.screen.ScreenRenderException; -import org.ofbiz.widget.screen.ScreenStringRenderer; -import org.w3c.dom.Element; -import org.xml.sax.SAXException; - -/** - * Models the <tree> element. - * - * @see widget-tree.xsd - */ -@SuppressWarnings("serial") -public class ModelTree extends ModelWidget { - - /* - * ----------------------------------------------------------------------- * - * DEVELOPERS PLEASE READ - * ----------------------------------------------------------------------- * - * - * This model is intended to be a read-only data structure that represents - * an XML element. Outside of object construction, the class should not - * have any behaviors. - * - * Instances of this class will be shared by multiple threads - therefore - * it is immutable. DO NOT CHANGE THE OBJECT'S STATE AT RUN TIME! - * - */ - - public static final String module = ModelTree.class.getName(); - - private final String defaultEntityName; - private final String defaultRenderStyle; - private final FlexibleStringExpander defaultWrapStyleExdr; - private final FlexibleStringExpander expandCollapseRequestExdr; - private final boolean forceChildCheck; - private final String location; - private final Map nodeMap; - private final int openDepth; - private final int postTrailOpenDepth; - private final String rootNodeName; - private final FlexibleStringExpander trailNameExdr; - - public ModelTree(Element treeElement, String location) { - super(treeElement); - this.location = location; - this.rootNodeName = treeElement.getAttribute("root-node-name"); - String defaultRenderStyle = UtilXml.checkEmpty(treeElement.getAttribute("default-render-style"), "simple"); - // A temporary hack to accommodate those who might still be using "render-style" instead of "default-render-style" - if (defaultRenderStyle.isEmpty() || defaultRenderStyle.equals("simple")) { - String rStyle = treeElement.getAttribute("render-style"); - if (!rStyle.isEmpty()) - defaultRenderStyle = rStyle; - } - this.defaultRenderStyle = defaultRenderStyle; - this.defaultWrapStyleExdr = FlexibleStringExpander.getInstance(treeElement.getAttribute("default-wrap-style")); - this.expandCollapseRequestExdr = FlexibleStringExpander.getInstance(treeElement.getAttribute("expand-collapse-request")); - this.trailNameExdr = FlexibleStringExpander.getInstance(UtilXml.checkEmpty(treeElement.getAttribute("trail-name"), - "trail")); - this.forceChildCheck = !"false".equals(treeElement.getAttribute("force-child-check")); - this.defaultEntityName = treeElement.getAttribute("entity-name"); - int openDepth = 0; - if (treeElement.hasAttribute("open-depth")) { - try { - openDepth = Integer.parseInt(treeElement.getAttribute("open-depth")); - } catch (NumberFormatException e) { - throw new IllegalArgumentException("Invalid open-depth attribute value for the tree definition with name: " - + getName()); - } - } - this.openDepth = openDepth; - int postTrailOpenDepth = 999; - if (treeElement.hasAttribute("post-trail-open-depth")) { - try { - postTrailOpenDepth = Integer.parseInt(treeElement.getAttribute("post-trail-open-depth")); - } catch (NumberFormatException e) { - throw new IllegalArgumentException( - "Invalid post-trail-open-depth attribute value for the tree definition with name: " + getName()); - } - } - this.postTrailOpenDepth = postTrailOpenDepth; - List nodeElements = UtilXml.childElementList(treeElement, "node"); - if (nodeElements.size() == 0) { - throw new IllegalArgumentException("No node elements found for the tree definition with name: " + getName()); - } - Map nodeMap = new HashMap(); - for (Element nodeElementEntry : UtilXml.childElementList(treeElement, "node")) { - ModelNode node = new ModelNode(nodeElementEntry, this); - String nodeName = node.getName(); - nodeMap.put(nodeName, node); - } - this.nodeMap = Collections.unmodifiableMap(nodeMap); - } - - @Override - public void accept(ModelWidgetVisitor visitor) throws Exception { - visitor.visit(this); - } - - @Override - public String getBoundaryCommentName() { - return location + "#" + getName(); - } - - public String getDefaultEntityName() { - return this.defaultEntityName; - } - - public String getDefaultPkName(Map context) { - ModelEntity modelEntity = WidgetWorker.getDelegator(context).getModelEntity(this.defaultEntityName); - if (modelEntity.getPksSize() == 1) { - ModelField modelField = modelEntity.getOnlyPk(); - return modelField.getName(); - } - return null; - } - - public String getExpandCollapseRequest(Map context) { - String expColReq = this.expandCollapseRequestExdr.expandString(context); - if (UtilValidate.isEmpty(expColReq)) { - HttpServletRequest request = (HttpServletRequest) context.get("request"); - String s1 = request.getRequestURI(); - int pos = s1.lastIndexOf("/"); - if (pos >= 0) - expColReq = s1.substring(pos + 1); - else - expColReq = s1; - } - //append also the request parameters - Map paramMap = UtilGenerics.checkMap(context.get("requestParameters")); - if (UtilValidate.isNotEmpty(paramMap)) { - Map requestParameters = new HashMap(paramMap); - requestParameters.remove(this.getTrailName(context)); - if (UtilValidate.isNotEmpty(requestParameters)) { - String queryString = UtilHttp.urlEncodeArgs(requestParameters, false); - if (expColReq.indexOf("?") < 0) { - expColReq += "?"; - } else { - expColReq += "&"; - } - expColReq += queryString; - } - } - return expColReq; - } - - public int getOpenDepth() { - return openDepth; - } - - public int getPostTrailOpenDepth() { - return postTrailOpenDepth; - } - - public String getRenderStyle() { - return this.defaultRenderStyle; - } - - public String getRootNodeName() { - return rootNodeName; - } - - public String getTrailName(Map context) { - return this.trailNameExdr.expandString(context); - } - - public String getWrapStyle(Map context) { - return this.defaultWrapStyleExdr.expandString(context); - } - - /** - * Renders this model. - * - * @param writer - * @param context - * @param treeStringRenderer - */ - @SuppressWarnings("rawtypes") - public void renderTreeString(Appendable writer, Map context, TreeStringRenderer treeStringRenderer) - throws GeneralException { - Map parameters = UtilGenerics.checkMap(context.get("parameters")); - ModelNode node = nodeMap.get(rootNodeName); - String trailName = trailNameExdr.expandString(context); - String treeString = (String) context.get(trailName); - if (UtilValidate.isEmpty(treeString)) { - treeString = (String) parameters.get(trailName); - } - List trail = null; - if (UtilValidate.isNotEmpty(treeString)) { - trail = StringUtil.split(treeString, "|"); - if (UtilValidate.isEmpty(trail)) - throw new RuntimeException("Tree 'trail' value is empty."); - context.put("rootEntityId", trail.get(0)); - context.put(getDefaultPkName(context), trail.get(0)); - } else { - trail = new LinkedList(); - } - context.put("targetNodeTrail", trail); - context.put("currentNodeTrail", new LinkedList()); - try { - node.renderNodeString(writer, context, treeStringRenderer, 0); - } catch (IOException e2) { - String errMsg = "Error rendering included label with name [" + getName() + "] : " + e2.toString(); - Debug.logError(e2, errMsg, module); - throw new RuntimeException(errMsg); - } - - } - - public String getDefaultRenderStyle() { - return defaultRenderStyle; - } - - public FlexibleStringExpander getDefaultWrapStyleExdr() { - return defaultWrapStyleExdr; - } - - public FlexibleStringExpander getExpandCollapseRequestExdr() { - return expandCollapseRequestExdr; - } - - public boolean getForceChildCheck() { - return forceChildCheck; - } - - public String getLocation() { - return location; - } - - public Map getNodeMap() { - return nodeMap; - } - - public FlexibleStringExpander getTrailNameExdr() { - return trailNameExdr; - } - - /** - * Models the <node> element. - * - * @see widget-tree.xsd - */ - public static class ModelNode extends ModelWidget { - - private final List actions; - // TODO: Make this a generic condition object. - private final ModelTreeCondition condition; - private final String entityName; - private final String entryName; - private final String expandCollapseStyle; - private final Label label; - private final Link link; - private final ModelTree modelTree; - private final String pkName; - private final String renderStyle; - private final FlexibleStringExpander screenLocationExdr; - private final FlexibleStringExpander screenNameExdr; - private final String shareScope; - private final List subNodeList; - private final FlexibleStringExpander wrapStyleExdr; - - public ModelNode(Element nodeElement, ModelTree modelTree) { - super(nodeElement); - this.modelTree = modelTree; - this.expandCollapseStyle = nodeElement.getAttribute("expand-collapse-style"); - this.wrapStyleExdr = FlexibleStringExpander.getInstance(nodeElement.getAttribute("wrap-style")); - this.renderStyle = nodeElement.getAttribute("render-style"); - this.entryName = nodeElement.getAttribute("entry-name"); - this.entityName = nodeElement.getAttribute("entity-name"); - this.pkName = nodeElement.getAttribute("join-field-name"); - ArrayList actions = new ArrayList(); - // FIXME: Validate child elements, should be only one of actions, entity-one, service, script. - Element actionsElement = UtilXml.firstChildElement(nodeElement, "actions"); - if (actionsElement != null) { - actions.addAll(ModelTreeAction.readNodeActions(this, actionsElement)); - } - Element actionElement = UtilXml.firstChildElement(nodeElement, "entity-one"); - if (actionElement != null) { - actions.add(new AbstractModelAction.EntityOne(this, actionElement)); - } - actionElement = UtilXml.firstChildElement(nodeElement, "service"); - if (actionElement != null) { - actions.add(new ModelTreeAction.Service(this, actionElement)); - } - actionElement = UtilXml.firstChildElement(nodeElement, "script"); - if (actionElement != null) { - actions.add(new ModelTreeAction.Script(this, actionElement)); - } - actions.trimToSize(); - this.actions = Collections.unmodifiableList(actions); - Element screenElement = UtilXml.firstChildElement(nodeElement, "include-screen"); - if (screenElement != null) { - this.screenNameExdr = FlexibleStringExpander.getInstance(screenElement.getAttribute("name")); - this.screenLocationExdr = FlexibleStringExpander.getInstance(screenElement.getAttribute("location")); - this.shareScope = screenElement.getAttribute("share-scope"); - } else { - this.screenNameExdr = FlexibleStringExpander.getInstance(""); - this.screenLocationExdr = FlexibleStringExpander.getInstance(""); - this.shareScope = ""; - } - Element labelElement = UtilXml.firstChildElement(nodeElement, "label"); - if (labelElement != null) { - this.label = new Label(labelElement); - } else { - this.label = null; - } - Element linkElement = UtilXml.firstChildElement(nodeElement, "link"); - if (linkElement != null) { - this.link = new Link(linkElement); - } else { - this.link = null; - } - Element conditionElement = UtilXml.firstChildElement(nodeElement, "condition"); - if (conditionElement != null) { - this.condition = new ModelTreeCondition(modelTree, conditionElement); - } else { - this.condition = null; - } - List nodeElements = UtilXml.childElementList(nodeElement, "sub-node"); - if (!nodeElements.isEmpty()) { - List subNodeList = new ArrayList(); - for (Element subNodeElementEntry : nodeElements) { - ModelSubNode subNode = new ModelSubNode(subNodeElementEntry, this); - subNodeList.add(subNode); - } - this.subNodeList = Collections.unmodifiableList(subNodeList); - } else { - this.subNodeList = Collections.emptyList(); - } - } - - @Override - public void accept(ModelWidgetVisitor visitor) throws Exception { - visitor.visit(this); - } - - private List getChildren(Map context) { - List subNodeValues = new ArrayList(); - for (ModelSubNode subNode : subNodeList) { - String nodeName = subNode.getNodeName(context); - ModelNode node = modelTree.nodeMap.get(nodeName); - List subNodeActions = subNode.getActions(); - //if (Debug.infoOn()) Debug.logInfo(" context.currentValue:" + context.get("currentValue"), module); - AbstractModelAction.runSubActions(subNodeActions, context); - // List dataFound = (List)context.get("dataFound"); - Iterator> dataIter = subNode.getListIterator(context); - if (dataIter instanceof EntityListIterator) { - EntityListIterator eli = (EntityListIterator) dataIter; - Map val = null; - while ((val = eli.next()) != null) { - Object[] arr = { node, val }; - subNodeValues.add(arr); - } - try { - eli.close(); - } catch (GenericEntityException e) { - Debug.logError(e, module); - throw new RuntimeException(e.getMessage()); - } - } else if (dataIter != null) { - while (dataIter.hasNext()) { - Map val = dataIter.next(); - Object[] arr = { node, val }; - subNodeValues.add(arr); - } - } - } - return subNodeValues; - } - - public String getEntityName() { - if (!this.entityName.isEmpty()) { - return this.entityName; - } else { - return this.modelTree.getDefaultEntityName(); - } - } - - public String getEntryName() { - return this.entryName; - } - - public String getExpandCollapseStyle() { - return expandCollapseStyle; - } - - public ModelTree getModelTree() { - return this.modelTree; - } - - public String getPkName(Map context) { - if (UtilValidate.isNotEmpty(this.pkName)) { - return this.pkName; - } else { - return this.modelTree.getDefaultPkName(context); - } - } - - public String getRenderStyle() { - if (this.renderStyle.isEmpty()) - return modelTree.getRenderStyle(); - return this.renderStyle; - } - - public String getWrapStyle(Map context) { - String val = this.wrapStyleExdr.expandString(context); - if (val.isEmpty()) { - val = this.modelTree.getWrapStyle(context); - } - return val; - } - - public boolean hasChildren(Map context) { - List subNodeValues = getChildren(context); - boolean hasChildren = false; - Long nodeCount = null; - String countFieldName = "childBranchCount"; - Object obj = null; - if (!this.entryName.isEmpty()) { - Map map = UtilGenerics.cast(context.get(this.entryName)); - if (map instanceof GenericValue) { - ModelEntity modelEntity = ((GenericValue) map).getModelEntity(); - if (modelEntity.isField(countFieldName)) { - obj = map.get(countFieldName); - } - } - } else { - obj = context.get(countFieldName); - } - if (obj != null) { - nodeCount = (Long) obj; - } - String entName = this.getEntityName(); - Delegator delegator = WidgetWorker.getDelegator(context); - ModelEntity modelEntity = delegator.getModelEntity(entName); - ModelField modelField = null; - if (modelEntity.isField(countFieldName)) { - modelField = modelEntity.getField(countFieldName); - } - if (nodeCount == null && modelField != null || this.modelTree.forceChildCheck) { - getChildren(context); - /* - String id = (String)context.get(modelTree.getPkName()); - if (UtilValidate.isNotEmpty(id)) { - try { - int leafCount = ContentManagementWorker.updateStatsTopDown(delegator, id, UtilMisc.toList("SUB_CONTENT", "PUBLISH_LINK")); - GenericValue entity = delegator.findOne(entName, UtilMisc.toMap(modelTree.getPkName(), id), true); - obj = entity.get("childBranchCount"); - if (obj != null) - nodeCount = (Long)obj; - } catch (GenericEntityException e) { - Debug.logError(e, module); - throw new RuntimeException(e.getMessage()); - } - } - */ - nodeCount = Long.valueOf(subNodeValues.size()); - String pkName = this.getPkName(context); - String id = null; - if (!this.entryName.isEmpty()) { - id = UtilGenerics.> cast(context.get(this.entryName)).get(pkName); - } else { - id = (String) context.get(pkName); - } - try { - if (id != null && modelEntity.getPksSize() == 1) { - GenericValue entity = EntityQuery.use(delegator).from(entName).where(pkName, id).queryOne(); - if (modelEntity.isField("childBranchCount")) { - entity.put("childBranchCount", nodeCount); - entity.store(); - } - } - } catch (GenericEntityException e) { - Debug.logError(e, module); - throw new RuntimeException(e.getMessage()); - } - } else if (nodeCount == null) { - getChildren(context); - if (subNodeValues != null) { - nodeCount = Long.valueOf(subNodeValues.size()); - } - } - if (nodeCount != null && nodeCount.intValue() > 0) { - hasChildren = true; - } - return hasChildren; - } - - public boolean isExpandCollapse() { - boolean isExpCollapse = false; - String rStyle = getRenderStyle(); - if (rStyle != null && rStyle.equals("expand-collapse")) - isExpCollapse = true; - return isExpCollapse; - } - - public boolean isFollowTrail() { - boolean isFollowTrail = false; - String rStyle = getRenderStyle(); - if (rStyle != null && (rStyle.equals("follow-trail") || rStyle.equals("show-peers") || rStyle.equals("follow-trail"))) { - isFollowTrail = true; - } - return isFollowTrail; - } - - public boolean isRootNode() { - return getName().equals(modelTree.getRootNodeName()); - } - - public void renderNodeString(Appendable writer, Map context, TreeStringRenderer treeStringRenderer, - int depth) throws IOException, GeneralException { - boolean passed = true; - if (this.condition != null) { - if (!this.condition.getCondition().eval(context)) { - passed = false; - } - } - //Debug.logInfo("in ModelMenu, name:" + this.getName(), module); - if (passed) { - List currentNodeTrail = UtilGenerics.toList(context.get("currentNodeTrail")); - context.put("processChildren", Boolean.TRUE); - // this action will usually obtain the "current" entity - ModelTreeAction.runSubActions(this.actions, context); - String pkName = getPkName(context); - String id = null; - if (!this.entryName.isEmpty()) { - id = UtilGenerics.> cast(context.get(this.entryName)).get(pkName); - } else { - id = (String) context.get(pkName); - } - currentNodeTrail.add(id); - treeStringRenderer.renderNodeBegin(writer, context, this, depth); - //if (Debug.infoOn()) Debug.logInfo(" context:" + - // context.entrySet(), module); - try { - String screenName = null; - if (!screenNameExdr.isEmpty()) - screenName = screenNameExdr.expandString(context); - String screenLocation = null; - if (!screenLocationExdr.isEmpty()) - screenLocation = screenLocationExdr.expandString(context); - if (screenName != null && screenLocation != null) { - ScreenStringRenderer screenStringRenderer = treeStringRenderer.getScreenStringRenderer(context); - ModelScreen modelScreen = ScreenFactory.getScreenFromLocation(screenLocation, screenName); - modelScreen.renderScreenString(writer, context, screenStringRenderer); - } - if (label != null) { - label.renderLabelString(writer, context, treeStringRenderer); - } - if (link != null) { - link.renderLinkString(writer, context, treeStringRenderer); - } - treeStringRenderer.renderLastElement(writer, context, this); - Boolean processChildren = (Boolean) context.get("processChildren"); - //if (Debug.infoOn()) Debug.logInfo(" processChildren:" + processChildren, module); - if (processChildren.booleanValue()) { - List subNodeValues = getChildren(context); - int newDepth = depth + 1; - for (Object[] arr : subNodeValues) { - ModelNode node = (ModelNode) arr[0]; - Map val = UtilGenerics.checkMap(arr[1]); - //GenericPK pk = val.getPrimaryKey(); - //if (Debug.infoOn()) Debug.logInfo(" pk:" + pk, - // module); - String thisPkName = node.getPkName(context); - String thisEntityId = (String) val.get(thisPkName); - MapStack newContext = MapStack.create(context); - newContext.push(); - String nodeEntryName = node.getEntryName(); - if (!nodeEntryName.isEmpty()) { - newContext.put(nodeEntryName, val); - } else { - newContext.putAll(val); - } - String targetEntityId = null; - List targetNodeTrail = UtilGenerics.checkList(context.get("targetNodeTrail")); - if (newDepth < targetNodeTrail.size()) { - targetEntityId = targetNodeTrail.get(newDepth); - } - if ((targetEntityId != null && targetEntityId.equals(thisEntityId)) - || this.showPeers(newDepth, context)) { - node.renderNodeString(writer, newContext, treeStringRenderer, newDepth); - } - } - } - } catch (ScreenRenderException e) { - String errMsg = "Error rendering included label with name [" + getName() + "] : " + e.toString(); - Debug.logError(e, errMsg, module); - throw new RuntimeException(errMsg); - } catch (SAXException e) { - String errMsg = "Error rendering included label with name [" + getName() + "] : " + e.toString(); - Debug.logError(e, errMsg, module); - throw new RuntimeException(errMsg); - } catch (ParserConfigurationException e3) { - String errMsg = "Error rendering included label with name [" + getName() + "] : " + e3.toString(); - Debug.logError(e3, errMsg, module); - throw new RuntimeException(errMsg); - } catch (IOException e2) { - String errMsg = "Error rendering included label with name [" + getName() + "] : " + e2.toString(); - Debug.logError(e2, errMsg, module); - throw new RuntimeException(errMsg); - } - treeStringRenderer.renderNodeEnd(writer, context, this); - int removeIdx = currentNodeTrail.size() - 1; - if (removeIdx >= 0) - currentNodeTrail.remove(removeIdx); - } - } - - public boolean showPeers(int currentDepth, Map context) { - int trailSize = 0; - List trail = UtilGenerics.checkList(context.get("targetNodeTrail")); - int openDepth = modelTree.getOpenDepth(); - int postTrailOpenDepth = modelTree.getPostTrailOpenDepth(); - if (trail != null) - trailSize = trail.size(); - - boolean showPeers = false; - String rStyle = getRenderStyle(); - if (rStyle == null) { - showPeers = true; - } else if (!isFollowTrail()) { - showPeers = true; - } else if ((currentDepth < trailSize) && (rStyle != null) - && (rStyle.equals("show-peers") || rStyle.equals("expand-collapse"))) { - showPeers = true; - } else if (openDepth >= currentDepth) { - showPeers = true; - } else { - int depthAfterTrail = currentDepth - trailSize; - if (depthAfterTrail >= 0 && depthAfterTrail <= postTrailOpenDepth) - showPeers = true; - } - return showPeers; - } - - public List getActions() { - return actions; - } - - public ModelTreeCondition getCondition() { - return condition; - } - - public Label getLabel() { - return label; - } - - public Link getLink() { - return link; - } - - public String getPkName() { - return pkName; - } - - public FlexibleStringExpander getScreenLocationExdr() { - return screenLocationExdr; - } - - public FlexibleStringExpander getScreenNameExdr() { - return screenNameExdr; - } - - public String getShareScope() { - return shareScope; - } - - public List getSubNodeList() { - return subNodeList; - } - - public FlexibleStringExpander getWrapStyleExdr() { - return wrapStyleExdr; - } - - /** - * Models the <image> element. - * - * @see widget-tree.xsd - */ - public static class Image { - - private final FlexibleStringExpander borderExdr; - private final FlexibleStringExpander heightExdr; - private final FlexibleStringExpander idExdr; - private final FlexibleStringExpander srcExdr; - private final FlexibleStringExpander styleExdr; - private final String urlMode; - private final FlexibleStringExpander widthExdr; - - public Image(Element imageElement) { - this.borderExdr = FlexibleStringExpander - .getInstance(UtilXml.checkEmpty(imageElement.getAttribute("border"), "0")); - this.heightExdr = FlexibleStringExpander.getInstance(imageElement.getAttribute("height")); - this.idExdr = FlexibleStringExpander.getInstance(imageElement.getAttribute("id")); - this.srcExdr = FlexibleStringExpander.getInstance(imageElement.getAttribute("src")); - this.styleExdr = FlexibleStringExpander.getInstance(imageElement.getAttribute("style")); - this.urlMode = UtilXml.checkEmpty(imageElement.getAttribute("url-mode"), "content"); - this.widthExdr = FlexibleStringExpander.getInstance(imageElement.getAttribute("width")); - } - - public String getBorder(Map context) { - return this.borderExdr.expandString(context); - } - - public String getHeight(Map context) { - return this.heightExdr.expandString(context); - } - - public String getId(Map context) { - return this.idExdr.expandString(context); - } - - public String getSrc(Map context) { - return this.srcExdr.expandString(context); - } - - public String getStyle(Map context) { - return this.styleExdr.expandString(context); - } - - public String getUrlMode() { - return this.urlMode; - } - - public String getWidth(Map context) { - return this.widthExdr.expandString(context); - } - - public void renderImageString(Appendable writer, Map context, TreeStringRenderer treeStringRenderer) { - try { - treeStringRenderer.renderImage(writer, context, this); - } catch (IOException e) { - String errMsg = "Error rendering image with id [" + getId(context) + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - throw new RuntimeException(errMsg); - } - } - } - - /** - * Models the <label> element. - * - * @see widget-tree.xsd - */ - public static final class Label { - private final FlexibleStringExpander idExdr; - private final FlexibleStringExpander styleExdr; - private final FlexibleStringExpander textExdr; - - public Label(Element labelElement) { - String textAttr = labelElement.getAttribute("text"); - String pcdata = UtilXml.checkEmpty(UtilXml.elementValue(labelElement), ""); - this.textExdr = FlexibleStringExpander.getInstance(textAttr + pcdata); - this.idExdr = FlexibleStringExpander.getInstance(labelElement.getAttribute("id")); - this.styleExdr = FlexibleStringExpander.getInstance(labelElement.getAttribute("style")); - } - - public String getId(Map context) { - return this.idExdr.expandString(context); - } - - public String getStyle(Map context) { - return this.styleExdr.expandString(context); - } - - public String getText(Map context) { - String text = this.textExdr.expandString(context); - // FIXME: Encoding should be done by the renderer, not by the model. - UtilCodec.SimpleEncoder simpleEncoder = (UtilCodec.SimpleEncoder) context.get("simpleEncoder"); - if (simpleEncoder != null) { - text = simpleEncoder.encode(text); - } - return text; - } - - public void renderLabelString(Appendable writer, Map context, TreeStringRenderer treeStringRenderer) { - try { - treeStringRenderer.renderLabel(writer, context, this); - } catch (IOException e) { - String errMsg = "Error rendering label with id [" + getId(context) + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - throw new RuntimeException(errMsg); - } - } - - public FlexibleStringExpander getIdExdr() { - return idExdr; - } - - public FlexibleStringExpander getStyleExdr() { - return styleExdr; - } - - public FlexibleStringExpander getTextExdr() { - return textExdr; - } - } - - /** - * Models the <link> element. - * - * @see widget-tree.xsd - */ - public static class Link { - private final boolean encode; - private final boolean fullPath; - private final FlexibleStringExpander idExdr; - private final Image image; - private final String linkType; - private final FlexibleStringExpander nameExdr; - private final List parameterList; - private final FlexibleStringExpander prefixExdr; - private final boolean secure; - private final FlexibleStringExpander styleExdr; - private final FlexibleStringExpander targetExdr; - private final FlexibleStringExpander targetWindowExdr; - private final FlexibleStringExpander textExdr; - private final FlexibleStringExpander titleExdr; - private final String urlMode; - - public Link(Element linkElement) { - this.encode = "true".equals(linkElement.getAttribute("encode")); - this.fullPath = "true".equals(linkElement.getAttribute("full-path")); - this.idExdr = FlexibleStringExpander.getInstance(linkElement.getAttribute("id")); - Element imageElement = UtilXml.firstChildElement(linkElement, "image"); - if (imageElement != null) { - this.image = new Image(imageElement); - } else { - this.image = null; - } - this.linkType = linkElement.getAttribute("link-type"); - this.nameExdr = FlexibleStringExpander.getInstance(linkElement.getAttribute("name")); - List parameterElementList = UtilXml.childElementList(linkElement, "parameter"); - if (!parameterElementList.isEmpty()) { - List parameterList = new ArrayList(parameterElementList.size()); - for (Element parameterElement : parameterElementList) { - parameterList.add(new Parameter(parameterElement)); - } - this.parameterList = Collections.unmodifiableList(parameterList); - } else { - this.parameterList = Collections.emptyList(); - } - this.prefixExdr = FlexibleStringExpander.getInstance(linkElement.getAttribute("prefix")); - this.secure = "true".equals(linkElement.getAttribute("secure")); - this.styleExdr = FlexibleStringExpander.getInstance(linkElement.getAttribute("style")); - this.targetExdr = FlexibleStringExpander.getInstance(linkElement.getAttribute("target")); - this.targetWindowExdr = FlexibleStringExpander.getInstance(linkElement.getAttribute("target-window")); - this.textExdr = FlexibleStringExpander.getInstance(linkElement.getAttribute("text")); - this.titleExdr = FlexibleStringExpander.getInstance(linkElement.getAttribute("title")); - this.urlMode = UtilXml.checkEmpty(linkElement.getAttribute("link-type"), "intra-app"); - } - - // FIXME: Using a widget model in this way is an ugly hack. - public Link(String style, String target, String text) { - this.encode = false; - this.fullPath = false; - this.idExdr = FlexibleStringExpander.getInstance(""); - this.image = null; - this.linkType = ""; - this.nameExdr = FlexibleStringExpander.getInstance(""); - this.parameterList = Collections.emptyList(); - this.prefixExdr = FlexibleStringExpander.getInstance(""); - this.secure = false; - this.styleExdr = FlexibleStringExpander.getInstance(style); - this.targetExdr = FlexibleStringExpander.getInstance(target); - this.targetWindowExdr = FlexibleStringExpander.getInstance(""); - this.textExdr = FlexibleStringExpander.getInstance(text); - this.titleExdr = FlexibleStringExpander.getInstance(""); - this.urlMode = "intra-app"; - } - - public boolean getEncode() { - return this.encode; - } - - public boolean getFullPath() { - return this.fullPath; - } - - public String getId(Map context) { - return this.idExdr.expandString(context); - } - - public Image getImage() { - return this.image; - } - - public String getLinkType() { - return this.linkType; - } - - public String getName(Map context) { - return this.nameExdr.expandString(context); - } - - public Map getParameterMap(Map context) { - Map fullParameterMap = new HashMap(); - /* leaving this here... may want to add it at some point like the hyperlink element: - Map addlParamMap = this.parametersMapAcsr.get(context); - if (addlParamMap != null) { - fullParameterMap.putAll(addlParamMap); - } - */ - for (CommonWidgetModels.Parameter parameter : this.parameterList) { - fullParameterMap.put(parameter.getName(), parameter.getValue(context)); - } - return fullParameterMap; - } - - public String getPrefix(Map context) { - return this.prefixExdr.expandString(context); - } - - public boolean getSecure() { - return this.secure; - } - - public String getStyle(Map context) { - return this.styleExdr.expandString(context); - } - - public String getTarget(Map context) { - UtilCodec.SimpleEncoder simpleEncoder = (UtilCodec.SimpleEncoder) context.get("simpleEncoder"); - if (simpleEncoder != null) { - return this.targetExdr.expandString(UtilCodec.HtmlEncodingMapWrapper.getHtmlEncodingMapWrapper(context, - simpleEncoder)); - } else { - return this.targetExdr.expandString(context); - } - } - - public String getTargetWindow(Map context) { - return this.targetWindowExdr.expandString(context); - } - - public String getText(Map context) { - String text = this.textExdr.expandString(context); - // FIXME: Encoding should be done by the renderer, not by the model. - UtilCodec.SimpleEncoder simpleEncoder = (UtilCodec.SimpleEncoder) context.get("simpleEncoder"); - if (simpleEncoder != null) { - text = simpleEncoder.encode(text); - } - return text; - } - - public String getTitle(Map context) { - String title = this.titleExdr.expandString(context); - // FIXME: Encoding should be done by the renderer, not by the model. - UtilCodec.SimpleEncoder simpleEncoder = (UtilCodec.SimpleEncoder) context.get("simpleEncoder"); - if (simpleEncoder != null) { - title = simpleEncoder.encode(title); - } - return title; - } - - public String getUrlMode() { - return this.urlMode; - } - - public void renderLinkString(Appendable writer, Map context, TreeStringRenderer treeStringRenderer) { - try { - treeStringRenderer.renderLink(writer, context, this); - } catch (IOException e) { - String errMsg = "Error rendering link with id [" + getId(context) + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - throw new RuntimeException(errMsg); - } - } - - public FlexibleStringExpander getIdExdr() { - return idExdr; - } - - public FlexibleStringExpander getNameExdr() { - return nameExdr; - } - - public List getParameterList() { - return parameterList; - } - - public FlexibleStringExpander getPrefixExdr() { - return prefixExdr; - } - - public FlexibleStringExpander getStyleExdr() { - return styleExdr; - } - - public FlexibleStringExpander getTargetExdr() { - return targetExdr; - } - - public FlexibleStringExpander getTargetWindowExdr() { - return targetWindowExdr; - } - - public FlexibleStringExpander getTextExdr() { - return textExdr; - } - - public FlexibleStringExpander getTitleExdr() { - return titleExdr; - } - } - - /** - * Models the <sub-node> element. - * - * @see widget-tree.xsd - */ - public static class ModelSubNode extends ModelWidget { - - private final List actions; - private final FlexibleStringExpander nodeNameExdr; - private final ModelNode rootNode; - private final String iteratorKey; - - public ModelSubNode(Element subNodeElement, ModelNode modelNode) { - super(subNodeElement); - this.rootNode = modelNode; - this.nodeNameExdr = FlexibleStringExpander.getInstance(subNodeElement.getAttribute("node-name")); - ArrayList actions = new ArrayList(); - // FIXME: Validate child elements, should be only one of actions, entity-and, entity-condition, service, script. - Element actionsElement = UtilXml.firstChildElement(subNodeElement, "actions"); - if (actionsElement != null) { - actions.addAll(ModelTreeAction.readSubNodeActions(this, actionsElement)); - } - Element actionElement = UtilXml.firstChildElement(subNodeElement, "entity-and"); - if (actionElement != null) { - actions.add(new ModelTreeAction.EntityAnd(this, actionElement)); - } - actionElement = UtilXml.firstChildElement(subNodeElement, "service"); - if (actionElement != null) { - actions.add(new ModelTreeAction.Service(this, actionElement)); - } - actionElement = UtilXml.firstChildElement(subNodeElement, "entity-condition"); - if (actionElement != null) { - actions.add(new ModelTreeAction.EntityCondition(this, actionElement)); - } - actionElement = UtilXml.firstChildElement(subNodeElement, "script"); - if (actionElement != null) { - actions.add(new ModelTreeAction.Script(this, actionElement)); - } - actions.trimToSize(); - this.actions = Collections.unmodifiableList(actions); - this.iteratorKey = this.rootNode.getName().concat(".").concat(this.nodeNameExdr.getOriginal()) - .concat(".ITERATOR"); - } - - @Override - public void accept(ModelWidgetVisitor visitor) throws Exception { - visitor.visit(this); - } - - public List getActions() { - return actions; - } - - @SuppressWarnings("unchecked") - public ListIterator> getListIterator(Map context) { - return (ListIterator>) context.get(this.iteratorKey); - } - - public ModelTree.ModelNode getNode() { - return this.rootNode; - } - - public String getNodeName(Map context) { - return this.nodeNameExdr.expandString(context); - } - - public FlexibleStringExpander getNodeNameExdr() { - return nodeNameExdr; - } - - public void setListIterator(ListIterator> iter, Map context) { - context.put(this.iteratorKey, iter); - } - } - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.model; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.ListIterator; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.xml.parsers.ParserConfigurationException; + +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.GeneralException; +import org.ofbiz.base.util.StringUtil; +import org.ofbiz.base.util.UtilCodec; +import org.ofbiz.base.util.UtilGenerics; +import org.ofbiz.base.util.UtilHttp; +import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.base.util.UtilXml; +import org.ofbiz.base.util.collections.MapStack; +import org.ofbiz.base.util.string.FlexibleStringExpander; +import org.ofbiz.entity.Delegator; +import org.ofbiz.entity.GenericEntityException; +import org.ofbiz.entity.GenericValue; +import org.ofbiz.entity.model.ModelEntity; +import org.ofbiz.entity.model.ModelField; +import org.ofbiz.entity.util.EntityListIterator; +import org.ofbiz.entity.util.EntityQuery; +import org.ofbiz.widget.WidgetWorker; +import org.ofbiz.widget.model.CommonWidgetModels.Parameter; +import org.ofbiz.widget.renderer.ScreenRenderException; +import org.ofbiz.widget.renderer.ScreenStringRenderer; +import org.ofbiz.widget.renderer.TreeStringRenderer; +import org.w3c.dom.Element; +import org.xml.sax.SAXException; + +/** + * Models the <tree> element. + * + * @see widget-tree.xsd + */ +@SuppressWarnings("serial") +public class ModelTree extends ModelWidget { + + /* + * ----------------------------------------------------------------------- * + * DEVELOPERS PLEASE READ + * ----------------------------------------------------------------------- * + * + * This model is intended to be a read-only data structure that represents + * an XML element. Outside of object construction, the class should not + * have any behaviors. + * + * Instances of this class will be shared by multiple threads - therefore + * it is immutable. DO NOT CHANGE THE OBJECT'S STATE AT RUN TIME! + * + */ + + public static final String module = ModelTree.class.getName(); + + private final String defaultEntityName; + private final String defaultRenderStyle; + private final FlexibleStringExpander defaultWrapStyleExdr; + private final FlexibleStringExpander expandCollapseRequestExdr; + private final boolean forceChildCheck; + private final String location; + private final Map nodeMap; + private final int openDepth; + private final int postTrailOpenDepth; + private final String rootNodeName; + private final FlexibleStringExpander trailNameExdr; + + public ModelTree(Element treeElement, String location) { + super(treeElement); + this.location = location; + this.rootNodeName = treeElement.getAttribute("root-node-name"); + String defaultRenderStyle = UtilXml.checkEmpty(treeElement.getAttribute("default-render-style"), "simple"); + // A temporary hack to accommodate those who might still be using "render-style" instead of "default-render-style" + if (defaultRenderStyle.isEmpty() || defaultRenderStyle.equals("simple")) { + String rStyle = treeElement.getAttribute("render-style"); + if (!rStyle.isEmpty()) + defaultRenderStyle = rStyle; + } + this.defaultRenderStyle = defaultRenderStyle; + this.defaultWrapStyleExdr = FlexibleStringExpander.getInstance(treeElement.getAttribute("default-wrap-style")); + this.expandCollapseRequestExdr = FlexibleStringExpander.getInstance(treeElement.getAttribute("expand-collapse-request")); + this.trailNameExdr = FlexibleStringExpander.getInstance(UtilXml.checkEmpty(treeElement.getAttribute("trail-name"), + "trail")); + this.forceChildCheck = !"false".equals(treeElement.getAttribute("force-child-check")); + this.defaultEntityName = treeElement.getAttribute("entity-name"); + int openDepth = 0; + if (treeElement.hasAttribute("open-depth")) { + try { + openDepth = Integer.parseInt(treeElement.getAttribute("open-depth")); + } catch (NumberFormatException e) { + throw new IllegalArgumentException("Invalid open-depth attribute value for the tree definition with name: " + + getName()); + } + } + this.openDepth = openDepth; + int postTrailOpenDepth = 999; + if (treeElement.hasAttribute("post-trail-open-depth")) { + try { + postTrailOpenDepth = Integer.parseInt(treeElement.getAttribute("post-trail-open-depth")); + } catch (NumberFormatException e) { + throw new IllegalArgumentException( + "Invalid post-trail-open-depth attribute value for the tree definition with name: " + getName()); + } + } + this.postTrailOpenDepth = postTrailOpenDepth; + List nodeElements = UtilXml.childElementList(treeElement, "node"); + if (nodeElements.size() == 0) { + throw new IllegalArgumentException("No node elements found for the tree definition with name: " + getName()); + } + Map nodeMap = new HashMap(); + for (Element nodeElementEntry : UtilXml.childElementList(treeElement, "node")) { + ModelNode node = new ModelNode(nodeElementEntry, this); + String nodeName = node.getName(); + nodeMap.put(nodeName, node); + } + this.nodeMap = Collections.unmodifiableMap(nodeMap); + } + + @Override + public void accept(ModelWidgetVisitor visitor) throws Exception { + visitor.visit(this); + } + + @Override + public String getBoundaryCommentName() { + return location + "#" + getName(); + } + + public String getDefaultEntityName() { + return this.defaultEntityName; + } + + public String getDefaultPkName(Map context) { + ModelEntity modelEntity = WidgetWorker.getDelegator(context).getModelEntity(this.defaultEntityName); + if (modelEntity.getPksSize() == 1) { + ModelField modelField = modelEntity.getOnlyPk(); + return modelField.getName(); + } + return null; + } + + public String getExpandCollapseRequest(Map context) { + String expColReq = this.expandCollapseRequestExdr.expandString(context); + if (UtilValidate.isEmpty(expColReq)) { + HttpServletRequest request = (HttpServletRequest) context.get("request"); + String s1 = request.getRequestURI(); + int pos = s1.lastIndexOf("/"); + if (pos >= 0) + expColReq = s1.substring(pos + 1); + else + expColReq = s1; + } + //append also the request parameters + Map paramMap = UtilGenerics.checkMap(context.get("requestParameters")); + if (UtilValidate.isNotEmpty(paramMap)) { + Map requestParameters = new HashMap(paramMap); + requestParameters.remove(this.getTrailName(context)); + if (UtilValidate.isNotEmpty(requestParameters)) { + String queryString = UtilHttp.urlEncodeArgs(requestParameters, false); + if (expColReq.indexOf("?") < 0) { + expColReq += "?"; + } else { + expColReq += "&"; + } + expColReq += queryString; + } + } + return expColReq; + } + + public int getOpenDepth() { + return openDepth; + } + + public int getPostTrailOpenDepth() { + return postTrailOpenDepth; + } + + public String getRenderStyle() { + return this.defaultRenderStyle; + } + + public String getRootNodeName() { + return rootNodeName; + } + + public String getTrailName(Map context) { + return this.trailNameExdr.expandString(context); + } + + public String getWrapStyle(Map context) { + return this.defaultWrapStyleExdr.expandString(context); + } + + /** + * Renders this model. + * + * @param writer + * @param context + * @param treeStringRenderer + */ + @SuppressWarnings("rawtypes") + public void renderTreeString(Appendable writer, Map context, TreeStringRenderer treeStringRenderer) + throws GeneralException { + Map parameters = UtilGenerics.checkMap(context.get("parameters")); + ModelNode node = nodeMap.get(rootNodeName); + String trailName = trailNameExdr.expandString(context); + String treeString = (String) context.get(trailName); + if (UtilValidate.isEmpty(treeString)) { + treeString = (String) parameters.get(trailName); + } + List trail = null; + if (UtilValidate.isNotEmpty(treeString)) { + trail = StringUtil.split(treeString, "|"); + if (UtilValidate.isEmpty(trail)) + throw new RuntimeException("Tree 'trail' value is empty."); + context.put("rootEntityId", trail.get(0)); + context.put(getDefaultPkName(context), trail.get(0)); + } else { + trail = new LinkedList(); + } + context.put("targetNodeTrail", trail); + context.put("currentNodeTrail", new LinkedList()); + try { + node.renderNodeString(writer, context, treeStringRenderer, 0); + } catch (IOException e2) { + String errMsg = "Error rendering included label with name [" + getName() + "] : " + e2.toString(); + Debug.logError(e2, errMsg, module); + throw new RuntimeException(errMsg); + } + + } + + public String getDefaultRenderStyle() { + return defaultRenderStyle; + } + + public FlexibleStringExpander getDefaultWrapStyleExdr() { + return defaultWrapStyleExdr; + } + + public FlexibleStringExpander getExpandCollapseRequestExdr() { + return expandCollapseRequestExdr; + } + + public boolean getForceChildCheck() { + return forceChildCheck; + } + + public String getLocation() { + return location; + } + + public Map getNodeMap() { + return nodeMap; + } + + public FlexibleStringExpander getTrailNameExdr() { + return trailNameExdr; + } + + /** + * Models the <node> element. + * + * @see widget-tree.xsd + */ + public static class ModelNode extends ModelWidget { + + private final List actions; + // TODO: Make this a generic condition object. + private final ModelTreeCondition condition; + private final String entityName; + private final String entryName; + private final String expandCollapseStyle; + private final Label label; + private final Link link; + private final ModelTree modelTree; + private final String pkName; + private final String renderStyle; + private final FlexibleStringExpander screenLocationExdr; + private final FlexibleStringExpander screenNameExdr; + private final String shareScope; + private final List subNodeList; + private final FlexibleStringExpander wrapStyleExdr; + + public ModelNode(Element nodeElement, ModelTree modelTree) { + super(nodeElement); + this.modelTree = modelTree; + this.expandCollapseStyle = nodeElement.getAttribute("expand-collapse-style"); + this.wrapStyleExdr = FlexibleStringExpander.getInstance(nodeElement.getAttribute("wrap-style")); + this.renderStyle = nodeElement.getAttribute("render-style"); + this.entryName = nodeElement.getAttribute("entry-name"); + this.entityName = nodeElement.getAttribute("entity-name"); + this.pkName = nodeElement.getAttribute("join-field-name"); + ArrayList actions = new ArrayList(); + // FIXME: Validate child elements, should be only one of actions, entity-one, service, script. + Element actionsElement = UtilXml.firstChildElement(nodeElement, "actions"); + if (actionsElement != null) { + actions.addAll(ModelTreeAction.readNodeActions(this, actionsElement)); + } + Element actionElement = UtilXml.firstChildElement(nodeElement, "entity-one"); + if (actionElement != null) { + actions.add(new AbstractModelAction.EntityOne(this, actionElement)); + } + actionElement = UtilXml.firstChildElement(nodeElement, "service"); + if (actionElement != null) { + actions.add(new ModelTreeAction.Service(this, actionElement)); + } + actionElement = UtilXml.firstChildElement(nodeElement, "script"); + if (actionElement != null) { + actions.add(new ModelTreeAction.Script(this, actionElement)); + } + actions.trimToSize(); + this.actions = Collections.unmodifiableList(actions); + Element screenElement = UtilXml.firstChildElement(nodeElement, "include-screen"); + if (screenElement != null) { + this.screenNameExdr = FlexibleStringExpander.getInstance(screenElement.getAttribute("name")); + this.screenLocationExdr = FlexibleStringExpander.getInstance(screenElement.getAttribute("location")); + this.shareScope = screenElement.getAttribute("share-scope"); + } else { + this.screenNameExdr = FlexibleStringExpander.getInstance(""); + this.screenLocationExdr = FlexibleStringExpander.getInstance(""); + this.shareScope = ""; + } + Element labelElement = UtilXml.firstChildElement(nodeElement, "label"); + if (labelElement != null) { + this.label = new Label(labelElement); + } else { + this.label = null; + } + Element linkElement = UtilXml.firstChildElement(nodeElement, "link"); + if (linkElement != null) { + this.link = new Link(linkElement); + } else { + this.link = null; + } + Element conditionElement = UtilXml.firstChildElement(nodeElement, "condition"); + if (conditionElement != null) { + this.condition = new ModelTreeCondition(modelTree, conditionElement); + } else { + this.condition = null; + } + List nodeElements = UtilXml.childElementList(nodeElement, "sub-node"); + if (!nodeElements.isEmpty()) { + List subNodeList = new ArrayList(); + for (Element subNodeElementEntry : nodeElements) { + ModelSubNode subNode = new ModelSubNode(subNodeElementEntry, this); + subNodeList.add(subNode); + } + this.subNodeList = Collections.unmodifiableList(subNodeList); + } else { + this.subNodeList = Collections.emptyList(); + } + } + + @Override + public void accept(ModelWidgetVisitor visitor) throws Exception { + visitor.visit(this); + } + + private List getChildren(Map context) { + List subNodeValues = new ArrayList(); + for (ModelSubNode subNode : subNodeList) { + String nodeName = subNode.getNodeName(context); + ModelNode node = modelTree.nodeMap.get(nodeName); + List subNodeActions = subNode.getActions(); + //if (Debug.infoOn()) Debug.logInfo(" context.currentValue:" + context.get("currentValue"), module); + AbstractModelAction.runSubActions(subNodeActions, context); + // List dataFound = (List)context.get("dataFound"); + Iterator> dataIter = subNode.getListIterator(context); + if (dataIter instanceof EntityListIterator) { + EntityListIterator eli = (EntityListIterator) dataIter; + Map val = null; + while ((val = eli.next()) != null) { + Object[] arr = { node, val }; + subNodeValues.add(arr); + } + try { + eli.close(); + } catch (GenericEntityException e) { + Debug.logError(e, module); + throw new RuntimeException(e.getMessage()); + } + } else if (dataIter != null) { + while (dataIter.hasNext()) { + Map val = dataIter.next(); + Object[] arr = { node, val }; + subNodeValues.add(arr); + } + } + } + return subNodeValues; + } + + public String getEntityName() { + if (!this.entityName.isEmpty()) { + return this.entityName; + } else { + return this.modelTree.getDefaultEntityName(); + } + } + + public String getEntryName() { + return this.entryName; + } + + public String getExpandCollapseStyle() { + return expandCollapseStyle; + } + + public ModelTree getModelTree() { + return this.modelTree; + } + + public String getPkName(Map context) { + if (UtilValidate.isNotEmpty(this.pkName)) { + return this.pkName; + } else { + return this.modelTree.getDefaultPkName(context); + } + } + + public String getRenderStyle() { + if (this.renderStyle.isEmpty()) + return modelTree.getRenderStyle(); + return this.renderStyle; + } + + public String getWrapStyle(Map context) { + String val = this.wrapStyleExdr.expandString(context); + if (val.isEmpty()) { + val = this.modelTree.getWrapStyle(context); + } + return val; + } + + public boolean hasChildren(Map context) { + List subNodeValues = getChildren(context); + boolean hasChildren = false; + Long nodeCount = null; + String countFieldName = "childBranchCount"; + Object obj = null; + if (!this.entryName.isEmpty()) { + Map map = UtilGenerics.cast(context.get(this.entryName)); + if (map instanceof GenericValue) { + ModelEntity modelEntity = ((GenericValue) map).getModelEntity(); + if (modelEntity.isField(countFieldName)) { + obj = map.get(countFieldName); + } + } + } else { + obj = context.get(countFieldName); + } + if (obj != null) { + nodeCount = (Long) obj; + } + String entName = this.getEntityName(); + Delegator delegator = WidgetWorker.getDelegator(context); + ModelEntity modelEntity = delegator.getModelEntity(entName); + ModelField modelField = null; + if (modelEntity.isField(countFieldName)) { + modelField = modelEntity.getField(countFieldName); + } + if (nodeCount == null && modelField != null || this.modelTree.forceChildCheck) { + getChildren(context); + /* + String id = (String)context.get(modelTree.getPkName()); + if (UtilValidate.isNotEmpty(id)) { + try { + int leafCount = ContentManagementWorker.updateStatsTopDown(delegator, id, UtilMisc.toList("SUB_CONTENT", "PUBLISH_LINK")); + GenericValue entity = delegator.findOne(entName, UtilMisc.toMap(modelTree.getPkName(), id), true); + obj = entity.get("childBranchCount"); + if (obj != null) + nodeCount = (Long)obj; + } catch (GenericEntityException e) { + Debug.logError(e, module); + throw new RuntimeException(e.getMessage()); + } + } + */ + nodeCount = Long.valueOf(subNodeValues.size()); + String pkName = this.getPkName(context); + String id = null; + if (!this.entryName.isEmpty()) { + id = UtilGenerics.> cast(context.get(this.entryName)).get(pkName); + } else { + id = (String) context.get(pkName); + } + try { + if (id != null && modelEntity.getPksSize() == 1) { + GenericValue entity = EntityQuery.use(delegator).from(entName).where(pkName, id).queryOne(); + if (modelEntity.isField("childBranchCount")) { + entity.put("childBranchCount", nodeCount); + entity.store(); + } + } + } catch (GenericEntityException e) { + Debug.logError(e, module); + throw new RuntimeException(e.getMessage()); + } + } else if (nodeCount == null) { + getChildren(context); + if (subNodeValues != null) { + nodeCount = Long.valueOf(subNodeValues.size()); + } + } + if (nodeCount != null && nodeCount.intValue() > 0) { + hasChildren = true; + } + return hasChildren; + } + + public boolean isExpandCollapse() { + boolean isExpCollapse = false; + String rStyle = getRenderStyle(); + if (rStyle != null && rStyle.equals("expand-collapse")) + isExpCollapse = true; + return isExpCollapse; + } + + public boolean isFollowTrail() { + boolean isFollowTrail = false; + String rStyle = getRenderStyle(); + if (rStyle != null && (rStyle.equals("follow-trail") || rStyle.equals("show-peers") || rStyle.equals("follow-trail"))) { + isFollowTrail = true; + } + return isFollowTrail; + } + + public boolean isRootNode() { + return getName().equals(modelTree.getRootNodeName()); + } + + public void renderNodeString(Appendable writer, Map context, TreeStringRenderer treeStringRenderer, + int depth) throws IOException, GeneralException { + boolean passed = true; + if (this.condition != null) { + if (!this.condition.getCondition().eval(context)) { + passed = false; + } + } + //Debug.logInfo("in ModelMenu, name:" + this.getName(), module); + if (passed) { + List currentNodeTrail = UtilGenerics.toList(context.get("currentNodeTrail")); + context.put("processChildren", Boolean.TRUE); + // this action will usually obtain the "current" entity + ModelTreeAction.runSubActions(this.actions, context); + String pkName = getPkName(context); + String id = null; + if (!this.entryName.isEmpty()) { + id = UtilGenerics.> cast(context.get(this.entryName)).get(pkName); + } else { + id = (String) context.get(pkName); + } + currentNodeTrail.add(id); + treeStringRenderer.renderNodeBegin(writer, context, this, depth); + //if (Debug.infoOn()) Debug.logInfo(" context:" + + // context.entrySet(), module); + try { + String screenName = null; + if (!screenNameExdr.isEmpty()) + screenName = screenNameExdr.expandString(context); + String screenLocation = null; + if (!screenLocationExdr.isEmpty()) + screenLocation = screenLocationExdr.expandString(context); + if (screenName != null && screenLocation != null) { + ScreenStringRenderer screenStringRenderer = treeStringRenderer.getScreenStringRenderer(context); + ModelScreen modelScreen = ScreenFactory.getScreenFromLocation(screenLocation, screenName); + modelScreen.renderScreenString(writer, context, screenStringRenderer); + } + if (label != null) { + label.renderLabelString(writer, context, treeStringRenderer); + } + if (link != null) { + link.renderLinkString(writer, context, treeStringRenderer); + } + treeStringRenderer.renderLastElement(writer, context, this); + Boolean processChildren = (Boolean) context.get("processChildren"); + //if (Debug.infoOn()) Debug.logInfo(" processChildren:" + processChildren, module); + if (processChildren.booleanValue()) { + List subNodeValues = getChildren(context); + int newDepth = depth + 1; + for (Object[] arr : subNodeValues) { + ModelNode node = (ModelNode) arr[0]; + Map val = UtilGenerics.checkMap(arr[1]); + //GenericPK pk = val.getPrimaryKey(); + //if (Debug.infoOn()) Debug.logInfo(" pk:" + pk, + // module); + String thisPkName = node.getPkName(context); + String thisEntityId = (String) val.get(thisPkName); + MapStack newContext = MapStack.create(context); + newContext.push(); + String nodeEntryName = node.getEntryName(); + if (!nodeEntryName.isEmpty()) { + newContext.put(nodeEntryName, val); + } else { + newContext.putAll(val); + } + String targetEntityId = null; + List targetNodeTrail = UtilGenerics.checkList(context.get("targetNodeTrail")); + if (newDepth < targetNodeTrail.size()) { + targetEntityId = targetNodeTrail.get(newDepth); + } + if ((targetEntityId != null && targetEntityId.equals(thisEntityId)) + || this.showPeers(newDepth, context)) { + node.renderNodeString(writer, newContext, treeStringRenderer, newDepth); + } + } + } + } catch (ScreenRenderException e) { + String errMsg = "Error rendering included label with name [" + getName() + "] : " + e.toString(); + Debug.logError(e, errMsg, module); + throw new RuntimeException(errMsg); + } catch (SAXException e) { + String errMsg = "Error rendering included label with name [" + getName() + "] : " + e.toString(); + Debug.logError(e, errMsg, module); + throw new RuntimeException(errMsg); + } catch (ParserConfigurationException e3) { + String errMsg = "Error rendering included label with name [" + getName() + "] : " + e3.toString(); + Debug.logError(e3, errMsg, module); + throw new RuntimeException(errMsg); + } catch (IOException e2) { + String errMsg = "Error rendering included label with name [" + getName() + "] : " + e2.toString(); + Debug.logError(e2, errMsg, module); + throw new RuntimeException(errMsg); + } + treeStringRenderer.renderNodeEnd(writer, context, this); + int removeIdx = currentNodeTrail.size() - 1; + if (removeIdx >= 0) + currentNodeTrail.remove(removeIdx); + } + } + + public boolean showPeers(int currentDepth, Map context) { + int trailSize = 0; + List trail = UtilGenerics.checkList(context.get("targetNodeTrail")); + int openDepth = modelTree.getOpenDepth(); + int postTrailOpenDepth = modelTree.getPostTrailOpenDepth(); + if (trail != null) + trailSize = trail.size(); + + boolean showPeers = false; + String rStyle = getRenderStyle(); + if (rStyle == null) { + showPeers = true; + } else if (!isFollowTrail()) { + showPeers = true; + } else if ((currentDepth < trailSize) && (rStyle != null) + && (rStyle.equals("show-peers") || rStyle.equals("expand-collapse"))) { + showPeers = true; + } else if (openDepth >= currentDepth) { + showPeers = true; + } else { + int depthAfterTrail = currentDepth - trailSize; + if (depthAfterTrail >= 0 && depthAfterTrail <= postTrailOpenDepth) + showPeers = true; + } + return showPeers; + } + + public List getActions() { + return actions; + } + + public ModelTreeCondition getCondition() { + return condition; + } + + public Label getLabel() { + return label; + } + + public Link getLink() { + return link; + } + + public String getPkName() { + return pkName; + } + + public FlexibleStringExpander getScreenLocationExdr() { + return screenLocationExdr; + } + + public FlexibleStringExpander getScreenNameExdr() { + return screenNameExdr; + } + + public String getShareScope() { + return shareScope; + } + + public List getSubNodeList() { + return subNodeList; + } + + public FlexibleStringExpander getWrapStyleExdr() { + return wrapStyleExdr; + } + + /** + * Models the <image> element. + * + * @see widget-tree.xsd + */ + public static class Image { + + private final FlexibleStringExpander borderExdr; + private final FlexibleStringExpander heightExdr; + private final FlexibleStringExpander idExdr; + private final FlexibleStringExpander srcExdr; + private final FlexibleStringExpander styleExdr; + private final String urlMode; + private final FlexibleStringExpander widthExdr; + + public Image(Element imageElement) { + this.borderExdr = FlexibleStringExpander + .getInstance(UtilXml.checkEmpty(imageElement.getAttribute("border"), "0")); + this.heightExdr = FlexibleStringExpander.getInstance(imageElement.getAttribute("height")); + this.idExdr = FlexibleStringExpander.getInstance(imageElement.getAttribute("id")); + this.srcExdr = FlexibleStringExpander.getInstance(imageElement.getAttribute("src")); + this.styleExdr = FlexibleStringExpander.getInstance(imageElement.getAttribute("style")); + this.urlMode = UtilXml.checkEmpty(imageElement.getAttribute("url-mode"), "content"); + this.widthExdr = FlexibleStringExpander.getInstance(imageElement.getAttribute("width")); + } + + public String getBorder(Map context) { + return this.borderExdr.expandString(context); + } + + public String getHeight(Map context) { + return this.heightExdr.expandString(context); + } + + public String getId(Map context) { + return this.idExdr.expandString(context); + } + + public String getSrc(Map context) { + return this.srcExdr.expandString(context); + } + + public String getStyle(Map context) { + return this.styleExdr.expandString(context); + } + + public String getUrlMode() { + return this.urlMode; + } + + public String getWidth(Map context) { + return this.widthExdr.expandString(context); + } + + public void renderImageString(Appendable writer, Map context, TreeStringRenderer treeStringRenderer) { + try { + treeStringRenderer.renderImage(writer, context, this); + } catch (IOException e) { + String errMsg = "Error rendering image with id [" + getId(context) + "]: " + e.toString(); + Debug.logError(e, errMsg, module); + throw new RuntimeException(errMsg); + } + } + } + + /** + * Models the <label> element. + * + * @see widget-tree.xsd + */ + public static final class Label { + private final FlexibleStringExpander idExdr; + private final FlexibleStringExpander styleExdr; + private final FlexibleStringExpander textExdr; + + public Label(Element labelElement) { + String textAttr = labelElement.getAttribute("text"); + String pcdata = UtilXml.checkEmpty(UtilXml.elementValue(labelElement), ""); + this.textExdr = FlexibleStringExpander.getInstance(textAttr + pcdata); + this.idExdr = FlexibleStringExpander.getInstance(labelElement.getAttribute("id")); + this.styleExdr = FlexibleStringExpander.getInstance(labelElement.getAttribute("style")); + } + + public String getId(Map context) { + return this.idExdr.expandString(context); + } + + public String getStyle(Map context) { + return this.styleExdr.expandString(context); + } + + public String getText(Map context) { + String text = this.textExdr.expandString(context); + // FIXME: Encoding should be done by the renderer, not by the model. + UtilCodec.SimpleEncoder simpleEncoder = (UtilCodec.SimpleEncoder) context.get("simpleEncoder"); + if (simpleEncoder != null) { + text = simpleEncoder.encode(text); + } + return text; + } + + public void renderLabelString(Appendable writer, Map context, TreeStringRenderer treeStringRenderer) { + try { + treeStringRenderer.renderLabel(writer, context, this); + } catch (IOException e) { + String errMsg = "Error rendering label with id [" + getId(context) + "]: " + e.toString(); + Debug.logError(e, errMsg, module); + throw new RuntimeException(errMsg); + } + } + + public FlexibleStringExpander getIdExdr() { + return idExdr; + } + + public FlexibleStringExpander getStyleExdr() { + return styleExdr; + } + + public FlexibleStringExpander getTextExdr() { + return textExdr; + } + } + + /** + * Models the <link> element. + * + * @see widget-tree.xsd + */ + public static class Link { + private final boolean encode; + private final boolean fullPath; + private final FlexibleStringExpander idExdr; + private final Image image; + private final String linkType; + private final FlexibleStringExpander nameExdr; + private final List parameterList; + private final FlexibleStringExpander prefixExdr; + private final boolean secure; + private final FlexibleStringExpander styleExdr; + private final FlexibleStringExpander targetExdr; + private final FlexibleStringExpander targetWindowExdr; + private final FlexibleStringExpander textExdr; + private final FlexibleStringExpander titleExdr; + private final String urlMode; + + public Link(Element linkElement) { + this.encode = "true".equals(linkElement.getAttribute("encode")); + this.fullPath = "true".equals(linkElement.getAttribute("full-path")); + this.idExdr = FlexibleStringExpander.getInstance(linkElement.getAttribute("id")); + Element imageElement = UtilXml.firstChildElement(linkElement, "image"); + if (imageElement != null) { + this.image = new Image(imageElement); + } else { + this.image = null; + } + this.linkType = linkElement.getAttribute("link-type"); + this.nameExdr = FlexibleStringExpander.getInstance(linkElement.getAttribute("name")); + List parameterElementList = UtilXml.childElementList(linkElement, "parameter"); + if (!parameterElementList.isEmpty()) { + List parameterList = new ArrayList(parameterElementList.size()); + for (Element parameterElement : parameterElementList) { + parameterList.add(new Parameter(parameterElement)); + } + this.parameterList = Collections.unmodifiableList(parameterList); + } else { + this.parameterList = Collections.emptyList(); + } + this.prefixExdr = FlexibleStringExpander.getInstance(linkElement.getAttribute("prefix")); + this.secure = "true".equals(linkElement.getAttribute("secure")); + this.styleExdr = FlexibleStringExpander.getInstance(linkElement.getAttribute("style")); + this.targetExdr = FlexibleStringExpander.getInstance(linkElement.getAttribute("target")); + this.targetWindowExdr = FlexibleStringExpander.getInstance(linkElement.getAttribute("target-window")); + this.textExdr = FlexibleStringExpander.getInstance(linkElement.getAttribute("text")); + this.titleExdr = FlexibleStringExpander.getInstance(linkElement.getAttribute("title")); + this.urlMode = UtilXml.checkEmpty(linkElement.getAttribute("link-type"), "intra-app"); + } + + // FIXME: Using a widget model in this way is an ugly hack. + public Link(String style, String target, String text) { + this.encode = false; + this.fullPath = false; + this.idExdr = FlexibleStringExpander.getInstance(""); + this.image = null; + this.linkType = ""; + this.nameExdr = FlexibleStringExpander.getInstance(""); + this.parameterList = Collections.emptyList(); + this.prefixExdr = FlexibleStringExpander.getInstance(""); + this.secure = false; + this.styleExdr = FlexibleStringExpander.getInstance(style); + this.targetExdr = FlexibleStringExpander.getInstance(target); + this.targetWindowExdr = FlexibleStringExpander.getInstance(""); + this.textExdr = FlexibleStringExpander.getInstance(text); + this.titleExdr = FlexibleStringExpander.getInstance(""); + this.urlMode = "intra-app"; + } + + public boolean getEncode() { + return this.encode; + } + + public boolean getFullPath() { + return this.fullPath; + } + + public String getId(Map context) { + return this.idExdr.expandString(context); + } + + public Image getImage() { + return this.image; + } + + public String getLinkType() { + return this.linkType; + } + + public String getName(Map context) { + return this.nameExdr.expandString(context); + } + + public Map getParameterMap(Map context) { + Map fullParameterMap = new HashMap(); + /* leaving this here... may want to add it at some point like the hyperlink element: + Map addlParamMap = this.parametersMapAcsr.get(context); + if (addlParamMap != null) { + fullParameterMap.putAll(addlParamMap); + } + */ + for (CommonWidgetModels.Parameter parameter : this.parameterList) { + fullParameterMap.put(parameter.getName(), parameter.getValue(context)); + } + return fullParameterMap; + } + + public String getPrefix(Map context) { + return this.prefixExdr.expandString(context); + } + + public boolean getSecure() { + return this.secure; + } + + public String getStyle(Map context) { + return this.styleExdr.expandString(context); + } + + public String getTarget(Map context) { + UtilCodec.SimpleEncoder simpleEncoder = (UtilCodec.SimpleEncoder) context.get("simpleEncoder"); + if (simpleEncoder != null) { + return this.targetExdr.expandString(UtilCodec.HtmlEncodingMapWrapper.getHtmlEncodingMapWrapper(context, + simpleEncoder)); + } else { + return this.targetExdr.expandString(context); + } + } + + public String getTargetWindow(Map context) { + return this.targetWindowExdr.expandString(context); + } + + public String getText(Map context) { + String text = this.textExdr.expandString(context); + // FIXME: Encoding should be done by the renderer, not by the model. + UtilCodec.SimpleEncoder simpleEncoder = (UtilCodec.SimpleEncoder) context.get("simpleEncoder"); + if (simpleEncoder != null) { + text = simpleEncoder.encode(text); + } + return text; + } + + public String getTitle(Map context) { + String title = this.titleExdr.expandString(context); + // FIXME: Encoding should be done by the renderer, not by the model. + UtilCodec.SimpleEncoder simpleEncoder = (UtilCodec.SimpleEncoder) context.get("simpleEncoder"); + if (simpleEncoder != null) { + title = simpleEncoder.encode(title); + } + return title; + } + + public String getUrlMode() { + return this.urlMode; + } + + public void renderLinkString(Appendable writer, Map context, TreeStringRenderer treeStringRenderer) { + try { + treeStringRenderer.renderLink(writer, context, this); + } catch (IOException e) { + String errMsg = "Error rendering link with id [" + getId(context) + "]: " + e.toString(); + Debug.logError(e, errMsg, module); + throw new RuntimeException(errMsg); + } + } + + public FlexibleStringExpander getIdExdr() { + return idExdr; + } + + public FlexibleStringExpander getNameExdr() { + return nameExdr; + } + + public List getParameterList() { + return parameterList; + } + + public FlexibleStringExpander getPrefixExdr() { + return prefixExdr; + } + + public FlexibleStringExpander getStyleExdr() { + return styleExdr; + } + + public FlexibleStringExpander getTargetExdr() { + return targetExdr; + } + + public FlexibleStringExpander getTargetWindowExdr() { + return targetWindowExdr; + } + + public FlexibleStringExpander getTextExdr() { + return textExdr; + } + + public FlexibleStringExpander getTitleExdr() { + return titleExdr; + } + } + + /** + * Models the <sub-node> element. + * + * @see widget-tree.xsd + */ + public static class ModelSubNode extends ModelWidget { + + private final List actions; + private final FlexibleStringExpander nodeNameExdr; + private final ModelNode rootNode; + private final String iteratorKey; + + public ModelSubNode(Element subNodeElement, ModelNode modelNode) { + super(subNodeElement); + this.rootNode = modelNode; + this.nodeNameExdr = FlexibleStringExpander.getInstance(subNodeElement.getAttribute("node-name")); + ArrayList actions = new ArrayList(); + // FIXME: Validate child elements, should be only one of actions, entity-and, entity-condition, service, script. + Element actionsElement = UtilXml.firstChildElement(subNodeElement, "actions"); + if (actionsElement != null) { + actions.addAll(ModelTreeAction.readSubNodeActions(this, actionsElement)); + } + Element actionElement = UtilXml.firstChildElement(subNodeElement, "entity-and"); + if (actionElement != null) { + actions.add(new ModelTreeAction.EntityAnd(this, actionElement)); + } + actionElement = UtilXml.firstChildElement(subNodeElement, "service"); + if (actionElement != null) { + actions.add(new ModelTreeAction.Service(this, actionElement)); + } + actionElement = UtilXml.firstChildElement(subNodeElement, "entity-condition"); + if (actionElement != null) { + actions.add(new ModelTreeAction.EntityCondition(this, actionElement)); + } + actionElement = UtilXml.firstChildElement(subNodeElement, "script"); + if (actionElement != null) { + actions.add(new ModelTreeAction.Script(this, actionElement)); + } + actions.trimToSize(); + this.actions = Collections.unmodifiableList(actions); + this.iteratorKey = this.rootNode.getName().concat(".").concat(this.nodeNameExdr.getOriginal()) + .concat(".ITERATOR"); + } + + @Override + public void accept(ModelWidgetVisitor visitor) throws Exception { + visitor.visit(this); + } + + public List getActions() { + return actions; + } + + @SuppressWarnings("unchecked") + public ListIterator> getListIterator(Map context) { + return (ListIterator>) context.get(this.iteratorKey); + } + + public ModelTree.ModelNode getNode() { + return this.rootNode; + } + + public String getNodeName(Map context) { + return this.nodeNameExdr.expandString(context); + } + + public FlexibleStringExpander getNodeNameExdr() { + return nodeNameExdr; + } + + public void setListIterator(ListIterator> iter, Map context) { + context.put(this.iteratorKey, iter); + } + } + } +} diff --git a/framework/widget/src/org/ofbiz/widget/tree/ModelTreeAction.java b/framework/widget/src/org/ofbiz/widget/model/ModelTreeAction.java similarity index 97% rename from framework/widget/src/org/ofbiz/widget/tree/ModelTreeAction.java rename to framework/widget/src/org/ofbiz/widget/model/ModelTreeAction.java index 3460b5b3e1..f9734c8c27 100644 --- a/framework/widget/src/org/ofbiz/widget/tree/ModelTreeAction.java +++ b/framework/widget/src/org/ofbiz/widget/model/ModelTreeAction.java @@ -1,463 +1,460 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget.tree; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.ListIterator; -import java.util.Map; -import java.util.regex.PatternSyntaxException; - -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.GeneralException; -import org.ofbiz.base.util.ScriptUtil; -import org.ofbiz.base.util.UtilFormatOut; -import org.ofbiz.base.util.UtilGenerics; -import org.ofbiz.base.util.UtilValidate; -import org.ofbiz.base.util.UtilXml; -import org.ofbiz.base.util.collections.FlexibleMapAccessor; -import org.ofbiz.base.util.string.FlexibleStringExpander; -import org.ofbiz.entity.finder.ByAndFinder; -import org.ofbiz.entity.finder.ByConditionFinder; -import org.ofbiz.entity.finder.EntityFinderUtil; -import org.ofbiz.entity.util.EntityListIterator; -import org.ofbiz.minilang.MiniLangException; -import org.ofbiz.minilang.SimpleMethod; -import org.ofbiz.minilang.method.MethodContext; -import org.ofbiz.service.DispatchContext; -import org.ofbiz.service.GenericServiceException; -import org.ofbiz.service.ModelService; -import org.ofbiz.widget.AbstractModelAction; -import org.ofbiz.widget.ModelAction; -import org.ofbiz.widget.ModelActionVisitor; -import org.ofbiz.widget.WidgetWorker; -import org.ofbiz.widget.tree.ModelTree.ModelNode; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -/** - * Abstract tree action. - */ -@SuppressWarnings("serial") -public abstract class ModelTreeAction extends AbstractModelAction { - - /* - * ----------------------------------------------------------------------- * - * DEVELOPERS PLEASE READ - * ----------------------------------------------------------------------- * - * - * This model is intended to be a read-only data structure that represents - * an XML element. Outside of object construction, the class should not - * have any behaviors. - * - * Instances of this class will be shared by multiple threads - therefore - * it is immutable. DO NOT CHANGE THE OBJECT'S STATE AT RUN TIME! - * - */ - - public static final String module = ModelTreeAction.class.getName(); - - public static List readNodeActions(ModelNode modelNode, Element actionsElement) { - List actionElementList = UtilXml.childElementList(actionsElement); - List actions = new ArrayList(actionElementList.size()); - for (Element actionElement : actionElementList) { - if ("service".equals(actionElement.getNodeName())) { - actions.add(new Service(modelNode, actionElement)); - } else if ("script".equals(actionElement.getNodeName())) { - actions.add(new Script(modelNode, actionElement)); - } else { - actions.add(AbstractModelAction.newInstance(modelNode, actionElement)); - } - } - return actions; - } - - public static List readSubNodeActions(ModelNode.ModelSubNode modelSubNode, Element actionsElement) { - List actionElementList = UtilXml.childElementList(actionsElement); - List actions = new ArrayList(actionElementList.size()); - for (Element actionElement : actionElementList) { - if ("service".equals(actionElement.getNodeName())) { - actions.add(new Service(modelSubNode, actionElement)); - } else if ("entity-and".equals(actionElement.getNodeName())) { - actions.add(new EntityAnd(modelSubNode, actionElement)); - } else if ("entity-condition".equals(actionElement.getNodeName())) { - actions.add(new EntityCondition(modelSubNode, actionElement)); - } else if ("script".equals(actionElement.getNodeName())) { - actions.add(new Script(modelSubNode, actionElement)); - } else { - actions.add(AbstractModelAction.newInstance(modelSubNode, actionElement)); - } - } - return actions; - } - - private final ModelNode.ModelSubNode modelSubNode; - private final ModelTree modelTree; - - protected ModelTreeAction(ModelNode modelNode, Element actionElement) { - if (Debug.verboseOn()) - Debug.logVerbose("Reading Tree action with name: " + actionElement.getNodeName(), module); - this.modelTree = modelNode.getModelTree(); - this.modelSubNode = null; - } - - protected ModelTreeAction(ModelNode.ModelSubNode modelSubNode, Element actionElement) { - if (Debug.verboseOn()) - Debug.logVerbose("Reading Tree action with name: " + actionElement.getNodeName(), module); - this.modelSubNode = modelSubNode; - this.modelTree = modelSubNode.getNode().getModelTree(); - } - - public ModelNode.ModelSubNode getModelSubNode() { - return modelSubNode; - } - - public ModelTree getModelTree() { - return modelTree; - } - - /** - * Models the <entity-and> element. - * - * @see widget-tree.xsd - */ - public static class EntityAnd extends ModelTreeAction { - private final ByAndFinder finder; - private final String listName; - - public EntityAnd(ModelNode.ModelSubNode modelSubNode, Element entityAndElement) { - super(modelSubNode, entityAndElement); - boolean useCache = "true".equalsIgnoreCase(entityAndElement.getAttribute("use-cache")); - Document ownerDoc = entityAndElement.getOwnerDocument(); - if (!useCache) - UtilXml.addChildElement(entityAndElement, "use-iterator", ownerDoc); - String listName = UtilFormatOut.checkEmpty(entityAndElement.getAttribute("list"), - entityAndElement.getAttribute("list-name")); - if (UtilValidate.isEmpty(listName)) - listName = "_LIST_ITERATOR_"; - this.listName = listName; - entityAndElement.setAttribute("list-name", this.listName); - finder = new ByAndFinder(entityAndElement); - } - - @Override - public void accept(ModelActionVisitor visitor) throws Exception { - visitor.visit(this); - } - - public ByAndFinder getFinder() { - return finder; - } - - public String getListName() { - return listName; - } - - @Override - public void runAction(Map context) { - try { - context.put(this.listName, null); - finder.runFind(context, WidgetWorker.getDelegator(context)); - Object obj = context.get(this.listName); - if (obj != null && (obj instanceof EntityListIterator || obj instanceof ListIterator)) { - ListIterator> listIt = UtilGenerics.cast(obj); - this.getModelSubNode().setListIterator(listIt, context); - } else { - if (obj instanceof List) { - List> list = UtilGenerics.checkList(obj); - this.getModelSubNode().setListIterator(list.listIterator(), context); - } - } - } catch (GeneralException e) { - String errMsg = "Error doing entity query by condition: " + e.toString(); - Debug.logError(e, errMsg, module); - throw new IllegalArgumentException(errMsg); - } - } - } - - /** - * Models the <entity-condition> element. - * - * @see widget-tree.xsd - */ - public static class EntityCondition extends ModelTreeAction { - private final ByConditionFinder finder; - private final String listName; - - public EntityCondition(ModelNode.ModelSubNode modelSubNode, Element entityConditionElement) { - super(modelSubNode, entityConditionElement); - Document ownerDoc = entityConditionElement.getOwnerDocument(); - boolean useCache = "true".equalsIgnoreCase(entityConditionElement.getAttribute("use-cache")); - if (!useCache) - UtilXml.addChildElement(entityConditionElement, "use-iterator", ownerDoc); - String listName = UtilFormatOut.checkEmpty(entityConditionElement.getAttribute("list"), - entityConditionElement.getAttribute("list-name")); - if (UtilValidate.isEmpty(listName)) - listName = "_LIST_ITERATOR_"; - this.listName = listName; - entityConditionElement.setAttribute("list-name", this.listName); - finder = new ByConditionFinder(entityConditionElement); - } - - @Override - public void accept(ModelActionVisitor visitor) throws Exception { - visitor.visit(this); - } - - public ByConditionFinder getFinder() { - return finder; - } - - public String getListName() { - return listName; - } - - @Override - public void runAction(Map context) { - try { - context.put(this.listName, null); - finder.runFind(context, WidgetWorker.getDelegator(context)); - Object obj = context.get(this.listName); - if (obj != null && (obj instanceof EntityListIterator || obj instanceof ListIterator)) { - ListIterator> listIt = UtilGenerics.cast(obj); - this.getModelSubNode().setListIterator(listIt, context); - } else { - if (obj instanceof List) { - List> list = UtilGenerics.cast(obj); - this.getModelSubNode().setListIterator(list.listIterator(), context); - } - } - } catch (GeneralException e) { - String errMsg = "Error doing entity query by condition: " + e.toString(); - Debug.logError(e, errMsg, module); - throw new IllegalArgumentException(errMsg); - } - } - } - - /** - * Models the <script> element. - * - * @see widget-tree.xsd - */ - public static class Script extends ModelTreeAction { - private final String location; - private final String method; - - public Script(ModelNode modelNode, Element scriptElement) { - super(modelNode, scriptElement); - String scriptLocation = scriptElement.getAttribute("location"); - this.location = WidgetWorker.getScriptLocation(scriptLocation); - this.method = WidgetWorker.getScriptMethodName(scriptLocation); - } - - public Script(ModelNode.ModelSubNode modelSubNode, Element scriptElement) { - super(modelSubNode, scriptElement); - String scriptLocation = scriptElement.getAttribute("location"); - this.location = WidgetWorker.getScriptLocation(scriptLocation); - this.method = WidgetWorker.getScriptMethodName(scriptLocation); - } - - @Override - public void accept(ModelActionVisitor visitor) throws Exception { - visitor.visit(this); - } - - public String getLocation() { - return location; - } - - public String getMethod() { - return method; - } - - @Override - public void runAction(Map context) { - context.put("_LIST_ITERATOR_", null); - if (location.endsWith(".xml")) { - Map localContext = new HashMap(); - localContext.putAll(context); - DispatchContext ctx = WidgetWorker.getDispatcher(context).getDispatchContext(); - MethodContext methodContext = new MethodContext(ctx, localContext, null); - try { - SimpleMethod.runSimpleMethod(location, method, methodContext); - context.putAll(methodContext.getResults()); - } catch (MiniLangException e) { - throw new RuntimeException("Error running simple method at location [" + location + "]", e); - } - } else { - ScriptUtil.executeScript(this.location, this.method, context); - } - Object obj = context.get("_LIST_ITERATOR_"); - if (this.getModelSubNode() != null) { - if (obj != null && (obj instanceof EntityListIterator || obj instanceof ListIterator)) { - ListIterator> listIt = UtilGenerics.cast(obj); - this.getModelSubNode().setListIterator(listIt, context); - } else { - if (obj instanceof List) { - List> list = UtilGenerics.checkList(obj); - this.getModelSubNode().setListIterator(list.listIterator(), context); - } - } - } - } - } - - /** - * Models the <service> element. - * - * @see widget-tree.xsd - */ - public static class Service extends ModelTreeAction { - private final FlexibleStringExpander autoFieldMapExdr; - private final Map, Object> fieldMap; - private final FlexibleStringExpander resultMapListNameExdr; - private final FlexibleMapAccessor> resultMapNameAcsr; - private final FlexibleStringExpander resultMapValueNameExdr; - private final FlexibleStringExpander serviceNameExdr; - private final FlexibleStringExpander valueNameExdr; - - public Service(ModelNode modelNode, Element serviceElement) { - super(modelNode, serviceElement); - this.serviceNameExdr = FlexibleStringExpander.getInstance(serviceElement.getAttribute("service-name")); - this.resultMapNameAcsr = FlexibleMapAccessor.getInstance(serviceElement.getAttribute("result-map")); - this.autoFieldMapExdr = FlexibleStringExpander.getInstance(serviceElement.getAttribute("auto-field-map")); - this.resultMapListNameExdr = FlexibleStringExpander.getInstance(serviceElement.getAttribute("result-map-list")); - this.resultMapValueNameExdr = FlexibleStringExpander.getInstance(serviceElement.getAttribute("result-map-value")); - this.valueNameExdr = FlexibleStringExpander.getInstance(serviceElement.getAttribute("value")); - this.fieldMap = EntityFinderUtil.makeFieldMap(serviceElement); - } - - public Service(ModelNode.ModelSubNode modelSubNode, Element serviceElement) { - super(modelSubNode, serviceElement); - this.serviceNameExdr = FlexibleStringExpander.getInstance(serviceElement.getAttribute("service-name")); - this.resultMapNameAcsr = FlexibleMapAccessor.getInstance(serviceElement.getAttribute("result-map")); - this.autoFieldMapExdr = FlexibleStringExpander.getInstance(serviceElement.getAttribute("auto-field-map")); - this.resultMapListNameExdr = FlexibleStringExpander.getInstance(serviceElement.getAttribute("result-map-list")); - this.resultMapValueNameExdr = FlexibleStringExpander.getInstance(serviceElement.getAttribute("result-map-value")); - this.valueNameExdr = FlexibleStringExpander.getInstance(serviceElement.getAttribute("value")); - this.fieldMap = EntityFinderUtil.makeFieldMap(serviceElement); - } - - @Override - public void accept(ModelActionVisitor visitor) throws Exception { - visitor.visit(this); - } - - public FlexibleStringExpander getAutoFieldMapExdr() { - return autoFieldMapExdr; - } - - public Map, Object> getFieldMap() { - return fieldMap; - } - - public FlexibleStringExpander getResultMapListNameExdr() { - return resultMapListNameExdr; - } - - public FlexibleMapAccessor> getResultMapNameAcsr() { - return resultMapNameAcsr; - } - - public FlexibleStringExpander getResultMapValueNameExdr() { - return resultMapValueNameExdr; - } - - public FlexibleStringExpander getServiceNameExdr() { - return serviceNameExdr; - } - - public FlexibleStringExpander getValueNameExdr() { - return valueNameExdr; - } - - @Override - public void runAction(Map context) { - String serviceNameExpanded = this.serviceNameExdr.expandString(context); - if (UtilValidate.isEmpty(serviceNameExpanded)) { - throw new IllegalArgumentException("Service name was empty, expanded from: " + this.serviceNameExdr.getOriginal()); - } - String autoFieldMapString = this.autoFieldMapExdr.expandString(context); - boolean autoFieldMapBool = !"false".equals(autoFieldMapString); - try { - Map serviceContext = null; - if (autoFieldMapBool) { - serviceContext = WidgetWorker.getDispatcher(context).getDispatchContext() - .makeValidContext(serviceNameExpanded, ModelService.IN_PARAM, context); - } else { - serviceContext = new HashMap(); - } - if (this.fieldMap != null) { - EntityFinderUtil.expandFieldMapToContext(this.fieldMap, context, serviceContext); - } - Map result = WidgetWorker.getDispatcher(context).runSync(serviceNameExpanded, serviceContext); - if (!this.resultMapNameAcsr.isEmpty()) { - this.resultMapNameAcsr.put(context, result); - String queryString = (String) result.get("queryString"); - context.put("queryString", queryString); - context.put("queryStringMap", result.get("queryStringMap")); - if (UtilValidate.isNotEmpty(queryString)) { - try { - String queryStringEncoded = queryString.replaceAll("&", "%26"); - context.put("queryStringEncoded", queryStringEncoded); - } catch (PatternSyntaxException e) { - - } - } - } else { - context.putAll(result); - } - String resultMapListName = resultMapListNameExdr.expandString(context); - //String resultMapListIteratorName = resultMapListIteratorNameExdr.expandString(context); - String resultMapValueName = resultMapValueNameExdr.expandString(context); - String valueName = valueNameExdr.expandString(context); - if (this.getModelSubNode() != null) { - //ListIterator iter = null; - if (UtilValidate.isNotEmpty(resultMapListName)) { - List> lst = UtilGenerics.checkList(result.get(resultMapListName)); - if (lst != null) { - if (lst instanceof ListIterator) { - ListIterator> listIt = UtilGenerics.cast(lst); - this.getModelSubNode().setListIterator(listIt, context); - } else { - this.getModelSubNode().setListIterator(lst.listIterator(), context); - } - } - } - } else { - if (UtilValidate.isNotEmpty(resultMapValueName)) { - if (UtilValidate.isNotEmpty(valueName)) { - context.put(valueName, result.get(resultMapValueName)); - } else { - Map resultMap = UtilGenerics.checkMap(result.get(resultMapValueName)); - context.putAll(resultMap); - } - } - } - } catch (GenericServiceException e) { - String errMsg = "Error calling service with name " + serviceNameExpanded + ": " + e.toString(); - Debug.logError(e, errMsg, module); - throw new IllegalArgumentException(errMsg); - } - } - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.model; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.ListIterator; +import java.util.Map; +import java.util.regex.PatternSyntaxException; + +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.GeneralException; +import org.ofbiz.base.util.ScriptUtil; +import org.ofbiz.base.util.UtilFormatOut; +import org.ofbiz.base.util.UtilGenerics; +import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.base.util.UtilXml; +import org.ofbiz.base.util.collections.FlexibleMapAccessor; +import org.ofbiz.base.util.string.FlexibleStringExpander; +import org.ofbiz.entity.finder.ByAndFinder; +import org.ofbiz.entity.finder.ByConditionFinder; +import org.ofbiz.entity.finder.EntityFinderUtil; +import org.ofbiz.entity.util.EntityListIterator; +import org.ofbiz.minilang.MiniLangException; +import org.ofbiz.minilang.SimpleMethod; +import org.ofbiz.minilang.method.MethodContext; +import org.ofbiz.service.DispatchContext; +import org.ofbiz.service.GenericServiceException; +import org.ofbiz.service.ModelService; +import org.ofbiz.widget.WidgetWorker; +import org.ofbiz.widget.model.ModelTree.ModelNode; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * Abstract tree action. + */ +@SuppressWarnings("serial") +public abstract class ModelTreeAction extends AbstractModelAction { + + /* + * ----------------------------------------------------------------------- * + * DEVELOPERS PLEASE READ + * ----------------------------------------------------------------------- * + * + * This model is intended to be a read-only data structure that represents + * an XML element. Outside of object construction, the class should not + * have any behaviors. + * + * Instances of this class will be shared by multiple threads - therefore + * it is immutable. DO NOT CHANGE THE OBJECT'S STATE AT RUN TIME! + * + */ + + public static final String module = ModelTreeAction.class.getName(); + + public static List readNodeActions(ModelNode modelNode, Element actionsElement) { + List actionElementList = UtilXml.childElementList(actionsElement); + List actions = new ArrayList(actionElementList.size()); + for (Element actionElement : actionElementList) { + if ("service".equals(actionElement.getNodeName())) { + actions.add(new Service(modelNode, actionElement)); + } else if ("script".equals(actionElement.getNodeName())) { + actions.add(new Script(modelNode, actionElement)); + } else { + actions.add(AbstractModelAction.newInstance(modelNode, actionElement)); + } + } + return actions; + } + + public static List readSubNodeActions(ModelNode.ModelSubNode modelSubNode, Element actionsElement) { + List actionElementList = UtilXml.childElementList(actionsElement); + List actions = new ArrayList(actionElementList.size()); + for (Element actionElement : actionElementList) { + if ("service".equals(actionElement.getNodeName())) { + actions.add(new Service(modelSubNode, actionElement)); + } else if ("entity-and".equals(actionElement.getNodeName())) { + actions.add(new EntityAnd(modelSubNode, actionElement)); + } else if ("entity-condition".equals(actionElement.getNodeName())) { + actions.add(new EntityCondition(modelSubNode, actionElement)); + } else if ("script".equals(actionElement.getNodeName())) { + actions.add(new Script(modelSubNode, actionElement)); + } else { + actions.add(AbstractModelAction.newInstance(modelSubNode, actionElement)); + } + } + return actions; + } + + private final ModelNode.ModelSubNode modelSubNode; + private final ModelTree modelTree; + + protected ModelTreeAction(ModelNode modelNode, Element actionElement) { + if (Debug.verboseOn()) + Debug.logVerbose("Reading Tree action with name: " + actionElement.getNodeName(), module); + this.modelTree = modelNode.getModelTree(); + this.modelSubNode = null; + } + + protected ModelTreeAction(ModelNode.ModelSubNode modelSubNode, Element actionElement) { + if (Debug.verboseOn()) + Debug.logVerbose("Reading Tree action with name: " + actionElement.getNodeName(), module); + this.modelSubNode = modelSubNode; + this.modelTree = modelSubNode.getNode().getModelTree(); + } + + public ModelNode.ModelSubNode getModelSubNode() { + return modelSubNode; + } + + public ModelTree getModelTree() { + return modelTree; + } + + /** + * Models the <entity-and> element. + * + * @see widget-tree.xsd + */ + public static class EntityAnd extends ModelTreeAction { + private final ByAndFinder finder; + private final String listName; + + public EntityAnd(ModelNode.ModelSubNode modelSubNode, Element entityAndElement) { + super(modelSubNode, entityAndElement); + boolean useCache = "true".equalsIgnoreCase(entityAndElement.getAttribute("use-cache")); + Document ownerDoc = entityAndElement.getOwnerDocument(); + if (!useCache) + UtilXml.addChildElement(entityAndElement, "use-iterator", ownerDoc); + String listName = UtilFormatOut.checkEmpty(entityAndElement.getAttribute("list"), + entityAndElement.getAttribute("list-name")); + if (UtilValidate.isEmpty(listName)) + listName = "_LIST_ITERATOR_"; + this.listName = listName; + entityAndElement.setAttribute("list-name", this.listName); + finder = new ByAndFinder(entityAndElement); + } + + @Override + public void accept(ModelActionVisitor visitor) throws Exception { + visitor.visit(this); + } + + public ByAndFinder getFinder() { + return finder; + } + + public String getListName() { + return listName; + } + + @Override + public void runAction(Map context) { + try { + context.put(this.listName, null); + finder.runFind(context, WidgetWorker.getDelegator(context)); + Object obj = context.get(this.listName); + if (obj != null && (obj instanceof EntityListIterator || obj instanceof ListIterator)) { + ListIterator> listIt = UtilGenerics.cast(obj); + this.getModelSubNode().setListIterator(listIt, context); + } else { + if (obj instanceof List) { + List> list = UtilGenerics.checkList(obj); + this.getModelSubNode().setListIterator(list.listIterator(), context); + } + } + } catch (GeneralException e) { + String errMsg = "Error doing entity query by condition: " + e.toString(); + Debug.logError(e, errMsg, module); + throw new IllegalArgumentException(errMsg); + } + } + } + + /** + * Models the <entity-condition> element. + * + * @see widget-tree.xsd + */ + public static class EntityCondition extends ModelTreeAction { + private final ByConditionFinder finder; + private final String listName; + + public EntityCondition(ModelNode.ModelSubNode modelSubNode, Element entityConditionElement) { + super(modelSubNode, entityConditionElement); + Document ownerDoc = entityConditionElement.getOwnerDocument(); + boolean useCache = "true".equalsIgnoreCase(entityConditionElement.getAttribute("use-cache")); + if (!useCache) + UtilXml.addChildElement(entityConditionElement, "use-iterator", ownerDoc); + String listName = UtilFormatOut.checkEmpty(entityConditionElement.getAttribute("list"), + entityConditionElement.getAttribute("list-name")); + if (UtilValidate.isEmpty(listName)) + listName = "_LIST_ITERATOR_"; + this.listName = listName; + entityConditionElement.setAttribute("list-name", this.listName); + finder = new ByConditionFinder(entityConditionElement); + } + + @Override + public void accept(ModelActionVisitor visitor) throws Exception { + visitor.visit(this); + } + + public ByConditionFinder getFinder() { + return finder; + } + + public String getListName() { + return listName; + } + + @Override + public void runAction(Map context) { + try { + context.put(this.listName, null); + finder.runFind(context, WidgetWorker.getDelegator(context)); + Object obj = context.get(this.listName); + if (obj != null && (obj instanceof EntityListIterator || obj instanceof ListIterator)) { + ListIterator> listIt = UtilGenerics.cast(obj); + this.getModelSubNode().setListIterator(listIt, context); + } else { + if (obj instanceof List) { + List> list = UtilGenerics.cast(obj); + this.getModelSubNode().setListIterator(list.listIterator(), context); + } + } + } catch (GeneralException e) { + String errMsg = "Error doing entity query by condition: " + e.toString(); + Debug.logError(e, errMsg, module); + throw new IllegalArgumentException(errMsg); + } + } + } + + /** + * Models the <script> element. + * + * @see widget-tree.xsd + */ + public static class Script extends ModelTreeAction { + private final String location; + private final String method; + + public Script(ModelNode modelNode, Element scriptElement) { + super(modelNode, scriptElement); + String scriptLocation = scriptElement.getAttribute("location"); + this.location = WidgetWorker.getScriptLocation(scriptLocation); + this.method = WidgetWorker.getScriptMethodName(scriptLocation); + } + + public Script(ModelNode.ModelSubNode modelSubNode, Element scriptElement) { + super(modelSubNode, scriptElement); + String scriptLocation = scriptElement.getAttribute("location"); + this.location = WidgetWorker.getScriptLocation(scriptLocation); + this.method = WidgetWorker.getScriptMethodName(scriptLocation); + } + + @Override + public void accept(ModelActionVisitor visitor) throws Exception { + visitor.visit(this); + } + + public String getLocation() { + return location; + } + + public String getMethod() { + return method; + } + + @Override + public void runAction(Map context) { + context.put("_LIST_ITERATOR_", null); + if (location.endsWith(".xml")) { + Map localContext = new HashMap(); + localContext.putAll(context); + DispatchContext ctx = WidgetWorker.getDispatcher(context).getDispatchContext(); + MethodContext methodContext = new MethodContext(ctx, localContext, null); + try { + SimpleMethod.runSimpleMethod(location, method, methodContext); + context.putAll(methodContext.getResults()); + } catch (MiniLangException e) { + throw new RuntimeException("Error running simple method at location [" + location + "]", e); + } + } else { + ScriptUtil.executeScript(this.location, this.method, context); + } + Object obj = context.get("_LIST_ITERATOR_"); + if (this.getModelSubNode() != null) { + if (obj != null && (obj instanceof EntityListIterator || obj instanceof ListIterator)) { + ListIterator> listIt = UtilGenerics.cast(obj); + this.getModelSubNode().setListIterator(listIt, context); + } else { + if (obj instanceof List) { + List> list = UtilGenerics.checkList(obj); + this.getModelSubNode().setListIterator(list.listIterator(), context); + } + } + } + } + } + + /** + * Models the <service> element. + * + * @see widget-tree.xsd + */ + public static class Service extends ModelTreeAction { + private final FlexibleStringExpander autoFieldMapExdr; + private final Map, Object> fieldMap; + private final FlexibleStringExpander resultMapListNameExdr; + private final FlexibleMapAccessor> resultMapNameAcsr; + private final FlexibleStringExpander resultMapValueNameExdr; + private final FlexibleStringExpander serviceNameExdr; + private final FlexibleStringExpander valueNameExdr; + + public Service(ModelNode modelNode, Element serviceElement) { + super(modelNode, serviceElement); + this.serviceNameExdr = FlexibleStringExpander.getInstance(serviceElement.getAttribute("service-name")); + this.resultMapNameAcsr = FlexibleMapAccessor.getInstance(serviceElement.getAttribute("result-map")); + this.autoFieldMapExdr = FlexibleStringExpander.getInstance(serviceElement.getAttribute("auto-field-map")); + this.resultMapListNameExdr = FlexibleStringExpander.getInstance(serviceElement.getAttribute("result-map-list")); + this.resultMapValueNameExdr = FlexibleStringExpander.getInstance(serviceElement.getAttribute("result-map-value")); + this.valueNameExdr = FlexibleStringExpander.getInstance(serviceElement.getAttribute("value")); + this.fieldMap = EntityFinderUtil.makeFieldMap(serviceElement); + } + + public Service(ModelNode.ModelSubNode modelSubNode, Element serviceElement) { + super(modelSubNode, serviceElement); + this.serviceNameExdr = FlexibleStringExpander.getInstance(serviceElement.getAttribute("service-name")); + this.resultMapNameAcsr = FlexibleMapAccessor.getInstance(serviceElement.getAttribute("result-map")); + this.autoFieldMapExdr = FlexibleStringExpander.getInstance(serviceElement.getAttribute("auto-field-map")); + this.resultMapListNameExdr = FlexibleStringExpander.getInstance(serviceElement.getAttribute("result-map-list")); + this.resultMapValueNameExdr = FlexibleStringExpander.getInstance(serviceElement.getAttribute("result-map-value")); + this.valueNameExdr = FlexibleStringExpander.getInstance(serviceElement.getAttribute("value")); + this.fieldMap = EntityFinderUtil.makeFieldMap(serviceElement); + } + + @Override + public void accept(ModelActionVisitor visitor) throws Exception { + visitor.visit(this); + } + + public FlexibleStringExpander getAutoFieldMapExdr() { + return autoFieldMapExdr; + } + + public Map, Object> getFieldMap() { + return fieldMap; + } + + public FlexibleStringExpander getResultMapListNameExdr() { + return resultMapListNameExdr; + } + + public FlexibleMapAccessor> getResultMapNameAcsr() { + return resultMapNameAcsr; + } + + public FlexibleStringExpander getResultMapValueNameExdr() { + return resultMapValueNameExdr; + } + + public FlexibleStringExpander getServiceNameExdr() { + return serviceNameExdr; + } + + public FlexibleStringExpander getValueNameExdr() { + return valueNameExdr; + } + + @Override + public void runAction(Map context) { + String serviceNameExpanded = this.serviceNameExdr.expandString(context); + if (UtilValidate.isEmpty(serviceNameExpanded)) { + throw new IllegalArgumentException("Service name was empty, expanded from: " + this.serviceNameExdr.getOriginal()); + } + String autoFieldMapString = this.autoFieldMapExdr.expandString(context); + boolean autoFieldMapBool = !"false".equals(autoFieldMapString); + try { + Map serviceContext = null; + if (autoFieldMapBool) { + serviceContext = WidgetWorker.getDispatcher(context).getDispatchContext() + .makeValidContext(serviceNameExpanded, ModelService.IN_PARAM, context); + } else { + serviceContext = new HashMap(); + } + if (this.fieldMap != null) { + EntityFinderUtil.expandFieldMapToContext(this.fieldMap, context, serviceContext); + } + Map result = WidgetWorker.getDispatcher(context).runSync(serviceNameExpanded, serviceContext); + if (!this.resultMapNameAcsr.isEmpty()) { + this.resultMapNameAcsr.put(context, result); + String queryString = (String) result.get("queryString"); + context.put("queryString", queryString); + context.put("queryStringMap", result.get("queryStringMap")); + if (UtilValidate.isNotEmpty(queryString)) { + try { + String queryStringEncoded = queryString.replaceAll("&", "%26"); + context.put("queryStringEncoded", queryStringEncoded); + } catch (PatternSyntaxException e) { + + } + } + } else { + context.putAll(result); + } + String resultMapListName = resultMapListNameExdr.expandString(context); + //String resultMapListIteratorName = resultMapListIteratorNameExdr.expandString(context); + String resultMapValueName = resultMapValueNameExdr.expandString(context); + String valueName = valueNameExdr.expandString(context); + if (this.getModelSubNode() != null) { + //ListIterator iter = null; + if (UtilValidate.isNotEmpty(resultMapListName)) { + List> lst = UtilGenerics.checkList(result.get(resultMapListName)); + if (lst != null) { + if (lst instanceof ListIterator) { + ListIterator> listIt = UtilGenerics.cast(lst); + this.getModelSubNode().setListIterator(listIt, context); + } else { + this.getModelSubNode().setListIterator(lst.listIterator(), context); + } + } + } + } else { + if (UtilValidate.isNotEmpty(resultMapValueName)) { + if (UtilValidate.isNotEmpty(valueName)) { + context.put(valueName, result.get(resultMapValueName)); + } else { + Map resultMap = UtilGenerics.checkMap(result.get(resultMapValueName)); + context.putAll(resultMap); + } + } + } + } catch (GenericServiceException e) { + String errMsg = "Error calling service with name " + serviceNameExpanded + ": " + e.toString(); + Debug.logError(e, errMsg, module); + throw new IllegalArgumentException(errMsg); + } + } + } +} diff --git a/framework/widget/src/org/ofbiz/widget/tree/ModelTreeCondition.java b/framework/widget/src/org/ofbiz/widget/model/ModelTreeCondition.java similarity index 92% rename from framework/widget/src/org/ofbiz/widget/tree/ModelTreeCondition.java rename to framework/widget/src/org/ofbiz/widget/model/ModelTreeCondition.java index 68128715cd..a225bfc755 100644 --- a/framework/widget/src/org/ofbiz/widget/tree/ModelTreeCondition.java +++ b/framework/widget/src/org/ofbiz/widget/model/ModelTreeCondition.java @@ -1,41 +1,39 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget.tree; - -import org.ofbiz.widget.AbstractModelCondition; -import org.ofbiz.widget.ModelCondition; -import org.w3c.dom.Element; - -/** - * Models the <condition> element. - * - * @see widget-tree.xsd - */ -public class ModelTreeCondition { - public static final String module = ModelTreeCondition.class.getName(); - private final ModelCondition condition; - - public ModelTreeCondition(ModelTree modelTree, Element conditionElement) { - this.condition = AbstractModelCondition.DEFAULT_CONDITION_FACTORY.newInstance(modelTree, conditionElement); - } - - public ModelCondition getCondition() { - return condition; - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.model; + +import org.w3c.dom.Element; + +/** + * Models the <condition> element. + * + * @see widget-tree.xsd + */ +public class ModelTreeCondition { + public static final String module = ModelTreeCondition.class.getName(); + private final ModelCondition condition; + + public ModelTreeCondition(ModelTree modelTree, Element conditionElement) { + this.condition = AbstractModelCondition.DEFAULT_CONDITION_FACTORY.newInstance(modelTree, conditionElement); + } + + public ModelCondition getCondition() { + return condition; + } +} diff --git a/framework/widget/src/org/ofbiz/widget/ModelWidget.java b/framework/widget/src/org/ofbiz/widget/model/ModelWidget.java similarity index 96% rename from framework/widget/src/org/ofbiz/widget/ModelWidget.java rename to framework/widget/src/org/ofbiz/widget/model/ModelWidget.java index 9c9e4b4815..8aec83eaa6 100644 --- a/framework/widget/src/org/ofbiz/widget/ModelWidget.java +++ b/framework/widget/src/org/ofbiz/widget/model/ModelWidget.java @@ -1,155 +1,154 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget; - -import java.io.Serializable; -import java.util.Map; - -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.UtilGenerics; -import org.ofbiz.base.util.UtilProperties; -import org.ofbiz.widget.xml.XmlWidgetVisitor; -import org.w3c.dom.Element; - -/** - * Widget Library - Widget model class. ModelWidget is a base class that is - * extended by other widget model classes. - */ -@SuppressWarnings("serial") -public abstract class ModelWidget implements Serializable { - - public static final String module = ModelWidget.class.getName(); - /** - * The parameter name used to control widget boundary comments. Currently - * set to "widgetVerbose". - */ - public static final String enableBoundaryCommentsParam = "widgetVerbose"; - - private final String name; - private final String systemId; - private final int startColumn; - private final int startLine; - - /** - * Derived classes must call this constructor. - * @param name The widget name - */ - protected ModelWidget(String name) { - this.name = name; - this.systemId = "anonymous"; - this.startColumn = 0; - this.startLine = 0; - } - - /** - * Derived classes must call this constructor. - * @param widgetElement The XML Element for the widget - */ - protected ModelWidget(Element widgetElement) { - this.name = widgetElement.getAttribute("name"); - this.systemId = (String) widgetElement.getUserData("systemId"); - this.startColumn = ((Integer) widgetElement.getUserData("startColumn")).intValue(); - this.startLine = ((Integer) widgetElement.getUserData("startLine")).intValue(); - } - - public abstract void accept(ModelWidgetVisitor visitor) throws Exception; - - /** - * Returns the widget's name. - * @return Widget's name - */ - public String getName() { - return name; - } - - /** - * Returns the url as a string, from where this widget was defined. - * @return url - */ - public String getSystemId() { - return systemId; - } - - /** - * Returns the column where this widget was defined, in it's containing xml file. - * @return start column - */ - public int getStartColumn() { - return startColumn; - } - - /** - * Returns the line where this widget was defined, in it's containing xml file. - * @return start line - */ - public int getStartLine() { - return startLine; - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - ModelWidgetVisitor visitor = new XmlWidgetVisitor(sb); - try { - accept(visitor); - } catch (Exception e) { - Debug.logWarning(e, "Exception thrown in XmlWidgetVisitor: ", module); - } - return sb.toString(); - } - - /** - * Returns the widget's name to be used in boundary comments. The default action - * is to return the widget's name. Derived classes can override this method to - * return a customized name. - * @return Name to be used in boundary comments - */ - public String getBoundaryCommentName() { - return name; - } - - /** - * Returns true if widget boundary comments are enabled. Widget boundary comments are - * enabled by setting widget.verbose=true in the widget.properties file. - * The true setting can be overridden in web.xml or in the screen - * rendering context. If widget.verbose is set to false in the - * widget.properties file, then that setting will override all other settings and - * disable all widget boundary comments. - * - * @param context Optional context Map - */ - public static boolean widgetBoundaryCommentsEnabled(Map context) { - boolean result = "true".equals(UtilProperties.getPropertyValue("widget", "widget.verbose")); - if (result && context != null) { - String str = (String) context.get(enableBoundaryCommentsParam); - if (str != null) { - result = "true".equals(str); - } else{ - Map parameters = UtilGenerics.checkMap(context.get("parameters")); - if (parameters != null) { - str = (String) parameters.get(enableBoundaryCommentsParam); - if (str != null) { - result = "true".equals(str); - } - } - } - } - return result; - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.model; + +import java.io.Serializable; +import java.util.Map; + +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilGenerics; +import org.ofbiz.base.util.UtilProperties; +import org.w3c.dom.Element; + +/** + * Widget Library - Widget model class. ModelWidget is a base class that is + * extended by other widget model classes. + */ +@SuppressWarnings("serial") +public abstract class ModelWidget implements Serializable { + + public static final String module = ModelWidget.class.getName(); + /** + * The parameter name used to control widget boundary comments. Currently + * set to "widgetVerbose". + */ + public static final String enableBoundaryCommentsParam = "widgetVerbose"; + + private final String name; + private final String systemId; + private final int startColumn; + private final int startLine; + + /** + * Derived classes must call this constructor. + * @param name The widget name + */ + protected ModelWidget(String name) { + this.name = name; + this.systemId = "anonymous"; + this.startColumn = 0; + this.startLine = 0; + } + + /** + * Derived classes must call this constructor. + * @param widgetElement The XML Element for the widget + */ + protected ModelWidget(Element widgetElement) { + this.name = widgetElement.getAttribute("name"); + this.systemId = (String) widgetElement.getUserData("systemId"); + this.startColumn = ((Integer) widgetElement.getUserData("startColumn")).intValue(); + this.startLine = ((Integer) widgetElement.getUserData("startLine")).intValue(); + } + + public abstract void accept(ModelWidgetVisitor visitor) throws Exception; + + /** + * Returns the widget's name. + * @return Widget's name + */ + public String getName() { + return name; + } + + /** + * Returns the url as a string, from where this widget was defined. + * @return url + */ + public String getSystemId() { + return systemId; + } + + /** + * Returns the column where this widget was defined, in it's containing xml file. + * @return start column + */ + public int getStartColumn() { + return startColumn; + } + + /** + * Returns the line where this widget was defined, in it's containing xml file. + * @return start line + */ + public int getStartLine() { + return startLine; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + ModelWidgetVisitor visitor = new XmlWidgetVisitor(sb); + try { + accept(visitor); + } catch (Exception e) { + Debug.logWarning(e, "Exception thrown in XmlWidgetVisitor: ", module); + } + return sb.toString(); + } + + /** + * Returns the widget's name to be used in boundary comments. The default action + * is to return the widget's name. Derived classes can override this method to + * return a customized name. + * @return Name to be used in boundary comments + */ + public String getBoundaryCommentName() { + return name; + } + + /** + * Returns true if widget boundary comments are enabled. Widget boundary comments are + * enabled by setting widget.verbose=true in the widget.properties file. + * The true setting can be overridden in web.xml or in the screen + * rendering context. If widget.verbose is set to false in the + * widget.properties file, then that setting will override all other settings and + * disable all widget boundary comments. + * + * @param context Optional context Map + */ + public static boolean widgetBoundaryCommentsEnabled(Map context) { + boolean result = "true".equals(UtilProperties.getPropertyValue("widget", "widget.verbose")); + if (result && context != null) { + String str = (String) context.get(enableBoundaryCommentsParam); + if (str != null) { + result = "true".equals(str); + } else{ + Map parameters = UtilGenerics.checkMap(context.get("parameters")); + if (parameters != null) { + str = (String) parameters.get(enableBoundaryCommentsParam); + if (str != null) { + result = "true".equals(str); + } + } + } + } + return result; + } +} diff --git a/framework/widget/src/org/ofbiz/widget/ModelWidgetCondition.java b/framework/widget/src/org/ofbiz/widget/model/ModelWidgetCondition.java similarity index 97% rename from framework/widget/src/org/ofbiz/widget/ModelWidgetCondition.java rename to framework/widget/src/org/ofbiz/widget/model/ModelWidgetCondition.java index 56feb69830..99fce33f59 100644 --- a/framework/widget/src/org/ofbiz/widget/ModelWidgetCondition.java +++ b/framework/widget/src/org/ofbiz/widget/model/ModelWidgetCondition.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. *******************************************************************************/ -package org.ofbiz.widget; +package org.ofbiz.widget.model; import java.io.Serializable; import java.lang.reflect.Method; diff --git a/framework/widget/src/org/ofbiz/widget/ModelWidgetVisitor.java b/framework/widget/src/org/ofbiz/widget/model/ModelWidgetVisitor.java similarity index 87% rename from framework/widget/src/org/ofbiz/widget/ModelWidgetVisitor.java rename to framework/widget/src/org/ofbiz/widget/model/ModelWidgetVisitor.java index c2b13ca4ee..50643fa062 100644 --- a/framework/widget/src/org/ofbiz/widget/ModelWidgetVisitor.java +++ b/framework/widget/src/org/ofbiz/widget/model/ModelWidgetVisitor.java @@ -16,16 +16,9 @@ * specific language governing permissions and limitations * under the License. *******************************************************************************/ -package org.ofbiz.widget; +package org.ofbiz.widget.model; -import org.ofbiz.widget.form.ModelForm; -import org.ofbiz.widget.menu.ModelMenu; -import org.ofbiz.widget.menu.ModelMenuItem; -import org.ofbiz.widget.screen.HtmlWidget; -import org.ofbiz.widget.screen.IterateSectionWidget; -import org.ofbiz.widget.screen.ModelScreen; -import org.ofbiz.widget.screen.ModelScreenWidget; -import org.ofbiz.widget.tree.ModelTree; +import org.ofbiz.widget.model.HtmlWidget; /** * A ModelWidget visitor. diff --git a/framework/widget/src/org/ofbiz/widget/screen/ScreenFactory.java b/framework/widget/src/org/ofbiz/widget/model/ScreenFactory.java similarity index 97% rename from framework/widget/src/org/ofbiz/widget/screen/ScreenFactory.java rename to framework/widget/src/org/ofbiz/widget/model/ScreenFactory.java index 1cdaaa1c70..d6021ef0a8 100644 --- a/framework/widget/src/org/ofbiz/widget/screen/ScreenFactory.java +++ b/framework/widget/src/org/ofbiz/widget/model/ScreenFactory.java @@ -1,212 +1,213 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget.screen; - -import java.io.IOException; -import java.net.URL; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletRequest; -import javax.xml.parsers.ParserConfigurationException; - -import org.ofbiz.base.location.FlexibleLocation; -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.GeneralException; -import org.ofbiz.base.util.UtilHttp; -import org.ofbiz.base.util.UtilValidate; -import org.ofbiz.base.util.UtilXml; -import org.ofbiz.base.util.cache.UtilCache; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.xml.sax.SAXException; - - -/** - * Widget Library - Screen factory class - */ -public class ScreenFactory { - - public static final String module = ScreenFactory.class.getName(); - - public static final UtilCache> screenLocationCache = UtilCache.createUtilCache("widget.screen.locationResource", 0, 0, false); - public static final UtilCache> screenWebappCache = UtilCache.createUtilCache("widget.screen.webappResource", 0, 0, false); - - public static boolean isCombinedName(String combinedName) { - int numSignIndex = combinedName.lastIndexOf("#"); - if (numSignIndex == -1) { - return false; - } - if (numSignIndex + 1 >= combinedName.length()) { - return false; - } - return true; - } - - public static String getResourceNameFromCombined(String combinedName) { - // split out the name on the last "#" - int numSignIndex = combinedName.lastIndexOf("#"); - if (numSignIndex == -1) { - throw new IllegalArgumentException("Error in screen location/name: no \"#\" found to separate the location from the name; correct example: component://product/screen/product/ProductScreens.xml#EditProduct"); - } - if (numSignIndex + 1 >= combinedName.length()) { - throw new IllegalArgumentException("Error in screen location/name: the \"#\" was at the end with no screen name after it; correct example: component://product/screen/product/ProductScreens.xml#EditProduct"); - } - String resourceName = combinedName.substring(0, numSignIndex); - return resourceName; - } - - public static String getScreenNameFromCombined(String combinedName) { - // split out the name on the last "#" - int numSignIndex = combinedName.lastIndexOf("#"); - if (numSignIndex == -1) { - throw new IllegalArgumentException("Error in screen location/name: no \"#\" found to separate the location from the name; correct example: component://product/screen/product/ProductScreens.xml#EditProduct"); - } - if (numSignIndex + 1 >= combinedName.length()) { - throw new IllegalArgumentException("Error in screen location/name: the \"#\" was at the end with no screen name after it; correct example: component://product/screen/product/ProductScreens.xml#EditProduct"); - } - String screenName = combinedName.substring(numSignIndex + 1); - return screenName; - } - - public static ModelScreen getScreenFromLocation(String combinedName) - throws IOException, SAXException, ParserConfigurationException { - String resourceName = getResourceNameFromCombined(combinedName); - String screenName = getScreenNameFromCombined(combinedName); - return getScreenFromLocation(resourceName, screenName); - } - - public static ModelScreen getScreenFromLocation(String resourceName, String screenName) - throws IOException, SAXException, ParserConfigurationException { - Map modelScreenMap = getScreensFromLocation(resourceName); - ModelScreen modelScreen = modelScreenMap.get(screenName); - if (modelScreen == null) { - throw new IllegalArgumentException("Could not find screen with name [" + screenName + "] in class resource [" + resourceName + "]"); - } - return modelScreen; - } - - public static Map getScreensFromLocation(String resourceName) - throws IOException, SAXException, ParserConfigurationException { - Map modelScreenMap = screenLocationCache.get(resourceName); - if (modelScreenMap == null) { - synchronized (ScreenFactory.class) { - modelScreenMap = screenLocationCache.get(resourceName); - if (modelScreenMap == null) { - long startTime = System.currentTimeMillis(); - URL screenFileUrl = null; - screenFileUrl = FlexibleLocation.resolveLocation(resourceName); - if (screenFileUrl == null) { - throw new IllegalArgumentException("Could not resolve location to URL: " + resourceName); - } - Document screenFileDoc = UtilXml.readXmlDocument(screenFileUrl, true, true); - modelScreenMap = readScreenDocument(screenFileDoc, resourceName); - screenLocationCache.put(resourceName, modelScreenMap); - double totalSeconds = (System.currentTimeMillis() - startTime)/1000.0; - Debug.logInfo("Got " + modelScreenMap.size() + " screens in " + totalSeconds + "s from: " + screenFileUrl.toExternalForm(), module); - } - } - } - - if (modelScreenMap.isEmpty()) { - throw new IllegalArgumentException("Could not find screen file with name [" + resourceName + "]"); - } - return modelScreenMap; - } - - public static ModelScreen getScreenFromWebappContext(String resourceName, String screenName, HttpServletRequest request) - throws IOException, SAXException, ParserConfigurationException { - String webappName = UtilHttp.getApplicationName(request); - String cacheKey = webappName + "::" + resourceName; - - - Map modelScreenMap = screenWebappCache.get(cacheKey); - if (modelScreenMap == null) { - synchronized (ScreenFactory.class) { - modelScreenMap = screenWebappCache.get(cacheKey); - if (modelScreenMap == null) { - ServletContext servletContext = (ServletContext) request.getAttribute("servletContext"); - - URL screenFileUrl = servletContext.getResource(resourceName); - Document screenFileDoc = UtilXml.readXmlDocument(screenFileUrl, true, true); - modelScreenMap = readScreenDocument(screenFileDoc, resourceName); - screenWebappCache.put(cacheKey, modelScreenMap); - } - } - } - - ModelScreen modelScreen = modelScreenMap.get(screenName); - if (modelScreen == null) { - throw new IllegalArgumentException("Could not find screen with name [" + screenName + "] in webapp resource [" + resourceName + "] in the webapp [" + webappName + "]"); - } - return modelScreen; - } - - public static Map readScreenDocument(Document screenFileDoc, String sourceLocation) { - Map modelScreenMap = new HashMap(); - if (screenFileDoc != null) { - // read document and construct ModelScreen for each screen element - Element rootElement = screenFileDoc.getDocumentElement(); - List screenElements = UtilXml.childElementList(rootElement, "screen"); - for (Element screenElement: screenElements) { - ModelScreen modelScreen = new ModelScreen(screenElement, modelScreenMap, sourceLocation); - //Debug.logInfo("Read Screen with name: " + modelScreen.getName(), module); - modelScreenMap.put(modelScreen.getName(), modelScreen); - } - } - return modelScreenMap; - } - - public static void renderReferencedScreen(String name, String location, ModelScreenWidget parentWidget, Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException, IOException { - // check to see if the name is a composite name separated by a #, if so split it up and get it by the full loc#name - if (ScreenFactory.isCombinedName(name)) { - String combinedName = name; - location = ScreenFactory.getResourceNameFromCombined(combinedName); - name = ScreenFactory.getScreenNameFromCombined(combinedName); - } - - ModelScreen modelScreen = null; - if (UtilValidate.isNotEmpty(location)) { - try { - modelScreen = ScreenFactory.getScreenFromLocation(location, name); - } catch (IOException e) { - String errMsg = "Error rendering included screen named [" + name + "] at location [" + location + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - throw new RuntimeException(errMsg); - } catch (SAXException e) { - String errMsg = "Error rendering included screen named [" + name + "] at location [" + location + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - throw new RuntimeException(errMsg); - } catch (ParserConfigurationException e) { - String errMsg = "Error rendering included screen named [" + name + "] at location [" + location + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - throw new RuntimeException(errMsg); - } - } else { - modelScreen = parentWidget.getModelScreen().getModelScreenMap().get(name); - if (modelScreen == null) { - throw new IllegalArgumentException("Could not find screen with name [" + name + "] in the same file as the screen with name [" + parentWidget.getModelScreen().getName() + "]"); - } - } - //Debug.logInfo("parent(" + parentWidget + ") rendering(" + modelScreen + ")", module); - modelScreen.renderScreenString(writer, context, screenStringRenderer); - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.model; + +import java.io.IOException; +import java.net.URL; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import javax.xml.parsers.ParserConfigurationException; + +import org.ofbiz.base.location.FlexibleLocation; +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.GeneralException; +import org.ofbiz.base.util.UtilHttp; +import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.base.util.UtilXml; +import org.ofbiz.base.util.cache.UtilCache; +import org.ofbiz.widget.renderer.ScreenStringRenderer; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.xml.sax.SAXException; + + +/** + * Widget Library - Screen factory class + */ +public class ScreenFactory { + + public static final String module = ScreenFactory.class.getName(); + + public static final UtilCache> screenLocationCache = UtilCache.createUtilCache("widget.screen.locationResource", 0, 0, false); + public static final UtilCache> screenWebappCache = UtilCache.createUtilCache("widget.screen.webappResource", 0, 0, false); + + public static boolean isCombinedName(String combinedName) { + int numSignIndex = combinedName.lastIndexOf("#"); + if (numSignIndex == -1) { + return false; + } + if (numSignIndex + 1 >= combinedName.length()) { + return false; + } + return true; + } + + public static String getResourceNameFromCombined(String combinedName) { + // split out the name on the last "#" + int numSignIndex = combinedName.lastIndexOf("#"); + if (numSignIndex == -1) { + throw new IllegalArgumentException("Error in screen location/name: no \"#\" found to separate the location from the name; correct example: component://product/screen/product/ProductScreens.xml#EditProduct"); + } + if (numSignIndex + 1 >= combinedName.length()) { + throw new IllegalArgumentException("Error in screen location/name: the \"#\" was at the end with no screen name after it; correct example: component://product/screen/product/ProductScreens.xml#EditProduct"); + } + String resourceName = combinedName.substring(0, numSignIndex); + return resourceName; + } + + public static String getScreenNameFromCombined(String combinedName) { + // split out the name on the last "#" + int numSignIndex = combinedName.lastIndexOf("#"); + if (numSignIndex == -1) { + throw new IllegalArgumentException("Error in screen location/name: no \"#\" found to separate the location from the name; correct example: component://product/screen/product/ProductScreens.xml#EditProduct"); + } + if (numSignIndex + 1 >= combinedName.length()) { + throw new IllegalArgumentException("Error in screen location/name: the \"#\" was at the end with no screen name after it; correct example: component://product/screen/product/ProductScreens.xml#EditProduct"); + } + String screenName = combinedName.substring(numSignIndex + 1); + return screenName; + } + + public static ModelScreen getScreenFromLocation(String combinedName) + throws IOException, SAXException, ParserConfigurationException { + String resourceName = getResourceNameFromCombined(combinedName); + String screenName = getScreenNameFromCombined(combinedName); + return getScreenFromLocation(resourceName, screenName); + } + + public static ModelScreen getScreenFromLocation(String resourceName, String screenName) + throws IOException, SAXException, ParserConfigurationException { + Map modelScreenMap = getScreensFromLocation(resourceName); + ModelScreen modelScreen = modelScreenMap.get(screenName); + if (modelScreen == null) { + throw new IllegalArgumentException("Could not find screen with name [" + screenName + "] in class resource [" + resourceName + "]"); + } + return modelScreen; + } + + public static Map getScreensFromLocation(String resourceName) + throws IOException, SAXException, ParserConfigurationException { + Map modelScreenMap = screenLocationCache.get(resourceName); + if (modelScreenMap == null) { + synchronized (ScreenFactory.class) { + modelScreenMap = screenLocationCache.get(resourceName); + if (modelScreenMap == null) { + long startTime = System.currentTimeMillis(); + URL screenFileUrl = null; + screenFileUrl = FlexibleLocation.resolveLocation(resourceName); + if (screenFileUrl == null) { + throw new IllegalArgumentException("Could not resolve location to URL: " + resourceName); + } + Document screenFileDoc = UtilXml.readXmlDocument(screenFileUrl, true, true); + modelScreenMap = readScreenDocument(screenFileDoc, resourceName); + screenLocationCache.put(resourceName, modelScreenMap); + double totalSeconds = (System.currentTimeMillis() - startTime)/1000.0; + Debug.logInfo("Got " + modelScreenMap.size() + " screens in " + totalSeconds + "s from: " + screenFileUrl.toExternalForm(), module); + } + } + } + + if (modelScreenMap.isEmpty()) { + throw new IllegalArgumentException("Could not find screen file with name [" + resourceName + "]"); + } + return modelScreenMap; + } + + public static ModelScreen getScreenFromWebappContext(String resourceName, String screenName, HttpServletRequest request) + throws IOException, SAXException, ParserConfigurationException { + String webappName = UtilHttp.getApplicationName(request); + String cacheKey = webappName + "::" + resourceName; + + + Map modelScreenMap = screenWebappCache.get(cacheKey); + if (modelScreenMap == null) { + synchronized (ScreenFactory.class) { + modelScreenMap = screenWebappCache.get(cacheKey); + if (modelScreenMap == null) { + ServletContext servletContext = (ServletContext) request.getAttribute("servletContext"); + + URL screenFileUrl = servletContext.getResource(resourceName); + Document screenFileDoc = UtilXml.readXmlDocument(screenFileUrl, true, true); + modelScreenMap = readScreenDocument(screenFileDoc, resourceName); + screenWebappCache.put(cacheKey, modelScreenMap); + } + } + } + + ModelScreen modelScreen = modelScreenMap.get(screenName); + if (modelScreen == null) { + throw new IllegalArgumentException("Could not find screen with name [" + screenName + "] in webapp resource [" + resourceName + "] in the webapp [" + webappName + "]"); + } + return modelScreen; + } + + public static Map readScreenDocument(Document screenFileDoc, String sourceLocation) { + Map modelScreenMap = new HashMap(); + if (screenFileDoc != null) { + // read document and construct ModelScreen for each screen element + Element rootElement = screenFileDoc.getDocumentElement(); + List screenElements = UtilXml.childElementList(rootElement, "screen"); + for (Element screenElement: screenElements) { + ModelScreen modelScreen = new ModelScreen(screenElement, modelScreenMap, sourceLocation); + //Debug.logInfo("Read Screen with name: " + modelScreen.getName(), module); + modelScreenMap.put(modelScreen.getName(), modelScreen); + } + } + return modelScreenMap; + } + + public static void renderReferencedScreen(String name, String location, ModelScreenWidget parentWidget, Appendable writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException, IOException { + // check to see if the name is a composite name separated by a #, if so split it up and get it by the full loc#name + if (ScreenFactory.isCombinedName(name)) { + String combinedName = name; + location = ScreenFactory.getResourceNameFromCombined(combinedName); + name = ScreenFactory.getScreenNameFromCombined(combinedName); + } + + ModelScreen modelScreen = null; + if (UtilValidate.isNotEmpty(location)) { + try { + modelScreen = ScreenFactory.getScreenFromLocation(location, name); + } catch (IOException e) { + String errMsg = "Error rendering included screen named [" + name + "] at location [" + location + "]: " + e.toString(); + Debug.logError(e, errMsg, module); + throw new RuntimeException(errMsg); + } catch (SAXException e) { + String errMsg = "Error rendering included screen named [" + name + "] at location [" + location + "]: " + e.toString(); + Debug.logError(e, errMsg, module); + throw new RuntimeException(errMsg); + } catch (ParserConfigurationException e) { + String errMsg = "Error rendering included screen named [" + name + "] at location [" + location + "]: " + e.toString(); + Debug.logError(e, errMsg, module); + throw new RuntimeException(errMsg); + } + } else { + modelScreen = parentWidget.getModelScreen().getModelScreenMap().get(name); + if (modelScreen == null) { + throw new IllegalArgumentException("Could not find screen with name [" + name + "] in the same file as the screen with name [" + parentWidget.getModelScreen().getName() + "]"); + } + } + //Debug.logInfo("parent(" + parentWidget + ") rendering(" + modelScreen + ")", module); + modelScreen.renderScreenString(writer, context, screenStringRenderer); + } +} diff --git a/framework/widget/src/org/ofbiz/widget/tree/TreeFactory.java b/framework/widget/src/org/ofbiz/widget/model/TreeFactory.java similarity index 97% rename from framework/widget/src/org/ofbiz/widget/tree/TreeFactory.java rename to framework/widget/src/org/ofbiz/widget/model/TreeFactory.java index 9e64caeefe..7772e7f709 100644 --- a/framework/widget/src/org/ofbiz/widget/tree/TreeFactory.java +++ b/framework/widget/src/org/ofbiz/widget/model/TreeFactory.java @@ -1,87 +1,87 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget.tree; - -import java.io.IOException; -import java.net.URL; -import java.util.HashMap; -import java.util.Map; - -import javax.xml.parsers.ParserConfigurationException; - -import org.ofbiz.base.location.FlexibleLocation; -import org.ofbiz.base.util.UtilXml; -import org.ofbiz.base.util.cache.UtilCache; -import org.ofbiz.entity.Delegator; -import org.ofbiz.service.LocalDispatcher; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.xml.sax.SAXException; - - -/** - * Widget Library - Tree factory class - */ -public class TreeFactory { - - public static final String module = TreeFactory.class.getName(); - - public static final UtilCache> treeLocationCache = UtilCache.createUtilCache("widget.tree.locationResource", 0, 0, false); - - public static ModelTree getTreeFromLocation(String resourceName, String treeName, Delegator delegator, LocalDispatcher dispatcher) - throws IOException, SAXException, ParserConfigurationException { - Map modelTreeMap = treeLocationCache.get(resourceName); - if (modelTreeMap == null) { - synchronized (TreeFactory.class) { - modelTreeMap = treeLocationCache.get(resourceName); - if (modelTreeMap == null) { - ClassLoader loader = Thread.currentThread().getContextClassLoader(); - if (loader == null) { - loader = TreeFactory.class.getClassLoader(); - } - - URL treeFileUrl = null; - treeFileUrl = FlexibleLocation.resolveLocation(resourceName); //, loader); - Document treeFileDoc = UtilXml.readXmlDocument(treeFileUrl, true, true); - modelTreeMap = readTreeDocument(treeFileDoc, delegator, dispatcher, resourceName); - treeLocationCache.put(resourceName, modelTreeMap); - } - } - } - - ModelTree modelTree = modelTreeMap.get(treeName); - if (modelTree == null) { - throw new IllegalArgumentException("Could not find tree with name [" + treeName + "] in class resource [" + resourceName + "]"); - } - return modelTree; - } - - public static Map readTreeDocument(Document treeFileDoc, Delegator delegator, LocalDispatcher dispatcher, String treeLocation) { - Map modelTreeMap = new HashMap(); - if (treeFileDoc != null) { - // read document and construct ModelTree for each tree element - Element rootElement = treeFileDoc.getDocumentElement(); - for (Element treeElement: UtilXml.childElementList(rootElement, "tree")) { - ModelTree modelTree = new ModelTree(treeElement, treeLocation); - modelTreeMap.put(modelTree.getName(), modelTree); - } - } - return modelTreeMap; - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.model; + +import java.io.IOException; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; + +import javax.xml.parsers.ParserConfigurationException; + +import org.ofbiz.base.location.FlexibleLocation; +import org.ofbiz.base.util.UtilXml; +import org.ofbiz.base.util.cache.UtilCache; +import org.ofbiz.entity.Delegator; +import org.ofbiz.service.LocalDispatcher; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.xml.sax.SAXException; + + +/** + * Widget Library - Tree factory class + */ +public class TreeFactory { + + public static final String module = TreeFactory.class.getName(); + + public static final UtilCache> treeLocationCache = UtilCache.createUtilCache("widget.tree.locationResource", 0, 0, false); + + public static ModelTree getTreeFromLocation(String resourceName, String treeName, Delegator delegator, LocalDispatcher dispatcher) + throws IOException, SAXException, ParserConfigurationException { + Map modelTreeMap = treeLocationCache.get(resourceName); + if (modelTreeMap == null) { + synchronized (TreeFactory.class) { + modelTreeMap = treeLocationCache.get(resourceName); + if (modelTreeMap == null) { + ClassLoader loader = Thread.currentThread().getContextClassLoader(); + if (loader == null) { + loader = TreeFactory.class.getClassLoader(); + } + + URL treeFileUrl = null; + treeFileUrl = FlexibleLocation.resolveLocation(resourceName); //, loader); + Document treeFileDoc = UtilXml.readXmlDocument(treeFileUrl, true, true); + modelTreeMap = readTreeDocument(treeFileDoc, delegator, dispatcher, resourceName); + treeLocationCache.put(resourceName, modelTreeMap); + } + } + } + + ModelTree modelTree = modelTreeMap.get(treeName); + if (modelTree == null) { + throw new IllegalArgumentException("Could not find tree with name [" + treeName + "] in class resource [" + resourceName + "]"); + } + return modelTree; + } + + public static Map readTreeDocument(Document treeFileDoc, Delegator delegator, LocalDispatcher dispatcher, String treeLocation) { + Map modelTreeMap = new HashMap(); + if (treeFileDoc != null) { + // read document and construct ModelTree for each tree element + Element rootElement = treeFileDoc.getDocumentElement(); + for (Element treeElement: UtilXml.childElementList(rootElement, "tree")) { + ModelTree modelTree = new ModelTree(treeElement, treeLocation); + modelTreeMap.put(modelTree.getName(), modelTree); + } + } + return modelTreeMap; + } +} diff --git a/framework/widget/src/org/ofbiz/widget/xml/AbstractWidgetVisitor.java b/framework/widget/src/org/ofbiz/widget/model/XmlAbstractWidgetVisitor.java similarity index 91% rename from framework/widget/src/org/ofbiz/widget/xml/AbstractWidgetVisitor.java rename to framework/widget/src/org/ofbiz/widget/model/XmlAbstractWidgetVisitor.java index 66d92ad29c..86d6e5d053 100644 --- a/framework/widget/src/org/ofbiz/widget/xml/AbstractWidgetVisitor.java +++ b/framework/widget/src/org/ofbiz/widget/model/XmlAbstractWidgetVisitor.java @@ -16,29 +16,28 @@ * specific language governing permissions and limitations * under the License. *******************************************************************************/ -package org.ofbiz.widget.xml; +package org.ofbiz.widget.model; import java.util.Collection; import org.ofbiz.base.util.Assert; import org.ofbiz.base.util.collections.FlexibleMapAccessor; import org.ofbiz.base.util.string.FlexibleStringExpander; -import org.ofbiz.widget.ModelWidget; -import org.ofbiz.widget.CommonWidgetModels.AutoEntityParameters; -import org.ofbiz.widget.CommonWidgetModels.AutoServiceParameters; -import org.ofbiz.widget.CommonWidgetModels.Image; -import org.ofbiz.widget.CommonWidgetModels.Link; -import org.ofbiz.widget.CommonWidgetModels.Parameter; +import org.ofbiz.widget.model.CommonWidgetModels.AutoEntityParameters; +import org.ofbiz.widget.model.CommonWidgetModels.AutoServiceParameters; +import org.ofbiz.widget.model.CommonWidgetModels.Image; +import org.ofbiz.widget.model.CommonWidgetModels.Link; +import org.ofbiz.widget.model.CommonWidgetModels.Parameter; /** * Abstract XML widget visitor. * */ -public abstract class AbstractWidgetVisitor { +public abstract class XmlAbstractWidgetVisitor { protected final Appendable writer; - public AbstractWidgetVisitor(Appendable writer) { + public XmlAbstractWidgetVisitor(Appendable writer) { Assert.notNull("writer", writer); this.writer = writer; } diff --git a/framework/widget/src/org/ofbiz/widget/xml/XmlWidgetActionVisitor.java b/framework/widget/src/org/ofbiz/widget/model/XmlWidgetActionVisitor.java similarity index 82% rename from framework/widget/src/org/ofbiz/widget/xml/XmlWidgetActionVisitor.java rename to framework/widget/src/org/ofbiz/widget/model/XmlWidgetActionVisitor.java index bfc76d3d46..540127e164 100644 --- a/framework/widget/src/org/ofbiz/widget/xml/XmlWidgetActionVisitor.java +++ b/framework/widget/src/org/ofbiz/widget/model/XmlWidgetActionVisitor.java @@ -16,20 +16,19 @@ * specific language governing permissions and limitations * under the License. *******************************************************************************/ -package org.ofbiz.widget.xml; +package org.ofbiz.widget.model; -import org.ofbiz.widget.AbstractModelAction.EntityAnd; -import org.ofbiz.widget.AbstractModelAction.EntityCondition; -import org.ofbiz.widget.AbstractModelAction.EntityOne; -import org.ofbiz.widget.AbstractModelAction.GetRelated; -import org.ofbiz.widget.AbstractModelAction.GetRelatedOne; -import org.ofbiz.widget.AbstractModelAction.PropertyMap; -import org.ofbiz.widget.AbstractModelAction.PropertyToField; -import org.ofbiz.widget.AbstractModelAction.Script; -import org.ofbiz.widget.AbstractModelAction.Service; -import org.ofbiz.widget.AbstractModelAction.SetField; -import org.ofbiz.widget.ModelActionVisitor; -import org.ofbiz.widget.form.ModelFormAction.CallParentActions; +import org.ofbiz.widget.model.AbstractModelAction.EntityAnd; +import org.ofbiz.widget.model.AbstractModelAction.EntityCondition; +import org.ofbiz.widget.model.AbstractModelAction.EntityOne; +import org.ofbiz.widget.model.AbstractModelAction.GetRelated; +import org.ofbiz.widget.model.AbstractModelAction.GetRelatedOne; +import org.ofbiz.widget.model.AbstractModelAction.PropertyMap; +import org.ofbiz.widget.model.AbstractModelAction.PropertyToField; +import org.ofbiz.widget.model.AbstractModelAction.Script; +import org.ofbiz.widget.model.AbstractModelAction.Service; +import org.ofbiz.widget.model.AbstractModelAction.SetField; +import org.ofbiz.widget.model.ModelFormAction.CallParentActions; /** * An object that generates XML from widget models. @@ -37,7 +36,7 @@ import org.ofbiz.widget.form.ModelFormAction.CallParentActions; * "pretty print" the XML, then use a transformer. * */ -public class XmlWidgetActionVisitor extends AbstractWidgetVisitor implements ModelActionVisitor { +public class XmlWidgetActionVisitor extends XmlAbstractWidgetVisitor implements ModelActionVisitor { public static final String module = XmlWidgetActionVisitor.class.getName(); @@ -57,7 +56,7 @@ public class XmlWidgetActionVisitor extends AbstractWidgetVisitor implements Mod } @Override - public void visit(org.ofbiz.widget.tree.ModelTreeAction.EntityAnd entityAnd) throws Exception { + public void visit(org.ofbiz.widget.model.ModelTreeAction.EntityAnd entityAnd) throws Exception { writer.append(""); // TODO: Create ByAndFinder visitor } @@ -69,7 +68,7 @@ public class XmlWidgetActionVisitor extends AbstractWidgetVisitor implements Mod } @Override - public void visit(org.ofbiz.widget.tree.ModelTreeAction.EntityCondition entityCondition) throws Exception { + public void visit(org.ofbiz.widget.model.ModelTreeAction.EntityCondition entityCondition) throws Exception { writer.append(""); // TODO: Create ByConditionFinder visitor } @@ -133,7 +132,7 @@ public class XmlWidgetActionVisitor extends AbstractWidgetVisitor implements Mod } @Override - public void visit(org.ofbiz.widget.tree.ModelTreeAction.Script script) throws Exception { + public void visit(org.ofbiz.widget.model.ModelTreeAction.Script script) throws Exception { writer.append(""); } diff --git a/framework/widget/src/org/ofbiz/widget/PortalPageWorker.java b/framework/widget/src/org/ofbiz/widget/portal/PortalPageWorker.java similarity index 97% rename from framework/widget/src/org/ofbiz/widget/PortalPageWorker.java rename to framework/widget/src/org/ofbiz/widget/portal/PortalPageWorker.java index 506120855c..7225b06680 100644 --- a/framework/widget/src/org/ofbiz/widget/PortalPageWorker.java +++ b/framework/widget/src/org/ofbiz/widget/portal/PortalPageWorker.java @@ -1,176 +1,177 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.GeneralException; -import org.ofbiz.base.util.UtilMisc; -import org.ofbiz.base.util.UtilValidate; -import org.ofbiz.entity.Delegator; -import org.ofbiz.entity.GenericEntityException; -import org.ofbiz.entity.GenericValue; -import org.ofbiz.entity.condition.EntityCondition; -import org.ofbiz.entity.condition.EntityOperator; -import org.ofbiz.entity.util.EntityQuery; -import org.ofbiz.entity.util.EntityUtil; -import org.ofbiz.security.Security; - -/** - * PortalPageWorker Class - */ -public class PortalPageWorker { - - public static final String module = PortalPageWorker.class.getName(); - - public PortalPageWorker() { } - - public String renderPortalPageAsTextExt(Delegator delegator, String portalPageId, Map templateContext, - boolean cache) throws GeneralException, IOException { - return "success"; - } - - /** - * Returns a list of PortalPages that have the specified parentPortalPageId as parent. - * If a specific PortalPage exists for the current userLogin it is returned instead of the original one. - */ - public static List getPortalPages(String parentPortalPageId, Map context) { - List portalPages = null; - if (UtilValidate.isNotEmpty(parentPortalPageId)) { - Delegator delegator = WidgetWorker.getDelegator(context); - try { - // first get public pages - EntityCondition cond = - EntityCondition.makeCondition(UtilMisc.toList( - EntityCondition.makeCondition("ownerUserLoginId", EntityOperator.EQUALS, "_NA_"), - EntityCondition.makeCondition(UtilMisc.toList( - EntityCondition.makeCondition("portalPageId", EntityOperator.EQUALS, parentPortalPageId), - EntityCondition.makeCondition("parentPortalPageId", EntityOperator.EQUALS, parentPortalPageId)), - EntityOperator.OR)), - EntityOperator.AND); - portalPages = EntityQuery.use(delegator).from("PortalPage").where(cond).queryList(); - List userPortalPages = new ArrayList(); - if (UtilValidate.isNotEmpty(context.get("userLogin"))) { // check if a user is logged in - String userLoginId = ((GenericValue)context.get("userLogin")).getString("userLoginId"); - // replace with private pages - for (GenericValue portalPage : portalPages) { - List privatePortalPages = EntityQuery.use(delegator) - .from("PortalPage") - .where("ownerUserLoginId", userLoginId, "originalPortalPageId", portalPage.getString("portalPageId")) - .queryList(); - if (UtilValidate.isNotEmpty(privatePortalPages)) { - userPortalPages.add(privatePortalPages.get(0)); - } else { - userPortalPages.add(portalPage); - } - } - // add any other created private pages - userPortalPages.addAll(EntityQuery.use(delegator) - .from("PortalPage") - .where("ownerUserLoginId", userLoginId, "originalPortalPageId", null, "parentPortalPageId", parentPortalPageId) - .queryList()); - } - portalPages = EntityUtil.orderBy(userPortalPages, UtilMisc.toList("sequenceNum")); - } catch (GenericEntityException e) { - Debug.logError("Could not retrieve portalpages:" + e.getMessage(), module); - } - } - return portalPages; - } - - /** - * Returns the PortalPage with the specified portalPageId. - * If a specific PortalPage exists for the current userLogin it is returned instead of the original one. - */ - public static GenericValue getPortalPage(String portalPageId, Map context) { - GenericValue portalPage = null; - if (UtilValidate.isNotEmpty(portalPageId)) { - Delegator delegator = WidgetWorker.getDelegator(context); - try { - // Get the current userLoginId - String userLoginId = "_NA_"; - if (UtilValidate.isNotEmpty(context.get("userLogin"))) { // check if a user is logged in - userLoginId = ((GenericValue)context.get("userLogin")).getString("userLoginId"); - } - - // Get the PortalPage ensuring that it is either owned by the user or a system page - EntityCondition cond = EntityCondition.makeCondition(UtilMisc.toList( - EntityCondition.makeCondition("portalPageId", EntityOperator.EQUALS, portalPageId), - EntityCondition.makeCondition(UtilMisc.toList( - EntityCondition.makeCondition("ownerUserLoginId", EntityOperator.EQUALS, "_NA_"), - EntityCondition.makeCondition("ownerUserLoginId", EntityOperator.EQUALS, userLoginId)), - EntityOperator.OR)), - EntityOperator.AND); - List portalPages = EntityQuery.use(delegator).from("PortalPage").where(cond).queryList(); - if (UtilValidate.isNotEmpty(portalPages)) { - portalPage = EntityUtil.getFirst(portalPages); - } - - // If a derived PortalPage private to the user exists, returns this instead of the system one - cond = EntityCondition.makeCondition(UtilMisc.toList( - EntityCondition.makeCondition("originalPortalPageId", EntityOperator.EQUALS, portalPageId), - EntityCondition.makeCondition("ownerUserLoginId", EntityOperator.EQUALS, userLoginId)), - EntityOperator.AND); - List privateDerivedPortalPages = EntityQuery.use(delegator).from("PortalPage").where(cond).queryList(); - if (UtilValidate.isNotEmpty(privateDerivedPortalPages)) { - portalPage = EntityUtil.getFirst(privateDerivedPortalPages); - } - } catch (GenericEntityException e) { - Debug.logError("Could not retrieve portalpage:" + e.getMessage(), module); - } - } - return portalPage; - } - - /** - * Checks if the user is allowed to configure the PortalPage. - * PortalPage configuration is allowed if he is the PortalPage owner or he has got the PORTALPAGE_ADMIN permission - */ - public static Boolean userIsAllowedToConfigure(String portalPageId, Map context) { - Boolean userIsAllowed = false; - - if (UtilValidate.isNotEmpty(portalPageId)) { - GenericValue userLogin = (GenericValue) context.get("userLogin"); - if (UtilValidate.isNotEmpty(userLogin)) { - String userLoginId = (String) userLogin.get("userLoginId"); - Security security = (Security) context.get("security"); - - Boolean hasPortalAdminPermission = security.hasPermission("PORTALPAGE_ADMIN", userLogin); - try { - Delegator delegator = WidgetWorker.getDelegator(context); - GenericValue portalPage = EntityQuery.use(delegator).from("PortalPage").where("portalPageId", portalPageId).queryOne(); - if (UtilValidate.isNotEmpty(portalPage)) { - String ownerUserLoginId = (String) portalPage.get("ownerUserLoginId"); - // Users with PORTALPAGE_ADMIN permission can configure every Portal Page - userIsAllowed = (ownerUserLoginId.equals(userLoginId) || hasPortalAdminPermission); - } - } catch (GenericEntityException e) { - return false; - } - } - } - - return userIsAllowed; - } - -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.portal; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.GeneralException; +import org.ofbiz.base.util.UtilMisc; +import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.entity.Delegator; +import org.ofbiz.entity.GenericEntityException; +import org.ofbiz.entity.GenericValue; +import org.ofbiz.entity.condition.EntityCondition; +import org.ofbiz.entity.condition.EntityOperator; +import org.ofbiz.entity.util.EntityQuery; +import org.ofbiz.entity.util.EntityUtil; +import org.ofbiz.security.Security; +import org.ofbiz.widget.WidgetWorker; + +/** + * PortalPageWorker Class + */ +public class PortalPageWorker { + + public static final String module = PortalPageWorker.class.getName(); + + public PortalPageWorker() { } + + public String renderPortalPageAsTextExt(Delegator delegator, String portalPageId, Map templateContext, + boolean cache) throws GeneralException, IOException { + return "success"; + } + + /** + * Returns a list of PortalPages that have the specified parentPortalPageId as parent. + * If a specific PortalPage exists for the current userLogin it is returned instead of the original one. + */ + public static List getPortalPages(String parentPortalPageId, Map context) { + List portalPages = null; + if (UtilValidate.isNotEmpty(parentPortalPageId)) { + Delegator delegator = WidgetWorker.getDelegator(context); + try { + // first get public pages + EntityCondition cond = + EntityCondition.makeCondition(UtilMisc.toList( + EntityCondition.makeCondition("ownerUserLoginId", EntityOperator.EQUALS, "_NA_"), + EntityCondition.makeCondition(UtilMisc.toList( + EntityCondition.makeCondition("portalPageId", EntityOperator.EQUALS, parentPortalPageId), + EntityCondition.makeCondition("parentPortalPageId", EntityOperator.EQUALS, parentPortalPageId)), + EntityOperator.OR)), + EntityOperator.AND); + portalPages = EntityQuery.use(delegator).from("PortalPage").where(cond).queryList(); + List userPortalPages = new ArrayList(); + if (UtilValidate.isNotEmpty(context.get("userLogin"))) { // check if a user is logged in + String userLoginId = ((GenericValue)context.get("userLogin")).getString("userLoginId"); + // replace with private pages + for (GenericValue portalPage : portalPages) { + List privatePortalPages = EntityQuery.use(delegator) + .from("PortalPage") + .where("ownerUserLoginId", userLoginId, "originalPortalPageId", portalPage.getString("portalPageId")) + .queryList(); + if (UtilValidate.isNotEmpty(privatePortalPages)) { + userPortalPages.add(privatePortalPages.get(0)); + } else { + userPortalPages.add(portalPage); + } + } + // add any other created private pages + userPortalPages.addAll(EntityQuery.use(delegator) + .from("PortalPage") + .where("ownerUserLoginId", userLoginId, "originalPortalPageId", null, "parentPortalPageId", parentPortalPageId) + .queryList()); + } + portalPages = EntityUtil.orderBy(userPortalPages, UtilMisc.toList("sequenceNum")); + } catch (GenericEntityException e) { + Debug.logError("Could not retrieve portalpages:" + e.getMessage(), module); + } + } + return portalPages; + } + + /** + * Returns the PortalPage with the specified portalPageId. + * If a specific PortalPage exists for the current userLogin it is returned instead of the original one. + */ + public static GenericValue getPortalPage(String portalPageId, Map context) { + GenericValue portalPage = null; + if (UtilValidate.isNotEmpty(portalPageId)) { + Delegator delegator = WidgetWorker.getDelegator(context); + try { + // Get the current userLoginId + String userLoginId = "_NA_"; + if (UtilValidate.isNotEmpty(context.get("userLogin"))) { // check if a user is logged in + userLoginId = ((GenericValue)context.get("userLogin")).getString("userLoginId"); + } + + // Get the PortalPage ensuring that it is either owned by the user or a system page + EntityCondition cond = EntityCondition.makeCondition(UtilMisc.toList( + EntityCondition.makeCondition("portalPageId", EntityOperator.EQUALS, portalPageId), + EntityCondition.makeCondition(UtilMisc.toList( + EntityCondition.makeCondition("ownerUserLoginId", EntityOperator.EQUALS, "_NA_"), + EntityCondition.makeCondition("ownerUserLoginId", EntityOperator.EQUALS, userLoginId)), + EntityOperator.OR)), + EntityOperator.AND); + List portalPages = EntityQuery.use(delegator).from("PortalPage").where(cond).queryList(); + if (UtilValidate.isNotEmpty(portalPages)) { + portalPage = EntityUtil.getFirst(portalPages); + } + + // If a derived PortalPage private to the user exists, returns this instead of the system one + cond = EntityCondition.makeCondition(UtilMisc.toList( + EntityCondition.makeCondition("originalPortalPageId", EntityOperator.EQUALS, portalPageId), + EntityCondition.makeCondition("ownerUserLoginId", EntityOperator.EQUALS, userLoginId)), + EntityOperator.AND); + List privateDerivedPortalPages = EntityQuery.use(delegator).from("PortalPage").where(cond).queryList(); + if (UtilValidate.isNotEmpty(privateDerivedPortalPages)) { + portalPage = EntityUtil.getFirst(privateDerivedPortalPages); + } + } catch (GenericEntityException e) { + Debug.logError("Could not retrieve portalpage:" + e.getMessage(), module); + } + } + return portalPage; + } + + /** + * Checks if the user is allowed to configure the PortalPage. + * PortalPage configuration is allowed if he is the PortalPage owner or he has got the PORTALPAGE_ADMIN permission + */ + public static Boolean userIsAllowedToConfigure(String portalPageId, Map context) { + Boolean userIsAllowed = false; + + if (UtilValidate.isNotEmpty(portalPageId)) { + GenericValue userLogin = (GenericValue) context.get("userLogin"); + if (UtilValidate.isNotEmpty(userLogin)) { + String userLoginId = (String) userLogin.get("userLoginId"); + Security security = (Security) context.get("security"); + + Boolean hasPortalAdminPermission = security.hasPermission("PORTALPAGE_ADMIN", userLogin); + try { + Delegator delegator = WidgetWorker.getDelegator(context); + GenericValue portalPage = EntityQuery.use(delegator).from("PortalPage").where("portalPageId", portalPageId).queryOne(); + if (UtilValidate.isNotEmpty(portalPage)) { + String ownerUserLoginId = (String) portalPage.get("ownerUserLoginId"); + // Users with PORTALPAGE_ADMIN permission can configure every Portal Page + userIsAllowed = (ownerUserLoginId.equals(userLoginId) || hasPortalAdminPermission); + } + } catch (GenericEntityException e) { + return false; + } + } + } + + return userIsAllowed; + } + +} diff --git a/framework/widget/src/org/ofbiz/widget/PortalPageWorkerInterface.java b/framework/widget/src/org/ofbiz/widget/portal/PortalPageWorkerInterface.java similarity index 95% rename from framework/widget/src/org/ofbiz/widget/PortalPageWorkerInterface.java rename to framework/widget/src/org/ofbiz/widget/portal/PortalPageWorkerInterface.java index 3cc1d87f18..bc60a5b5af 100644 --- a/framework/widget/src/org/ofbiz/widget/PortalPageWorkerInterface.java +++ b/framework/widget/src/org/ofbiz/widget/portal/PortalPageWorkerInterface.java @@ -1,33 +1,33 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget; - -import java.io.IOException; -import java.util.Map; - -import org.ofbiz.base.util.GeneralException; -import org.ofbiz.entity.Delegator; - -/** - * PortalPageWorkerInterface - */ -public interface PortalPageWorkerInterface { - public String renderPortalPageAsTextExt(Delegator delegator, String portalPageId, Map templateContext, - boolean cache) throws GeneralException, IOException; -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.portal; + +import java.io.IOException; +import java.util.Map; + +import org.ofbiz.base.util.GeneralException; +import org.ofbiz.entity.Delegator; + +/** + * PortalPageWorkerInterface + */ +public interface PortalPageWorkerInterface { + public String renderPortalPageAsTextExt(Delegator delegator, String portalPageId, Map templateContext, + boolean cache) throws GeneralException, IOException; +} diff --git a/framework/widget/src/org/ofbiz/widget/WidgetPortalPageWorker.java b/framework/widget/src/org/ofbiz/widget/portal/WidgetPortalPageWorker.java similarity index 92% rename from framework/widget/src/org/ofbiz/widget/WidgetPortalPageWorker.java rename to framework/widget/src/org/ofbiz/widget/portal/WidgetPortalPageWorker.java index 8b942a3ca4..66dd28d383 100644 --- a/framework/widget/src/org/ofbiz/widget/WidgetPortalPageWorker.java +++ b/framework/widget/src/org/ofbiz/widget/portal/WidgetPortalPageWorker.java @@ -1,41 +1,42 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget; -import org.ofbiz.base.util.Debug; - -/** - * PortalPageWorker Class - */ -public class WidgetPortalPageWorker { - public static final String module = WidgetPortalPageWorker.class.getName(); - public static PortalPageWorkerInterface portalPageWorker = null; - static { - try { - ClassLoader loader = Thread.currentThread().getContextClassLoader(); - // note: loadClass is necessary for these since this class doesn't know anything about them at compile time - portalPageWorker = (PortalPageWorkerInterface) loader.loadClass("org.ofbiz.widget.PortalPageWorker").newInstance(); - } catch (ClassNotFoundException e) { - Debug.logError(e, "Could not pre-initialize dynamically loaded class: ", module); - } catch (IllegalAccessException e) { - Debug.logError(e, "Could not pre-initialize dynamically loaded class: ", module); - } catch (InstantiationException e) { - Debug.logError(e, "Could not pre-initialize dynamically loaded class: ", module); - } - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.portal; + +import org.ofbiz.base.util.Debug; + +/** + * PortalPageWorker Class + */ +public class WidgetPortalPageWorker { + public static final String module = WidgetPortalPageWorker.class.getName(); + public static PortalPageWorkerInterface portalPageWorker = null; + static { + try { + ClassLoader loader = Thread.currentThread().getContextClassLoader(); + // note: loadClass is necessary for these since this class doesn't know anything about them at compile time + portalPageWorker = (PortalPageWorkerInterface) loader.loadClass("org.ofbiz.widget.portal.PortalPageWorker").newInstance(); + } catch (ClassNotFoundException e) { + Debug.logError(e, "Could not pre-initialize dynamically loaded class: ", module); + } catch (IllegalAccessException e) { + Debug.logError(e, "Could not pre-initialize dynamically loaded class: ", module); + } catch (InstantiationException e) { + Debug.logError(e, "Could not pre-initialize dynamically loaded class: ", module); + } + } +} diff --git a/framework/widget/src/org/ofbiz/widget/form/FormRenderer.java b/framework/widget/src/org/ofbiz/widget/renderer/FormRenderer.java similarity index 97% rename from framework/widget/src/org/ofbiz/widget/form/FormRenderer.java rename to framework/widget/src/org/ofbiz/widget/renderer/FormRenderer.java index c4619d1ee5..f257c782b1 100644 --- a/framework/widget/src/org/ofbiz/widget/form/FormRenderer.java +++ b/framework/widget/src/org/ofbiz/widget/renderer/FormRenderer.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. *******************************************************************************/ -package org.ofbiz.widget.form; +package org.ofbiz.widget.renderer; import java.io.IOException; import java.util.ArrayList; @@ -41,10 +41,13 @@ import org.ofbiz.base.util.string.FlexibleStringExpander; import org.ofbiz.entity.GenericEntity; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.util.EntityListIterator; -import org.ofbiz.widget.AbstractModelAction; import org.ofbiz.widget.WidgetWorker; -import org.ofbiz.widget.form.ModelForm.FieldGroup; -import org.ofbiz.widget.form.ModelForm.FieldGroupBase; +import org.ofbiz.widget.model.AbstractModelAction; +import org.ofbiz.widget.model.FieldInfo; +import org.ofbiz.widget.model.ModelForm; +import org.ofbiz.widget.model.ModelForm.FieldGroup; +import org.ofbiz.widget.model.ModelForm.FieldGroupBase; +import org.ofbiz.widget.model.ModelFormField; /** * A form rendering engine. diff --git a/framework/widget/src/org/ofbiz/widget/form/FormStringRenderer.java b/framework/widget/src/org/ofbiz/widget/renderer/FormStringRenderer.java similarity index 97% rename from framework/widget/src/org/ofbiz/widget/form/FormStringRenderer.java rename to framework/widget/src/org/ofbiz/widget/renderer/FormStringRenderer.java index 487d8949dd..9f648599e9 100644 --- a/framework/widget/src/org/ofbiz/widget/form/FormStringRenderer.java +++ b/framework/widget/src/org/ofbiz/widget/renderer/FormStringRenderer.java @@ -1,96 +1,99 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget.form; - -import java.io.IOException; -import java.util.Map; - -/** - * Widget Library - Form String Renderer interface. - */ -public interface FormStringRenderer { - public void renderDisplayField(Appendable writer, Map context, ModelFormField.DisplayField displayField) throws IOException; - public void renderHyperlinkField(Appendable writer, Map context, ModelFormField.HyperlinkField hyperlinkField) throws IOException; - - public void renderTextField(Appendable writer, Map context, ModelFormField.TextField textField) throws IOException; - public void renderTextareaField(Appendable writer, Map context, ModelFormField.TextareaField textareaField) throws IOException; - public void renderDateTimeField(Appendable writer, Map context, ModelFormField.DateTimeField dateTimeField) throws IOException; - - public void renderDropDownField(Appendable writer, Map context, ModelFormField.DropDownField dropDownField) throws IOException; - public void renderCheckField(Appendable writer, Map context, ModelFormField.CheckField checkField) throws IOException; - public void renderRadioField(Appendable writer, Map context, ModelFormField.RadioField radioField) throws IOException; - - public void renderSubmitField(Appendable writer, Map context, ModelFormField.SubmitField submitField) throws IOException; - public void renderResetField(Appendable writer, Map context, ModelFormField.ResetField resetField) throws IOException; - - public void renderHiddenField(Appendable writer, Map context, ModelFormField modelFormField, String value) throws IOException; - public void renderHiddenField(Appendable writer, Map context, ModelFormField.HiddenField hiddenField) throws IOException; - public void renderIgnoredField(Appendable writer, Map context, ModelFormField.IgnoredField ignoredField) throws IOException; - - public void renderFieldTitle(Appendable writer, Map context, ModelFormField modelFormField) throws IOException; - public void renderSingleFormFieldTitle(Appendable writer, Map context, ModelFormField modelFormField) throws IOException; - - public void renderFormOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException; - public void renderFormClose(Appendable writer, Map context, ModelForm modelForm) throws IOException; - public void renderMultiFormClose(Appendable writer, Map context, ModelForm modelForm) throws IOException; - - public void renderFormatListWrapperOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException; - public void renderFormatListWrapperClose(Appendable writer, Map context, ModelForm modelForm) throws IOException; - - public void renderFormatHeaderRowOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException; - public void renderFormatHeaderRowClose(Appendable writer, Map context, ModelForm modelForm) throws IOException; - public void renderFormatHeaderRowCellOpen(Appendable writer, Map context, ModelForm modelForm, ModelFormField modelFormField, int positionSpan) throws IOException; - public void renderFormatHeaderRowCellClose(Appendable writer, Map context, ModelForm modelForm, ModelFormField modelFormField) throws IOException; - - public void renderFormatHeaderRowFormCellOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException; - public void renderFormatHeaderRowFormCellClose(Appendable writer, Map context, ModelForm modelForm) throws IOException; - public void renderFormatHeaderRowFormCellTitleSeparator(Appendable writer, Map context, ModelForm modelForm, ModelFormField modelFormField, boolean isLast) throws IOException; - - public void renderFormatItemRowOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException; - public void renderFormatItemRowClose(Appendable writer, Map context, ModelForm modelForm) throws IOException; - public void renderFormatItemRowCellOpen(Appendable writer, Map context, ModelForm modelForm, ModelFormField modelFormField, int positionSpan) throws IOException; - public void renderFormatItemRowCellClose(Appendable writer, Map context, ModelForm modelForm, ModelFormField modelFormField) throws IOException; - public void renderFormatItemRowFormCellOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException; - public void renderFormatItemRowFormCellClose(Appendable writer, Map context, ModelForm modelForm) throws IOException; - - public void renderFormatSingleWrapperOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException; - public void renderFormatSingleWrapperClose(Appendable writer, Map context, ModelForm modelForm) throws IOException; - - public void renderFormatFieldRowOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException; - public void renderFormatFieldRowClose(Appendable writer, Map context, ModelForm modelForm) throws IOException; - public void renderFormatFieldRowTitleCellOpen(Appendable writer, Map context, ModelFormField modelFormField) throws IOException; - public void renderFormatFieldRowTitleCellClose(Appendable writer, Map context, ModelFormField modelFormField) throws IOException; - public void renderFormatFieldRowSpacerCell(Appendable writer, Map context, ModelFormField modelFormField) throws IOException; - public void renderFormatFieldRowWidgetCellOpen(Appendable writer, Map context, ModelFormField modelFormField, int positions, int positionSpan, Integer nextPositionInRow) throws IOException; - public void renderFormatFieldRowWidgetCellClose(Appendable writer, Map context, ModelFormField modelFormField, int positions, int positionSpan, Integer nextPositionInRow) throws IOException; - - public void renderFormatEmptySpace(Appendable writer, Map context, ModelForm modelForm) throws IOException; - - public void renderTextFindField(Appendable writer, Map context, ModelFormField.TextFindField textField) throws IOException; - public void renderDateFindField(Appendable writer, Map context, ModelFormField.DateFindField textField) throws IOException; - public void renderRangeFindField(Appendable writer, Map context, ModelFormField.RangeFindField textField) throws IOException; - public void renderLookupField(Appendable writer, Map context, ModelFormField.LookupField textField) throws IOException; - public void renderFileField(Appendable writer, Map context, ModelFormField.FileField textField) throws IOException; - public void renderPasswordField(Appendable writer, Map context, ModelFormField.PasswordField textField) throws IOException; - public void renderImageField(Appendable writer, Map context, ModelFormField.ImageField textField) throws IOException; - public void renderBanner(Appendable writer, Map context, ModelForm.Banner banner) throws IOException; - public void renderContainerFindField(Appendable writer, Map context, ModelFormField.ContainerField containerField) throws IOException; - public void renderFieldGroupOpen(Appendable writer, Map context, ModelForm.FieldGroup fieldGroup) throws IOException; - public void renderFieldGroupClose(Appendable writer, Map context, ModelForm.FieldGroup fieldGroup) throws IOException; -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.renderer; + +import java.io.IOException; +import java.util.Map; + +import org.ofbiz.widget.model.ModelForm; +import org.ofbiz.widget.model.ModelFormField; + +/** + * Widget Library - Form String Renderer interface. + */ +public interface FormStringRenderer { + public void renderDisplayField(Appendable writer, Map context, ModelFormField.DisplayField displayField) throws IOException; + public void renderHyperlinkField(Appendable writer, Map context, ModelFormField.HyperlinkField hyperlinkField) throws IOException; + + public void renderTextField(Appendable writer, Map context, ModelFormField.TextField textField) throws IOException; + public void renderTextareaField(Appendable writer, Map context, ModelFormField.TextareaField textareaField) throws IOException; + public void renderDateTimeField(Appendable writer, Map context, ModelFormField.DateTimeField dateTimeField) throws IOException; + + public void renderDropDownField(Appendable writer, Map context, ModelFormField.DropDownField dropDownField) throws IOException; + public void renderCheckField(Appendable writer, Map context, ModelFormField.CheckField checkField) throws IOException; + public void renderRadioField(Appendable writer, Map context, ModelFormField.RadioField radioField) throws IOException; + + public void renderSubmitField(Appendable writer, Map context, ModelFormField.SubmitField submitField) throws IOException; + public void renderResetField(Appendable writer, Map context, ModelFormField.ResetField resetField) throws IOException; + + public void renderHiddenField(Appendable writer, Map context, ModelFormField modelFormField, String value) throws IOException; + public void renderHiddenField(Appendable writer, Map context, ModelFormField.HiddenField hiddenField) throws IOException; + public void renderIgnoredField(Appendable writer, Map context, ModelFormField.IgnoredField ignoredField) throws IOException; + + public void renderFieldTitle(Appendable writer, Map context, ModelFormField modelFormField) throws IOException; + public void renderSingleFormFieldTitle(Appendable writer, Map context, ModelFormField modelFormField) throws IOException; + + public void renderFormOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException; + public void renderFormClose(Appendable writer, Map context, ModelForm modelForm) throws IOException; + public void renderMultiFormClose(Appendable writer, Map context, ModelForm modelForm) throws IOException; + + public void renderFormatListWrapperOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException; + public void renderFormatListWrapperClose(Appendable writer, Map context, ModelForm modelForm) throws IOException; + + public void renderFormatHeaderRowOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException; + public void renderFormatHeaderRowClose(Appendable writer, Map context, ModelForm modelForm) throws IOException; + public void renderFormatHeaderRowCellOpen(Appendable writer, Map context, ModelForm modelForm, ModelFormField modelFormField, int positionSpan) throws IOException; + public void renderFormatHeaderRowCellClose(Appendable writer, Map context, ModelForm modelForm, ModelFormField modelFormField) throws IOException; + + public void renderFormatHeaderRowFormCellOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException; + public void renderFormatHeaderRowFormCellClose(Appendable writer, Map context, ModelForm modelForm) throws IOException; + public void renderFormatHeaderRowFormCellTitleSeparator(Appendable writer, Map context, ModelForm modelForm, ModelFormField modelFormField, boolean isLast) throws IOException; + + public void renderFormatItemRowOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException; + public void renderFormatItemRowClose(Appendable writer, Map context, ModelForm modelForm) throws IOException; + public void renderFormatItemRowCellOpen(Appendable writer, Map context, ModelForm modelForm, ModelFormField modelFormField, int positionSpan) throws IOException; + public void renderFormatItemRowCellClose(Appendable writer, Map context, ModelForm modelForm, ModelFormField modelFormField) throws IOException; + public void renderFormatItemRowFormCellOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException; + public void renderFormatItemRowFormCellClose(Appendable writer, Map context, ModelForm modelForm) throws IOException; + + public void renderFormatSingleWrapperOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException; + public void renderFormatSingleWrapperClose(Appendable writer, Map context, ModelForm modelForm) throws IOException; + + public void renderFormatFieldRowOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException; + public void renderFormatFieldRowClose(Appendable writer, Map context, ModelForm modelForm) throws IOException; + public void renderFormatFieldRowTitleCellOpen(Appendable writer, Map context, ModelFormField modelFormField) throws IOException; + public void renderFormatFieldRowTitleCellClose(Appendable writer, Map context, ModelFormField modelFormField) throws IOException; + public void renderFormatFieldRowSpacerCell(Appendable writer, Map context, ModelFormField modelFormField) throws IOException; + public void renderFormatFieldRowWidgetCellOpen(Appendable writer, Map context, ModelFormField modelFormField, int positions, int positionSpan, Integer nextPositionInRow) throws IOException; + public void renderFormatFieldRowWidgetCellClose(Appendable writer, Map context, ModelFormField modelFormField, int positions, int positionSpan, Integer nextPositionInRow) throws IOException; + + public void renderFormatEmptySpace(Appendable writer, Map context, ModelForm modelForm) throws IOException; + + public void renderTextFindField(Appendable writer, Map context, ModelFormField.TextFindField textField) throws IOException; + public void renderDateFindField(Appendable writer, Map context, ModelFormField.DateFindField textField) throws IOException; + public void renderRangeFindField(Appendable writer, Map context, ModelFormField.RangeFindField textField) throws IOException; + public void renderLookupField(Appendable writer, Map context, ModelFormField.LookupField textField) throws IOException; + public void renderFileField(Appendable writer, Map context, ModelFormField.FileField textField) throws IOException; + public void renderPasswordField(Appendable writer, Map context, ModelFormField.PasswordField textField) throws IOException; + public void renderImageField(Appendable writer, Map context, ModelFormField.ImageField textField) throws IOException; + public void renderBanner(Appendable writer, Map context, ModelForm.Banner banner) throws IOException; + public void renderContainerFindField(Appendable writer, Map context, ModelFormField.ContainerField containerField) throws IOException; + public void renderFieldGroupOpen(Appendable writer, Map context, ModelForm.FieldGroup fieldGroup) throws IOException; + public void renderFieldGroupClose(Appendable writer, Map context, ModelForm.FieldGroup fieldGroup) throws IOException; +} diff --git a/framework/widget/src/org/ofbiz/widget/menu/MenuStringRenderer.java b/framework/widget/src/org/ofbiz/widget/renderer/MenuStringRenderer.java similarity index 90% rename from framework/widget/src/org/ofbiz/widget/menu/MenuStringRenderer.java rename to framework/widget/src/org/ofbiz/widget/renderer/MenuStringRenderer.java index 71f6a328c8..b1bf5c3fc4 100644 --- a/framework/widget/src/org/ofbiz/widget/menu/MenuStringRenderer.java +++ b/framework/widget/src/org/ofbiz/widget/renderer/MenuStringRenderer.java @@ -1,39 +1,41 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License") throws IOException ; you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget.menu; - -import java.io.IOException; -import java.util.Map; - -import org.ofbiz.widget.CommonWidgetModels.Image; - - -/** - * Widget Library - Form String Renderer interface - */ -public interface MenuStringRenderer { - public void renderMenuItem(Appendable writer, Map context, ModelMenuItem menuItem) throws IOException ; - public void renderMenuOpen(Appendable writer, Map context, ModelMenu menu) throws IOException ; - public void renderMenuClose(Appendable writer, Map context, ModelMenu menu) throws IOException ; - public void renderFormatSimpleWrapperOpen(Appendable writer, Map context, ModelMenu menu) throws IOException ; - public void renderFormatSimpleWrapperClose(Appendable writer, Map context, ModelMenu menu) throws IOException ; - public void renderFormatSimpleWrapperRows(Appendable writer, Map context, Object menu) throws IOException ; - public void renderLink(Appendable writer, Map context, ModelMenuItem.MenuLink link) throws IOException ; - public void renderImage(Appendable writer, Map context, Image image) throws IOException ; -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License") throws IOException ; you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.renderer; + +import java.io.IOException; +import java.util.Map; + +import org.ofbiz.widget.model.CommonWidgetModels.Image; +import org.ofbiz.widget.model.ModelMenu; +import org.ofbiz.widget.model.ModelMenuItem; + + +/** + * Widget Library - Form String Renderer interface + */ +public interface MenuStringRenderer { + public void renderMenuItem(Appendable writer, Map context, ModelMenuItem menuItem) throws IOException ; + public void renderMenuOpen(Appendable writer, Map context, ModelMenu menu) throws IOException ; + public void renderMenuClose(Appendable writer, Map context, ModelMenu menu) throws IOException ; + public void renderFormatSimpleWrapperOpen(Appendable writer, Map context, ModelMenu menu) throws IOException ; + public void renderFormatSimpleWrapperClose(Appendable writer, Map context, ModelMenu menu) throws IOException ; + public void renderFormatSimpleWrapperRows(Appendable writer, Map context, Object menu) throws IOException ; + public void renderLink(Appendable writer, Map context, ModelMenuItem.MenuLink link) throws IOException ; + public void renderImage(Appendable writer, Map context, Image image) throws IOException ; +} diff --git a/framework/widget/src/org/ofbiz/widget/menu/MenuWrapTransform.java b/framework/widget/src/org/ofbiz/widget/renderer/MenuWrapTransform.java similarity index 96% rename from framework/widget/src/org/ofbiz/widget/menu/MenuWrapTransform.java rename to framework/widget/src/org/ofbiz/widget/renderer/MenuWrapTransform.java index e95b92404e..45120b5376 100644 --- a/framework/widget/src/org/ofbiz/widget/menu/MenuWrapTransform.java +++ b/framework/widget/src/org/ofbiz/widget/renderer/MenuWrapTransform.java @@ -1,200 +1,200 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget.menu; - -import java.io.IOException; -import java.io.Writer; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; - -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.GeneralException; -import org.ofbiz.base.util.UtilGenerics; -import org.ofbiz.base.util.UtilValidate; -import org.ofbiz.base.util.template.FreeMarkerWorker; -import org.ofbiz.entity.Delegator; -import org.ofbiz.entity.GenericValue; -import org.ofbiz.webapp.ftl.LoopWriter; -import org.ofbiz.widget.WidgetContentWorker; -import org.ofbiz.widget.html.HtmlMenuWrapper; - -import freemarker.core.Environment; -import freemarker.template.TemplateModelException; -import freemarker.template.TemplateTransformModel; -import freemarker.template.TransformControl; - -//import com.clarkware.profiler.Profiler; -/** - * MenuWrapTransform - a FreeMarker transform that allow the ModelMenu - * stuff to be used at the FM level. It can be used to add "function bars" - * to pages. - * - * Accepts the following arguments (all of which can alternatively be present in the template context): - * - List> globalNodeTrail - * - String contentAssocPredicateId - * - String nullThruDatesOnly - * - String subDataResourceTypeId - * - String renderOnStart - * - String renderOnClose - * - String menuDefFile - * - String menuName - * - String menuWrapperClassName - * - String associatedContentId - * - * This is an interactive FreeMarker transform that allows the user to modify the contents that are placed within it. - */ -public class MenuWrapTransform implements TemplateTransformModel { - - public static final String module = MenuWrapTransform.class.getName(); - public static final String [] upSaveKeyNames = {"globalNodeTrail"}; - public static final String [] saveKeyNames = {"contentId", "subContentId", "subDataResourceTypeId", "mimeTypeId", "whenMap", "locale", "wrapTemplateId", "encloseWrapText", "nullThruDatesOnly", "renderOnStart", "renderOnClose", "menuDefFile", "menuName", "associatedContentId", "wrapperClassName"}; - - @SuppressWarnings("unchecked") - public Writer getWriter(final Writer out, Map args) { - final Environment env = Environment.getCurrentEnvironment(); - final Delegator delegator = FreeMarkerWorker.getWrappedObject("delegator", env); - final HttpServletRequest request = FreeMarkerWorker.getWrappedObject("request", env); - final HttpServletResponse response = FreeMarkerWorker.getWrappedObject("response", env); - final HttpSession session = FreeMarkerWorker.getWrappedObject("session", env); - - final GenericValue userLogin = FreeMarkerWorker.getWrappedObject("userLogin", env); - final Map templateCtx = FreeMarkerWorker.getWrappedObject("context", env); - - FreeMarkerWorker.getSiteParameters(request, templateCtx); - - final Map savedValuesUp = new HashMap(); - FreeMarkerWorker.saveContextValues(templateCtx, upSaveKeyNames, savedValuesUp); - - Map checkedArgs = UtilGenerics.checkMap(args); - FreeMarkerWorker.overrideWithArgs(templateCtx, checkedArgs); - //final String menuDefFile = (String)templateCtx.get("menuDefFile"); - //final String menuName = (String)templateCtx.get("menuName"); - //final String associatedContentId = (String)templateCtx.get("associatedContentId"); - List> trail = UtilGenerics.checkList(templateCtx.get("globalNodeTrail")); - String contentAssocPredicateId = (String)templateCtx.get("contentAssocPredicateId"); - String strNullThruDatesOnly = (String)templateCtx.get("nullThruDatesOnly"); - Boolean nullThruDatesOnly = (strNullThruDatesOnly != null && strNullThruDatesOnly.equalsIgnoreCase("true")) ? Boolean.TRUE :Boolean.FALSE; - GenericValue val = null; - try { - if (WidgetContentWorker.contentWorker != null) { - val = WidgetContentWorker.contentWorker.getCurrentContentExt(delegator, trail, userLogin, templateCtx, nullThruDatesOnly, contentAssocPredicateId); - } else { - Debug.logError("Not rendering content, not ContentWorker found.", module); - } - } catch (GeneralException e) { - throw new RuntimeException("Error getting current content. " + e.toString()); - } - final GenericValue view = val; - - String dataResourceId = null; - try { - dataResourceId = (String) view.get("drDataResourceId"); - } catch (Exception e) { - dataResourceId = (String) view.get("dataResourceId"); - } - String subContentIdSub = (String) view.get("contentId"); - // This order is taken so that the dataResourceType can be overridden in the transform arguments. - String subDataResourceTypeId = (String)templateCtx.get("subDataResourceTypeId"); - if (UtilValidate.isEmpty(subDataResourceTypeId)) { - try { - subDataResourceTypeId = (String) view.get("drDataResourceTypeId"); - } catch (Exception e) { - // view may be "Content" - } - // TODO: If this value is still empty then it is probably necessary to get a value from - // the parent context. But it will already have one and it is the same context that is - // being passed. - } - // This order is taken so that the mimeType can be overridden in the transform arguments. - String mimeTypeId = null; - if (WidgetContentWorker.contentWorker != null) { - mimeTypeId = WidgetContentWorker.contentWorker.getMimeTypeIdExt(delegator, view, templateCtx); - } else { - Debug.logError("Not rendering content, not ContentWorker found.", module); - } - templateCtx.put("drDataResourceId", dataResourceId); - templateCtx.put("mimeTypeId", mimeTypeId); - templateCtx.put("dataResourceId", dataResourceId); - templateCtx.put("subContentIdSub", subContentIdSub); - templateCtx.put("subDataResourceTypeId", subDataResourceTypeId); - final Map savedValues = new HashMap(); - FreeMarkerWorker.saveContextValues(templateCtx, saveKeyNames, savedValues); - - final StringBuilder buf = new StringBuilder(); - - return new LoopWriter(out) { - - @Override - public int onStart() throws TemplateModelException, IOException { - String renderOnStart = (String)templateCtx.get("renderOnStart"); - if (renderOnStart != null && renderOnStart.equalsIgnoreCase("true")) { - renderMenu(); - } - return TransformControl.EVALUATE_BODY; - } - - @Override - public void write(char cbuf[], int off, int len) { - buf.append(cbuf, off, len); - } - - @Override - public void flush() throws IOException { - out.flush(); - } - - @Override - public void close() throws IOException { - FreeMarkerWorker.reloadValues(templateCtx, savedValues, env); - String wrappedContent = buf.toString(); - out.write(wrappedContent); - String renderOnClose = (String)templateCtx.get("renderOnClose"); - if (renderOnClose == null || !renderOnClose.equalsIgnoreCase("false")) { - renderMenu(); - } - FreeMarkerWorker.reloadValues(templateCtx, savedValuesUp, env); - } - - public void renderMenu() throws IOException { - - String menuDefFile = (String)templateCtx.get("menuDefFile"); - String menuName = (String)templateCtx.get("menuName"); - String menuWrapperClassName = (String)templateCtx.get("menuWrapperClassName"); - HtmlMenuWrapper menuWrapper = HtmlMenuWrapper.getMenuWrapper(request, response, session, menuDefFile, menuName, menuWrapperClassName); - - if (menuWrapper == null) { - throw new IOException("HtmlMenuWrapper with def file:" + menuDefFile + " menuName:" + menuName + " and HtmlMenuWrapper class:" + menuWrapperClassName + " could not be instantiated."); - } - - String associatedContentId = (String)templateCtx.get("associatedContentId"); - menuWrapper.putInContext("defaultAssociatedContentId", associatedContentId); - menuWrapper.putInContext("currentValue", view); - - String menuStr = menuWrapper.renderMenuString(); - out.write(menuStr); - } - - }; - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.renderer; + +import java.io.IOException; +import java.io.Writer; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.GeneralException; +import org.ofbiz.base.util.UtilGenerics; +import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.base.util.template.FreeMarkerWorker; +import org.ofbiz.entity.Delegator; +import org.ofbiz.entity.GenericValue; +import org.ofbiz.webapp.ftl.LoopWriter; +import org.ofbiz.widget.content.WidgetContentWorker; +import org.ofbiz.widget.renderer.html.HtmlMenuWrapper; + +import freemarker.core.Environment; +import freemarker.template.TemplateModelException; +import freemarker.template.TemplateTransformModel; +import freemarker.template.TransformControl; + +//import com.clarkware.profiler.Profiler; +/** + * MenuWrapTransform - a FreeMarker transform that allow the ModelMenu + * stuff to be used at the FM level. It can be used to add "function bars" + * to pages. + * + * Accepts the following arguments (all of which can alternatively be present in the template context): + * - List> globalNodeTrail + * - String contentAssocPredicateId + * - String nullThruDatesOnly + * - String subDataResourceTypeId + * - String renderOnStart + * - String renderOnClose + * - String menuDefFile + * - String menuName + * - String menuWrapperClassName + * - String associatedContentId + * + * This is an interactive FreeMarker transform that allows the user to modify the contents that are placed within it. + */ +public class MenuWrapTransform implements TemplateTransformModel { + + public static final String module = MenuWrapTransform.class.getName(); + public static final String [] upSaveKeyNames = {"globalNodeTrail"}; + public static final String [] saveKeyNames = {"contentId", "subContentId", "subDataResourceTypeId", "mimeTypeId", "whenMap", "locale", "wrapTemplateId", "encloseWrapText", "nullThruDatesOnly", "renderOnStart", "renderOnClose", "menuDefFile", "menuName", "associatedContentId", "wrapperClassName"}; + + @SuppressWarnings("unchecked") + public Writer getWriter(final Writer out, Map args) { + final Environment env = Environment.getCurrentEnvironment(); + final Delegator delegator = FreeMarkerWorker.getWrappedObject("delegator", env); + final HttpServletRequest request = FreeMarkerWorker.getWrappedObject("request", env); + final HttpServletResponse response = FreeMarkerWorker.getWrappedObject("response", env); + final HttpSession session = FreeMarkerWorker.getWrappedObject("session", env); + + final GenericValue userLogin = FreeMarkerWorker.getWrappedObject("userLogin", env); + final Map templateCtx = FreeMarkerWorker.getWrappedObject("context", env); + + FreeMarkerWorker.getSiteParameters(request, templateCtx); + + final Map savedValuesUp = new HashMap(); + FreeMarkerWorker.saveContextValues(templateCtx, upSaveKeyNames, savedValuesUp); + + Map checkedArgs = UtilGenerics.checkMap(args); + FreeMarkerWorker.overrideWithArgs(templateCtx, checkedArgs); + //final String menuDefFile = (String)templateCtx.get("menuDefFile"); + //final String menuName = (String)templateCtx.get("menuName"); + //final String associatedContentId = (String)templateCtx.get("associatedContentId"); + List> trail = UtilGenerics.checkList(templateCtx.get("globalNodeTrail")); + String contentAssocPredicateId = (String)templateCtx.get("contentAssocPredicateId"); + String strNullThruDatesOnly = (String)templateCtx.get("nullThruDatesOnly"); + Boolean nullThruDatesOnly = (strNullThruDatesOnly != null && strNullThruDatesOnly.equalsIgnoreCase("true")) ? Boolean.TRUE :Boolean.FALSE; + GenericValue val = null; + try { + if (WidgetContentWorker.contentWorker != null) { + val = WidgetContentWorker.contentWorker.getCurrentContentExt(delegator, trail, userLogin, templateCtx, nullThruDatesOnly, contentAssocPredicateId); + } else { + Debug.logError("Not rendering content, not ContentWorker found.", module); + } + } catch (GeneralException e) { + throw new RuntimeException("Error getting current content. " + e.toString()); + } + final GenericValue view = val; + + String dataResourceId = null; + try { + dataResourceId = (String) view.get("drDataResourceId"); + } catch (Exception e) { + dataResourceId = (String) view.get("dataResourceId"); + } + String subContentIdSub = (String) view.get("contentId"); + // This order is taken so that the dataResourceType can be overridden in the transform arguments. + String subDataResourceTypeId = (String)templateCtx.get("subDataResourceTypeId"); + if (UtilValidate.isEmpty(subDataResourceTypeId)) { + try { + subDataResourceTypeId = (String) view.get("drDataResourceTypeId"); + } catch (Exception e) { + // view may be "Content" + } + // TODO: If this value is still empty then it is probably necessary to get a value from + // the parent context. But it will already have one and it is the same context that is + // being passed. + } + // This order is taken so that the mimeType can be overridden in the transform arguments. + String mimeTypeId = null; + if (WidgetContentWorker.contentWorker != null) { + mimeTypeId = WidgetContentWorker.contentWorker.getMimeTypeIdExt(delegator, view, templateCtx); + } else { + Debug.logError("Not rendering content, not ContentWorker found.", module); + } + templateCtx.put("drDataResourceId", dataResourceId); + templateCtx.put("mimeTypeId", mimeTypeId); + templateCtx.put("dataResourceId", dataResourceId); + templateCtx.put("subContentIdSub", subContentIdSub); + templateCtx.put("subDataResourceTypeId", subDataResourceTypeId); + final Map savedValues = new HashMap(); + FreeMarkerWorker.saveContextValues(templateCtx, saveKeyNames, savedValues); + + final StringBuilder buf = new StringBuilder(); + + return new LoopWriter(out) { + + @Override + public int onStart() throws TemplateModelException, IOException { + String renderOnStart = (String)templateCtx.get("renderOnStart"); + if (renderOnStart != null && renderOnStart.equalsIgnoreCase("true")) { + renderMenu(); + } + return TransformControl.EVALUATE_BODY; + } + + @Override + public void write(char cbuf[], int off, int len) { + buf.append(cbuf, off, len); + } + + @Override + public void flush() throws IOException { + out.flush(); + } + + @Override + public void close() throws IOException { + FreeMarkerWorker.reloadValues(templateCtx, savedValues, env); + String wrappedContent = buf.toString(); + out.write(wrappedContent); + String renderOnClose = (String)templateCtx.get("renderOnClose"); + if (renderOnClose == null || !renderOnClose.equalsIgnoreCase("false")) { + renderMenu(); + } + FreeMarkerWorker.reloadValues(templateCtx, savedValuesUp, env); + } + + public void renderMenu() throws IOException { + + String menuDefFile = (String)templateCtx.get("menuDefFile"); + String menuName = (String)templateCtx.get("menuName"); + String menuWrapperClassName = (String)templateCtx.get("menuWrapperClassName"); + HtmlMenuWrapper menuWrapper = HtmlMenuWrapper.getMenuWrapper(request, response, session, menuDefFile, menuName, menuWrapperClassName); + + if (menuWrapper == null) { + throw new IOException("HtmlMenuWrapper with def file:" + menuDefFile + " menuName:" + menuName + " and HtmlMenuWrapper class:" + menuWrapperClassName + " could not be instantiated."); + } + + String associatedContentId = (String)templateCtx.get("associatedContentId"); + menuWrapper.putInContext("defaultAssociatedContentId", associatedContentId); + menuWrapper.putInContext("currentValue", view); + + String menuStr = menuWrapper.renderMenuString(); + out.write(menuStr); + } + + }; + } +} diff --git a/framework/widget/src/org/ofbiz/widget/form/Paginator.java b/framework/widget/src/org/ofbiz/widget/renderer/Paginator.java similarity index 96% rename from framework/widget/src/org/ofbiz/widget/form/Paginator.java rename to framework/widget/src/org/ofbiz/widget/renderer/Paginator.java index 621c9b0f14..2d051f13eb 100644 --- a/framework/widget/src/org/ofbiz/widget/form/Paginator.java +++ b/framework/widget/src/org/ofbiz/widget/renderer/Paginator.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. *******************************************************************************/ -package org.ofbiz.widget.form; +package org.ofbiz.widget.renderer; import java.util.Iterator; import java.util.List; @@ -29,6 +29,7 @@ import org.ofbiz.base.util.UtilValidate; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.util.EntityListIterator; import org.ofbiz.widget.WidgetWorker; +import org.ofbiz.widget.model.ModelForm; /** * Utility methods for handling list pagination. diff --git a/framework/widget/src/org/ofbiz/widget/screen/ScreenRenderException.java b/framework/widget/src/org/ofbiz/widget/renderer/ScreenRenderException.java similarity index 95% rename from framework/widget/src/org/ofbiz/widget/screen/ScreenRenderException.java rename to framework/widget/src/org/ofbiz/widget/renderer/ScreenRenderException.java index ca8bdbc812..9406a339bc 100644 --- a/framework/widget/src/org/ofbiz/widget/screen/ScreenRenderException.java +++ b/framework/widget/src/org/ofbiz/widget/renderer/ScreenRenderException.java @@ -1,48 +1,48 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ - -package org.ofbiz.widget.screen; - -import org.ofbiz.base.util.GeneralException; - -/** - * Wraps any exceptions encountered during the rendering of - * a screen. It is thrown to the top of the recursive - * rendering process so that we avoid having to log redundant - * exceptions. - */ -@SuppressWarnings("serial") -public class ScreenRenderException extends GeneralException { - - public ScreenRenderException() { - super(); - } - - public ScreenRenderException(Throwable nested) { - super(nested); - } - - public ScreenRenderException(String str) { - super(str); - } - - public ScreenRenderException(String str, Throwable nested) { - super(str, nested); - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ + +package org.ofbiz.widget.renderer; + +import org.ofbiz.base.util.GeneralException; + +/** + * Wraps any exceptions encountered during the rendering of + * a screen. It is thrown to the top of the recursive + * rendering process so that we avoid having to log redundant + * exceptions. + */ +@SuppressWarnings("serial") +public class ScreenRenderException extends GeneralException { + + public ScreenRenderException() { + super(); + } + + public ScreenRenderException(Throwable nested) { + super(nested); + } + + public ScreenRenderException(String str) { + super(str); + } + + public ScreenRenderException(String str, Throwable nested) { + super(str, nested); + } +} diff --git a/framework/widget/src/org/ofbiz/widget/screen/ScreenRenderer.java b/framework/widget/src/org/ofbiz/widget/renderer/ScreenRenderer.java similarity index 97% rename from framework/widget/src/org/ofbiz/widget/screen/ScreenRenderer.java rename to framework/widget/src/org/ofbiz/widget/renderer/ScreenRenderer.java index 738c009437..87192b5f0e 100644 --- a/framework/widget/src/org/ofbiz/widget/screen/ScreenRenderer.java +++ b/framework/widget/src/org/ofbiz/widget/renderer/ScreenRenderer.java @@ -1,316 +1,318 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget.screen; - -import java.io.IOException; -import java.io.StringWriter; -import java.io.Writer; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; - -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; -import javax.xml.parsers.ParserConfigurationException; - -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.GeneralException; -import org.ofbiz.base.util.UtilDateTime; -import org.ofbiz.base.util.UtilFormatOut; -import org.ofbiz.base.util.UtilGenerics; -import org.ofbiz.base.util.UtilHttp; -import org.ofbiz.base.util.UtilMisc; -import org.ofbiz.base.util.UtilValidate; -import org.ofbiz.base.util.collections.MapStack; -import org.ofbiz.base.util.template.FreeMarkerWorker; -import org.ofbiz.entity.Delegator; -import org.ofbiz.entity.GenericEntity; -import org.ofbiz.entity.GenericValue; -import org.ofbiz.security.Security; -import org.ofbiz.service.DispatchContext; -import org.ofbiz.service.GenericServiceException; -import org.ofbiz.service.LocalDispatcher; -import org.ofbiz.webapp.control.LoginWorker; -import org.ofbiz.webapp.website.WebSiteWorker; -import org.ofbiz.widget.cache.GenericWidgetOutput; -import org.ofbiz.widget.cache.ScreenCache; -import org.ofbiz.widget.cache.WidgetContextCacheKey; -import org.xml.sax.SAXException; - -import freemarker.ext.jsp.TaglibFactory; -import freemarker.ext.servlet.HttpRequestHashModel; -import freemarker.ext.servlet.HttpSessionHashModel; - -/** - * Widget Library - Screen model class - */ -public class ScreenRenderer { - - public static final String module = ScreenRenderer.class.getName(); - - protected Appendable writer; - protected MapStack context; - protected ScreenStringRenderer screenStringRenderer; - protected int renderFormSeqNumber = 0; - - public ScreenRenderer(Appendable writer, MapStack context, ScreenStringRenderer screenStringRenderer) { - this.writer = writer; - this.context = context; - if (this.context == null) this.context = MapStack.create(); - this.screenStringRenderer = screenStringRenderer; - } - - /** - * Renders the named screen using the render environment configured when this ScreenRenderer was created. - * - * @param combinedName A combination of the resource name/location for the screen XML file and the name of the screen within that file, separated by a pound sign ("#"). This is the same format that is used in the view-map elements on the controller.xml file. - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - */ - public String render(String combinedName) throws GeneralException, IOException, SAXException, ParserConfigurationException { - String resourceName = ScreenFactory.getResourceNameFromCombined(combinedName); - String screenName = ScreenFactory.getScreenNameFromCombined(combinedName); - this.render(resourceName, screenName); - return ""; - } - - /** - * Renders the named screen using the render environment configured when this ScreenRenderer was created. - * - * @param resourceName The name/location of the resource to use, can use "component://[component-name]/" and "ofbiz://" and other special OFBiz style URLs - * @param screenName The name of the screen within the XML file specified by the resourceName. - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - */ - public String render(String resourceName, String screenName) throws GeneralException, IOException, SAXException, ParserConfigurationException { - ModelScreen modelScreen = ScreenFactory.getScreenFromLocation(resourceName, screenName); - if (modelScreen.getUseCache()) { - // if in the screen definition use-cache is set to true - // then try to get an already built screen output from the cache: - // 1) if we find it then we get it and attach it to the passed in writer - // 2) if we can't find one, we create a new StringWriter, - // and pass it to the renderScreenString; - // then we wrap its content and put it in the cache; - // and we attach it to the passed in writer - WidgetContextCacheKey wcck = new WidgetContextCacheKey(context); - String screenCombinedName = resourceName + ":" + screenName; - ScreenCache screenCache = new ScreenCache(); - GenericWidgetOutput gwo = screenCache.get(screenCombinedName, wcck); - if (gwo == null) { - Writer sw = new StringWriter(); - modelScreen.renderScreenString(sw, context, screenStringRenderer); - gwo = new GenericWidgetOutput(sw.toString()); - screenCache.put(screenCombinedName, wcck, gwo); - writer.append(gwo.toString()); - } else { - writer.append(gwo.toString()); - } - } else { - context.put("renderFormSeqNumber", String.valueOf(renderFormSeqNumber)); - modelScreen.renderScreenString(writer, context, screenStringRenderer); - } - return ""; - } - - public void setRenderFormUniqueSeq (int renderFormSeqNumber) { - this.renderFormSeqNumber = renderFormSeqNumber; - } - - public ScreenStringRenderer getScreenStringRenderer() { - return this.screenStringRenderer; - } - - public void populateBasicContext(Map parameters, Delegator delegator, LocalDispatcher dispatcher, Security security, Locale locale, GenericValue userLogin) { - populateBasicContext(context, this, parameters, delegator, dispatcher, security, locale, userLogin); - } - - public static void populateBasicContext(MapStack context, ScreenRenderer screens, Map parameters, Delegator delegator, LocalDispatcher dispatcher, Security security, Locale locale, GenericValue userLogin) { - // ========== setup values that should always be in a screen context - // include an object to more easily render screens - context.put("screens", screens); - - // make a reference for high level variables, a global context - context.put("globalContext", context.standAloneStack()); - - // make sure the "nullField" object is in there for entity ops; note this is nullField and not null because as null causes problems in FreeMarker and such... - context.put("nullField", GenericEntity.NULL_FIELD); - - context.put("parameters", parameters); - context.put("delegator", delegator); - context.put("dispatcher", dispatcher); - context.put("security", security); - context.put("locale", locale); - context.put("userLogin", userLogin); - context.put("nowTimestamp", UtilDateTime.nowTimestamp()); - try { - Map result = dispatcher.runSync("getUserPreferenceGroup", UtilMisc.toMap("userLogin", userLogin, "userPrefGroupTypeId", "GLOBAL_PREFERENCES")); - context.put("userPreferences", result.get("userPrefMap")); - } catch (GenericServiceException e) { - Debug.logError(e, "Error while getting user preferences: ", module); - } - } - - /** - * This method populates the context for this ScreenRenderer based on the HTTP Request and Response objects and the ServletContext. - * It leverages various conventions used in other places, namely the ControlServlet and so on, of OFBiz to get the different resources needed. - * - * @param request - * @param response - * @param servletContext - */ - public void populateContextForRequest(HttpServletRequest request, HttpServletResponse response, ServletContext servletContext) { - populateContextForRequest(context, this, request, response, servletContext); - } - - @SuppressWarnings("rawtypes") - public static void populateContextForRequest(MapStack context, ScreenRenderer screens, HttpServletRequest request, HttpServletResponse response, ServletContext servletContext) { - HttpSession session = request.getSession(); - - // attribute names to skip for session and application attributes; these are all handled as special cases, duplicating results and causing undesired messages - Set attrNamesToSkip = UtilMisc.toSet("delegator", "dispatcher", "security", "webSiteId", - "org.apache.catalina.jsp_classpath"); - Map parameterMap = UtilHttp.getCombinedMap(request, attrNamesToSkip); - - GenericValue userLogin = (GenericValue) session.getAttribute("userLogin"); - - populateBasicContext(context, screens, parameterMap, (Delegator) request.getAttribute("delegator"), - (LocalDispatcher) request.getAttribute("dispatcher"), - (Security) request.getAttribute("security"), UtilHttp.getLocale(request), userLogin); - - context.put("autoUserLogin", session.getAttribute("autoUserLogin")); - context.put("person", session.getAttribute("person")); - context.put("partyGroup", session.getAttribute("partyGroup")); - - // some things also seem to require this, so here it is: - request.setAttribute("userLogin", userLogin); - - // set up the user's time zone - context.put("timeZone", UtilHttp.getTimeZone(request)); - - // ========== setup values that are specific to OFBiz webapps - - context.put("request", request); - context.put("response", response); - context.put("session", session); - context.put("application", servletContext); - if (session != null) { - context.put("webappName", session.getAttribute("_WEBAPP_NAME_")); - } - if (servletContext != null) { - String rootDir = (String) context.get("rootDir"); - String webSiteId = (String) context.get("webSiteId"); - String https = (String) context.get("https"); - if (UtilValidate.isEmpty(rootDir)) { - rootDir = servletContext.getRealPath("/"); - context.put("rootDir", rootDir); - } - if (UtilValidate.isEmpty(webSiteId)) { - webSiteId = WebSiteWorker.getWebSiteId(request); - context.put("webSiteId", webSiteId); - } - if (UtilValidate.isEmpty(https)) { - https = (String) servletContext.getAttribute("https"); - context.put("https", https); - } - } - context.put("javaScriptEnabled", Boolean.valueOf(UtilHttp.isJavaScriptEnabled(request))); - - // these ones are FreeMarker specific and will only work in FTL templates, mainly here for backward compatibility - context.put("sessionAttributes", new HttpSessionHashModel(session, FreeMarkerWorker.getDefaultOfbizWrapper())); - context.put("requestAttributes", new HttpRequestHashModel(request, FreeMarkerWorker.getDefaultOfbizWrapper())); - TaglibFactory JspTaglibs = new TaglibFactory(servletContext); - context.put("JspTaglibs", JspTaglibs); - context.put("requestParameters", UtilHttp.getParameterMap(request)); - - // this is a dummy object to stand-in for the JPublish page object for backward compatibility - context.put("page", new HashMap()); - - // some information from/about the ControlServlet environment - context.put("controlPath", request.getAttribute("_CONTROL_PATH_")); - context.put("contextRoot", request.getAttribute("_CONTEXT_ROOT_")); - context.put("serverRoot", request.getAttribute("_SERVER_ROOT_URL_")); - context.put("checkLoginUrl", LoginWorker.makeLoginUrl(request)); - String externalLoginKey = LoginWorker.getExternalLoginKey(request); - String externalKeyParam = externalLoginKey == null ? "" : "&externalLoginKey=" + externalLoginKey; - context.put("externalLoginKey", externalLoginKey); - context.put("externalKeyParam", externalKeyParam); - - // setup message lists - List eventMessageList = UtilGenerics.toList(request.getAttribute("eventMessageList")); - if (eventMessageList == null) eventMessageList = new LinkedList(); - List errorMessageList = UtilGenerics.toList(request.getAttribute("errorMessageList")); - if (errorMessageList == null) errorMessageList = new LinkedList(); - - if (request.getAttribute("_EVENT_MESSAGE_") != null) { - eventMessageList.add(UtilFormatOut.replaceString((String) request.getAttribute("_EVENT_MESSAGE_"), "\n", "
")); - request.removeAttribute("_EVENT_MESSAGE_"); - } - List msgList = UtilGenerics.toList(request.getAttribute("_EVENT_MESSAGE_LIST_")); - if (msgList != null) { - eventMessageList.addAll(msgList); - request.removeAttribute("_EVENT_MESSAGE_LIST_"); - } - if (request.getAttribute("_ERROR_MESSAGE_") != null) { - errorMessageList.add(UtilFormatOut.replaceString((String) request.getAttribute("_ERROR_MESSAGE_"), "\n", "
")); - request.removeAttribute("_ERROR_MESSAGE_"); - } - if (session.getAttribute("_ERROR_MESSAGE_") != null) { - errorMessageList.add(UtilFormatOut.replaceString((String) session.getAttribute("_ERROR_MESSAGE_"), "\n", "
")); - session.removeAttribute("_ERROR_MESSAGE_"); - } - msgList = UtilGenerics.toList(request.getAttribute("_ERROR_MESSAGE_LIST_")); - if (msgList != null) { - errorMessageList.addAll(msgList); - request.removeAttribute("_ERROR_MESSAGE_LIST_"); - } - context.put("eventMessageList", eventMessageList); - context.put("errorMessageList", errorMessageList); - - if (request.getAttribute("serviceValidationException") != null) { - context.put("serviceValidationException", request.getAttribute("serviceValidationException")); - request.removeAttribute("serviceValidationException"); - } - - // if there was an error message, this is an error - context.put("isError", errorMessageList.size() > 0 ? Boolean.TRUE : Boolean.FALSE); - // if a parameter was passed saying this is an error, it is an error - if ("true".equals(parameterMap.get("isError"))) { - context.put("isError", Boolean.TRUE); - } - - // to preserve these values, push the MapStack - context.push(); - } - - public Map getContext() { - return context; - } - - public void populateContextForService(DispatchContext dctx, Map serviceContext) { - this.populateBasicContext(serviceContext, dctx.getDelegator(), dctx.getDispatcher(), - dctx.getSecurity(), (Locale) serviceContext.get("locale"), (GenericValue) serviceContext.get("userLogin")); - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.renderer; + +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; + +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import javax.xml.parsers.ParserConfigurationException; + +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.GeneralException; +import org.ofbiz.base.util.UtilDateTime; +import org.ofbiz.base.util.UtilFormatOut; +import org.ofbiz.base.util.UtilGenerics; +import org.ofbiz.base.util.UtilHttp; +import org.ofbiz.base.util.UtilMisc; +import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.base.util.collections.MapStack; +import org.ofbiz.base.util.template.FreeMarkerWorker; +import org.ofbiz.entity.Delegator; +import org.ofbiz.entity.GenericEntity; +import org.ofbiz.entity.GenericValue; +import org.ofbiz.security.Security; +import org.ofbiz.service.DispatchContext; +import org.ofbiz.service.GenericServiceException; +import org.ofbiz.service.LocalDispatcher; +import org.ofbiz.webapp.control.LoginWorker; +import org.ofbiz.webapp.website.WebSiteWorker; +import org.ofbiz.widget.cache.GenericWidgetOutput; +import org.ofbiz.widget.cache.ScreenCache; +import org.ofbiz.widget.cache.WidgetContextCacheKey; +import org.ofbiz.widget.model.ModelScreen; +import org.ofbiz.widget.model.ScreenFactory; +import org.xml.sax.SAXException; + +import freemarker.ext.jsp.TaglibFactory; +import freemarker.ext.servlet.HttpRequestHashModel; +import freemarker.ext.servlet.HttpSessionHashModel; + +/** + * Widget Library - Screen model class + */ +public class ScreenRenderer { + + public static final String module = ScreenRenderer.class.getName(); + + protected Appendable writer; + protected MapStack context; + protected ScreenStringRenderer screenStringRenderer; + protected int renderFormSeqNumber = 0; + + public ScreenRenderer(Appendable writer, MapStack context, ScreenStringRenderer screenStringRenderer) { + this.writer = writer; + this.context = context; + if (this.context == null) this.context = MapStack.create(); + this.screenStringRenderer = screenStringRenderer; + } + + /** + * Renders the named screen using the render environment configured when this ScreenRenderer was created. + * + * @param combinedName A combination of the resource name/location for the screen XML file and the name of the screen within that file, separated by a pound sign ("#"). This is the same format that is used in the view-map elements on the controller.xml file. + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + */ + public String render(String combinedName) throws GeneralException, IOException, SAXException, ParserConfigurationException { + String resourceName = ScreenFactory.getResourceNameFromCombined(combinedName); + String screenName = ScreenFactory.getScreenNameFromCombined(combinedName); + this.render(resourceName, screenName); + return ""; + } + + /** + * Renders the named screen using the render environment configured when this ScreenRenderer was created. + * + * @param resourceName The name/location of the resource to use, can use "component://[component-name]/" and "ofbiz://" and other special OFBiz style URLs + * @param screenName The name of the screen within the XML file specified by the resourceName. + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + */ + public String render(String resourceName, String screenName) throws GeneralException, IOException, SAXException, ParserConfigurationException { + ModelScreen modelScreen = ScreenFactory.getScreenFromLocation(resourceName, screenName); + if (modelScreen.getUseCache()) { + // if in the screen definition use-cache is set to true + // then try to get an already built screen output from the cache: + // 1) if we find it then we get it and attach it to the passed in writer + // 2) if we can't find one, we create a new StringWriter, + // and pass it to the renderScreenString; + // then we wrap its content and put it in the cache; + // and we attach it to the passed in writer + WidgetContextCacheKey wcck = new WidgetContextCacheKey(context); + String screenCombinedName = resourceName + ":" + screenName; + ScreenCache screenCache = new ScreenCache(); + GenericWidgetOutput gwo = screenCache.get(screenCombinedName, wcck); + if (gwo == null) { + Writer sw = new StringWriter(); + modelScreen.renderScreenString(sw, context, screenStringRenderer); + gwo = new GenericWidgetOutput(sw.toString()); + screenCache.put(screenCombinedName, wcck, gwo); + writer.append(gwo.toString()); + } else { + writer.append(gwo.toString()); + } + } else { + context.put("renderFormSeqNumber", String.valueOf(renderFormSeqNumber)); + modelScreen.renderScreenString(writer, context, screenStringRenderer); + } + return ""; + } + + public void setRenderFormUniqueSeq (int renderFormSeqNumber) { + this.renderFormSeqNumber = renderFormSeqNumber; + } + + public ScreenStringRenderer getScreenStringRenderer() { + return this.screenStringRenderer; + } + + public void populateBasicContext(Map parameters, Delegator delegator, LocalDispatcher dispatcher, Security security, Locale locale, GenericValue userLogin) { + populateBasicContext(context, this, parameters, delegator, dispatcher, security, locale, userLogin); + } + + public static void populateBasicContext(MapStack context, ScreenRenderer screens, Map parameters, Delegator delegator, LocalDispatcher dispatcher, Security security, Locale locale, GenericValue userLogin) { + // ========== setup values that should always be in a screen context + // include an object to more easily render screens + context.put("screens", screens); + + // make a reference for high level variables, a global context + context.put("globalContext", context.standAloneStack()); + + // make sure the "nullField" object is in there for entity ops; note this is nullField and not null because as null causes problems in FreeMarker and such... + context.put("nullField", GenericEntity.NULL_FIELD); + + context.put("parameters", parameters); + context.put("delegator", delegator); + context.put("dispatcher", dispatcher); + context.put("security", security); + context.put("locale", locale); + context.put("userLogin", userLogin); + context.put("nowTimestamp", UtilDateTime.nowTimestamp()); + try { + Map result = dispatcher.runSync("getUserPreferenceGroup", UtilMisc.toMap("userLogin", userLogin, "userPrefGroupTypeId", "GLOBAL_PREFERENCES")); + context.put("userPreferences", result.get("userPrefMap")); + } catch (GenericServiceException e) { + Debug.logError(e, "Error while getting user preferences: ", module); + } + } + + /** + * This method populates the context for this ScreenRenderer based on the HTTP Request and Response objects and the ServletContext. + * It leverages various conventions used in other places, namely the ControlServlet and so on, of OFBiz to get the different resources needed. + * + * @param request + * @param response + * @param servletContext + */ + public void populateContextForRequest(HttpServletRequest request, HttpServletResponse response, ServletContext servletContext) { + populateContextForRequest(context, this, request, response, servletContext); + } + + @SuppressWarnings("rawtypes") + public static void populateContextForRequest(MapStack context, ScreenRenderer screens, HttpServletRequest request, HttpServletResponse response, ServletContext servletContext) { + HttpSession session = request.getSession(); + + // attribute names to skip for session and application attributes; these are all handled as special cases, duplicating results and causing undesired messages + Set attrNamesToSkip = UtilMisc.toSet("delegator", "dispatcher", "security", "webSiteId", + "org.apache.catalina.jsp_classpath"); + Map parameterMap = UtilHttp.getCombinedMap(request, attrNamesToSkip); + + GenericValue userLogin = (GenericValue) session.getAttribute("userLogin"); + + populateBasicContext(context, screens, parameterMap, (Delegator) request.getAttribute("delegator"), + (LocalDispatcher) request.getAttribute("dispatcher"), + (Security) request.getAttribute("security"), UtilHttp.getLocale(request), userLogin); + + context.put("autoUserLogin", session.getAttribute("autoUserLogin")); + context.put("person", session.getAttribute("person")); + context.put("partyGroup", session.getAttribute("partyGroup")); + + // some things also seem to require this, so here it is: + request.setAttribute("userLogin", userLogin); + + // set up the user's time zone + context.put("timeZone", UtilHttp.getTimeZone(request)); + + // ========== setup values that are specific to OFBiz webapps + + context.put("request", request); + context.put("response", response); + context.put("session", session); + context.put("application", servletContext); + if (session != null) { + context.put("webappName", session.getAttribute("_WEBAPP_NAME_")); + } + if (servletContext != null) { + String rootDir = (String) context.get("rootDir"); + String webSiteId = (String) context.get("webSiteId"); + String https = (String) context.get("https"); + if (UtilValidate.isEmpty(rootDir)) { + rootDir = servletContext.getRealPath("/"); + context.put("rootDir", rootDir); + } + if (UtilValidate.isEmpty(webSiteId)) { + webSiteId = WebSiteWorker.getWebSiteId(request); + context.put("webSiteId", webSiteId); + } + if (UtilValidate.isEmpty(https)) { + https = (String) servletContext.getAttribute("https"); + context.put("https", https); + } + } + context.put("javaScriptEnabled", Boolean.valueOf(UtilHttp.isJavaScriptEnabled(request))); + + // these ones are FreeMarker specific and will only work in FTL templates, mainly here for backward compatibility + context.put("sessionAttributes", new HttpSessionHashModel(session, FreeMarkerWorker.getDefaultOfbizWrapper())); + context.put("requestAttributes", new HttpRequestHashModel(request, FreeMarkerWorker.getDefaultOfbizWrapper())); + TaglibFactory JspTaglibs = new TaglibFactory(servletContext); + context.put("JspTaglibs", JspTaglibs); + context.put("requestParameters", UtilHttp.getParameterMap(request)); + + // this is a dummy object to stand-in for the JPublish page object for backward compatibility + context.put("page", new HashMap()); + + // some information from/about the ControlServlet environment + context.put("controlPath", request.getAttribute("_CONTROL_PATH_")); + context.put("contextRoot", request.getAttribute("_CONTEXT_ROOT_")); + context.put("serverRoot", request.getAttribute("_SERVER_ROOT_URL_")); + context.put("checkLoginUrl", LoginWorker.makeLoginUrl(request)); + String externalLoginKey = LoginWorker.getExternalLoginKey(request); + String externalKeyParam = externalLoginKey == null ? "" : "&externalLoginKey=" + externalLoginKey; + context.put("externalLoginKey", externalLoginKey); + context.put("externalKeyParam", externalKeyParam); + + // setup message lists + List eventMessageList = UtilGenerics.toList(request.getAttribute("eventMessageList")); + if (eventMessageList == null) eventMessageList = new LinkedList(); + List errorMessageList = UtilGenerics.toList(request.getAttribute("errorMessageList")); + if (errorMessageList == null) errorMessageList = new LinkedList(); + + if (request.getAttribute("_EVENT_MESSAGE_") != null) { + eventMessageList.add(UtilFormatOut.replaceString((String) request.getAttribute("_EVENT_MESSAGE_"), "\n", "
")); + request.removeAttribute("_EVENT_MESSAGE_"); + } + List msgList = UtilGenerics.toList(request.getAttribute("_EVENT_MESSAGE_LIST_")); + if (msgList != null) { + eventMessageList.addAll(msgList); + request.removeAttribute("_EVENT_MESSAGE_LIST_"); + } + if (request.getAttribute("_ERROR_MESSAGE_") != null) { + errorMessageList.add(UtilFormatOut.replaceString((String) request.getAttribute("_ERROR_MESSAGE_"), "\n", "
")); + request.removeAttribute("_ERROR_MESSAGE_"); + } + if (session.getAttribute("_ERROR_MESSAGE_") != null) { + errorMessageList.add(UtilFormatOut.replaceString((String) session.getAttribute("_ERROR_MESSAGE_"), "\n", "
")); + session.removeAttribute("_ERROR_MESSAGE_"); + } + msgList = UtilGenerics.toList(request.getAttribute("_ERROR_MESSAGE_LIST_")); + if (msgList != null) { + errorMessageList.addAll(msgList); + request.removeAttribute("_ERROR_MESSAGE_LIST_"); + } + context.put("eventMessageList", eventMessageList); + context.put("errorMessageList", errorMessageList); + + if (request.getAttribute("serviceValidationException") != null) { + context.put("serviceValidationException", request.getAttribute("serviceValidationException")); + request.removeAttribute("serviceValidationException"); + } + + // if there was an error message, this is an error + context.put("isError", errorMessageList.size() > 0 ? Boolean.TRUE : Boolean.FALSE); + // if a parameter was passed saying this is an error, it is an error + if ("true".equals(parameterMap.get("isError"))) { + context.put("isError", Boolean.TRUE); + } + + // to preserve these values, push the MapStack + context.push(); + } + + public Map getContext() { + return context; + } + + public void populateContextForService(DispatchContext dctx, Map serviceContext) { + this.populateBasicContext(serviceContext, dctx.getDelegator(), dctx.getDispatcher(), + dctx.getSecurity(), (Locale) serviceContext.get("locale"), (GenericValue) serviceContext.get("userLogin")); + } +} diff --git a/framework/widget/src/org/ofbiz/widget/screen/ScreenStringRenderer.java b/framework/widget/src/org/ofbiz/widget/renderer/ScreenStringRenderer.java similarity index 97% rename from framework/widget/src/org/ofbiz/widget/screen/ScreenStringRenderer.java rename to framework/widget/src/org/ofbiz/widget/renderer/ScreenStringRenderer.java index ecb39ebfd2..5cdc80dd9e 100644 --- a/framework/widget/src/org/ofbiz/widget/screen/ScreenStringRenderer.java +++ b/framework/widget/src/org/ofbiz/widget/renderer/ScreenStringRenderer.java @@ -1,66 +1,67 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget.screen; - -import java.io.IOException; -import java.util.Map; -import org.ofbiz.entity.GenericValue; - -import org.ofbiz.base.util.GeneralException; - -/** - * Widget Library - Screen String Renderer interface. - */ -public interface ScreenStringRenderer { - public String getRendererName(); - public void renderScreenBegin(Appendable writer, Map context) throws IOException; - public void renderScreenEnd(Appendable writer, Map context) throws IOException; - public void renderSectionBegin(Appendable writer, Map context, ModelScreenWidget.Section section) throws IOException; - public void renderSectionEnd(Appendable writer, Map context, ModelScreenWidget.Section section) throws IOException; - public void renderColumnContainer(Appendable writer, Map context, ModelScreenWidget.ColumnContainer columnContainer) throws IOException; - public void renderContainerBegin(Appendable writer, Map context, ModelScreenWidget.Container container) throws IOException; - public void renderContainerEnd(Appendable writer, Map context, ModelScreenWidget.Container container) throws IOException; - public void renderContentBegin(Appendable writer, Map context, ModelScreenWidget.Content content) throws IOException; - public void renderContentBody(Appendable writer, Map context, ModelScreenWidget.Content content) throws IOException; - public void renderContentEnd(Appendable writer, Map context, ModelScreenWidget.Content content) throws IOException; - public void renderSubContentBegin(Appendable writer, Map context, ModelScreenWidget.SubContent content) throws IOException; - public void renderSubContentBody(Appendable writer, Map context, ModelScreenWidget.SubContent content) throws IOException; - public void renderSubContentEnd(Appendable writer, Map context, ModelScreenWidget.SubContent content) throws IOException; - - public void renderHorizontalSeparator(Appendable writer, Map context, ModelScreenWidget.HorizontalSeparator separator) throws IOException; - public void renderLabel(Appendable writer, Map context, ModelScreenWidget.Label label) throws IOException; - public void renderLink(Appendable writer, Map context, ModelScreenWidget.ScreenLink link) throws IOException; - public void renderImage(Appendable writer, Map context, ModelScreenWidget.ScreenImage image) throws IOException; - - public void renderContentFrame(Appendable writer, Map context, ModelScreenWidget.Content content) throws IOException; - public void renderScreenletBegin(Appendable writer, Map context, boolean collapsed, ModelScreenWidget.Screenlet screenlet) throws IOException; - public void renderScreenletSubWidget(Appendable writer, Map context, ModelScreenWidget subWidget, ModelScreenWidget.Screenlet screenlet) throws GeneralException, IOException; - public void renderScreenletEnd(Appendable writer, Map context, ModelScreenWidget.Screenlet screenlet) throws IOException; - - public void renderPortalPageBegin(Appendable writer, Map context, ModelScreenWidget.PortalPage portalPage) throws GeneralException, IOException; - public void renderPortalPageEnd(Appendable writer, Map context, ModelScreenWidget.PortalPage portalPage) throws GeneralException, IOException; - public void renderPortalPageColumnBegin(Appendable writer, Map context, ModelScreenWidget.PortalPage portalPage, GenericValue portalPageColumn) throws GeneralException, IOException; - public void renderPortalPageColumnEnd(Appendable writer, Map context, ModelScreenWidget.PortalPage portalPage, GenericValue portalPageColumn) throws GeneralException, IOException; - public void renderPortalPagePortletBegin(Appendable writer, Map context, ModelScreenWidget.PortalPage portalPage, GenericValue portalPortlet) throws GeneralException, IOException; - public void renderPortalPagePortletBody(Appendable writer, Map context, ModelScreenWidget.PortalPage portalPage, GenericValue portalPortlet) throws GeneralException, IOException; - public void renderPortalPagePortletEnd(Appendable writer, Map context, ModelScreenWidget.PortalPage portalPage, GenericValue portalPortlet) throws GeneralException, IOException; -} - - - +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.renderer; + +import java.io.IOException; +import java.util.Map; + +import org.ofbiz.base.util.GeneralException; +import org.ofbiz.entity.GenericValue; +import org.ofbiz.widget.model.ModelScreenWidget; + +/** + * Widget Library - Screen String Renderer interface. + */ +public interface ScreenStringRenderer { + public String getRendererName(); + public void renderScreenBegin(Appendable writer, Map context) throws IOException; + public void renderScreenEnd(Appendable writer, Map context) throws IOException; + public void renderSectionBegin(Appendable writer, Map context, ModelScreenWidget.Section section) throws IOException; + public void renderSectionEnd(Appendable writer, Map context, ModelScreenWidget.Section section) throws IOException; + public void renderColumnContainer(Appendable writer, Map context, ModelScreenWidget.ColumnContainer columnContainer) throws IOException; + public void renderContainerBegin(Appendable writer, Map context, ModelScreenWidget.Container container) throws IOException; + public void renderContainerEnd(Appendable writer, Map context, ModelScreenWidget.Container container) throws IOException; + public void renderContentBegin(Appendable writer, Map context, ModelScreenWidget.Content content) throws IOException; + public void renderContentBody(Appendable writer, Map context, ModelScreenWidget.Content content) throws IOException; + public void renderContentEnd(Appendable writer, Map context, ModelScreenWidget.Content content) throws IOException; + public void renderSubContentBegin(Appendable writer, Map context, ModelScreenWidget.SubContent content) throws IOException; + public void renderSubContentBody(Appendable writer, Map context, ModelScreenWidget.SubContent content) throws IOException; + public void renderSubContentEnd(Appendable writer, Map context, ModelScreenWidget.SubContent content) throws IOException; + + public void renderHorizontalSeparator(Appendable writer, Map context, ModelScreenWidget.HorizontalSeparator separator) throws IOException; + public void renderLabel(Appendable writer, Map context, ModelScreenWidget.Label label) throws IOException; + public void renderLink(Appendable writer, Map context, ModelScreenWidget.ScreenLink link) throws IOException; + public void renderImage(Appendable writer, Map context, ModelScreenWidget.ScreenImage image) throws IOException; + + public void renderContentFrame(Appendable writer, Map context, ModelScreenWidget.Content content) throws IOException; + public void renderScreenletBegin(Appendable writer, Map context, boolean collapsed, ModelScreenWidget.Screenlet screenlet) throws IOException; + public void renderScreenletSubWidget(Appendable writer, Map context, ModelScreenWidget subWidget, ModelScreenWidget.Screenlet screenlet) throws GeneralException, IOException; + public void renderScreenletEnd(Appendable writer, Map context, ModelScreenWidget.Screenlet screenlet) throws IOException; + + public void renderPortalPageBegin(Appendable writer, Map context, ModelScreenWidget.PortalPage portalPage) throws GeneralException, IOException; + public void renderPortalPageEnd(Appendable writer, Map context, ModelScreenWidget.PortalPage portalPage) throws GeneralException, IOException; + public void renderPortalPageColumnBegin(Appendable writer, Map context, ModelScreenWidget.PortalPage portalPage, GenericValue portalPageColumn) throws GeneralException, IOException; + public void renderPortalPageColumnEnd(Appendable writer, Map context, ModelScreenWidget.PortalPage portalPage, GenericValue portalPageColumn) throws GeneralException, IOException; + public void renderPortalPagePortletBegin(Appendable writer, Map context, ModelScreenWidget.PortalPage portalPage, GenericValue portalPortlet) throws GeneralException, IOException; + public void renderPortalPagePortletBody(Appendable writer, Map context, ModelScreenWidget.PortalPage portalPage, GenericValue portalPortlet) throws GeneralException, IOException; + public void renderPortalPagePortletEnd(Appendable writer, Map context, ModelScreenWidget.PortalPage portalPage, GenericValue portalPortlet) throws GeneralException, IOException; +} + + + diff --git a/framework/widget/src/org/ofbiz/widget/tree/TreeStringRenderer.java b/framework/widget/src/org/ofbiz/widget/renderer/TreeStringRenderer.java similarity index 94% rename from framework/widget/src/org/ofbiz/widget/tree/TreeStringRenderer.java rename to framework/widget/src/org/ofbiz/widget/renderer/TreeStringRenderer.java index 63184b7b0b..d56d02206a 100644 --- a/framework/widget/src/org/ofbiz/widget/tree/TreeStringRenderer.java +++ b/framework/widget/src/org/ofbiz/widget/renderer/TreeStringRenderer.java @@ -1,38 +1,38 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget.tree; - -import java.io.IOException; -import java.util.Map; - -import org.ofbiz.widget.screen.ScreenStringRenderer; - -/** - * Widget Library - Tree String Renderer interface - */ -public interface TreeStringRenderer { - - public void renderNodeBegin(Appendable writer, Map context, ModelTree.ModelNode node, int depth) throws IOException; - public void renderNodeEnd(Appendable writer, Map context, ModelTree.ModelNode node) throws IOException; - public void renderLabel(Appendable writer, Map context, ModelTree.ModelNode.Label label) throws IOException; - public void renderLink(Appendable writer, Map context, ModelTree.ModelNode.Link link) throws IOException; - public void renderImage(Appendable writer, Map context, ModelTree.ModelNode.Image image) throws IOException; - public void renderLastElement(Appendable writer, Map context, ModelTree.ModelNode node) throws IOException; - public ScreenStringRenderer getScreenStringRenderer(Map context); -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.renderer; + +import java.io.IOException; +import java.util.Map; + +import org.ofbiz.widget.model.ModelTree; + +/** + * Widget Library - Tree String Renderer interface + */ +public interface TreeStringRenderer { + + public void renderNodeBegin(Appendable writer, Map context, ModelTree.ModelNode node, int depth) throws IOException; + public void renderNodeEnd(Appendable writer, Map context, ModelTree.ModelNode node) throws IOException; + public void renderLabel(Appendable writer, Map context, ModelTree.ModelNode.Label label) throws IOException; + public void renderLink(Appendable writer, Map context, ModelTree.ModelNode.Link link) throws IOException; + public void renderImage(Appendable writer, Map context, ModelTree.ModelNode.Image image) throws IOException; + public void renderLastElement(Appendable writer, Map context, ModelTree.ModelNode node) throws IOException; + public ScreenStringRenderer getScreenStringRenderer(Map context); +} diff --git a/framework/widget/src/org/ofbiz/widget/form/UtilHelpText.java b/framework/widget/src/org/ofbiz/widget/renderer/UtilHelpText.java similarity index 96% rename from framework/widget/src/org/ofbiz/widget/form/UtilHelpText.java rename to framework/widget/src/org/ofbiz/widget/renderer/UtilHelpText.java index a605bb15ad..5f88381f44 100644 --- a/framework/widget/src/org/ofbiz/widget/form/UtilHelpText.java +++ b/framework/widget/src/org/ofbiz/widget/renderer/UtilHelpText.java @@ -1,87 +1,87 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget.form; - -import java.util.Locale; - -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.UtilProperties; -import org.ofbiz.base.util.UtilValidate; -import org.ofbiz.entity.Delegator; -import org.ofbiz.entity.GenericEntityException; -import org.ofbiz.entity.model.ModelEntity; -import org.ofbiz.entity.model.ModelReader; - -/** - * Util for working with Help Text - */ -public class UtilHelpText { - - public static final String module = UtilHelpText.class.getName(); - - /** - * Find the help text associated with an entity field. - * - * @param entityName the entity name - * @param fieldName the field name - * @param delegator the delegator - * @param locale the locale - * @return the help text, or the resource propertyName if no help text exists - */ - public static String getEntityFieldDescription(final String entityName, final String fieldName, final Delegator delegator, final Locale locale) { - - if (UtilValidate.isEmpty(entityName)) { - // Debug.logWarning("entityName [" + entityName + "] is empty", module); - return ""; - } - if (UtilValidate.isEmpty(fieldName)) { - Debug.logWarning("fieldName [" + fieldName + "] is empty", module); - return ""; - } - ModelReader reader = delegator.getModelReader(); - ModelEntity entity = null; - try { - if (!reader.getEntityNames().contains(entityName)) { - Debug.logWarning("couldn't find entityName [" + entityName + "]", module); - return ""; - } - entity = reader.getModelEntity(entityName); - } catch (GenericEntityException e) { - Debug.logError(e, "Error getting help text for entity=" + entityName + " field " + fieldName, module); - return ""; - } - String entityResourceName = entity.getDefaultResourceName(); - String messageId = "FieldDescription." + entityName + "." + fieldName; - String fieldDescription = UtilProperties.getMessage(entityResourceName, messageId, locale); - if (fieldDescription.equals(messageId)) { - messageId = "FieldDescription." + fieldName; - if (Debug.verboseOn()) { - Debug.logVerbose("No help text found in [" + entityResourceName + "] with key [" + messageId + "], Trying with: " + messageId, module); - } - fieldDescription = UtilProperties.getMessage(entityResourceName, messageId, locale); - if (fieldDescription.equals(messageId)) { - if (Debug.verboseOn()) { - Debug.logVerbose("No help text found in [" + entityResourceName + "] with key [" + messageId + "]", module); - } - return ""; - } - } - return fieldDescription; - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.renderer; + +import java.util.Locale; + +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilProperties; +import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.entity.Delegator; +import org.ofbiz.entity.GenericEntityException; +import org.ofbiz.entity.model.ModelEntity; +import org.ofbiz.entity.model.ModelReader; + +/** + * Util for working with Help Text + */ +public class UtilHelpText { + + public static final String module = UtilHelpText.class.getName(); + + /** + * Find the help text associated with an entity field. + * + * @param entityName the entity name + * @param fieldName the field name + * @param delegator the delegator + * @param locale the locale + * @return the help text, or the resource propertyName if no help text exists + */ + public static String getEntityFieldDescription(final String entityName, final String fieldName, final Delegator delegator, final Locale locale) { + + if (UtilValidate.isEmpty(entityName)) { + // Debug.logWarning("entityName [" + entityName + "] is empty", module); + return ""; + } + if (UtilValidate.isEmpty(fieldName)) { + Debug.logWarning("fieldName [" + fieldName + "] is empty", module); + return ""; + } + ModelReader reader = delegator.getModelReader(); + ModelEntity entity = null; + try { + if (!reader.getEntityNames().contains(entityName)) { + Debug.logWarning("couldn't find entityName [" + entityName + "]", module); + return ""; + } + entity = reader.getModelEntity(entityName); + } catch (GenericEntityException e) { + Debug.logError(e, "Error getting help text for entity=" + entityName + " field " + fieldName, module); + return ""; + } + String entityResourceName = entity.getDefaultResourceName(); + String messageId = "FieldDescription." + entityName + "." + fieldName; + String fieldDescription = UtilProperties.getMessage(entityResourceName, messageId, locale); + if (fieldDescription.equals(messageId)) { + messageId = "FieldDescription." + fieldName; + if (Debug.verboseOn()) { + Debug.logVerbose("No help text found in [" + entityResourceName + "] with key [" + messageId + "], Trying with: " + messageId, module); + } + fieldDescription = UtilProperties.getMessage(entityResourceName, messageId, locale); + if (fieldDescription.equals(messageId)) { + if (Debug.verboseOn()) { + Debug.logVerbose("No help text found in [" + entityResourceName + "] with key [" + messageId + "]", module); + } + return ""; + } + } + return fieldDescription; + } +} diff --git a/framework/widget/src/org/ofbiz/widget/fo/FoFormRenderer.java b/framework/widget/src/org/ofbiz/widget/renderer/fo/FoFormRenderer.java similarity index 90% rename from framework/widget/src/org/ofbiz/widget/fo/FoFormRenderer.java rename to framework/widget/src/org/ofbiz/widget/renderer/fo/FoFormRenderer.java index 01c78cd2ea..29bc6588a7 100644 --- a/framework/widget/src/org/ofbiz/widget/fo/FoFormRenderer.java +++ b/framework/widget/src/org/ofbiz/widget/renderer/fo/FoFormRenderer.java @@ -1,427 +1,427 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget.fo; - -import java.io.IOException; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.ofbiz.base.util.UtilFormatOut; -import org.ofbiz.base.util.UtilValidate; -import org.ofbiz.widget.ModelWidget; -import org.ofbiz.widget.WidgetWorker; -import org.ofbiz.widget.form.FieldInfo; -import org.ofbiz.widget.form.FormStringRenderer; -import org.ofbiz.widget.form.ModelForm; -import org.ofbiz.widget.form.ModelFormField; -import org.ofbiz.widget.form.ModelFormField.CheckField; -import org.ofbiz.widget.form.ModelFormField.ContainerField; -import org.ofbiz.widget.form.ModelFormField.DateFindField; -import org.ofbiz.widget.form.ModelFormField.DateTimeField; -import org.ofbiz.widget.form.ModelFormField.DisplayField; -import org.ofbiz.widget.form.ModelFormField.DropDownField; -import org.ofbiz.widget.form.ModelFormField.FieldInfoWithOptions; -import org.ofbiz.widget.form.ModelFormField.FileField; -import org.ofbiz.widget.form.ModelFormField.HiddenField; -import org.ofbiz.widget.form.ModelFormField.HyperlinkField; -import org.ofbiz.widget.form.ModelFormField.IgnoredField; -import org.ofbiz.widget.form.ModelFormField.ImageField; -import org.ofbiz.widget.form.ModelFormField.LookupField; -import org.ofbiz.widget.form.ModelFormField.PasswordField; -import org.ofbiz.widget.form.ModelFormField.RadioField; -import org.ofbiz.widget.form.ModelFormField.RangeFindField; -import org.ofbiz.widget.form.ModelFormField.ResetField; -import org.ofbiz.widget.form.ModelFormField.SubmitField; -import org.ofbiz.widget.form.ModelFormField.TextField; -import org.ofbiz.widget.form.ModelFormField.TextFindField; -import org.ofbiz.widget.form.ModelFormField.TextareaField; -import org.ofbiz.widget.html.HtmlWidgetRenderer; - - -/** - * Widget Library - FO Form Renderer implementation - * - */ -public class FoFormRenderer extends HtmlWidgetRenderer implements FormStringRenderer { - - public static final String module = FoFormRenderer.class.getName(); - - HttpServletRequest request; - HttpServletResponse response; - - public FoFormRenderer() {} - - public FoFormRenderer(HttpServletRequest request, HttpServletResponse response) throws IOException { - this.request = request; - this.response = response; - } - - private void makeBlockString(Appendable writer, String widgetStyle, String text) throws IOException { - writer.append(""); - writer.append(UtilFormatOut.encodeXmlValue(text)); - writer.append(""); - } - - public void renderDisplayField(Appendable writer, Map context, DisplayField displayField) throws IOException { - ModelFormField modelFormField = displayField.getModelFormField(); - this.makeBlockString(writer, modelFormField.getWidgetStyle(), displayField.getDescription(context)); - appendWhitespace(writer); - } - - public void renderHyperlinkField(Appendable writer, Map context, HyperlinkField hyperlinkField) throws IOException { - ModelFormField modelFormField = hyperlinkField.getModelFormField(); - this.makeBlockString(writer, modelFormField.getWidgetStyle(), hyperlinkField.getDescription(context)); - appendWhitespace(writer); - } - - public void renderTextField(Appendable writer, Map context, TextField textField) throws IOException { - ModelFormField modelFormField = textField.getModelFormField(); - this.makeBlockString(writer, modelFormField.getWidgetStyle(), modelFormField.getEntry(context, textField.getDefaultValue(context))); - appendWhitespace(writer); - } - - public void renderTextareaField(Appendable writer, Map context, TextareaField textareaField) throws IOException { - ModelFormField modelFormField = textareaField.getModelFormField(); - this.makeBlockString(writer, modelFormField.getWidgetStyle(), modelFormField.getEntry(context, textareaField.getDefaultValue(context))); - appendWhitespace(writer); - } - - public void renderDateTimeField(Appendable writer, Map context, DateTimeField dateTimeField) throws IOException { - ModelFormField modelFormField = dateTimeField.getModelFormField(); - this.makeBlockString(writer, modelFormField.getWidgetStyle(), modelFormField.getEntry(context, dateTimeField.getDefaultValue(context))); - appendWhitespace(writer); - } - - public void renderDropDownField(Appendable writer, Map context, DropDownField dropDownField) throws IOException { - ModelFormField modelFormField = dropDownField.getModelFormField(); - String currentValue = modelFormField.getEntry(context); - List allOptionValues = dropDownField.getAllOptionValues(context, WidgetWorker.getDelegator(context)); - // if the current value should go first, display it - if (UtilValidate.isNotEmpty(currentValue) && "first-in-list".equals(dropDownField.getCurrent())) { - String explicitDescription = dropDownField.getCurrentDescription(context); - if (UtilValidate.isNotEmpty(explicitDescription)) { - this.makeBlockString(writer, modelFormField.getWidgetStyle(), explicitDescription); - } else { - this.makeBlockString(writer, modelFormField.getWidgetStyle(), FieldInfoWithOptions.getDescriptionForOptionKey(currentValue, allOptionValues)); - } - } else { - boolean optionSelected = false; - for (ModelFormField.OptionValue optionValue : allOptionValues) { - String noCurrentSelectedKey = dropDownField.getNoCurrentSelectedKey(context); - if ((UtilValidate.isNotEmpty(currentValue) && currentValue.equals(optionValue.getKey()) && "selected".equals(dropDownField.getCurrent())) || - (UtilValidate.isEmpty(currentValue) && noCurrentSelectedKey != null && noCurrentSelectedKey.equals(optionValue.getKey()))) { - this.makeBlockString(writer, modelFormField.getWidgetStyle(), optionValue.getDescription()); - optionSelected = true; - break; - } - } - if (!optionSelected) { - this.makeBlockString(writer, null, ""); - } - } - appendWhitespace(writer); - } - - public void renderCheckField(Appendable writer, Map context, CheckField checkField) throws IOException { - this.makeBlockString(writer, null, ""); - } - - public void renderRadioField(Appendable writer, Map context, RadioField radioField) throws IOException { - this.makeBlockString(writer, null, ""); - } - - public void renderSubmitField(Appendable writer, Map context, SubmitField submitField) throws IOException { - this.makeBlockString(writer, null, ""); - } - - public void renderResetField(Appendable writer, Map context, ResetField resetField) throws IOException { - this.makeBlockString(writer, null, ""); - } - - public void renderHiddenField(Appendable writer, Map context, HiddenField hiddenField) throws IOException { - } - - public void renderHiddenField(Appendable writer, Map context, ModelFormField modelFormField, String value) throws IOException { - } - - public void renderIgnoredField(Appendable writer, Map context, IgnoredField ignoredField) throws IOException { - } - - public void renderFieldTitle(Appendable writer, Map context, ModelFormField modelFormField) throws IOException { - String tempTitleText = modelFormField.getTitle(context); - writer.append(tempTitleText); - } - - public void renderSingleFormFieldTitle(Appendable writer, Map context, ModelFormField modelFormField) throws IOException { - renderFieldTitle(writer, context, modelFormField); - } - - public void renderFormOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException { - this.widgetCommentsEnabled = ModelWidget.widgetBoundaryCommentsEnabled(context); - renderBeginningBoundaryComment(writer, "Form Widget", modelForm); - } - - public void renderFormClose(Appendable writer, Map context, ModelForm modelForm) throws IOException { - renderEndingBoundaryComment(writer, "Form Widget", modelForm); - } - - public void renderMultiFormClose(Appendable writer, Map context, ModelForm modelForm) throws IOException { - renderEndingBoundaryComment(writer, "Form Widget", modelForm); - } - - public void renderFormatListWrapperOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException { - writer.append(""); - List childFieldList = modelForm.getFieldList(); - for (ModelFormField childField : childFieldList) { - int childFieldType = childField.getFieldInfo().getFieldType(); - if (childFieldType == FieldInfo.HIDDEN || childFieldType == FieldInfo.IGNORED) { - continue; - } - writer.append(""); - appendWhitespace(writer); - } - appendWhitespace(writer); - } - - public void renderFormatListWrapperClose(Appendable writer, Map context, ModelForm modelForm) throws IOException { - writer.append(""); - writer.append(""); - appendWhitespace(writer); - } - - public void renderFormatHeaderRowOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException { - writer.append(""); - writer.append(""); - appendWhitespace(writer); - } - - public void renderFormatHeaderRowClose(Appendable writer, Map context, ModelForm modelForm) throws IOException { - writer.append(""); - writer.append(""); - writer.append(""); - // FIXME: this is an hack to avoid FOP rendering errors for empty lists (fo:table-body cannot be null) - writer.append(""); - appendWhitespace(writer); - } - - public void renderFormatHeaderRowCellOpen(Appendable writer, Map context, ModelForm modelForm, ModelFormField modelFormField, int positionSpan) throws IOException { - writer.append(" 1) { - writer.append("number-columns-spanned=\""); - writer.append(Integer.toString(positionSpan)); - writer.append("\" "); - } - writer.append("font-weight=\"bold\" text-align=\"center\" border=\"solid black\" padding=\"2pt\""); - writer.append(">"); - writer.append(""); - appendWhitespace(writer); - } - - public void renderFormatHeaderRowCellClose(Appendable writer, Map context, ModelForm modelForm, ModelFormField modelFormField) throws IOException { - writer.append(""); - writer.append(""); - appendWhitespace(writer); - } - - public void renderFormatHeaderRowFormCellOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException { - writer.append(""); - appendWhitespace(writer); - } - - public void renderFormatHeaderRowFormCellClose(Appendable writer, Map context, ModelForm modelForm) throws IOException { - writer.append(""); - appendWhitespace(writer); - } - - public void renderFormatHeaderRowFormCellTitleSeparator(Appendable writer, Map context, ModelForm modelForm, ModelFormField modelFormField, boolean isLast) throws IOException { - } - - public void renderFormatItemRowOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException { - writer.append(""); - appendWhitespace(writer); - } - - public void renderFormatItemRowClose(Appendable writer, Map context, ModelForm modelForm) throws IOException { - writer.append(""); - appendWhitespace(writer); - } - - public void renderFormatItemRowCellOpen(Appendable writer, Map context, ModelForm modelForm, ModelFormField modelFormField, int positionSpan) throws IOException { - writer.append(" 1) { - writer.append("number-columns-spanned=\""); - writer.append(Integer.toString(positionSpan)); - writer.append("\" "); - } - String areaStyle = modelFormField.getWidgetAreaStyle(); - if (UtilValidate.isEmpty(areaStyle)) { - areaStyle = "tabletext"; - } - writer.append(FoScreenRenderer.getFoStyle(areaStyle)); - writer.append(">"); - appendWhitespace(writer); - } - - public void renderFormatItemRowCellClose(Appendable writer, Map context, ModelForm modelForm, ModelFormField modelFormField) throws IOException { - writer.append(""); - appendWhitespace(writer); - } - - public void renderFormatItemRowFormCellOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException { - writer.append(""); - appendWhitespace(writer); - } - - public void renderFormatItemRowFormCellClose(Appendable writer, Map context, ModelForm modelForm) throws IOException { - writer.append(""); - appendWhitespace(writer); - } - - // TODO: multi columns (position attribute) in single forms are still not implemented - public void renderFormatSingleWrapperOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException { - writer.append(""); - appendWhitespace(writer); - writer.append(""); - appendWhitespace(writer); - writer.append(""); - appendWhitespace(writer); - writer.append(""); - appendWhitespace(writer); - } - public void renderFormatSingleWrapperClose(Appendable writer, Map context, ModelForm modelForm) throws IOException { - writer.append(""); - writer.append(""); - appendWhitespace(writer); - } - - public void renderFormatFieldRowOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException { - writer.append(""); - appendWhitespace(writer); - } - - public void renderFormatFieldRowClose(Appendable writer, Map context, ModelForm modelForm) throws IOException { - writer.append(""); - appendWhitespace(writer); - } - - - public void renderFormatFieldRowTitleCellOpen(Appendable writer, Map context, ModelFormField modelFormField) throws IOException { - writer.append(""); - writer.append(""); - appendWhitespace(writer); - } - - public void renderFormatFieldRowTitleCellClose(Appendable writer, Map context, ModelFormField modelFormField) throws IOException { - writer.append(""); - writer.append(""); - appendWhitespace(writer); - } - - public void renderFormatFieldRowSpacerCell(Appendable writer, Map context, ModelFormField modelFormField) throws IOException { - } - - public void renderFormatFieldRowWidgetCellOpen(Appendable writer, Map context, ModelFormField modelFormField, int positions, int positionSpan, Integer nextPositionInRow) throws IOException { - writer.append(""); - appendWhitespace(writer); - } - - public void renderFormatFieldRowWidgetCellClose(Appendable writer, Map context, ModelFormField modelFormField, int positions, int positionSpan, Integer nextPositionInRow) throws IOException { - writer.append(""); - appendWhitespace(writer); - } - - public void renderFormatEmptySpace(Appendable writer, Map context, ModelForm modelForm) throws IOException { - // TODO - } - - public void renderTextFindField(Appendable writer, Map context, TextFindField textFindField) throws IOException { - ModelFormField modelFormField = textFindField.getModelFormField(); - this.makeBlockString(writer, modelFormField.getWidgetStyle(), modelFormField.getEntry(context, textFindField.getDefaultValue(context))); - appendWhitespace(writer); - } - - public void renderRangeFindField(Appendable writer, Map context, RangeFindField rangeFindField) throws IOException { - ModelFormField modelFormField = rangeFindField.getModelFormField(); - this.makeBlockString(writer, modelFormField.getWidgetStyle(), modelFormField.getEntry(context, rangeFindField.getDefaultValue(context))); - appendWhitespace(writer); - } - - public void renderDateFindField(Appendable writer, Map context, DateFindField dateFindField) throws IOException { - ModelFormField modelFormField = dateFindField.getModelFormField(); - this.makeBlockString(writer, modelFormField.getWidgetStyle(), modelFormField.getEntry(context, dateFindField.getDefaultValue(context))); - appendWhitespace(writer); - } - - public void renderLookupField(Appendable writer, Map context, LookupField lookupField) throws IOException { - ModelFormField modelFormField = lookupField.getModelFormField(); - this.makeBlockString(writer, modelFormField.getWidgetStyle(), modelFormField.getEntry(context, lookupField.getDefaultValue(context))); - appendWhitespace(writer); - } - - public void renderNextPrev(Appendable writer, Map context, ModelForm modelForm) throws IOException { - } - - public void renderFileField(Appendable writer, Map context, FileField textField) throws IOException { - ModelFormField modelFormField = textField.getModelFormField(); - this.makeBlockString(writer, modelFormField.getWidgetStyle(), modelFormField.getEntry(context, textField.getDefaultValue(context))); - appendWhitespace(writer); - } - - public void renderPasswordField(Appendable writer, Map context, PasswordField passwordField) throws IOException { - this.makeBlockString(writer, null, ""); - } - - public void renderImageField(Appendable writer, Map context, ImageField imageField) throws IOException { - // TODO - this.makeBlockString(writer, null, ""); - } - - public void renderFieldGroupOpen(Appendable writer, Map context, ModelForm.FieldGroup fieldGroup) throws IOException { - // TODO - } - - public void renderFieldGroupClose(Appendable writer, Map context, ModelForm.FieldGroup fieldGroup) throws IOException { - // TODO - } - - public void renderBanner(Appendable writer, Map context, ModelForm.Banner banner) throws IOException { - // TODO - this.makeBlockString(writer, null, ""); - } - - public void renderHyperlinkTitle(Appendable writer, Map context, ModelFormField modelFormField, String titleText) throws IOException { - } - - public void renderContainerFindField(Appendable writer, Map context, ContainerField containerField) throws IOException { - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.renderer.fo; + +import java.io.IOException; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.ofbiz.base.util.UtilFormatOut; +import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.widget.WidgetWorker; +import org.ofbiz.widget.model.FieldInfo; +import org.ofbiz.widget.model.ModelForm; +import org.ofbiz.widget.model.ModelFormField; +import org.ofbiz.widget.model.ModelFormField.CheckField; +import org.ofbiz.widget.model.ModelFormField.ContainerField; +import org.ofbiz.widget.model.ModelFormField.DateFindField; +import org.ofbiz.widget.model.ModelFormField.DateTimeField; +import org.ofbiz.widget.model.ModelFormField.DisplayField; +import org.ofbiz.widget.model.ModelFormField.DropDownField; +import org.ofbiz.widget.model.ModelFormField.FieldInfoWithOptions; +import org.ofbiz.widget.model.ModelFormField.FileField; +import org.ofbiz.widget.model.ModelFormField.HiddenField; +import org.ofbiz.widget.model.ModelFormField.HyperlinkField; +import org.ofbiz.widget.model.ModelFormField.IgnoredField; +import org.ofbiz.widget.model.ModelFormField.ImageField; +import org.ofbiz.widget.model.ModelFormField.LookupField; +import org.ofbiz.widget.model.ModelFormField.PasswordField; +import org.ofbiz.widget.model.ModelFormField.RadioField; +import org.ofbiz.widget.model.ModelFormField.RangeFindField; +import org.ofbiz.widget.model.ModelFormField.ResetField; +import org.ofbiz.widget.model.ModelFormField.SubmitField; +import org.ofbiz.widget.model.ModelFormField.TextField; +import org.ofbiz.widget.model.ModelFormField.TextFindField; +import org.ofbiz.widget.model.ModelFormField.TextareaField; +import org.ofbiz.widget.model.ModelWidget; +import org.ofbiz.widget.renderer.FormStringRenderer; +import org.ofbiz.widget.renderer.html.HtmlWidgetRenderer; + + +/** + * Widget Library - FO Form Renderer implementation + * + */ +public class FoFormRenderer extends HtmlWidgetRenderer implements FormStringRenderer { + + public static final String module = FoFormRenderer.class.getName(); + + HttpServletRequest request; + HttpServletResponse response; + + public FoFormRenderer() {} + + public FoFormRenderer(HttpServletRequest request, HttpServletResponse response) throws IOException { + this.request = request; + this.response = response; + } + + private void makeBlockString(Appendable writer, String widgetStyle, String text) throws IOException { + writer.append(""); + writer.append(UtilFormatOut.encodeXmlValue(text)); + writer.append(""); + } + + public void renderDisplayField(Appendable writer, Map context, DisplayField displayField) throws IOException { + ModelFormField modelFormField = displayField.getModelFormField(); + this.makeBlockString(writer, modelFormField.getWidgetStyle(), displayField.getDescription(context)); + appendWhitespace(writer); + } + + public void renderHyperlinkField(Appendable writer, Map context, HyperlinkField hyperlinkField) throws IOException { + ModelFormField modelFormField = hyperlinkField.getModelFormField(); + this.makeBlockString(writer, modelFormField.getWidgetStyle(), hyperlinkField.getDescription(context)); + appendWhitespace(writer); + } + + public void renderTextField(Appendable writer, Map context, TextField textField) throws IOException { + ModelFormField modelFormField = textField.getModelFormField(); + this.makeBlockString(writer, modelFormField.getWidgetStyle(), modelFormField.getEntry(context, textField.getDefaultValue(context))); + appendWhitespace(writer); + } + + public void renderTextareaField(Appendable writer, Map context, TextareaField textareaField) throws IOException { + ModelFormField modelFormField = textareaField.getModelFormField(); + this.makeBlockString(writer, modelFormField.getWidgetStyle(), modelFormField.getEntry(context, textareaField.getDefaultValue(context))); + appendWhitespace(writer); + } + + public void renderDateTimeField(Appendable writer, Map context, DateTimeField dateTimeField) throws IOException { + ModelFormField modelFormField = dateTimeField.getModelFormField(); + this.makeBlockString(writer, modelFormField.getWidgetStyle(), modelFormField.getEntry(context, dateTimeField.getDefaultValue(context))); + appendWhitespace(writer); + } + + public void renderDropDownField(Appendable writer, Map context, DropDownField dropDownField) throws IOException { + ModelFormField modelFormField = dropDownField.getModelFormField(); + String currentValue = modelFormField.getEntry(context); + List allOptionValues = dropDownField.getAllOptionValues(context, WidgetWorker.getDelegator(context)); + // if the current value should go first, display it + if (UtilValidate.isNotEmpty(currentValue) && "first-in-list".equals(dropDownField.getCurrent())) { + String explicitDescription = dropDownField.getCurrentDescription(context); + if (UtilValidate.isNotEmpty(explicitDescription)) { + this.makeBlockString(writer, modelFormField.getWidgetStyle(), explicitDescription); + } else { + this.makeBlockString(writer, modelFormField.getWidgetStyle(), FieldInfoWithOptions.getDescriptionForOptionKey(currentValue, allOptionValues)); + } + } else { + boolean optionSelected = false; + for (ModelFormField.OptionValue optionValue : allOptionValues) { + String noCurrentSelectedKey = dropDownField.getNoCurrentSelectedKey(context); + if ((UtilValidate.isNotEmpty(currentValue) && currentValue.equals(optionValue.getKey()) && "selected".equals(dropDownField.getCurrent())) || + (UtilValidate.isEmpty(currentValue) && noCurrentSelectedKey != null && noCurrentSelectedKey.equals(optionValue.getKey()))) { + this.makeBlockString(writer, modelFormField.getWidgetStyle(), optionValue.getDescription()); + optionSelected = true; + break; + } + } + if (!optionSelected) { + this.makeBlockString(writer, null, ""); + } + } + appendWhitespace(writer); + } + + public void renderCheckField(Appendable writer, Map context, CheckField checkField) throws IOException { + this.makeBlockString(writer, null, ""); + } + + public void renderRadioField(Appendable writer, Map context, RadioField radioField) throws IOException { + this.makeBlockString(writer, null, ""); + } + + public void renderSubmitField(Appendable writer, Map context, SubmitField submitField) throws IOException { + this.makeBlockString(writer, null, ""); + } + + public void renderResetField(Appendable writer, Map context, ResetField resetField) throws IOException { + this.makeBlockString(writer, null, ""); + } + + public void renderHiddenField(Appendable writer, Map context, HiddenField hiddenField) throws IOException { + } + + public void renderHiddenField(Appendable writer, Map context, ModelFormField modelFormField, String value) throws IOException { + } + + public void renderIgnoredField(Appendable writer, Map context, IgnoredField ignoredField) throws IOException { + } + + public void renderFieldTitle(Appendable writer, Map context, ModelFormField modelFormField) throws IOException { + String tempTitleText = modelFormField.getTitle(context); + writer.append(tempTitleText); + } + + public void renderSingleFormFieldTitle(Appendable writer, Map context, ModelFormField modelFormField) throws IOException { + renderFieldTitle(writer, context, modelFormField); + } + + public void renderFormOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException { + this.widgetCommentsEnabled = ModelWidget.widgetBoundaryCommentsEnabled(context); + renderBeginningBoundaryComment(writer, "Form Widget", modelForm); + } + + public void renderFormClose(Appendable writer, Map context, ModelForm modelForm) throws IOException { + renderEndingBoundaryComment(writer, "Form Widget", modelForm); + } + + public void renderMultiFormClose(Appendable writer, Map context, ModelForm modelForm) throws IOException { + renderEndingBoundaryComment(writer, "Form Widget", modelForm); + } + + public void renderFormatListWrapperOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException { + writer.append(""); + List childFieldList = modelForm.getFieldList(); + for (ModelFormField childField : childFieldList) { + int childFieldType = childField.getFieldInfo().getFieldType(); + if (childFieldType == FieldInfo.HIDDEN || childFieldType == FieldInfo.IGNORED) { + continue; + } + writer.append(""); + appendWhitespace(writer); + } + appendWhitespace(writer); + } + + public void renderFormatListWrapperClose(Appendable writer, Map context, ModelForm modelForm) throws IOException { + writer.append(""); + writer.append(""); + appendWhitespace(writer); + } + + public void renderFormatHeaderRowOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException { + writer.append(""); + writer.append(""); + appendWhitespace(writer); + } + + public void renderFormatHeaderRowClose(Appendable writer, Map context, ModelForm modelForm) throws IOException { + writer.append(""); + writer.append(""); + writer.append(""); + // FIXME: this is an hack to avoid FOP rendering errors for empty lists (fo:table-body cannot be null) + writer.append(""); + appendWhitespace(writer); + } + + public void renderFormatHeaderRowCellOpen(Appendable writer, Map context, ModelForm modelForm, ModelFormField modelFormField, int positionSpan) throws IOException { + writer.append(" 1) { + writer.append("number-columns-spanned=\""); + writer.append(Integer.toString(positionSpan)); + writer.append("\" "); + } + writer.append("font-weight=\"bold\" text-align=\"center\" border=\"solid black\" padding=\"2pt\""); + writer.append(">"); + writer.append(""); + appendWhitespace(writer); + } + + public void renderFormatHeaderRowCellClose(Appendable writer, Map context, ModelForm modelForm, ModelFormField modelFormField) throws IOException { + writer.append(""); + writer.append(""); + appendWhitespace(writer); + } + + public void renderFormatHeaderRowFormCellOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException { + writer.append(""); + appendWhitespace(writer); + } + + public void renderFormatHeaderRowFormCellClose(Appendable writer, Map context, ModelForm modelForm) throws IOException { + writer.append(""); + appendWhitespace(writer); + } + + public void renderFormatHeaderRowFormCellTitleSeparator(Appendable writer, Map context, ModelForm modelForm, ModelFormField modelFormField, boolean isLast) throws IOException { + } + + public void renderFormatItemRowOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException { + writer.append(""); + appendWhitespace(writer); + } + + public void renderFormatItemRowClose(Appendable writer, Map context, ModelForm modelForm) throws IOException { + writer.append(""); + appendWhitespace(writer); + } + + public void renderFormatItemRowCellOpen(Appendable writer, Map context, ModelForm modelForm, ModelFormField modelFormField, int positionSpan) throws IOException { + writer.append(" 1) { + writer.append("number-columns-spanned=\""); + writer.append(Integer.toString(positionSpan)); + writer.append("\" "); + } + String areaStyle = modelFormField.getWidgetAreaStyle(); + if (UtilValidate.isEmpty(areaStyle)) { + areaStyle = "tabletext"; + } + writer.append(FoScreenRenderer.getFoStyle(areaStyle)); + writer.append(">"); + appendWhitespace(writer); + } + + public void renderFormatItemRowCellClose(Appendable writer, Map context, ModelForm modelForm, ModelFormField modelFormField) throws IOException { + writer.append(""); + appendWhitespace(writer); + } + + public void renderFormatItemRowFormCellOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException { + writer.append(""); + appendWhitespace(writer); + } + + public void renderFormatItemRowFormCellClose(Appendable writer, Map context, ModelForm modelForm) throws IOException { + writer.append(""); + appendWhitespace(writer); + } + + // TODO: multi columns (position attribute) in single forms are still not implemented + public void renderFormatSingleWrapperOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException { + writer.append(""); + appendWhitespace(writer); + writer.append(""); + appendWhitespace(writer); + writer.append(""); + appendWhitespace(writer); + writer.append(""); + appendWhitespace(writer); + } + public void renderFormatSingleWrapperClose(Appendable writer, Map context, ModelForm modelForm) throws IOException { + writer.append(""); + writer.append(""); + appendWhitespace(writer); + } + + public void renderFormatFieldRowOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException { + writer.append(""); + appendWhitespace(writer); + } + + public void renderFormatFieldRowClose(Appendable writer, Map context, ModelForm modelForm) throws IOException { + writer.append(""); + appendWhitespace(writer); + } + + + public void renderFormatFieldRowTitleCellOpen(Appendable writer, Map context, ModelFormField modelFormField) throws IOException { + writer.append(""); + writer.append(""); + appendWhitespace(writer); + } + + public void renderFormatFieldRowTitleCellClose(Appendable writer, Map context, ModelFormField modelFormField) throws IOException { + writer.append(""); + writer.append(""); + appendWhitespace(writer); + } + + public void renderFormatFieldRowSpacerCell(Appendable writer, Map context, ModelFormField modelFormField) throws IOException { + } + + public void renderFormatFieldRowWidgetCellOpen(Appendable writer, Map context, ModelFormField modelFormField, int positions, int positionSpan, Integer nextPositionInRow) throws IOException { + writer.append(""); + appendWhitespace(writer); + } + + public void renderFormatFieldRowWidgetCellClose(Appendable writer, Map context, ModelFormField modelFormField, int positions, int positionSpan, Integer nextPositionInRow) throws IOException { + writer.append(""); + appendWhitespace(writer); + } + + public void renderFormatEmptySpace(Appendable writer, Map context, ModelForm modelForm) throws IOException { + // TODO + } + + public void renderTextFindField(Appendable writer, Map context, TextFindField textFindField) throws IOException { + ModelFormField modelFormField = textFindField.getModelFormField(); + this.makeBlockString(writer, modelFormField.getWidgetStyle(), modelFormField.getEntry(context, textFindField.getDefaultValue(context))); + appendWhitespace(writer); + } + + public void renderRangeFindField(Appendable writer, Map context, RangeFindField rangeFindField) throws IOException { + ModelFormField modelFormField = rangeFindField.getModelFormField(); + this.makeBlockString(writer, modelFormField.getWidgetStyle(), modelFormField.getEntry(context, rangeFindField.getDefaultValue(context))); + appendWhitespace(writer); + } + + public void renderDateFindField(Appendable writer, Map context, DateFindField dateFindField) throws IOException { + ModelFormField modelFormField = dateFindField.getModelFormField(); + this.makeBlockString(writer, modelFormField.getWidgetStyle(), modelFormField.getEntry(context, dateFindField.getDefaultValue(context))); + appendWhitespace(writer); + } + + public void renderLookupField(Appendable writer, Map context, LookupField lookupField) throws IOException { + ModelFormField modelFormField = lookupField.getModelFormField(); + this.makeBlockString(writer, modelFormField.getWidgetStyle(), modelFormField.getEntry(context, lookupField.getDefaultValue(context))); + appendWhitespace(writer); + } + + public void renderNextPrev(Appendable writer, Map context, ModelForm modelForm) throws IOException { + } + + public void renderFileField(Appendable writer, Map context, FileField textField) throws IOException { + ModelFormField modelFormField = textField.getModelFormField(); + this.makeBlockString(writer, modelFormField.getWidgetStyle(), modelFormField.getEntry(context, textField.getDefaultValue(context))); + appendWhitespace(writer); + } + + public void renderPasswordField(Appendable writer, Map context, PasswordField passwordField) throws IOException { + this.makeBlockString(writer, null, ""); + } + + public void renderImageField(Appendable writer, Map context, ImageField imageField) throws IOException { + // TODO + this.makeBlockString(writer, null, ""); + } + + public void renderFieldGroupOpen(Appendable writer, Map context, ModelForm.FieldGroup fieldGroup) throws IOException { + // TODO + } + + public void renderFieldGroupClose(Appendable writer, Map context, ModelForm.FieldGroup fieldGroup) throws IOException { + // TODO + } + + public void renderBanner(Appendable writer, Map context, ModelForm.Banner banner) throws IOException { + // TODO + this.makeBlockString(writer, null, ""); + } + + public void renderHyperlinkTitle(Appendable writer, Map context, ModelFormField modelFormField, String titleText) throws IOException { + } + + public void renderContainerFindField(Appendable writer, Map context, ContainerField containerField) throws IOException { + } +} diff --git a/framework/widget/src/org/ofbiz/widget/fo/FoScreenRenderer.java b/framework/widget/src/org/ofbiz/widget/renderer/fo/FoScreenRenderer.java similarity index 94% rename from framework/widget/src/org/ofbiz/widget/fo/FoScreenRenderer.java rename to framework/widget/src/org/ofbiz/widget/renderer/fo/FoScreenRenderer.java index 882e013544..3ffa1c9877 100644 --- a/framework/widget/src/org/ofbiz/widget/fo/FoScreenRenderer.java +++ b/framework/widget/src/org/ofbiz/widget/renderer/fo/FoScreenRenderer.java @@ -1,195 +1,195 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget.fo; - -import java.io.IOException; -import java.util.Map; - -import org.ofbiz.base.util.GeneralException; -import org.ofbiz.base.util.UtilProperties; -import org.ofbiz.base.util.UtilValidate; -import org.ofbiz.widget.ModelWidget; -import org.ofbiz.widget.html.HtmlWidgetRenderer; -import org.ofbiz.widget.screen.ModelScreenWidget; -import org.ofbiz.widget.screen.ScreenStringRenderer; -import org.ofbiz.widget.screen.ModelScreenWidget.ColumnContainer; -import org.ofbiz.entity.GenericValue; - -/** - * Widget Library - HTML Form Renderer implementation - * @deprecated Use MacroScreenRenderer. - */ -public class FoScreenRenderer extends HtmlWidgetRenderer implements ScreenStringRenderer { - - public static final String module = FoScreenRenderer.class.getName(); - - public FoScreenRenderer() {} - - // This is a util method to get the style from a property file - public static String getFoStyle(String styleName) { - String value = UtilProperties.getPropertyValue("fo-styles.properties", styleName); - if (value.equals(styleName)) { - return ""; - } - return value; - } - - public String getRendererName() { - return "xsl-fo"; - } - - public void renderScreenBegin(Appendable writer, Map context) throws IOException { - } - - public void renderScreenEnd(Appendable writer, Map context) throws IOException { - - } - - public void renderSectionBegin(Appendable writer, Map context, ModelScreenWidget.Section section) throws IOException { - if (section.isMainSection()) { - this.widgetCommentsEnabled = ModelWidget.widgetBoundaryCommentsEnabled(context); - } - renderBeginningBoundaryComment(writer, section.isMainSection()?"Screen":"Section Widget", section); - } - public void renderSectionEnd(Appendable writer, Map context, ModelScreenWidget.Section section) throws IOException { - renderEndingBoundaryComment(writer, section.isMainSection()?"Screen":"Section Widget", section); - } - - public void renderContainerBegin(Appendable writer, Map context, ModelScreenWidget.Container container) throws IOException { - writer.append(""); - appendWhitespace(writer); - } - public void renderContainerEnd(Appendable writer, Map context, ModelScreenWidget.Container container) throws IOException { - writer.append(""); - appendWhitespace(writer); - } - - public void renderLabel(Appendable writer, Map context, ModelScreenWidget.Label label) throws IOException { - String labelText = label.getText(context); - if (UtilValidate.isEmpty(labelText)) { - // nothing to render - return; - } - // open tag - String style = label.getStyle(context); - if (UtilValidate.isNotEmpty(style)) { - writer.append(""); - // the text - writer.append(labelText); - // close tag - writer.append(""); - } else { - writer.append(labelText); - } - appendWhitespace(writer); - } - - public void renderHorizontalSeparator(Appendable writer, Map context, ModelScreenWidget.HorizontalSeparator separator) throws IOException { - writer.append(""); - appendWhitespace(writer); - writer.append(""); - appendWhitespace(writer); - writer.append(""); - appendWhitespace(writer); - } - - public void renderLink(Appendable writer, Map context, ModelScreenWidget.ScreenLink link) throws IOException { - // TODO: not implemented - } - - public void renderImage(Appendable writer, Map context, ModelScreenWidget.ScreenImage image) throws IOException { - // TODO: not implemented - } - - public void renderContentBegin(Appendable writer, Map context, ModelScreenWidget.Content content) throws IOException { - // TODO: not implemented - } - - public void renderContentBody(Appendable writer, Map context, ModelScreenWidget.Content content) throws IOException { - // TODO: not implemented - } - - public void renderContentEnd(Appendable writer, Map context, ModelScreenWidget.Content content) throws IOException { - // TODO: not implemented - } - - public void renderContentFrame(Appendable writer, Map context, ModelScreenWidget.Content content) throws IOException { - // TODO: not implemented - } - - public void renderSubContentBegin(Appendable writer, Map context, ModelScreenWidget.SubContent content) throws IOException { - // TODO: not implemented - } - - public void renderSubContentBody(Appendable writer, Map context, ModelScreenWidget.SubContent content) throws IOException { - // TODO: not implemented - } - - public void renderSubContentEnd(Appendable writer, Map context, ModelScreenWidget.SubContent content) throws IOException { - // TODO: not implemented - } - - public void renderScreenletBegin(Appendable writer, Map context, boolean collapsed, ModelScreenWidget.Screenlet screenlet) throws IOException { - // TODO: not implemented - } - - public void renderScreenletSubWidget(Appendable writer, Map context, ModelScreenWidget subWidget, ModelScreenWidget.Screenlet screenlet) throws GeneralException { - // TODO: not implemented - } - - public void renderScreenletEnd(Appendable writer, Map context, ModelScreenWidget.Screenlet screenlet) throws IOException { - // TODO: not implemented - } - - public void renderPortalPageBegin(Appendable writer, Map context, ModelScreenWidget.PortalPage portalPage) throws GeneralException, IOException { - // TODO: not implemented - } - public void renderPortalPageEnd(Appendable writer, Map context, ModelScreenWidget.PortalPage portalPage) throws GeneralException, IOException { - // TODO: not implemented - } - public void renderPortalPageColumnBegin(Appendable writer, Map context, ModelScreenWidget.PortalPage portalPage, GenericValue portalPageColumn) throws GeneralException, IOException { - // TODO: not implemented - } - public void renderPortalPageColumnEnd(Appendable writer, Map context, ModelScreenWidget.PortalPage portalPage, GenericValue portalPageColumn) throws GeneralException, IOException { - // TODO: not implemented - } - public void renderPortalPagePortletBegin(Appendable writer, Map context, ModelScreenWidget.PortalPage portalPage, GenericValue portalPortlet) throws GeneralException, IOException { - // TODO: not implemented - } - public void renderPortalPagePortletEnd(Appendable writer, Map context, ModelScreenWidget.PortalPage portalPage, GenericValue portalPortlet) throws GeneralException, IOException { - // TODO: not implemented - } - public void renderPortalPagePortletBody(Appendable writer, Map context, ModelScreenWidget.PortalPage portalPage, GenericValue portalPortlet) throws GeneralException, IOException { - // TODO: not implemented - } - - @Override - public void renderColumnContainer(Appendable writer, Map context, ColumnContainer columnContainer) throws IOException { - // TODO: not implemented - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.renderer.fo; + +import java.io.IOException; +import java.util.Map; + +import org.ofbiz.base.util.GeneralException; +import org.ofbiz.base.util.UtilProperties; +import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.entity.GenericValue; +import org.ofbiz.widget.model.ModelScreenWidget; +import org.ofbiz.widget.model.ModelScreenWidget.ColumnContainer; +import org.ofbiz.widget.model.ModelWidget; +import org.ofbiz.widget.renderer.ScreenStringRenderer; +import org.ofbiz.widget.renderer.html.HtmlWidgetRenderer; + +/** + * Widget Library - HTML Form Renderer implementation + * @deprecated Use MacroScreenRenderer. + */ +public class FoScreenRenderer extends HtmlWidgetRenderer implements ScreenStringRenderer { + + public static final String module = FoScreenRenderer.class.getName(); + + public FoScreenRenderer() {} + + // This is a util method to get the style from a property file + public static String getFoStyle(String styleName) { + String value = UtilProperties.getPropertyValue("fo-styles.properties", styleName); + if (value.equals(styleName)) { + return ""; + } + return value; + } + + public String getRendererName() { + return "xsl-fo"; + } + + public void renderScreenBegin(Appendable writer, Map context) throws IOException { + } + + public void renderScreenEnd(Appendable writer, Map context) throws IOException { + + } + + public void renderSectionBegin(Appendable writer, Map context, ModelScreenWidget.Section section) throws IOException { + if (section.isMainSection()) { + this.widgetCommentsEnabled = ModelWidget.widgetBoundaryCommentsEnabled(context); + } + renderBeginningBoundaryComment(writer, section.isMainSection()?"Screen":"Section Widget", section); + } + public void renderSectionEnd(Appendable writer, Map context, ModelScreenWidget.Section section) throws IOException { + renderEndingBoundaryComment(writer, section.isMainSection()?"Screen":"Section Widget", section); + } + + public void renderContainerBegin(Appendable writer, Map context, ModelScreenWidget.Container container) throws IOException { + writer.append(""); + appendWhitespace(writer); + } + public void renderContainerEnd(Appendable writer, Map context, ModelScreenWidget.Container container) throws IOException { + writer.append(""); + appendWhitespace(writer); + } + + public void renderLabel(Appendable writer, Map context, ModelScreenWidget.Label label) throws IOException { + String labelText = label.getText(context); + if (UtilValidate.isEmpty(labelText)) { + // nothing to render + return; + } + // open tag + String style = label.getStyle(context); + if (UtilValidate.isNotEmpty(style)) { + writer.append(""); + // the text + writer.append(labelText); + // close tag + writer.append(""); + } else { + writer.append(labelText); + } + appendWhitespace(writer); + } + + public void renderHorizontalSeparator(Appendable writer, Map context, ModelScreenWidget.HorizontalSeparator separator) throws IOException { + writer.append(""); + appendWhitespace(writer); + writer.append(""); + appendWhitespace(writer); + writer.append(""); + appendWhitespace(writer); + } + + public void renderLink(Appendable writer, Map context, ModelScreenWidget.ScreenLink link) throws IOException { + // TODO: not implemented + } + + public void renderImage(Appendable writer, Map context, ModelScreenWidget.ScreenImage image) throws IOException { + // TODO: not implemented + } + + public void renderContentBegin(Appendable writer, Map context, ModelScreenWidget.Content content) throws IOException { + // TODO: not implemented + } + + public void renderContentBody(Appendable writer, Map context, ModelScreenWidget.Content content) throws IOException { + // TODO: not implemented + } + + public void renderContentEnd(Appendable writer, Map context, ModelScreenWidget.Content content) throws IOException { + // TODO: not implemented + } + + public void renderContentFrame(Appendable writer, Map context, ModelScreenWidget.Content content) throws IOException { + // TODO: not implemented + } + + public void renderSubContentBegin(Appendable writer, Map context, ModelScreenWidget.SubContent content) throws IOException { + // TODO: not implemented + } + + public void renderSubContentBody(Appendable writer, Map context, ModelScreenWidget.SubContent content) throws IOException { + // TODO: not implemented + } + + public void renderSubContentEnd(Appendable writer, Map context, ModelScreenWidget.SubContent content) throws IOException { + // TODO: not implemented + } + + public void renderScreenletBegin(Appendable writer, Map context, boolean collapsed, ModelScreenWidget.Screenlet screenlet) throws IOException { + // TODO: not implemented + } + + public void renderScreenletSubWidget(Appendable writer, Map context, ModelScreenWidget subWidget, ModelScreenWidget.Screenlet screenlet) throws GeneralException { + // TODO: not implemented + } + + public void renderScreenletEnd(Appendable writer, Map context, ModelScreenWidget.Screenlet screenlet) throws IOException { + // TODO: not implemented + } + + public void renderPortalPageBegin(Appendable writer, Map context, ModelScreenWidget.PortalPage portalPage) throws GeneralException, IOException { + // TODO: not implemented + } + public void renderPortalPageEnd(Appendable writer, Map context, ModelScreenWidget.PortalPage portalPage) throws GeneralException, IOException { + // TODO: not implemented + } + public void renderPortalPageColumnBegin(Appendable writer, Map context, ModelScreenWidget.PortalPage portalPage, GenericValue portalPageColumn) throws GeneralException, IOException { + // TODO: not implemented + } + public void renderPortalPageColumnEnd(Appendable writer, Map context, ModelScreenWidget.PortalPage portalPage, GenericValue portalPageColumn) throws GeneralException, IOException { + // TODO: not implemented + } + public void renderPortalPagePortletBegin(Appendable writer, Map context, ModelScreenWidget.PortalPage portalPage, GenericValue portalPortlet) throws GeneralException, IOException { + // TODO: not implemented + } + public void renderPortalPagePortletEnd(Appendable writer, Map context, ModelScreenWidget.PortalPage portalPage, GenericValue portalPortlet) throws GeneralException, IOException { + // TODO: not implemented + } + public void renderPortalPagePortletBody(Appendable writer, Map context, ModelScreenWidget.PortalPage portalPage, GenericValue portalPortlet) throws GeneralException, IOException { + // TODO: not implemented + } + + @Override + public void renderColumnContainer(Appendable writer, Map context, ColumnContainer columnContainer) throws IOException { + // TODO: not implemented + } +} diff --git a/framework/widget/src/org/ofbiz/widget/screen/ScreenFopViewHandler.java b/framework/widget/src/org/ofbiz/widget/renderer/fo/ScreenFopViewHandler.java similarity index 93% rename from framework/widget/src/org/ofbiz/widget/screen/ScreenFopViewHandler.java rename to framework/widget/src/org/ofbiz/widget/renderer/fo/ScreenFopViewHandler.java index c76018cae2..ff649d060b 100644 --- a/framework/widget/src/org/ofbiz/widget/screen/ScreenFopViewHandler.java +++ b/framework/widget/src/org/ofbiz/widget/renderer/fo/ScreenFopViewHandler.java @@ -1,141 +1,144 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget.screen; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.Reader; -import java.io.StringReader; -import java.io.StringWriter; -import java.io.Writer; - -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.xml.transform.stream.StreamSource; - -import org.apache.fop.apps.Fop; -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.UtilCodec; -import org.ofbiz.base.util.UtilProperties; -import org.ofbiz.base.util.UtilValidate; -import org.ofbiz.entity.Delegator; -import org.ofbiz.entity.util.EntityUtilProperties; -import org.ofbiz.webapp.view.AbstractViewHandler; -import org.ofbiz.webapp.view.ApacheFopWorker; -import org.ofbiz.webapp.view.ViewHandlerException; -import org.ofbiz.widget.form.FormStringRenderer; -import org.ofbiz.widget.form.MacroFormRenderer; -import org.ofbiz.widget.html.HtmlScreenRenderer; - -/** - * Uses XSL-FO formatted templates to generate PDF, PCL, POSTSCRIPT etc. views - * This handler will use JPublish to generate the XSL-FO - */ -public class ScreenFopViewHandler extends AbstractViewHandler { - public static final String module = ScreenFopViewHandler.class.getName(); - protected static final String DEFAULT_ERROR_TEMPLATE = "component://common/widget/CommonScreens.xml#FoError"; - - protected ServletContext servletContext = null; - - /** - * @see org.ofbiz.webapp.view.ViewHandler#init(javax.servlet.ServletContext) - */ - @Override - public void init(ServletContext context) throws ViewHandlerException { - this.servletContext = context; - } - - /** - * @see org.ofbiz.webapp.view.ViewHandler#render(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) - */ - @Override - public void render(String name, String page, String info, String contentType, String encoding, HttpServletRequest request, HttpServletResponse response) throws ViewHandlerException { - - Delegator delegator = (Delegator) request.getAttribute("delegator"); - // render and obtain the XSL-FO - Writer writer = new StringWriter(); - try { - ScreenStringRenderer screenStringRenderer = new MacroScreenRenderer(EntityUtilProperties.getPropertyValue("widget", getName() + ".name", delegator), EntityUtilProperties.getPropertyValue("widget", getName() + ".screenrenderer", delegator)); - FormStringRenderer formStringRenderer = new MacroFormRenderer(EntityUtilProperties.getPropertyValue("widget", getName() + ".formrenderer", delegator), request, response); - // TODO: uncomment these lines when the renderers are implemented - //TreeStringRenderer treeStringRenderer = new MacroTreeRenderer(UtilProperties.getPropertyValue("widget", getName() + ".treerenderer"), writer); - //MenuStringRenderer menuStringRenderer = new MacroMenuRenderer(UtilProperties.getPropertyValue("widget", getName() + ".menurenderer"), writer); - ScreenRenderer screens = new ScreenRenderer(writer, null, screenStringRenderer); - screens.populateContextForRequest(request, response, servletContext); - - // this is the object used to render forms from their definitions - screens.getContext().put("formStringRenderer", formStringRenderer); - screens.getContext().put("simpleEncoder", UtilCodec.getEncoder(EntityUtilProperties.getPropertyValue("widget", getName() + ".encoder", delegator))); - screens.render(page); - } catch (Exception e) { - renderError("Problems with the response writer/output stream", e, "[Not Yet Rendered]", request, response); - return; - } - - // set the input source (XSL-FO) and generate the output stream of contentType - String screenOutString = writer.toString(); - if (!screenOutString.startsWith("\n" + screenOutString; - } - if (Debug.verboseOn()) Debug.logVerbose("XSL:FO Screen Output: " + screenOutString, module); - - if (UtilValidate.isEmpty(contentType)) { - contentType = UtilProperties.getPropertyValue("widget", getName() + ".default.contenttype"); - } - Reader reader = new StringReader(screenOutString); - StreamSource src = new StreamSource(reader); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - try { - Fop fop = ApacheFopWorker.createFopInstance(out, contentType); - ApacheFopWorker.transform(src, null, fop); - } catch (Exception e) { - renderError("Unable to transform FO file", e, screenOutString, request, response); - return; - } - // set the content type and length - response.setContentType(contentType); - response.setContentLength(out.size()); - - // write to the browser - try { - out.writeTo(response.getOutputStream()); - response.getOutputStream().flush(); - } catch (IOException e) { - renderError("Unable to write to OutputStream", e, screenOutString, request, response); - } - } - - protected void renderError(String msg, Exception e, String screenOutString, HttpServletRequest request, HttpServletResponse response) throws ViewHandlerException { - Debug.logError(msg + ": " + e + "; Screen XSL:FO text was:\n" + screenOutString, module); - try { - Writer writer = new StringWriter(); - ScreenRenderer screens = new ScreenRenderer(writer, null, new HtmlScreenRenderer()); - screens.populateContextForRequest(request, response, servletContext); - screens.getContext().put("errorMessage", msg + ": " + e); - screens.render(DEFAULT_ERROR_TEMPLATE); - response.setContentType("text/html"); - response.getWriter().write(writer.toString()); - writer.close(); - } catch (Exception x) { - Debug.logError("Multiple errors rendering FOP", module); - throw new ViewHandlerException("Multiple errors rendering FOP", x); - } - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.renderer.fo; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; +import java.io.Writer; + +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.xml.transform.stream.StreamSource; + +import org.apache.fop.apps.Fop; +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilCodec; +import org.ofbiz.base.util.UtilProperties; +import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.entity.Delegator; +import org.ofbiz.entity.util.EntityUtilProperties; +import org.ofbiz.webapp.view.AbstractViewHandler; +import org.ofbiz.webapp.view.ApacheFopWorker; +import org.ofbiz.webapp.view.ViewHandlerException; +import org.ofbiz.widget.renderer.FormStringRenderer; +import org.ofbiz.widget.renderer.ScreenRenderer; +import org.ofbiz.widget.renderer.ScreenStringRenderer; +import org.ofbiz.widget.renderer.html.HtmlScreenRenderer; +import org.ofbiz.widget.renderer.macro.MacroFormRenderer; +import org.ofbiz.widget.renderer.macro.MacroScreenRenderer; + +/** + * Uses XSL-FO formatted templates to generate PDF, PCL, POSTSCRIPT etc. views + * This handler will use JPublish to generate the XSL-FO + */ +public class ScreenFopViewHandler extends AbstractViewHandler { + public static final String module = ScreenFopViewHandler.class.getName(); + protected static final String DEFAULT_ERROR_TEMPLATE = "component://common/widget/CommonScreens.xml#FoError"; + + protected ServletContext servletContext = null; + + /** + * @see org.ofbiz.webapp.view.ViewHandler#init(javax.servlet.ServletContext) + */ + @Override + public void init(ServletContext context) throws ViewHandlerException { + this.servletContext = context; + } + + /** + * @see org.ofbiz.webapp.view.ViewHandler#render(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) + */ + @Override + public void render(String name, String page, String info, String contentType, String encoding, HttpServletRequest request, HttpServletResponse response) throws ViewHandlerException { + + Delegator delegator = (Delegator) request.getAttribute("delegator"); + // render and obtain the XSL-FO + Writer writer = new StringWriter(); + try { + ScreenStringRenderer screenStringRenderer = new MacroScreenRenderer(EntityUtilProperties.getPropertyValue("widget", getName() + ".name", delegator), EntityUtilProperties.getPropertyValue("widget", getName() + ".screenrenderer", delegator)); + FormStringRenderer formStringRenderer = new MacroFormRenderer(EntityUtilProperties.getPropertyValue("widget", getName() + ".formrenderer", delegator), request, response); + // TODO: uncomment these lines when the renderers are implemented + //TreeStringRenderer treeStringRenderer = new MacroTreeRenderer(UtilProperties.getPropertyValue("widget", getName() + ".treerenderer"), writer); + //MenuStringRenderer menuStringRenderer = new MacroMenuRenderer(UtilProperties.getPropertyValue("widget", getName() + ".menurenderer"), writer); + ScreenRenderer screens = new ScreenRenderer(writer, null, screenStringRenderer); + screens.populateContextForRequest(request, response, servletContext); + + // this is the object used to render forms from their definitions + screens.getContext().put("formStringRenderer", formStringRenderer); + screens.getContext().put("simpleEncoder", UtilCodec.getEncoder(EntityUtilProperties.getPropertyValue("widget", getName() + ".encoder", delegator))); + screens.render(page); + } catch (Exception e) { + renderError("Problems with the response writer/output stream", e, "[Not Yet Rendered]", request, response); + return; + } + + // set the input source (XSL-FO) and generate the output stream of contentType + String screenOutString = writer.toString(); + if (!screenOutString.startsWith("\n" + screenOutString; + } + if (Debug.verboseOn()) Debug.logVerbose("XSL:FO Screen Output: " + screenOutString, module); + + if (UtilValidate.isEmpty(contentType)) { + contentType = UtilProperties.getPropertyValue("widget", getName() + ".default.contenttype"); + } + Reader reader = new StringReader(screenOutString); + StreamSource src = new StreamSource(reader); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + try { + Fop fop = ApacheFopWorker.createFopInstance(out, contentType); + ApacheFopWorker.transform(src, null, fop); + } catch (Exception e) { + renderError("Unable to transform FO file", e, screenOutString, request, response); + return; + } + // set the content type and length + response.setContentType(contentType); + response.setContentLength(out.size()); + + // write to the browser + try { + out.writeTo(response.getOutputStream()); + response.getOutputStream().flush(); + } catch (IOException e) { + renderError("Unable to write to OutputStream", e, screenOutString, request, response); + } + } + + protected void renderError(String msg, Exception e, String screenOutString, HttpServletRequest request, HttpServletResponse response) throws ViewHandlerException { + Debug.logError(msg + ": " + e + "; Screen XSL:FO text was:\n" + screenOutString, module); + try { + Writer writer = new StringWriter(); + ScreenRenderer screens = new ScreenRenderer(writer, null, new HtmlScreenRenderer()); + screens.populateContextForRequest(request, response, servletContext); + screens.getContext().put("errorMessage", msg + ": " + e); + screens.render(DEFAULT_ERROR_TEMPLATE); + response.setContentType("text/html"); + response.getWriter().write(writer.toString()); + writer.close(); + } catch (Exception x) { + Debug.logError("Multiple errors rendering FOP", module); + throw new ViewHandlerException("Multiple errors rendering FOP", x); + } + } +} diff --git a/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java b/framework/widget/src/org/ofbiz/widget/renderer/html/HtmlFormRenderer.java similarity index 94% rename from framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java rename to framework/widget/src/org/ofbiz/widget/renderer/html/HtmlFormRenderer.java index 526da1c0d8..18998c33ed 100644 --- a/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java +++ b/framework/widget/src/org/ofbiz/widget/renderer/html/HtmlFormRenderer.java @@ -1,2823 +1,2823 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget.html; - -import java.io.IOException; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Map.Entry; - -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.UtilCodec; -import org.ofbiz.base.util.UtilGenerics; -import org.ofbiz.base.util.UtilHttp; -import org.ofbiz.base.util.UtilMisc; -import org.ofbiz.base.util.UtilProperties; -import org.ofbiz.base.util.UtilValidate; -import org.ofbiz.base.util.string.FlexibleStringExpander; -import org.ofbiz.base.util.template.FreeMarkerWorker; -import org.ofbiz.entity.Delegator; -import org.ofbiz.webapp.control.RequestHandler; -import org.ofbiz.webapp.taglib.ContentUrlTag; -import org.ofbiz.widget.CommonWidgetModels; -import org.ofbiz.widget.ModelWidget; -import org.ofbiz.widget.WidgetWorker; -import org.ofbiz.widget.form.FormRenderer; -import org.ofbiz.widget.form.FormStringRenderer; -import org.ofbiz.widget.form.MacroFormRenderer; -import org.ofbiz.widget.form.ModelForm; -import org.ofbiz.widget.form.ModelFormField; -import org.ofbiz.widget.form.ModelFormField.CheckField; -import org.ofbiz.widget.form.ModelFormField.ContainerField; -import org.ofbiz.widget.form.ModelFormField.DateFindField; -import org.ofbiz.widget.form.ModelFormField.DateTimeField; -import org.ofbiz.widget.form.ModelFormField.DisplayEntityField; -import org.ofbiz.widget.form.ModelFormField.DisplayField; -import org.ofbiz.widget.form.ModelFormField.DropDownField; -import org.ofbiz.widget.form.ModelFormField.FieldInfoWithOptions; -import org.ofbiz.widget.form.ModelFormField.FileField; -import org.ofbiz.widget.form.ModelFormField.HiddenField; -import org.ofbiz.widget.form.ModelFormField.HyperlinkField; -import org.ofbiz.widget.form.ModelFormField.IgnoredField; -import org.ofbiz.widget.form.ModelFormField.ImageField; -import org.ofbiz.widget.form.ModelFormField.LookupField; -import org.ofbiz.widget.form.ModelFormField.PasswordField; -import org.ofbiz.widget.form.ModelFormField.RadioField; -import org.ofbiz.widget.form.ModelFormField.RangeFindField; -import org.ofbiz.widget.form.ModelFormField.ResetField; -import org.ofbiz.widget.form.ModelFormField.SubmitField; -import org.ofbiz.widget.form.ModelFormField.TextField; -import org.ofbiz.widget.form.ModelFormField.TextFindField; -import org.ofbiz.widget.form.ModelFormField.TextareaField; -import org.ofbiz.widget.form.Paginator; -import org.ofbiz.widget.form.UtilHelpText; - -import freemarker.template.TemplateException; - -/** - * Widget Library - HTML Form Renderer implementation - */ -public class HtmlFormRenderer extends HtmlWidgetRenderer implements FormStringRenderer { - - public static final String module = HtmlFormRenderer.class.getName(); - - protected HttpServletRequest request; - protected HttpServletResponse response; - protected RequestHandler rh; - protected String lastFieldGroupId = ""; - protected boolean renderPagination = true; - protected boolean javaScriptEnabled = false; - private UtilCodec.SimpleEncoder internalEncoder; - - protected HtmlFormRenderer() {} - - public HtmlFormRenderer(HttpServletRequest request, HttpServletResponse response) { - this.request = request; - this.response = response; - ServletContext ctx = (ServletContext) request.getAttribute("servletContext"); - this.rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_"); - this.javaScriptEnabled = UtilHttp.isJavaScriptEnabled(request); - internalEncoder = UtilCodec.getEncoder("string"); - } - - public boolean getRenderPagination() { - return this.renderPagination; - } - - public void setRenderPagination(boolean renderPagination) { - this.renderPagination = renderPagination; - } - - public void appendOfbizUrl(Appendable writer, String location) throws IOException { - writer.append(this.rh.makeLink(this.request, this.response, location)); - } - - public void appendContentUrl(Appendable writer, String location) throws IOException { - ContentUrlTag.appendContentPrefix(this.request, writer); - writer.append(location); - } - - public void appendTooltip(Appendable writer, Map context, ModelFormField modelFormField) throws IOException { - // render the tooltip, in other methods too - String tooltip = modelFormField.getTooltip(context); - if (UtilValidate.isNotEmpty(tooltip)) { - writer.append(""); - writer.append(tooltip); - writer.append(""); - } - } - - public void addAsterisks(Appendable writer, Map context, ModelFormField modelFormField) throws IOException { - - boolean requiredField = modelFormField.getRequiredField(); - if (requiredField) { - String requiredStyle = modelFormField.getRequiredFieldStyle(); - - if (UtilValidate.isEmpty(requiredStyle)) { - writer.append("*"); - } - } - } - - public void appendClassNames(Appendable writer, Map context, ModelFormField modelFormField) throws IOException { - String className = modelFormField.getWidgetStyle(); - if (UtilValidate.isNotEmpty(className) || modelFormField.shouldBeRed(context)) { - writer.append(" class=\""); - writer.append(className); - // add a style of red if redWhen is true - if (modelFormField.shouldBeRed(context)) { - writer.append(" alert"); - } - writer.append('"'); - } - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderDisplayField(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelFormField.DisplayField) - */ - public void renderDisplayField(Appendable writer, Map context, DisplayField displayField) throws IOException { - ModelFormField modelFormField = displayField.getModelFormField(); - - StringBuilder str = new StringBuilder(); - - String idName = modelFormField.getCurrentContainerId(context); - - if (UtilValidate.isNotEmpty(modelFormField.getWidgetStyle()) || modelFormField.shouldBeRed(context)) { - str.append("'); - } - - if (str.length() > 0) { - writer.append(str.toString()); - } - String description = displayField.getDescription(context); - //Replace new lines with
- description = description.replaceAll("\n", "
"); - - if (UtilValidate.isEmpty(description)) { - this.renderFormatEmptySpace(writer, context, modelFormField.getModelForm()); - } else { - writer.append(description); - } - - if (str.length() > 0) { - writer.append("
"); - } - - ModelFormField.InPlaceEditor inPlaceEditor = displayField.getInPlaceEditor(); - boolean ajaxEnabled = inPlaceEditor != null && this.javaScriptEnabled; - - if (ajaxEnabled) { - writer.append(""); - } - - if (displayField instanceof DisplayEntityField) { - this.makeHyperlinkString(writer, ((DisplayEntityField) displayField).getSubHyperlink(), context); - } - - this.appendTooltip(writer, context, modelFormField); - - //appendWhitespace(writer); - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderHyperlinkField(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelFormField.HyperlinkField) - */ - public void renderHyperlinkField(Appendable writer, Map context, HyperlinkField hyperlinkField) throws IOException { - this.request.setAttribute("image", hyperlinkField.getImageLocation(context)); - ModelFormField modelFormField = hyperlinkField.getModelFormField(); - String description = encode(hyperlinkField.getDescription(context), modelFormField, context); - String confirmation = encode(hyperlinkField.getConfirmation(context), modelFormField, context); - WidgetWorker.makeHyperlinkByType(writer, hyperlinkField.getLinkType(), modelFormField.getWidgetStyle(), hyperlinkField.getUrlMode(), hyperlinkField.getTarget(context), - hyperlinkField.getParameterMap(context), description, hyperlinkField.getTargetWindow(context), confirmation, modelFormField, - this.request, this.response, context); - this.appendTooltip(writer, context, modelFormField); - //appendWhitespace(writer); - } - - public void makeHyperlinkString(Appendable writer, ModelFormField.SubHyperlink subHyperlink, Map context) throws IOException { - if (subHyperlink == null) { - return; - } - if (subHyperlink.shouldUse(context)) { - writer.append(' '); - String description = encode(subHyperlink.getDescription(context), subHyperlink.getModelFormField(), context); - WidgetWorker.makeHyperlinkByType(writer, subHyperlink.getLinkType(), subHyperlink.getStyle(context), subHyperlink.getUrlMode(), subHyperlink.getTarget(context), - subHyperlink.getParameterMap(context), description, subHyperlink.getTargetWindow(context), null, subHyperlink.getModelFormField(), - this.request, this.response, context); - } - } - - private String encode(String value, ModelFormField modelFormField, Map context) { - if (UtilValidate.isEmpty(value)) { - return value; - } - UtilCodec.SimpleEncoder encoder = (UtilCodec.SimpleEncoder)context.get("simpleEncoder"); - if (modelFormField.getEncodeOutput() && encoder != null) { - value = encoder.encode(value); - } else { - value = internalEncoder.encode(value); - } - return value; - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderTextField(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelFormField.TextField) - */ - public void renderTextField(Appendable writer, Map context, TextField textField) throws IOException { - ModelFormField modelFormField = textField.getModelFormField(); - - writer.append(" updateAreas = modelFormField.getOnChangeUpdateAreas(); - boolean ajaxEnabled = updateAreas != null && this.javaScriptEnabled; - if (!textField.getClientAutocompleteField() || ajaxEnabled) { - writer.append(" autocomplete=\"off\""); - } - - writer.append("/>"); - - this.addAsterisks(writer, context, modelFormField); - - this.makeHyperlinkString(writer, textField.getSubHyperlink(), context); - - this.appendTooltip(writer, context, modelFormField); - - if (ajaxEnabled) { - appendWhitespace(writer); - writer.append(""); - } - appendWhitespace(writer); - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderTextareaField(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelFormField.TextareaField) - */ - public void renderTextareaField(Appendable writer, Map context, TextareaField textareaField) throws IOException { - ModelFormField modelFormField = textareaField.getModelFormField(); - - writer.append("'); - - String value = modelFormField.getEntry(context, textareaField.getDefaultValue(context)); - if (UtilValidate.isNotEmpty(value)) { - writer.append(value); - } - - writer.append(""); - - if (textareaField.getVisualEditorEnable()) { - writer.append(""); - writer.append(""); - writer.append(""); - } - - this.addAsterisks(writer, context, modelFormField); - - this.appendTooltip(writer, context, modelFormField); - - //appendWhitespace(writer); - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderDateTimeField(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelFormField.DateTimeField) - */ - public void renderDateTimeField(Appendable writer, Map context, DateTimeField dateTimeField) throws IOException { - String macroLibraryPath = UtilProperties.getPropertyValue("widget", "screen.formrenderer"); - try { - MacroFormRenderer macroFormRenderer = new MacroFormRenderer(macroLibraryPath, this.request, this.response); - macroFormRenderer.renderDateTimeField(writer, context, dateTimeField); - } catch (TemplateException e) { - Debug.logError(e, "Error rendering screen thru ftl macro: renderDateTimeField", module); - } catch (IOException e) { - Debug.logError(e, "Error rendering screen thru ftl, macro: renderDateTimeField", module); - } - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderDropDownField(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelFormField.DropDownField) - */ - public void renderDropDownField(Appendable writer, Map context, DropDownField dropDownField) throws IOException { - ModelFormField modelFormField = dropDownField.getModelFormField(); - ModelForm modelForm = modelFormField.getModelForm(); - ModelFormField.AutoComplete autoComplete = dropDownField.getAutoComplete(); - boolean ajaxEnabled = autoComplete != null && this.javaScriptEnabled; - List allOptionValues = dropDownField.getAllOptionValues(context, WidgetWorker.getDelegator(context)); - - String event = modelFormField.getEvent(); - String action = modelFormField.getAction(context); - - String currentValue = modelFormField.getEntry(context); - // Get the current value's description from the option value. If there - // is a localized version it will be there. - String currentDescription = null; - if (UtilValidate.isNotEmpty(currentValue)) { - for (ModelFormField.OptionValue optionValue : allOptionValues) { - if (encode(optionValue.getKey(), modelFormField, context).equals(currentValue)) { - currentDescription = optionValue.getDescription(); - break; - } - } - } - - if (ajaxEnabled) { - writer.append(""); - - appendWhitespace(writer); - writer.append(""); - - appendWhitespace(writer); - writer.append(""); - } else { - writer.append('"'); - - if (UtilValidate.isNotEmpty(idName)) { - writer.append(" id=\""); - writer.append(idName); - writer.append('"'); - } - - if (dropDownField.getAllowMultiple()) { - writer.append(" multiple=\"multiple\""); - } - - int otherFieldSize = dropDownField.getOtherFieldSize(); - String otherFieldName = dropDownField.getParameterNameOther(context); - if (otherFieldSize > 0) { - //writer.append(" onchange=\"alert('ONCHANGE, process_choice:' + process_choice)\""); - //writer.append(" onchange='test_js()' "); - writer.append(" onchange=\"process_choice(this,document."); - writer.append(modelForm.getName()); - writer.append("."); - writer.append(otherFieldName); - writer.append(")\" "); - } - - if (UtilValidate.isNotEmpty(event) && UtilValidate.isNotEmpty(action)) { - writer.append(" "); - writer.append(event); - writer.append("=\""); - writer.append(action); - writer.append('"'); - } - - writer.append(" size=\"").append(dropDownField.getSize()).append("\">"); - - // if the current value should go first, stick it in - if (UtilValidate.isNotEmpty(currentValue) && "first-in-list".equals(dropDownField.getCurrent())) { - writer.append(""); - String explicitDescription = (currentDescription != null ? currentDescription : dropDownField.getCurrentDescription(context)); - if (UtilValidate.isNotEmpty(explicitDescription)) { - writer.append(encode(explicitDescription, modelFormField, context)); - } else { - String description = FieldInfoWithOptions.getDescriptionForOptionKey(currentValue, allOptionValues); - writer.append(encode(description, modelFormField, context)); - } - writer.append(""); - - // add a "separator" option - writer.append(""); - } - - // if allow empty is true, add an empty option - if (dropDownField.getAllowEmpty()) { - writer.append(""); - } - - // list out all options according to the option list - for (ModelFormField.OptionValue optionValue: allOptionValues) { - String noCurrentSelectedKey = dropDownField.getNoCurrentSelectedKey(context); - writer.append(""); - writer.append(encode(optionValue.getDescription(), modelFormField, context)); - writer.append(""); - } - - writer.append(""); - - - // Adapted from work by Yucca Korpela - // http://www.cs.tut.fi/~jkorpela/forms/combo.html - if (otherFieldSize > 0) { - - String fieldName = modelFormField.getParameterName(context); - Map dataMap = UtilGenerics.checkMap(modelFormField.getMap(context)); - if (dataMap == null) { - dataMap = context; - } - Object otherValueObj = dataMap.get(otherFieldName); - String otherValue = (otherValueObj == null) ? "" : otherValueObj.toString(); - - writer.append(""); - writer.append("\n"); - } - } - - this.makeHyperlinkString(writer, dropDownField.getSubHyperlink(), context); - - this.appendTooltip(writer, context, modelFormField); - - //appendWhitespace(writer); - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderCheckField(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelFormField.CheckField) - */ - public void renderCheckField(Appendable writer, Map context, CheckField checkField) throws IOException { - ModelFormField modelFormField = checkField.getModelFormField(); - String currentValue = modelFormField.getEntry(context); - Boolean allChecked = checkField.isAllChecked(context); - - List allOptionValues = checkField.getAllOptionValues(context, WidgetWorker.getDelegator(context)); - String event = modelFormField.getEvent(); - String action = modelFormField.getAction(context); - - // list out all options according to the option list - for (ModelFormField.OptionValue optionValue: allOptionValues) { - - writer.append(""); - - writer.append(encode(optionValue.getDescription(), modelFormField, context)); - } - - this.appendTooltip(writer, context, modelFormField); - - //appendWhitespace(writer); - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderRadioField(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelFormField.RadioField) - */ - public void renderRadioField(Appendable writer, Map context, RadioField radioField) throws IOException { - ModelFormField modelFormField = radioField.getModelFormField(); - List allOptionValues = radioField.getAllOptionValues(context, WidgetWorker.getDelegator(context)); - String currentValue = modelFormField.getEntry(context); - String event = modelFormField.getEvent(); - String action = modelFormField.getAction(context); - - // list out all options according to the option list - for (ModelFormField.OptionValue optionValue: allOptionValues) { - - writer.append(""); - - writer.append(encode(optionValue.getDescription(), modelFormField, context)); - writer.append(""); - } - - this.appendTooltip(writer, context, modelFormField); - - //appendWhitespace(writer); - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderSubmitField(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelFormField.SubmitField) - */ - public void renderSubmitField(Appendable writer, Map context, SubmitField submitField) throws IOException { - ModelFormField modelFormField = submitField.getModelFormField(); - ModelForm modelForm = modelFormField.getModelForm(); - String event = null; - String action = null; - String confirmation = encode(submitField.getConfirmation(context), modelFormField, context); - - if ("text-link".equals(submitField.getButtonType())) { - writer.append(""); - - writer.append(encode(modelFormField.getTitle(context), modelFormField, context)); - - writer.append(""); - } else if ("image".equals(submitField.getButtonType())) { - writer.append(""); - } else { - // default to "button" - - String formId = modelForm.getContainerId(); - List updateAreas = modelForm.getOnSubmitUpdateAreas(); - // This is here for backwards compatibility. Use on-event-update-area - // elements instead. - String backgroundSubmitRefreshTarget = submitField.getBackgroundSubmitRefreshTarget(context); - if (UtilValidate.isNotEmpty(backgroundSubmitRefreshTarget)) { - if (updateAreas == null) { - updateAreas = new LinkedList(); - } - updateAreas.add(new ModelForm.UpdateArea("submit", formId, backgroundSubmitRefreshTarget)); - } - - boolean ajaxEnabled = (UtilValidate.isNotEmpty(updateAreas) || UtilValidate.isNotEmpty(backgroundSubmitRefreshTarget)) && this.javaScriptEnabled; - if (ajaxEnabled) { - writer.append(""); - } - - this.appendTooltip(writer, context, modelFormField); - - //appendWhitespace(writer); - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderResetField(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelFormField.ResetField) - */ - public void renderResetField(Appendable writer, Map context, ResetField resetField) throws IOException { - ModelFormField modelFormField = resetField.getModelFormField(); - - writer.append(""); - - this.appendTooltip(writer, context, modelFormField); - - //appendWhitespace(writer); - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderHiddenField(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelFormField.HiddenField) - */ - public void renderHiddenField(Appendable writer, Map context, HiddenField hiddenField) throws IOException { - ModelFormField modelFormField = hiddenField.getModelFormField(); - String value = hiddenField.getValue(context); - this.renderHiddenField(writer, context, modelFormField, value); - } - - public void renderHiddenField(Appendable writer, Map context, ModelFormField modelFormField, String value) throws IOException { - writer.append(""); - appendWhitespace(writer); - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderIgnoredField(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelFormField.IgnoredField) - */ - public void renderIgnoredField(Appendable writer, Map context, IgnoredField ignoredField) throws IOException { - // do nothing, it's an ignored field; could add a comment or something if we wanted to - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderFieldTitle(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelFormField) - */ - public void renderFieldTitle(Appendable writer, Map context, ModelFormField modelFormField) throws IOException { - String tempTitleText = modelFormField.getTitle(context); - String titleText = UtilHttp.encodeAmpersands(tempTitleText); - - if (UtilValidate.isNotEmpty(titleText)) { - // copied from MacroFormRenderer renderFieldTitle - String displayHelpText = UtilProperties.getPropertyValue("widget.properties", "widget.form.displayhelpText"); - String helpText = null; - if ("Y".equals(displayHelpText)) { - Delegator delegator = WidgetWorker.getDelegator(context); - Locale locale = (Locale)context.get("locale"); - String entityName = modelFormField.getEntityName(); - String fieldName = modelFormField.getFieldName(); - helpText = UtilHelpText.getEntityFieldDescription(entityName, fieldName, delegator, locale); - } - if (UtilValidate.isNotEmpty(modelFormField.getTitleStyle()) || UtilValidate.isNotEmpty(helpText)) { - writer.append(""); - } - if (" ".equals(titleText)) { - // If the title content is just a blank then render it colling renderFormatEmptySpace: - // the method will set its content to work fine in most browser - this.renderFormatEmptySpace(writer, context, modelFormField.getModelForm()); - } else { - renderHyperlinkTitle(writer, context, modelFormField, titleText); - } - - if (UtilValidate.isNotEmpty(modelFormField.getTitleStyle())) { - writer.append(""); - } - - //appendWhitespace(writer); - } - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderFieldTitle(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelFormField) - */ - public void renderSingleFormFieldTitle(Appendable writer, Map context, ModelFormField modelFormField) throws IOException { - boolean requiredField = modelFormField.getRequiredField(); - if (requiredField) { - - String requiredStyle = modelFormField.getRequiredFieldStyle(); - if (UtilValidate.isEmpty(requiredStyle)) { - requiredStyle = modelFormField.getTitleStyle(); - } - - if (UtilValidate.isNotEmpty(requiredStyle)) { - writer.append(""); - } - renderHyperlinkTitle(writer, context, modelFormField, modelFormField.getTitle(context)); - if (UtilValidate.isNotEmpty(requiredStyle)) { - writer.append(""); - } - - //appendWhitespace(writer); - } else { - renderFieldTitle(writer, context, modelFormField); - } - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderFormOpen(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelForm) - */ - public void renderFormOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException { - this.widgetCommentsEnabled = ModelWidget.widgetBoundaryCommentsEnabled(context); - renderBeginningBoundaryComment(writer, "Form Widget - Form Element", modelForm); - writer.append("
"); - - boolean useRowSubmit = modelForm.getUseRowSubmit(); - if (useRowSubmit) { - writer.append(""); - } - - appendWhitespace(writer); - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderFormClose(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelForm) - */ - public void renderFormClose(Appendable writer, Map context, ModelForm modelForm) throws IOException { - writer.append(""); - String focusFieldName = FormRenderer.getFocusFieldName(modelForm, context); - if (UtilValidate.isNotEmpty(focusFieldName)) { - appendWhitespace(writer); - writer.append(""); - } - appendWhitespace(writer); - renderEndingBoundaryComment(writer, "Form Widget - Form Element", modelForm); - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderFormClose(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelForm) - */ - public void renderMultiFormClose(Appendable writer, Map context, ModelForm modelForm) throws IOException { - for (ModelFormField submitField: modelForm.getMultiSubmitFields()) { - if (submitField != null) { - - // Threw this in that as a hack to keep the submit button from expanding the first field - // Needs a more rugged solution - // WARNING: this method (renderMultiFormClose) must be called after the - // table that contains the list has been closed (to avoid validation errors) so - // we cannot call here the methods renderFormatItemRowCell*: for this reason - // they are now commented. - - // this.renderFormatItemRowCellOpen(writer, context, modelForm, submitField); - // this.renderFormatItemRowCellClose(writer, context, modelForm, submitField); - - // this.renderFormatItemRowCellOpen(writer, context, modelForm, submitField); - - submitField.renderFieldString(writer, context, this); - - // this.renderFormatItemRowCellClose(writer, context, modelForm, submitField); - - } - } - writer.append(""); - appendWhitespace(writer); - - // see if there is anything that needs to be added outside of the multi-form - Map wholeFormContext = UtilGenerics.checkMap(context.get("wholeFormContext")); - Appendable postMultiFormWriter = wholeFormContext != null ? (Appendable) wholeFormContext.get("postMultiFormWriter") : null; - if (postMultiFormWriter != null) { - writer.append(postMultiFormWriter.toString()); - appendWhitespace(writer); - } - - renderEndingBoundaryComment(writer, "Form Widget - Form Element (Multi)", modelForm); - } - - public void renderFormatListWrapperOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException { - - Map inputFields = UtilGenerics.checkMap(context.get("requestParameters")); - Map queryStringMap = UtilGenerics.toMap(context.get("queryStringMap")); - if (UtilValidate.isNotEmpty(queryStringMap)) { - inputFields.putAll(queryStringMap); - } - if (modelForm.getType().equals("multi")) { - inputFields = UtilHttp.removeMultiFormParameters(inputFields); - } - String queryString = UtilHttp.urlEncodeArgs(inputFields); - context.put("_QBESTRING_", queryString); - - this.widgetCommentsEnabled = ModelWidget.widgetBoundaryCommentsEnabled(context); - renderBeginningBoundaryComment(writer, "Form Widget", modelForm); - - if (this.renderPagination) { - this.renderNextPrev(writer, context, modelForm); - } - writer.append(" "); - appendWhitespace(writer); - } - - public void renderFormatListWrapperClose(Appendable writer, Map context, ModelForm modelForm) throws IOException { - writer.append("
"); - - appendWhitespace(writer); - if (this.renderPagination) { - this.renderNextPrev(writer, context, modelForm); - } - renderEndingBoundaryComment(writer, "Form Widget - Formal List Wrapper", modelForm); - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderFormatHeaderRowOpen(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelForm) - */ - public void renderFormatHeaderRowOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException { - writer.append(" "); - appendWhitespace(writer); - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderFormatHeaderRowClose(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelForm) - */ - public void renderFormatHeaderRowClose(Appendable writer, Map context, ModelForm modelForm) throws IOException { - writer.append(" "); - - appendWhitespace(writer); - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderFormatHeaderRowCellOpen(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelForm, org.ofbiz.widget.form.ModelFormField, int positionSpan) - */ - public void renderFormatHeaderRowCellOpen(Appendable writer, Map context, ModelForm modelForm, ModelFormField modelFormField, int positionSpan) throws IOException { - writer.append(" 1) { - writer.append(" colspan=\""); - writer.append(Integer.toString(positionSpan)); - writer.append("\""); - } - if (UtilValidate.isNotEmpty(areaStyle)) { - writer.append(" class=\""); - writer.append(areaStyle); - writer.append("\""); - } - writer.append(">"); - //appendWhitespace(writer); - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderFormatHeaderRowCellClose(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelForm, org.ofbiz.widget.form.ModelFormField) - */ - public void renderFormatHeaderRowCellClose(Appendable writer, Map context, ModelForm modelForm, ModelFormField modelFormField) throws IOException { - writer.append(""); - appendWhitespace(writer); - } - - public void renderFormatHeaderRowFormCellOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException { - writer.append(" "); - //appendWhitespace(writer); - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderFormatHeaderRowFormCellClose(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelForm) - */ - public void renderFormatHeaderRowFormCellClose(Appendable writer, Map context, ModelForm modelForm) throws IOException { - writer.append(""); - appendWhitespace(writer); - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderFormatHeaderRowFormCellTitleSeparator(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelForm, boolean) - */ - public void renderFormatHeaderRowFormCellTitleSeparator(Appendable writer, Map context, ModelForm modelForm, ModelFormField modelFormField, boolean isLast) throws IOException { - - String titleStyle = modelFormField.getTitleStyle(); - if (UtilValidate.isNotEmpty(titleStyle)) { - writer.append(""); - } - if (isLast) { - writer.append(" - "); - } else { - writer.append(" - "); - } - if (UtilValidate.isNotEmpty(titleStyle)) { - writer.append(""); - } - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderFormatItemRowOpen(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelForm) - */ - public void renderFormatItemRowOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException { - Integer itemIndex = (Integer)context.get("itemIndex"); - - writer.append(" "); - appendWhitespace(writer); - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderFormatItemRowClose(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelForm) - */ - public void renderFormatItemRowClose(Appendable writer, Map context, ModelForm modelForm) throws IOException { - writer.append(" "); - - appendWhitespace(writer); - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderFormatItemRowCellOpen(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelForm, org.ofbiz.widget.form.ModelFormField) - */ - public void renderFormatItemRowCellOpen(Appendable writer, Map context, ModelForm modelForm, ModelFormField modelFormField, int positionSpan) throws IOException { - writer.append(" 1) { - writer.append(" colspan=\""); - writer.append(Integer.toString(positionSpan)); - writer.append("\""); - } - if (UtilValidate.isNotEmpty(areaStyle)) { - writer.append(" class=\""); - writer.append(areaStyle); - writer.append("\""); - } - writer.append(">"); - //appendWhitespace(writer); - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderFormatItemRowCellClose(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelForm, org.ofbiz.widget.form.ModelFormField) - */ - public void renderFormatItemRowCellClose(Appendable writer, Map context, ModelForm modelForm, ModelFormField modelFormField) throws IOException { - writer.append(""); - appendWhitespace(writer); - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderFormatItemRowFormCellOpen(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelForm) - */ - public void renderFormatItemRowFormCellOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException { - writer.append(" "); - //appendWhitespace(writer); - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderFormatItemRowFormCellClose(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelForm) - */ - public void renderFormatItemRowFormCellClose(Appendable writer, Map context, ModelForm modelForm) throws IOException { - writer.append(""); - appendWhitespace(writer); - } - - public void renderFormatSingleWrapperOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException { - writer.append(" "); - appendWhitespace(writer); - } - - public void renderFormatSingleWrapperClose(Appendable writer, Map context, ModelForm modelForm) throws IOException { - writer.append("
"); - appendWhitespace(writer); - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderFormatFieldRowOpen(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelForm) - */ - public void renderFormatFieldRowOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException { - writer.append(" "); - appendWhitespace(writer); - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderFormatFieldRowClose(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelForm) - */ - public void renderFormatFieldRowClose(Appendable writer, Map context, ModelForm modelForm) throws IOException { - writer.append(" "); - appendWhitespace(writer); - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderFormatFieldRowTitleCellOpen(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelFormField) - */ - public void renderFormatFieldRowTitleCellOpen(Appendable writer, Map context, ModelFormField modelFormField) throws IOException { - writer.append(" "); - //appendWhitespace(writer); - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderFormatFieldRowTitleCellClose(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelFormField) - */ - public void renderFormatFieldRowTitleCellClose(Appendable writer, Map context, ModelFormField modelFormField) throws IOException { - writer.append(""); - appendWhitespace(writer); - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderFormatFieldRowSpacerCell(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelFormField) - */ - public void renderFormatFieldRowSpacerCell(Appendable writer, Map context, ModelFormField modelFormField) throws IOException { - // Embedded styling - bad idea - //writer.append(" "); - - //appendWhitespace(writer); - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderFormatFieldRowWidgetCellOpen(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelFormField, int) - */ - public void renderFormatFieldRowWidgetCellOpen(Appendable writer, Map context, ModelFormField modelFormField, int positions, int positionSpan, Integer nextPositionInRow) throws IOException { -// writer.append(" 1) { -// writer.append("30"); -// } else { -// writer.append("80"); -// } -// writer.append("%\""); - writer.append(" 0) { - writer.append(" colspan=\""); - // do a span of 1 for this column, plus 3 columns for each spanned - //position or each blank position that this will be filling in - writer.append(Integer.toString(1 + (positionSpan * 3))); - writer.append("\""); - } - String areaStyle = modelFormField.getWidgetAreaStyle(); - if (UtilValidate.isNotEmpty(areaStyle)) { - writer.append(" class=\""); - writer.append(areaStyle); - writer.append("\""); - } - writer.append(">"); - - //appendWhitespace(writer); - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderFormatFieldRowWidgetCellClose(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelFormField, int) - */ - public void renderFormatFieldRowWidgetCellClose(Appendable writer, Map context, ModelFormField modelFormField, int positions, int positionSpan, Integer nextPositionInRow) throws IOException { - writer.append(""); - appendWhitespace(writer); - } - - public void renderFormatEmptySpace(Appendable writer, Map context, ModelForm modelForm) throws IOException { - writer.append(" "); - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderTextFindField(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelFormField.TextFindField) - */ - public void renderTextFindField(Appendable writer, Map context, TextFindField textFindField) throws IOException { - - ModelFormField modelFormField = textFindField.getModelFormField(); - - String defaultOption = textFindField.getDefaultOption(); - Locale locale = (Locale)context.get("locale"); - if (!textFindField.getHideOptions()) { - String opEquals = UtilProperties.getMessage("conditional", "equals", locale); - String opBeginsWith = UtilProperties.getMessage("conditional", "begins_with", locale); - String opContains = UtilProperties.getMessage("conditional", "contains", locale); - String opIsEmpty = UtilProperties.getMessage("conditional", "is_empty", locale); - String opNotEqual = UtilProperties.getMessage("conditional", "not_equal", locale); - writer.append(" "); - } else { - writer.append(" "); - } - - writer.append(""); - - if (UtilValidate.isNotEmpty(modelFormField.getTitleStyle())) { - writer.append(" "); - } - - String ignoreCase = UtilProperties.getMessage("conditional", "ignore_case", locale); - boolean ignCase = textFindField.getIgnoreCase(); - - if (!textFindField.getHideIgnoreCase()) { - writer.append(" "); - writer.append(ignoreCase); - } else { - writer.append(""); - } - - if (UtilValidate.isNotEmpty(modelFormField.getTitleStyle())) { - writer.append(""); - } - - this.appendTooltip(writer, context, modelFormField); - - //appendWhitespace(writer); - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderRangeFindField(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelFormField.RangeFindField) - */ - public void renderRangeFindField(Appendable writer, Map context, RangeFindField rangeFindField) throws IOException { - - ModelFormField modelFormField = rangeFindField.getModelFormField(); - Locale locale = (Locale)context.get("locale"); - String opEquals = UtilProperties.getMessage("conditional", "equals", locale); - String opGreaterThan = UtilProperties.getMessage("conditional", "greater_than", locale); - String opGreaterThanEquals = UtilProperties.getMessage("conditional", "greater_than_equals", locale); - String opLessThan = UtilProperties.getMessage("conditional", "less_than", locale); - String opLessThanEquals = UtilProperties.getMessage("conditional", "less_than_equals", locale); - //String opIsEmpty = UtilProperties.getMessage("conditional", "is_empty", locale); - - writer.append(""); - - if (UtilValidate.isNotEmpty(modelFormField.getTitleStyle())) { - writer.append(" "); - } - - String defaultOptionFrom = rangeFindField.getDefaultOptionFrom(); - writer.append(" "); - - writer.append(""); - - writer.append("
"); - - writer.append(""); - - String defaultOptionThru = rangeFindField.getDefaultOptionThru(); - writer.append(" "); - - if (UtilValidate.isNotEmpty(modelFormField.getTitleStyle())) { - writer.append(""); - } - - this.appendTooltip(writer, context, modelFormField); - - //appendWhitespace(writer); - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderDateFindField(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelFormField.DateFindField) - */ - public void renderDateFindField(Appendable writer, Map context, DateFindField dateFindField) throws IOException { - ModelFormField modelFormField = dateFindField.getModelFormField(); - - Locale locale = (Locale)context.get("locale"); - String opEquals = UtilProperties.getMessage("conditional", "equals", locale); - String opGreaterThan = UtilProperties.getMessage("conditional", "greater_than", locale); - String opSameDay = UtilProperties.getMessage("conditional", "same_day", locale); - String opGreaterThanFromDayStart = UtilProperties.getMessage("conditional", - "greater_than_from_day_start", locale); - String opLessThan = UtilProperties.getMessage("conditional", "less_than", locale); - String opUpToDay = UtilProperties.getMessage("conditional", "up_to_day", locale); - String opUpThruDay = UtilProperties.getMessage("conditional", "up_thru_day", locale); - String opIsEmpty = UtilProperties.getMessage("conditional", "is_empty", locale); - - Map uiLabelMap = UtilGenerics.checkMap(context.get("uiLabelMap")); - if (uiLabelMap == null) { - Debug.logWarning("Could not find uiLabelMap in context", module); - } - String localizedInputTitle = "", localizedIconTitle = ""; - - writer.append(" maxlength) { - value = value.substring(0, maxlength); - } - writer.append(" value=\""); - writer.append(value); - writer.append('"'); - } - - writer.append(" size=\""); - writer.append(Integer.toString(size)); - writer.append('"'); - - writer.append(" maxlength=\""); - writer.append(Integer.toString(maxlength)); - writer.append('"'); - - writer.append("/>"); - - // search for a localized label for the icon - if (uiLabelMap != null) { - localizedIconTitle = uiLabelMap.get("CommonViewCalendar"); - } - ModelForm modelForm = modelFormField.getModelForm(); - // add calendar pop-up button and seed data IF this is not a "time" type date-find - if (!"time".equals(dateFindField.getType())) { - if ("date".equals(dateFindField.getType())) { - writer.append(""); - - writer.append("\"");"); - } - - if (UtilValidate.isNotEmpty(modelFormField.getTitleStyle())) { - writer.append(" "); - } - - String defaultOptionFrom = dateFindField.getDefaultOptionFrom(); - writer.append(" "); - - if (UtilValidate.isNotEmpty(modelFormField.getTitleStyle())) { - writer.append(" "); - } - - writer.append("
"); - - writer.append(" maxlength) { - value = value.substring(0, maxlength); - } - writer.append(" value=\""); - writer.append(value); - writer.append('"'); - } - - writer.append(" size=\""); - writer.append(Integer.toString(size)); - writer.append('"'); - - writer.append(" maxlength=\""); - writer.append(Integer.toString(maxlength)); - writer.append('"'); - - writer.append("/>"); - - // add calendar pop-up button and seed data IF this is not a "time" type date-find - if (!"time".equals(dateFindField.getType())) { - if ("date".equals(dateFindField.getType())) { - writer.append(""); - - writer.append("\"");"); - } - - if (UtilValidate.isNotEmpty(modelFormField.getTitleStyle())) { - writer.append(" "); - } - - String defaultOptionThru = dateFindField.getDefaultOptionThru(); - writer.append(" "); - - if (UtilValidate.isNotEmpty(modelFormField.getTitleStyle())) { - writer.append(""); - } - - this.appendTooltip(writer, context, modelFormField); - - //appendWhitespace(writer); - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderLookupField(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelFormField.LookupField) - */ - public void renderLookupField(Appendable writer, Map context, LookupField lookupField) throws IOException { - ModelFormField modelFormField = lookupField.getModelFormField(); - - writer.append(" updateAreas = modelFormField.getOnChangeUpdateAreas(); - boolean ajaxEnabled = updateAreas != null && this.javaScriptEnabled; - if (!lookupField.getClientAutocompleteField() || ajaxEnabled) { - writer.append(" autocomplete=\"off\""); - } - - writer.append("/>"); - ModelForm modelForm = modelFormField.getModelForm(); - // add lookup pop-up button - String descriptionFieldName = lookupField.getDescriptionFieldName(); - if (UtilValidate.isNotEmpty(descriptionFieldName)) { - writer.append(" targetParameterList = lookupField.getTargetParameterList(); - for (String targetParameter: targetParameterList) { - // named like: document.${formName}.${targetParameter}.value - writer.append(", document."); - writer.append(FormRenderer.getCurrentFormName(modelForm, context)); - writer.append("."); - writer.append(targetParameter); - writer.append(".value"); - } - writer.append(");\">"); - writer.append("\"Lookup\"/"); - - this.addAsterisks(writer, context, modelFormField); - - this.makeHyperlinkString(writer, lookupField.getSubHyperlink(), context); - this.appendTooltip(writer, context, modelFormField); - - if (ajaxEnabled) { - appendWhitespace(writer); - writer.append(""); - } - appendWhitespace(writer); - - //appendWhitespace(writer); - } - - protected String appendExternalLoginKey(String target) { - String result = target; - String sessionId = ";jsessionid=" + request.getSession().getId(); - int questionIndex = target.indexOf("?"); - if (questionIndex == -1) { - result += sessionId; - } else { - result = result.replace("?", sessionId + "?"); - } - return result; - } - - private int getActualPageSize(Map context) { - Integer value = (Integer) context.get("actualPageSize"); - return value != null ? value.intValue() : (getHighIndex(context) - getLowIndex(context)); - } - - private int getHighIndex(Map context) { - Integer value = (Integer) context.get("highIndex"); - return value != null ? value.intValue() : 0; - } - - private int getListSize(Map context) { - Integer value = (Integer) context.get("listSize"); - return value != null ? value.intValue() : 0; - } - - private int getLowIndex(Map context) { - Integer value = (Integer) context.get("lowIndex"); - return value != null ? value.intValue() : 0; - } - - public void renderNextPrev(Appendable writer, Map context, ModelForm modelForm) throws IOException { - boolean ajaxEnabled = false; - List updateAreas = modelForm.getOnPaginateUpdateAreas(); - String targetService = modelForm.getPaginateTarget(context); - if (this.javaScriptEnabled) { - if (UtilValidate.isNotEmpty(updateAreas)) { - ajaxEnabled = true; - } - } - if (targetService == null) { - targetService = "${targetService}"; - } - if (UtilValidate.isEmpty(targetService) && updateAreas == null) { - Debug.logWarning("Cannot paginate because TargetService is empty for the form: " + modelForm.getName(), module); - return; - } - - // get the parameterized pagination index and size fields - int paginatorNumber = WidgetWorker.getPaginatorNumber(context); - String viewIndexParam = modelForm.getMultiPaginateIndexField(context); - String viewSizeParam = modelForm.getMultiPaginateSizeField(context); - - int viewIndex = Paginator.getViewIndex(modelForm, context); - int viewSize = Paginator.getViewSize(modelForm, context); - int listSize = getListSize(context); - - int lowIndex = getLowIndex(context); - int highIndex = getHighIndex(context); - int actualPageSize = getActualPageSize(context); - - // if this is all there seems to be (if listSize < 0, then size is unknown) - if (actualPageSize >= listSize && listSize >= 0) return; - - // needed for the "Page" and "rows" labels - Map uiLabelMap = UtilGenerics.checkMap(context.get("uiLabelMap")); - String pageLabel = ""; - String commonDisplaying = ""; - if (uiLabelMap == null) { - Debug.logWarning("Could not find uiLabelMap in context", module); - } else { - pageLabel = uiLabelMap.get("CommonPage"); - Map messageMap = UtilMisc.toMap("lowCount", Integer.valueOf(lowIndex + 1), "highCount", Integer.valueOf(lowIndex + actualPageSize), "total", Integer.valueOf(listSize)); - commonDisplaying = UtilProperties.getMessage("CommonUiLabels", "CommonDisplaying", messageMap, (Locale) context.get("locale")); - } - - // for legacy support, the viewSizeParam is VIEW_SIZE and viewIndexParam is VIEW_INDEX when the fields are "viewSize" and "viewIndex" - if (viewIndexParam.equals("viewIndex" + "_" + paginatorNumber)) viewIndexParam = "VIEW_INDEX" + "_" + paginatorNumber; - if (viewSizeParam.equals("viewSize" + "_" + paginatorNumber)) viewSizeParam = "VIEW_SIZE" + "_" + paginatorNumber; - - String str = (String) context.get("_QBESTRING_"); - - // strip legacy viewIndex/viewSize params from the query string - String queryString = UtilHttp.stripViewParamsFromQueryString(str, "" + paginatorNumber); - - // strip parametrized index/size params from the query string - HashSet paramNames = new HashSet(); - paramNames.add(viewIndexParam); - paramNames.add(viewSizeParam); - queryString = UtilHttp.stripNamedParamsFromQueryString(queryString, paramNames); - - String anchor = ""; - String paginateAnchor = modelForm.getPaginateTargetAnchor(); - if (paginateAnchor != null) anchor = "#" + paginateAnchor; - - // Create separate url path String and request parameters String, - // add viewIndex/viewSize parameters to request parameter String - String urlPath = UtilHttp.removeQueryStringFromTarget(targetService); - StringBuilder prepLinkBuffer = new StringBuilder(); - String prepLinkQueryString = UtilHttp.getQueryStringFromTarget(targetService); - if (prepLinkQueryString != null) { - prepLinkBuffer.append(prepLinkQueryString); - } - if (prepLinkBuffer.indexOf("?") < 0) { - prepLinkBuffer.append("?"); - } else if (prepLinkBuffer.indexOf("?", prepLinkBuffer.length() - 1) > 0) { - prepLinkBuffer.append("&"); - } - if (!UtilValidate.isEmpty(queryString) && !queryString.equals("null")) { - prepLinkBuffer.append(queryString).append("&"); - } - prepLinkBuffer.append(viewSizeParam).append("=").append(viewSize).append("&").append(viewIndexParam).append("="); - String prepLinkText = prepLinkBuffer.toString(); - if (ajaxEnabled) { - // Prepare params for prototype.js - prepLinkText = prepLinkText.replace("?", ""); - prepLinkText = prepLinkText.replace("&", "&"); - } - - writer.append("
"); - appendWhitespace(writer); - writer.append("
    "); - appendWhitespace(writer); - - String linkText; - - // First button - writer.append("
  • 0) { - writer.append("\">").append(modelForm.getPaginateFirstLabel(context)).append(""); - } else { - // disabled button - writer.append("-disabled\">").append(modelForm.getPaginateFirstLabel(context)); - } - writer.append("
  • "); - appendWhitespace(writer); - - // Previous button - writer.append("
  • 0) { - writer.append("\">").append(modelForm.getPaginatePreviousLabel(context)).append(""); - } else { - // disabled button - writer.append("-disabled\">").append(modelForm.getPaginatePreviousLabel(context)); - } - writer.append("
  • "); - appendWhitespace(writer); - - // Page select dropdown - if (listSize > 0 && this.javaScriptEnabled) { - writer.append("
  • ").append(pageLabel).append("
  • "); - } - - // show row count - writer.append("
  • "); - writer.append(commonDisplaying); - writer.append("
  • "); - appendWhitespace(writer); - - // Next button - writer.append("
  • ").append(modelForm.getPaginateNextLabel(context)).append(""); - } else { - // disabled button - writer.append("-disabled\">").append(modelForm.getPaginateNextLabel(context)); - } - writer.append("
  • "); - appendWhitespace(writer); - - // Last button - writer.append("
  • ").append(modelForm.getPaginateLastLabel(context)).append(""); - } else { - // disabled button - writer.append("-disabled\">").append(modelForm.getPaginateLastLabel(context)); - } - writer.append("
  • "); - appendWhitespace(writer); - - writer.append("
"); - appendWhitespace(writer); - writer.append("
"); - appendWhitespace(writer); - } - - public void renderSortField(Appendable writer, Map context, ModelFormField modelFormField, String titleText) throws IOException { - boolean ajaxEnabled = false; - ModelForm modelForm = modelFormField.getModelForm(); - List updateAreas = modelForm.getOnPaginateUpdateAreas(); - String targetService = modelForm.getPaginateTarget(context); - if (this.javaScriptEnabled) { - if (UtilValidate.isNotEmpty(updateAreas)) { - ajaxEnabled = true; - } - } - if (targetService == null) { - targetService = "${targetService}"; - } - if (UtilValidate.isEmpty(targetService) && updateAreas == null) { - Debug.logWarning("Cannot sort because TargetService is empty for the form: " + modelForm.getName(), module); - return; - } - - String str = (String) context.get("_QBESTRING_"); - String oldSortField = modelForm.getSortField(context); - String sortFieldStyle = modelFormField.getSortFieldStyle(); - - // if the entry-name is defined use this instead of field name - String columnField = modelFormField.getEntryName(); - if (UtilValidate.isEmpty(columnField)) { - columnField = modelFormField.getFieldName(); - } - - // switch beetween asc/desc order - String newSortField = columnField; - if (UtilValidate.isNotEmpty(oldSortField)) { - if (oldSortField.equals(columnField)) { - newSortField = "-" + columnField; - sortFieldStyle = modelFormField.getSortFieldStyleDesc(); - } else if (oldSortField.equals("-" + columnField)) { - newSortField = columnField; - sortFieldStyle = modelFormField.getSortFieldStyleAsc(); - } - } - - // strip sortField param from the query string - HashSet paramName = new HashSet(); - paramName.add("sortField"); - String queryString = UtilHttp.stripNamedParamsFromQueryString(str, paramName); - String urlPath = UtilHttp.removeQueryStringFromTarget(targetService); - StringBuilder prepLinkBuffer = new StringBuilder(); - String prepLinkQueryString = UtilHttp.getQueryStringFromTarget(targetService); - if (prepLinkQueryString != null) { - prepLinkBuffer.append(prepLinkQueryString); - } - if (prepLinkBuffer.indexOf("?") < 0) { - prepLinkBuffer.append("?"); - } else if (prepLinkBuffer.indexOf("?", prepLinkBuffer.length() - 1) > 0) { - prepLinkBuffer.append("&"); - } - if (!UtilValidate.isEmpty(queryString) && !queryString.equals("null")) { - prepLinkBuffer.append(queryString).append("&"); - } - prepLinkBuffer.append("sortField").append("=").append(newSortField); - String prepLinkText = prepLinkBuffer.toString(); - if (ajaxEnabled) { - prepLinkText = prepLinkText.replace("?", ""); - prepLinkText = prepLinkText.replace("&", "&"); - } - - writer.append("").append(titleText).append(""); - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderFileField(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelFormField.FileField) - */ - public void renderFileField(Appendable writer, Map context, FileField textField) throws IOException { - ModelFormField modelFormField = textField.getModelFormField(); - - writer.append(""); - - this.makeHyperlinkString(writer, textField.getSubHyperlink(), context); - - this.appendTooltip(writer, context, modelFormField); - - //appendWhitespace(writer); - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderPasswordField(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelFormField.PasswordField) - */ - public void renderPasswordField(Appendable writer, Map context, PasswordField passwordField) throws IOException { - ModelFormField modelFormField = passwordField.getModelFormField(); - - writer.append(""); - - this.addAsterisks(writer, context, modelFormField); - - this.makeHyperlinkString(writer, passwordField.getSubHyperlink(), context); - - this.appendTooltip(writer, context, modelFormField); - - //appendWhitespace(writer); - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.form.FormStringRenderer#renderImageField(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelFormField.ImageField) - */ - public void renderImageField(Appendable writer, Map context, ImageField imageField) throws IOException { - ModelFormField modelFormField = imageField.getModelFormField(); - - writer.append(""); - - this.makeHyperlinkString(writer, imageField.getSubHyperlink(), context); - - this.appendTooltip(writer, context, modelFormField); - - //appendWhitespace(writer); - } - - public void renderFieldGroupOpen(Appendable writer, Map context, ModelForm.FieldGroup fieldGroup) throws IOException { - String style = fieldGroup.getStyle(); - String id = fieldGroup.getId(); - FlexibleStringExpander titleNotExpanded = FlexibleStringExpander.getInstance(fieldGroup.getTitle()); - String title = titleNotExpanded.expandString(context); - Boolean collapsed = fieldGroup.initiallyCollapsed(); - String collapsibleAreaId = fieldGroup.getId() + "_body"; - - if (UtilValidate.isNotEmpty(style) || UtilValidate.isNotEmpty(id) || UtilValidate.isNotEmpty(title)) { - - writer.append("
"); - - writer.append("
"); - - if (fieldGroup.collapsible()) { - String expandToolTip = null; - String collapseToolTip = null; - Map uiLabelMap = UtilGenerics.checkMap(context.get("uiLabelMap")); - //Map paramMap = UtilGenerics.checkMap(context.get("requestParameters")); - if (uiLabelMap != null) { - expandToolTip = (String) uiLabelMap.get("CommonExpand"); - collapseToolTip = (String) uiLabelMap.get("CommonCollapse"); - } - - writer.append(""); - - appendWhitespace(writer); - } - writer.append(""); - - if (UtilValidate.isNotEmpty(title)) { - writer.append("
"); - writer.append(title); - writer.append("
"); - } - - writer.append("
"); - - writer.append("
"); - } - } - - public void renderFieldGroupClose(Appendable writer, Map context, ModelForm.FieldGroup fieldGroup) throws IOException { - String style = fieldGroup.getStyle(); - String id = fieldGroup.getId(); - String title = fieldGroup.getTitle(); - if (UtilValidate.isNotEmpty(style) || UtilValidate.isNotEmpty(id) || UtilValidate.isNotEmpty(title)) { - writer.append("
"); - writer.append("
"); - } - } - - // TODO: Remove embedded styling - public void renderBanner(Appendable writer, Map context, ModelForm.Banner banner) throws IOException { - writer.append(" "); - String style = banner.getStyle(context); - String leftStyle = banner.getLeftTextStyle(context); - if (UtilValidate.isEmpty(leftStyle)) leftStyle = style; - String rightStyle = banner.getRightTextStyle(context); - if (UtilValidate.isEmpty(rightStyle)) rightStyle = style; - - String leftText = banner.getLeftText(context); - if (UtilValidate.isNotEmpty(leftText)) { - writer.append(" "); - } - - String text = banner.getText(context); - if (UtilValidate.isNotEmpty(text)) { - writer.append(" "); - } - - String rightText = banner.getRightText(context); - if (UtilValidate.isNotEmpty(rightText)) { - writer.append(" "); - } - writer.append("
"); - if (UtilValidate.isNotEmpty(leftStyle)) { - writer.append(""); - } - writer.append(leftText); - if (UtilValidate.isNotEmpty(leftStyle)) { - writer.append(""); - } - writer.append(""); - if (UtilValidate.isNotEmpty(style)) { - writer.append(""); - } - writer.append(text); - if (UtilValidate.isNotEmpty(style)) { - writer.append(""); - } - writer.append(""); - if (UtilValidate.isNotEmpty(rightStyle)) { - writer.append(""); - } - writer.append(rightText); - if (UtilValidate.isNotEmpty(rightStyle)) { - writer.append(""); - } - writer.append("
"); - } - - /** - * Renders a link for the column header fields when there is a header-link="" specified in the tag, using - * style from header-link-style="". Also renders a selectAll checkbox in multi forms. - * @param writer - * @param context - * @param modelFormField - * @param titleText - */ - public void renderHyperlinkTitle(Appendable writer, Map context, ModelFormField modelFormField, String titleText) throws IOException { - if (UtilValidate.isNotEmpty(modelFormField.getHeaderLink())) { - StringBuilder targetBuffer = new StringBuilder(); - FlexibleStringExpander target = FlexibleStringExpander.getInstance(modelFormField.getHeaderLink()); - String fullTarget = target.expandString(context); - targetBuffer.append(fullTarget); - String targetType = CommonWidgetModels.Link.DEFAULT_URL_MODE; - if (UtilValidate.isNotEmpty(targetBuffer.toString()) && targetBuffer.toString().toLowerCase().startsWith("javascript:")) { - targetType="plain"; - } - WidgetWorker.makeHyperlinkString(writer, modelFormField.getHeaderLinkStyle(), targetType, targetBuffer.toString(), null, titleText, null, modelFormField, this.request, this.response, null, null); - } else if (modelFormField.isSortField()) { - renderSortField (writer, context, modelFormField, titleText); - } else if (modelFormField.isRowSubmit()) { - if (UtilValidate.isNotEmpty(titleText)) writer.append(titleText).append("
"); - writer.append(""); - } else { - writer.append(titleText); - } - } - - public void renderContainerFindField(Appendable writer, Map context, ContainerField containerField) throws IOException { - writer.append("
"); - } - - /** Create an ajaxXxxx JavaScript CSV string from a list of UpdateArea objects. See - * selectall.js. - * @param updateAreas - * @param extraParams Renderer-supplied additional target parameters - * @param context - * @return Parameter string or empty string if no UpdateArea objects were found - */ - public String createAjaxParamsFromUpdateAreas(List updateAreas, String extraParams, Map context) { - if (updateAreas == null) { - return ""; - } - StringBuilder ajaxUrl = new StringBuilder(); - boolean firstLoop = true; - for (ModelForm.UpdateArea updateArea : updateAreas) { - if (firstLoop) { - firstLoop = false; - } else { - ajaxUrl.append(","); - } - String targetUrl = updateArea.getAreaTarget(context); - String ajaxParams = getAjaxParamsFromTarget(targetUrl); - if (UtilValidate.isNotEmpty(extraParams)) { - if (ajaxParams.length() > 0 && !extraParams.startsWith("&")) { - ajaxParams += "&"; - } - ajaxParams += extraParams; - } - ajaxUrl.append(updateArea.getAreaId()).append(","); - try { - appendOfbizUrl(ajaxUrl, UtilHttp.removeQueryStringFromTarget(targetUrl)); - } catch (IOException e) { - throw UtilMisc.initCause(new InternalError(e.getMessage()), e); - } - ajaxUrl.append(",").append(ajaxParams); - } - return ajaxUrl.toString(); - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.renderer.html; + +import java.io.IOException; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Map.Entry; + +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilCodec; +import org.ofbiz.base.util.UtilGenerics; +import org.ofbiz.base.util.UtilHttp; +import org.ofbiz.base.util.UtilMisc; +import org.ofbiz.base.util.UtilProperties; +import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.base.util.string.FlexibleStringExpander; +import org.ofbiz.base.util.template.FreeMarkerWorker; +import org.ofbiz.entity.Delegator; +import org.ofbiz.webapp.control.RequestHandler; +import org.ofbiz.webapp.taglib.ContentUrlTag; +import org.ofbiz.widget.WidgetWorker; +import org.ofbiz.widget.model.CommonWidgetModels; +import org.ofbiz.widget.model.ModelForm; +import org.ofbiz.widget.model.ModelFormField; +import org.ofbiz.widget.model.ModelFormField.CheckField; +import org.ofbiz.widget.model.ModelFormField.ContainerField; +import org.ofbiz.widget.model.ModelFormField.DateFindField; +import org.ofbiz.widget.model.ModelFormField.DateTimeField; +import org.ofbiz.widget.model.ModelFormField.DisplayEntityField; +import org.ofbiz.widget.model.ModelFormField.DisplayField; +import org.ofbiz.widget.model.ModelFormField.DropDownField; +import org.ofbiz.widget.model.ModelFormField.FieldInfoWithOptions; +import org.ofbiz.widget.model.ModelFormField.FileField; +import org.ofbiz.widget.model.ModelFormField.HiddenField; +import org.ofbiz.widget.model.ModelFormField.HyperlinkField; +import org.ofbiz.widget.model.ModelFormField.IgnoredField; +import org.ofbiz.widget.model.ModelFormField.ImageField; +import org.ofbiz.widget.model.ModelFormField.LookupField; +import org.ofbiz.widget.model.ModelFormField.PasswordField; +import org.ofbiz.widget.model.ModelFormField.RadioField; +import org.ofbiz.widget.model.ModelFormField.RangeFindField; +import org.ofbiz.widget.model.ModelFormField.ResetField; +import org.ofbiz.widget.model.ModelFormField.SubmitField; +import org.ofbiz.widget.model.ModelFormField.TextField; +import org.ofbiz.widget.model.ModelFormField.TextFindField; +import org.ofbiz.widget.model.ModelFormField.TextareaField; +import org.ofbiz.widget.model.ModelWidget; +import org.ofbiz.widget.renderer.FormRenderer; +import org.ofbiz.widget.renderer.FormStringRenderer; +import org.ofbiz.widget.renderer.Paginator; +import org.ofbiz.widget.renderer.UtilHelpText; +import org.ofbiz.widget.renderer.macro.MacroFormRenderer; + +import freemarker.template.TemplateException; + +/** + * Widget Library - HTML Form Renderer implementation + */ +public class HtmlFormRenderer extends HtmlWidgetRenderer implements FormStringRenderer { + + public static final String module = HtmlFormRenderer.class.getName(); + + protected HttpServletRequest request; + protected HttpServletResponse response; + protected RequestHandler rh; + protected String lastFieldGroupId = ""; + protected boolean renderPagination = true; + protected boolean javaScriptEnabled = false; + private UtilCodec.SimpleEncoder internalEncoder; + + protected HtmlFormRenderer() {} + + public HtmlFormRenderer(HttpServletRequest request, HttpServletResponse response) { + this.request = request; + this.response = response; + ServletContext ctx = (ServletContext) request.getAttribute("servletContext"); + this.rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_"); + this.javaScriptEnabled = UtilHttp.isJavaScriptEnabled(request); + internalEncoder = UtilCodec.getEncoder("string"); + } + + public boolean getRenderPagination() { + return this.renderPagination; + } + + public void setRenderPagination(boolean renderPagination) { + this.renderPagination = renderPagination; + } + + public void appendOfbizUrl(Appendable writer, String location) throws IOException { + writer.append(this.rh.makeLink(this.request, this.response, location)); + } + + public void appendContentUrl(Appendable writer, String location) throws IOException { + ContentUrlTag.appendContentPrefix(this.request, writer); + writer.append(location); + } + + public void appendTooltip(Appendable writer, Map context, ModelFormField modelFormField) throws IOException { + // render the tooltip, in other methods too + String tooltip = modelFormField.getTooltip(context); + if (UtilValidate.isNotEmpty(tooltip)) { + writer.append(""); + writer.append(tooltip); + writer.append(""); + } + } + + public void addAsterisks(Appendable writer, Map context, ModelFormField modelFormField) throws IOException { + + boolean requiredField = modelFormField.getRequiredField(); + if (requiredField) { + String requiredStyle = modelFormField.getRequiredFieldStyle(); + + if (UtilValidate.isEmpty(requiredStyle)) { + writer.append("*"); + } + } + } + + public void appendClassNames(Appendable writer, Map context, ModelFormField modelFormField) throws IOException { + String className = modelFormField.getWidgetStyle(); + if (UtilValidate.isNotEmpty(className) || modelFormField.shouldBeRed(context)) { + writer.append(" class=\""); + writer.append(className); + // add a style of red if redWhen is true + if (modelFormField.shouldBeRed(context)) { + writer.append(" alert"); + } + writer.append('"'); + } + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderDisplayField(java.io.Writer, java.util.Map, org.ofbiz.widget.model.ModelFormField.DisplayField) + */ + public void renderDisplayField(Appendable writer, Map context, DisplayField displayField) throws IOException { + ModelFormField modelFormField = displayField.getModelFormField(); + + StringBuilder str = new StringBuilder(); + + String idName = modelFormField.getCurrentContainerId(context); + + if (UtilValidate.isNotEmpty(modelFormField.getWidgetStyle()) || modelFormField.shouldBeRed(context)) { + str.append("'); + } + + if (str.length() > 0) { + writer.append(str.toString()); + } + String description = displayField.getDescription(context); + //Replace new lines with
+ description = description.replaceAll("\n", "
"); + + if (UtilValidate.isEmpty(description)) { + this.renderFormatEmptySpace(writer, context, modelFormField.getModelForm()); + } else { + writer.append(description); + } + + if (str.length() > 0) { + writer.append("
"); + } + + ModelFormField.InPlaceEditor inPlaceEditor = displayField.getInPlaceEditor(); + boolean ajaxEnabled = inPlaceEditor != null && this.javaScriptEnabled; + + if (ajaxEnabled) { + writer.append(""); + } + + if (displayField instanceof DisplayEntityField) { + this.makeHyperlinkString(writer, ((DisplayEntityField) displayField).getSubHyperlink(), context); + } + + this.appendTooltip(writer, context, modelFormField); + + //appendWhitespace(writer); + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderHyperlinkField(java.io.Writer, java.util.Map, org.ofbiz.widget.model.ModelFormField.HyperlinkField) + */ + public void renderHyperlinkField(Appendable writer, Map context, HyperlinkField hyperlinkField) throws IOException { + this.request.setAttribute("image", hyperlinkField.getImageLocation(context)); + ModelFormField modelFormField = hyperlinkField.getModelFormField(); + String description = encode(hyperlinkField.getDescription(context), modelFormField, context); + String confirmation = encode(hyperlinkField.getConfirmation(context), modelFormField, context); + WidgetWorker.makeHyperlinkByType(writer, hyperlinkField.getLinkType(), modelFormField.getWidgetStyle(), hyperlinkField.getUrlMode(), hyperlinkField.getTarget(context), + hyperlinkField.getParameterMap(context), description, hyperlinkField.getTargetWindow(context), confirmation, modelFormField, + this.request, this.response, context); + this.appendTooltip(writer, context, modelFormField); + //appendWhitespace(writer); + } + + public void makeHyperlinkString(Appendable writer, ModelFormField.SubHyperlink subHyperlink, Map context) throws IOException { + if (subHyperlink == null) { + return; + } + if (subHyperlink.shouldUse(context)) { + writer.append(' '); + String description = encode(subHyperlink.getDescription(context), subHyperlink.getModelFormField(), context); + WidgetWorker.makeHyperlinkByType(writer, subHyperlink.getLinkType(), subHyperlink.getStyle(context), subHyperlink.getUrlMode(), subHyperlink.getTarget(context), + subHyperlink.getParameterMap(context), description, subHyperlink.getTargetWindow(context), null, subHyperlink.getModelFormField(), + this.request, this.response, context); + } + } + + private String encode(String value, ModelFormField modelFormField, Map context) { + if (UtilValidate.isEmpty(value)) { + return value; + } + UtilCodec.SimpleEncoder encoder = (UtilCodec.SimpleEncoder)context.get("simpleEncoder"); + if (modelFormField.getEncodeOutput() && encoder != null) { + value = encoder.encode(value); + } else { + value = internalEncoder.encode(value); + } + return value; + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderTextField(java.io.Writer, java.util.Map, org.ofbiz.widget.model.ModelFormField.TextField) + */ + public void renderTextField(Appendable writer, Map context, TextField textField) throws IOException { + ModelFormField modelFormField = textField.getModelFormField(); + + writer.append(" updateAreas = modelFormField.getOnChangeUpdateAreas(); + boolean ajaxEnabled = updateAreas != null && this.javaScriptEnabled; + if (!textField.getClientAutocompleteField() || ajaxEnabled) { + writer.append(" autocomplete=\"off\""); + } + + writer.append("/>"); + + this.addAsterisks(writer, context, modelFormField); + + this.makeHyperlinkString(writer, textField.getSubHyperlink(), context); + + this.appendTooltip(writer, context, modelFormField); + + if (ajaxEnabled) { + appendWhitespace(writer); + writer.append(""); + } + appendWhitespace(writer); + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderTextareaField(java.io.Writer, java.util.Map, org.ofbiz.widget.model.ModelFormField.TextareaField) + */ + public void renderTextareaField(Appendable writer, Map context, TextareaField textareaField) throws IOException { + ModelFormField modelFormField = textareaField.getModelFormField(); + + writer.append("'); + + String value = modelFormField.getEntry(context, textareaField.getDefaultValue(context)); + if (UtilValidate.isNotEmpty(value)) { + writer.append(value); + } + + writer.append(""); + + if (textareaField.getVisualEditorEnable()) { + writer.append(""); + writer.append(""); + writer.append(""); + } + + this.addAsterisks(writer, context, modelFormField); + + this.appendTooltip(writer, context, modelFormField); + + //appendWhitespace(writer); + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderDateTimeField(java.io.Writer, java.util.Map, org.ofbiz.widget.model.ModelFormField.DateTimeField) + */ + public void renderDateTimeField(Appendable writer, Map context, DateTimeField dateTimeField) throws IOException { + String macroLibraryPath = UtilProperties.getPropertyValue("widget", "screen.formrenderer"); + try { + MacroFormRenderer macroFormRenderer = new MacroFormRenderer(macroLibraryPath, this.request, this.response); + macroFormRenderer.renderDateTimeField(writer, context, dateTimeField); + } catch (TemplateException e) { + Debug.logError(e, "Error rendering screen thru ftl macro: renderDateTimeField", module); + } catch (IOException e) { + Debug.logError(e, "Error rendering screen thru ftl, macro: renderDateTimeField", module); + } + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderDropDownField(java.io.Writer, java.util.Map, org.ofbiz.widget.model.ModelFormField.DropDownField) + */ + public void renderDropDownField(Appendable writer, Map context, DropDownField dropDownField) throws IOException { + ModelFormField modelFormField = dropDownField.getModelFormField(); + ModelForm modelForm = modelFormField.getModelForm(); + ModelFormField.AutoComplete autoComplete = dropDownField.getAutoComplete(); + boolean ajaxEnabled = autoComplete != null && this.javaScriptEnabled; + List allOptionValues = dropDownField.getAllOptionValues(context, WidgetWorker.getDelegator(context)); + + String event = modelFormField.getEvent(); + String action = modelFormField.getAction(context); + + String currentValue = modelFormField.getEntry(context); + // Get the current value's description from the option value. If there + // is a localized version it will be there. + String currentDescription = null; + if (UtilValidate.isNotEmpty(currentValue)) { + for (ModelFormField.OptionValue optionValue : allOptionValues) { + if (encode(optionValue.getKey(), modelFormField, context).equals(currentValue)) { + currentDescription = optionValue.getDescription(); + break; + } + } + } + + if (ajaxEnabled) { + writer.append(""); + + appendWhitespace(writer); + writer.append(""); + + appendWhitespace(writer); + writer.append(""); + } else { + writer.append('"'); + + if (UtilValidate.isNotEmpty(idName)) { + writer.append(" id=\""); + writer.append(idName); + writer.append('"'); + } + + if (dropDownField.getAllowMultiple()) { + writer.append(" multiple=\"multiple\""); + } + + int otherFieldSize = dropDownField.getOtherFieldSize(); + String otherFieldName = dropDownField.getParameterNameOther(context); + if (otherFieldSize > 0) { + //writer.append(" onchange=\"alert('ONCHANGE, process_choice:' + process_choice)\""); + //writer.append(" onchange='test_js()' "); + writer.append(" onchange=\"process_choice(this,document."); + writer.append(modelForm.getName()); + writer.append("."); + writer.append(otherFieldName); + writer.append(")\" "); + } + + if (UtilValidate.isNotEmpty(event) && UtilValidate.isNotEmpty(action)) { + writer.append(" "); + writer.append(event); + writer.append("=\""); + writer.append(action); + writer.append('"'); + } + + writer.append(" size=\"").append(dropDownField.getSize()).append("\">"); + + // if the current value should go first, stick it in + if (UtilValidate.isNotEmpty(currentValue) && "first-in-list".equals(dropDownField.getCurrent())) { + writer.append(""); + String explicitDescription = (currentDescription != null ? currentDescription : dropDownField.getCurrentDescription(context)); + if (UtilValidate.isNotEmpty(explicitDescription)) { + writer.append(encode(explicitDescription, modelFormField, context)); + } else { + String description = FieldInfoWithOptions.getDescriptionForOptionKey(currentValue, allOptionValues); + writer.append(encode(description, modelFormField, context)); + } + writer.append(""); + + // add a "separator" option + writer.append(""); + } + + // if allow empty is true, add an empty option + if (dropDownField.getAllowEmpty()) { + writer.append(""); + } + + // list out all options according to the option list + for (ModelFormField.OptionValue optionValue: allOptionValues) { + String noCurrentSelectedKey = dropDownField.getNoCurrentSelectedKey(context); + writer.append(""); + writer.append(encode(optionValue.getDescription(), modelFormField, context)); + writer.append(""); + } + + writer.append(""); + + + // Adapted from work by Yucca Korpela + // http://www.cs.tut.fi/~jkorpela/forms/combo.html + if (otherFieldSize > 0) { + + String fieldName = modelFormField.getParameterName(context); + Map dataMap = UtilGenerics.checkMap(modelFormField.getMap(context)); + if (dataMap == null) { + dataMap = context; + } + Object otherValueObj = dataMap.get(otherFieldName); + String otherValue = (otherValueObj == null) ? "" : otherValueObj.toString(); + + writer.append(""); + writer.append("\n"); + } + } + + this.makeHyperlinkString(writer, dropDownField.getSubHyperlink(), context); + + this.appendTooltip(writer, context, modelFormField); + + //appendWhitespace(writer); + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderCheckField(java.io.Writer, java.util.Map, org.ofbiz.widget.model.ModelFormField.CheckField) + */ + public void renderCheckField(Appendable writer, Map context, CheckField checkField) throws IOException { + ModelFormField modelFormField = checkField.getModelFormField(); + String currentValue = modelFormField.getEntry(context); + Boolean allChecked = checkField.isAllChecked(context); + + List allOptionValues = checkField.getAllOptionValues(context, WidgetWorker.getDelegator(context)); + String event = modelFormField.getEvent(); + String action = modelFormField.getAction(context); + + // list out all options according to the option list + for (ModelFormField.OptionValue optionValue: allOptionValues) { + + writer.append(""); + + writer.append(encode(optionValue.getDescription(), modelFormField, context)); + } + + this.appendTooltip(writer, context, modelFormField); + + //appendWhitespace(writer); + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderRadioField(java.io.Writer, java.util.Map, org.ofbiz.widget.model.ModelFormField.RadioField) + */ + public void renderRadioField(Appendable writer, Map context, RadioField radioField) throws IOException { + ModelFormField modelFormField = radioField.getModelFormField(); + List allOptionValues = radioField.getAllOptionValues(context, WidgetWorker.getDelegator(context)); + String currentValue = modelFormField.getEntry(context); + String event = modelFormField.getEvent(); + String action = modelFormField.getAction(context); + + // list out all options according to the option list + for (ModelFormField.OptionValue optionValue: allOptionValues) { + + writer.append(""); + + writer.append(encode(optionValue.getDescription(), modelFormField, context)); + writer.append(""); + } + + this.appendTooltip(writer, context, modelFormField); + + //appendWhitespace(writer); + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderSubmitField(java.io.Writer, java.util.Map, org.ofbiz.widget.model.ModelFormField.SubmitField) + */ + public void renderSubmitField(Appendable writer, Map context, SubmitField submitField) throws IOException { + ModelFormField modelFormField = submitField.getModelFormField(); + ModelForm modelForm = modelFormField.getModelForm(); + String event = null; + String action = null; + String confirmation = encode(submitField.getConfirmation(context), modelFormField, context); + + if ("text-link".equals(submitField.getButtonType())) { + writer.append(""); + + writer.append(encode(modelFormField.getTitle(context), modelFormField, context)); + + writer.append(""); + } else if ("image".equals(submitField.getButtonType())) { + writer.append(""); + } else { + // default to "button" + + String formId = modelForm.getContainerId(); + List updateAreas = modelForm.getOnSubmitUpdateAreas(); + // This is here for backwards compatibility. Use on-event-update-area + // elements instead. + String backgroundSubmitRefreshTarget = submitField.getBackgroundSubmitRefreshTarget(context); + if (UtilValidate.isNotEmpty(backgroundSubmitRefreshTarget)) { + if (updateAreas == null) { + updateAreas = new LinkedList(); + } + updateAreas.add(new ModelForm.UpdateArea("submit", formId, backgroundSubmitRefreshTarget)); + } + + boolean ajaxEnabled = (UtilValidate.isNotEmpty(updateAreas) || UtilValidate.isNotEmpty(backgroundSubmitRefreshTarget)) && this.javaScriptEnabled; + if (ajaxEnabled) { + writer.append(""); + } + + this.appendTooltip(writer, context, modelFormField); + + //appendWhitespace(writer); + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderResetField(java.io.Writer, java.util.Map, org.ofbiz.widget.model.ModelFormField.ResetField) + */ + public void renderResetField(Appendable writer, Map context, ResetField resetField) throws IOException { + ModelFormField modelFormField = resetField.getModelFormField(); + + writer.append(""); + + this.appendTooltip(writer, context, modelFormField); + + //appendWhitespace(writer); + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderHiddenField(java.io.Writer, java.util.Map, org.ofbiz.widget.model.ModelFormField.HiddenField) + */ + public void renderHiddenField(Appendable writer, Map context, HiddenField hiddenField) throws IOException { + ModelFormField modelFormField = hiddenField.getModelFormField(); + String value = hiddenField.getValue(context); + this.renderHiddenField(writer, context, modelFormField, value); + } + + public void renderHiddenField(Appendable writer, Map context, ModelFormField modelFormField, String value) throws IOException { + writer.append(""); + appendWhitespace(writer); + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderIgnoredField(java.io.Writer, java.util.Map, org.ofbiz.widget.model.ModelFormField.IgnoredField) + */ + public void renderIgnoredField(Appendable writer, Map context, IgnoredField ignoredField) throws IOException { + // do nothing, it's an ignored field; could add a comment or something if we wanted to + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderFieldTitle(java.io.Writer, java.util.Map, org.ofbiz.widget.model.ModelFormField) + */ + public void renderFieldTitle(Appendable writer, Map context, ModelFormField modelFormField) throws IOException { + String tempTitleText = modelFormField.getTitle(context); + String titleText = UtilHttp.encodeAmpersands(tempTitleText); + + if (UtilValidate.isNotEmpty(titleText)) { + // copied from MacroFormRenderer renderFieldTitle + String displayHelpText = UtilProperties.getPropertyValue("widget.properties", "widget.form.displayhelpText"); + String helpText = null; + if ("Y".equals(displayHelpText)) { + Delegator delegator = WidgetWorker.getDelegator(context); + Locale locale = (Locale)context.get("locale"); + String entityName = modelFormField.getEntityName(); + String fieldName = modelFormField.getFieldName(); + helpText = UtilHelpText.getEntityFieldDescription(entityName, fieldName, delegator, locale); + } + if (UtilValidate.isNotEmpty(modelFormField.getTitleStyle()) || UtilValidate.isNotEmpty(helpText)) { + writer.append(""); + } + if (" ".equals(titleText)) { + // If the title content is just a blank then render it colling renderFormatEmptySpace: + // the method will set its content to work fine in most browser + this.renderFormatEmptySpace(writer, context, modelFormField.getModelForm()); + } else { + renderHyperlinkTitle(writer, context, modelFormField, titleText); + } + + if (UtilValidate.isNotEmpty(modelFormField.getTitleStyle())) { + writer.append(""); + } + + //appendWhitespace(writer); + } + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderFieldTitle(java.io.Writer, java.util.Map, org.ofbiz.widget.model.ModelFormField) + */ + public void renderSingleFormFieldTitle(Appendable writer, Map context, ModelFormField modelFormField) throws IOException { + boolean requiredField = modelFormField.getRequiredField(); + if (requiredField) { + + String requiredStyle = modelFormField.getRequiredFieldStyle(); + if (UtilValidate.isEmpty(requiredStyle)) { + requiredStyle = modelFormField.getTitleStyle(); + } + + if (UtilValidate.isNotEmpty(requiredStyle)) { + writer.append(""); + } + renderHyperlinkTitle(writer, context, modelFormField, modelFormField.getTitle(context)); + if (UtilValidate.isNotEmpty(requiredStyle)) { + writer.append(""); + } + + //appendWhitespace(writer); + } else { + renderFieldTitle(writer, context, modelFormField); + } + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderFormOpen(java.io.Writer, java.util.Map, org.ofbiz.widget.form.model.ModelForm) + */ + public void renderFormOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException { + this.widgetCommentsEnabled = ModelWidget.widgetBoundaryCommentsEnabled(context); + renderBeginningBoundaryComment(writer, "Form Widget - Form Element", modelForm); + writer.append("
"); + + boolean useRowSubmit = modelForm.getUseRowSubmit(); + if (useRowSubmit) { + writer.append(""); + } + + appendWhitespace(writer); + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderFormClose(java.io.Writer, java.util.Map, org.ofbiz.widget.form.model.ModelForm) + */ + public void renderFormClose(Appendable writer, Map context, ModelForm modelForm) throws IOException { + writer.append(""); + String focusFieldName = FormRenderer.getFocusFieldName(modelForm, context); + if (UtilValidate.isNotEmpty(focusFieldName)) { + appendWhitespace(writer); + writer.append(""); + } + appendWhitespace(writer); + renderEndingBoundaryComment(writer, "Form Widget - Form Element", modelForm); + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderFormClose(java.io.Writer, java.util.Map, org.ofbiz.widget.form.model.ModelForm) + */ + public void renderMultiFormClose(Appendable writer, Map context, ModelForm modelForm) throws IOException { + for (ModelFormField submitField: modelForm.getMultiSubmitFields()) { + if (submitField != null) { + + // Threw this in that as a hack to keep the submit button from expanding the first field + // Needs a more rugged solution + // WARNING: this method (renderMultiFormClose) must be called after the + // table that contains the list has been closed (to avoid validation errors) so + // we cannot call here the methods renderFormatItemRowCell*: for this reason + // they are now commented. + + // this.renderFormatItemRowCellOpen(writer, context, modelForm, submitField); + // this.renderFormatItemRowCellClose(writer, context, modelForm, submitField); + + // this.renderFormatItemRowCellOpen(writer, context, modelForm, submitField); + + submitField.renderFieldString(writer, context, this); + + // this.renderFormatItemRowCellClose(writer, context, modelForm, submitField); + + } + } + writer.append(""); + appendWhitespace(writer); + + // see if there is anything that needs to be added outside of the multi-form + Map wholeFormContext = UtilGenerics.checkMap(context.get("wholeFormContext")); + Appendable postMultiFormWriter = wholeFormContext != null ? (Appendable) wholeFormContext.get("postMultiFormWriter") : null; + if (postMultiFormWriter != null) { + writer.append(postMultiFormWriter.toString()); + appendWhitespace(writer); + } + + renderEndingBoundaryComment(writer, "Form Widget - Form Element (Multi)", modelForm); + } + + public void renderFormatListWrapperOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException { + + Map inputFields = UtilGenerics.checkMap(context.get("requestParameters")); + Map queryStringMap = UtilGenerics.toMap(context.get("queryStringMap")); + if (UtilValidate.isNotEmpty(queryStringMap)) { + inputFields.putAll(queryStringMap); + } + if (modelForm.getType().equals("multi")) { + inputFields = UtilHttp.removeMultiFormParameters(inputFields); + } + String queryString = UtilHttp.urlEncodeArgs(inputFields); + context.put("_QBESTRING_", queryString); + + this.widgetCommentsEnabled = ModelWidget.widgetBoundaryCommentsEnabled(context); + renderBeginningBoundaryComment(writer, "Form Widget", modelForm); + + if (this.renderPagination) { + this.renderNextPrev(writer, context, modelForm); + } + writer.append(" "); + appendWhitespace(writer); + } + + public void renderFormatListWrapperClose(Appendable writer, Map context, ModelForm modelForm) throws IOException { + writer.append("
"); + + appendWhitespace(writer); + if (this.renderPagination) { + this.renderNextPrev(writer, context, modelForm); + } + renderEndingBoundaryComment(writer, "Form Widget - Formal List Wrapper", modelForm); + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderFormatHeaderRowOpen(java.io.Writer, java.util.Map, org.ofbiz.widget.form.model.ModelForm) + */ + public void renderFormatHeaderRowOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException { + writer.append(" "); + appendWhitespace(writer); + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderFormatHeaderRowClose(java.io.Writer, java.util.Map, org.ofbiz.widget.form.model.ModelForm) + */ + public void renderFormatHeaderRowClose(Appendable writer, Map context, ModelForm modelForm) throws IOException { + writer.append(" "); + + appendWhitespace(writer); + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderFormatHeaderRowCellOpen(java.io.Writer, java.util.Map, org.ofbiz.widget.form.model.ModelForm, org.ofbiz.widget.model.ModelFormField, int positionSpan) + */ + public void renderFormatHeaderRowCellOpen(Appendable writer, Map context, ModelForm modelForm, ModelFormField modelFormField, int positionSpan) throws IOException { + writer.append(" 1) { + writer.append(" colspan=\""); + writer.append(Integer.toString(positionSpan)); + writer.append("\""); + } + if (UtilValidate.isNotEmpty(areaStyle)) { + writer.append(" class=\""); + writer.append(areaStyle); + writer.append("\""); + } + writer.append(">"); + //appendWhitespace(writer); + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderFormatHeaderRowCellClose(java.io.Writer, java.util.Map, org.ofbiz.widget.form.model.ModelForm, org.ofbiz.widget.model.ModelFormField) + */ + public void renderFormatHeaderRowCellClose(Appendable writer, Map context, ModelForm modelForm, ModelFormField modelFormField) throws IOException { + writer.append(""); + appendWhitespace(writer); + } + + public void renderFormatHeaderRowFormCellOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException { + writer.append(" "); + //appendWhitespace(writer); + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderFormatHeaderRowFormCellClose(java.io.Writer, java.util.Map, org.ofbiz.widget.form.model.ModelForm) + */ + public void renderFormatHeaderRowFormCellClose(Appendable writer, Map context, ModelForm modelForm) throws IOException { + writer.append(""); + appendWhitespace(writer); + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderFormatHeaderRowFormCellTitleSeparator(java.io.Writer, java.util.Map, org.ofbiz.widget.form.model.ModelForm, boolean) + */ + public void renderFormatHeaderRowFormCellTitleSeparator(Appendable writer, Map context, ModelForm modelForm, ModelFormField modelFormField, boolean isLast) throws IOException { + + String titleStyle = modelFormField.getTitleStyle(); + if (UtilValidate.isNotEmpty(titleStyle)) { + writer.append(""); + } + if (isLast) { + writer.append(" - "); + } else { + writer.append(" - "); + } + if (UtilValidate.isNotEmpty(titleStyle)) { + writer.append(""); + } + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderFormatItemRowOpen(java.io.Writer, java.util.Map, org.ofbiz.widget.form.model.ModelForm) + */ + public void renderFormatItemRowOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException { + Integer itemIndex = (Integer)context.get("itemIndex"); + + writer.append(" "); + appendWhitespace(writer); + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderFormatItemRowClose(java.io.Writer, java.util.Map, org.ofbiz.widget.form.model.ModelForm) + */ + public void renderFormatItemRowClose(Appendable writer, Map context, ModelForm modelForm) throws IOException { + writer.append(" "); + + appendWhitespace(writer); + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderFormatItemRowCellOpen(java.io.Writer, java.util.Map, org.ofbiz.widget.form.model.ModelForm, org.ofbiz.widget.model.ModelFormField) + */ + public void renderFormatItemRowCellOpen(Appendable writer, Map context, ModelForm modelForm, ModelFormField modelFormField, int positionSpan) throws IOException { + writer.append(" 1) { + writer.append(" colspan=\""); + writer.append(Integer.toString(positionSpan)); + writer.append("\""); + } + if (UtilValidate.isNotEmpty(areaStyle)) { + writer.append(" class=\""); + writer.append(areaStyle); + writer.append("\""); + } + writer.append(">"); + //appendWhitespace(writer); + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderFormatItemRowCellClose(java.io.Writer, java.util.Map, org.ofbiz.widget.form.model.ModelForm, org.ofbiz.widget.model.ModelFormField) + */ + public void renderFormatItemRowCellClose(Appendable writer, Map context, ModelForm modelForm, ModelFormField modelFormField) throws IOException { + writer.append(""); + appendWhitespace(writer); + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderFormatItemRowFormCellOpen(java.io.Writer, java.util.Map, org.ofbiz.widget.form.model.ModelForm) + */ + public void renderFormatItemRowFormCellOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException { + writer.append(" "); + //appendWhitespace(writer); + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderFormatItemRowFormCellClose(java.io.Writer, java.util.Map, org.ofbiz.widget.form.model.ModelForm) + */ + public void renderFormatItemRowFormCellClose(Appendable writer, Map context, ModelForm modelForm) throws IOException { + writer.append(""); + appendWhitespace(writer); + } + + public void renderFormatSingleWrapperOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException { + writer.append(" "); + appendWhitespace(writer); + } + + public void renderFormatSingleWrapperClose(Appendable writer, Map context, ModelForm modelForm) throws IOException { + writer.append("
"); + appendWhitespace(writer); + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderFormatFieldRowOpen(java.io.Writer, java.util.Map, org.ofbiz.widget.form.model.ModelForm) + */ + public void renderFormatFieldRowOpen(Appendable writer, Map context, ModelForm modelForm) throws IOException { + writer.append(" "); + appendWhitespace(writer); + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderFormatFieldRowClose(java.io.Writer, java.util.Map, org.ofbiz.widget.form.model.ModelForm) + */ + public void renderFormatFieldRowClose(Appendable writer, Map context, ModelForm modelForm) throws IOException { + writer.append(" "); + appendWhitespace(writer); + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderFormatFieldRowTitleCellOpen(java.io.Writer, java.util.Map, org.ofbiz.widget.model.ModelFormField) + */ + public void renderFormatFieldRowTitleCellOpen(Appendable writer, Map context, ModelFormField modelFormField) throws IOException { + writer.append(" "); + //appendWhitespace(writer); + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderFormatFieldRowTitleCellClose(java.io.Writer, java.util.Map, org.ofbiz.widget.model.ModelFormField) + */ + public void renderFormatFieldRowTitleCellClose(Appendable writer, Map context, ModelFormField modelFormField) throws IOException { + writer.append(""); + appendWhitespace(writer); + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderFormatFieldRowSpacerCell(java.io.Writer, java.util.Map, org.ofbiz.widget.model.ModelFormField) + */ + public void renderFormatFieldRowSpacerCell(Appendable writer, Map context, ModelFormField modelFormField) throws IOException { + // Embedded styling - bad idea + //writer.append(" "); + + //appendWhitespace(writer); + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderFormatFieldRowWidgetCellOpen(java.io.Writer, java.util.Map, org.ofbiz.widget.model.ModelFormField, int) + */ + public void renderFormatFieldRowWidgetCellOpen(Appendable writer, Map context, ModelFormField modelFormField, int positions, int positionSpan, Integer nextPositionInRow) throws IOException { +// writer.append(" 1) { +// writer.append("30"); +// } else { +// writer.append("80"); +// } +// writer.append("%\""); + writer.append(" 0) { + writer.append(" colspan=\""); + // do a span of 1 for this column, plus 3 columns for each spanned + //position or each blank position that this will be filling in + writer.append(Integer.toString(1 + (positionSpan * 3))); + writer.append("\""); + } + String areaStyle = modelFormField.getWidgetAreaStyle(); + if (UtilValidate.isNotEmpty(areaStyle)) { + writer.append(" class=\""); + writer.append(areaStyle); + writer.append("\""); + } + writer.append(">"); + + //appendWhitespace(writer); + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderFormatFieldRowWidgetCellClose(java.io.Writer, java.util.Map, org.ofbiz.widget.model.ModelFormField, int) + */ + public void renderFormatFieldRowWidgetCellClose(Appendable writer, Map context, ModelFormField modelFormField, int positions, int positionSpan, Integer nextPositionInRow) throws IOException { + writer.append(""); + appendWhitespace(writer); + } + + public void renderFormatEmptySpace(Appendable writer, Map context, ModelForm modelForm) throws IOException { + writer.append(" "); + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderTextFindField(java.io.Writer, java.util.Map, org.ofbiz.widget.model.ModelFormField.TextFindField) + */ + public void renderTextFindField(Appendable writer, Map context, TextFindField textFindField) throws IOException { + + ModelFormField modelFormField = textFindField.getModelFormField(); + + String defaultOption = textFindField.getDefaultOption(); + Locale locale = (Locale)context.get("locale"); + if (!textFindField.getHideOptions()) { + String opEquals = UtilProperties.getMessage("conditional", "equals", locale); + String opBeginsWith = UtilProperties.getMessage("conditional", "begins_with", locale); + String opContains = UtilProperties.getMessage("conditional", "contains", locale); + String opIsEmpty = UtilProperties.getMessage("conditional", "is_empty", locale); + String opNotEqual = UtilProperties.getMessage("conditional", "not_equal", locale); + writer.append(" "); + } else { + writer.append(" "); + } + + writer.append(""); + + if (UtilValidate.isNotEmpty(modelFormField.getTitleStyle())) { + writer.append(" "); + } + + String ignoreCase = UtilProperties.getMessage("conditional", "ignore_case", locale); + boolean ignCase = textFindField.getIgnoreCase(); + + if (!textFindField.getHideIgnoreCase()) { + writer.append(" "); + writer.append(ignoreCase); + } else { + writer.append(""); + } + + if (UtilValidate.isNotEmpty(modelFormField.getTitleStyle())) { + writer.append(""); + } + + this.appendTooltip(writer, context, modelFormField); + + //appendWhitespace(writer); + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderRangeFindField(java.io.Writer, java.util.Map, org.ofbiz.widget.model.ModelFormField.RangeFindField) + */ + public void renderRangeFindField(Appendable writer, Map context, RangeFindField rangeFindField) throws IOException { + + ModelFormField modelFormField = rangeFindField.getModelFormField(); + Locale locale = (Locale)context.get("locale"); + String opEquals = UtilProperties.getMessage("conditional", "equals", locale); + String opGreaterThan = UtilProperties.getMessage("conditional", "greater_than", locale); + String opGreaterThanEquals = UtilProperties.getMessage("conditional", "greater_than_equals", locale); + String opLessThan = UtilProperties.getMessage("conditional", "less_than", locale); + String opLessThanEquals = UtilProperties.getMessage("conditional", "less_than_equals", locale); + //String opIsEmpty = UtilProperties.getMessage("conditional", "is_empty", locale); + + writer.append(""); + + if (UtilValidate.isNotEmpty(modelFormField.getTitleStyle())) { + writer.append(" "); + } + + String defaultOptionFrom = rangeFindField.getDefaultOptionFrom(); + writer.append(" "); + + writer.append(""); + + writer.append("
"); + + writer.append(""); + + String defaultOptionThru = rangeFindField.getDefaultOptionThru(); + writer.append(" "); + + if (UtilValidate.isNotEmpty(modelFormField.getTitleStyle())) { + writer.append(""); + } + + this.appendTooltip(writer, context, modelFormField); + + //appendWhitespace(writer); + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderDateFindField(java.io.Writer, java.util.Map, org.ofbiz.widget.model.ModelFormField.DateFindField) + */ + public void renderDateFindField(Appendable writer, Map context, DateFindField dateFindField) throws IOException { + ModelFormField modelFormField = dateFindField.getModelFormField(); + + Locale locale = (Locale)context.get("locale"); + String opEquals = UtilProperties.getMessage("conditional", "equals", locale); + String opGreaterThan = UtilProperties.getMessage("conditional", "greater_than", locale); + String opSameDay = UtilProperties.getMessage("conditional", "same_day", locale); + String opGreaterThanFromDayStart = UtilProperties.getMessage("conditional", + "greater_than_from_day_start", locale); + String opLessThan = UtilProperties.getMessage("conditional", "less_than", locale); + String opUpToDay = UtilProperties.getMessage("conditional", "up_to_day", locale); + String opUpThruDay = UtilProperties.getMessage("conditional", "up_thru_day", locale); + String opIsEmpty = UtilProperties.getMessage("conditional", "is_empty", locale); + + Map uiLabelMap = UtilGenerics.checkMap(context.get("uiLabelMap")); + if (uiLabelMap == null) { + Debug.logWarning("Could not find uiLabelMap in context", module); + } + String localizedInputTitle = "", localizedIconTitle = ""; + + writer.append(" maxlength) { + value = value.substring(0, maxlength); + } + writer.append(" value=\""); + writer.append(value); + writer.append('"'); + } + + writer.append(" size=\""); + writer.append(Integer.toString(size)); + writer.append('"'); + + writer.append(" maxlength=\""); + writer.append(Integer.toString(maxlength)); + writer.append('"'); + + writer.append("/>"); + + // search for a localized label for the icon + if (uiLabelMap != null) { + localizedIconTitle = uiLabelMap.get("CommonViewCalendar"); + } + ModelForm modelForm = modelFormField.getModelForm(); + // add calendar pop-up button and seed data IF this is not a "time" type date-find + if (!"time".equals(dateFindField.getType())) { + if ("date".equals(dateFindField.getType())) { + writer.append(""); + + writer.append("\"");"); + } + + if (UtilValidate.isNotEmpty(modelFormField.getTitleStyle())) { + writer.append(" "); + } + + String defaultOptionFrom = dateFindField.getDefaultOptionFrom(); + writer.append(" "); + + if (UtilValidate.isNotEmpty(modelFormField.getTitleStyle())) { + writer.append(" "); + } + + writer.append("
"); + + writer.append(" maxlength) { + value = value.substring(0, maxlength); + } + writer.append(" value=\""); + writer.append(value); + writer.append('"'); + } + + writer.append(" size=\""); + writer.append(Integer.toString(size)); + writer.append('"'); + + writer.append(" maxlength=\""); + writer.append(Integer.toString(maxlength)); + writer.append('"'); + + writer.append("/>"); + + // add calendar pop-up button and seed data IF this is not a "time" type date-find + if (!"time".equals(dateFindField.getType())) { + if ("date".equals(dateFindField.getType())) { + writer.append(""); + + writer.append("\"");"); + } + + if (UtilValidate.isNotEmpty(modelFormField.getTitleStyle())) { + writer.append(" "); + } + + String defaultOptionThru = dateFindField.getDefaultOptionThru(); + writer.append(" "); + + if (UtilValidate.isNotEmpty(modelFormField.getTitleStyle())) { + writer.append(""); + } + + this.appendTooltip(writer, context, modelFormField); + + //appendWhitespace(writer); + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderLookupField(java.io.Writer, java.util.Map, org.ofbiz.widget.model.ModelFormField.LookupField) + */ + public void renderLookupField(Appendable writer, Map context, LookupField lookupField) throws IOException { + ModelFormField modelFormField = lookupField.getModelFormField(); + + writer.append(" updateAreas = modelFormField.getOnChangeUpdateAreas(); + boolean ajaxEnabled = updateAreas != null && this.javaScriptEnabled; + if (!lookupField.getClientAutocompleteField() || ajaxEnabled) { + writer.append(" autocomplete=\"off\""); + } + + writer.append("/>"); + ModelForm modelForm = modelFormField.getModelForm(); + // add lookup pop-up button + String descriptionFieldName = lookupField.getDescriptionFieldName(); + if (UtilValidate.isNotEmpty(descriptionFieldName)) { + writer.append(" targetParameterList = lookupField.getTargetParameterList(); + for (String targetParameter: targetParameterList) { + // named like: document.${formName}.${targetParameter}.value + writer.append(", document."); + writer.append(FormRenderer.getCurrentFormName(modelForm, context)); + writer.append("."); + writer.append(targetParameter); + writer.append(".value"); + } + writer.append(");\">"); + writer.append("\"Lookup\"/"); + + this.addAsterisks(writer, context, modelFormField); + + this.makeHyperlinkString(writer, lookupField.getSubHyperlink(), context); + this.appendTooltip(writer, context, modelFormField); + + if (ajaxEnabled) { + appendWhitespace(writer); + writer.append(""); + } + appendWhitespace(writer); + + //appendWhitespace(writer); + } + + protected String appendExternalLoginKey(String target) { + String result = target; + String sessionId = ";jsessionid=" + request.getSession().getId(); + int questionIndex = target.indexOf("?"); + if (questionIndex == -1) { + result += sessionId; + } else { + result = result.replace("?", sessionId + "?"); + } + return result; + } + + private int getActualPageSize(Map context) { + Integer value = (Integer) context.get("actualPageSize"); + return value != null ? value.intValue() : (getHighIndex(context) - getLowIndex(context)); + } + + private int getHighIndex(Map context) { + Integer value = (Integer) context.get("highIndex"); + return value != null ? value.intValue() : 0; + } + + private int getListSize(Map context) { + Integer value = (Integer) context.get("listSize"); + return value != null ? value.intValue() : 0; + } + + private int getLowIndex(Map context) { + Integer value = (Integer) context.get("lowIndex"); + return value != null ? value.intValue() : 0; + } + + public void renderNextPrev(Appendable writer, Map context, ModelForm modelForm) throws IOException { + boolean ajaxEnabled = false; + List updateAreas = modelForm.getOnPaginateUpdateAreas(); + String targetService = modelForm.getPaginateTarget(context); + if (this.javaScriptEnabled) { + if (UtilValidate.isNotEmpty(updateAreas)) { + ajaxEnabled = true; + } + } + if (targetService == null) { + targetService = "${targetService}"; + } + if (UtilValidate.isEmpty(targetService) && updateAreas == null) { + Debug.logWarning("Cannot paginate because TargetService is empty for the form: " + modelForm.getName(), module); + return; + } + + // get the parameterized pagination index and size fields + int paginatorNumber = WidgetWorker.getPaginatorNumber(context); + String viewIndexParam = modelForm.getMultiPaginateIndexField(context); + String viewSizeParam = modelForm.getMultiPaginateSizeField(context); + + int viewIndex = Paginator.getViewIndex(modelForm, context); + int viewSize = Paginator.getViewSize(modelForm, context); + int listSize = getListSize(context); + + int lowIndex = getLowIndex(context); + int highIndex = getHighIndex(context); + int actualPageSize = getActualPageSize(context); + + // if this is all there seems to be (if listSize < 0, then size is unknown) + if (actualPageSize >= listSize && listSize >= 0) return; + + // needed for the "Page" and "rows" labels + Map uiLabelMap = UtilGenerics.checkMap(context.get("uiLabelMap")); + String pageLabel = ""; + String commonDisplaying = ""; + if (uiLabelMap == null) { + Debug.logWarning("Could not find uiLabelMap in context", module); + } else { + pageLabel = uiLabelMap.get("CommonPage"); + Map messageMap = UtilMisc.toMap("lowCount", Integer.valueOf(lowIndex + 1), "highCount", Integer.valueOf(lowIndex + actualPageSize), "total", Integer.valueOf(listSize)); + commonDisplaying = UtilProperties.getMessage("CommonUiLabels", "CommonDisplaying", messageMap, (Locale) context.get("locale")); + } + + // for legacy support, the viewSizeParam is VIEW_SIZE and viewIndexParam is VIEW_INDEX when the fields are "viewSize" and "viewIndex" + if (viewIndexParam.equals("viewIndex" + "_" + paginatorNumber)) viewIndexParam = "VIEW_INDEX" + "_" + paginatorNumber; + if (viewSizeParam.equals("viewSize" + "_" + paginatorNumber)) viewSizeParam = "VIEW_SIZE" + "_" + paginatorNumber; + + String str = (String) context.get("_QBESTRING_"); + + // strip legacy viewIndex/viewSize params from the query string + String queryString = UtilHttp.stripViewParamsFromQueryString(str, "" + paginatorNumber); + + // strip parametrized index/size params from the query string + HashSet paramNames = new HashSet(); + paramNames.add(viewIndexParam); + paramNames.add(viewSizeParam); + queryString = UtilHttp.stripNamedParamsFromQueryString(queryString, paramNames); + + String anchor = ""; + String paginateAnchor = modelForm.getPaginateTargetAnchor(); + if (paginateAnchor != null) anchor = "#" + paginateAnchor; + + // Create separate url path String and request parameters String, + // add viewIndex/viewSize parameters to request parameter String + String urlPath = UtilHttp.removeQueryStringFromTarget(targetService); + StringBuilder prepLinkBuffer = new StringBuilder(); + String prepLinkQueryString = UtilHttp.getQueryStringFromTarget(targetService); + if (prepLinkQueryString != null) { + prepLinkBuffer.append(prepLinkQueryString); + } + if (prepLinkBuffer.indexOf("?") < 0) { + prepLinkBuffer.append("?"); + } else if (prepLinkBuffer.indexOf("?", prepLinkBuffer.length() - 1) > 0) { + prepLinkBuffer.append("&"); + } + if (!UtilValidate.isEmpty(queryString) && !queryString.equals("null")) { + prepLinkBuffer.append(queryString).append("&"); + } + prepLinkBuffer.append(viewSizeParam).append("=").append(viewSize).append("&").append(viewIndexParam).append("="); + String prepLinkText = prepLinkBuffer.toString(); + if (ajaxEnabled) { + // Prepare params for prototype.js + prepLinkText = prepLinkText.replace("?", ""); + prepLinkText = prepLinkText.replace("&", "&"); + } + + writer.append("
"); + appendWhitespace(writer); + writer.append("
    "); + appendWhitespace(writer); + + String linkText; + + // First button + writer.append("
  • 0) { + writer.append("\">").append(modelForm.getPaginateFirstLabel(context)).append(""); + } else { + // disabled button + writer.append("-disabled\">").append(modelForm.getPaginateFirstLabel(context)); + } + writer.append("
  • "); + appendWhitespace(writer); + + // Previous button + writer.append("
  • 0) { + writer.append("\">").append(modelForm.getPaginatePreviousLabel(context)).append(""); + } else { + // disabled button + writer.append("-disabled\">").append(modelForm.getPaginatePreviousLabel(context)); + } + writer.append("
  • "); + appendWhitespace(writer); + + // Page select dropdown + if (listSize > 0 && this.javaScriptEnabled) { + writer.append("
  • ").append(pageLabel).append("
  • "); + } + + // show row count + writer.append("
  • "); + writer.append(commonDisplaying); + writer.append("
  • "); + appendWhitespace(writer); + + // Next button + writer.append("
  • ").append(modelForm.getPaginateNextLabel(context)).append(""); + } else { + // disabled button + writer.append("-disabled\">").append(modelForm.getPaginateNextLabel(context)); + } + writer.append("
  • "); + appendWhitespace(writer); + + // Last button + writer.append("
  • ").append(modelForm.getPaginateLastLabel(context)).append(""); + } else { + // disabled button + writer.append("-disabled\">").append(modelForm.getPaginateLastLabel(context)); + } + writer.append("
  • "); + appendWhitespace(writer); + + writer.append("
"); + appendWhitespace(writer); + writer.append("
"); + appendWhitespace(writer); + } + + public void renderSortField(Appendable writer, Map context, ModelFormField modelFormField, String titleText) throws IOException { + boolean ajaxEnabled = false; + ModelForm modelForm = modelFormField.getModelForm(); + List updateAreas = modelForm.getOnPaginateUpdateAreas(); + String targetService = modelForm.getPaginateTarget(context); + if (this.javaScriptEnabled) { + if (UtilValidate.isNotEmpty(updateAreas)) { + ajaxEnabled = true; + } + } + if (targetService == null) { + targetService = "${targetService}"; + } + if (UtilValidate.isEmpty(targetService) && updateAreas == null) { + Debug.logWarning("Cannot sort because TargetService is empty for the form: " + modelForm.getName(), module); + return; + } + + String str = (String) context.get("_QBESTRING_"); + String oldSortField = modelForm.getSortField(context); + String sortFieldStyle = modelFormField.getSortFieldStyle(); + + // if the entry-name is defined use this instead of field name + String columnField = modelFormField.getEntryName(); + if (UtilValidate.isEmpty(columnField)) { + columnField = modelFormField.getFieldName(); + } + + // switch beetween asc/desc order + String newSortField = columnField; + if (UtilValidate.isNotEmpty(oldSortField)) { + if (oldSortField.equals(columnField)) { + newSortField = "-" + columnField; + sortFieldStyle = modelFormField.getSortFieldStyleDesc(); + } else if (oldSortField.equals("-" + columnField)) { + newSortField = columnField; + sortFieldStyle = modelFormField.getSortFieldStyleAsc(); + } + } + + // strip sortField param from the query string + HashSet paramName = new HashSet(); + paramName.add("sortField"); + String queryString = UtilHttp.stripNamedParamsFromQueryString(str, paramName); + String urlPath = UtilHttp.removeQueryStringFromTarget(targetService); + StringBuilder prepLinkBuffer = new StringBuilder(); + String prepLinkQueryString = UtilHttp.getQueryStringFromTarget(targetService); + if (prepLinkQueryString != null) { + prepLinkBuffer.append(prepLinkQueryString); + } + if (prepLinkBuffer.indexOf("?") < 0) { + prepLinkBuffer.append("?"); + } else if (prepLinkBuffer.indexOf("?", prepLinkBuffer.length() - 1) > 0) { + prepLinkBuffer.append("&"); + } + if (!UtilValidate.isEmpty(queryString) && !queryString.equals("null")) { + prepLinkBuffer.append(queryString).append("&"); + } + prepLinkBuffer.append("sortField").append("=").append(newSortField); + String prepLinkText = prepLinkBuffer.toString(); + if (ajaxEnabled) { + prepLinkText = prepLinkText.replace("?", ""); + prepLinkText = prepLinkText.replace("&", "&"); + } + + writer.append("").append(titleText).append(""); + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderFileField(java.io.Writer, java.util.Map, org.ofbiz.widget.model.ModelFormField.FileField) + */ + public void renderFileField(Appendable writer, Map context, FileField textField) throws IOException { + ModelFormField modelFormField = textField.getModelFormField(); + + writer.append(""); + + this.makeHyperlinkString(writer, textField.getSubHyperlink(), context); + + this.appendTooltip(writer, context, modelFormField); + + //appendWhitespace(writer); + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderPasswordField(java.io.Writer, java.util.Map, org.ofbiz.widget.model.ModelFormField.PasswordField) + */ + public void renderPasswordField(Appendable writer, Map context, PasswordField passwordField) throws IOException { + ModelFormField modelFormField = passwordField.getModelFormField(); + + writer.append(""); + + this.addAsterisks(writer, context, modelFormField); + + this.makeHyperlinkString(writer, passwordField.getSubHyperlink(), context); + + this.appendTooltip(writer, context, modelFormField); + + //appendWhitespace(writer); + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.form.FormStringRenderer#renderImageField(java.io.Writer, java.util.Map, org.ofbiz.widget.model.ModelFormField.ImageField) + */ + public void renderImageField(Appendable writer, Map context, ImageField imageField) throws IOException { + ModelFormField modelFormField = imageField.getModelFormField(); + + writer.append(""); + + this.makeHyperlinkString(writer, imageField.getSubHyperlink(), context); + + this.appendTooltip(writer, context, modelFormField); + + //appendWhitespace(writer); + } + + public void renderFieldGroupOpen(Appendable writer, Map context, ModelForm.FieldGroup fieldGroup) throws IOException { + String style = fieldGroup.getStyle(); + String id = fieldGroup.getId(); + FlexibleStringExpander titleNotExpanded = FlexibleStringExpander.getInstance(fieldGroup.getTitle()); + String title = titleNotExpanded.expandString(context); + Boolean collapsed = fieldGroup.initiallyCollapsed(); + String collapsibleAreaId = fieldGroup.getId() + "_body"; + + if (UtilValidate.isNotEmpty(style) || UtilValidate.isNotEmpty(id) || UtilValidate.isNotEmpty(title)) { + + writer.append("
"); + + writer.append("
"); + + if (fieldGroup.collapsible()) { + String expandToolTip = null; + String collapseToolTip = null; + Map uiLabelMap = UtilGenerics.checkMap(context.get("uiLabelMap")); + //Map paramMap = UtilGenerics.checkMap(context.get("requestParameters")); + if (uiLabelMap != null) { + expandToolTip = (String) uiLabelMap.get("CommonExpand"); + collapseToolTip = (String) uiLabelMap.get("CommonCollapse"); + } + + writer.append(""); + + appendWhitespace(writer); + } + writer.append(""); + + if (UtilValidate.isNotEmpty(title)) { + writer.append("
"); + writer.append(title); + writer.append("
"); + } + + writer.append("
"); + + writer.append("
"); + } + } + + public void renderFieldGroupClose(Appendable writer, Map context, ModelForm.FieldGroup fieldGroup) throws IOException { + String style = fieldGroup.getStyle(); + String id = fieldGroup.getId(); + String title = fieldGroup.getTitle(); + if (UtilValidate.isNotEmpty(style) || UtilValidate.isNotEmpty(id) || UtilValidate.isNotEmpty(title)) { + writer.append("
"); + writer.append("
"); + } + } + + // TODO: Remove embedded styling + public void renderBanner(Appendable writer, Map context, ModelForm.Banner banner) throws IOException { + writer.append(" "); + String style = banner.getStyle(context); + String leftStyle = banner.getLeftTextStyle(context); + if (UtilValidate.isEmpty(leftStyle)) leftStyle = style; + String rightStyle = banner.getRightTextStyle(context); + if (UtilValidate.isEmpty(rightStyle)) rightStyle = style; + + String leftText = banner.getLeftText(context); + if (UtilValidate.isNotEmpty(leftText)) { + writer.append(" "); + } + + String text = banner.getText(context); + if (UtilValidate.isNotEmpty(text)) { + writer.append(" "); + } + + String rightText = banner.getRightText(context); + if (UtilValidate.isNotEmpty(rightText)) { + writer.append(" "); + } + writer.append("
"); + if (UtilValidate.isNotEmpty(leftStyle)) { + writer.append(""); + } + writer.append(leftText); + if (UtilValidate.isNotEmpty(leftStyle)) { + writer.append(""); + } + writer.append(""); + if (UtilValidate.isNotEmpty(style)) { + writer.append(""); + } + writer.append(text); + if (UtilValidate.isNotEmpty(style)) { + writer.append(""); + } + writer.append(""); + if (UtilValidate.isNotEmpty(rightStyle)) { + writer.append(""); + } + writer.append(rightText); + if (UtilValidate.isNotEmpty(rightStyle)) { + writer.append(""); + } + writer.append("
"); + } + + /** + * Renders a link for the column header fields when there is a header-link="" specified in the tag, using + * style from header-link-style="". Also renders a selectAll checkbox in multi forms. + * @param writer + * @param context + * @param modelFormField + * @param titleText + */ + public void renderHyperlinkTitle(Appendable writer, Map context, ModelFormField modelFormField, String titleText) throws IOException { + if (UtilValidate.isNotEmpty(modelFormField.getHeaderLink())) { + StringBuilder targetBuffer = new StringBuilder(); + FlexibleStringExpander target = FlexibleStringExpander.getInstance(modelFormField.getHeaderLink()); + String fullTarget = target.expandString(context); + targetBuffer.append(fullTarget); + String targetType = CommonWidgetModels.Link.DEFAULT_URL_MODE; + if (UtilValidate.isNotEmpty(targetBuffer.toString()) && targetBuffer.toString().toLowerCase().startsWith("javascript:")) { + targetType="plain"; + } + WidgetWorker.makeHyperlinkString(writer, modelFormField.getHeaderLinkStyle(), targetType, targetBuffer.toString(), null, titleText, null, modelFormField, this.request, this.response, null, null); + } else if (modelFormField.isSortField()) { + renderSortField (writer, context, modelFormField, titleText); + } else if (modelFormField.isRowSubmit()) { + if (UtilValidate.isNotEmpty(titleText)) writer.append(titleText).append("
"); + writer.append(""); + } else { + writer.append(titleText); + } + } + + public void renderContainerFindField(Appendable writer, Map context, ContainerField containerField) throws IOException { + writer.append("
"); + } + + /** Create an ajaxXxxx JavaScript CSV string from a list of UpdateArea objects. See + * selectall.js. + * @param updateAreas + * @param extraParams Renderer-supplied additional target parameters + * @param context + * @return Parameter string or empty string if no UpdateArea objects were found + */ + public String createAjaxParamsFromUpdateAreas(List updateAreas, String extraParams, Map context) { + if (updateAreas == null) { + return ""; + } + StringBuilder ajaxUrl = new StringBuilder(); + boolean firstLoop = true; + for (ModelForm.UpdateArea updateArea : updateAreas) { + if (firstLoop) { + firstLoop = false; + } else { + ajaxUrl.append(","); + } + String targetUrl = updateArea.getAreaTarget(context); + String ajaxParams = getAjaxParamsFromTarget(targetUrl); + if (UtilValidate.isNotEmpty(extraParams)) { + if (ajaxParams.length() > 0 && !extraParams.startsWith("&")) { + ajaxParams += "&"; + } + ajaxParams += extraParams; + } + ajaxUrl.append(updateArea.getAreaId()).append(","); + try { + appendOfbizUrl(ajaxUrl, UtilHttp.removeQueryStringFromTarget(targetUrl)); + } catch (IOException e) { + throw UtilMisc.initCause(new InternalError(e.getMessage()), e); + } + ajaxUrl.append(",").append(ajaxParams); + } + return ajaxUrl.toString(); + } +} diff --git a/framework/widget/src/org/ofbiz/widget/html/HtmlFormWrapper.java b/framework/widget/src/org/ofbiz/widget/renderer/html/HtmlFormWrapper.java similarity index 94% rename from framework/widget/src/org/ofbiz/widget/html/HtmlFormWrapper.java rename to framework/widget/src/org/ofbiz/widget/renderer/html/HtmlFormWrapper.java index 6b36db2b86..3718ea0223 100644 --- a/framework/widget/src/org/ofbiz/widget/html/HtmlFormWrapper.java +++ b/framework/widget/src/org/ofbiz/widget/renderer/html/HtmlFormWrapper.java @@ -1,200 +1,200 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget.html; - -import java.io.IOException; -import java.io.StringWriter; -import java.util.HashMap; -import java.util.Map; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.xml.parsers.ParserConfigurationException; - -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.UtilGenerics; -import org.ofbiz.base.util.UtilHttp; -import org.ofbiz.base.util.UtilValidate; -import org.ofbiz.base.util.collections.MapStack; -import org.ofbiz.entity.Delegator; -import org.ofbiz.service.LocalDispatcher; -import org.ofbiz.widget.form.FormFactory; -import org.ofbiz.widget.form.FormStringRenderer; -import org.ofbiz.widget.form.ModelForm; -import org.ofbiz.widget.form.FormRenderer; - -import org.xml.sax.SAXException; - - -/** - * Widget Library - HTML Form Wrapper class - makes it easy to do the setup and render of a form - */ -public class HtmlFormWrapper { - - public static final String module = HtmlFormWrapper.class.getName(); - - protected String resourceName; - protected String formName; - protected HttpServletRequest request; - protected HttpServletResponse response; - protected ModelForm modelForm; - protected FormStringRenderer renderer; - protected Map context; - - protected HtmlFormWrapper() {} - - public HtmlFormWrapper(String resourceName, String formName, HttpServletRequest request, HttpServletResponse response) - throws IOException, SAXException, ParserConfigurationException { - this.resourceName = resourceName; - this.formName = formName; - this.request = request; - this.response = response; - Delegator delegator = null; - try { - delegator = (Delegator) request.getAttribute("delegator"); - LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher"); - this.modelForm = FormFactory.getFormFromLocation(resourceName, formName, delegator.getModelReader(), dispatcher.getDispatchContext()); - } catch (IllegalArgumentException iae) { - Debug.logWarning("Could not find form with name [" + formName + "] in class resource [" + resourceName + "], will try to load it using relative path syntax.", module); - this.modelForm = FormFactory.getFormFromWebappContext(resourceName, formName, request); - } - - this.renderer = new HtmlFormRenderer(request, response); - - this.context = new HashMap(); - Map parameterMap = UtilHttp.getParameterMap(request); - context.put("parameters", parameterMap); - - //make sure the locale is in the context - context.put("locale", UtilHttp.getLocale(request)); - //make sure the timeZone is in the context - context.put("timeZone", UtilHttp.getTimeZone(request)); - - // if there was an error message, this is an error - if (UtilValidate.isNotEmpty(request.getAttribute("_ERROR_MESSAGE_"))) { - context.put("isError", Boolean.TRUE); - } else { - context.put("isError", Boolean.FALSE); - } - - // if a parameter was passed saying this is an error, it is an error - if ("true".equals(parameterMap.get("isError"))) { - context.put("isError", Boolean.TRUE); - } - - Map uiLabelMap = UtilGenerics.cast(request.getAttribute("uiLabelMap")); - if (UtilValidate.isNotEmpty(uiLabelMap) && context.get("uiLabelMap") == null) { - Debug.logInfo("Got uiLabelMap: " + uiLabelMap, module); - context.put("uiLabelMap", uiLabelMap); - } - if (UtilValidate.isNotEmpty(delegator) && context.get("delegator") == null) { - context.put("delegator", delegator); - } - } - - @SuppressWarnings("unchecked") - public StringWriter renderFormString(Object contextStack) throws Exception { - if (contextStack instanceof MapStack) { - return renderFormString((MapStack) contextStack); - } else { - Debug.logWarning("Call renderFormString with a non-MapStack: " + (contextStack == null ? "null" : contextStack.getClass().getName()), module); - return renderFormString(); - } - } - public StringWriter renderFormString(MapStack contextStack) throws Exception { - // create a new context with the current context on the bottom - contextStack.push(this.context); - StringWriter buffer = new StringWriter(); - FormRenderer formRenderer = new FormRenderer(modelForm, renderer); - formRenderer.render(buffer, contextStack); - contextStack.pop(); - return buffer; - } - public StringWriter renderFormString() throws Exception { - StringWriter buffer = new StringWriter(); - FormRenderer formRenderer = new FormRenderer(modelForm, renderer); - formRenderer.render(buffer, context); - return buffer; - } - - /** - * Tells the form library whether this is a response to an error or not. - * Defaults on initialization according to the presense of an errorMessage - * in the request or if an isError parameter was passed to the page with - * the value "true". If true then the prefilled values will come from the - * parameters Map instead of the value Map. - */ - public void setIsError(boolean isError) { - this.context.put("isError", Boolean.valueOf(isError)); - } - - public boolean getIsError() { - Boolean isErrorBoolean = (Boolean) this.context.get("isError"); - if (isErrorBoolean == null) { - return false; - } else { - return isErrorBoolean.booleanValue(); - } - } - - /** - * The "useRequestParameters" value in the form context tells the form library - * to use the request parameters to fill in values instead of the value map. - * This is generally used when it is an empty form to pre-set inital values. - * This is automatically set to false for list and multi forms. For related - * functionality see the setIsError method. - * - * @param useRequestParameters - */ - public void setUseRequestParameters(boolean useRequestParameters) { - this.context.put("useRequestParameters", Boolean.valueOf(useRequestParameters)); - } - - public boolean getUseRequestParameters() { - Boolean useRequestParametersBoolean = (Boolean) this.context.get("useRequestParameters"); - if (useRequestParametersBoolean == null) { - return false; - } else { - return useRequestParametersBoolean.booleanValue(); - } - } - - public void setFormOverrideName(String formName) { - this.context.put("formName", formName); - } - - public void putInContext(String name, Object value) { - this.context.put(name, value); - } - - public Object getFromContext(String name) { - return this.context.get(name); - } - - public ModelForm getModelForm() { - return modelForm; - } - - public FormStringRenderer getRenderer() { - return renderer; - } - - public void setRenderer(FormStringRenderer renderer) { - this.renderer = renderer; - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.renderer.html; + +import java.io.IOException; +import java.io.StringWriter; +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.xml.parsers.ParserConfigurationException; + +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilGenerics; +import org.ofbiz.base.util.UtilHttp; +import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.base.util.collections.MapStack; +import org.ofbiz.entity.Delegator; +import org.ofbiz.service.LocalDispatcher; +import org.ofbiz.widget.model.FormFactory; +import org.ofbiz.widget.model.ModelForm; +import org.ofbiz.widget.renderer.FormRenderer; +import org.ofbiz.widget.renderer.FormStringRenderer; +import org.xml.sax.SAXException; + + +/** + * Widget Library - HTML Form Wrapper class - makes it easy to do the setup and render of a form + */ +public class HtmlFormWrapper { + + public static final String module = HtmlFormWrapper.class.getName(); + + protected String resourceName; + protected String formName; + protected HttpServletRequest request; + protected HttpServletResponse response; + protected ModelForm modelForm; + protected FormStringRenderer renderer; + protected Map context; + + protected HtmlFormWrapper() {} + + public HtmlFormWrapper(String resourceName, String formName, HttpServletRequest request, HttpServletResponse response) + throws IOException, SAXException, ParserConfigurationException { + this.resourceName = resourceName; + this.formName = formName; + this.request = request; + this.response = response; + Delegator delegator = null; + try { + delegator = (Delegator) request.getAttribute("delegator"); + LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher"); + this.modelForm = FormFactory.getFormFromLocation(resourceName, formName, delegator.getModelReader(), dispatcher.getDispatchContext()); + } catch (IllegalArgumentException iae) { + Debug.logWarning("Could not find form with name [" + formName + "] in class resource [" + resourceName + "], will try to load it using relative path syntax.", module); + this.modelForm = FormFactory.getFormFromWebappContext(resourceName, formName, request); + } + + this.renderer = new HtmlFormRenderer(request, response); + + this.context = new HashMap(); + Map parameterMap = UtilHttp.getParameterMap(request); + context.put("parameters", parameterMap); + + //make sure the locale is in the context + context.put("locale", UtilHttp.getLocale(request)); + //make sure the timeZone is in the context + context.put("timeZone", UtilHttp.getTimeZone(request)); + + // if there was an error message, this is an error + if (UtilValidate.isNotEmpty(request.getAttribute("_ERROR_MESSAGE_"))) { + context.put("isError", Boolean.TRUE); + } else { + context.put("isError", Boolean.FALSE); + } + + // if a parameter was passed saying this is an error, it is an error + if ("true".equals(parameterMap.get("isError"))) { + context.put("isError", Boolean.TRUE); + } + + Map uiLabelMap = UtilGenerics.cast(request.getAttribute("uiLabelMap")); + if (UtilValidate.isNotEmpty(uiLabelMap) && context.get("uiLabelMap") == null) { + Debug.logInfo("Got uiLabelMap: " + uiLabelMap, module); + context.put("uiLabelMap", uiLabelMap); + } + if (UtilValidate.isNotEmpty(delegator) && context.get("delegator") == null) { + context.put("delegator", delegator); + } + } + + @SuppressWarnings("unchecked") + public StringWriter renderFormString(Object contextStack) throws Exception { + if (contextStack instanceof MapStack) { + return renderFormString((MapStack) contextStack); + } else { + Debug.logWarning("Call renderFormString with a non-MapStack: " + (contextStack == null ? "null" : contextStack.getClass().getName()), module); + return renderFormString(); + } + } + public StringWriter renderFormString(MapStack contextStack) throws Exception { + // create a new context with the current context on the bottom + contextStack.push(this.context); + StringWriter buffer = new StringWriter(); + FormRenderer formRenderer = new FormRenderer(modelForm, renderer); + formRenderer.render(buffer, contextStack); + contextStack.pop(); + return buffer; + } + public StringWriter renderFormString() throws Exception { + StringWriter buffer = new StringWriter(); + FormRenderer formRenderer = new FormRenderer(modelForm, renderer); + formRenderer.render(buffer, context); + return buffer; + } + + /** + * Tells the form library whether this is a response to an error or not. + * Defaults on initialization according to the presense of an errorMessage + * in the request or if an isError parameter was passed to the page with + * the value "true". If true then the prefilled values will come from the + * parameters Map instead of the value Map. + */ + public void setIsError(boolean isError) { + this.context.put("isError", Boolean.valueOf(isError)); + } + + public boolean getIsError() { + Boolean isErrorBoolean = (Boolean) this.context.get("isError"); + if (isErrorBoolean == null) { + return false; + } else { + return isErrorBoolean.booleanValue(); + } + } + + /** + * The "useRequestParameters" value in the form context tells the form library + * to use the request parameters to fill in values instead of the value map. + * This is generally used when it is an empty form to pre-set inital values. + * This is automatically set to false for list and multi forms. For related + * functionality see the setIsError method. + * + * @param useRequestParameters + */ + public void setUseRequestParameters(boolean useRequestParameters) { + this.context.put("useRequestParameters", Boolean.valueOf(useRequestParameters)); + } + + public boolean getUseRequestParameters() { + Boolean useRequestParametersBoolean = (Boolean) this.context.get("useRequestParameters"); + if (useRequestParametersBoolean == null) { + return false; + } else { + return useRequestParametersBoolean.booleanValue(); + } + } + + public void setFormOverrideName(String formName) { + this.context.put("formName", formName); + } + + public void putInContext(String name, Object value) { + this.context.put(name, value); + } + + public Object getFromContext(String name) { + return this.context.get(name); + } + + public ModelForm getModelForm() { + return modelForm; + } + + public FormStringRenderer getRenderer() { + return renderer; + } + + public void setRenderer(FormStringRenderer renderer) { + this.renderer = renderer; + } +} diff --git a/framework/widget/src/org/ofbiz/widget/html/HtmlMenuRenderer.java b/framework/widget/src/org/ofbiz/widget/renderer/html/HtmlMenuRenderer.java similarity index 96% rename from framework/widget/src/org/ofbiz/widget/html/HtmlMenuRenderer.java rename to framework/widget/src/org/ofbiz/widget/renderer/html/HtmlMenuRenderer.java index 77b36c178a..15531a3302 100644 --- a/framework/widget/src/org/ofbiz/widget/html/HtmlMenuRenderer.java +++ b/framework/widget/src/org/ofbiz/widget/renderer/html/HtmlMenuRenderer.java @@ -1,592 +1,592 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget.html; - -import java.io.IOException; -import java.math.BigDecimal; -import java.util.List; -import java.util.Map; - -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; - -import org.ofbiz.base.util.StringUtil; -import org.ofbiz.base.util.UtilCodec; -import org.ofbiz.base.util.UtilMisc; -import org.ofbiz.base.util.UtilValidate; -import org.ofbiz.entity.Delegator; -import org.ofbiz.entity.GenericValue; -import org.ofbiz.webapp.control.RequestHandler; -import org.ofbiz.webapp.taglib.ContentUrlTag; -import org.ofbiz.widget.ModelWidget; -import org.ofbiz.widget.WidgetWorker; -import org.ofbiz.widget.menu.MenuStringRenderer; -import org.ofbiz.widget.menu.ModelMenu; -import org.ofbiz.widget.menu.ModelMenuItem; -import org.ofbiz.widget.CommonWidgetModels.*; -import org.ofbiz.widget.menu.ModelMenuItem.MenuLink; - -/** - * Widget Library - HTML Menu Renderer implementation - */ -public class HtmlMenuRenderer extends HtmlWidgetRenderer implements MenuStringRenderer { - - HttpServletRequest request; - HttpServletResponse response; - protected String userLoginIdAtPermGrant; - protected String permissionErrorMessage = ""; - - public static final String module = HtmlMenuRenderer.class.getName(); - - protected HtmlMenuRenderer() {} - - public HtmlMenuRenderer(HttpServletRequest request, HttpServletResponse response) { - this.request = request; - this.response = response; - } - - public void appendOfbizUrl(Appendable writer, String location) throws IOException { - ServletContext ctx = (ServletContext) request.getAttribute("servletContext"); - if (ctx == null) { - //if (Debug.infoOn()) Debug.logInfo("in appendOfbizUrl, ctx is null(0): buffer=" + buffer.toString() + " location:" + location, ""); - HttpSession session = request.getSession(); - if (session != null) { - ctx = session.getServletContext(); - } else { - //if (Debug.infoOn()) Debug.logInfo("in appendOfbizUrl, session is null(1)", ""); - } - if (ctx == null) { - throw new RuntimeException("ctx is null. location:" + location); - } - //if (Debug.infoOn()) Debug.logInfo("in appendOfbizUrl, ctx is NOT null(2)", ""); - } - Delegator delegator = (Delegator)request.getAttribute("delegator"); - if (delegator == null) { - //if (Debug.infoOn()) Debug.logInfo("in appendOfbizUrl, delegator is null(5)", ""); - } - RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_"); - // make and append the link - String s = rh.makeLink(this.request, this.response, location); - if (s.indexOf("null") >= 0) { - //if (Debug.infoOn()) Debug.logInfo("in appendOfbizUrl(3), url: " + s, ""); - } - writer.append(s); - } - - public void appendContentUrl(Appendable writer, String location) throws IOException { - ServletContext ctx = (ServletContext) this.request.getAttribute("servletContext"); - if (ctx == null) { - //if (Debug.infoOn()) Debug.logInfo("in appendContentUrl, ctx is null(0): buffer=" + buffer.toString() + " location:" + location, ""); - HttpSession session = request.getSession(); - if (session != null) { - ctx = session.getServletContext(); - } else { - //if (Debug.infoOn()) Debug.logInfo("in appendContentUrl, session is null(1)", ""); - } - if (ctx == null) { - throw new RuntimeException("ctx is null. location:" + location); - } - //if (Debug.infoOn()) Debug.logInfo("in appendContentUrl, ctx is NOT null(2)", ""); - this.request.setAttribute("servletContext", ctx); - } - Delegator delegator = (Delegator) request.getAttribute("delegator"); - if (delegator == null) { - //if (Debug.infoOn()) Debug.logInfo("in appendContentUrl, delegator is null(6)", ""); - } - StringBuilder buffer = new StringBuilder(); - ContentUrlTag.appendContentPrefix(this.request, buffer); - writer.append(buffer.toString()); - writer.append(location); - } - - public void appendTooltip(Appendable writer, Map context, ModelMenuItem modelMenuItem) throws IOException { - // render the tooltip - String tooltip = modelMenuItem.getTooltip(context); - if (UtilValidate.isNotEmpty(tooltip)) { - writer.append(""); - } - } - - public void renderFormatSimpleWrapperRows(Appendable writer, Map context, Object menuObj) throws IOException { - List menuItemList = ((ModelMenu) menuObj).getMenuItemList(); - for (ModelMenuItem currentMenuItem: menuItemList) { - renderMenuItem(writer, context, currentMenuItem); - } - } - - public void renderMenuItem(Appendable writer, Map context, ModelMenuItem menuItem) throws IOException { - - //Debug.logInfo("in renderMenuItem, menuItem:" + menuItem.getName() + " context:" + context ,""); - boolean hideThisItem = isHideIfSelected(menuItem, context); - //if (Debug.infoOn()) Debug.logInfo("in HtmlMenuRendererImage, hideThisItem:" + hideThisItem,""); - if (hideThisItem) - return; - - String style = menuItem.getWidgetStyle(); - - if (menuItem.isSelected(context)) { - style = menuItem.getSelectedStyle(); - if (UtilValidate.isEmpty(style)) { - style = "selected"; - } - } - - if (this.isDisableIfEmpty(menuItem, context)) { - style = menuItem.getDisabledTitleStyle(); - } - - writer.append(" "); - - MenuLink link = menuItem.getLink(); - //if (Debug.infoOn()) Debug.logInfo("in HtmlMenuRendererImage, link(0):" + link,""); - if (link != null) { - renderLink(writer, context, link); - } else { - String txt = menuItem.getTitle(context); - UtilCodec.SimpleEncoder simpleEncoder = (UtilCodec.SimpleEncoder) context.get("simpleEncoder"); - if (simpleEncoder != null) { - txt = simpleEncoder.encode(txt); - } - writer.append(txt); - - } - if (!menuItem.getMenuItemList().isEmpty()) { - appendWhitespace(writer); - writer.append("
    "); - appendWhitespace(writer); - for (ModelMenuItem childMenuItem : menuItem.getMenuItemList()) { - childMenuItem.renderMenuItemString(writer, context, this); - } - writer.append("
"); - appendWhitespace(writer); - } - - writer.append(""); - - appendWhitespace(writer); - } - - public boolean isDisableIfEmpty(ModelMenuItem menuItem, Map context) { - boolean disabled = false; - String disableIfEmpty = menuItem.getDisableIfEmpty(); - if (UtilValidate.isNotEmpty(disableIfEmpty)) { - List keys = StringUtil.split(disableIfEmpty, "|"); - for (String key: keys) { - Object obj = context.get(key); - if (obj == null) { - disabled = true; - break; - } - } - } - return disabled; - } - -/* - public String buildDivStr(ModelMenuItem menuItem, Map context) { - String divStr = ""; - divStr = menuItem.getTitle(context); - return divStr; - } -*/ - public void renderMenuOpen(Appendable writer, Map context, ModelMenu modelMenu) throws IOException { - - //Debug.logInfo("in HtmlMenuRenderer, userLoginIdHasChanged:" + userLoginIdHasChanged,""); - this.widgetCommentsEnabled = ModelWidget.widgetBoundaryCommentsEnabled(context); - renderBeginningBoundaryComment(writer, "Menu Widget", modelMenu); - writer.append(""); - appendWhitespace(writer); - String menuTitle = modelMenu.getTitle(context); - if (UtilValidate.isNotEmpty(menuTitle)) { - writer.append("

").append(menuTitle).append("

"); - appendWhitespace(writer); - } - if (modelMenu.renderedMenuItemCount(context) > 0) { - writer.append("
    "); - appendWhitespace(writer); - writer.append("
  • "); - appendWhitespace(writer); - writer.append("
      "); - appendWhitespace(writer); - } - } - - /* (non-Javadoc) - * @see org.ofbiz.widget.menu.MenuStringRenderer#renderMenuClose(java.io.Writer, java.util.Map, org.ofbiz.widget.menu.ModelMenu) - */ - public void renderMenuClose(Appendable writer, Map context, ModelMenu modelMenu) throws IOException { - // TODO: div can't be directly inside an UL - String fillStyle = modelMenu.getFillStyle(); - if (UtilValidate.isNotEmpty(fillStyle)) { - writer.append("
       
      "); - } - //String menuContainerStyle = modelMenu.getMenuContainerStyle(context); - if (modelMenu.renderedMenuItemCount(context) > 0) { - writer.append("
    "); - appendWhitespace(writer); - writer.append("
  • "); - appendWhitespace(writer); - writer.append("
"); - appendWhitespace(writer); - } - writer.append("
"); - appendWhitespace(writer); - writer.append("
"); - appendWhitespace(writer); - renderEndingBoundaryComment(writer, "Menu Widget", modelMenu); - - GenericValue userLogin = (GenericValue)request.getSession().getAttribute("userLogin"); - if (userLogin != null) { - String userLoginId = userLogin.getString("userLoginId"); - //request.getSession().setAttribute("userLoginIdAtPermGrant", userLoginId); - setUserLoginIdAtPermGrant(userLoginId); - //Debug.logInfo("in HtmlMenuRenderer, userLoginId(Close):" + userLoginId + " userLoginIdAtPermGrant:" + request.getSession().getAttribute("userLoginIdAtPermGrant"),""); - } else { - request.getSession().setAttribute("userLoginIdAtPermGrant", null); - } - } - - public void renderFormatSimpleWrapperOpen(Appendable writer, Map context, ModelMenu modelMenu) throws IOException { - //appendWhitespace(writer); - } - - public void renderFormatSimpleWrapperClose(Appendable writer, Map context, ModelMenu modelMenu) throws IOException { - //appendWhitespace(writer); - } - - public void setRequest(HttpServletRequest request) { - this.request = request; - } - - public void setResponse(HttpServletResponse response) { - this.response = response; - } - - - /** - * @param string - */ - public void setUserLoginIdAtPermGrant(String string) { - //Debug.logInfo("in HtmlMenuRenderer, userLoginIdAtPermGrant(setUserLoginIdAtPermGrant):" + string,""); - this.userLoginIdAtPermGrant = string; - } - - public String getUserLoginIdAtPermGrant() { - return this.userLoginIdAtPermGrant; - } - - public boolean isHideIfSelected(ModelMenuItem menuItem, Map context) { - ModelMenu menu = menuItem.getModelMenu(); - String currentMenuItemName = menu.getSelectedMenuItemContextFieldName(context); - String currentItemName = menuItem.getName(); - Boolean hideIfSelected = menuItem.getHideIfSelected(); - //Debug.logInfo("in HtmlMenuRenderer, currentMenuItemName:" + currentMenuItemName + " currentItemName:" + currentItemName + " hideIfSelected:" + hideIfSelected,""); - return (hideIfSelected != null && hideIfSelected.booleanValue() && currentMenuItemName != null && currentMenuItemName.equals(currentItemName)); - } - - - public boolean userLoginIdHasChanged() { - boolean hasChanged = false; - GenericValue userLogin = (GenericValue)request.getSession().getAttribute("userLogin"); - userLoginIdAtPermGrant = getUserLoginIdAtPermGrant(); - //userLoginIdAtPermGrant = (String)request.getSession().getAttribute("userLoginIdAtPermGrant"); - String userLoginId = null; - if (userLogin != null) - userLoginId = userLogin.getString("userLoginId"); - //Debug.logInfo("in HtmlMenuRenderer, userLoginId:" + userLoginId + " userLoginIdAtPermGrant:" + userLoginIdAtPermGrant ,""); - if ((userLoginId == null && userLoginIdAtPermGrant != null) - || (userLoginId != null && userLoginIdAtPermGrant == null) - || ((userLoginId != null && userLoginIdAtPermGrant != null) - && !userLoginId.equals(userLoginIdAtPermGrant))) { - hasChanged = true; - } else { - if (userLoginIdAtPermGrant != null) - hasChanged = true; - else - hasChanged = false; - - userLoginIdAtPermGrant = null; - } - return hasChanged; - } - - public String getTitle(ModelMenuItem menuItem, Map context) { - String title = null; - title = menuItem.getTitle(context); - return title; - } - - public void renderLink(Appendable writer, Map context, ModelMenuItem.MenuLink link) throws IOException { - String target = link.getTarget(context); - ModelMenuItem menuItem = link.getLinkMenuItem(); - if (isDisableIfEmpty(menuItem, context)) { - target = null; - } - - if (UtilValidate.isNotEmpty(target)) { - HttpServletResponse response = (HttpServletResponse) context.get("response"); - HttpServletRequest request = (HttpServletRequest) context.get("request"); - - String targetWindow = link.getTargetWindow(context); - String uniqueItemName = menuItem.getModelMenu().getName() + "_" + menuItem.getName() + "_LF_" + UtilMisc.addToBigDecimalInMap(context, "menuUniqueItemIndex", BigDecimal.ONE); - - String linkType = WidgetWorker.determineAutoLinkType(link.getLinkType(), target, link.getUrlMode(), request); - if ("hidden-form".equals(linkType)) { - writer.append("
"); - - UtilCodec.SimpleEncoder simpleEncoder = (UtilCodec.SimpleEncoder) context.get("simpleEncoder"); - for (Map.Entry parameter: link.getParameterMap(context).entrySet()) { - writer.append(""); - } - - writer.append(""); - } - - writer.append(""); - } - - // the text - Image img = link.getImage(); - if (img != null) { - renderImage(writer, context, img); - writer.append(" " + link.getText(context)); - } else { - writer.append(link.getText(context)); - } - - if (UtilValidate.isNotEmpty(target)) { - // close tag - writer.append(""); - } - - /* NOTE DEJ20090316: This was here as a comment and not sure what it is for or if it is useful... can probably be safely removed in the future if still not used/needed - boolean isSelected = menuItem.isSelected(context); - - String style = null; - - if (isSelected) { - style = menuItem.getSelectedStyle(); - } else { - style = link.getStyle(context); - if (UtilValidate.isEmpty(style)) - style = menuItem.getTitleStyle(); - if (UtilValidate.isEmpty(style)) - style = menuItem.getWidgetStyle(); - } - - if (menuItem.getDisabled()) { - style = menuItem.getDisabledTitleStyle(); - } - - if (UtilValidate.isNotEmpty(style)) { - writer.append(" class=\""); - writer.append(style); - writer.append("\""); - } - */ - } - - public void renderImage(Appendable writer, Map context, Image image) throws IOException { - // open tag - writer.append(""); - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.renderer.html; + +import java.io.IOException; +import java.math.BigDecimal; +import java.util.List; +import java.util.Map; + +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.ofbiz.base.util.StringUtil; +import org.ofbiz.base.util.UtilCodec; +import org.ofbiz.base.util.UtilMisc; +import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.entity.Delegator; +import org.ofbiz.entity.GenericValue; +import org.ofbiz.webapp.control.RequestHandler; +import org.ofbiz.webapp.taglib.ContentUrlTag; +import org.ofbiz.widget.WidgetWorker; +import org.ofbiz.widget.model.CommonWidgetModels.Image; +import org.ofbiz.widget.model.ModelMenu; +import org.ofbiz.widget.model.ModelMenuItem; +import org.ofbiz.widget.model.ModelMenuItem.MenuLink; +import org.ofbiz.widget.model.ModelWidget; +import org.ofbiz.widget.renderer.MenuStringRenderer; + +/** + * Widget Library - HTML Menu Renderer implementation + */ +public class HtmlMenuRenderer extends HtmlWidgetRenderer implements MenuStringRenderer { + + HttpServletRequest request; + HttpServletResponse response; + protected String userLoginIdAtPermGrant; + protected String permissionErrorMessage = ""; + + public static final String module = HtmlMenuRenderer.class.getName(); + + protected HtmlMenuRenderer() {} + + public HtmlMenuRenderer(HttpServletRequest request, HttpServletResponse response) { + this.request = request; + this.response = response; + } + + public void appendOfbizUrl(Appendable writer, String location) throws IOException { + ServletContext ctx = (ServletContext) request.getAttribute("servletContext"); + if (ctx == null) { + //if (Debug.infoOn()) Debug.logInfo("in appendOfbizUrl, ctx is null(0): buffer=" + buffer.toString() + " location:" + location, ""); + HttpSession session = request.getSession(); + if (session != null) { + ctx = session.getServletContext(); + } else { + //if (Debug.infoOn()) Debug.logInfo("in appendOfbizUrl, session is null(1)", ""); + } + if (ctx == null) { + throw new RuntimeException("ctx is null. location:" + location); + } + //if (Debug.infoOn()) Debug.logInfo("in appendOfbizUrl, ctx is NOT null(2)", ""); + } + Delegator delegator = (Delegator)request.getAttribute("delegator"); + if (delegator == null) { + //if (Debug.infoOn()) Debug.logInfo("in appendOfbizUrl, delegator is null(5)", ""); + } + RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_"); + // make and append the link + String s = rh.makeLink(this.request, this.response, location); + if (s.indexOf("null") >= 0) { + //if (Debug.infoOn()) Debug.logInfo("in appendOfbizUrl(3), url: " + s, ""); + } + writer.append(s); + } + + public void appendContentUrl(Appendable writer, String location) throws IOException { + ServletContext ctx = (ServletContext) this.request.getAttribute("servletContext"); + if (ctx == null) { + //if (Debug.infoOn()) Debug.logInfo("in appendContentUrl, ctx is null(0): buffer=" + buffer.toString() + " location:" + location, ""); + HttpSession session = request.getSession(); + if (session != null) { + ctx = session.getServletContext(); + } else { + //if (Debug.infoOn()) Debug.logInfo("in appendContentUrl, session is null(1)", ""); + } + if (ctx == null) { + throw new RuntimeException("ctx is null. location:" + location); + } + //if (Debug.infoOn()) Debug.logInfo("in appendContentUrl, ctx is NOT null(2)", ""); + this.request.setAttribute("servletContext", ctx); + } + Delegator delegator = (Delegator) request.getAttribute("delegator"); + if (delegator == null) { + //if (Debug.infoOn()) Debug.logInfo("in appendContentUrl, delegator is null(6)", ""); + } + StringBuilder buffer = new StringBuilder(); + ContentUrlTag.appendContentPrefix(this.request, buffer); + writer.append(buffer.toString()); + writer.append(location); + } + + public void appendTooltip(Appendable writer, Map context, ModelMenuItem modelMenuItem) throws IOException { + // render the tooltip + String tooltip = modelMenuItem.getTooltip(context); + if (UtilValidate.isNotEmpty(tooltip)) { + writer.append(""); + } + } + + public void renderFormatSimpleWrapperRows(Appendable writer, Map context, Object menuObj) throws IOException { + List menuItemList = ((ModelMenu) menuObj).getMenuItemList(); + for (ModelMenuItem currentMenuItem: menuItemList) { + renderMenuItem(writer, context, currentMenuItem); + } + } + + public void renderMenuItem(Appendable writer, Map context, ModelMenuItem menuItem) throws IOException { + + //Debug.logInfo("in renderMenuItem, menuItem:" + menuItem.getName() + " context:" + context ,""); + boolean hideThisItem = isHideIfSelected(menuItem, context); + //if (Debug.infoOn()) Debug.logInfo("in HtmlMenuRendererImage, hideThisItem:" + hideThisItem,""); + if (hideThisItem) + return; + + String style = menuItem.getWidgetStyle(); + + if (menuItem.isSelected(context)) { + style = menuItem.getSelectedStyle(); + if (UtilValidate.isEmpty(style)) { + style = "selected"; + } + } + + if (this.isDisableIfEmpty(menuItem, context)) { + style = menuItem.getDisabledTitleStyle(); + } + + writer.append(" "); + + MenuLink link = menuItem.getLink(); + //if (Debug.infoOn()) Debug.logInfo("in HtmlMenuRendererImage, link(0):" + link,""); + if (link != null) { + renderLink(writer, context, link); + } else { + String txt = menuItem.getTitle(context); + UtilCodec.SimpleEncoder simpleEncoder = (UtilCodec.SimpleEncoder) context.get("simpleEncoder"); + if (simpleEncoder != null) { + txt = simpleEncoder.encode(txt); + } + writer.append(txt); + + } + if (!menuItem.getMenuItemList().isEmpty()) { + appendWhitespace(writer); + writer.append("
    "); + appendWhitespace(writer); + for (ModelMenuItem childMenuItem : menuItem.getMenuItemList()) { + childMenuItem.renderMenuItemString(writer, context, this); + } + writer.append("
"); + appendWhitespace(writer); + } + + writer.append(""); + + appendWhitespace(writer); + } + + public boolean isDisableIfEmpty(ModelMenuItem menuItem, Map context) { + boolean disabled = false; + String disableIfEmpty = menuItem.getDisableIfEmpty(); + if (UtilValidate.isNotEmpty(disableIfEmpty)) { + List keys = StringUtil.split(disableIfEmpty, "|"); + for (String key: keys) { + Object obj = context.get(key); + if (obj == null) { + disabled = true; + break; + } + } + } + return disabled; + } + +/* + public String buildDivStr(ModelMenuItem menuItem, Map context) { + String divStr = ""; + divStr = menuItem.getTitle(context); + return divStr; + } +*/ + public void renderMenuOpen(Appendable writer, Map context, ModelMenu modelMenu) throws IOException { + + //Debug.logInfo("in HtmlMenuRenderer, userLoginIdHasChanged:" + userLoginIdHasChanged,""); + this.widgetCommentsEnabled = ModelWidget.widgetBoundaryCommentsEnabled(context); + renderBeginningBoundaryComment(writer, "Menu Widget", modelMenu); + writer.append(""); + appendWhitespace(writer); + String menuTitle = modelMenu.getTitle(context); + if (UtilValidate.isNotEmpty(menuTitle)) { + writer.append("

").append(menuTitle).append("

"); + appendWhitespace(writer); + } + if (modelMenu.renderedMenuItemCount(context) > 0) { + writer.append("
    "); + appendWhitespace(writer); + writer.append("
  • "); + appendWhitespace(writer); + writer.append("
      "); + appendWhitespace(writer); + } + } + + /* (non-Javadoc) + * @see org.ofbiz.widget.menu.MenuStringRenderer#renderMenuClose(java.io.Writer, java.util.Map, org.ofbiz.widget.menu.ModelMenu) + */ + public void renderMenuClose(Appendable writer, Map context, ModelMenu modelMenu) throws IOException { + // TODO: div can't be directly inside an UL + String fillStyle = modelMenu.getFillStyle(); + if (UtilValidate.isNotEmpty(fillStyle)) { + writer.append("
       
      "); + } + //String menuContainerStyle = modelMenu.getMenuContainerStyle(context); + if (modelMenu.renderedMenuItemCount(context) > 0) { + writer.append("
    "); + appendWhitespace(writer); + writer.append("
  • "); + appendWhitespace(writer); + writer.append("
"); + appendWhitespace(writer); + } + writer.append("
"); + appendWhitespace(writer); + writer.append("
"); + appendWhitespace(writer); + renderEndingBoundaryComment(writer, "Menu Widget", modelMenu); + + GenericValue userLogin = (GenericValue)request.getSession().getAttribute("userLogin"); + if (userLogin != null) { + String userLoginId = userLogin.getString("userLoginId"); + //request.getSession().setAttribute("userLoginIdAtPermGrant", userLoginId); + setUserLoginIdAtPermGrant(userLoginId); + //Debug.logInfo("in HtmlMenuRenderer, userLoginId(Close):" + userLoginId + " userLoginIdAtPermGrant:" + request.getSession().getAttribute("userLoginIdAtPermGrant"),""); + } else { + request.getSession().setAttribute("userLoginIdAtPermGrant", null); + } + } + + public void renderFormatSimpleWrapperOpen(Appendable writer, Map context, ModelMenu modelMenu) throws IOException { + //appendWhitespace(writer); + } + + public void renderFormatSimpleWrapperClose(Appendable writer, Map context, ModelMenu modelMenu) throws IOException { + //appendWhitespace(writer); + } + + public void setRequest(HttpServletRequest request) { + this.request = request; + } + + public void setResponse(HttpServletResponse response) { + this.response = response; + } + + + /** + * @param string + */ + public void setUserLoginIdAtPermGrant(String string) { + //Debug.logInfo("in HtmlMenuRenderer, userLoginIdAtPermGrant(setUserLoginIdAtPermGrant):" + string,""); + this.userLoginIdAtPermGrant = string; + } + + public String getUserLoginIdAtPermGrant() { + return this.userLoginIdAtPermGrant; + } + + public boolean isHideIfSelected(ModelMenuItem menuItem, Map context) { + ModelMenu menu = menuItem.getModelMenu(); + String currentMenuItemName = menu.getSelectedMenuItemContextFieldName(context); + String currentItemName = menuItem.getName(); + Boolean hideIfSelected = menuItem.getHideIfSelected(); + //Debug.logInfo("in HtmlMenuRenderer, currentMenuItemName:" + currentMenuItemName + " currentItemName:" + currentItemName + " hideIfSelected:" + hideIfSelected,""); + return (hideIfSelected != null && hideIfSelected.booleanValue() && currentMenuItemName != null && currentMenuItemName.equals(currentItemName)); + } + + + public boolean userLoginIdHasChanged() { + boolean hasChanged = false; + GenericValue userLogin = (GenericValue)request.getSession().getAttribute("userLogin"); + userLoginIdAtPermGrant = getUserLoginIdAtPermGrant(); + //userLoginIdAtPermGrant = (String)request.getSession().getAttribute("userLoginIdAtPermGrant"); + String userLoginId = null; + if (userLogin != null) + userLoginId = userLogin.getString("userLoginId"); + //Debug.logInfo("in HtmlMenuRenderer, userLoginId:" + userLoginId + " userLoginIdAtPermGrant:" + userLoginIdAtPermGrant ,""); + if ((userLoginId == null && userLoginIdAtPermGrant != null) + || (userLoginId != null && userLoginIdAtPermGrant == null) + || ((userLoginId != null && userLoginIdAtPermGrant != null) + && !userLoginId.equals(userLoginIdAtPermGrant))) { + hasChanged = true; + } else { + if (userLoginIdAtPermGrant != null) + hasChanged = true; + else + hasChanged = false; + + userLoginIdAtPermGrant = null; + } + return hasChanged; + } + + public String getTitle(ModelMenuItem menuItem, Map context) { + String title = null; + title = menuItem.getTitle(context); + return title; + } + + public void renderLink(Appendable writer, Map context, ModelMenuItem.MenuLink link) throws IOException { + String target = link.getTarget(context); + ModelMenuItem menuItem = link.getLinkMenuItem(); + if (isDisableIfEmpty(menuItem, context)) { + target = null; + } + + if (UtilValidate.isNotEmpty(target)) { + HttpServletResponse response = (HttpServletResponse) context.get("response"); + HttpServletRequest request = (HttpServletRequest) context.get("request"); + + String targetWindow = link.getTargetWindow(context); + String uniqueItemName = menuItem.getModelMenu().getName() + "_" + menuItem.getName() + "_LF_" + UtilMisc.addToBigDecimalInMap(context, "menuUniqueItemIndex", BigDecimal.ONE); + + String linkType = WidgetWorker.determineAutoLinkType(link.getLinkType(), target, link.getUrlMode(), request); + if ("hidden-form".equals(linkType)) { + writer.append("
"); + + UtilCodec.SimpleEncoder simpleEncoder = (UtilCodec.SimpleEncoder) context.get("simpleEncoder"); + for (Map.Entry parameter: link.getParameterMap(context).entrySet()) { + writer.append(""); + } + + writer.append(""); + } + + writer.append(""); + } + + // the text + Image img = link.getImage(); + if (img != null) { + renderImage(writer, context, img); + writer.append(" " + link.getText(context)); + } else { + writer.append(link.getText(context)); + } + + if (UtilValidate.isNotEmpty(target)) { + // close tag + writer.append(""); + } + + /* NOTE DEJ20090316: This was here as a comment and not sure what it is for or if it is useful... can probably be safely removed in the future if still not used/needed + boolean isSelected = menuItem.isSelected(context); + + String style = null; + + if (isSelected) { + style = menuItem.getSelectedStyle(); + } else { + style = link.getStyle(context); + if (UtilValidate.isEmpty(style)) + style = menuItem.getTitleStyle(); + if (UtilValidate.isEmpty(style)) + style = menuItem.getWidgetStyle(); + } + + if (menuItem.getDisabled()) { + style = menuItem.getDisabledTitleStyle(); + } + + if (UtilValidate.isNotEmpty(style)) { + writer.append(" class=\""); + writer.append(style); + writer.append("\""); + } + */ + } + + public void renderImage(Appendable writer, Map context, Image image) throws IOException { + // open tag + writer.append(""); + } +} diff --git a/framework/widget/src/org/ofbiz/widget/html/HtmlMenuRendererImage.java b/framework/widget/src/org/ofbiz/widget/renderer/html/HtmlMenuRendererImage.java similarity index 93% rename from framework/widget/src/org/ofbiz/widget/html/HtmlMenuRendererImage.java rename to framework/widget/src/org/ofbiz/widget/renderer/html/HtmlMenuRendererImage.java index e521b905b5..d0a51c65b4 100644 --- a/framework/widget/src/org/ofbiz/widget/html/HtmlMenuRendererImage.java +++ b/framework/widget/src/org/ofbiz/widget/renderer/html/HtmlMenuRendererImage.java @@ -1,80 +1,80 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget.html; - -import java.io.IOException; -import java.io.StringWriter; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.UtilValidate; -import org.ofbiz.entity.Delegator; -import org.ofbiz.entity.GenericEntityException; -import org.ofbiz.entity.GenericValue; -import org.ofbiz.widget.WidgetContentWorker; -import org.ofbiz.widget.menu.ModelMenuItem; - -/** - * Widget Library - HTML Menu Renderer implementation - */ - -public class HtmlMenuRendererImage extends HtmlMenuRenderer { - - protected HtmlMenuRendererImage() {} - - public HtmlMenuRendererImage(HttpServletRequest request, HttpServletResponse response) { - super(request, response); - } - - - public String buildDivStr(ModelMenuItem menuItem, Map context) throws IOException { - - StringBuilder imgStr = new StringBuilder(""); - return imgStr.toString(); - } - -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.renderer.html; + +import java.io.IOException; +import java.io.StringWriter; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.entity.Delegator; +import org.ofbiz.entity.GenericEntityException; +import org.ofbiz.entity.GenericValue; +import org.ofbiz.widget.content.WidgetContentWorker; +import org.ofbiz.widget.model.ModelMenuItem; + +/** + * Widget Library - HTML Menu Renderer implementation + */ + +public class HtmlMenuRendererImage extends HtmlMenuRenderer { + + protected HtmlMenuRendererImage() {} + + public HtmlMenuRendererImage(HttpServletRequest request, HttpServletResponse response) { + super(request, response); + } + + + public String buildDivStr(ModelMenuItem menuItem, Map context) throws IOException { + + StringBuilder imgStr = new StringBuilder(""); + return imgStr.toString(); + } + +} diff --git a/framework/widget/src/org/ofbiz/widget/html/HtmlMenuWrapper.java b/framework/widget/src/org/ofbiz/widget/renderer/html/HtmlMenuWrapper.java similarity index 95% rename from framework/widget/src/org/ofbiz/widget/html/HtmlMenuWrapper.java rename to framework/widget/src/org/ofbiz/widget/renderer/html/HtmlMenuWrapper.java index dcb589823b..54cb8d5abc 100644 --- a/framework/widget/src/org/ofbiz/widget/html/HtmlMenuWrapper.java +++ b/framework/widget/src/org/ofbiz/widget/renderer/html/HtmlMenuWrapper.java @@ -1,252 +1,252 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget.html; - -import java.io.IOException; -import java.io.StringWriter; -import java.io.Writer; -import java.util.HashMap; -import java.util.Map; - -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; -import javax.xml.parsers.ParserConfigurationException; - -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.UtilGenerics; -import org.ofbiz.base.util.UtilHttp; -import org.ofbiz.base.util.UtilValidate; -import org.ofbiz.entity.GenericValue; -import org.ofbiz.widget.menu.MenuFactory; -import org.ofbiz.widget.menu.MenuStringRenderer; -import org.ofbiz.widget.menu.ModelMenu; -import org.xml.sax.SAXException; - - -/** - * Widget Library - HTML Menu Wrapper class - makes it easy to do the setup and render of a menu - */ -public class HtmlMenuWrapper { - - public static final String module = HtmlMenuWrapper.class.getName(); - - protected String resourceName; - protected String menuName; - protected HttpServletRequest request; - protected HttpServletResponse response; - protected ModelMenu modelMenu; - protected MenuStringRenderer renderer; - protected Map context; - - protected HtmlMenuWrapper() {} - - public HtmlMenuWrapper(String resourceName, String menuName, HttpServletRequest request, HttpServletResponse response) - throws IOException, SAXException, ParserConfigurationException { - init(resourceName, menuName, request, response); - } - - public void init(String resourceName, String menuName, HttpServletRequest request, HttpServletResponse response) - throws IOException, SAXException, ParserConfigurationException { - this.resourceName = resourceName; - this.menuName = menuName; - this.request = request; - this.response = response; - - this.modelMenu = MenuFactory.getMenuFromWebappContext(resourceName, menuName, request); - - this.renderer = getMenuRenderer(); - - this.context = new HashMap(); - Map parameterMap = UtilHttp.getParameterMap(request); - context.put("parameters", parameterMap); - - HttpSession session = request.getSession(); - GenericValue userLogin = (GenericValue)session.getAttribute("userLogin"); - context.put("userLogin", userLogin); - - //make sure the locale is in the context - context.put("locale", UtilHttp.getLocale(request)); - - // if there was an error message, this is an error - if (UtilValidate.isNotEmpty(request.getAttribute("_ERROR_MESSAGE_"))) { - context.put("isError", Boolean.TRUE); - } else { - context.put("isError", Boolean.FALSE); - } - - // if a parameter was passed saying this is an error, it is an error - if ("true".equals(parameterMap.get("isError"))) { - context.put("isError", Boolean.TRUE); - } - } - - public MenuStringRenderer getMenuRenderer() { - return new HtmlMenuRenderer(request, response); - } - - public String renderMenuString() throws IOException { - HttpServletRequest req = ((HtmlMenuRenderer)renderer).request; - ServletContext ctx = (ServletContext) req.getAttribute("servletContext"); - if (ctx == null) { - if (Debug.infoOn()) Debug.logInfo("in renderMenuString, ctx is null(0)" , ""); - } - - Writer writer = new StringWriter(); - modelMenu.renderMenuString(writer, context, renderer); - - HttpServletRequest req2 = ((HtmlMenuRenderer)renderer).request; - ServletContext ctx2 = (ServletContext) req2.getAttribute("servletContext"); - if (ctx2 == null) { - if (Debug.infoOn()) Debug.logInfo("in renderMenuString, ctx is null(2)" , ""); - } - - return writer.toString(); - } - - /** - * Tells the menu library whether this is a response to an error or not. - * Defaults on initialization according to the presense of an errorMessage - * in the request or if an isError parameter was passed to the page with - * the value "true". If true then the prefilled values will come from the - * parameters Map instead of the value Map. - */ - public void setIsError(boolean isError) { - this.context.put("isError", Boolean.valueOf(isError)); - } - - public boolean getIsError() { - Boolean isErrorBoolean = (Boolean) this.context.get("isError"); - if (isErrorBoolean == null) { - return false; - } else { - return isErrorBoolean.booleanValue(); - } - } - - public void setMenuOverrideName(String menuName) { - this.context.put("menuName", menuName); - } - - public void putInContext(String name, Object value) { - this.context.put(name, value); - } - - public void putInContext(String menuItemName, String valueName, Object value) { - Map valueMap = UtilGenerics.toMap(context.get(menuItemName)); - if (valueMap == null) { - valueMap = new HashMap(); - context.put(menuItemName, valueMap); - } - valueMap.put(valueName, value); - } - - public Object getFromContext(String name) { - return this.context.get(name); - } - - public Object getFromContext(String menuItemName, String valueName) { - Map valueMap = UtilGenerics.toMap(context.get(menuItemName)); - if (valueMap == null) { - valueMap = new HashMap(); - context.put(menuItemName, valueMap); - } - return valueMap.get(valueName); - } - - public ModelMenu getModelMenu() { - return modelMenu; - } - - public MenuStringRenderer getRenderer() { - return renderer; - } - - public void setRenderer(MenuStringRenderer renderer) { - this.renderer = renderer; - } - - public void setRequest(HttpServletRequest request) { - this.request = request; - ((HtmlMenuRenderer)renderer).setRequest(request); - } - - public void setResponse(HttpServletResponse response) { - this.response = response; - ((HtmlMenuRenderer)renderer).setResponse(response); - } - - public HttpServletRequest getRequest() { - return ((HtmlMenuRenderer)renderer).request; - } - - public HttpServletResponse getResponse() { - return ((HtmlMenuRenderer)renderer).response; - } - - public static HtmlMenuWrapper getMenuWrapper(HttpServletRequest request, HttpServletResponse response, HttpSession session, String menuDefFile, String menuName, String menuWrapperClassName) { - - HtmlMenuWrapper menuWrapper = null; - - String menuSig = menuDefFile + "__" + menuName; - if (session != null) { - menuWrapper = (HtmlMenuWrapper)session.getAttribute(menuSig); - } - - if (menuWrapper == null) { - try { - Class cls = Class.forName("org.ofbiz.widget.html." + menuWrapperClassName); - menuWrapper = (HtmlMenuWrapper)cls.newInstance(); - menuWrapper.init(menuDefFile, menuName, request, response); - } catch (InstantiationException e) { - throw new RuntimeException(e.getMessage()); - } catch (IllegalAccessException e2) { - throw new RuntimeException(e2.getMessage()); - } catch (ClassNotFoundException e3) { - throw new RuntimeException("Class not found:" + e3.getMessage()); - } catch (IOException e4) { - throw new RuntimeException(e4.getMessage()); - } catch (SAXException e5) { - throw new RuntimeException(e5.getMessage()); - } catch (ParserConfigurationException e6) { - throw new RuntimeException(e6.getMessage()); - } - } else { - menuWrapper.setRequest(request); - menuWrapper.setResponse(response); - Map parameterMap = UtilHttp.getParameterMap(request); - menuWrapper.setParameters(parameterMap); - - GenericValue userLogin = (GenericValue)session.getAttribute("userLogin"); - menuWrapper.putInContext("userLogin", userLogin); - - } - - if (session != null) { - session.setAttribute(menuSig, menuWrapper); - } - return menuWrapper; - } - - public void setParameters(Map paramMap) { - context.put("parameters", paramMap); - } - -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.renderer.html; + +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import javax.xml.parsers.ParserConfigurationException; + +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilGenerics; +import org.ofbiz.base.util.UtilHttp; +import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.entity.GenericValue; +import org.ofbiz.widget.model.MenuFactory; +import org.ofbiz.widget.model.ModelMenu; +import org.ofbiz.widget.renderer.MenuStringRenderer; +import org.xml.sax.SAXException; + + +/** + * Widget Library - HTML Menu Wrapper class - makes it easy to do the setup and render of a menu + */ +public class HtmlMenuWrapper { + + public static final String module = HtmlMenuWrapper.class.getName(); + + protected String resourceName; + protected String menuName; + protected HttpServletRequest request; + protected HttpServletResponse response; + protected ModelMenu modelMenu; + protected MenuStringRenderer renderer; + protected Map context; + + protected HtmlMenuWrapper() {} + + public HtmlMenuWrapper(String resourceName, String menuName, HttpServletRequest request, HttpServletResponse response) + throws IOException, SAXException, ParserConfigurationException { + init(resourceName, menuName, request, response); + } + + public void init(String resourceName, String menuName, HttpServletRequest request, HttpServletResponse response) + throws IOException, SAXException, ParserConfigurationException { + this.resourceName = resourceName; + this.menuName = menuName; + this.request = request; + this.response = response; + + this.modelMenu = MenuFactory.getMenuFromWebappContext(resourceName, menuName, request); + + this.renderer = getMenuRenderer(); + + this.context = new HashMap(); + Map parameterMap = UtilHttp.getParameterMap(request); + context.put("parameters", parameterMap); + + HttpSession session = request.getSession(); + GenericValue userLogin = (GenericValue)session.getAttribute("userLogin"); + context.put("userLogin", userLogin); + + //make sure the locale is in the context + context.put("locale", UtilHttp.getLocale(request)); + + // if there was an error message, this is an error + if (UtilValidate.isNotEmpty(request.getAttribute("_ERROR_MESSAGE_"))) { + context.put("isError", Boolean.TRUE); + } else { + context.put("isError", Boolean.FALSE); + } + + // if a parameter was passed saying this is an error, it is an error + if ("true".equals(parameterMap.get("isError"))) { + context.put("isError", Boolean.TRUE); + } + } + + public MenuStringRenderer getMenuRenderer() { + return new HtmlMenuRenderer(request, response); + } + + public String renderMenuString() throws IOException { + HttpServletRequest req = ((HtmlMenuRenderer)renderer).request; + ServletContext ctx = (ServletContext) req.getAttribute("servletContext"); + if (ctx == null) { + if (Debug.infoOn()) Debug.logInfo("in renderMenuString, ctx is null(0)" , ""); + } + + Writer writer = new StringWriter(); + modelMenu.renderMenuString(writer, context, renderer); + + HttpServletRequest req2 = ((HtmlMenuRenderer)renderer).request; + ServletContext ctx2 = (ServletContext) req2.getAttribute("servletContext"); + if (ctx2 == null) { + if (Debug.infoOn()) Debug.logInfo("in renderMenuString, ctx is null(2)" , ""); + } + + return writer.toString(); + } + + /** + * Tells the menu library whether this is a response to an error or not. + * Defaults on initialization according to the presense of an errorMessage + * in the request or if an isError parameter was passed to the page with + * the value "true". If true then the prefilled values will come from the + * parameters Map instead of the value Map. + */ + public void setIsError(boolean isError) { + this.context.put("isError", Boolean.valueOf(isError)); + } + + public boolean getIsError() { + Boolean isErrorBoolean = (Boolean) this.context.get("isError"); + if (isErrorBoolean == null) { + return false; + } else { + return isErrorBoolean.booleanValue(); + } + } + + public void setMenuOverrideName(String menuName) { + this.context.put("menuName", menuName); + } + + public void putInContext(String name, Object value) { + this.context.put(name, value); + } + + public void putInContext(String menuItemName, String valueName, Object value) { + Map valueMap = UtilGenerics.toMap(context.get(menuItemName)); + if (valueMap == null) { + valueMap = new HashMap(); + context.put(menuItemName, valueMap); + } + valueMap.put(valueName, value); + } + + public Object getFromContext(String name) { + return this.context.get(name); + } + + public Object getFromContext(String menuItemName, String valueName) { + Map valueMap = UtilGenerics.toMap(context.get(menuItemName)); + if (valueMap == null) { + valueMap = new HashMap(); + context.put(menuItemName, valueMap); + } + return valueMap.get(valueName); + } + + public ModelMenu getModelMenu() { + return modelMenu; + } + + public MenuStringRenderer getRenderer() { + return renderer; + } + + public void setRenderer(MenuStringRenderer renderer) { + this.renderer = renderer; + } + + public void setRequest(HttpServletRequest request) { + this.request = request; + ((HtmlMenuRenderer)renderer).setRequest(request); + } + + public void setResponse(HttpServletResponse response) { + this.response = response; + ((HtmlMenuRenderer)renderer).setResponse(response); + } + + public HttpServletRequest getRequest() { + return ((HtmlMenuRenderer)renderer).request; + } + + public HttpServletResponse getResponse() { + return ((HtmlMenuRenderer)renderer).response; + } + + public static HtmlMenuWrapper getMenuWrapper(HttpServletRequest request, HttpServletResponse response, HttpSession session, String menuDefFile, String menuName, String menuWrapperClassName) { + + HtmlMenuWrapper menuWrapper = null; + + String menuSig = menuDefFile + "__" + menuName; + if (session != null) { + menuWrapper = (HtmlMenuWrapper)session.getAttribute(menuSig); + } + + if (menuWrapper == null) { + try { + Class cls = Class.forName("org.ofbiz.widget.html." + menuWrapperClassName); + menuWrapper = (HtmlMenuWrapper)cls.newInstance(); + menuWrapper.init(menuDefFile, menuName, request, response); + } catch (InstantiationException e) { + throw new RuntimeException(e.getMessage()); + } catch (IllegalAccessException e2) { + throw new RuntimeException(e2.getMessage()); + } catch (ClassNotFoundException e3) { + throw new RuntimeException("Class not found:" + e3.getMessage()); + } catch (IOException e4) { + throw new RuntimeException(e4.getMessage()); + } catch (SAXException e5) { + throw new RuntimeException(e5.getMessage()); + } catch (ParserConfigurationException e6) { + throw new RuntimeException(e6.getMessage()); + } + } else { + menuWrapper.setRequest(request); + menuWrapper.setResponse(response); + Map parameterMap = UtilHttp.getParameterMap(request); + menuWrapper.setParameters(parameterMap); + + GenericValue userLogin = (GenericValue)session.getAttribute("userLogin"); + menuWrapper.putInContext("userLogin", userLogin); + + } + + if (session != null) { + session.setAttribute(menuSig, menuWrapper); + } + return menuWrapper; + } + + public void setParameters(Map paramMap) { + context.put("parameters", paramMap); + } + +} diff --git a/framework/widget/src/org/ofbiz/widget/html/HtmlMenuWrapperImage.java b/framework/widget/src/org/ofbiz/widget/renderer/html/HtmlMenuWrapperImage.java similarity index 94% rename from framework/widget/src/org/ofbiz/widget/html/HtmlMenuWrapperImage.java rename to framework/widget/src/org/ofbiz/widget/renderer/html/HtmlMenuWrapperImage.java index 6346ef4f51..c41f2ac4f5 100644 --- a/framework/widget/src/org/ofbiz/widget/html/HtmlMenuWrapperImage.java +++ b/framework/widget/src/org/ofbiz/widget/renderer/html/HtmlMenuWrapperImage.java @@ -1,81 +1,80 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget.html; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.xml.parsers.ParserConfigurationException; - -import org.ofbiz.base.util.UtilMisc; -import org.ofbiz.entity.Delegator; -import org.ofbiz.entity.GenericEntityException; -import org.ofbiz.entity.GenericValue; -import org.ofbiz.entity.util.EntityQuery; -import org.ofbiz.widget.menu.MenuStringRenderer; -import org.ofbiz.widget.menu.ModelMenuItem; -import org.xml.sax.SAXException; - -/** - * Widget Library - HTML Menu Wrapper class - makes it easy to do the setup and render of a menu - */ -public class HtmlMenuWrapperImage extends HtmlMenuWrapper { - - public static final String module = HtmlMenuWrapperImage.class.getName(); - - protected HtmlMenuWrapperImage() {} - - public HtmlMenuWrapperImage(String resourceName, String menuName, HttpServletRequest request, HttpServletResponse response) - throws IOException, SAXException, ParserConfigurationException { - super(resourceName, menuName, request, response); - } - - @Override - public MenuStringRenderer getMenuRenderer() { - return new HtmlMenuRendererImage(request, response); - } - - @Override - public void init(String resourceName, String menuName, HttpServletRequest request, HttpServletResponse response) - throws IOException, SAXException, ParserConfigurationException { - - super.init(resourceName, menuName, request, response); - //String pubPt = (String)request.getAttribute("pubPt"); - //if (Debug.infoOn()) Debug.logInfo("in init, pubPt:" + pubPt, module); - Map dummyMap = new HashMap(); - Delegator delegator = (Delegator)request.getAttribute("delegator"); - //if (Debug.infoOn()) Debug.logInfo("in init, delegator:" + delegator, module); - try { - for (ModelMenuItem menuItem : modelMenu.getMenuItemList()) { - String contentId = menuItem.getAssociatedContentId(dummyMap); - //if (Debug.infoOn()) Debug.logInfo("in init, contentId:" + contentId, module); - GenericValue webSitePublishPoint = EntityQuery.use(delegator).from("WebSitePublishPoint").where("contentId", contentId).cache().queryOne(); - String menuItemName = menuItem.getName(); - //if (Debug.infoOn()) Debug.logInfo("in init, menuItemName:" + menuItemName, module); - //if (Debug.infoOn()) Debug.logInfo("in init, webSitePublishPoint:" + webSitePublishPoint, module); - putInContext(menuItemName, "WebSitePublishPoint", webSitePublishPoint); - } - } catch (GenericEntityException e) { - return; - } - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.renderer.html; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.xml.parsers.ParserConfigurationException; + +import org.ofbiz.entity.Delegator; +import org.ofbiz.entity.GenericEntityException; +import org.ofbiz.entity.GenericValue; +import org.ofbiz.entity.util.EntityQuery; +import org.ofbiz.widget.model.ModelMenuItem; +import org.ofbiz.widget.renderer.MenuStringRenderer; +import org.xml.sax.SAXException; + +/** + * Widget Library - HTML Menu Wrapper class - makes it easy to do the setup and render of a menu + */ +public class HtmlMenuWrapperImage extends HtmlMenuWrapper { + + public static final String module = HtmlMenuWrapperImage.class.getName(); + + protected HtmlMenuWrapperImage() {} + + public HtmlMenuWrapperImage(String resourceName, String menuName, HttpServletRequest request, HttpServletResponse response) + throws IOException, SAXException, ParserConfigurationException { + super(resourceName, menuName, request, response); + } + + @Override + public MenuStringRenderer getMenuRenderer() { + return new HtmlMenuRendererImage(request, response); + } + + @Override + public void init(String resourceName, String menuName, HttpServletRequest request, HttpServletResponse response) + throws IOException, SAXException, ParserConfigurationException { + + super.init(resourceName, menuName, request, response); + //String pubPt = (String)request.getAttribute("pubPt"); + //if (Debug.infoOn()) Debug.logInfo("in init, pubPt:" + pubPt, module); + Map dummyMap = new HashMap(); + Delegator delegator = (Delegator)request.getAttribute("delegator"); + //if (Debug.infoOn()) Debug.logInfo("in init, delegator:" + delegator, module); + try { + for (ModelMenuItem menuItem : modelMenu.getMenuItemList()) { + String contentId = menuItem.getAssociatedContentId(dummyMap); + //if (Debug.infoOn()) Debug.logInfo("in init, contentId:" + contentId, module); + GenericValue webSitePublishPoint = EntityQuery.use(delegator).from("WebSitePublishPoint").where("contentId", contentId).cache().queryOne(); + String menuItemName = menuItem.getName(); + //if (Debug.infoOn()) Debug.logInfo("in init, menuItemName:" + menuItemName, module); + //if (Debug.infoOn()) Debug.logInfo("in init, webSitePublishPoint:" + webSitePublishPoint, module); + putInContext(menuItemName, "WebSitePublishPoint", webSitePublishPoint); + } + } catch (GenericEntityException e) { + return; + } + } +} diff --git a/framework/widget/src/org/ofbiz/widget/html/HtmlScreenRenderer.java b/framework/widget/src/org/ofbiz/widget/renderer/html/HtmlScreenRenderer.java similarity index 95% rename from framework/widget/src/org/ofbiz/widget/html/HtmlScreenRenderer.java rename to framework/widget/src/org/ofbiz/widget/renderer/html/HtmlScreenRenderer.java index 90c05b1d8e..04a81cba35 100644 --- a/framework/widget/src/org/ofbiz/widget/html/HtmlScreenRenderer.java +++ b/framework/widget/src/org/ofbiz/widget/renderer/html/HtmlScreenRenderer.java @@ -1,932 +1,944 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.widget.html; - -import java.io.IOException; -import java.math.BigDecimal; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Locale; -import java.util.Map; - -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.GeneralException; -import org.ofbiz.base.util.UtilFormatOut; -import org.ofbiz.base.util.UtilGenerics; -import org.ofbiz.base.util.UtilHttp; -import org.ofbiz.base.util.UtilMisc; -import org.ofbiz.base.util.UtilValidate; -import org.ofbiz.entity.Delegator; -import org.ofbiz.entity.GenericValue; -import org.ofbiz.service.LocalDispatcher; -import org.ofbiz.webapp.control.RequestHandler; -import org.ofbiz.webapp.taglib.ContentUrlTag; -import org.ofbiz.widget.ModelWidget; -import org.ofbiz.widget.WidgetContentWorker; -import org.ofbiz.widget.WidgetDataResourceWorker; -import org.ofbiz.widget.WidgetWorker; -import org.ofbiz.widget.form.FormStringRenderer; -import org.ofbiz.widget.form.ModelForm; -import org.ofbiz.widget.form.Paginator; -import org.ofbiz.widget.menu.MenuStringRenderer; -import org.ofbiz.widget.menu.ModelMenu; -import org.ofbiz.widget.screen.ModelScreenWidget; -import org.ofbiz.widget.screen.ModelScreenWidget.*; -import org.ofbiz.widget.screen.ScreenStringRenderer; - -/** - * Widget Library - HTML Form Renderer implementation - * @deprecated Use MacroScreenRenderer. - */ -public class HtmlScreenRenderer extends HtmlWidgetRenderer implements ScreenStringRenderer { - - public static final String module = HtmlScreenRenderer.class.getName(); - protected int elementId = 999; - - public HtmlScreenRenderer() {} - - protected String getNextElementId() { - elementId++; - return "hsr" + elementId; - } - - public String getRendererName() { - return "html"; - } - - public void renderScreenBegin(Appendable writer, Map context) throws IOException { - writer.append(""); - appendWhitespace(writer); - } - - public void renderScreenEnd(Appendable writer, Map context) throws IOException { - } - - public void renderSectionBegin(Appendable writer, Map context, Section section) throws IOException { - if (section.isMainSection()) { - this.widgetCommentsEnabled = ModelWidget.widgetBoundaryCommentsEnabled(context); - } - renderBeginningBoundaryComment(writer, section.isMainSection()?"Screen":"Section Widget", section); - } - - public void renderSectionEnd(Appendable writer, Map context, Section section) throws IOException { - renderEndingBoundaryComment(writer, section.isMainSection()?"Screen":"Section Widget", section); - } - - public void renderContainerBegin(Appendable writer, Map context, Container container) throws IOException { - String containerId = container.getId(context); - String autoUpdateTarget = container.getAutoUpdateTargetExdr(context); - HttpServletRequest request = (HttpServletRequest) context.get("request"); - if (UtilValidate.isNotEmpty(autoUpdateTarget) && UtilHttp.isJavaScriptEnabled(request)) { - if (UtilValidate.isEmpty(containerId)) { - containerId = getNextElementId(); - } - HttpServletResponse response = (HttpServletResponse) context.get("response"); - ServletContext ctx = (ServletContext) request.getAttribute("servletContext"); - RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_"); - - writer.append(""); - appendWhitespace(writer); - } - writer.append(""); - appendWhitespace(writer); - } - public void renderContainerEnd(Appendable writer, Map context, Container container) throws IOException { - writer.append(""); - appendWhitespace(writer); - } - - public void renderHorizontalSeparator(Appendable writer, Map context, HorizontalSeparator separator) throws IOException { - writer.append(""); - appendWhitespace(writer); - } - - public void renderScreenletBegin(Appendable writer, Map context, boolean collapsed, Screenlet screenlet) throws IOException { - HttpServletRequest request = (HttpServletRequest) context.get("request"); - HttpServletResponse response = (HttpServletResponse) context.get("response"); - boolean javaScriptEnabled = UtilHttp.isJavaScriptEnabled(request); - Menu tabMenu = screenlet.getTabMenu(); - if (tabMenu != null) { - tabMenu.renderWidgetString(writer, context, this); - } - writer.append("
"); - appendWhitespace(writer); - - String title = screenlet.getTitle(context); - Menu navMenu = screenlet.getNavigationMenu(); - Form navForm = screenlet.getNavigationForm(); - String collapsibleAreaId = null; - if (UtilValidate.isNotEmpty(title) || navMenu != null || navForm != null || screenlet.collapsible()) { - writer.append("
"); - appendWhitespace(writer); - writer.append("
    "); - appendWhitespace(writer); - if (UtilValidate.isNotEmpty(title)) { - writer.append("
  • "); - writer.append(title); - writer.append("
  • "); - appendWhitespace(writer); - } - if (screenlet.collapsible()) { - collapsibleAreaId = this.getNextElementId(); - String expandToolTip = null; - String collapseToolTip = null; - Map uiLabelMap = UtilGenerics.checkMap(context.get("uiLabelMap")); - Map paramMap = UtilGenerics.checkMap(context.get("requestParameters")); - Map requestParameters = new HashMap(paramMap); - if (uiLabelMap != null) { - expandToolTip = (String) uiLabelMap.get("CommonExpand"); - collapseToolTip = (String) uiLabelMap.get("CommonCollapse"); - } - writer.append("
  •  
  • "); - appendWhitespace(writer); - } - if (!collapsed) { - if (navMenu != null) { - MenuStringRenderer savedRenderer = (MenuStringRenderer) context.get("menuStringRenderer"); - MenuStringRenderer renderer = new ScreenletMenuRenderer(request, response); - context.put("menuStringRenderer", renderer); - navMenu.renderWidgetString(writer, context, this); - context.put("menuStringRenderer", savedRenderer); - } else if (navForm != null) { - renderScreenletPaginateMenu(writer, context, navForm); - } - } - writer.append("
"); - appendWhitespace(writer); - writer.append("
"); - appendWhitespace(writer); - writer.append("
"); - appendWhitespace(writer); - writer.append(""); - appendWhitespace(writer); - } - } - - private int getActualPageSize(Map context) { - Integer value = (Integer) context.get("actualPageSize"); - return value != null ? value.intValue() : (getHighIndex(context) - getLowIndex(context)); - } - - private int getHighIndex(Map context) { - Integer value = (Integer) context.get("highIndex"); - return value != null ? value.intValue() : 0; - } - - private int getListSize(Map context) { - Integer value = (Integer) context.get("listSize"); - return value != null ? value.intValue() : 0; - } - - private int getLowIndex(Map context) { - Integer value = (Integer) context.get("lowIndex"); - return value != null ? value.intValue() : 0; - } - - protected void renderScreenletPaginateMenu(Appendable writer, Map context, Form form) throws IOException { - HttpServletResponse response = (HttpServletResponse) context.get("response"); - HttpServletRequest request = (HttpServletRequest) context.get("request"); - ModelForm modelForm = form.getModelForm(context); - modelForm.runFormActions(context); - Paginator.preparePager(modelForm, context); - String targetService = modelForm.getPaginateTarget(context); - if (targetService == null) { - targetService = "${targetService}"; - } - - // get the parametrized pagination index and size fields - int paginatorNumber = WidgetWorker.getPaginatorNumber(context); - String viewIndexParam = modelForm.getMultiPaginateIndexField(context); - String viewSizeParam = modelForm.getMultiPaginateSizeField(context); - - int viewIndex = Paginator.getViewIndex(modelForm, context); - int viewSize = Paginator.getViewSize(modelForm, context); - int listSize = getListSize(context); - - int lowIndex = getLowIndex(context); - int highIndex = getHighIndex(context); - int actualPageSize = getActualPageSize(context); - - // if this is all there seems to be (if listSize < 0, then size is unknown) - if (actualPageSize >= listSize && listSize >= 0) return; - - // needed for the "Page" and "rows" labels - Map uiLabelMap = UtilGenerics.cast(context.get("uiLabelMap")); - String ofLabel = ""; - if (uiLabelMap == null) { - Debug.logWarning("Could not find uiLabelMap in context", module); - } else { - ofLabel = uiLabelMap.get("CommonOf"); - ofLabel = ofLabel.toLowerCase(); - } - - // for legacy support, the viewSizeParam is VIEW_SIZE and viewIndexParam is VIEW_INDEX when the fields are "viewSize" and "viewIndex" - if (viewIndexParam.equals("viewIndex" + "_" + paginatorNumber)) viewIndexParam = "VIEW_INDEX" + "_" + paginatorNumber; - if (viewSizeParam.equals("viewSize" + "_" + paginatorNumber)) viewSizeParam = "VIEW_SIZE" + "_" + paginatorNumber; - - ServletContext ctx = (ServletContext) request.getAttribute("servletContext"); - RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_"); - - Map inputFields = UtilGenerics.toMap(context.get("requestParameters")); - // strip out any multi form fields if the form is of type multi - if (modelForm.getType().equals("multi")) { - inputFields = UtilHttp.removeMultiFormParameters(inputFields); - } - String queryString = UtilHttp.urlEncodeArgs(inputFields); - // strip legacy viewIndex/viewSize params from the query string - queryString = UtilHttp.stripViewParamsFromQueryString(queryString, "" + paginatorNumber); - // strip parametrized index/size params from the query string - HashSet paramNames = new HashSet(); - paramNames.add(viewIndexParam); - paramNames.add(viewSizeParam); - queryString = UtilHttp.stripNamedParamsFromQueryString(queryString, paramNames); - - String anchor = ""; - String paginateAnchor = modelForm.getPaginateTargetAnchor(); - if (paginateAnchor != null) anchor = "#" + paginateAnchor; - - // preparing the link text, so that later in the code we can reuse this and just add the viewIndex - StringBuilder prepLinkTextBuffer = new StringBuilder(targetService); - if (prepLinkTextBuffer.indexOf("?") < 0) { - prepLinkTextBuffer.append("?"); - } else if (prepLinkTextBuffer.indexOf("?", prepLinkTextBuffer.length() - 1) > 0) { - prepLinkTextBuffer.append("&"); - } - if (!UtilValidate.isEmpty(queryString) && !queryString.equals("null")) { - prepLinkTextBuffer.append(queryString).append("&"); - } - prepLinkTextBuffer.append(viewSizeParam).append("=").append(viewSize).append("&").append(viewIndexParam).append("="); - String prepLinkText = prepLinkTextBuffer.toString(); - - String linkText; - - appendWhitespace(writer); - // The current screenlet title bar navigation syling requires rendering - // these links in reverse order - // Last button - writer.append("
  • ").append(modelForm.getPaginateLastLabel(context)).append(""); - } else { - // disabled button - writer.append(" disabled\">").append(modelForm.getPaginateLastLabel(context)); - } - writer.append("
  • "); - appendWhitespace(writer); - // Next button - writer.append("
  • ").append(modelForm.getPaginateNextLabel(context)).append(""); - } else { - // disabled button - writer.append(" disabled\">").append(modelForm.getPaginateNextLabel(context)); - } - writer.append("
  • "); - appendWhitespace(writer); - if (listSize > 0) { - writer.append("
  • "); - writer.append(Integer.toString(lowIndex + 1)).append(" - ").append(Integer.toString(lowIndex + actualPageSize)).append(" ").append(ofLabel).append(" ").append(Integer.toString(listSize)); - writer.append("
  • "); - appendWhitespace(writer); - } - // Previous button - writer.append("
  • 0) { - writer.append("\">").append(modelForm.getPaginatePreviousLabel(context)).append(""); - } else { - // disabled button - writer.append(" disabled\">").append(modelForm.getPaginatePreviousLabel(context)); - } - writer.append("
  • "); - appendWhitespace(writer); - // First button - writer.append("
  • 0) { - writer.append("\">").append(modelForm.getPaginateFirstLabel(context)).append(""); - } else { - writer.append(" disabled\">").append(modelForm.getPaginateFirstLabel(context)); - } - writer.append("
  • "); - appendWhitespace(writer); - } - - public void renderScreenletSubWidget(Appendable writer, Map context, ModelScreenWidget subWidget, Screenlet screenlet) throws GeneralException, IOException { - if (subWidget.equals(screenlet.getNavigationForm())) { - HttpServletRequest request = (HttpServletRequest) context.get("request"); - HttpServletResponse response = (HttpServletResponse) context.get("response"); - if (request != null && response != null) { - Map globalCtx = UtilGenerics.checkMap(context.get("globalContext")); - globalCtx.put("NO_PAGINATOR", true); - FormStringRenderer savedRenderer = (FormStringRenderer) context.get("formStringRenderer"); - HtmlFormRenderer renderer = new HtmlFormRenderer(request, response); - renderer.setRenderPagination(false); - context.put("formStringRenderer", renderer); - subWidget.renderWidgetString(writer, context, this); - context.put("formStringRenderer", savedRenderer); - } - } else { - subWidget.renderWidgetString(writer, context, this); - } - } - - public void renderScreenletEnd(Appendable writer, Map context, Screenlet screenlet) throws IOException { - writer.append("
    "); - appendWhitespace(writer); - writer.append(""); - appendWhitespace(writer); - } - - public static class ScreenletMenuRenderer extends HtmlMenuRenderer { - public ScreenletMenuRenderer(HttpServletRequest request, HttpServletResponse response) { - super(request, response); - } - @Override - public void renderMenuOpen(Appendable writer, Map context, ModelMenu modelMenu) {} - @Override - public void renderMenuClose(Appendable writer, Map context, ModelMenu modelMenu) {} - } - - public void renderLabel(Appendable writer, Map context, Label label) throws IOException { - String labelText = label.getText(context); - if (UtilValidate.isEmpty(labelText)) { - // nothing to render - return; - } - // open tag - String style = label.getStyle(context); - String id = label.getId(context); - if (UtilValidate.isNotEmpty(style) || UtilValidate.isNotEmpty(id)) { - writer.append(""); - - // the text - writer.append(labelText); - - // close tag - writer.append(""); - - } else { - writer.append(labelText); - } - - appendWhitespace(writer); - } - - public void renderLink(Appendable writer, Map context, ScreenLink link) throws IOException { - HttpServletResponse response = (HttpServletResponse) context.get("response"); - HttpServletRequest request = (HttpServletRequest) context.get("request"); - - String targetWindow = link.getTargetWindow(context); - String target = link.getTarget(context); - - String uniqueItemName = link.getModelScreen().getName() + "_LF_" + UtilMisc.addToBigDecimalInMap(context, "screenUniqueItemIndex", BigDecimal.ONE); - - String linkType = WidgetWorker.determineAutoLinkType(link.getLinkType(), target, link.getUrlMode(), request); - if ("hidden-form".equals(linkType)) { - writer.append("
    "); - - for (Map.Entry parameter: link.getParameterMap(context).entrySet()) { - writer.append(""); - } - - writer.append(""); - } - - writer.append(""); - - // the text - ScreenImage img = link.getImage(); - if (img == null) { - writer.append(link.getText(context)); - } else { - renderImage(writer, context, img); - } - - // close tag - writer.append(""); - - appendWhitespace(writer); - } - - public void renderImage(Appendable writer, Map context, ScreenImage image) throws IOException { - // open tag - String src = image.getSrc(context); - if (UtilValidate.isEmpty(src)) { - return; - } - writer.append("image.getAlt(context);"); - - appendWhitespace(writer); - } - - public void renderContentBegin(Appendable writer, Map context, Content content) throws IOException { - String editRequest = content.getEditRequest(context); - String editContainerStyle = content.getEditContainerStyle(context); - String enableEditName = content.getEnableEditName(context); - String enableEditValue = (String)context.get(enableEditName); - - if (Debug.verboseOn()) Debug.logVerbose("directEditRequest:" + editRequest, module); - - if (UtilValidate.isNotEmpty(editRequest) && "true".equals(enableEditValue)) { - writer.append(" "); - appendWhitespace(writer); - } - } - - public void renderContentBody(Appendable writer, Map context, Content content) throws IOException { - Locale locale = UtilMisc.ensureLocale(context.get("locale")); - //Boolean nullThruDatesOnly = Boolean.valueOf(false); - String mimeTypeId = "text/html"; - String expandedContentId = content.getContentId(context); - String expandedDataResourceId = content.getDataResourceId(context); - String renderedContent = null; - LocalDispatcher dispatcher = (LocalDispatcher) context.get("dispatcher"); - Delegator delegator = (Delegator) context.get("delegator"); - - // make a new map for content rendering; so our current map does not get clobbered - Map contentContext = new HashMap(); - contentContext.putAll(context); - String dataResourceId = (String)contentContext.get("dataResourceId"); - if (Debug.verboseOn()) Debug.logVerbose("expandedContentId:" + expandedContentId, module); - - try { - if (UtilValidate.isNotEmpty(dataResourceId)) { - if (WidgetDataResourceWorker.dataresourceWorker != null) { - renderedContent = WidgetDataResourceWorker.dataresourceWorker.renderDataResourceAsTextExt(delegator, dataResourceId, contentContext, locale, mimeTypeId, false); - } else { - Debug.logError("Not rendering content, WidgetDataResourceWorker.dataresourceWorker not found.", module); - } - } else if (UtilValidate.isNotEmpty(expandedContentId)) { - if (WidgetContentWorker.contentWorker != null) { - renderedContent = WidgetContentWorker.contentWorker.renderContentAsTextExt(dispatcher, delegator, expandedContentId, contentContext, locale, mimeTypeId, true); - } else { - Debug.logError("Not rendering content, WidgetContentWorker.contentWorker not found.", module); - } - } else if (UtilValidate.isNotEmpty(expandedDataResourceId)) { - if (WidgetDataResourceWorker.dataresourceWorker != null) { - renderedContent = WidgetDataResourceWorker.dataresourceWorker.renderDataResourceAsTextExt(delegator, expandedDataResourceId, contentContext, locale, mimeTypeId, false); - } else { - Debug.logError("Not rendering content, WidgetDataResourceWorker.dataresourceWorker not found.", module); - } - } - if (UtilValidate.isEmpty(renderedContent)) { - String editRequest = content.getEditRequest(context); - if (UtilValidate.isNotEmpty(editRequest)) { - if (WidgetContentWorker.contentWorker != null) { - WidgetContentWorker.contentWorker.renderContentAsTextExt(dispatcher, delegator, "NOCONTENTFOUND", writer, contentContext, locale, mimeTypeId, true); - } else { - Debug.logError("Not rendering content, WidgetContentWorker.contentWorker not found.", module); - } - } - } else { - if (content.xmlEscape()) { - renderedContent = UtilFormatOut.encodeXmlValue(renderedContent); - } - - writer.append(renderedContent); - } - - } catch (GeneralException e) { - String errMsg = "Error rendering included content with id [" + expandedContentId + "] : " + e.toString(); - Debug.logError(e, errMsg, module); - //throw new RuntimeException(errMsg); - } catch (IOException e2) { - String errMsg = "Error rendering included content with id [" + expandedContentId + "] : " + e2.toString(); - Debug.logError(e2, errMsg, module); - //throw new RuntimeException(errMsg); - } - } - - public void renderContentEnd(Appendable writer, Map context, Content content) throws IOException { - - //Debug.logInfo("renderContentEnd, context:" + context, module); - String expandedContentId = content.getContentId(context); - String editMode = "Edit"; - String editRequest = content.getEditRequest(context); - String editContainerStyle = content.getEditContainerStyle(context); - String enableEditName = content.getEnableEditName(context); - String enableEditValue = (String)context.get(enableEditName); - if (editRequest != null && editRequest.toUpperCase().indexOf("IMAGE") > 0) { - editMode += " Image"; - } - //String editRequestWithParams = editRequest + "?contentId=${currentValue.contentId}&drDataResourceId=${currentValue.drDataResourceId}&directEditRequest=${directEditRequest}&indirectEditRequest=${indirectEditRequest}&caContentIdTo=${currentValue.caContentIdTo}&caFromDate=${currentValue.caFromDate}&caContentAssocTypeId=${currentValue.caContentAssocTypeId}"; - - if (UtilValidate.isNotEmpty(editRequest) && "true".equals(enableEditValue)) { - HttpServletResponse response = (HttpServletResponse) context.get("response"); - HttpServletRequest request = (HttpServletRequest) context.get("request"); - if (request != null && response != null) { - if (editRequest.indexOf("?") < 0) editRequest += "?"; - else editRequest += "&"; - editRequest += "contentId=" + expandedContentId; - ServletContext ctx = (ServletContext) request.getAttribute("servletContext"); - RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_"); - writer.append("").append(editMode).append(""); - } - if (UtilValidate.isNotEmpty(editContainerStyle)) { - writer.append(""); - } - appendWhitespace(writer); - } - } - - public void renderContentFrame(Appendable writer, Map context, Content content) throws IOException { - - - HttpServletRequest request = (HttpServletRequest) context.get("request"); - HttpServletResponse response = (HttpServletResponse) context.get("response"); - if (request != null && response != null) { - ServletContext ctx = (ServletContext) request.getAttribute("servletContext"); - RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_"); - String dataResourceId = content.getDataResourceId(context); -// String urlString = "/content/control/ViewSimpleContent?dataResourceId=" + dataResourceId; - String urlString = "/ViewSimpleContent?dataResourceId=" + dataResourceId; - - writer.append("