internal static IStrutsConfigXml getStrutsConfig(string strutsConfigFile, ITilesDefinitions tilesDefinitions, IValidationXml validation)
        {
            var strutsConfigXml = new KStrutsConfigXml();
            try
            {
                var strutsConfig =
                    ((strutsconfig) Serialize.getDeSerializedObjectFromXmlFile(strutsConfigFile, typeof (strutsconfig)));

                if (strutsConfig != null)
                {
                    if (strutsConfig.formbeans != null)
                    {
                        // first add the forms
                        foreach (var formBean in strutsConfig.formbeans)
                        {
                            var newFormBean = new KStrutsConfig_FormBean()
                                                  {
                                                      name = formBean.name,
                                                      type = formBean.type,
                                                      extends = formBean.extends,
                                                  };
                            if (formBean.formproperty != null)
                                foreach (var formProperty in formBean.formproperty)
                                {
                                    var field = new KStrutsConfig_FormBean_Field()
                                                    {
                                                        name = formProperty.name,
                                                        type = formProperty.type,
                                                        initial = formProperty.initial
                                                    };
                                    newFormBean.fields.Add(formProperty.name, field);

                                    //newFormBean.properties.Add(formProperty.name, formProperty.type);
                                }
                            strutsConfigXml.formBeans.Add(newFormBean);
                        }
                        // now map the validation
                        if (validation != null)
                        {
                            var validationForms = new Dictionary<string, IValidation_Form>();
                            foreach (var validationForm in validation.forms)
                                if (false == validationForms.ContainsKey(validationForm.name))
                                    validationForms.Add(validationForm.name, validationForm);
                                else
                                {
                                    PublicDI.log.error("Duplicate form validator: {0}", validationForm.name);
                                    //var asd = validationForms[validationForm.name].fields;
                                }

                            foreach (var formBean in strutsConfigXml.formBeans)
                            {
                                if (false == validationForms.ContainsKey(formBean.name))
                                    formBean.hasValidationMapping = false;
                                else
                                {
                                    var validatorForm = validationForms[formBean.name];
                                    foreach (var field in formBean.fields)
                                    {
                                        if (validatorForm.fields.ContainsKey(field.Key))
                                        {
                                            field.Value.hasValidationMapping = true;
                                            field.Value.depends = validatorForm.fields[field.Key].depends;
                                            foreach (var var in validatorForm.fields[field.Key].vars)
                                                field.Value.validators.Add(var.Key, var.Value);
                                        }
                                        else
                                            field.Value.hasValidationMapping = false;
                                    }
                                    //formBean.properties
                                    //foreach(var )
                                    formBean.hasValidationMapping = true;
                                }
                            }
                        }
                    }
                    if (strutsConfig.globalforwards != null)
                        foreach (var globalForward in strutsConfig.globalforwards)
                            strutsConfigXml.globalForwards.Add(globalForward.name, globalForward.path);


                    if (strutsConfig.actionmappings != null)
                        foreach (var action in strutsConfig.actionmappings)
                        {
                            var newActionMapping = new KStrutsConfig_Action()
                                                       {
                                                           name = action.name,
                                                           path = action.path,
                                                           input = action.input,
                                                           scope = action.scope,
                                                           type = action.type,
                                                           validate = action.validate.ToString(),
                                                           unknown = action.unknown,
                                                           extends = action.extends,
                                                           parameter = action.parameter
                                                       };
                            if (action.forward != null)
                                foreach (var forward in action.forward)
                                {
                                    var newForward = new KStrutsConfig_Action_Forward()
                                                         {
                                                             name = forward.name,
                                                             path = forward.path,
                                                             redirect = forward.redirect
                                                         };
                                    newActionMapping.forwards.Add(newForward);
                                }
                            strutsConfigXml.actionmappings.Add(newActionMapping);
                        }
                    if (strutsConfig.plugin != null)
                        foreach (var plugin in strutsConfig.plugin)
                        {
                            var newPlugIn = new KStrutsConfig_PlugIn()
                                                {
                                                    className = plugin.className
                                                };
                            if (plugin.setproperty != null)
                                foreach (var property in plugin.setproperty)
                                    newPlugIn.properties.Add(property.property, property.value);

                            strutsConfigXml.plugIns.Add(newPlugIn);
                        }

                    if (tilesDefinitions != null)
                        foreach (var titleDefinition in tilesDefinitions.definitions)
                        {
                            //var value = titleDefinition.page ?? titleDefinition.path ?? "";
                            var value = titleDefinition.page ?? titleDefinition.path;

                            addTileDefinition(strutsConfigXml.resolvedViews, titleDefinition.name, value);

                            foreach (var put in titleDefinition.puts)
                                addTileDefinition(strutsConfigXml.resolvedViews, titleDefinition.name, put.Value);
                            /*if (value != null)
                                if (false == strutsConfigXml.resolvedViews.ContainsKey(titleDefinition.name))
                                    strutsConfigXml.resolvedViews.Add(titleDefinition.name, value);
                                else
                                    DI.log.error("in mapping TilesDefinition, there was a duplicate key: {0} with value {1}",
                                                titleDefinition.name, value);
                            */


                        }

                }
            }
            catch (Exception ex)
            {
                PublicDI.log.error("in getStrutsConfig: {0}", ex.Message);

            }
            return strutsConfigXml;
        }
