summaryrefslogtreecommitdiff
path: root/sources/scala/tools/scaladoc/HTMLGenerator.java
blob: e804f5a24bde75251cd4c9bf9a436f0b6d3c6240 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
/*     ____ ____  ____ ____  ______                                     *\
**    / __// __ \/ __// __ \/ ____/    SOcos COmpiles Scala             **
**  __\_ \/ /_/ / /__/ /_/ /\_ \       (c) 2002-04, LAMP/EPFL           **
** /_____/\____/\___/\____/____/                                        **
**                                                                      **
** $Id$
\*                                                                      */

package scala.tools.scaladoc;

import java.io.Writer;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.IOException;
import java.net.URI;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Stack;
import java.util.regex.*;

import ch.epfl.lamp.util.XMLAttribute;
import ch.epfl.lamp.util.HTMLPrinter;
import ch.epfl.lamp.util.HTMLRepresentation;
import ch.epfl.lamp.util.Pair;
import ch.epfl.lamp.util.Position;
import ch.epfl.lamp.util.XHTMLPrinter;

import scalac.Global;
import scalac.Unit;
import scalac.symtab.Kinds;
import scalac.symtab.Modifiers;
import scalac.symtab.Scope;
import scalac.symtab.Scope.SymbolIterator;
import scalac.symtab.Symbol;
import scalac.symtab.Type;
import scalac.symtab.Type.*;
import scalac.symtab.SymbolTablePrinter;
import scalac.util.Debug;
import scalac.util.Name;
import scalac.util.Names;
import scalac.util.Strings;
import SymbolBooleanFunction;
import scalac.util.ScalaProgramArgumentParser;

/**
 * The class <code>HTMLGenerator</code> generates
 * the HTML documentation for a given Scala library.
 */
public abstract class HTMLGenerator {

    /*
     * Names of predefined page names.
     */
    protected final String FRAME_PAGE            = "index.html";
    protected final String ROOT_PAGE             = Location.ROOT_NAME + ".html";
    protected final String PACKAGE_LIST_PAGE     = "package-list-page.html";
    protected final String HELP_PAGE             = "help-page.html";
    protected final String SEARCH_SECTION        = "search-section";
    protected final String INDEX_PAGE            = "index-page.html";
    protected final String PACKAGE_PAGE          = "package-page.html";

    /*
     * Names of frames.
     */
    protected final String ROOT_FRAME     = "rootFrame";
    protected final String PACKAGES_FRAME = "packagesFrame";
    protected final String CLASSES_FRAME  = "classesFrame";
    protected final String SELF_FRAME     = "_self";

    /**
     * HTML DTD
     */
    protected final String[] HTML_DTD = new String[] { "xhtml1-transitional.dtd",
                                                        "xhtml-lat1.ent",
                                                        "xhtml-special.ent",
                                                        "xhtml-symbol.ent" };

    /**
     * HTML validator.
     */
    protected HTMLValidator xhtml;

    /*
     * XML attributes.
     */
    protected final XMLAttribute[] ATTRS_DOCTAG =
        new XMLAttribute[]{
            new XMLAttribute("style", "margin-top:10px;")
        };
    protected final XMLAttribute[] ATTRS_ENTITY =
        new XMLAttribute[]{ new XMLAttribute("class", "entity") };

    protected final XMLAttribute[] ATTRS_LIST =
        new XMLAttribute[] { new XMLAttribute("class", "list")};

    protected final XMLAttribute[] ATTRS_MEMBER =
        new XMLAttribute[]{
            new XMLAttribute("cellpadding", "3"),
            new XMLAttribute("class", "member")
        };
    protected final XMLAttribute[] ATTRS_MEMBER_DETAIL =
        new XMLAttribute[]{
            new XMLAttribute("cellpadding", "3"),
            new XMLAttribute("class", "member-detail")
        };

    protected final XMLAttribute[] ATTRS_MEMBER_TITLE =
        new XMLAttribute[]{ new XMLAttribute("class", "member-title") };

    protected final XMLAttribute[] ATTRS_MODIFIERS =
        new XMLAttribute[]{
            new XMLAttribute("valign", "top"),
            new XMLAttribute("class", "modifiers")
        };
    protected final XMLAttribute[] ATTRS_NAVIGATION =
        new XMLAttribute[]{ new XMLAttribute("class", "navigation") };

    protected final XMLAttribute[] ATTRS_NAVIGATION_LINKS =
        new XMLAttribute[]{
            new XMLAttribute("valign", "top"),
            new XMLAttribute("class", "navigation-links")
        };
    protected final XMLAttribute[] ATTRS_NAVIGATION_ENABLED = new XMLAttribute[]{
            new XMLAttribute("class", "navigation-enabled") };

    protected final XMLAttribute[] ATTRS_NAVIGATION_SELECTED = new XMLAttribute[]{
            new XMLAttribute("class", "navigation-selected") };

    protected final XMLAttribute[] ATTRS_NAVIGATION_PRODUCT =
        new XMLAttribute[]{
            new XMLAttribute("align", "right"),
            new XMLAttribute("valign", "top"),
            new XMLAttribute("style", "white-space:nowrap;"),
            new XMLAttribute("rowspan", "2")
        };
    protected final XMLAttribute[] ATTRS_PAGE_TITLE = new XMLAttribute[]{
            new XMLAttribute("class", "page-title")
        };
    protected final XMLAttribute[] ATTRS_SIGNATURE =
        new XMLAttribute[]{ new XMLAttribute("class", "signature") };

    protected final XMLAttribute[] ATTRS_TITLE_SUMMARY =
        new XMLAttribute[]{
            new XMLAttribute("colspan", "2"),
            new XMLAttribute("class", "title")
        };
    protected final XMLAttribute[] ATTRS_VALIDATION =
        new XMLAttribute[]{
            new XMLAttribute("style", "margin-top:5px; text-align:center; font-size:9pt;")
        };

    /** HTML meta information.
     */
    public static final String PRODUCT =
        System.getProperty("scala.product", "scaladoc");
    public static final String VERSION =
        System.getProperty("scala.version", "unknown version");
    protected final String GENERATOR = PRODUCT + " (" + VERSION + ")";
    protected final SimpleDateFormat df = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy");
    protected final XMLAttribute[] ATTRS_META =
        new XMLAttribute[]{ new XMLAttribute("generator", GENERATOR) };
    protected String getGenerator() {
    	return "Generated by " + GENERATOR + " on " + df.format(new Date());
    }

    /** Global compiler environment.
     */
    protected final Global global;

    /** Directory where to put generated HTML pages.
     */
    protected File directory;

    /** Comments associated with symbols.
     */
    protected Map/*<Symbol, Comment>*/ comments = new HashMap();

    /** The underlying HTML printer.
     */
    public Page page;

    /** The current URI.
     */
    protected URI uri;

    /**
     * The underlying symbol table printer.
     */
    protected MySymbolTablePrinter symtab;

    /**
     * The underlying document representation of the generated documentation.
     */
    protected HTMLRepresentation representation;

    /**
     * The command option settings.
     */
    protected String windowtitle;
    protected String doctitle;
    protected String stylesheet;
    protected boolean noindex;
    protected boolean validate;
    protected boolean launchServer;
    protected int port;

    /**
     * HTML pages may be generated recursively,
     * so we need to save active printers.
     */
    protected final Stack stack = new Stack();

    /**
     * Navigation context.
     */
    private final int ROOT_NAV_CONTEXT   = 0; // on the root page
    private final int INDEX_NAV_CONTEXT  = 1; // on the index page
    private final int HELP_NAV_CONTEXT   = 2; // on the help page
    private final int CONTAINER_NAV_CONTEXT = 3; // on a container page different from the root.

    /**
     * Variables used when loading this documentation generator.
     */
    public static final String DEFAULT_DOCTITLE = "";
    public static final String DEFAULT_WINDOWTITLE = "Generated Documentation";

    /** Root scope.
     */
    protected final Symbol root;

    /** Documented Symbols.
     */
    protected SymbolBooleanFunction isDocumented;

    /** ML module factory.
     */
    public abstract TypeIsomorphism newTypeIso(Global global);

