Esempio n. 1
0
        public static List <Field> ReadXmlForList(XmlElement rootEle)
        {
            List <Field>      fieldList    = SchemaFactory.CreateEmptyFieldList();
            List <XmlElement> fieldElmList = XmlUtils.GetChildElements(rootEle, "field");

            foreach (XmlElement fieldElm in fieldElmList)
            {
                Field field = ElementToField(fieldElm);
                fieldList.Add(field);
            }
            return(fieldList);
        }
Esempio n. 2
0
        private static InputField ElementToInputField(XmlElement fieldElm, string fieldId, string fieldName)
        {
            if (fieldElm == null)
            {
                return(null);
            }
            InputField inputField = (InputField)SchemaFactory.CreateField(FieldTypeEnum.INPUT);

            inputField.Id   = fieldId;
            inputField.Name = fieldName;
            //rules
            XmlElement rulesEle = XmlUtils.GetChildElement(fieldElm, "rules");

            if (rulesEle != null)
            {
                List <XmlElement> ruleEleList = XmlUtils.GetChildElements(rulesEle, "rule");
                foreach (XmlElement ruleEle in ruleEleList)
                {
                    Rule rule = ElementToRule(ruleEle, inputField.Id);
                    inputField.Add(rule);
                }
            }
            //property
            XmlElement propertiesEle = XmlUtils.GetChildElement(fieldElm, "properties");

            if (propertiesEle != null)
            {
                List <XmlElement> propertyEleList = XmlUtils.GetChildElements(propertiesEle, "property");
                foreach (XmlElement propertyEle in propertyEleList)
                {
                    Property.Property property = ElementToProperty(propertyEle, inputField.Id);
                    inputField.Add(property);
                }
            }
            //defaultValue
            XmlElement defaultValueEle = XmlUtils.GetChildElement(fieldElm, "default-value");

            if (defaultValueEle != null)
            {
                String dvalue = defaultValueEle.InnerText;
                inputField.SetDefaultValue(dvalue);
            }
            //value
            XmlElement value = XmlUtils.GetChildElement(fieldElm, "value");

            if (value != null)
            {
                inputField.Value = XmlUtils.GetElementValue(value);
            }
            return(inputField);
        }
Esempio n. 3
0
        private static LabelField ElementToLabelField(XmlElement fieldElm, string fieldId, string fieldName)
        {
            if (fieldElm == null)
            {
                return(null);
            }
            LabelField labelField = (LabelField)SchemaFactory.CreateField(FieldTypeEnum.LABEL);

            labelField.Id   = fieldId;
            labelField.Name = fieldName;
            //rules
            XmlElement rulesEle = XmlUtils.GetChildElement(fieldElm, "rules");

            if (rulesEle != null)
            {
                List <XmlElement> ruleEleList = XmlUtils.GetChildElements(rulesEle, "rule");
                foreach (XmlElement ruleEle in ruleEleList)
                {
                    Rule rule = ElementToRule(ruleEle, labelField.Id);
                    labelField.Add(rule);
                }
            }
            //property
            XmlElement propertiesEle = XmlUtils.GetChildElement(fieldElm, "properties");

            if (propertiesEle != null)
            {
                List <XmlElement> propertyEleList = XmlUtils.GetChildElements(propertiesEle, "property");
                foreach (XmlElement propertyEle in propertyEleList)
                {
                    Property.Property property = ElementToProperty(propertyEle, labelField.Id);
                    labelField.Add(property);
                }
            }
            //labelGroup
            XmlElement labelGroupEle = XmlUtils.GetChildElement(fieldElm, "label-group");

            if (labelGroupEle != null)
            {
                LabelGroup labelGroup = ElementToLabelGroup(labelGroupEle, fieldId);
                labelField.SetLabelGroup(labelGroup);
            }
            return(labelField);
        }