Example #2
0
        internal static IStrutsConfigXml getStrutsConfig(string strutsConfigFile, ITilesDefinitions tilesDefinitions, IValidationXml validation)
        {
            var strutsConfigXml = new KStrutsConfigXml();

            try
            {
                var strutsConfig =
                    ((strutsconfig)Serialize.getDeSerializedObjectFromXmlFile(strutsConfigFile, typeof(strutsconfig)));

                if (strutsConfig != null)
                {
                    if (strutsConfig.formbeans != null)
                    {
                        // first add the forms
                        foreach (var formBean in strutsConfig.formbeans)
                        {
                            var newFormBean = new KStrutsConfig_FormBean()
                            {
                                name    = formBean.name,
                                type    = formBean.type,
                                extends = formBean.extends,
                            };
                            if (formBean.formproperty != null)
                            {
                                foreach (var formProperty in formBean.formproperty)
                                {
                                    var field = new KStrutsConfig_FormBean_Field()
                                    {
                                        name    = formProperty.name,
                                        type    = formProperty.type,
                                        initial = formProperty.initial
                                    };
                                    newFormBean.fields.Add(formProperty.name, field);

                                    //newFormBean.properties.Add(formProperty.name, formProperty.type);
                                }
                            }
                            strutsConfigXml.formBeans.Add(newFormBean);
                        }
                        // now map the validation
                        if (validation != null)
                        {
                            var validationForms = new Dictionary <string, IValidation_Form>();
                            foreach (var validationForm in validation.forms)
                            {
                                if (false == validationForms.ContainsKey(validationForm.name))
                                {
                                    validationForms.Add(validationForm.name, validationForm);
                                }
                                else
                                {
                                    DI.log.error("Duplicate form validator: {0}", validationForm.name);
                                    //var asd = validationForms[validationForm.name].fields;
                                }
                            }

                            foreach (var formBean in strutsConfigXml.formBeans)
                            {
                                if (false == validationForms.ContainsKey(formBean.name))
                                {
                                    formBean.hasValidationMapping = false;
                                }
                                else
                                {
                                    var validatorForm = validationForms[formBean.name];
                                    foreach (var field in formBean.fields)
                                    {
                                        if (validatorForm.fields.ContainsKey(field.Key))
                                        {
                                            field.Value.hasValidationMapping = true;
                                            field.Value.depends = validatorForm.fields[field.Key].depends;
                                            foreach (var var in validatorForm.fields[field.Key].vars)
                                            {
                                                field.Value.validators.Add(var.Key, var.Value);
                                            }
                                        }
                                        else
                                        {
                                            field.Value.hasValidationMapping = false;
                                        }
                                    }
                                    //formBean.properties
                                    //foreach(var )
                                    formBean.hasValidationMapping = true;
                                }
                            }
                        }
                    }
                    if (strutsConfig.globalforwards != null)
                    {
                        foreach (var globalForward in strutsConfig.globalforwards)
                        {
                            strutsConfigXml.globalForwards.Add(globalForward.name, globalForward.path);
                        }
                    }


                    if (strutsConfig.actionmappings != null)
                    {
                        foreach (var action in strutsConfig.actionmappings)
                        {
                            var newActionMapping = new KStrutsConfig_Action()
                            {
                                name      = action.name,
                                path      = action.path,
                                input     = action.input,
                                scope     = action.scope,
                                type      = action.type,
                                validate  = action.validate.ToString(),
                                unknown   = action.unknown,
                                extends   = action.extends,
                                parameter = action.parameter
                            };
                            if (action.forward != null)
                            {
                                foreach (var forward in action.forward)
                                {
                                    var newForward = new KStrutsConfig_Action_Forward()
                                    {
                                        name     = forward.name,
                                        path     = forward.path,
                                        redirect = forward.redirect
                                    };
                                    newActionMapping.forwards.Add(newForward);
                                }
                            }
                            strutsConfigXml.actionmappings.Add(newActionMapping);
                        }
                    }
                    if (strutsConfig.plugin != null)
                    {
                        foreach (var plugin in strutsConfig.plugin)
                        {
                            var newPlugIn = new KStrutsConfig_PlugIn()
                            {
                                className = plugin.className
                            };
                            if (plugin.setproperty != null)
                            {
                                foreach (var property in plugin.setproperty)
                                {
                                    newPlugIn.properties.Add(property.property, property.value);
                                }
                            }

                            strutsConfigXml.plugIns.Add(newPlugIn);
                        }
                    }

                    if (tilesDefinitions != null)
                    {
                        foreach (var titleDefinition in tilesDefinitions.definitions)
                        {
                            //var value = titleDefinition.page ?? titleDefinition.path ?? "";
                            var value = titleDefinition.page ?? titleDefinition.path;

                            addTileDefinition(strutsConfigXml.resolvedViews, titleDefinition.name, value);

                            foreach (var put in titleDefinition.puts)
                            {
                                addTileDefinition(strutsConfigXml.resolvedViews, titleDefinition.name, put.Value);
                            }

                            /*if (value != null)
                             *  if (false == strutsConfigXml.resolvedViews.ContainsKey(titleDefinition.name))
                             *      strutsConfigXml.resolvedViews.Add(titleDefinition.name, value);
                             *  else
                             *      DI.log.error("in mapping TilesDefinition, there was a duplicate key: {0} with value {1}",
                             *                  titleDefinition.name, value);
                             */
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                DI.log.error("in getStrutsConfig: {0}", ex.Message);
            }
            return(strutsConfigXml);
        }