    /**
     * Creates a new instance.
     *
     * @param global
     */
    protected HTMLGenerator(Global global) {
	this.global = global;
	this.root = global.definitions.ROOT_CLASS;
	this.uri = Location.makeURI(".");

        assert global.args instanceof HTMLGeneratorCommand;
        HTMLGeneratorCommand args = (HTMLGeneratorCommand) global.args;
        this.representation = new HTMLRepresentation(
            args.doctype.value,
            args.docencoding.value,
            HTMLRepresentation.DEFAULT_DOCLANGUAGE);
        this.windowtitle = args.windowtitle.value;
        this.doctitle = args.doctitle.value;
        this.stylesheet = args.stylesheet.value;
        this.noindex = args.noindex.value;
        this.validate = args.validate.value;
        this.launchServer = args.server.value;
        try {
            this.port = Integer.parseInt(args.port.value);
        }
        catch (NumberFormatException e) {
            this.port = 1280;
        }
        Symbol[] packages = getPackages(args.packages);
        final DocSyms docSyms = new DocSyms(global, packages);
        this.isDocumented = new SymbolBooleanFunction() {
		public boolean apply(Symbol sym) {
		    return docSyms.contains(sym) && ScalaSearch.isRelevant(sym)
                        && !getComment(sym).containsTag("@ignore");
		}
	    };
    }

    /** Relative URL of the definition of the given symbol.
     */
    protected String definitionURL(Symbol sym, Page page) {
        return page.rel(Location.get(sym));
    }

    protected String definitionURL(Symbol sym) {
        return definitionURL(sym, page);
    }

    /** Get the list pf packages to be documented.
     */
    protected Symbol[] getPackages(ScalaProgramArgumentParser option) {
	if (option.main != null) {
	    Symbol[] packages = new Symbol[option.args.length + 1];
	    packages[0] = global.definitions.getModule(option.main);
	    for(int i = 0; i < option.args.length; i++)
		packages[i+1] = global.definitions.getModule(option.args[i]);
	    return packages;
	}
	else
	    return new Symbol[] { root };
    }

    /** Get a file writer to a page.
     */
    protected static Writer fileWriter(File rootDirectory, URI uri) {
        try {
            File f = new File(rootDirectory, uri.toString());
            f.getParentFile().mkdirs();
            return new BufferedWriter(new FileWriter(f));
        } catch(IOException e) { throw Debug.abort(e); }
    }

    /**
     * Open a new documentation page and make it the current page.
     * @param uri   URL of the page
     * @param title Title of the page
     */
    protected void createPrinters(URI uri, String title, String destinationFrame) {
	stack.push(page);
	stack.push(symtab);
	// Create a new page.
	page = new Page(fileWriter(directory, uri), uri, destinationFrame,
			title, representation,
			stylesheet/*, script*/);
	// Create a printer to print symbols and types.
	symtab = SymbolTablePrinterFactory.makeHTML(page, isDocumented);
	page.open();
    }

    /**
     * Close the current page.
     */
    protected void closePrinters() {
        page.close();
        symtab = (MySymbolTablePrinter) stack.pop();
        page = (Page) stack.pop();
    }

    /**
     * Check if the outpath is valid.
     */
    private boolean checkOutpath()  {
        String text = "Output path \"" + global.outpath + "\" ";
        boolean ok = false;
        try {
            directory = new File(global.outpath);
            if (! directory.exists())
                global.reporter.error(null, text + "does not exist");
            else if (! directory.isDirectory())
                global.reporter.error(null, text + "is not a directory");
            else if (! directory.canWrite())
                global.reporter.error(null, text + "cannot be modified");
            else
                ok = true;
        } catch (NullPointerException e) {
            global.reporter.error(null, e.getMessage());
        }
        return ok;
    }

    /**
     * Generates the HTML pages.
     */
    public void apply() {

        if (! checkOutpath())
            return;

        this.xhtml = new HTMLValidator(getResourceURL(HTML_DTD[0]));

        // page with list of packages
        createPackageIndexPage();

        // class and object pages
        ScalaSearch.foreach(root,
			    new ScalaSearch.SymFun() {
				public void apply(Symbol sym) {
				    if (ScalaSearch.isContainer(sym) &&
					isDocumented.apply(sym)) {
 					createPages(sym);
 					if (sym.isPackage() || sym.isPackageClass()) {
 					    createContainerIndexPage(sym);
                                        }
				    }
				}
			    }
			    );

	if (!noindex) {
            // page with index of Scala documented entities.
	    createIndexPage();
        }

        createHelpPage();

	// frame description page
	createFramePage();

        // style sheet
        createResource(HTMLPrinter.DEFAULT_STYLESHEET, null);

        // script
        createResource(HTMLPrinter.DEFAULT_JAVASCRIPT, null);

        // launch HTTP server
        if (launchServer) {
            Servlet servlet = new ScaladocServlet();
            Servlet[] servlets = new Servlet[]{ servlet };
            //	File directory = new File(global.outpath);
            try {
                HTTPServer webServer = new HTTPServer(directory, port, servlets);
                webServer.start();
            }
            catch (IOException e) {
                System.out.println("Server could not start because of an "
                                   + e.getClass());
                System.out.println(e);
            }
            // to prevent going to the next phase (implies checking
            // errors when parsing a type after RefCheck)
            try {
                synchronized(this) { wait(); }
            }
            catch(InterruptedException e) {
                System.err.println("Error while waiting.");
                System.exit(0);
            }
        }

    }

    /**
     * Returns the comment associated with a given symbol.
     *
     * @param sym
     */
    protected Comment getComment(Symbol sym) {
	Comment comment = (Comment) comments.get(sym);
	if (comment == null) {
            Pair p = (Pair) global.mapSymbolComment.get(sym);
            if (p != null) {
                String s = (String) p.fst;
                Unit unit = (Unit) p.snd;
                comment = new Comment(s, sym, unit, xhtml);
            }
            else { // comment inheritance
                Symbol overriden = ScalaSearch.overridenBySymbol(sym);
                if (overriden == Symbol.NONE)
                    comment = new Comment(null, sym, null, xhtml);
                else
                    comment = getComment(overriden);
                //s = "/** (Inherited comment) " + getComment(overriden).rawText + "*/";
            }
            comments.put(sym, comment);
	}
	return comment;
    }

    /**
     * Filters modifiers so that modifiers added by the analyzer are
     * not printed.
     */
    protected String filterModifiers(Symbol sym) {
        int flags = sym.flags;
        if (sym.isPackage() || sym.isPackageClass()) {
            if ((flags & Modifiers.FINAL) != 0)
                flags = flags - Modifiers.FINAL;
        }
        if (sym.isModule()) {
            if ((flags & Modifiers.FINAL) != 0)
                flags = flags - Modifiers.FINAL;
        }
        if (sym.isTrait()) {
            if ((flags & Modifiers.ABSTRACT) != 0)
                flags = flags - Modifiers.ABSTRACT;
            if ((flags & Modifiers.INTERFACE) != 0)
                flags = flags - Modifiers.INTERFACE;
        }
        return Modifiers.Helper.toString(flags);
    }

    /**
     * Generates a HTML page for a class or object definition.
     */
    protected void createPages(Symbol sym) {
	String title = Location.getName(sym);
        createPrinters(Location.getURI(sym), title, SELF_FRAME);
        page.printHeader(ATTRS_META, getGenerator());
	page.printOpenBody();

	if (sym.isRoot())
	    addNavigationBar(ROOT_NAV_CONTEXT);
	else
	    addNavigationBar(CONTAINER_NAV_CONTEXT);
        page.printlnHLine();

        addTitle(sym);
        addDocumentationComment(sym);
        page.printlnHLine();

        String[] titles = new String[]{ "Field", "Method", "Object",
            "Trait", "Class", "Package" }; // "Constructor"
        String[] inherited = new String[]{ "Fields", "Methods", "Objects",
            "Traits", "Classes", "Packages" };
	Symbol[][] members =
            ScalaSearch.splitMembers(ScalaSearch.members(sym, isDocumented));
	for (int i = 0; i < members.length; i++) {
	    addMemberSummary(members[i], titles[i] + " Summary");
	    if (i == 1) addInheritedMembers(sym, inherited[i]);
        }
	for (int i = 0; i < titles.length; i++)
            addMemberDetail(members[i], titles[i] + " Detail");

        page.printlnHLine();
	if (sym.isRoot())
	    addNavigationBar(ROOT_NAV_CONTEXT);
	else
	    addNavigationBar(CONTAINER_NAV_CONTEXT);
        if (validate)
            addValidationBar();

	page.printFootpage();
        closePrinters();
    }