Esempio n. 4
0
        /**
         * xml Element to Rule
         * @param ruleEle
         * @param fieldId
         * @return
         * @throws TopSchemaException
         */
        private static Rule ElementToRule(XmlElement ruleEle, string fieldId)
        {
            if (ruleEle == null)
            {
                return(null);
            }
            String ruleName = XmlUtils.GetAttributeValue(ruleEle, "name");

            if (StringUtil.IsEmpty(ruleName))
            {
                throw new TopSchemaException(TopSchemaErrorCodeEnum.ERROR_CODE_31001, fieldId);
            }
            String ruleValue = XmlUtils.GetAttributeValue(ruleEle, "value");

            if (StringUtil.IsEmpty(ruleValue))
            {
                throw new TopSchemaException(TopSchemaErrorCodeEnum.ERROR_CODE_31002, fieldId);
            }

            Rule         rule     = null;
            RuleTypeEnum ruleEnum = RuleTypeEnumHelper.GetEnum(ruleName);

            if (ruleEnum != RuleTypeEnum.UNKNOWN)
            {
                rule = SchemaFactory.CreateRule(ruleEnum);
            }
            else
            {
                rule = SchemaFactory.CreateCustomRule(ruleName, ruleValue);
            }

            if (ruleName.Equals(RuleTypeEnumHelper.ToType(RuleTypeEnum.TIP_RULE)) && !StringUtil.IsEmpty(ruleValue))
            {
                String url = XmlUtils.GetAttributeValue(ruleEle, "url");
                ((TipRule)rule).Url = url;
            }
            if (ruleName.Equals(RuleTypeEnumHelper.ToType(RuleTypeEnum.DEV_TIP_RULE)) && !StringUtil.IsEmpty(ruleValue))
            {
                String url = XmlUtils.GetAttributeValue(ruleEle, "url");
                ((DevTipRule)rule).Url = url;
            }

            String unit = XmlUtils.GetAttributeValue(ruleEle, "unit");

            if (ruleName.Equals(RuleTypeEnumHelper.ToType(RuleTypeEnum.MAX_TARGET_SIZE_RULE)) &&
                !StringUtil.IsEmpty(ruleValue))
            {
                MaxTargetSizeRule mtsRule = (MaxTargetSizeRule)rule;
                mtsRule.Unit = unit;
            }
            else if (ruleName.Equals(RuleTypeEnumHelper.ToType(RuleTypeEnum.MIN_TARGET_SIZE_RULE)) &&
                     !StringUtil.IsEmpty(ruleValue))
            {
                MinTargetSizeRule misRule = (MinTargetSizeRule)rule;
                misRule.Unit = unit;
            }

            String exProperty = XmlUtils.GetAttributeValue(ruleEle, "exProperty");

            if (!StringUtil.IsEmpty(exProperty))
            {
                rule.ExProperty = exProperty;
            }
            rule.Value = ruleValue;
            XmlElement  dependGroupEle = XmlUtils.GetChildElement(ruleEle, "depend-group");
            DependGroup dependGroup    = ElementToDependGroup(dependGroupEle, fieldId);

            rule.DependGroup = dependGroup;
            return(rule);
        }
Esempio n. 5
0
        private static ComplexField ElementToComplexField(XmlElement fieldElm, string fieldId, string fieldName)
        {
            if (fieldElm == null)
            {
                return(null);
            }
            ComplexField complexField = (ComplexField)SchemaFactory.CreateField(FieldTypeEnum.COMPLEX);

            complexField.Id   = fieldId;
            complexField.Name = fieldName;
            XmlElement fieldsEle = XmlUtils.GetChildElement(fieldElm, "fields");

            if (fieldsEle != null)
            {
                List <XmlElement> fieldEleList = XmlUtils.GetChildElements(fieldsEle, "field");
                foreach (XmlElement subFieldEle in fieldEleList)
                {
                    Field fieldFromEle = ElementToField(subFieldEle);
                    complexField.Add(fieldFromEle);
                }
            }
            //rules
            XmlElement rulesEle = XmlUtils.GetChildElement(fieldElm, "rules");

            if (rulesEle != null)
            {
                List <XmlElement> ruleEleList = XmlUtils.GetChildElements(rulesEle, "rule");
                foreach (XmlElement ruleEle in ruleEleList)
                {
                    Rule rule = ElementToRule(ruleEle, complexField.Id);
                    complexField.Add(rule);
                }
            }
            //property
            XmlElement propertiesEle = XmlUtils.GetChildElement(fieldElm, "properties");

            if (propertiesEle != null)
            {
                List <XmlElement> propertyEleList = XmlUtils.GetChildElements(propertiesEle, "property");
                foreach (XmlElement propertyEle in propertyEleList)
                {
                    Property.Property property = ElementToProperty(propertyEle, complexField.Id);
                    complexField.Add(property);
                }
            }
            //default-complex-value
            XmlElement defaultComplexValueEle = XmlUtils.GetChildElement(fieldElm, "default-complex-values");

            if (defaultComplexValueEle != null)
            {
                List <XmlElement> defaultValuesSubFieldList = XmlUtils.GetChildElements(defaultComplexValueEle, "field");
                ComplexValue      defaultCvalue             = new ComplexValue();
                foreach (XmlElement subFiledValueEle in defaultValuesSubFieldList)
                {
                    Field field = ElementToField(subFiledValueEle);
                    defaultCvalue.Put(field);
                }
                complexField.SetDefaultValue(defaultCvalue);
            }
            //complex-value
            XmlElement complexValueEle = XmlUtils.GetChildElement(fieldElm, "complex-values");

            if (complexValueEle != null)
            {
                List <XmlElement> valuesSubFieldList = XmlUtils.GetChildElements(complexValueEle, "field");
                ComplexValue      cvalue             = new ComplexValue();
                foreach (XmlElement subFiledValueEle in valuesSubFieldList)
                {
                    Field field = ElementToField(subFiledValueEle);
                    cvalue.Put(field);
                }
                complexField.SetComplexValue(cvalue);
            }
            return(complexField);
        }
Esempio n. 6
0
        private static MultiCheckField ElementToMultiCheckField(XmlElement fieldElm, string fieldId, string fieldName)
        {
            if (fieldElm == null)
            {
                return(null);
            }
            MultiCheckField multiCheckField = (MultiCheckField)SchemaFactory.CreateField(FieldTypeEnum.MULTICHECK);

            multiCheckField.Id   = fieldId;
            multiCheckField.Name = fieldName;
            //rules
            XmlElement rulesEle = XmlUtils.GetChildElement(fieldElm, "rules");

            if (rulesEle != null)
            {
                List <XmlElement> ruleEleList = XmlUtils.GetChildElements(rulesEle, "rule");
                foreach (XmlElement ruleEle in ruleEleList)
                {
                    Rule rule = ElementToRule(ruleEle, multiCheckField.Id);
                    multiCheckField.Add(rule);
                }
            }
            //option
            XmlElement optionsEle = XmlUtils.GetChildElement(fieldElm, "options");

            if (optionsEle != null)
            {
                List <XmlElement> optionEleList = XmlUtils.GetChildElements(optionsEle, "option");
                foreach (XmlElement optionEleEle in optionEleList)
                {
                    Option op = ElementToOption(optionEleEle, multiCheckField.Id);
                    multiCheckField.Add(op);
                }
            }
            //property
            XmlElement propertiesEle = XmlUtils.GetChildElement(fieldElm, "properties");

            if (propertiesEle != null)
            {
                List <XmlElement> propertyEleList = XmlUtils.GetChildElements(propertiesEle, "property");
                foreach (XmlElement propertyEle in propertyEleList)
                {
                    Property.Property property = ElementToProperty(propertyEle, multiCheckField.Id);
                    multiCheckField.Add(property);
                }
            }
            //defaultValue
            XmlElement defaultValuesEle = XmlUtils.GetChildElement(fieldElm, "default-values");

            if (defaultValuesEle != null)
            {
                List <XmlElement> defaultValueEleList = XmlUtils.GetChildElements(defaultValuesEle, "default-value");
                foreach (XmlElement defaultValueEle in defaultValueEleList)
                {
                    Value  value  = new Value();
                    String dvalue = defaultValueEle.InnerText;
                    value.PropertyValue = dvalue;
                    multiCheckField.AddDefaultValueDO(value);
                }
            }
            //value
            XmlElement valuesEle = XmlUtils.GetChildElement(fieldElm, "values");

            if (valuesEle != null)
            {
                List <XmlElement> valueEleList = XmlUtils.GetChildElements(valuesEle, "value");
                foreach (XmlElement valueEle in valueEleList)
                {
                    Value value = new Value();
                    value.PropertyValue = XmlUtils.GetElementValue(valueEle);
                    multiCheckField.AddValue(value);
                }
            }
            return(multiCheckField);
        }