matreshka_league_21.0.0_0c8f4d47/source/xml/sax/xml-utilities-namespace_supports.ads

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
------------------------------------------------------------------------------
--                                                                          --
--                            Matreshka Project                             --
--                                                                          --
--                               XML Processor                              --
--                                                                          --
--                        Runtime Library Component                         --
--                                                                          --
------------------------------------------------------------------------------
--                                                                          --
-- Copyright © 2013, Vadim Godunko <vgodunko@gmail.com>                     --
-- All rights reserved.                                                     --
--                                                                          --
-- Redistribution and use in source and binary forms, with or without       --
-- modification, are permitted provided that the following conditions       --
-- are met:                                                                 --
--                                                                          --
--  * Redistributions of source code must retain the above copyright        --
--    notice, this list of conditions and the following disclaimer.         --
--                                                                          --
--  * Redistributions in binary form must reproduce the above copyright     --
--    notice, this list of conditions and the following disclaimer in the   --
--    documentation and/or other materials provided with the distribution.  --
--                                                                          --
--  * Neither the name of the Vadim Godunko, IE nor the names of its        --
--    contributors may be used to endorse or promote products derived from  --
--    this software without specific prior written permission.              --
--                                                                          --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS      --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT        --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR    --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT     --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,   --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR   --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF   --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING     --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS       --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.             --
--                                                                          --
------------------------------------------------------------------------------
--  $Revision: 4112 $ $Date: 2013-09-30 13:14:15 +0400 (Пн, 30 сен 2013) $
------------------------------------------------------------------------------
private with Ada.Containers.Hashed_Maps;
private with Ada.Containers.Vectors;
private with Ada.Finalization;

with League.String_Vectors;
with League.Strings;
private with League.Strings.Hash;

package XML.Utilities.Namespace_Supports is

   pragma Preelaborate;

   type XML_Namespace_Support is tagged private;

   type Component_Kinds is (Attribute, Element);

   --  Process_Name

   procedure Declare_Prefix
    (Self          : in out XML_Namespace_Support'Class;
     Prefix        : League.Strings.Universal_String;
     Namespace_URI : League.Strings.Universal_String);
   --  This procedure declares a prefix in the future namespace context to be
   --  namespace uri. The prefix is activated then context is pushed and
   --  remains in force until this context is popped, unless it is shadowed in
   --  a descendant context.

   function Namespace_URI
    (Self      : XML_Namespace_Support'Class;
     Prefix    : League.Strings.Universal_String;
     Component : Component_Kinds := Element)
       return League.Strings.Universal_String;
   --  Looks up the prefix prefix in the current context and returns the
   --  currently-mapped namespace URI. Use the empty string ("") for the
   --  default namespace.

   function Prefix
    (Self          : XML_Namespace_Support'Class;
     Namespace_URI : League.Strings.Universal_String;
     Component     : Component_Kinds := Element)
       return League.Strings.Universal_String;
   --  Returns one of the prefixes mapped to the namespace URI.
   --
   --  If more than one prefix is currently mapped to the same URI, this method
   --  will make an arbitrary selection; if you want all of the prefixes, use
   --  the Prefixes function instead.
   --
   --  This function return the empty (default) prefix only for Element
   --  component.

   function Prefixes
    (Self      : XML_Namespace_Support'Class;
     Component : Component_Kinds := Element)
       return League.String_Vectors.Universal_String_Vector;
   --  Return an enumeration of all prefixes declared in this context. The
   --  'xml:' prefix will be included.
   --
   --  The empty (default) prefix will be included in this enumeration; then
   --  specified component is Element.

   function Prefixes
    (Self          : XML_Namespace_Support'Class;
     Namespace_URI : League.Strings.Universal_String;
     Component     : Component_Kinds := Element)
       return League.String_Vectors.Universal_String_Vector;
   --  Return an enumeration of all prefixes for a given URI whose declarations
   --  are active in the current context. This includes declarations from
   --  parent contexts that have not been overridden.
   --
   --  The empty (default) prefix will be included in this enumeration; then
   --  specified component is Element.

   procedure Process_Name
    (Self           : XML_Namespace_Support'Class;
     Qualified_Name : League.Strings.Universal_String;
     Component      : Component_Kinds;
     Namespace_URI  : out League.Strings.Universal_String;
     Local_Name     : out League.Strings.Universal_String);
   --  Process a raw XML qualified name, after all declarations in the current
   --  context.
   --
   --  Note that attribute names are processed differently than element names:
   --  an unprefixed element name will receive the default Namespace (if any),
   --  while an unprefixed attribute name will not.

   procedure Pop_Context (Self : in out XML_Namespace_Support'Class);
   --  Revert to the previous Namespace context.
   --
   --  Normally, you should pop the context at the end of each XML element.
   --  After popping the context, all Namespace prefix mappings that were
   --  previously in force are restored.
   --
   --  You must not attempt to declare additional Namespace prefixes after
   --  popping a context, unless you push another context first.

   procedure Push_Context (Self : in out XML_Namespace_Support'Class);
   --  Starts a new namespace context.
   --
   --  Normally, you should push a new context at the beginning of each XML
   --  element: the new context automatically inherits the declarations of its
   --  parent context, and it also keeps track of which declarations were made
   --  within this context.
   --
   --  The namespace support object always starts with a base context already
   --  in force: in this context, only the "xml" prefix is declared.

   procedure Reset (Self : in out XML_Namespace_Support'Class);
   --  Reset this Namespace support object for reuse.
   --
   --  It is necessary to invoke this method before reusing the Namespace
   --  support object for a new session.

private

   package String_Maps is
     new Ada.Containers.Hashed_Maps
          (League.Strings.Universal_String,
           League.Strings.Universal_String,
           League.Strings.Hash,
           League.Strings."=",
           League.Strings."=");

   type Context is record
      Prefix        : String_Maps.Map;
      Namespace_URI : String_Maps.Map;
   end record;

   package Context_Vectors is
     new Ada.Containers.Vectors (Positive, Context);

   type XML_Namespace_Support is new Ada.Finalization.Controlled with record
      Current : Context;
      Future  : Context;
      Stack   : Context_Vectors.Vector;
   end record;

   overriding procedure Initialize (Self : in out XML_Namespace_Support);
   --  Define default prefix mapping.

end XML.Utilities.Namespace_Supports;