Ejemplo n.º 1
0
        /// <summary> Reads metadata from an open stream and saves to the provided item/package </summary>
        /// <param name="Input_Stream"> Open stream to read metadata from </param>
        /// <param name="Return_Package"> Package into which to read the metadata </param>
        /// <param name="Options"> Dictionary of any options which this metadata reader/writer may utilize </param>
        /// <param name="Error_Message">[OUTPUT] Explanation of the error, if an error occurs during reading </param>
        /// <returns>TRUE if successful, otherwise FALSE </returns>
        public bool Read_Metadata(Stream Input_Stream, SobekCM_Item Return_Package, Dictionary <string, object> Options, out string Error_Message)
        {
            // Set default error outpt message
            Error_Message = String.Empty;

            // Create a XML reader and read the metadata
            XmlTextReader nodeReader  = null;
            bool          returnValue = true;

            try
            {
                // create the node reader
                nodeReader = new XmlTextReader(Input_Stream);
                MODS_METS_dmdSec_ReaderWriter.Read_MODS_Info(nodeReader, Return_Package.Bib_Info, Return_Package);
            }
            catch (Exception ee)
            {
                Error_Message = "Error reading MODS from stream: " + ee.Message;
                returnValue   = false;
            }
            finally
            {
                if (nodeReader != null)
                {
                    nodeReader.Close();
                }
            }

            return(returnValue);
        }
Ejemplo n.º 2
0
        /// <summary> Writes the formatted metadata from the provided item to a TextWriter (usually to an output stream) </summary>
        /// <param name="Output_Stream"></param>
        /// <param name="Item_To_Save"> Package with all the metadata to save </param>
        /// <param name="Options"> Dictionary of any options which this metadata reader/writer may utilize </param>
        /// <param name="Error_Message">[OUTPUT] Explanation of the error, if an error occurs during write </param>
        /// <returns>TRUE if successful, otherwise FALSE </returns>
        public bool Write_Metadata(TextWriter Output_Stream, SobekCM_Item Item_To_Save, Dictionary <string, object> Options, out string Error_Message)
        {
            // Set default error outpt message
            Error_Message = String.Empty;

            try
            {
                // Start to build the XML result
                StringBuilder results = new StringBuilder();
                results.Append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n");
                string mods_start = "<mods xmlns:xlink=\"http://www.w3.org/1999/xlink\" version=\"3.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://www.loc.gov/mods/v3\" xsi:schemaLocation=\"http://www.loc.gov/mods/v3 http://www.loc.gov/mods/v3/mods-3-4.xsd\">\r\n";

                StringWriter string_writer = new StringWriter(results);
                MODS_METS_dmdSec_ReaderWriter.Write_MODS(string_writer, Item_To_Save.Bib_Info);

                Output_Stream.Write(results.ToString().Replace("<mods:", "<").Replace("</mods:", "</").Replace("<mods>", mods_start));

                return(true);
            }
            catch
            {
                Error_Message = "Error saving MODS metadata to output stream";
                return(false);
            }
        }