Example #1
0
 public virtual ValuedEnum getEnum(string @value)
 {
     try
     {
         System.Type[] methodArgs = { typeof(string) };
         MethodInfo    m          = getEnumType().GetType().GetMethod("getEnum", methodArgs);
         object[]      args       = { @value };
         ValuedEnum    ve         = (ValuedEnum)m.Invoke(null, args);
         return(ve);
     }
     catch (System.Security.SecurityException)
     {
         // in case of exceptions, simply apply NMTOKENS rule
     }
     catch (MethodAccessException)
     {
         // in case of exceptions, simply apply NMTOKENS rule
     }
     catch (ArgumentException)
     {
         // in case of exceptions, simply apply NMTOKENS rule
     }
     catch (UnauthorizedAccessException)
     {
         // in case of exceptions, simply apply NMTOKENS rule
     }
     catch (System.Reflection.TargetInvocationException)
     {
         // in case of exceptions, simply apply NMTOKENS rule
     }
     return(null);
 }
Example #2
0
        ///
        ///	 <summary> * checks whether the value of an enum is less or equal to another
        ///	 *  </summary>
        ///	 * <param name="a"> the first enum; if this is smaller we return true </param>
        ///	 * <param name="b"> the second enum </param>
        ///	 * <returns> boolean a is < b </returns>
        ///
        public static bool aLessEqualsThanB(ValuedEnum a, ValuedEnum b)
        {
            int aa = a == null ? -1 : a.getValue();
            int bb = b == null ? -1 : b.getValue();

            return(aa <= bb);
        }
Example #3
0
 public AtrInfo(long s, AttributeInfo.EnumAttributeType t, ValuedEnum e)
 {
     atrValidityStatus = s;
     atrType           = t;
     enumEnum          = e;
     atrDefault        = null;
 }
Example #4
0
 ///
 ///	 <summary> * get the lower of two enum values, null is lowest
 ///	 *  </summary>
 ///	 * <param name="e1"> </param>
 ///	 * <param name="e2"> </param>
 ///	 * <returns> the lower of the two values </returns>
 ///
 public static ValuedEnum min(ValuedEnum e1, ValuedEnum e2)
 {
     if (e1 == null || e2 == null)
     {
         return(null);
     }
     return(e1.getValue() < e2.getValue() ? e1 : e2);
 }
Example #5
0
 ///
 ///	 <summary> * get the higher of two enum values, null is lowest
 ///	 *  </summary>
 ///	 * <param name="e1"> </param>
 ///	 * <param name="e2"> </param>
 ///	 * <returns> the higher of the two values </returns>
 ///
 public static ValuedEnum max(ValuedEnum e1, ValuedEnum e2)
 {
     if (e1 == null)
     {
         return(e2);
     }
     if (e2 == null)
     {
         return(e1);
     }
     return(e1.getValue() > e2.getValue() ? e1 : e2);
 }
Example #6
0
        public virtual bool validAttribute(string key, string attribute, KElement.EnumValidationLevel level)
        {
            EnumAttributeType typ = getAttributeType(key);

            if (typ == null) // unknown attributes are by definition valid, the
            // check is done in the unknown method
            {
                return(true);
            }

            // get the correct enumeration lists
            ValuedEnum enu = null;

            if ((typ == EnumAttributeType.enumeration) || (typ == EnumAttributeType.enumerations))
            {
                enu = getAttributeEnum(key);
            }
            else if (typ == EnumAttributeType.JDFJMFVersion)
            {
                enu = EnumVersion.getEnum(0);
            }

            EnumAttributeValidity val = getAttributeValidity(key);

            if (val == EnumAttributeValidity.Unknown)
            {
                return(attribute == null);
            }
            else if (val == EnumAttributeValidity.Deprecated)
            {
                return((attribute == null) || EnumValidationLevel.isNoWarn(level));
            }
            else if (val == EnumAttributeValidity.None) // prerelease may be set
            // by schema validating
            // parser
            {
                return((attribute == null) || attribute.Equals(getAttributeDefault(key)) || EnumValidationLevel.isNoWarn(level));
            }
            else if ((val == EnumAttributeValidity.Optional) || ((level != EnumValidationLevel.Complete) && (level != EnumValidationLevel.RecursiveComplete)))
            {
                return((attribute == null) || validStringForType(attribute, typ, enu));
            }
            else if (val == EnumAttributeValidity.Required)
            {
                return((attribute != null) && validStringForType(attribute, typ, enu));
            }

            return(true);
        }
