1(* 	$Id: Opaque.Mod,v 1.3 2003/05/20 20:10:33 mva Exp $	 *)
2MODULE URI:Scheme:Opaque;
3(*  Implementation of the generic opaque URI.
4    Copyright (C) 2000  Michael van Acken
5
6    This module is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Lesser General Public License
8    as published by the Free Software Foundation; either version 2 of
9    the License, or (at your option) any later version.
10
11    This module is distributed in the hope that it will be useful, but
12    WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Lesser General Public License for more details.
15
16    You should have received a copy of the GNU Lesser General Public
17    License along with OOC. If not, write to the Free Software Foundation,
18    59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19*)
20
21
22IMPORT
23  TextRider, CC := CharClass, Object, Exception, ADT:StringBuffer,
24  URI, URI:CharClass, URI:String;
25
26
27TYPE
28  Generic* = POINTER TO GenericDesc;
29  GenericDesc* = RECORD
30  (**This class implements the generic opaque URI.  *)
31    (URI.OpaqueURIDesc)
32    opaque-: STRING;
33  END;
34
35
36PROCEDURE Init* (uri: Generic; schemeId, opaque: STRING);
37  BEGIN
38    URI.InitOpaqueURI (uri, schemeId);
39    ASSERT (opaque # NIL);
40    uri. opaque := opaque
41  END Init;
42
43PROCEDURE New* (schemeId, opaque: STRING): Generic;
44  VAR
45    uri: Generic;
46  BEGIN
47    NEW (uri);
48    Init (uri, schemeId, opaque);
49    RETURN uri
50  END New;
51
52PROCEDURE (uri: Generic) Clone* (): Generic;
53  VAR
54    copy: Generic;
55  BEGIN
56    NEW (copy);
57    uri. Copy (copy);
58    RETURN copy
59  END Clone;
60
61PROCEDURE (uri: Generic) Copy* (dest: URI.URI);
62  BEGIN
63    uri. Copy^ (dest);
64    WITH dest: Generic DO
65      dest. opaque := uri. opaque;
66    END
67  END Copy;
68
69PROCEDURE IsValidOpaqueStr (str[NO_COPY]: ARRAY OF CHAR): URI.Offset;
70  VAR
71    i: URI.Offset;
72  BEGIN
73    IF (str[0] = "/") THEN
74      RETURN 0
75    ELSE
76      i := 0;
77      WHILE CharClass.SkipURIC (str, i) DO END;
78      IF (str[i] = 0X) THEN
79        RETURN -1
80      ELSE
81        RETURN i
82      END
83    END
84  END IsValidOpaqueStr;
85
86PROCEDURE (uri: Generic) ParseOpaquePart* (str: Object.CharsLatin1; offset: URI.Offset)
87RAISES Exception.ParseError;
88  VAR
89    pos: URI.Offset;
90  BEGIN
91    pos := IsValidOpaqueStr (str^);
92    IF (pos < 0) THEN
93      uri. opaque := String.Unescape(Object.NewLatin1(str^));
94    ELSE
95      RAISE(NEW(Exception.ParseError,
96                "Illegal character for opaque component of an URI",
97                pos+offset));
98    END
99  END ParseOpaquePart;
100
101PROCEDURE (uri: Generic) WriteXML* (w: TextRider.Writer);
102  BEGIN
103    w. WriteString (CC.eol+"<opaque-uri>");
104    IF (uri. schemeId # NIL) THEN
105      w. WriteString (CC.eol+"<scheme>");
106      w. WriteObject (uri. schemeId);
107      w. WriteString ("</scheme>")
108    END;
109    w. WriteString (CC.eol+"<opaque-part>");
110    w. WriteObject (uri. opaque);
111    w. WriteString ("</opaque-part>");
112    w. WriteString (CC.eol+"</opaque-uri>")
113  END WriteXML;
114
115PROCEDURE (uri: Generic) ToString*(): Object.String8;
116  VAR
117    sb: StringBuffer.StringBuffer;
118    str: STRING;
119  BEGIN
120    sb := StringBuffer.New("");
121    uri. AppendScheme (sb);
122    String.AppendEscaped (uri. opaque, CharClass.reserved, sb);
123    str := sb.ToString();
124    RETURN str(Object.String8);
125  END ToString;
126
127END URI:Scheme:Opaque.
128