/// <summary>Appends a qualifier to the qualifier list and sets respective options.</summary> /// <param name="qualNode">a qualifier node.</param> /// <exception cref="iText.Kernel.XMP.XMPException"></exception> public virtual void AddQualifier(iText.Kernel.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().Insert(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().Insert(!options.GetHasLanguage() ? 0 : 1, qualNode); } else { // other qualifiers are appended GetQualifier().Add(qualNode); } } }
/// <summary>Adds a node as child to this node.</summary> /// <param name="node">an XMPNode</param> /// <exception cref="iText.Kernel.XMP.XMPException"></exception> public virtual void AddChild(iText.Kernel.XMP.Impl.XMPNode node) { // check for duplicate properties AssertChildNotExisting(node.GetName()); node.SetParent(this); GetChildren().Add(node); }
/// <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 iText.Kernel.XMP.Impl.XMPNode Find(IList list, String expr) { if (list != null) { for (IEnumerator it = list.GetEnumerator(); it.MoveNext();) { iText.Kernel.XMP.Impl.XMPNode child = (iText.Kernel.XMP.Impl.XMPNode)it .Current; if (child.GetName().Equals(expr)) { return(child); } } } return(null); }
/// <summary>Performs a <b>deep clone</b> of the node and the complete subtree.</summary> /// <seealso cref="System.Object.Clone()"/> public virtual Object Clone() { PropertyOptions newOptions; try { newOptions = new PropertyOptions(GetOptions().GetOptions()); } catch (XMPException) { // cannot happen newOptions = new PropertyOptions(); } iText.Kernel.XMP.Impl.XMPNode newNode = new iText.Kernel.XMP.Impl.XMPNode (name, value, newOptions); CloneSubtree(newNode); return(newNode); }
/// <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(iText.Kernel.XMP.Impl.XMPNode destination) { try { for (IEnumerator it = IterateChildren(); it.MoveNext();) { iText.Kernel.XMP.Impl.XMPNode child = (iText.Kernel.XMP.Impl.XMPNode)it .Current; destination.AddChild((iText.Kernel.XMP.Impl.XMPNode)child.Clone()); } for (IEnumerator it_1 = IterateQualifier(); it_1.MoveNext();) { iText.Kernel.XMP.Impl.XMPNode qualifier = (iText.Kernel.XMP.Impl.XMPNode )it_1.Current; destination.AddQualifier((iText.Kernel.XMP.Impl.XMPNode)qualifier.Clone()); } } catch (XMPException) { // cannot happen (duplicate childs/quals do not exist in this node) System.Diagnostics.Debug.Assert(false); } }
/// <summary>Removes one qualifier node and fixes the options.</summary> /// <param name="qualNode">qualifier to remove</param> public virtual void RemoveQualifier(iText.Kernel.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.Count == 0) { opts.SetHasQualifiers(false); qualifier = null; } }
/// <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(iText.Kernel.XMP.Impl.XMPNode parent ) { this.parent = parent; }
//------------------------------------------------------------------------------ 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()) { XMPNode[] quals = new XMPNode[GetQualifier().Count]; GetQualifier().CopyTo(quals, 0); int i = 0; while (quals.Length > i && (XMPConst.XML_LANG.Equals(quals[i].GetName()) || "rdf:type" .Equals(quals[i].GetName()))) { i++; } System.Array.Sort(quals, i, quals.Length); for (i = 0; i < quals.Length; i++) { iText.Kernel.XMP.Impl.XMPNode qualifier = quals[i]; qualifier.DumpNode(result, recursive, indent + 2, i + 1); } } // render children if (recursive && HasChildren()) { XMPNode[] children = new XMPNode[GetChildren().Count]; GetChildren().CopyTo(children, 0); if (!GetOptions().IsArray()) { System.Array.Sort(children); } for (int i = 0; i < children.Length; i++) { iText.Kernel.XMP.Impl.XMPNode child = children[i]; child.DumpNode(result, recursive, indent + 1, i + 1); } } }
/// <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(iText.Kernel.XMP.Impl.XMPNode node) { GetChildren().Remove(node); CleanupChildren(); }
/// <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, iText.Kernel.XMP.Impl.XMPNode node ) { node.SetParent(this); GetChildren()[index - 1] = node; }
/// <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="iText.Kernel.XMP.XMPException"></exception> public virtual void AddChild(int index, iText.Kernel.XMP.Impl.XMPNode node) { AssertChildNotExisting(node.GetName()); node.SetParent(this); GetChildren().Insert(index - 1, node); }