    /**
     * Writes the product name and version to the current page.
     *
     * @param attrs
     */
    protected void addDocumentationTitle(XMLAttribute[] attrs, Page page) {
        page.printlnOTag("div", attrs).indent();
        page.println(doctitle).undent();
        page.printlnCTag("div");
    }

    protected void addDocumentationTitle(XMLAttribute[] attrs) {
        addDocumentationTitle(attrs, page);
    }

    protected void addSearchSection(Page page) {
	page.printlnOTag("form", new XMLAttribute[] {
            new XMLAttribute("action", "/" + SERVLET_NAME),
            new XMLAttribute("method", "get") }).indent();

        page.printlnOTag("table", new XMLAttribute[] {
            new XMLAttribute("border", "0") }).indent();

        // Text field
        page.printlnOTag("tr").indent();
        page.printlnOTag("td").indent();
        page.printlnSTag("input", new XMLAttribute[] {
            new XMLAttribute("name", "searchString"),
            new XMLAttribute("id", "word"),
            new XMLAttribute("size", "100%"),
            // new XMLAttribute("maxlength", "30"),
            new XMLAttribute("type", "text"),
        });
        // Button
	page.printlnSTag("input", new XMLAttribute[] {
            new XMLAttribute("type", "submit"),
            new XMLAttribute("value", "Search"),
        }).undent();
        page.printlnCTag("td").undent();
	page.printlnCTag("tr");

        page.printlnOTag("tr").indent();
        page.printlnOTag("td", new XMLAttribute[] {
            new XMLAttribute("align", "center") }).indent();
        // by name
	page.printlnSTag("input", new XMLAttribute[] {
            new XMLAttribute("type", "radio"),
            new XMLAttribute("checked", "true"),
            new XMLAttribute("name", "searchKind"),
            new XMLAttribute("id", "byName"),
            new XMLAttribute("value", "byName")
        });
        page.println("By name");
        // by comment
	page.printlnSTag("input", new XMLAttribute[] {
            new XMLAttribute("type", "radio"),
            new XMLAttribute("name", "searchKind"),
            new XMLAttribute("id", "byComment"),
            new XMLAttribute("value", "byComment")
        });
        page.println("By comment");
        // by type
	page.printlnSTag("input", new XMLAttribute[] {
            new XMLAttribute("type", "radio"),
            new XMLAttribute("name", "searchKind"),
            new XMLAttribute("id", "byType"),
            new XMLAttribute("value", "byType")
        });
        page.println("By type").undent();
        page.printlnCTag("td").undent();
	page.printlnCTag("tr").undent();
	page.printlnCTag("table").undent();
	page.printlnCTag("form");
    }

    protected void addSearchSection() {
        addSearchSection(page);
    }

    /**
     * Writes the navigation bar to the current page.
     *
     * @param sym
     */
    protected void addNavigationBar(int navigationContext, Page page) {
	try {
	    String overviewLink = page.rel(ROOT_PAGE);
	    String indexLink    = page.rel(INDEX_PAGE);
	    String helpLink     = page.rel(HELP_PAGE);

	    page.printlnOTag("table", ATTRS_NAVIGATION).indent();
	    page.printlnOTag("tr").indent();
	    page.printlnOTag("td", ATTRS_NAVIGATION_LINKS).indent();
	    page.printlnOTag("table").indent();
	    page.printlnOTag("tr").indent();

	    // overview link
	    if (navigationContext == ROOT_NAV_CONTEXT)
		page.printlnTag("td", ATTRS_NAVIGATION_SELECTED, "Overview");
	    else {
		page.printOTag("td", ATTRS_NAVIGATION_ENABLED);
		page.printAhref(overviewLink, SELF_FRAME, "Overview");
		page.printlnCTag("td");
	    }
	    // index link
	    if (navigationContext == INDEX_NAV_CONTEXT)
		page.printlnTag("td", ATTRS_NAVIGATION_SELECTED, "Index");
	    else {
		page.printOTag("td", ATTRS_NAVIGATION_ENABLED);
		page.printAhref(indexLink, SELF_FRAME, "Index");
		page.printlnCTag("td");
	    }
	    // help link
	    if (navigationContext == HELP_NAV_CONTEXT)
		page.printlnTag("td", ATTRS_NAVIGATION_SELECTED, "Help");
	    else {
		page.printOTag("td", ATTRS_NAVIGATION_ENABLED);
		page.printAhref(helpLink, SELF_FRAME, "Help");
		page.printlnCTag("td");
	    }

	    page.undent();
	    page.printlnCTag("tr").undent();
	    page.printlnCTag("table").undent();
	    page.printlnCTag("td");

	    // product & version
	    page.printlnOTag("td", ATTRS_NAVIGATION_PRODUCT).indent();
	    addDocumentationTitle(new XMLAttribute[]{
                                      new XMLAttribute("class", "doctitle")}, page);
	    page.undent();
	    page.printlnCTag("td").undent();

	    page.printlnCTag("tr");

	    page.printlnOTag("tr").indent();
	    page.printlnTag("td", "&nbsp;").undent();
	    page.printlnCTag("tr").undent();
            if (launchServer) {
                page.printlnOTag("tr").indent();
                addSearchSection(page);
                page.undent();
                page.printlnCTag("tr");
            }
	    page.printlnCTag("table");
	} catch(Exception e) { throw Debug.abort(e); }
    }

    protected void addNavigationBar(int navigationContext) {
        addNavigationBar(navigationContext, page);
    }

    /**
     * Writes the validation bar to the current page.
     */
    protected void addValidationBar() {
        page.printlnOTag("div", ATTRS_VALIDATION);
        page.indent();
        page.printlnAhref(
			  "http://validator.w3.org/check/referer", SELF_FRAME,
			  "validate html");
        page.undent();
        page.printlnCTag("div");
    }

    /**
     * Writes the signature of the class or object to the current page.
     *
     * @param sym
     */
    protected void addTitle(Symbol sym) {
        if (sym.isRoot()) {
            page.printlnOTag("div", ATTRS_PAGE_TITLE).indent();
            page.println(doctitle.replaceAll("<.*>", " "));
            page.printlnSTag("br");
            page.println("API Specification").undent();
            page.printlnCTag("div");
            page.println("This document is the API specification for "
                + doctitle.replaceAll("<.*>", " ") + ".");
            page.printlnSTag("p");
        } else {
	    // in
	    page.print("in ");
	    printPath(sym.owner(), SELF_FRAME);

            // kind and name
	    page.printlnOTag("div", ATTRS_ENTITY).indent();
            page.print(symtab.getSymbolKeywordForDoc(sym) + " ");
	    page.printlnTag("span", ATTRS_ENTITY, sym.nameString()).undent();
	    page.printlnCTag("div");
	    page.printlnHLine();

	    // complete signature
	    // !!! page.println(printer().printTemplateHtmlSignature(sym, false).toString());
	    printTemplateHtmlSignature(sym, false);

	    // implementing classes or modules
	    // Maps classes to their direct implementing classes or modules
	    Map subs = ScalaSearch.subTemplates(root, isDocumented);

	    if (sym.isClass()) {
		List subList = (List) subs.get(sym);
		if (subList != null && subList.size() != 0) {
		    page.printlnOTag("dl").indent();
		    page.printlnOTag("dt");
		    page.printlnBold("Implementing classes or objects:");
		    page.printlnCTag("dt");
		    Iterator it = subList.iterator();
		    while (it.hasNext()) {
			Pair p = (Pair) it.next();
			Symbol sub = (Symbol) p.fst;
			Type tipe = (Type) p.snd;
			page.printlnOTag("dd");

			symtab.defString(sub, true /*addLink*/);
			if (sub.owner() != sym.owner()) {
                            page.print(" in ");
			    printPath(sub.owner(), SELF_FRAME);
                        }
			page.printlnCTag("dd");
		    }
                    page.undent();
		    page.printlnCTag("dl");
		}
	    }
 	}
    }

