AddQualifier() public method

Appends a qualifier to the qualifier list and sets respective options.
public AddQualifier ( XmpNode qualNode ) : void
qualNode XmpNode a qualifier node.
return void
Esempio n. 1
0
        /// <summary>
        /// Searches for a qualifier selector in a node:
        /// [?qualName="value"] - an element in an array, chosen by a qualifier value.
        /// No implicit nodes are created for qualifier selectors,
        /// except for an alias to an x-default item.
        /// </summary>
        /// <param name="arrayNode"> an array node </param>
        /// <param name="qualName"> the qualifier name </param>
        /// <param name="qualValue"> the qualifier value </param>
        /// <param name="aliasForm"> in case the qual selector results from an alias,
        ///           an x-default node is created if there has not been one. </param>
        /// <returns> Returns the index of th </returns>
        /// <exception cref="XmpException">  </exception>
        private static int LookupQualSelector(XmpNode arrayNode, string qualName, string qualValue, uint aliasForm)
        {
            if (XML_LANG.Equals(qualName))
            {
                qualValue = Utils.NormalizeLangValue(qualValue);
                int index = LookupLanguageItem(arrayNode, qualValue);
                if (index < 0 && (aliasForm & AliasOptions.PROP_ARRAY_ALT_TEXT) > 0)
                {
                    XmpNode langNode = new XmpNode(ARRAY_ITEM_NAME, null);
                    XmpNode xdefault = new XmpNode(XML_LANG, X_DEFAULT, null);
                    langNode.AddQualifier(xdefault);
                    arrayNode.AddChild(1, langNode);
                    return(1);
                }
                return(index);
            }
            for (int index = 1; index < arrayNode.ChildrenLength; index++)
            {
                XmpNode currItem = arrayNode.GetChild(index);

                for (IEnumerator it = currItem.IterateQualifier(); it.MoveNext();)
                {
                    XmpNode qualifier = (XmpNode)it.Current;
                    if (qualifier != null && qualName.Equals(qualifier.Name) && qualValue.Equals(qualifier.Value))
                    {
                        return(index);
                    }
                }
            }
            return(-1);
        }
