/// <exception cref="XmpException"/> public IXmpProperty GetQualifier(string schemaNs, string propName, string qualNs, string qualName) { // qualNS and qualName are checked inside composeQualfierPath ParameterAsserts.AssertSchemaNs(schemaNs); ParameterAsserts.AssertPropName(propName); var qualPath = propName + XmpPathFactory.ComposeQualifierPath(qualNs, qualName); return(GetProperty(schemaNs, qualPath)); }
/// <exception cref="XmpException"/> public void SetQualifier(string schemaNs, string propName, string qualNs, string qualName, string qualValue, PropertyOptions options) { ParameterAsserts.AssertSchemaNs(schemaNs); ParameterAsserts.AssertPropName(propName); if (!DoesPropertyExist(schemaNs, propName)) { throw new XmpException("Specified property does not exist!", XmpErrorCode.BadXPath); } var qualPath = propName + XmpPathFactory.ComposeQualifierPath(qualNs, qualName); SetProperty(schemaNs, qualPath, qualValue, options); }
public void DeleteQualifier(string schemaNs, string propName, string qualNs, string qualName) { try { // Note: qualNS and qualName are checked inside composeQualfierPath ParameterAsserts.AssertSchemaNs(schemaNs); ParameterAsserts.AssertPropName(propName); var qualPath = propName + XmpPathFactory.ComposeQualifierPath(qualNs, qualName); DeleteProperty(schemaNs, qualPath); } catch (XmpException) { } }
public bool DoesQualifierExist(string schemaNs, string propName, string qualNs, string qualName) { try { // qualNS and qualName are checked inside composeQualifierPath() ParameterAsserts.AssertSchemaNs(schemaNs); ParameterAsserts.AssertPropName(propName); var path = XmpPathFactory.ComposeQualifierPath(qualNs, qualName); return(DoesPropertyExist(schemaNs, propName + path)); } catch (XmpException) { return(false); } }
public bool DoesPropertyExist(string schemaNs, string propName) { try { ParameterAsserts.AssertSchemaNs(schemaNs); ParameterAsserts.AssertPropName(propName); var expPath = XmpPathParser.ExpandXPath(schemaNs, propName); var propNode = XmpNodeUtils.FindNode(_tree, expPath, false, null); return(propNode != null); } catch (XmpException) { return(false); } }
/// <summary>Associates an alias name with an actual name.</summary> /// <remarks> /// Associates an alias name with an actual name. /// <para /> /// Define a alias mapping from one namespace/property to another. Both /// property names must be simple names. An alias can be a direct mapping, /// where the alias and actual have the same data type. It is also possible /// to map a simple alias to an item in an array. This can either be to the /// first item in the array, or to the 'x-default' item in an alt-text array. /// Multiple alias names may map to the same actual, as long as the forms /// match. It is a no-op to reregister an alias in an identical fashion. /// Note: This method is not locking because only called by registerStandardAliases /// which is only called by the constructor. /// Note2: The method is only package-private so that it can be tested with unittests /// </remarks> /// <param name="aliasNs">The namespace URI for the alias. Must not be null or the empty string.</param> /// <param name="aliasProp">The name of the alias. Must be a simple name, not null or the empty string and not a general path expression.</param> /// <param name="actualNs">The namespace URI for the actual. Must not be null or the empty string.</param> /// <param name="actualProp">The name of the actual. Must be a simple name, not null or the empty string and not a general path expression.</param> /// <param name="aliasForm">Provides options for aliases for simple aliases to array items. This is needed to know what kind of array to create if /// set for the first time via the simple alias. Pass <c>XMP_NoOptions</c>, the default value, for all direct aliases regardless of whether the actual /// data type is an array or not (see <see cref="AliasOptions"/>).</param> /// <exception cref="XmpException">for inconsistant aliases.</exception> private void RegisterAlias(string aliasNs, string aliasProp, string actualNs, string actualProp, AliasOptions aliasForm) { lock (_lock) { ParameterAsserts.AssertSchemaNs(aliasNs); ParameterAsserts.AssertPropName(aliasProp); ParameterAsserts.AssertSchemaNs(actualNs); ParameterAsserts.AssertPropName(actualProp); // FfF: if we need the decoration with [1] or // FfF: [?xml:lang="x-default"] for array forms // Fix the alias options var aliasOpts = aliasForm != null ? new AliasOptions(XmpNodeUtils.VerifySetOptions(aliasForm.ToPropertyOptions(), null).GetOptions()) : new AliasOptions(); if (_p.IsMatch(aliasProp) || _p.IsMatch(actualProp)) { throw new XmpException("Alias and actual property names must be simple", XmpErrorCode.BadXPath); } // check if both namespaces are registered var aliasPrefix = GetNamespacePrefix(aliasNs); var actualPrefix = GetNamespacePrefix(actualNs); if (aliasPrefix == null) { throw new XmpException("Alias namespace is not registered", XmpErrorCode.BadSchema); } if (actualPrefix == null) { throw new XmpException("Actual namespace is not registered", XmpErrorCode.BadSchema); } var key = aliasPrefix + aliasProp; // check if alias is already existing if (_aliasMap.ContainsKey(key)) { throw new XmpException("Alias is already existing", XmpErrorCode.BadParam); } if (_aliasMap.ContainsKey(actualPrefix + actualProp)) { throw new XmpException("Actual property is already an alias, use the base property", XmpErrorCode.BadParam); } _aliasMap[key] = new XmpAliasInfo(actualNs, actualPrefix, actualProp, aliasOpts); } }
/// <exception cref="XmpException"/> public void SetProperty(string schemaNs, string propName, object propValue, PropertyOptions options) { ParameterAsserts.AssertSchemaNs(schemaNs); ParameterAsserts.AssertPropName(propName); options = XmpNodeUtils.VerifySetOptions(options, propValue); var expPath = XmpPathParser.ExpandXPath(schemaNs, propName); var propNode = XmpNodeUtils.FindNode(_tree, expPath, true, options); if (propNode != null) { SetNode(propNode, propValue, options, false); } else { throw new XmpException("Specified property does not exist", XmpErrorCode.BadXPath); } }
/// <summary>Returns a property, but the result value can be requested.</summary> /// <param name="schemaNs">a schema namespace</param> /// <param name="propName">a property name or path</param> /// <param name="valueType">the type of the value, see VALUE_...</param> /// <returns> /// Returns the node value as an object according to the /// <c>valueType</c>. /// </returns> /// <exception cref="XmpException">Collects any exception that occurs.</exception> private object GetPropertyObject(string schemaNs, string propName, ValueType valueType) { ParameterAsserts.AssertSchemaNs(schemaNs); ParameterAsserts.AssertPropName(propName); var expPath = XmpPathParser.ExpandXPath(schemaNs, propName); var propNode = XmpNodeUtils.FindNode(_tree, expPath, false, null); if (propNode != null) { if (valueType != ValueType.String && propNode.Options.IsCompositeProperty) { throw new XmpException("Property must be simple when a value type is requested", XmpErrorCode.BadXPath); } return(EvaluateNodeValue(valueType, propNode)); } return(null); }
public void DeleteProperty(string schemaNs, string propName) { try { ParameterAsserts.AssertSchemaNs(schemaNs); ParameterAsserts.AssertPropName(propName); var expPath = XmpPathParser.ExpandXPath(schemaNs, propName); var propNode = XmpNodeUtils.FindNode(_tree, expPath, false, null); if (propNode != null) { XmpNodeUtils.DeleteNode(propNode); } } catch (XmpException) { } }