Beispiel #1
0
            /// <param name="currNode"> the node that will be added to the path. </param>
            /// <param name="parentPath"> the path up to this node. </param>
            /// <param name="currentIndex"> the current array index if an arrey is traversed </param>
            /// <returns> Returns the updated path. </returns>
            protected internal virtual String AccumulatePath(XMPNode currNode, string parentPath, int currentIndex)
            {
                String separator;
                String segmentName;

                if (currNode.GetParent() == null || currNode.GetOptions().IsSchemaNode())
                {
                    return(null);
                }
                if (currNode.GetParent().GetOptions().IsArray())
                {
                    separator   = "";
                    segmentName = "[" + Convert.ToString(currentIndex) + "]";
                }
                else
                {
                    separator   = "/";
                    segmentName = currNode.GetName();
                }


                if (String.IsNullOrEmpty(parentPath))
                {
                    return(segmentName);
                }
                if (outerInstance.GetOptions().IsJustLeafname())
                {
                    return(!segmentName.StartsWith("?") ? segmentName : segmentName.Substring(1));                    // qualifier
                }
                return(parentPath + separator + segmentName);
            }
Beispiel #2
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="iText.Kernel.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", XMPError.BADSCHEMA);
                    }
                }
                schemaNode.SetValue(prefix);
                tree.AddChild(schemaNode);
            }
            return(schemaNode);
        }
Beispiel #3
0
            /// <summary>
            /// Prepares the next node to return if not already done.
            /// </summary>
            /// <seealso cref="IEnumerator.MoveNext"/>
            public override bool MoveNext()
            {
                if (outerInstance.skipSiblings)
                {
                    return(false);
                }
                if (childrenIterator.MoveNext())
                {
                    XMPNode child = (XMPNode)childrenIterator.Current;
                    if (child != null)
                    {
                        index++;
                        string path = null;
                        if (child.GetOptions().IsSchemaNode())
                        {
                            outerInstance.SetBaseNS(child.GetName());
                        }
                        else if (child.GetParent() != null)
                        {
                            // for all but the root node and schema nodes
                            path = AccumulatePath(child, parentPath, index);
                        }

                        // report next property, skip not-leaf nodes in case options is set
                        if (!outerInstance.GetOptions().IsJustLeafnodes() || !child.HasChildren())
                        {
                            SetReturnProperty(CreatePropertyInfo(child, outerInstance.GetBaseNS(), path));
                            return(true);
                        }
                    }
                    return(MoveNext());
                }
                return(false);
            }
 /// <summary>
 /// The initial support for WAV files mapped a legacy ID3 audio copyright
 /// into a new xmpDM:copyright property.
 /// </summary>
 /// <remarks>
 /// The initial support for WAV files mapped a legacy ID3 audio copyright
 /// into a new xmpDM:copyright property. This is special case code to migrate
 /// that into dc:rights['x-default']. The rules:
 /// <pre>
 /// 1. If there is no dc:rights array, or an empty array -
 /// Create one with dc:rights['x-default'] set from double linefeed and xmpDM:copyright.
 /// 2. If there is a dc:rights array but it has no x-default item -
 /// Create an x-default item as a copy of the first item then apply rule #3.
 /// 3. If there is a dc:rights array with an x-default item,
 /// Look for a double linefeed in the value.
 /// A. If no double linefeed, compare the x-default value to the xmpDM:copyright value.
 /// A1. If they match then leave the x-default value alone.
 /// A2. Otherwise, append a double linefeed and
 /// the xmpDM:copyright value to the x-default value.
 /// B. If there is a double linefeed, compare the trailing text to the xmpDM:copyright value.
 /// B1. If they match then leave the x-default value alone.
 /// B2. Otherwise, replace the trailing x-default text with the xmpDM:copyright value.
 /// 4. In all cases, delete the xmpDM:copyright property.
 /// </pre>
 /// </remarks>
 /// <param name="xmp">the metadata object</param>
 /// <param name="dmCopyright">the "dm:copyright"-property</param>
 private static void MigrateAudioCopyright(XMPMeta xmp, XMPNode dmCopyright)
 {
     try
     {
         XMPNode dcSchema = XMPNodeUtils.FindSchemaNode(((XMPMetaImpl)xmp).GetRoot(), XMPConst
                                                        .NS_DC, true);
         String  dmValue       = dmCopyright.GetValue();
         String  doubleLF      = "\n\n";
         XMPNode dcRightsArray = XMPNodeUtils.FindChildNode(dcSchema, "dc:rights", false);
         if (dcRightsArray == null || !dcRightsArray.HasChildren())
         {
             // 1. No dc:rights array, create from double linefeed and xmpDM:copyright.
             dmValue = doubleLF + dmValue;
             xmp.SetLocalizedText(XMPConst.NS_DC, "rights", "", XMPConst.X_DEFAULT, dmValue, null
                                  );
         }
         else
         {
             int xdIndex = XMPNodeUtils.LookupLanguageItem(dcRightsArray, XMPConst.X_DEFAULT);
             if (xdIndex < 0)
             {
                 // 2. No x-default item, create from the first item.
                 String firstValue = dcRightsArray.GetChild(1).GetValue();
                 xmp.SetLocalizedText(XMPConst.NS_DC, "rights", "", XMPConst.X_DEFAULT, firstValue
                                      , null);
                 xdIndex = XMPNodeUtils.LookupLanguageItem(dcRightsArray, XMPConst.X_DEFAULT);
             }
             // 3. Look for a double linefeed in the x-default value.
             XMPNode defaultNode  = dcRightsArray.GetChild(xdIndex);
             String  defaultValue = defaultNode.GetValue();
             int     lfPos        = defaultValue.IndexOf(doubleLF);
             if (lfPos < 0)
             {
                 // 3A. No double LF, compare whole values.
                 if (!dmValue.Equals(defaultValue))
                 {
                     // 3A2. Append the xmpDM:copyright to the x-default
                     // item.
                     defaultNode.SetValue(defaultValue + doubleLF + dmValue);
                 }
             }
             else
             {
                 // 3B. Has double LF, compare the tail.
                 if (!defaultValue.Substring(lfPos + 2).Equals(dmValue))
                 {
                     // 3B2. Replace the x-default tail.
                     defaultNode.SetValue(defaultValue.JSubstring(0, lfPos + 2) + dmValue);
                 }
             }
         }
         // 4. Get rid of the xmpDM:copyright.
         dmCopyright.GetParent().RemoveChild(dmCopyright);
     }
     catch (XMPException)
     {
     }
 }
Beispiel #5
0
        /// <summary>Deletes the the given node and its children from its parent.</summary>
        /// <remarks>
        /// Deletes the the given node and its children from its parent.
        /// Takes care about adjusting the flags.
        /// </remarks>
        /// <param name="node">the top-most node to delete.</param>
        internal static void DeleteNode(XMPNode node)
        {
            XMPNode parent = node.GetParent();

            if (node.GetOptions().IsQualifier())
            {
                // root is qualifier
                parent.RemoveQualifier(node);
            }
            else
            {
                // root is NO qualifier
                parent.RemoveChild(node);
            }
            // delete empty Schema nodes
            if (!parent.HasChildren() && parent.GetOptions().IsSchemaNode())
            {
                parent.GetParent().RemoveChild(parent);
            }
        }