Esempio n. 2
0
        /// <summary>
        /// Make sure that the array is well-formed AltText. Each item must be simple
        /// and have an "xml:lang" qualifier. If repairs are needed, keep simple
        /// non-empty items by adding the "xml:lang" with value "x-repair". </summary>
        /// <param name="arrayNode"> the property node of the array to repair. </param>
        /// <exception cref="XmpException"> Forwards unexpected exceptions. </exception>
        private static void RepairAltText(XmpNode arrayNode)
        {
            if (arrayNode == null || !arrayNode.Options.Array)
            {
                // Already OK or not even an array.
                return;
            }

            // fix options
            arrayNode.Options.ArrayOrdered   = true;
            arrayNode.Options.ArrayAlternate = true;
            arrayNode.Options.ArrayAltText   = true;
            ArrayList   currChildsToRemove = new ArrayList();
            IEnumerator it = arrayNode.IterateChildren();

            while (it.MoveNext())
            {
                XmpNode currChild = (XmpNode)it.Current;
                if (currChild == null)
                {
                    continue;
                }
                if (currChild.Options.CompositeProperty)
                {
                    // Delete non-simple children.
                    currChildsToRemove.Add(currChild);
                }
                else if (!currChild.Options.HasLanguage)
                {
                    string childValue = currChild.Value;
                    if (String.IsNullOrEmpty(childValue))
                    {
                        // Delete empty valued children that have no xml:lang.
                        currChildsToRemove.Add(currChild);
                    }
                    else
                    {
                        // Add an xml:lang qualifier with the value "x-repair".
                        XmpNode repairLang = new XmpNode(XmpConst.XML_LANG, "x-repair", null);
                        currChild.AddQualifier(repairLang);
                    }
                }
            }
            foreach (object o in currChildsToRemove)
            {
                arrayNode.Children.Remove(o);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Appends a language item to an alt text array.
        /// </summary>
        /// <param name="arrayNode"> the language array </param>
        /// <param name="itemLang"> the language of the item </param>
        /// <param name="itemValue"> the content of the item </param>
        /// <exception cref="XmpException"> Thrown if a duplicate property is added </exception>
        internal static void AppendLangItem(XmpNode arrayNode, string itemLang, string itemValue)
        {
            XmpNode newItem  = new XmpNode(ARRAY_ITEM_NAME, itemValue, null);
            XmpNode langQual = new XmpNode(XML_LANG, itemLang, null);

            newItem.AddQualifier(langQual);

            if (!X_DEFAULT.Equals(langQual.Value))
            {
                arrayNode.AddChild(newItem);
            }
            else
            {
                arrayNode.AddChild(1, newItem);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Find or create a qualifier node under a given parent node. Returns a pointer to the
        /// qualifier node, and optionally an iterator for the node's position in
        /// the parent's vector of qualifiers. The iterator is unchanged if no qualifier node (null)
        /// is returned.
        /// <em>Note:</em> On entry, the qualName parameter must not have the leading '?' from the
        /// XmpPath step.
        /// </summary>
        /// <param name="parent"> the parent XMPNode </param>
        /// <param name="qualName"> the qualifier name </param>
        /// <param name="createNodes"> flag if nodes shall be created </param>
        /// <returns> Returns the qualifier node if found or created, <code>null</code> otherwise. </returns>
        /// <exception cref="XmpException">  </exception>
        private static XmpNode FindQualifierNode(XmpNode parent, string qualName, bool createNodes)
        {
            Debug.Assert(!qualName.StartsWith("?"));

            XmpNode qualNode = parent.FindQualifierByName(qualName);

            if (qualNode == null && createNodes)
            {
                qualNode          = new XmpNode(qualName, null);
                qualNode.Implicit = true;

                parent.AddQualifier(qualNode);
            }

            return(qualNode);
        }
Esempio n. 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(XmpNode destination)
 {
     try {
         foreach (XmpNode node in Children)
         {
             destination.AddChild((XmpNode)node.Clone());
         }
         foreach (XmpNode node in Qualifier)
         {
             destination.AddQualifier((XmpNode)node.Clone());
         }
     }
     catch (XmpException) {
         // cannot happen (duplicate childs/quals do not exist in this node)
         Debug.Assert(false);
     }
 }
Esempio n. 6
0
        /// <summary>
        /// Moves an alias node of array form to another schema into an array </summary>
        /// <param name="childNode"> the node to be moved </param>
        /// <param name="baseArray"> the base array for the array item </param>
        /// <exception cref="XmpException"> Forwards XMP errors </exception>
        private static void TransplantArrayItemAlias(XmpNode childNode, XmpNode baseArray)
        {
            if (baseArray.Options.ArrayAltText)
            {
                if (childNode.Options.HasLanguage)
                {
                    throw new XmpException("Alias to x-default already has a language qualifier",
                                           XmpError.BADXMP);
                }

                XmpNode langQual = new XmpNode(XmpConst.XML_LANG, XmpConst.X_DEFAULT, null);
                childNode.AddQualifier(langQual);
            }

            childNode.Name = XmpConst.ARRAY_ITEM_NAME;
            baseArray.AddChild(childNode);
        }
Esempio n. 7
0
        /// <summary>
        /// Undo the denormalization performed by the XMP used in Acrobat 5.<br>
        /// If a Dublin Core array had only one item, it was serialized as a simple
        /// property. <br>
        /// The <code>xml:lang</code> attribute was dropped from an
        /// <code>alt-text</code> item if the language was <code>x-default</code>.
        /// </summary>
        /// <param name="dcSchema"> the DC schema node </param>
        /// <exception cref="XmpException"> Thrown if normalization fails </exception>
        private static void NormalizeDcArrays(XmpNode dcSchema)
        {
            for (int i = 1; i <= dcSchema.ChildrenLength; i++)
            {
                XmpNode currProp = dcSchema.GetChild(i);

                PropertyOptions arrayForm = (PropertyOptions)_dcArrayForms[currProp.Name];
                if (arrayForm == null)
                {
                    continue;
                }
                if (currProp.Options.Simple)
                {
                    // create a new array and add the current property as child,
                    // if it was formerly simple
                    XmpNode newArray = new XmpNode(currProp.Name, arrayForm);
                    currProp.Name = XmpConst.ARRAY_ITEM_NAME;
                    newArray.AddChild(currProp);
                    dcSchema.ReplaceChild(i, newArray);

                    // fix language alternatives
                    if (arrayForm.ArrayAltText && !currProp.Options.HasLanguage)
                    {
                        XmpNode newLang = new XmpNode(XmpConst.XML_LANG, XmpConst.X_DEFAULT, null);
                        currProp.AddQualifier(newLang);
                    }
                }
                else
                {
                    // clear array options and add corrected array form if it has been an array before
                    currProp.Options.SetOption(
                        PropertyOptions.ARRAY | PropertyOptions.ARRAY_ORDERED | PropertyOptions.ARRAY_ALTERNATE |
                        PropertyOptions.ARRAY_ALT_TEXT, false);
                    currProp.Options.MergeWith(arrayForm);

                    if (arrayForm.ArrayAltText)
                    {
                        // applying for "dc:description", "dc:rights", "dc:title"
                        RepairAltText(currProp);
                    }
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// The parent is an RDF pseudo-struct containing an rdf:value field. Fix the
        /// XMP data model. The rdf:value node must be the first child, the other
        /// children are qualifiers. The form, value, and children of the rdf:value
        /// node are the real ones. The rdf:value node's qualifiers must be added to
        /// the others.
        /// </summary>
        /// <param name="xmpParent"> the parent xmp node </param>
        /// <exception cref="XmpException"> thown on parsing errors </exception>
        private static void FixupQualifiedNode(XmpNode xmpParent) {
            Debug.Assert(xmpParent.Options.Struct && xmpParent.HasChildren());

            XmpNode valueNode = xmpParent.GetChild(1);
            Debug.Assert("rdf:value".Equals(valueNode.Name));

            // Move the qualifiers on the value node to the parent. 
            // Make sure an xml:lang qualifier stays at the front.
            // Check for duplicate names between the value node's qualifiers and the parent's children. 
            // The parent's children are about to become qualifiers. Check here, between the groups. 
            // Intra-group duplicates are caught by XMPNode#addChild(...).
            if (valueNode.Options.HasLanguage) {
                if (xmpParent.Options.HasLanguage) {
                    throw new XmpException("Redundant xml:lang for rdf:value element", XmpError.BADXMP);
                }
                XmpNode langQual = valueNode.GetQualifier(1);
                valueNode.RemoveQualifier(langQual);
                xmpParent.AddQualifier(langQual);
            }

            // Start the remaining copy after the xml:lang qualifier.		
            for (int i = 1; i <= valueNode.QualifierLength; i++) {
                XmpNode qualifier = valueNode.GetQualifier(i);
                xmpParent.AddQualifier(qualifier);
            }


            // Change the parent's other children into qualifiers. 
            // This loop starts at 1, child 0 is the rdf:value node.
            for (int i = 2; i <= xmpParent.ChildrenLength; i++) {
                XmpNode qualifier = xmpParent.GetChild(i);
                xmpParent.AddQualifier(qualifier);
            }

            // Move the options and value last, other checks need the parent's original options. 
            // Move the value node's children to be the parent's children.
            Debug.Assert(xmpParent.Options.Struct || xmpParent.HasValueChild);

            xmpParent.HasValueChild = false;
            xmpParent.Options.Struct = false;
            xmpParent.Options.MergeWith(valueNode.Options);
            xmpParent.Value = valueNode.Value;

            xmpParent.RemoveChildren();
            for (IEnumerator it = valueNode.IterateChildren(); it.MoveNext();) {
                XmpNode child = (XmpNode) it.Current;
                xmpParent.AddChild(child);
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Adds a qualifier node.
        /// </summary>
        /// <param name="xmpParent"> the parent xmp node </param>
        /// <param name="name"> the name of the qualifier which has to be 
        /// 		QName including the <b>default prefix</b> </param>
        /// <param name="value"> the value of the qualifier </param>
        /// <returns> Returns the newly created child node. </returns>
        /// <exception cref="XmpException"> thown on parsing errors </exception>
        private static XmpNode AddQualifierNode(XmpNode xmpParent, string name, string value) {
            bool isLang = XML_LANG.Equals(name);
            // normalize value of language qualifiers
            XmpNode newQual = new XmpNode(name, isLang ? Utils.NormalizeLangValue(value) : value, null);
            xmpParent.AddQualifier(newQual);

            return newQual;
        }
Esempio n. 10
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(XmpNode destination) {
     try {
         foreach (XmpNode node in Children) {
             destination.AddChild((XmpNode) node.Clone());
         }
         foreach (XmpNode node in Qualifier) {
             destination.AddQualifier((XmpNode) node.Clone());
         }
     }
     catch (XmpException) {
         // cannot happen (duplicate childs/quals do not exist in this node)
         Debug.Assert(false);
     }
 }
Esempio n. 11
0
        /// <summary>
        /// Appends a language item to an alt text array.
        /// </summary>
        /// <param name="arrayNode"> the language array </param>
        /// <param name="itemLang"> the language of the item </param>
        /// <param name="itemValue"> the content of the item </param>
        /// <exception cref="XmpException"> Thrown if a duplicate property is added </exception>
        internal static void AppendLangItem(XmpNode arrayNode, string itemLang, string itemValue) {
            XmpNode newItem = new XmpNode(ARRAY_ITEM_NAME, itemValue, null);
            XmpNode langQual = new XmpNode(XML_LANG, itemLang, null);
            newItem.AddQualifier(langQual);

            if (!X_DEFAULT.Equals(langQual.Value)) {
                arrayNode.AddChild(newItem);
            }
            else {
                arrayNode.AddChild(1, newItem);
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Searches for a qualifier selector in a node:
        /// [?qualName="value"] - an element in an array, chosen by a qualifier value.
        /// No implicit nodes are created for qualifier selectors, 
        /// except for an alias to an x-default item.
        /// </summary>
        /// <param name="arrayNode"> an array node </param>
        /// <param name="qualName"> the qualifier name </param>
        /// <param name="qualValue"> the qualifier value </param>
        /// <param name="aliasForm"> in case the qual selector results from an alias,
        /// 		  an x-default node is created if there has not been one. </param>
        /// <returns> Returns the index of th </returns>
        /// <exception cref="XmpException">  </exception>
        private static int LookupQualSelector(XmpNode arrayNode, string qualName, string qualValue, uint aliasForm) {
            if (XML_LANG.Equals(qualName)) {
                qualValue = Utils.NormalizeLangValue(qualValue);
                int index = LookupLanguageItem(arrayNode, qualValue);
                if (index < 0 && (aliasForm & AliasOptions.PROP_ARRAY_ALT_TEXT) > 0) {
                    XmpNode langNode = new XmpNode(ARRAY_ITEM_NAME, null);
                    XmpNode xdefault = new XmpNode(XML_LANG, X_DEFAULT, null);
                    langNode.AddQualifier(xdefault);
                    arrayNode.AddChild(1, langNode);
                    return 1;
                }
                return index;
            }
            for (int index = 1; index < arrayNode.ChildrenLength; index++) {
                XmpNode currItem = arrayNode.GetChild(index);

                for (IEnumerator it = currItem.IterateQualifier(); it.MoveNext();) {
                    XmpNode qualifier = (XmpNode) it.Current;
                    if (qualifier != null && qualName.Equals(qualifier.Name) && qualValue.Equals(qualifier.Value)) {
                        return index;
                    }
                }
            }
            return -1;
        }
Esempio n. 13
0
        /// <summary>
        /// Find or create a qualifier node under a given parent node. Returns a pointer to the 
        /// qualifier node, and optionally an iterator for the node's position in 
        /// the parent's vector of qualifiers. The iterator is unchanged if no qualifier node (null) 
        /// is returned.
        /// <em>Note:</em> On entry, the qualName parameter must not have the leading '?' from the 
        /// XmpPath step.
        /// </summary>
        /// <param name="parent"> the parent XMPNode </param>
        /// <param name="qualName"> the qualifier name </param>
        /// <param name="createNodes"> flag if nodes shall be created </param>
        /// <returns> Returns the qualifier node if found or created, <code>null</code> otherwise. </returns>
        /// <exception cref="XmpException">  </exception>
        private static XmpNode FindQualifierNode(XmpNode parent, string qualName, bool createNodes) {
            Debug.Assert(!qualName.StartsWith("?"));

            XmpNode qualNode = parent.FindQualifierByName(qualName);

            if (qualNode == null && createNodes) {
                qualNode = new XmpNode(qualName, null);
                qualNode.Implicit = true;

                parent.AddQualifier(qualNode);
            }

            return qualNode;
        }
Esempio n. 14
0
        /// <summary>
        /// Moves an alias node of array form to another schema into an array </summary>
        /// <param name="childNode"> the node to be moved </param>
        /// <param name="baseArray"> the base array for the array item </param>
        /// <exception cref="XmpException"> Forwards XMP errors </exception>
        private static void TransplantArrayItemAlias(XmpNode childNode, XmpNode baseArray) {
            if (baseArray.Options.ArrayAltText) {
                if (childNode.Options.HasLanguage) {
                    throw new XmpException("Alias to x-default already has a language qualifier",
                                           XmpError.BADXMP);
                }

                XmpNode langQual = new XmpNode(XmpConst.XML_LANG, XmpConst.X_DEFAULT, null);
                childNode.AddQualifier(langQual);
            }

            childNode.Name = XmpConst.ARRAY_ITEM_NAME;
            baseArray.AddChild(childNode);
        }