1------------------------------------------------------------------------------
2--                                                                          --
3--                            Matreshka Project                             --
4--                                                                          --
5--                               XML Processor                              --
6--                                                                          --
7--                        Runtime Library Component                         --
8--                                                                          --
9------------------------------------------------------------------------------
10--                                                                          --
11-- Copyright © 2011-2014, Vadim Godunko <vgodunko@gmail.com>                --
12-- All rights reserved.                                                     --
13--                                                                          --
14-- Redistribution and use in source and binary forms, with or without       --
15-- modification, are permitted provided that the following conditions       --
16-- are met:                                                                 --
17--                                                                          --
18--  * Redistributions of source code must retain the above copyright        --
19--    notice, this list of conditions and the following disclaimer.         --
20--                                                                          --
21--  * Redistributions in binary form must reproduce the above copyright     --
22--    notice, this list of conditions and the following disclaimer in the   --
23--    documentation and/or other materials provided with the distribution.  --
24--                                                                          --
25--  * Neither the name of the Vadim Godunko, IE nor the names of its        --
26--    contributors may be used to endorse or promote products derived from  --
27--    this software without specific prior written permission.              --
28--                                                                          --
29-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS      --
30-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT        --
31-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR    --
32-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT     --
33-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,   --
34-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
35-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR   --
36-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF   --
37-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING     --
38-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS       --
39-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.             --
40--                                                                          --
41------------------------------------------------------------------------------
42--  $Revision: 4781 $ $Date: 2014-03-29 12:27:25 +0400 (Sat, 29 Mar 2014) $
43------------------------------------------------------------------------------
44with Matreshka.XML_Catalogs.Handlers;
45with XML.SAX.Input_Sources.Streams.Files;
46with XML.SAX.Simple_Readers;
47
48package body Matreshka.XML_Catalogs.Loader is
49
50   ----------
51   -- Load --
52   ----------
53
54   function Load
55    (URI    : League.Strings.Universal_String;
56     Prefer : Matreshka.XML_Catalogs.Entry_Files.Prefer_Mode)
57       return Matreshka.XML_Catalogs.Entry_Files.Catalog_Entry_File_Access
58   is
59      Source  : aliased XML.SAX.Input_Sources.Streams.Files.File_Input_Source;
60      Handler : aliased Matreshka.XML_Catalogs.Handlers.XML_Catalog_Handler;
61      Reader  : aliased XML.SAX.Simple_Readers.Simple_Reader;
62
63   begin
64      Handler.Set_Default_Prefer_Mode (Prefer);
65      Reader.Set_Content_Handler (Handler'Unchecked_Access);
66
67      Source.Open_By_URI (URI);
68      Reader.Parse (Source'Unchecked_Access);
69
70      return Handler.Get_Catalog_Entry_File;
71   end Load;
72
73   -----------------------
74   -- Load_By_File_Name --
75   -----------------------
76
77   function Load_By_File_Name
78    (Name   : League.Strings.Universal_String;
79     Prefer : Matreshka.XML_Catalogs.Entry_Files.Prefer_Mode)
80       return Matreshka.XML_Catalogs.Entry_Files.Catalog_Entry_File_Access
81   is
82      Source  : aliased XML.SAX.Input_Sources.Streams.Files.File_Input_Source;
83      Handler : aliased Matreshka.XML_Catalogs.Handlers.XML_Catalog_Handler;
84      Reader  : aliased XML.SAX.Simple_Readers.Simple_Reader;
85
86   begin
87      Handler.Set_Default_Prefer_Mode (Prefer);
88      Reader.Set_Content_Handler (Handler'Unchecked_Access);
89      Reader.Set_Error_Handler (Handler'Unchecked_Access);
90
91      Source.Open_By_File_Name (Name);
92      Reader.Parse (Source'Unchecked_Access);
93
94      return Handler.Get_Catalog_Entry_File;
95   end Load_By_File_Name;
96
97end Matreshka.XML_Catalogs.Loader;
98