-------------------------------------------------------- ------------------------ -- -- -- OCARINA COMPONENTS -- -- -- -- O C A R I N A . D I A . P A R S E R . C O R E . A T T R I B U T E S -- -- -- -- B o d y -- -- -- -- Copyright (C) 2005-2006, GET-Telecom Paris. -- -- -- -- Ocarina is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by the -- -- Free Software Foundation; either version 2, or (at your option) any -- -- later version. Ocarina is distributed in the hope that it will be -- -- useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -- -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -- -- Public License for more details. You should have received a copy of the -- -- GNU General Public License distributed with Ocarina; see file COPYING. -- -- If not, write to the Free Software Foundation, 51 Franklin Street, Fifth -- -- Floor, Boston, MA 02111-1301, USA. -- -- -- -- As a special exception, if other files instantiate generics from this -- -- unit, or you link this unit with other files to produce an executable, -- -- this unit does not by itself cause the resulting executable to be -- -- covered by the GNU General Public License. This exception does not -- -- however invalidate any other reasons why the executable file might be -- -- covered by the GNU Public License. -- -- -- -- Ocarina is maintained by the Ocarina team -- -- (ocarina-users@listes.enst.fr) -- -- -- ------------------------------------------------------------------------------ with Ada.Text_IO; use Ada.Text_IO; with DOM.Core.Nodes; package body Ocarina.Dia.Parser.Core.Attributes is -- Parses the dia:attribute node list of an object, and looks for -- a particular one function Get_Attribute_Node (NL : DOM.Core.node_list; Name : String) return DOM.Core.node is use DOM.Core; begin for I in 0 .. (DOM.Core.Nodes.Length (NL) - 1) loop declare Item : constant DOM.Core.node := DOM.Core.Nodes.Item (NL, I); begin if DOM.Core.Nodes.Node_Name (Item) = "dia:attribute" then if Get_Required_Attribute (DOM.Core.Nodes.Attributes (Item), "name") = Name then return Item; end if; end if; exception when Missing_Attribute => null; end; end loop; Put_Line (Name); raise Missing_Dia_Attribute; end Get_Attribute_Node; -- Parses a attribute, like declaration function Get_String_Attribute (E : DOM.Core.node) return Unbounded_String is use DOM.Core; Children : constant DOM.Core.node_list := DOM.Core.Nodes.Child_Nodes (E); N : DOM.Core.node; P : Natural := 0; R : Unbounded_String; begin Get_Required_Child (Children, "dia:string", P, N); N := DOM.Core.Nodes.First_Child (N); if N /= null and then N.Node_Type = text_node then R := To_Unbounded_String (DOM.Core.Nodes.Node_Value (N)); return R; end if; raise Illformed_Dia_Attribute; end Get_String_Attribute; -- Parses a name attribute and returns the name string function Get_Name_Attribute (E : DOM.Core.node) return Unbounded_String is use DOM.Core; Children : DOM.Core.node_list := DOM.Core.Nodes.Child_Nodes (E); N : DOM.Core.node; P : Natural := 0; begin Get_Required_Child (Children, "dia:composite", P, N); Children := DOM.Core.Nodes.Child_Nodes (N); N := Get_Attribute_Node (Children, "string"); return Get_String_Attribute (N); exception when Missing_Child => raise Illformed_Dia_Attribute; end Get_Name_Attribute; -- Parses a value attribute and returns the val string function Get_Val_Attribute (E : DOM.Core.node) return Unbounded_String is use DOM.Core; NA : DOM.Core.named_node_map; N : DOM.Core.node; R : Unbounded_String; begin N := DOM.Core.Nodes.First_Child (E); while N.Node_Type /= element_node loop N := DOM.Core.Nodes.Next_Sibling (N); end loop; begin NA := DOM.Core.Nodes.Attributes (N); R := To_Unbounded_String (Get_Required_Attribute (NA, "val")); return R; exception when others => raise Illformed_Dia_Attribute; end; end Get_Val_Attribute; end Ocarina.Dia.Parser.Core.Attributes;