Example #7
0
 ///
 ///	 <summary> * null save convenience name getter
 ///	 *  </summary>
 ///	 * <param name="en"> the enum to get the name
 ///	 * @return </param>
 ///
 public static string getName(ValuedEnum en)
 {
     return(en == null ? "null" : en.getName());
 }
Example #8
0
        ///
        ///	 * <param name="n"> </param>
        ///	 * <param name="s"> </param>
        ///	 * <param name="t"> </param>
        ///	 * <param name="e"> </param>
        ///

        public AtrInfoTable(string n, long s, AttributeInfo.EnumAttributeType t, ValuedEnum e, string def)
        {
            attributeName = n;
            info          = new AtrInfo(s, t, e, def);
        }
Example #9
0
 ///
 ///	 <summary> * utility constructor to construct a single value map
 ///	 *  </summary>
 ///	 * <param name="key"> the key of the single value map </param>
 ///	 * <param name="value"> the value of the single value map </param>
 ///
 public JDFAttributeMap(string key, ValuedEnum value)
 {
     put(key, value.getName());
 }
Example #10
0
 ///
 ///	 <summary> * Set attribute Preferred
 ///	 *  </summary>
 ///	 * <param name="int"> value - the enumeration equivalent of value to set </param>
 ///
 public virtual void setPreferred(ValuedEnum @value)
 {
     setAttribute(AttributeName.PREFERRED, @value.getName(), null);
 }
Example #11
0
 ///
 ///	 <summary> * Set attribute Actual
 ///	 *  </summary>
 ///	 * <param name="int"> value - the value to set </param>
 ///
 public virtual void setActual(ValuedEnum @value)
 {
     setAttribute(AttributeName.ACTUAL, @value.getName(), null);
 }
Example #12
0
        public static bool validStringForType(string val, EnumAttributeType iType, ValuedEnum enu)
        {
            if (val == null)
            {
                return(false);
            }

            try
            {
                if (iType == AttributeInfo.EnumAttributeType.Any)
                {
                    return(true);
                }
                if (iType == AttributeInfo.EnumAttributeType.string_)
                {
                    return(val.Length < 1024);
                }
                if (iType == AttributeInfo.EnumAttributeType.shortString)
                {
                    return(val.Length < 64);
                }
                if (iType == AttributeInfo.EnumAttributeType.ID)
                {
                    return(StringUtil.isID(val));
                }
                if (iType == AttributeInfo.EnumAttributeType.NMTOKEN)
                {
                    return(StringUtil.isNMTOKEN(val));
                }
                if (iType == AttributeInfo.EnumAttributeType.NMTOKENS)
                {
                    return(StringUtil.isNMTOKENS(val, false));
                }
                if (iType == AttributeInfo.EnumAttributeType.IDREF)
                {
                    return(StringUtil.isID(val));
                }
                if (iType == AttributeInfo.EnumAttributeType.IDREFS)
                {
                    return(StringUtil.isNMTOKENS(val, true));
                }
                if (iType == AttributeInfo.EnumAttributeType.boolean_)
                {
                    return(StringUtil.isBoolean(val));
                }
                if (iType == AttributeInfo.EnumAttributeType.double_)
                {
                    return(StringUtil.isNumber(val));
                }
                if (iType == AttributeInfo.EnumAttributeType.integer)
                {
                    return(StringUtil.isInteger(val));
                }
                // integer or unbounded
                if (iType == AttributeInfo.EnumAttributeType.unbounded)
                {
                    return(JDFConstants.UNBOUNDED.Equals(val) || StringUtil.isInteger(val));
                }

                if ((iType == AttributeInfo.EnumAttributeType.URI) || (iType == AttributeInfo.EnumAttributeType.URL))
                {
                    return(UrlUtil.isIRL(val));
                }
                else if (iType == AttributeInfo.EnumAttributeType.RegExp)
                {
                    return(true);
                }

                else if ((iType == AttributeInfo.EnumAttributeType.enumeration) || (iType == AttributeInfo.EnumAttributeType.JDFJMFVersion))
                {
                    if (enu != null)
                    {
                        ValuedEnum ve = (ValuedEnum)EnumUtils.getEnum(enu.GetType(), val);
                        return(ve != null);
                    }
                    // limp along if something went wrong
                    return(StringUtil.isNMTOKEN(val));
                }
                else if (iType == AttributeInfo.EnumAttributeType.enumerations)
                {
                    if (enu != null)
                    {
                        VString vs = new VString(StringUtil.tokenize(val, JDFConstants.BLANK, false));
                        for (int i = 0; i < vs.Count; i++)
                        {
                            ValuedEnum ve = (ValuedEnum)EnumUtils.getEnum(enu.GetType(), vs.stringAt(i));
                            // there was an invalid token
                            if (ve == null)
                            {
                                return(false);
                            }
                        }
                        // all were ok
                        return(true);
                    }
                    // limp along if something went wrong
                    return(StringUtil.isNMTOKENS(val, false));
                }
                else if (iType == AttributeInfo.EnumAttributeType.IntegerRange)
                {
                    new JDFIntegerRange(val);
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.IntegerList)
                {
                    new JDFIntegerList(val);
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.IntegerRangeList)
                {
                    new JDFIntegerRangeList(val);
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.NumberRange)
                {
                    new JDFNumberRange(val);
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.NumberRangeList)
                {
                    new JDFNumberRangeList(val);
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.NumberList)
                {
                    new JDFNumberList(val);
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.matrix)
                {
                    new JDFMatrix(val);
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.rectangle)
                {
                    new JDFRectangle(val);
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.shape)
                {
                    new JDFShape(val);
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.XYPair)
                {
                    new JDFXYPair(val);
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.XYPairRange)
                {
                    new JDFXYPairRange(val);
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.XYPairRangeList)
                {
                    new JDFXYPairRangeList(val);
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.dateTime)
                {
                    new JDFDate(val);
                    return(val.IndexOf("T") == 10); // pure dates are not valid
                }
                else if (iType == AttributeInfo.EnumAttributeType.duration)
                {
                    new JDFDuration(val);
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.DurationRangeList)
                {
                    new JDFDurationRangeList(val);
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.DateTimeRangeList)
                {
                    new JDFDateTimeRangeList(val);
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.RectangleRangeList)
                {
                    new JDFRectangleRangeList(val);
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.ShapeRangeList)
                {
                    new JDFShapeRangeList(val);
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.CMYKColor)
                {
                    new JDFCMYKColor(val);
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.LabColor)
                {
                    new JDFLabColor(val);
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.RGBColor)
                {
                    new JDFRGBColor(val);
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.language)
                {
                    return(validLanguageString(val));
                }
                else if (iType == AttributeInfo.EnumAttributeType.languages)
                {
                    VString v = new VString(StringUtil.tokenize(val, JDFConstants.BLANK, false));
                    for (int i = 0; i < v.Count; i++)
                    {
                        if (!validLanguageString(v[i]))
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.PDFPath)
                {
                    // TODO better regexp
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.XPath)
                {
                    // TODO better regexp
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.hexBinary)
                {
                    return(StringUtil.matches(val, JDFConstants.REGEXP_HEXBINARY));
                }
                else if (iType == AttributeInfo.EnumAttributeType.TransferFunction)
                {
                    JDFNumberList nl = new JDFNumberList(val);
                    return(nl.Count % 2 == 0);
                }
                else
                {
                    // TODO check if we are complete
                    Console.WriteLine("validStringForType: unknown type:" + iType.getName());
                    return(false);
                }
            }
            catch (FormatException)
            {
                return(false);
            }
        }