示例#1
0
        /// <summary>Find or create a schema node if <code>createNodes</code> is true.</summary>
        /// <param name="tree">the root of the xmp tree.</param>
        /// <param name="namespaceURI">a namespace</param>
        /// <param name="suggestedPrefix">If a prefix is suggested, the namespace is allowed to be registered.</param>
        /// <param name="createNodes">
        /// a flag indicating if the node shall be created if not found.
        /// <em>Note:</em> The namespace must be registered prior to this call.
        /// </param>
        /// <returns>
        /// Returns the schema node if found, <code>null</code> otherwise.
        /// Note: If <code>createNodes</code> is <code>true</code>, it is <b>always</b>
        /// returned a valid node.
        /// </returns>
        /// <exception cref="Com.Adobe.Xmp.XMPException">
        /// An exception is only thrown if an error occurred, not if a
        /// node was not found.
        /// </exception>
        internal static XMPNode FindSchemaNode(XMPNode tree, string namespaceURI, string suggestedPrefix, bool createNodes)
        {
            System.Diagnostics.Debug.Assert(tree.GetParent() == null);
            // make sure that its the root
            XMPNode schemaNode = tree.FindChildByName(namespaceURI);

            if (schemaNode == null && createNodes)
            {
                schemaNode = new XMPNode(namespaceURI, new PropertyOptions().SetSchemaNode(true));
                schemaNode.SetImplicit(true);
                // only previously registered schema namespaces are allowed in the XMP tree.
                string prefix = XMPMetaFactory.GetSchemaRegistry().GetNamespacePrefix(namespaceURI);
                if (prefix == null)
                {
                    if (suggestedPrefix != null && suggestedPrefix.Length != 0)
                    {
                        prefix = XMPMetaFactory.GetSchemaRegistry().RegisterNamespace(namespaceURI, suggestedPrefix);
                    }
                    else
                    {
                        throw new XMPException("Unregistered schema namespace URI", XMPErrorConstants.Badschema);
                    }
                }
                schemaNode.SetValue(prefix);
                tree.AddChild(schemaNode);
            }
            return(schemaNode);
        }
示例#2
0
        /// <summary>Find or create a child node under a given parent node.</summary>
        /// <remarks>
        /// Find or create a child node under a given parent node. If the parent node is no
        /// Returns the found or created child node.
        /// </remarks>
        /// <param name="parent">the parent node</param>
        /// <param name="childName">the node name to find</param>
        /// <param name="createNodes">flag, if new nodes shall be created.</param>
        /// <returns>Returns the found or created node or <code>null</code>.</returns>
        /// <exception cref="Com.Adobe.Xmp.XMPException">Thrown if</exception>
        internal static XMPNode FindChildNode(XMPNode parent, string childName, bool createNodes)
        {
            if (!parent.GetOptions().IsSchemaNode() && !parent.GetOptions().IsStruct())
            {
                if (!parent.IsImplicit())
                {
                    throw new XMPException("Named children only allowed for schemas and structs", XMPErrorConstants.Badxpath);
                }
                else
                {
                    if (parent.GetOptions().IsArray())
                    {
                        throw new XMPException("Named children not allowed for arrays", XMPErrorConstants.Badxpath);
                    }
                    else
                    {
                        if (createNodes)
                        {
                            parent.GetOptions().SetStruct(true);
                        }
                    }
                }
            }
            XMPNode childNode = parent.FindChildByName(childName);

            if (childNode == null && createNodes)
            {
                PropertyOptions options = new PropertyOptions();
                childNode = new XMPNode(childName, options);
                childNode.SetImplicit(true);
                parent.AddChild(childNode);
            }
            System.Diagnostics.Debug.Assert(childNode != null || !createNodes);
            return(childNode);
        }
		/// <summary>Find or create a schema node if <code>createNodes</code> is true.</summary>
		/// <param name="tree">the root of the xmp tree.</param>
		/// <param name="namespaceURI">a namespace</param>
		/// <param name="suggestedPrefix">If a prefix is suggested, the namespace is allowed to be registered.</param>
		/// <param name="createNodes">
		/// a flag indicating if the node shall be created if not found.
		/// <em>Note:</em> The namespace must be registered prior to this call.
		/// </param>
		/// <returns>
		/// Returns the schema node if found, <code>null</code> otherwise.
		/// Note: If <code>createNodes</code> is <code>true</code>, it is <b>always</b>
		/// returned a valid node.
		/// </returns>
		/// <exception cref="Com.Adobe.Xmp.XMPException">
		/// An exception is only thrown if an error occurred, not if a
		/// node was not found.
		/// </exception>
		internal static XMPNode FindSchemaNode(XMPNode tree, string namespaceURI, string suggestedPrefix, bool createNodes)
		{
			System.Diagnostics.Debug.Assert(tree.GetParent() == null);
			// make sure that its the root
			XMPNode schemaNode = tree.FindChildByName(namespaceURI);
			if (schemaNode == null && createNodes)
			{
				schemaNode = new XMPNode(namespaceURI, new PropertyOptions().SetSchemaNode(true));
				schemaNode.SetImplicit(true);
				// only previously registered schema namespaces are allowed in the XMP tree.
				string prefix = XMPMetaFactory.GetSchemaRegistry().GetNamespacePrefix(namespaceURI);
				if (prefix == null)
				{
					if (suggestedPrefix != null && suggestedPrefix.Length != 0)
					{
						prefix = XMPMetaFactory.GetSchemaRegistry().RegisterNamespace(namespaceURI, suggestedPrefix);
					}
					else
					{
						throw new XMPException("Unregistered schema namespace URI", XMPErrorConstants.Badschema);
					}
				}
				schemaNode.SetValue(prefix);
				tree.AddChild(schemaNode);
			}
			return schemaNode;
		}
 /// <summary>Find or create a child node under a given parent node.</summary>
 /// <remarks>
 /// Find or create a child node under a given parent node. If the parent node is no
 /// Returns the found or created child node.
 /// </remarks>
 /// <param name="parent">the parent node</param>
 /// <param name="childName">the node name to find</param>
 /// <param name="createNodes">flag, if new nodes shall be created.</param>
 /// <returns>Returns the found or created node or <code>null</code>.</returns>
 /// <exception cref="Com.Adobe.Xmp.XMPException">Thrown if</exception>
 internal static XMPNode FindChildNode(XMPNode parent, string childName, bool createNodes)
 {
     if (!parent.GetOptions().IsSchemaNode() && !parent.GetOptions().IsStruct())
     {
         if (!parent.IsImplicit())
         {
             throw new XMPException("Named children only allowed for schemas and structs", XMPErrorConstants.Badxpath);
         }
         else
         {
             if (parent.GetOptions().IsArray())
             {
                 throw new XMPException("Named children not allowed for arrays", XMPErrorConstants.Badxpath);
             }
             else
             {
                 if (createNodes)
                 {
                     parent.GetOptions().SetStruct(true);
                 }
             }
         }
     }
     XMPNode childNode = parent.FindChildByName(childName);
     if (childNode == null && createNodes)
     {
         PropertyOptions options = new PropertyOptions();
         childNode = new XMPNode(childName, options);
         childNode.SetImplicit(true);
         parent.AddChild(childNode);
     }
     System.Diagnostics.Debug.Assert(childNode != null || !createNodes);
     return childNode;
 }