Commit 3c47624b authored by Pietro Abate's avatar Pietro Abate
Browse files

[r2005-03-07 00:09:50 by afrisch] Partial hack to let PXP read relative external urls

Original author: afrisch
Date: 2005-03-07 00:09:50+00:00
parent 79b508a5
...@@ -20,7 +20,6 @@ let no_load_url s = ...@@ -20,7 +20,6 @@ let no_load_url s =
let load_url = ref no_load_url let load_url = ref no_load_url
type kind = File of string | Uri of string | String of string type kind = File of string | Uri of string | String of string
let kind s = let kind s =
...@@ -48,16 +47,7 @@ let local s1 s2 = ...@@ -48,16 +47,7 @@ let local s1 s2 =
~base_syntax:(Neturl.url_syntax_of_url url1) ~base_syntax:(Neturl.url_syntax_of_url url1)
s2 in s2 in
Neturl.string_of_url (Neturl.ensure_absolute_url ~base:url1 url2) Neturl.string_of_url (Neturl.ensure_absolute_url ~base:url1 url2)
(*
match (kind s1, kind s2) with
| File _, File _ ->
Filename.concat s1 s2
| _, (String _ | Uri _) | (String _, File _) ->
s2
| Uri _, File _ ->
if (s1 = "") || (s1.[String.length s1 - 1] = '/') then (s1 ^ s2)
else (s1 ^ "/" ^ s2)
*)
let process s = let process s =
match kind s with match kind s with
| File s -> Location.protect_op "loading file"; Filename s | File s -> Location.protect_op "loading file"; Filename s
......
type url = Filename of string | Url of string type url = Filename of string | Url of string
(* It recognizes if it is a valid url. If it is connect and bufferize
* in a string otherwise consider it as filename
*)
val process: string -> url val process: string -> url
val local: string -> string -> string val local: string -> string -> string
val load_url: (string -> string) ref val load_url: (string -> string) ref
...@@ -26,7 +26,7 @@ let load_expat s = ...@@ -26,7 +26,7 @@ let load_expat s =
Expat.set_end_element_handler p Load_xml.end_element_handler; Expat.set_end_element_handler p Load_xml.end_element_handler;
Expat.set_character_data_handler p Load_xml.text_handler; Expat.set_character_data_handler p Load_xml.text_handler;
try try
match s with match Url.process s with
| Url.Url s -> Expat.parse p s | Url.Url s -> Expat.parse p s
| Url.Filename s -> load_from_file p s | Url.Filename s -> load_from_file p s
with Expat.Expat_error e -> with Expat.Expat_error e ->
......
...@@ -18,14 +18,31 @@ let pxp_config = ...@@ -18,14 +18,31 @@ let pxp_config =
} }
let load_pxp s = let channel_of_id rt rid =
match rid.rid_system with
| Some local ->
let s = Url.local rt local in
let ch =
match Url.process s with
| Url.Url s -> new Netchannels.input_string s
| Url.Filename s -> raise Not_competent
in
ch, None, None
| None -> raise Not_competent
let load_pxp rt =
try try
let src = let src =
match s with match Url.process rt with
| Url.Url s -> from_string s | Url.Url s ->
| Url.Filename s -> from_file s in let channel_of_id = channel_of_id rt in
let r =
new Pxp_reader.resolve_to_any_obj_channel ~channel_of_id () in
from_string ~alt:[r] s
| Url.Filename s -> from_file s in
let mgr = create_entity_manager pxp_config src in let mgr = create_entity_manager pxp_config src in
process_entity pxp_config (`Entry_document[`Extend_dtd_fully]) mgr pxp_handle_event; process_entity pxp_config
(`Entry_document[`Extend_dtd_fully]) mgr pxp_handle_event;
with exn -> with exn ->
raise (Location.Generic (Pxp_types.string_of_exn exn)) raise (Location.Generic (Pxp_types.string_of_exn exn))
......
...@@ -91,7 +91,6 @@ let xml_parser = ref (fun s -> failwith "No XML parser available") ...@@ -91,7 +91,6 @@ let xml_parser = ref (fun s -> failwith "No XML parser available")
let load_xml s = let load_xml s =
let s = Url.process s in
try try
!xml_parser s; !xml_parser s;
match !stack with match !stack with
......
...@@ -4,7 +4,7 @@ val load_html: string -> Value.t ...@@ -4,7 +4,7 @@ val load_html: string -> Value.t
(* To define and register a parser *) (* To define and register a parser *)
val xml_parser: (Url.url -> unit) ref val xml_parser: (string -> unit) ref
val start_element_handler : string -> (string * string) list -> unit val start_element_handler : string -> (string * string) list -> unit
val end_element_handler : 'a -> unit val end_element_handler : 'a -> unit
......
...@@ -41,11 +41,28 @@ let new_xsd_config () = ...@@ -41,11 +41,28 @@ let new_xsd_config () =
let node_of src = let node_of src =
(Pxp_tree_parser.parse_wfdocument_entity (new_xsd_config ()) src spec) # root (Pxp_tree_parser.parse_wfdocument_entity (new_xsd_config ()) src spec) # root
open Pxp_types
let channel_of_id rt rid =
match rid.rid_system with
| Some local ->
let s = Url.local rt local in
let ch =
match Url.process s with
| Url.Url s -> new Netchannels.input_string s
| Url.Filename s -> raise Not_competent
in
ch, None, None
| None -> raise Not_competent
let node_of_uri uri = let node_of_uri uri =
try try
let source = match Url.process uri with let source = match Url.process uri with
| Url.Filename s -> Pxp_types.from_file s | Url.Filename s -> Pxp_types.from_file s
| Url.Url s -> Pxp_types.from_string s | Url.Url s ->
let channel_of_id = channel_of_id uri in
let r =
new Pxp_reader.resolve_to_any_obj_channel ~channel_of_id () in
from_string ~alt:[r] s
in in
node_of source node_of source
with exn -> raise (Location.Generic (Pxp_types.string_of_exn exn)) with exn -> raise (Location.Generic (Pxp_types.string_of_exn exn))
......
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