/// /// <summary> * set all separation names in the SeparationSpec elements, remove any prior elements /// * </summary> /// * <param name="vSeps"> the vector of separation names to set </param> /// public virtual void setSeparations(VString vSeps) { removeChildren(ElementName.SEPARATIONSPEC, null, null); if (vSeps == null) { return; } for (int i = 0; i < vSeps.Count; i++) { appendSeparation(vSeps.stringAt(i)); } }
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); } }
/// /// <summary> * version fixing routine for JDF /// * /// * uses heuristics to modify this element and its children to be compatible with a given version in general, it will /// * be able to move from low to high versions but potentially fail when attempting to move from higher to lower /// * versions /// * </summary> /// * <param name="version"> : version that the resulting element should correspond to </param> /// * <returns> true if successful </returns> /// public override bool fixVersion(EnumVersion version) { if (version != null) { int @value = version.getValue(); if (@value >= EnumVersion.Version_1_3.getValue()) { appendAnchor(null); } else { removeAttribute(AttributeName.ID); // TODO fix agentname and agentversion } string author = getAuthor(); if (@value <= EnumVersion.Version_1_1.getValue()) { string tmp = getAgentName(); bool b = false; if (tmp.Length != 0) { author += "_|_" + tmp; b = true; } tmp = getAgentVersion(); if (tmp.Length != 0) { if (!b) { author += "_|_ "; } author += "_|_" + tmp; b = true; } removeAttribute(AttributeName.AGENTNAME); removeAttribute(AttributeName.AGENTVERSION); if (b) { setAuthor(author); } } else if (author.Length > 0) // version>=1.2 and has author { VString tokens = new VString(StringUtil.tokenize(author, "_|_", false)); if (tokens.Count == 3) { // it was previously fixed string tmp = tokens.stringAt(0); if (!tmp.Equals(JDFConstants.EMPTYSTRING) && !tmp.Equals(JDFConstants.BLANK)) { setAuthor(tmp); } tmp = tokens.stringAt(1); if (!tmp.Equals(JDFConstants.EMPTYSTRING) && !tmp.Equals(JDFConstants.BLANK)) { setAgentName(tmp); } tmp = tokens.stringAt(2); if (!tmp.Equals(JDFConstants.EMPTYSTRING) && !tmp.Equals(JDFConstants.BLANK)) { setAgentVersion(tmp); } } } } return(base.fixVersion(version)); }