    /**
     * Writes a documentation comment to the current page.
     *
     * @param sym
     */
    protected void addDocumentationComment(Symbol sym) {
	Comment comment = getComment(sym);
	if (!comment.isEmpty()) {
	    page.printlnHLine();
	    addComments(comment);
	}
    }

    /**
     * Writes a sorted list of all members with a short summary
     * for each one.
     *
     * @param members
     * @param title
     */
    protected void addMemberSummary(Symbol[] members, String title) {
	if (members.length > 0) {
	    Symbol[] sortedMembers = new Symbol[members.length];
	    for (int i = 0; i < members.length; i++) {
		assert members[i] != null : "HA ENFIN !";
		sortedMembers[i] = members[i];
	    }
	    Arrays.sort(sortedMembers, ScalaSearch.symAlphaOrder);

	    // open table
	    page.printlnOTag("table", ATTRS_MEMBER).indent();

	    // title
	    page.printlnOTag("tr").indent();
	    page.printlnOTag("td", ATTRS_TITLE_SUMMARY).indent();
	    page.println(title).undent();
	    page.printlnCTag("td").undent();
	    page.printlnCTag("tr");

	    // members
	    for (int i = 0; i < members.length; i++)
		addMemberSummary(sortedMembers[i]);

	    // close table
            page.undent();
	    page.printlnCTag("table");
	    page.printlnSTag("br");
	}
    }

    /**
     * Writes the summary of a member symbol to the current page.
     *
     * @param sym
     */
    protected void addMemberSummary(Symbol sym) {
	page.printlnOTag("tr").indent();

	// modifiers
        String mods = filterModifiers(sym);
	page.printlnOTag("td", ATTRS_MODIFIERS).indent();
	if (mods.length() > 0)
	    page.printlnTag("code", mods);
	else
	    page.printlnNbsp(1);
	page.undent();
	page.printlnCTag("td");

	// signature
	page.printlnOTag("td", ATTRS_SIGNATURE).indent();
	page.printOTag("code");
	symtab.defString(sym, true /*addLink*/);
	page.printlnCTag("code");

	// short description
	String firstSentence = firstSentence(getComment(sym));
	if (! firstSentence.equals("")) {
	    page.printlnSTag("br");
	    page.printNbsp(4);
	    page.println(firstSentence);
	}
	page.undent();
	page.printlnCTag("td").undent();
	page.printlnCTag("tr");
    }

    /**
     * Adds a list of all members with all details.
     *
     * @param members
     */
    protected void addMemberDetail(Symbol[] members, String title) {
	boolean first = true;
	for (int i = 0; i < members.length; i++) {
            Symbol sym = members[i];
	    if (!ScalaSearch.isContainer(sym)) {
		if (first) {
		    page.printlnOTag("table", ATTRS_MEMBER_DETAIL).indent();
                    page.printlnOTag("tr").indent();
                    page.printlnTag("td", ATTRS_MEMBER_TITLE, title).undent();
                    page.printlnCTag("tr").undent();
                    page.printlnCTag("table");
		    first = false;
		} else
		    page.printlnHLine();
		addMemberDetail(sym);
	    }
	}
    }

    /**
     * Writes the detail of a member symbol to the page, but create
     * instead a separate page for a class or an object.
     *
     * @param sym
     */
    protected void addMemberDetail(Symbol sym) {
	// title with label
	page.printlnAname(Page.asSeenFrom(Location.getURI(sym), uri).getFragment(), "");
	page.printTag("h3", sym.nameString());

	// signature
	page.printlnOTag("pre");
        String mods = filterModifiers(sym);
        //	String mods = Modifiers.Helper.toString(sym.flags);
	if (mods.length() > 0) page.print(mods + " ");
	symtab.printSignature(sym, false /*addLink*/);
	page.printlnCTag("pre");

	// comment
	addComments(getComment(sym));
    }

    /**
     * Add for each "strict" base type of this class or object symbol
     * the members that are inherited by this class or object.
     *
     * @param sym
     */
    protected void addInheritedMembers(Symbol sym, String inheritedMembers) {
        Symbol[] syms = ScalaSearch.collectMembers(sym);
	Pair grouped = ScalaSearch.groupSymbols(syms);
	Symbol[] owners = (Symbol[]) grouped.fst;
	Map/*<Symbol, Symbol[]>*/ group = (Map) grouped.snd;
	for (int i = 0; i < owners.length; i++) {
	    if (owners[i] != sym.moduleClass()) {
                page.printlnOTag("table", ATTRS_MEMBER).indent();

		// owner
                page.printlnOTag("tr").indent();
                page.printlnOTag("td", new XMLAttribute[]{
		    new XMLAttribute("class", "inherited-owner")}).indent();
                page.print(inheritedMembers + " inherited from ");
		printPath(owners[i], SELF_FRAME);
                page.undent();
                page.printlnCTag("td").undent();
                page.printlnCTag("tr");

		// members
                page.printlnOTag("tr").indent();
                page.printlnOTag("td", new XMLAttribute[]{
                   new XMLAttribute("class", "inherited-members")}).indent();
		Symbol[] members = (Symbol[]) group.get(owners[i]);
		for (int j = 0; j < members.length; j++) {
		    if (j > 0) page.print(", ");
		    symtab.printSymbol(members[j], true);
		}
                page.undent();
                page.printlnCTag("td").undent();
                page.printlnCTag("tr").undent();
                page.printlnCTag("table");
                page.printlnSTag("br");
	    }
	}
    }

    /**
     * Prints the signature of a class symbol.
     *
     * @param symbol
     * @param addLink
     */
    public void printTemplateHtmlSignature(Symbol symbol, boolean addLink) {
	// modifiers
        String mods = filterModifiers(symbol);
        //        String mods = Modifiers.Helper.toString(symbol.flags);
	page.printlnOTag("dl");
	page.printlnOTag("dt");
	symtab.print(mods).space();

        // kind
	String keyword = symtab.getSymbolKeywordForDoc(symbol);
        if (keyword != null) symtab.print(keyword).space();
        String inner = symtab.getSymbolInnerString(symbol);

        // name
	symtab.printDefinedSymbolName(symbol, addLink);
	if (symbol.isClass()) {
	    // type parameters
	    Symbol[] tparams = symbol.typeParams();
	    if (tparams.length != 0 || global.debug) {
		symtab.print('[');
		for (int i = 0; i < tparams.length; i++) {
		    if (i > 0) symtab.print(",");
		    symtab.printSignature(tparams[i], false);
		}
		symtab.print(']');
	    }
	    // value parameters
	    Symbol[] vparams = symbol.valueParams();
	    symtab.print('(');
	    for (int i = 0; i < vparams.length; i++) {
		if (i > 0) symtab.print(", ");
		if (vparams[i].isDefParameter()) symtab.print("def ");
		symtab.defString(vparams[i], false);
	    }
	    symtab.print(')');
	}

        // parents
        Type[] parts = symbol.moduleClass().parents();
        page.printlnCTag("dt");
        for (int i = 0; i < parts.length; i++) {
            page.printOTag("dd");
            symtab.print((i == 0) ? "extends " : "with ");
            symtab.printType(parts[i]);
	    page.printlnCTag("dd");
	}
	page.printCTag("dl");
    }

    /**
     * Creates the page describing the different frames.
     *
     * @param title The page title
     */
    protected void createFramePage() {
        createPrinters(Location.makeURI(FRAME_PAGE), windowtitle, "");
        page.printHeader(ATTRS_META, getGenerator());

	page.printlnOTag("frameset", new XMLAttribute[] {
            new XMLAttribute("cols", "25%, 75%")}).indent();
	page.printlnOTag("frameset", new XMLAttribute[] {
            new XMLAttribute("rows", "50%, 50%")}).indent();

	page.printlnOTag("frame", new XMLAttribute[] {
            new XMLAttribute("src", PACKAGE_LIST_PAGE),
            new XMLAttribute("name", PACKAGES_FRAME)});
	page.printlnOTag("frame", new XMLAttribute[] {
            new XMLAttribute("src", PACKAGE_PAGE),
            new XMLAttribute("name", CLASSES_FRAME)}).undent();
	page.printlnCTag("frameset");
	page.printlnOTag("frame", new XMLAttribute[] {
            new XMLAttribute("src", ROOT_PAGE),
            new XMLAttribute("name", ROOT_FRAME)});

        page.printlnOTag("noframes").indent();
        page.printlnSTag("p");
        page.print("Here is the ");
        page.printAhref(ROOT_PAGE, "non-frame based version");
        page.println(" of the documentation.").undent();
        page.printlnCTag("noframes").undent();

        page.printlnCTag("frameset");
        page.printlnCTag("html");

        closePrinters();
    }

    /**
     * Get the URL (as a string) of a resource located in the
     * directory "resources" relative to the classfile of this class.
     */
    protected String getResourceURL(String name) {
        String rsc = HTMLGenerator.class
            .getResource("resources/" + name)
            .toString();
        //        System.out.println("Some used resource: " + rsc);
        return rsc;
    }

    /**
     * Generates a resource file.
     *
     * @param name The name of the resource file
     */
    protected void createResource(String name, String dir) {
        File dest;
        if (dir == null)
            dest = new File(directory, name);
        else {
            File f = new File(directory, dir);
            f.mkdirs();
            dest = new File(f, name);
        }
        String rsrcName = "resources/" + name;
        InputStream in = HTMLGenerator.class.getResourceAsStream(rsrcName);
        if (in == null)
	    throw Debug.abort("Resource file \"" + rsrcName + "\" not found");
        try {
            FileOutputStream out = new FileOutputStream(dest);

            byte[] buf = new byte[1024];
            int len;
            while (true) {
                len = in.read(buf, 0, buf.length);
                if (len <= 0) break;
               out.write(buf, 0, len);
            }

            in.close();
            out.close();
	} catch (IOException exception) {
	    throw Debug.abort(exception); // !!! reporting an error would be wiser
	}
    }

    private String removeHtmlSuffix(String url) {
	return url.substring(0, url.length() - 5);
    }

    /** Returns the summary page attached to a package symbol. */
    private String packageSummaryPage(Symbol sym) {
	if (sym.isRoot())
	    return PACKAGE_PAGE;
	else {
	    String packagePage = Location.getURI(sym).toString();
	    return removeHtmlSuffix(packagePage) + File.separator + PACKAGE_PAGE;
	}
    }

    /**
     * Writes a table containing a list of packages to the current page.
     *
     * @param syms The package list
     * @param title The title of the package list
     */
    private void printPackagesTable(Symbol[] syms, String title) {
        if (syms.length > 0) {
            page.printlnBold(title);
	    page.printlnOTag("table", ATTRS_LIST).indent();
	    page.printlnOTag("tr").indent();
	    page.printlnOTag("td", new XMLAttribute[] {
                new XMLAttribute("style", "white-space:nowrap;")}).indent();
	    for (int i = 1; i < syms.length; i++) {
	        Symbol sym = syms[i];
                page.printAhref(
                    packageSummaryPage(sym),
                    CLASSES_FRAME,
		    removeHtmlSuffix(Location.getURI(sym).toString()));
	        page.printlnSTag("br");
	    }
            page.undent();
	    page.printlnCTag("td").undent();
	    page.printlnCTag("tr").undent();
	    page.printlnCTag("table");
            page.printlnSTag("p");
        }
    }

    /**
     * Writes a table containing a list of symbols to the current page.
     *
     * @param syms
     * @param title
     */
    private void addSymbolTable(Symbol[] syms, String title, boolean useFullName) {
        if (syms.length > 0) {
            page.printlnBold(title);
	    page.printlnOTag("table", ATTRS_LIST).indent();
	    page.printlnOTag("tr").indent();
	    page.printlnOTag("td", new XMLAttribute[] {
                new XMLAttribute("style", "white-space:nowrap;")}).indent();
	    for (int i = 0; i < syms.length; i++) {
	        Symbol sym = syms[i];
                if (! sym.isRoot()) {
                    String name = sym.nameString();
                    if (sym.isPackage() || sym.isPackageClass())
                        page.printAhref(definitionURL(sym), CLASSES_FRAME, name);
                    else {
                        Symbol user = (useFullName) ? global.definitions.ROOT_CLASS : Symbol.NONE;
                        page.printAhref(definitionURL(sym), ROOT_FRAME, name);
                    }
	            page.printlnSTag("br");
                }
	    }
            page.undent();
	    page.printlnCTag("td").undent();
	    page.printlnCTag("tr").undent();
	    page.printlnCTag("table");
            page.printlnSTag("p");
        }
    }

    /**
     * Creates a page with the list of packages.
     *
     * @param title
     */
    protected void createPackageIndexPage() {
	createPrinters(Location.makeURI(PACKAGE_LIST_PAGE), "List of packages", CLASSES_FRAME);
        page.printHeader(ATTRS_META, getGenerator());
	page.printOpenBody();

        Symbol[] packages = ScalaSearch.getSortedPackageList(root, isDocumented);

        addDocumentationTitle(new XMLAttribute[]{
            new XMLAttribute("class", "doctitle-larger")});
        page.printAhref(PACKAGE_PAGE, CLASSES_FRAME, "All objects, traits and classes");
        page.printlnSTag("p");
        printPackagesTable(packages, "Packages");
        if (validate)
            addValidationBar();

	page.printFootpage();
	closePrinters();
    }

    /**
     * Creates a page with a list of classes or objects.
     *
     * @param sym
     */
    protected void createContainerIndexPage(Symbol sym) {
        createPrinters(Location.makeURI(packageSummaryPage(sym)), Location.getName(sym), ROOT_FRAME);
        page.printHeader(ATTRS_META, getGenerator());
	page.printOpenBody();

	page.printlnOTag("table", ATTRS_NAVIGATION).indent();
	page.printlnOTag("tr").indent();
	page.printlnOTag("td", ATTRS_NAVIGATION_LINKS).indent();
	printPath(sym, ROOT_FRAME);
	page.printlnCTag("td");
	page.printlnCTag("tr");
	page.printlnCTag("table");
	page.printlnSTag("p");

        String[] titles = new String[]{ "Objects", "Traits", "Classes" };
	if (sym.isRoot()) {
	    Symbol[][] members = ScalaSearch.getSubContainerMembers(root, isDocumented);
	    for (int i = 0; i < titles.length; i++)
		addSymbolTable(members[i], "All " + titles[i], true);
	} else {
	    Symbol[][] members = ScalaSearch.splitMembers(ScalaSearch.members(sym, isDocumented));
	    for (int i = 0; i < titles.length; i++) {
                Arrays.sort(members[i + 2], ScalaSearch.symAlphaOrder);
		addSymbolTable(members[i + 2], titles[i], false);
            }
	}

        if (validate)
            addValidationBar();

	page.printFootpage();
        closePrinters();
    }

    /**
     * Creates the index page.
     *
     * @param title The page title
     */
    protected void createIndexPage() {
	String title = "Scala Library Index";
	createPrinters(Location.makeURI(INDEX_PAGE), title, SELF_FRAME);
        page.printHeader(ATTRS_META, getGenerator());
	page.printOpenBody();

        addNavigationBar(INDEX_NAV_CONTEXT);
        page.printlnHLine();

        page.printlnOTag("table", ATTRS_MEMBER).indent();
        page.printlnOTag("tr").indent();
        page.printlnOTag("td", ATTRS_MEMBER_TITLE).indent();
        page.println("Index").undent();
        page.printlnCTag("td").undent();
        page.printlnCTag("tr").undent();
        page.printlnCTag("table");
        page.printlnSTag("br");

	Pair index = ScalaSearch.index(root, isDocumented);
	Character[] chars = (Character[]) index.fst;
	Map map = (Map) index.snd;
	for (int i  = 0; i < chars.length; i++)
	    page.printlnAhref("#" + i, SELF_FRAME, HTMLPrinter.encode(chars[i]));
	page.printlnHLine();
	for (int i  = 0; i < chars.length; i++) {
	    Character car = chars[i];
	    page.printlnAname(String.valueOf(i), "");
	    page.printlnOTag("h2");
            page.printBold(HTMLPrinter.encode(car));
            page.printlnCTag("h2");
	    page.printlnOTag("dl").indent();
	    Symbol[] syms = (Symbol[]) map.get(car);
	    for (int j  = 0; j < syms.length; j++) {
		page.printOTag("dt");
                addIndexEntry(syms[j]);
                page.printlnCTag("dt");
		page.printlnTag("dd", firstSentence(getComment(syms[j])));
	    }
            page.undent().printlnCTag("dl");
	}

        page.printlnHLine();
        addNavigationBar(INDEX_NAV_CONTEXT);
        if (validate)
            addValidationBar();

	page.printFootpage();
        closePrinters();
    }

    /**
     * Creates the help page.
     *
     * @param title The page title
     */
    protected void createHelpPage() {
	String title = "API Help";
	createPrinters(Location.makeURI(HELP_PAGE), title, ROOT_PAGE);
        page.printHeader(ATTRS_META, getGenerator());
	page.printOpenBody();

        addNavigationBar(HELP_NAV_CONTEXT);
        page.printlnHLine();

        XMLAttribute[] h3 = new XMLAttribute[]{
            new XMLAttribute("style", "margin:15px 0px 0px 0px; "
                + "font-size:large; font-weight: bold;")
        };
        XMLAttribute[] em = new XMLAttribute[]{
            new XMLAttribute("style", "margin:15px 0px 15px 0px; "
                + "font-size:small; font-style: italic;")
        };
        page.printlnTag("div", ATTRS_PAGE_TITLE, "How This API Document Is Organized");
        page.println("This API (Application Programming Interface) document "
            + "has pages corresponding to the items in the navigation bar, "
            + "described as follows.");

        page.printlnTag("div", h3, "Overview");
        page.printlnOTag("blockquote").indent();
        page.print("The ");
        page.printAhref(ROOT_PAGE, SELF_FRAME, "Overview");
        page.println(" page is the front page of this API document and "
	    + "provides a list of all top-level packages, classes, traits "
	    + "and objects with a summary for each. "
            + "This page can also contain an overall description of the "
            + "set of packages.").undent();
        page.printlnCTag("blockquote");

        page.printlnTag("div", h3, "Package");
        page.printlnOTag("blockquote").indent();
        page.println("Each package has a page that contains a list of "
            + "its objects, traits and classes, with a summary for each. "
            + "This page can contain three categories:");
        page.printlnOTag("ul").indent();
        page.printlnTag("li", "Objects");
        page.printlnTag("li", "Traits");
        page.printlnTag("li", "Classes").undent();
        page.printlnCTag("ul").undent();
        page.printlnCTag("blockquote");

        page.printlnTag("div", h3, "Object/Trait/Class");
        page.printlnOTag("blockquote").indent();
        page.println("Each object, trait, class, nested object, nested "
            + "trait and nested class has its own separate page. Each "
            + "of these pages has three sections consisting of a object"
            + "/trait/class description, summary tables, and detailed "
            + "member descriptions:");
        page.printlnOTag("ul").indent();
        page.printlnTag("li", "Class inheritance diagram");
        page.printlnTag("li", "Direct Subclasses");
        page.printlnTag("li", "All Known Subinterfaces");
        page.printlnTag("li", "All Known Implementing Classes");
        page.printlnTag("li", "Class/interface declaration");
        page.printlnTag("li", "Class/interface description<p/>");
        page.printlnTag("li", "Nested Class Summary");
        page.printlnTag("li", "Field Summary");
        page.printlnTag("li", "Constructor Summary");
        page.printlnTag("li", "Method Summary<p/>");
        page.printlnTag("li", "Field Detail");
        page.printlnTag("li", "Constructor Detail");
        page.printlnTag("li", "Method Detail").undent();
        page.printlnCTag("ul").undent();
        page.println("Each summary entry contains the first sentence from "
            + "the detailed description for that item. The summary entries "
            + "are alphabetical, while the detailed descriptions are in "
            + "the order they appear in the source code. This preserves "
            + "the logical groupings established by the programmer.");
        page.printlnCTag("blockquote");


        page.printlnTag("div", h3, "Index");
        page.printlnOTag("blockquote").indent();
        page.print("The ");
        page.printAhref(INDEX_PAGE, SELF_FRAME, "Index");
        page.print(" contains an alphabetic list of all classes, interfaces, "
            + "constructors, methods, and fields.");
        page.printlnCTag("blockquote");

        if (launchServer) {
            page.printlnTag("div", h3, "Searching a definition");
            page.printlnOTag("blockquote").indent();
            page.printlnSTag("a",
                             new XMLAttribute[] {
                                 new XMLAttribute("name", SEARCH_SECTION) });
            page.printlnOTag("p");
            page.println("At the top and and at the bottom of each page, there is a form that "
                         + "allows to search the definition of a <em>symbol</em> (field, method, "
                         + "package, object, type, trait or class).");
            page.printlnCTag("p");

            page.printlnOTag("p");
            page.println("There are three ways of specifying the symbols of interest:");
            page.printlnOTag("dl");
            page.printOTag("dt");
            page.printlnTag("b", "By name");
            page.printOTag("dd");
            page.println("The search string must be a ");
            page.printlnTag("a",
                           new XMLAttribute[] {
                               new XMLAttribute("href",
                                                "http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html") },
                           "regular expression");
            page.print(" that has to match a substring in the name of the searched symbol.");
            page.printOTag("dt");
            page.printlnTag("b", "By comment");
            page.printOTag("dd");
            page.println("The search string must be a ");
            page.printlnTag("a",
                           new XMLAttribute[] {
                               new XMLAttribute("href",
                                                "http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html") },
                           "regular expression");
            page.print(" that has to match a substring in the comments associated to the searched symbol.");
            page.printOTag("dt");
            page.printlnTag("b", "By type");
            page.printOTag("dd");
            page.println("The search string must represent a Scala type. Any string ");
            page.printlnTag("code", "S");
            page.println(" such that ");
            page.printlnTag("pre", "def foo S;");
            page.println(" is a valid function definition is accepted. Here are some examples:");
            page.printlnOTag("ul");
            page.printOTag("li");
            page.printlnTag("code", ": int => int");
            page.printOTag("li");
            page.printlnTag("code", "[a,b]: List[a] => (a => b) => List[b]");
            page.printOTag("li");
            page.printlnTag("code", "(x: int, y: int): unit");
            page.printlnCTag("ul");
            page.println("The searched symbols must conform to the entered type modulo ");
            page.printlnTag("a",
                           new XMLAttribute[] {
                               new XMLAttribute("href",
                                                "http://www.pps.jussieu.fr/~dicosmo/Publications/ISObook.html") },
                           "type isomorphism");
            page.println(". This concept allows to unify types that differ by their exact "
                         + "representation but not by their meaning.  The order of parameters is "
                         + "for instance irrelevant when looking for a function. Note finally that "
                         + "methods of classes are interpreted as functions that would take an "
                         + "extra argument of the type of the class.");
            page.printlnCTag("dl");
            page.printlnCTag("p");
            page.printlnCTag("blockquote");
        }

        page.printlnOTag("div", em);
        page.println("This help file applies to API documentation generated "
            + "using the standard doclet.");
        page.printlnCTag("div");

        page.printlnHLine();
        addNavigationBar(HELP_NAV_CONTEXT);
        if (validate)
            addValidationBar();

	page.printFootpage();
        closePrinters();
    }

    /**
     * Adds to the current page an hyperlinked path leading to a given
     * symbol (including itself).
     */
    protected void printPath(Symbol sym, String destinationFrame, Page page) {
	sym = sym.isModuleClass() ? sym.module() : sym;
	String name = removeHtmlSuffix(Location.getURI(sym).toString());
	if (isDocumented.apply(sym)) {
	    String target = definitionURL(sym, page);
	    page.printlnAhref(target, destinationFrame, name);
	}
	else
	    page.println(name);
    }

    protected void printPath(Symbol sym, String destinationFrame) {
        printPath(sym, destinationFrame, page);
    }

    /**
     * Writes the string representation of a symbol entry in the index.
     *
     * @param symbol
     */
    protected void addIndexEntry(Symbol symbol, Page page, MySymbolTablePrinter symtab) {
	// kind
	String keyword = symtab.getSymbolKeywordForDoc(symbol);

        if (keyword != null) page.print(keyword).space();
	// name
	symtab.printDefinedSymbolName(symbol, true);
	// owner
	if (!symbol.isRoot()) {
	    page.print(" in ");
	    printPath(symbol.owner(), SELF_FRAME, page);
	}
    }

    protected void addIndexEntry(Symbol symbol) {
        addIndexEntry(symbol, page, symtab);
    }

    /**
     * Writes documentation comments to the current page.
     *
     * @param comment
     */
    protected void addComments(Comment comment) {
	if (!comment.isEmpty()) {
	    page.printlnOTag("dl").indent();
	    // text with inlined links
	    page.printlnTag("dd", inlineLinkTags(comment.holder, comment.text));
	    page.undent().printlnCTag("dl");

	    // tags
	    addTags(comment.tags);
	}
    }

    /** Inline all the {@link ...} tags inside the text.
     */
    protected String inlineLinkTags(Symbol holder, String text) {
	StringBuffer buff = new StringBuffer();
	Tag[] tags = Comment.makeTags(holder, text);
	for (int i = 0; i < tags.length; i++) {
	    if (tags[i].isText())
		buff.append(tags[i].text);
	    else if (tags[i].isReference())
		buff.append(inlineRefTag(tags[i]));
	}
	return buff.toString();
    }

    /**
     * Returns the first sentence of a documentation comment where all
     * links {@link ...} have been inlined.
     *
     * @param comment
     */
    protected String firstSentence(Comment comment) {
	return
	    inlineLinkTags(comment.holder, comment.firstSentence());
    }

    // TODO: remove this !
    private static String ahref(String dest, String target, String text) {
	return "<a href=\"" + dest + "\" target=\"" + target + "\">" +
	    text + "/a>";
    }

    /** Inline a @see documentation tag.
     */
    protected String inlineRefTag(Tag tag) {
	switch(Tag.parseReference(tag)) {
	case Bad(String ref):
	    return ref;
	case Url(String ref):
	    return ref;
	case Literal(String ref):
	    return ref;
	case Scala(String container, String member, String label):
	    Symbol sym = findSymbolFromString(tag.holder, container, member);
	    if (sym == Symbol.NONE) {
		System.err.println("Warning: not found " + tag);
		return tag.text;
	    }
	    else if (!isDocumented.apply(sym)) {
		System.err.println("Warning: not referenced " + tag);
		return tag.text;
	    }
	    else {
		String labl = label.equals("") ? sym.nameString() : label;
		return ahref(definitionURL(sym), ROOT_FRAME, labl);
	    }
	default:
	    throw Debug.abort("illegal case", tag);
	}
    }

    /**
     * Writes a set of Scaladoc tags to a page.
     *
     * @param tags
     */
    protected void addTags(Tag[] tags) {
	if (tags.length > 0) {
	    Tag returnTag = null;
	    Tag sinceTag = null;
	    Tag versionTag = null;
	    final List paramTagList = new LinkedList();;
	    final List seeTagList = new LinkedList();
	    final List throwsTagList = new LinkedList();
	    final List authorTagList = new LinkedList();
	    final List otherTagList = new LinkedList();

	    // partitioning the tags
	    for (int i = 0; i < tags.length; i++) {
		if ("@return".equals(tags[i].name))
		    returnTag = tags[i];
		else if ("@since".equals(tags[i].name))
		    sinceTag = tags[i];
		else if ("@version".equals(tags[i].name))
		    versionTag = tags[i];
		else if ("@param".equals(tags[i].name))
		    paramTagList.add(tags[i]);
		else if ("@see".equals(tags[i].name))
		    seeTagList.add(tags[i]);
		else if (tags[i].isException())
		    throwsTagList.add(tags[i]);
		else if ("@author".equals(tags[i].name))
		    authorTagList.add(tags[i]);
		else
		    otherTagList.add(tags[i]);
	    }

	    page.printlnOTag("dl");

	    // Author.
	    if (authorTagList.size() > 0) {
		addTagSection("Author");
		page.printlnOTag("dd").indent();
		Iterator it = authorTagList.iterator();
		Tag authorTag = (Tag) it.next();
		page.print(authorTag.text);
		while (it.hasNext()) {
		    authorTag = (Tag) it.next();
		    page.print(", " + authorTag.text);
		}
                page.println().undent();
		page.printlnCTag("dd");
	    }
	    // Since.
	    if (sinceTag != null) {
		addTagSection("Since");
		page.printlnTag("dd", sinceTag.text);
	    }
	    // Version.
	    if (versionTag != null) {
		addTagSection("Version");
		page.printlnTag("dd", versionTag.text);
	    }
	    // Parameters.
	    if (paramTagList.size() > 0) {
		addTagSection("Parameters");
		Iterator it = paramTagList.iterator();
		Tag paramTag = null;
		while (it.hasNext()) {
		    paramTag = (Tag) it.next();
		    Pair fields = Tag.split(paramTag.text);
		    String paramName = (String) fields.fst;
		    String paramDesc = (String) fields.snd;
		    page.printOTag("dd");
		    page.printTag("code", paramName);
                    page.println(" - ");
		    page.println(inlineLinkTags(paramTag.holder, paramDesc));
		    page.printlnCTag("dd");
		}
	    }
	    // Returns.
	    if (returnTag != null) {
		addTagSection("Returns");
		page.printlnTag("dd", returnTag.text);
	    }
	    // Throws.
	    if (throwsTagList.size() > 0) {
		addTagSection("Throws");
		Iterator it = throwsTagList.iterator();
		Tag throwsTag = null;
		while (it.hasNext()) {
		    throwsTag = (Tag) it.next();
		    Pair fields = Tag.split(throwsTag.text);
		    String exceptionName = (String) fields.fst;
		    String exceptionDesc = (String) fields.snd;
		    page.printOTag("dd");
		    page.printTag("code", exceptionName);
                    page.println(" - "); // TODO: hypertext link
		    page.println(inlineLinkTags(throwsTag.holder, exceptionDesc));
		    page.printlnCTag("dd");
		}
	    }
	    // See Also.
	    if (seeTagList.size() > 0) {
		addTagSection("See Also");
		page.printlnOTag("dd");
		Iterator it = seeTagList.iterator();
		Tag seetag = (Tag) it.next();
		page.println(inlineRefTag(seetag));
		while (it.hasNext()) {
		    seetag = (Tag) it.next();
		    page.print(", ");
		    page.println(inlineRefTag(seetag));
		}
		page.printlnCTag("dd");
	    }
	    // Others.
	    if (otherTagList.size() > 0) {
		Iterator it = otherTagList.iterator();
		while (it.hasNext())
		    addStandardTag((Tag) it.next());
	    }

	    page.printlnCTag("dl");
	}
    }

    /**
     * Returns the HTML representation of a documentation tag.
     *
     * @param tagName
     */
    protected void addTagSection(String tagName) {
	page.printOTag("dt", ATTRS_DOCTAG);
        page.printBold(tagName + ":");
        page.printlnCTag("dt");
    }

    /**
     * Returns the HTML representation of a standard documentation tag.
     *
     * @param tag
     */
    protected void addStandardTag(Tag tag) {
	String sectionName = "";
	if (tag.name.length() > 1) {
	    sectionName += Character.toUpperCase(tag.name.charAt(1));
	    if (tag.name.length() > 2)
		sectionName += tag.name.substring(2);
	}
	addTagSection(sectionName);
	page.printTag("dd", inlineLinkTags(tag.holder, tag.text));
    }

    /**
     * Returns the symbol contained in a specified class or object and
     * described by its label or its name. Return Symbol.NONE if not
     * found.
     *
     * @param context
     * @param classOrObject
     * @param label
     */
    protected Symbol findSymbolFromString(Symbol context, String classOrObject, String label) {
	/*
	String path;
	// absolute path
	if (classOrObject.startsWith(new Character(ScalaSearch.classChar).toString()) ||
	    classOrObject.startsWith(new Character(ScalaSearch.objectChar).toString()))
	    path = classOrObject;
	else // relative path
	    path = ScalaSearch.getOwnersString(context.owner()) + classOrObject;
	path = path.substring(1);
	Symbol sym = ScalaSearch.lookup(global.definitions.ROOT_CLASS, path);
	if (sym == Symbol.NONE)
	    return Symbol.NONE;
	else {
	    if (label == null)
		return sym;
	    else {
		// look for a member in the scope that has a tag
		// @label with the given label
		Scope scope = sym.moduleClass().members();
		SymbolIterator it  = scope.iterator(true);
		while (it.hasNext()) {
		    Symbol member = (Symbol) it.next();
		    Tag[] tags = getComment(member).tags;
		    for (int i = 0; i < tags.length; i++)
			if ("@label".equals(tags[i].name) &&
			    label.equals(tags[i].text))
			    return member;
		}
		// look for the first term with label as name
		return sym.moduleClass().lookup(Name.fromString(label).toTermName());
	    }
	}
	*/
	return Symbol.NONE;
    }

    protected void addCategory(Symbol[] symbols, String title, Page page, MySymbolTablePrinter symtab) {
        if (symbols.length > 0) {
            page.printlnTag("h3", title);
            page.printlnOTag("dl").indent();
            for(int i = 0; i < symbols.length; i++) {
                page.printOTag("dt");
                addIndexEntry(symbols[i], page, symtab);
                page.printlnCTag("dt");
                page.printlnTag("dd", firstSentence(getComment(symbols[i])));
            }
            page.undent().printlnCTag("dl");
        }
    }

    protected void addFoundSymbols(List symbols, Page page, MySymbolTablePrinter symtab) {
        // partition and sort
        List fields = new LinkedList();
        List modules = new LinkedList();
        List types = new LinkedList();
        ScalaSearch.categorizeSymbols(symbols, fields, modules, types);
        Symbol[] sortedFields = ScalaSearch.sortList(fields);
        Symbol[] sortedModules = ScalaSearch.sortList(modules);
        Symbol[] sortedTypes = ScalaSearch.sortList(types);

        addCategory(sortedFields, "val/def", page, symtab);
        addCategory(sortedModules, "package/object", page, symtab);
        addCategory(sortedTypes, "type/trait/class", page, symtab);
    }

    protected void addResultNumber(int number, Page page) {
        page.printOTag("p");
        page.printOTag("b");
        page.print("" + number + " result(s).");
        page.printCTag("b");
        page.printCTag("p");
    }

    public static String SERVLET_NAME = "scaladocServlet";

    public class ScaladocServlet extends Servlet {

        public String name() {
            return SERVLET_NAME;
        }

        public void apply(Map req, Writer out) {
            // create page
            String pagename = "search-page";
            URI uri = Location.makeURI(pagename + ".html");
            String destinationFrame = SELF_FRAME;
            String title = pagename;

            final Page page = new Page(out, uri, destinationFrame,
                                 title, representation,
                                 stylesheet/*, script*/);
            page.open();
            page.printHeader(ATTRS_META, getGenerator());
            page.printOpenBody();
            addNavigationBar(CONTAINER_NAV_CONTEXT, page);
            page.printlnHLine();

            // create symbol printer
            final MySymbolTablePrinter symtab =
                SymbolTablePrinterFactory.makeHTML(page, isDocumented);

            // analyze the request
            String searchKind = (String) req.get("searchKind");
            String searchString = (String) req.get("searchString");

            // search summary
            String searchKindSummary = null;
            if (searchKind.equals("byName"))
                searchKindSummary = "in defined names";
            else if (searchKind.equals("byComment"))
                searchKindSummary = "in comments";
            else if (searchKind.equals("byType"))
                searchKindSummary = "by type";
            String searchSummary =
                "Scaladoc searched for the string (" + searchString + ") " + searchKindSummary + ".";
            page.printOTag("p");
            page.printOTag("b");
            page.print(searchSummary);
            page.printCTag("b");
            page.printCTag("p");

            // Search by name.
            if (searchKind.equals("byName")) {
                String regexp = searchString;
                final Pattern p = Pattern.compile(regexp);

                final List found = new LinkedList();
                //collect
                ScalaSearch.foreach(global.definitions.ROOT_CLASS,
                                    new ScalaSearch.SymFun() {
                                        public void apply(Symbol sym) {
                                            String name = sym.nameString();
                                            Matcher m = p.matcher(name);
                                            if (m.find())
                                                found.add(sym);
                                        }
                                    },
                                    isDocumented);
                addResultNumber(found.size(), page);
                addFoundSymbols(found, page, symtab);
            }
            // Search by comment.
            else if (searchKind.equals("byComment")) {
                String regexp = searchString;
                final Pattern p = Pattern.compile(regexp);

                final List found = new LinkedList();
                ScalaSearch.foreach(global.definitions.ROOT_CLASS,
                                    new ScalaSearch.SymFun() {
                                        public void apply(Symbol sym) {
                                            Pair c = (Pair) global.mapSymbolComment.get(sym);
                                            if (c != null) {
                                                String comment = (String) c.fst;
                                                Matcher m = p.matcher(comment);
                                                if (m.find())
                                                    found.add(sym);
                                            }
                                        }
                                    },
                                    isDocumented);
                addResultNumber(found.size(), page);
                addFoundSymbols(found, page, symtab);
            }
            // Search by type.
            else if (searchKind.equals("byType")) {
                Type t = ScalaSearch.typeOfString(searchString, global);
                TypeIsomorphism ml = newTypeIso(global);

                List found = new LinkedList();
                Map searchResults = new HashMap();
                Iterator it = ml.searchType(t, isDocumented);
                while (it.hasNext()) {
                    SearchResult result = (SearchResult) it.next();
                    found.add(result.symbol);
                    searchResults.put(result.symbol, result);
                }
                if (t == Type.NoType) {
                    page.printOTag("p");
                    page.println("Scaladoc could not recognize your search string as a type, "
                                 + "see the ");
                    page.printlnTag("a",
                                    new XMLAttribute[] {
                                        new XMLAttribute("href", HELP_PAGE + "#" + SEARCH_SECTION) },
                                    "help page");
                    page.println(" to know which syntax to use.");
                    page.printCTag("p");
                }
                else {
                    page.printOTag("p");
                    page.print("You are searching for symbols with type: ");
                    page.print(t.toString());
                    page.printCTag("p");

                    addResultNumber(found.size(), page);

                    Symbol[] sortedSymbols = ScalaSearch.sortList(found);

                    for(int i = 0; i < sortedSymbols.length; i++) {
                        Symbol sym = sortedSymbols[i];
                        SearchResult result = (SearchResult) searchResults.get(sym);
                        Type adaptedType = result.getType;
                        page.printOTag("dt");
                        //page.printOTag("code");
                        symtab.printShortSignature(sym, true);
                        symtab.printSeqType(sym, adaptedType, symtab.getSymbolInnerString(sym));
                        page.printlnCTag("dt");
                        if (!sym.isRoot()) {
                            page.printOTag("dd");
                            page.print("in ");
                            printPath(sym.owner(), SELF_FRAME, page);
                            if (result.isInClass && (result.tparams.length > 0)) {
                                page.print("[");
                                for(int j = 0; j < result.tparams.length; j++) {
                                    if (j != 0) page.print(",");
                                    page.print(result.tparams[j].nameString());
                                }
                                page.print("]");
                            }
                            page.printCTag("dd");
                        }
                        String firstSent = firstSentence(getComment(sym));
                        if (!firstSent.equals(""))
                            page.printlnTag("dd", firstSent);
                        //page.printlnCTag("code");
                    }
                }
            }
            // close page
            page.printlnHLine();
            addNavigationBar(CONTAINER_NAV_CONTEXT, page);
            page.printFootpage();
            // page.close();
            // already done by the HTTP server when closing connection
        }
    }
}

public class SearchResult {
    Symbol symbol;
    Type getType;
    boolean isInClass;
    Symbol[] tparams;
    public SearchResult(Symbol symbol,
                        Type getType,
                        boolean isInClass,
                        Symbol[] tparams) {
        this.symbol = symbol;
        this.getType = getType;
        this.isInClass = isInClass;
        this.tparams = tparams;
    }
}