1573
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger
|
|
3 |
|
|
4 |
New code and modifications done at SWING Research Group [1]:
|
|
5 |
|
|
6 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
|
|
7 |
SWING Research Group, Czech Technical University in Prague
|
|
8 |
|
|
9 |
This software is furnished under a license and may be used
|
|
10 |
only in accordance with the terms of that license and with the
|
|
11 |
inclusion of the above copyright notice. This software may not
|
|
12 |
be provided or otherwise made available to, or used by, any
|
|
13 |
other person. No title to or ownership of the software is
|
|
14 |
hereby transferred.
|
|
15 |
|
|
16 |
[1] Code written at SWING Research Group contains a signature
|
|
17 |
of one of the above copright owners. For exact set of such code,
|
|
18 |
see the differences between this version and version stx:libjava
|
|
19 |
as of 1.9.2010
|
|
20 |
"
|
|
21 |
"{ Package: 'stx:libjava/examples' }"
|
|
22 |
|
|
23 |
Object subclass:#JavaExamples
|
|
24 |
instanceVariableNames:''
|
|
25 |
classVariableNames:''
|
|
26 |
poolDictionaries:''
|
1628
|
27 |
category:'Languages-Java-Examples'
|
1573
|
28 |
!
|
|
29 |
|
|
30 |
!JavaExamples class methodsFor:'documentation'!
|
|
31 |
|
|
32 |
copyright
|
|
33 |
"
|
|
34 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger
|
|
35 |
|
|
36 |
New code and modifications done at SWING Research Group [1]:
|
|
37 |
|
|
38 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
|
|
39 |
SWING Research Group, Czech Technical University in Prague
|
|
40 |
|
|
41 |
This software is furnished under a license and may be used
|
|
42 |
only in accordance with the terms of that license and with the
|
|
43 |
inclusion of the above copyright notice. This software may not
|
|
44 |
be provided or otherwise made available to, or used by, any
|
|
45 |
other person. No title to or ownership of the software is
|
|
46 |
hereby transferred.
|
|
47 |
|
|
48 |
[1] Code written at SWING Research Group contains a signature
|
|
49 |
of one of the above copright owners. For exact set of such code,
|
|
50 |
see the differences between this version and version stx:libjava
|
|
51 |
as of 1.9.2010
|
|
52 |
|
|
53 |
"
|
|
54 |
! !
|
|
55 |
|
|
56 |
!JavaExamples class methodsFor:'examples'!
|
|
57 |
|
|
58 |
example_1
|
1628
|
59 |
"A CD .xml parsing example. The handler prints each CD it parses
|
|
60 |
from given XML file. Demonstrates:
|
1573
|
61 |
- proxy creation
|
|
62 |
- exception handling
|
|
63 |
|
|
64 |
cd.xml may look like:
|
|
65 |
|
|
66 |
<?xml version='1.0' encoding='ISO-8859-1'?>
|
|
67 |
<catalog>
|
|
68 |
<cd>
|
|
69 |
<title>Empire Burlesque</title>
|
|
70 |
<artist>Bob Dylan</artist>
|
|
71 |
<country>USA</country>
|
|
72 |
<company>Columbia</company>
|
|
73 |
<price>10.90</price>
|
|
74 |
<year>1985</year>
|
|
75 |
</cd>
|
|
76 |
</catalog>
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
"
|
|
81 |
|
1628
|
82 |
| file factory parser |
|
|
83 |
|
|
84 |
file := (Smalltalk packageDirectoryForPackageId: self package) asFilename
|
|
85 |
/ 'data' / 'cd.xml'.
|
1573
|
86 |
|
|
87 |
factory := JAVA javax xml parsers SAXParserFactory newInstance.
|
|
88 |
parser := factory newSAXParser getXMLReader.
|
1628
|
89 |
parser setContentHandler: JavaExamples::CDDatabaseHandler1 new.
|
1573
|
90 |
[
|
1628
|
91 |
parser parse: file pathName
|
1573
|
92 |
] on: JAVA java io IOException do:[:ioe|
|
|
93 |
Transcript showCR: 'I/O error: ', ioe getMessage.
|
|
94 |
ioe printStackTrace
|
|
95 |
] on: UserNotification do:[:un|
|
|
96 |
Transcript showCR: un messageText.
|
|
97 |
un proceed.
|
|
98 |
]
|
|
99 |
|
|
100 |
"Created: / 13-05-2012 / 18:27:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
101 |
!
|
|
102 |
|
1628
|
103 |
example_2
|
|
104 |
"A CD .xml parsing example. The parser raises a UserNotification
|
|
105 |
whenever it parses a CD. The notification is then handled and printed.
|
|
106 |
Demonstrates:
|
|
107 |
- proxy creation
|
|
108 |
- exception handling
|
1573
|
109 |
|
1628
|
110 |
cd.xml may look like:
|
1573
|
111 |
|
1628
|
112 |
<?xml version='1.0' encoding='ISO-8859-1'?>
|
|
113 |
<catalog>
|
|
114 |
<cd>
|
|
115 |
<title>Empire Burlesque</title>
|
|
116 |
<artist>Bob Dylan</artist>
|
|
117 |
<country>USA</country>
|
|
118 |
<company>Columbia</company>
|
|
119 |
<price>10.90</price>
|
|
120 |
<year>1985</year>
|
|
121 |
</cd>
|
|
122 |
</catalog>
|
1573
|
123 |
|
|
124 |
|
1628
|
125 |
|
|
126 |
"
|
|
127 |
|
|
128 |
| file factory parser |
|
|
129 |
|
|
130 |
file := (Smalltalk packageDirectoryForPackageId: self package) asFilename
|
|
131 |
/ 'data' / 'cd.xml'.
|
|
132 |
|
|
133 |
factory := JAVA javax xml parsers SAXParserFactory newInstance.
|
|
134 |
parser := factory newSAXParser getXMLReader.
|
|
135 |
parser setContentHandler: JavaExamples::CDDatabaseHandler2 new.
|
|
136 |
[
|
|
137 |
parser parse: file pathName
|
|
138 |
] on: JAVA java io IOException do:[:ioe|
|
|
139 |
Transcript showCR: 'I/O error: ', ioe getMessage.
|
|
140 |
ioe printStackTrace
|
|
141 |
] on: UserNotification do:[:un|
|
|
142 |
Transcript showCR: un messageText.
|
|
143 |
un proceed.
|
1573
|
144 |
]
|
|
145 |
|
1628
|
146 |
"Created: / 20-08-2012 / 17:28:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
1573
|
147 |
! !
|
|
148 |
|
|
149 |
!JavaExamples class methodsFor:'documentation'!
|
|
150 |
|
|
151 |
version_SVN
|
|
152 |
^ '$Id:: $'
|
|
153 |
! !
|