Commit 51b78571 authored by gerd's avatar gerd

Introducing new exceptions Namespace_(prefix)_not_managed,

Namespace_not_in_scope.


git-svn-id: https://godirepo.camlcity.org/svn/lib-pxp/trunk@694 dbe99aee-44db-0310-b2b3-d33182c8eb97
parent 040d852c
......@@ -56,6 +56,11 @@ for PXP; if you are looking for the stable distribution, please go
<p>Revised namespace handling: There are now namespace_scope
objects keeping the scoping structure of the namespaces.
The namespace_info stuff has been removed.</p>
<p>New exceptions Namespace_not_managed, Namespace_prefix_not_managed,
Namespace_not_in_scope (all replacing Not_found). Methods
of namespace_manager may raise these exceptions.
</p>
<p>Addition of pxp-pp, the PXP preprocessor.</p>
</li>
<li><p><em>1.1.94.2:</em> Again fixes for the combination of
......
......@@ -254,7 +254,7 @@ class virtual core_parser
| Some uri ->
let normprefix =
try mng # get_normprefix uri
with Not_found ->
with Namespace_not_managed _ ->
mng # lookup_or_add_namespace "default" uri
in
ns_default_normprefix <- normprefix;
......
......@@ -238,6 +238,13 @@ exception Not_competent
exception Not_resolvable of exn
exception Namespace_not_managed of string
exception Namespace_prefix_not_managed of string
exception Namespace_not_in_scope of string
let rec string_of_exn x0 =
match x0 with
At (s, x) ->
......@@ -256,12 +263,20 @@ let rec string_of_exn x0 =
"INFORMATION: Undeclared"
| Method_not_applicable mname ->
"INTERNAL ERROR (method `" ^ mname ^ "' not applicable)"
| Namespace_method_not_applicable mname ->
"INTERNAL ERROR (namespace method `" ^ mname ^ "' not applicable)"
| Parsing.Parse_error ->
"SYNTAX ERROR"
| Not_competent ->
"NO COMPETENT RESOLVER FOUND"
| Not_resolvable x ->
"NOT RESOLVABLE: " ^ string_of_exn x
| Namespace_not_managed uri ->
"ERROR: NAMESPACE NOT MANAGED: " ^ uri
| Namespace_prefix_not_managed p ->
"ERROR: NAMESPACE PREFIX NOT MANAGED: " ^ p
| Namespace_not_in_scope uri ->
"ERROR: NAMESPACE NOT IN SCOPE: " ^ uri
| _ ->
"Other exception: " ^ Printexc.to_string x0
;;
......
......@@ -275,6 +275,23 @@ module type CORE_TYPES = sig
exception Not_resolvable of exn
(* While opening the entity, the nested exception occurred *)
exception Namespace_not_managed of string
(* A namespace URI is used but not declared in the namespace manager.
* The string argument is the URI in question.
* (New in PXP 1.2)
*)
exception Namespace_prefix_not_managed of string
(* A namespace prefix is used but not declared in the namespace manager.
* The string argument is the prefix in question.
* (New in PXP 1.2)
*)
exception Namespace_not_in_scope of string
(* The namespace scope does not know the URI *)
(* (New in PXP 1.2) *)
val string_of_exn : exn -> string
(* Converts a PXP exception into a readable string *)
......
......@@ -2956,14 +2956,7 @@ class [ 'ext ] namespace_element_impl an_ext =
let mng = self # namespace_manager in
List.map
(fun p ->
try
p, Value (mng # get_primary_uri p)
with
Not_found -> (* raised by get_primary_uri *)
failwith ("Pxp_document.namespace_element_impl#write: cannot map the prefix `" ^ p ^ "' to any URI")
)
(fun p -> p, Value (mng # get_primary_uri p) )
prefixes'
method private make_attribute_node element_name att_name value dtd =
......@@ -3045,7 +3038,7 @@ class [ 'ext ] namespace_element_impl an_ext =
else
let d =
try scope # display_prefix_of_normprefix p
with Not_found ->
with Namespace_not_in_scope _ ->
(* Display prefix is missing. This is an error, but we
* can search or invent a new prefix on the fly.
*)
......@@ -3061,7 +3054,7 @@ class [ 'ext ] namespace_element_impl an_ext =
let this_display_prefix =
try self # display_prefix
with Not_found ->
with Namespace_not_in_scope _ ->
(* Display prefix is missing. This is an error, but we
* can search or invent a new prefix on the fly.
*)
......
......@@ -39,7 +39,8 @@ object (self)
ignore(self # add_namespace "xml" "http://www.w3.org/XML/1998/namespace")
method add_uri (np:string) (uri:string) =
if not (Hashtbl.mem uri_of_prefix np) then raise Not_found;
if not (Hashtbl.mem uri_of_prefix np) then
raise(Namespace_prefix_not_managed np);
try
let np' = Hashtbl.find prefix_of_uri uri in
if np <> np' then
......@@ -84,18 +85,34 @@ object (self)
(* prefix = "": make sure that such a prefix is never added *)
method get_primary_uri normprefix =
Hashtbl.find primary_uri_of_prefix normprefix
try
Hashtbl.find primary_uri_of_prefix normprefix
with
Not_found ->
raise(Namespace_prefix_not_managed normprefix)
method get_uri_list normprefix =
Hashtbl.find_all uri_of_prefix normprefix
method get_normprefix uri =
Hashtbl.find prefix_of_uri uri
try
Hashtbl.find prefix_of_uri uri
with
Not_found ->
raise(Namespace_not_managed uri)
method iter_namespaces f =
Hashtbl.iter
(fun p uri -> f p)
primary_uri_of_prefix
method as_declaration =
let l = ref [] in
Hashtbl.iter
(fun p uri -> l := (p, uri) :: !l)
primary_uri_of_prefix;
!l
end
;;
......@@ -153,18 +170,20 @@ object(self)
Not_found ->
( match parent_opt with
Some pa -> pa # display_prefix_of_uri uri
| None -> raise Not_found
| None -> raise(Namespace_not_in_scope uri)
)
method display_prefix_of_normprefix np =
let uris = mng # get_uri_list np in
if uris = [] then raise(Namespace_prefix_not_managed np);
try
fst(List.find (fun (p,u) -> List.mem u uris) decl)
with
Not_found ->
( match parent_opt with
Some pa -> pa # display_prefix_of_normprefix np
| None -> raise Not_found
| None -> raise(Namespace_not_in_scope
(List.hd(List.rev uris)))
)
method uri_of_display_prefix dp =
......@@ -404,7 +423,7 @@ class dtd ?swarner the_warner init_encoding =
raise(Error("Cannot do pxp:dtd instruction: namespaces not enabled"))
| Some m ->
( try m # add_uri prefix uri
with Not_found ->
with Namespace_prefix_not_managed _ ->
m # add_namespace prefix uri
)
)
......
......@@ -78,10 +78,14 @@ class namespace_manager :
method add_uri : string -> string -> unit
(* add_uri np uri: adds uri as alias URI to the namespace identified
* by the normprefix np (see above for detailed semantics). The method
* raises Not_found if the normprefix np is unknown to the object,
* raises Namespace_prefix_not_managed if the normprefix np is unknown
* to the object,
* and it fails (Namespace_error) if the uri is member of a
* different namespace. Nothing happens if the uri is already member
* of the namespace np.
*
* CHANGE IN PXP 1.2: Using exception Namespace_prefix_not_managed
* instead of Not_found.
*)
method add_namespace : string -> string -> unit
(* add_namespace np uri: adds a new namespace to the object. The
......@@ -102,8 +106,12 @@ class namespace_manager :
* the normprefix.
*)
method get_primary_uri : string -> string
(* Return the primary URI for a normprefix, or raises Not_found.
* get_uri "" raises always Not_found.
(* Return the primary URI for a normprefix, or raises
* Namespace_prefix_not_managed. get_uri "" raises always this
* exception.
*
* CHANGE IN PXP 1.2: Using exception Namespace_prefix_not_managed
* instead of Not_found.
*)
method get_uri_list : string -> string list
(* Return all URIs for a normprefix, or [] if the normprefix is
......@@ -111,12 +119,22 @@ class namespace_manager :
* returned list is the primary URI.
*)
method get_normprefix : string -> string
(* Return the normprefix for a URI, or raises Not_found *)
(* Return the normprefix for a URI, or raises
* Namespace_not_managed.
*
* CHANGE IN PXP 1.2: Using exception Namespace_not_managed
* instead of Not_found.
*)
method iter_namespaces : (string -> unit) -> unit
(* Iterates over all namespaces contained in the object, and
* calls the passed function for every namespace. The argument of the
* invoked function is the normprefix of the namespace.
*)
method as_declaration : (string * string) list
(* Returns the list of normprefixes and primary URIs. Useful
* to create the corresponding namespace scope, e.g.
* new namespace_scope_impl mng None (mng#as_declaration)
*)
(* Encodings: prefixes and URIs are always encoded in the default
* encoding of the document
......@@ -168,13 +186,14 @@ object
*)
method display_prefix_of_uri : string -> string
(** Translates the URI to the corresponding display prefix as declared
* in this object or any parent object. Raises [Not_found] when the
* declaration cannot be found.
* in this object or any parent object. Raises [Namespace_not_in_scope]
* when the declaration cannot be found.
*)
method display_prefix_of_normprefix : string -> string
(** Translates the normalized prefix to the corresponding display
* prefix as declared in this object or any parent object. Raises
* [Not_found] when the declaration cannot be found, or the
* [Namespace_not_in_scope] when the declaration cannot be found, and
* [Namespace_prefix_not_managed] when the
* normalized prefix is unknown to the namespace manager.
*)
method uri_of_display_prefix : string -> string
......@@ -185,7 +204,8 @@ object
method normprefix_of_display_prefix : string -> string
(** Translates the display prefix to the corresponding normalized
* prefix as declared in this object or any parent object. Raises
* [Not_found] when the declaration cannot be found, or the
* [Not_found] when the declaration cannot be found, and
* [Namespace_not_managed] when the
* namespace manager does not know the namespace.
*)
end
......
......@@ -364,14 +364,10 @@ let subtree_from_cmd_sequence_nohead ~recode f0 dtd spec =
(* p is mapped to the primary URI of mng, and then mapped
* to the normprefix of dest_mng
*)
try
let primary_uri = mng # get_primary_uri p in
let normprefix =
dest_mng # lookup_or_add_namespace p primary_uri in
normprefix ^ ":" ^ l
with
Not_found ->
failwith "Pxp_marshal.subtree_from_cmd_sequence: Found an undeclared namespace prefix"
let primary_uri = mng # get_primary_uri p in
let normprefix =
dest_mng # lookup_or_add_namespace p primary_uri in
normprefix ^ ":" ^ l
end
in
let rec read_node dont_add first_cmd =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment