Пример #1
0
 /// <summary>Appends a qualifier to the qualifier list and sets respective options.</summary>
 /// <param name="qualNode">a qualifier node.</param>
 /// <exception cref="Com.Adobe.Xmp.XMPException"></exception>
 public virtual void AddQualifier(Com.Adobe.Xmp.Impl.XMPNode qualNode)
 {
     AssertQualifierNotExisting(qualNode.GetName());
     qualNode.SetParent(this);
     qualNode.GetOptions().SetQualifier(true);
     GetOptions().SetHasQualifiers(true);
     // contraints
     if (qualNode.IsLanguageNode())
     {
         // "xml:lang" is always first and the option "hasLanguage" is set
         options.SetHasLanguage(true);
         GetQualifier().Add(0, qualNode);
     }
     else
     {
         if (qualNode.IsTypeNode())
         {
             // "rdf:type" must be first or second after "xml:lang" and the option "hasType" is set
             options.SetHasType(true);
             GetQualifier().Add(!options.GetHasLanguage() ? 0 : 1, qualNode);
         }
         else
         {
             // other qualifiers are appended
             GetQualifier().Add(qualNode);
         }
     }
 }
Пример #2
0
 /// <summary>Adds a node as child to this node.</summary>
 /// <param name="node">an XMPNode</param>
 /// <exception cref="Com.Adobe.Xmp.XMPException"></exception>
 public virtual void AddChild(Com.Adobe.Xmp.Impl.XMPNode node)
 {
     // check for duplicate properties
     AssertChildNotExisting(node.GetName());
     node.SetParent(this);
     GetChildren().Add(node);
 }
Пример #3
0
 /// <summary>Internal find.</summary>
 /// <param name="list">the list to search in</param>
 /// <param name="expr">the search expression</param>
 /// <returns>Returns the found node or <code>nulls</code>.</returns>
 private Com.Adobe.Xmp.Impl.XMPNode Find(IList list, string expr)
 {
     if (list != null)
     {
         for (Iterator it = list.Iterator(); it.HasNext();)
         {
             Com.Adobe.Xmp.Impl.XMPNode child = (Com.Adobe.Xmp.Impl.XMPNode)it.Next();
             if (child.GetName().Equals(expr))
             {
                 return(child);
             }
         }
     }
     return(null);
 }
Пример #4
0
        /// <summary>Performs a <b>deep clone</b> of the node and the complete subtree.</summary>
        /// <seealso cref="ICloneable.Clone()"/>
        public virtual object Clone()
        {
            PropertyOptions newOptions;

            try
            {
                newOptions = new PropertyOptions(GetOptions().GetOptions());
            }
            catch (XMPException)
            {
                // cannot happen
                newOptions = new PropertyOptions();
            }
            Com.Adobe.Xmp.Impl.XMPNode newNode = new Com.Adobe.Xmp.Impl.XMPNode(name, value, newOptions);
            CloneSubtree(newNode);
            return(newNode);
        }
Пример #5
0
 /// <summary>
 /// Performs a <b>deep clone</b> of the complete subtree (children and
 /// qualifier )into and add it to the destination node.
 /// </summary>
 /// <param name="destination">the node to add the cloned subtree</param>
 public virtual void CloneSubtree(Com.Adobe.Xmp.Impl.XMPNode destination)
 {
     try
     {
         for (Iterator it = IterateChildren(); it.HasNext();)
         {
             Com.Adobe.Xmp.Impl.XMPNode child = (Com.Adobe.Xmp.Impl.XMPNode)it.Next();
             destination.AddChild((Com.Adobe.Xmp.Impl.XMPNode)child.Clone());
         }
         for (Iterator it_1 = IterateQualifier(); it_1.HasNext();)
         {
             Com.Adobe.Xmp.Impl.XMPNode qualifier = (Com.Adobe.Xmp.Impl.XMPNode)it_1.Next();
             destination.AddQualifier((Com.Adobe.Xmp.Impl.XMPNode)qualifier.Clone());
         }
     }
     catch (XMPException)
     {
         // cannot happen (duplicate childs/quals do not exist in this node)
         System.Diagnostics.Debug.Assert(false);
     }
 }
Пример #6
0
        /// <summary>Removes one qualifier node and fixes the options.</summary>
        /// <param name="qualNode">qualifier to remove</param>
        public virtual void RemoveQualifier(Com.Adobe.Xmp.Impl.XMPNode qualNode)
        {
            PropertyOptions opts = GetOptions();

            if (qualNode.IsLanguageNode())
            {
                // if "xml:lang" is removed, remove hasLanguage-flag too
                opts.SetHasLanguage(false);
            }
            else
            {
                if (qualNode.IsTypeNode())
                {
                    // if "rdf:type" is removed, remove hasType-flag too
                    opts.SetHasType(false);
                }
            }
            GetQualifier().Remove(qualNode);
            if (qualifier.IsEmpty())
            {
                opts.SetHasQualifiers(false);
                qualifier = null;
            }
        }
Пример #7
0
 /// <summary>
 /// Sets the parent node, this is solely done by <code>addChild(...)</code>
 /// and <code>addQualifier()</code>.
 /// </summary>
 /// <param name="parent">Sets the parent node.</param>
 protected internal virtual void SetParent(Com.Adobe.Xmp.Impl.XMPNode parent)
 {
     this.parent = parent;
 }
Пример #8
0
 /// <summary>Performs a <b>deep clone</b> of the node and the complete subtree.</summary>
 /// <seealso cref="object.Clone()"/>
 public virtual object Clone()
 {
     PropertyOptions newOptions;
     try
     {
         newOptions = new PropertyOptions(GetOptions().GetOptions());
     }
     catch (XMPException)
     {
         // cannot happen
         newOptions = new PropertyOptions();
     }
     Com.Adobe.Xmp.Impl.XMPNode newNode = new Com.Adobe.Xmp.Impl.XMPNode(name, value, newOptions);
     CloneSubtree(newNode);
     return newNode;
 }
Пример #9
0
 /// <summary>
 /// Sets the parent node, this is solely done by <code>AddChild(...)</code>
 /// and <code>AddQualifier()</code>.
 /// </summary>
 /// <param name="parent">Sets the parent node.</param>
 protected internal virtual void SetParent(Com.Adobe.Xmp.Impl.XMPNode parent)
 {
     this.parent = parent;
 }
Пример #10
0
 //------------------------------------------------------------------------------ private methods
 /// <summary>Dumps this node and its qualifier and children recursively.</summary>
 /// <remarks>
 /// Dumps this node and its qualifier and children recursively.
 /// <em>Note:</em> It creats empty options on every node.
 /// </remarks>
 /// <param name="result">the buffer to append the dump.</param>
 /// <param name="recursive">Flag is qualifier and child nodes shall be rendered too</param>
 /// <param name="indent">the current indent level.</param>
 /// <param name="index">the index within the parent node (important for arrays)</param>
 private void DumpNode(StringBuilder result, bool recursive, int indent, int index)
 {
     // write indent
     for (int i = 0; i < indent; i++)
     {
         result.Append('\t');
     }
     // render Node
     if (parent != null)
     {
         if (GetOptions().IsQualifier())
         {
             result.Append('?');
             result.Append(name);
         }
         else
         {
             if (GetParent().GetOptions().IsArray())
             {
                 result.Append('[');
                 result.Append(index);
                 result.Append(']');
             }
             else
             {
                 result.Append(name);
             }
         }
     }
     else
     {
         // applies only to the root node
         result.Append("ROOT NODE");
         if (name != null && name.Length > 0)
         {
             // the "about" attribute
             result.Append(" (");
             result.Append(name);
             result.Append(')');
         }
     }
     if (value != null && value.Length > 0)
     {
         result.Append(" = \"");
         result.Append(value);
         result.Append('"');
     }
     // render options if at least one is set
     if (GetOptions().ContainsOneOf(unchecked ((int)(0xffffffff))))
     {
         result.Append("\t(");
         result.Append(GetOptions().ToString());
         result.Append(" : ");
         result.Append(GetOptions().GetOptionsString());
         result.Append(')');
     }
     result.Append('\n');
     // render qualifier
     if (recursive && HasQualifier())
     {
         Com.Adobe.Xmp.Impl.XMPNode[] quals = (Com.Adobe.Xmp.Impl.XMPNode[])Sharpen.Collections.ToArray(GetQualifier(), new Com.Adobe.Xmp.Impl.XMPNode[GetQualifierLength()]);
         int i_1 = 0;
         while (quals.Length > i_1 && (XMPConstConstants.XmlLang.Equals(quals[i_1].GetName()) || "rdf:type".Equals(quals[i_1].GetName())))
         {
             i_1++;
         }
         Arrays.Sort(quals, i_1, quals.Length);
         for (i_1 = 0; i_1 < quals.Length; i_1++)
         {
             Com.Adobe.Xmp.Impl.XMPNode qualifier = quals[i_1];
             qualifier.DumpNode(result, recursive, indent + 2, i_1 + 1);
         }
     }
     // render children
     if (recursive && HasChildren())
     {
         Com.Adobe.Xmp.Impl.XMPNode[] children = (Com.Adobe.Xmp.Impl.XMPNode[])Sharpen.Collections.ToArray(GetChildren(), new Com.Adobe.Xmp.Impl.XMPNode[GetChildrenLength()]);
         if (!GetOptions().IsArray())
         {
             Arrays.Sort(children);
         }
         for (int i_1 = 0; i_1 < children.Length; i_1++)
         {
             Com.Adobe.Xmp.Impl.XMPNode child = children[i_1];
             child.DumpNode(result, recursive, indent + 1, i_1 + 1);
         }
     }
 }
Пример #11
0
 /// <summary>Removes a child node.</summary>
 /// <remarks>
 /// Removes a child node.
 /// If its a schema node and doesn't have any children anymore, its deleted.
 /// </remarks>
 /// <param name="node">the child node to delete.</param>
 public virtual void RemoveChild(Com.Adobe.Xmp.Impl.XMPNode node)
 {
     GetChildren().Remove(node);
     CleanupChildren();
 }
Пример #12
0
 /// <summary>Replaces a node with another one.</summary>
 /// <param name="index">
 /// the index of the node that will be replaced.
 /// <em>Note:</em> The node children are indexed from [1..size]!
 /// </param>
 /// <param name="node">the replacement XMPNode</param>
 public virtual void ReplaceChild(int index, Com.Adobe.Xmp.Impl.XMPNode node)
 {
     node.SetParent(this);
     GetChildren().Set(index - 1, node);
 }
Пример #13
0
 /// <summary>Adds a node as child to this node.</summary>
 /// <param name="index">
 /// the index of the node <em>before</em> which the new one is inserted.
 /// <em>Note:</em> The node children are indexed from [1..size]!
 /// An index of size + 1 appends a node.
 /// </param>
 /// <param name="node">an XMPNode</param>
 /// <exception cref="Com.Adobe.Xmp.XMPException"></exception>
 public virtual void AddChild(int index, Com.Adobe.Xmp.Impl.XMPNode node)
 {
     AssertChildNotExisting(node.GetName());
     node.SetParent(this);
     GetChildren().Add(index - 1, node);
 }