This repository was archived by the owner on Jan 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathHelpSet.java
More file actions
1917 lines (1731 loc) · 50 KB
/
HelpSet.java
File metadata and controls
1917 lines (1731 loc) · 50 KB
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
/*
* @(#)HelpSet.java 1.108 06/10/30
*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package javax.help;
import java.net.URL;
import java.net.URLConnection;
import java.net.MalformedURLException;
import java.util.*;
import java.io.*;
import java.awt.Dimension;
import java.awt.Point;
import javax.help.event.EventListenerList;
import javax.help.DefaultHelpBroker;
import javax.help.event.HelpSetListener;
import javax.help.event.HelpSetEvent;
import javax.help.Map.ID;
// implementation-specific
import com.sun.java.help.impl.Parser;
import com.sun.java.help.impl.ParserListener;
import com.sun.java.help.impl.ParserEvent;
import com.sun.java.help.impl.Tag;
import com.sun.java.help.impl.TagProperties;
import com.sun.java.help.impl.XmlReader;
import com.sun.java.help.impl.LangElement;
import javax.help.Map.ID;
import java.beans.PropertyChangeSupport;
import java.lang.reflect.Constructor;
/**
* A HelpSet is a collection of help information consisting of a HelpSet
* file, table of contents (TOC), index, topic files, and Map file.
* The HelpSet file is the portal to the HelpSet.
*
* @author Roger D. Brinkley
* @author Eduardo Pelegri-Llopart
* @author Stepan Marek
* @version 1.108 10/30/06
*/
public class HelpSet implements Serializable{
private static String errorMsg = null;
/*
* Event listeners for adding to the HelpSet
*/
protected EventListenerList listenerList = new EventListenerList();
/**
* PublicID (known to this XML processor) to the DTD for version 1.0 of the HelpSet
*/
public static final String publicIDString =
"-//Sun Microsystems Inc.//DTD JavaHelp HelpSet Version 1.0//EN";
/**
* PublicID (known to this XML processor) to the DTD for version 2.0 of the HelpSet
*/
public static final String publicIDString_V2 =
"-//Sun Microsystems Inc.//DTD JavaHelp HelpSet Version 2.0//EN";
/**
* Information for implementation customization.
*
* helpBroker/class is used to locate the class for a HelpBroker.
* helpBroker/loader is used to determine the ClassLoader to use.
*/
public static final Object implRegistry =
new StringBuffer("HelpSet.implRegistry");
public static final String helpBrokerClass = "helpBroker/class";
public static final String helpBrokerLoader = "helpBroker/loader";
/**
* HelpSet context information.
*
* A HelpSet can map between keys (String) and values (Strings).
* There is a per-HelpSet value and a default value.
* The per-HelpSet value is specified in the appropriate section of the
* HelpSet file.
* The default value is global and only specified at class initialization time.
*/
public static final Object kitTypeRegistry =
new StringBuffer("JHelpViewer.kitTypeRegistry");
public static final Object kitLoaderRegistry =
new StringBuffer("JHelpViewer.kitLoaderRegistry");
/**
* Creates an empty HelpSet that one can parse into.
* @param loader The ClassLoader to use. If loader is null, the default
* ClassLoader is used.
*/
public HelpSet(ClassLoader loader) {
this.helpsets = new Vector();
this.loader = loader;
}
/**
* Creates an empty HelpSet. Uses the default ClassLoader
*/
public HelpSet() {
this.helpsets = new Vector();
this.loader = null;
}
/**
* Creates a HelpSet. The locale for the data is either that indicated in
* the <tt>lang</tt> attribute of the <tt>helpset</tt> tag, or
* <tt>Locale.getDefault()</tt> if the <tt>lang</tt> attribute is not present.
*
* @param loader The class loader to use to locate any classes
* required by the navigators in the Helpset
* If loader is null, the default ClassLoader is used.
* @param helpset The URL to the HelpSet "file"
*
* @exception HelpSetException if there are problems parsing the helpset
*/
public HelpSet(ClassLoader loader, URL helpset) throws HelpSetException {
this(loader);
this.helpset = helpset; // so it can be used in parseInto()
HelpSetFactory factory = new DefaultHelpSetFactory();
parseInto(helpset, factory);
HelpSet x = factory.parsingEnded(this); // use the error reporting
if (x == null) {
// We had trouble parsing
// May need to revisit this...
throw new HelpSetException("Could not parse\n"+errorMsg);
}
}
/**
* Locates a HelpSet file and return its URL.
* Applies localization conventions.
*
* @param cl The classloader to use when searching for the resource
* with the appropriate name. If cl is null the default
* ClassLoader is used.
* @param shortName The shortname of the resource.
* @param extension The extension of the resource.
* @param locale The desired Locale
* @see javax.help.HelpUtilities
*/
public static URL findHelpSet(ClassLoader cl,
String shortName,
String extension,
Locale locale) {
// Test for whether URL can be opened! - workaround Browser bugs
return HelpUtilities.getLocalizedResource(cl,
shortName,
extension,
locale,
true);
}
/**
* Locates a HelpSet file and return its URL.
*
* If the name does not end with the ".hs" extension, the
* ".hs" extension is appended and localization rules
* are applied to it.
*
* @param cl The classloader to use. If cl is null the default
* ClassLoader is used.
* @param name The name of the resource.
* @param locale The desired locale.
*/
public static URL findHelpSet(ClassLoader cl,
String name,
Locale locale) {
String shortName;
String extension;
if (name.endsWith(".hs")) {
shortName = name.substring(0, name.length()-3);
extension = ".hs";
} else {
shortName = name;
extension = ".hs";
}
return findHelpSet(cl, shortName, extension, locale);
}
/**
* As above but default on locale to Locale.getDefault()
*
* @param cl The ClassLoader to use. If cl is null the default
* ClassLoader is used.
* @param name The name of the resource.
* @return Null if not found.
*/
public static URL findHelpSet(ClassLoader cl,
String name) {
return findHelpSet(cl, name, Locale.getDefault());
}
/**
* Creates a presentation object for this HelpSet.
* Consults the <tt>implRegistry</tt> of <tt>KeyData</tt> for
* the class name (as helpBrokerClass) and for the ClassLoader
* instance (as helpBrokerLoader) and then tries to instantiate
* that class. It then invokes <tt>setHelpSet()</tt> with
* this instance of HelpSet as the argument. The resulting object is
* returned.
* @see createHelpBroker(String)
*/
public HelpBroker createHelpBroker() {
return createHelpBroker(null);
}
/**
* Creates a presentation object for this HelpSet.
* Consults the <tt>implRegistry</tt> of <tt>KeyData</tt> for
* the class name (as helpBrokerClass) and for the ClassLoader
* instance (as helpBrokerLoader) and then tries to instantiate
* that class. It then invokes <tt>setHelpSet()</tt> with
* this instance of HelpSet as the argument. The resulting object is
* returned.
* @param presenationName A presentation name defined in the HelpSet
* that will dictate the presentation.
* @return HelpBroker The created HelpBroker
* @since 2.0
* @see createHelpBroker()
*/
public HelpBroker createHelpBroker(String presentationName) {
HelpBroker back = null;
String classname =
(String) getKeyData(implRegistry, helpBrokerClass);
ClassLoader loader =
(ClassLoader) getKeyData(implRegistry, helpBrokerLoader);
if (loader == null) {
loader = getLoader();
}
try {
Class c;
if (loader != null) {
c = loader.loadClass(classname);
} else {
c = Class.forName(classname);
}
back = (HelpBroker) c.newInstance();
} catch (Throwable e) {
back = null;
}
if (back != null) {
back.setHelpSet(this);
HelpSet.Presentation hsPres = null;
// If there is a presentation name find it otherwise get the
// default if one exists.
if (presentationName != null) {
hsPres = getPresentation(presentationName);
} else {
hsPres = getDefaultPresentation();
}
if (hsPres != null) {
back.setHelpSetPresentation(hsPres);
}
}
return back;
}
/**
* Adds a HelpSet, HelpSetEvents are generated.
* Adding a composed HelpSet to another is equivalent to
* adding all the HelpSets individually.
*
* @param hs The HelpSet to add.
*/
public void add(HelpSet hs) {
debug("add("+hs+")");
helpsets.addElement(hs);
fireHelpSetAdded(this, hs);
combinedMap = null; // invalidate the map
}
/**
* Removes a HelpSet from this HelpSet; HelpSetEvents are generated
* Return True if it is found, otherwise false.
*
* @param hs The HelpSet to remove.
* @return False if the hs is null or was not in this HelpSet
*/
public boolean remove(HelpSet hs) {
if (helpsets.removeElement(hs)) {
fireHelpSetRemoved(this, hs);
combinedMap = null; // HERE - invalidate it - epll
return true;
} else {
return false;
}
}
/**
* Enumerates all the HelpSets that have been added to this one.
*
* @return An enumeration of the HelpSets that have been added to
* this HelpSet.
*/
public Enumeration getHelpSets() {
return helpsets.elements();
}
/**
* Determines if a HelpSet is a sub-HelpSet of this object.
*
* @param hs The HelpSet to check
* @return true If <tt>hs</tt> is contained in this HelpSet or in one of its children.
*/
public boolean contains(HelpSet hs) {
if (hs == this) {
return true;
}
for (Enumeration e = helpsets.elements();
e.hasMoreElements();) {
HelpSet child = (HelpSet) e.nextElement();
if (child.contains(hs)) {
return true;
}
}
return false;
}
/**
* Adds a listener for the HelpSetEvent posted after the model has
* changed.
*
* @param l - The listener to add.
* @see javax.help.HelpSet#removeHelpSetListener.
* @throws IllegalArgumentException if l is null.
*/
public void addHelpSetListener(HelpSetListener l) {
debug("addHelpSetListener("+l+")");
listenerList.add(HelpSetListener.class, l);
}
/**
* Removes a listener previously added with <tt>addHelpSetListener</tt>
*
* @param l - The listener to remove.
* @see javax.help.HelpSet#addHelpSetListener.
* @throws IllegalArgumentException if l is null.
*/
public void removeHelpSetListener(HelpSetListener l) {
listenerList.remove(HelpSetListener.class, l);
}
/**
* Fires a helpSetAdded event.
*/
protected void fireHelpSetAdded(Object source, HelpSet helpset){
Object[] listeners = listenerList.getListenerList();
HelpSetEvent e = null;
for (int i = listeners.length - 2; i >= 0; i -= 2) {
if (listeners[i] == HelpSetListener.class) {
if (e == null) {
e = new HelpSetEvent(this, helpset,
HelpSetEvent.HELPSET_ADDED);
}
((HelpSetListener)listeners[i+1]).helpSetAdded(e);
}
}
}
/**
* Fires a helpSetRemoved event.
*/
protected void fireHelpSetRemoved(Object source, HelpSet helpset){
Object[] listeners = listenerList.getListenerList();
HelpSetEvent e = null;
for (int i = listeners.length - 2; i >= 0; i -= 2) {
if (listeners[i] == HelpSetListener.class) {
if (e == null) {
e = new HelpSetEvent(this, helpset,
HelpSetEvent.HELPSET_REMOVED);
}
((HelpSetListener)listeners[i+1]).helpSetRemoved(e);
}
}
}
// ======= Labels, etc =======
/**
* Gets the title of this HelpSet.
*
* @return the title
*/
public String getTitle() {
if (title == null) {
return "";
} else {
return title;
}
}
/**
* Sest the title for this HelpSet. This is a bound property.
*
* @param title The title to set.
*/
public void setTitle(String title) {
String oldTitle = this.title;
this.title = title;
changes.firePropertyChange("title", oldTitle, title);
}
/**
* Gets the locale for this HelpSet.
*
* @return The locale.
*/
public Locale getLocale() {
return locale;
}
/**
* Sets the locale for this HelpSet.
* Strictly a private routine but the read-only property is bound.
*
* @param locale The locale to set.
*/
private void setLocale(Locale l) {
Locale oldLocale = locale;
locale = l;
changes.firePropertyChange("locale", oldLocale, locale);
}
/**
* Returns
* the ID to visit when the user makes a "go home" gesture.
* This can be identified in the project file, but may also be changed
* programmatically or (possibly) via the UI.
*
* @return The ID of home. A null is returned if homeID is null
* or if an ID cannot be created for the homeID.
*/
public ID getHomeID() {
if (homeID == null) {
return null;
} else {
try {
return ID.create(homeID, this);
} catch (Exception ex) {
return null;
}
}
}
/**
* Sets the Home ID for a HelpSet. This is a bound property.
*
* @param The ID (in the Map) that identifies the default topic for this HelpSet. Null is valid homeID.
*/
public void setHomeID(String homeID) {
String oldID = homeID;
this.homeID = homeID;
changes.firePropertyChange("homeID", oldID, homeID);
}
// WARNING/HERE: In this implementation, the Map is not updated automatically
// so you need to come get a new one - epll
// Warning. This is not handling recursive aggregation
/**
* The map for this HelpSet. This map involves the closure of
* this HelpSet's children HelpSets.
*
* @return The map
*/
public Map getCombinedMap() {
if (combinedMap == null) {
combinedMap = new TryMap();
if (map != null) {
combinedMap.add(map); // the local map
}
for (Enumeration e = helpsets.elements();
e.hasMoreElements(); ) {
HelpSet hs = (HelpSet) e.nextElement();
combinedMap.add(hs.getCombinedMap());
}
}
return combinedMap;
}
/**
* Get the local (i.e.<!-- --> non-recursive) Map for this HelpSet.
* This Map does not include the Maps for its children.
*
* @return The Map object that associates ID->URL. A null map is valid.
*/
public Map getLocalMap() {
return this.map;
}
/**
* Set the Map for this HelpSet. This Map object is not recursive; for example,
* it does not include the Maps for its children.
*
* @param The Map object that associates ID->URL. A null map is a valid.
*/
public void setLocalMap(Map map) {
this.map = map;
}
/**
* The URL that is the base for this HelpSet.
*
* @return The URL that is base to this HelpSet.
*/
public URL getHelpSetURL() {
return helpset;
}
/**
* A classloader to use when locating classes.
*
* @return The ClassLoader to use when locating classes mentioned
* in this HelpSet.
*/
public ClassLoader getLoader() {
return loader;
}
/**
* NavigatorView describes the navigator views that are requested
* by this HelpSet.
*
* @return The array of NavigatorView.
*/
public NavigatorView[] getNavigatorViews() {
NavigatorView back[] = new NavigatorView[views.size()];
views.copyInto(back);
return back;
}
/**
* Gets the NavigatorView with a specific name.
*
* @param The name of the desired navigator view.
*/
public NavigatorView getNavigatorView(String name) {
debug("getNavigatorView("+name+")");
for (int i=0; i<views.size(); i++) {
NavigatorView view = (NavigatorView) views.elementAt(i);
if (view.getName().equals(name)) {
debug(" = "+view);
return view;
}
}
debug(" = null");
return null;
}
/**
* HelpSet.Presentation describes the presentations that are defined
* by this HelpSet.
*
* @return The array of HelpSet.Presentations.
*/
public HelpSet.Presentation [] getPresentations() {
HelpSet.Presentation back[] = new HelpSet.Presentation[presentations.size()];
presentations.copyInto(back);
return back;
}
/**
* Gets the HelpSet.Presentation with a specific name.
*
* @param The name of the desired HelpSet.Presentation.
*/
public HelpSet.Presentation getPresentation(String name) {
debug("getPresentation("+name+")");
for (int i=0; i<presentations.size(); i++) {
HelpSet.Presentation pres = (HelpSet.Presentation) presentations.elementAt(i);
if (pres.getName().equals(name)) {
debug(" = "+pres);
return pres;
}
}
debug(" = null");
return null;
}
public HelpSet.Presentation getDefaultPresentation() {
return defaultPresentation;
}
/**
* Prints Name for this HelpSet.
*/
public String toString() {
return getTitle();
}
// ===== Public interfaces to parsing
/**
* Parsed a HelpSet file.
*/
public static HelpSet parse(URL url,
ClassLoader loader,
HelpSetFactory factory) {
HelpSet hs = new HelpSet(loader); // an empty HelpSet
hs.helpset = url;
hs.parseInto(url, factory);
return factory.parsingEnded(hs);
}
/**
* Parses into this HelpSet.
*/
public void parseInto(URL url,
HelpSetFactory factory) {
Reader src;
try {
URLConnection uc = url.openConnection();
src = XmlReader.createReader(uc);
factory.parsingStarted(url);
(new HelpSetParser(factory)).parseInto(src, this);
src.close();
} catch (Exception ex) {
factory.reportMessage("Got an IOException ("+
ex.getMessage()+
")", false);
if(debug)
ex.printStackTrace();
}
// Now add any subhelpsets
for (int i=0; i<subHelpSets.size(); i++) {
HelpSet subHS = (HelpSet) subHelpSets.elementAt(i);
add(subHS);
}
}
/**
* The default HelpSetFactory that processes HelpSets.
*/
public static class DefaultHelpSetFactory implements HelpSetFactory {
private Vector messages = new Vector();
private URL source;
private boolean validParse = true;
/**
* Parsing starts.
*/
public void parsingStarted(URL source) {
if (source == null) {
throw new NullPointerException("source");
}
this.source = source;
}
/**
* Process a DOCTYPE
* @param publicID the document. If null or is not valid a parsingError
* will be generated.
*/
public void processDOCTYPE(String root,
String publicID,
String systemID) {
if (publicID == null ||
(publicID.compareTo(publicIDString) != 0 &&
publicID.compareTo(publicIDString_V2) != 0)) {
parsingError("helpset.wrongPublicID", publicID);
}
}
/**
* Processes a PI
*/
public void processPI(HelpSet hs,
String target,
String data) {
// ignore for now
}
/**
* A title is found
*/
public void processTitle(HelpSet hs,
String value) {
String title = hs.getTitle();
if ((title != null) && !title.equals("")) {
parsingWarning("helpset.wrongTitle", value, title);
}
hs.setTitle(value);
}
/**
* A HomeID is found.
*/
public void processHomeID(HelpSet hs,
String value) {
ID homeID = hs.getHomeID();
if ((homeID == null) || homeID.equals("")) {
//parsingError("helpset.wrongHomeID", value, homeID.id);
hs.setHomeID(value);
}else{
parsingError("helpset.wrongHomeID", value, homeID.id);
}
}
/**
* process a <mapref>
*
* @param Spec to the URL
* @param Attributes for the tag
*/
public void processMapRef(HelpSet hs,
Hashtable attributes) {
String spec = (String) attributes.get("location");
URL hsURL = hs.getHelpSetURL();
try {
Map map = new FlatMap(new URL(hsURL, spec), hs);
Map omap = hs.getLocalMap();
if (omap == null) {
debug("map is null");
hs.setLocalMap(map);
} else {
// to implement multiple Maps add this code:
//
if (omap instanceof TryMap) {
debug("map is TryMap");
((TryMap)omap).add(map);
///
///what about hs.setLocalMap////
///
hs.setLocalMap(omap);
} else {
debug("map is not TryMap");
TryMap tmap = new TryMap();
tmap.add(omap);
tmap.add(map);
hs.setLocalMap(tmap);
}
}
} catch (MalformedURLException ee) {
parsingError("helpset.malformedURL", spec);
} catch (IOException ee) {
parsingError("helpset.incorrectURL", spec);
} catch (Exception ex) {
// parsing error...
}
}
/*
* Called per <view>
*/
public void processView(HelpSet hs,
String name,
String label,
String type,
Hashtable viewAttributes,
String data,
Hashtable dataAttributes,
Locale locale) {
try {
NavigatorView view;
if (data != null) {
if (dataAttributes == null) {
dataAttributes = new Hashtable();
}
dataAttributes.put("data", data);
}
view = NavigatorView.create(hs,
name, label,
locale,
type,
dataAttributes);
if (view == null) {
// ignore ??
} else {
hs.addView(view);
}
} catch (Exception ex) {
// ignore this view...
}
}
/*
* Called per <presentation>
*/
public void processPresentation(HelpSet hs,
String name,
boolean defaultPresentation,
boolean displayViews,
boolean displayViewImages,
Dimension size,
Point location,
String title,
String imageID,
boolean toolbar,
Vector helpActions) {
Map.ID imageMapID = null;
try {
imageMapID = ID.create(imageID, hs);
} catch (BadIDException bex2) {
}
try {
HelpSet.Presentation presentation =
new HelpSet.Presentation(name, displayViews,
displayViewImages, size,
location, title, imageMapID,
toolbar, helpActions);
if (presentation == null) {
// ignore ??
} else {
hs.addPresentation(presentation, defaultPresentation);
}
} catch (Exception ex) {
// ignore this presentation...
}
}
/**
* Called when a sub-HelpSet is found.
*/
public void processSubHelpSet(HelpSet hs,
Hashtable attributes) {
debug("createSubHelpSet");
String spec = (String) attributes.get("location");
URL base = hs.getHelpSetURL();
debug(" location: "+spec);
debug(" base helpset: "+base);
URL u = null;
HelpSet subHS = null;
try {
u = new URL(base, spec);
// test and see if the file is there
// if it doesnt' through an exception all is ok
InputStream is = u.openStream();
if (is != null) {
subHS = new HelpSet(hs.getLoader(), u);
if (subHS != null) {
hs.addSubHelpSet(subHS);
}
}
} catch (MalformedURLException ex) {
// ignore a malformed URL
// The subhelpset is just ignored
} catch (IOException ex) {
// ignore an IOException
// The subhelpset is just ignored
} catch (HelpSetException ex) {
parsingError("helpset.subHelpSetTrouble", spec);
}
}
/**
* Reports an error message.
*/
public void reportMessage(String msg, boolean validParse) {
messages.addElement(msg);
this.validParse = this.validParse && validParse;
}
/**
* Enumerates all the error messages.
*/
public Enumeration listMessages() {
return messages.elements();
}
/**
* Parsing has ended. Last chance to do something
* to the HelpSet.
* @param hs The HelpSet the parsing ended on. A null hs is valid.
*/
public HelpSet parsingEnded(HelpSet hs) {
HelpSet back = hs;
if (! validParse) {
// A parse with problems...
back = null;
String errMsg = "Parsing failed for "+source;
//System.err.println(errMsg);
messages.addElement(errMsg);
for (Enumeration e = messages.elements();
e.hasMoreElements();) {
String msg = (String) e.nextElement();
if(debug)
System.err.println(msg);
if(HelpSet.errorMsg == null)
HelpSet.errorMsg = msg;
else{
HelpSet.errorMsg = HelpSet.errorMsg+"\n";
HelpSet.errorMsg = HelpSet.errorMsg + msg;
}
}
}
return back;
}
// Convenience methods
private void parsingError(String key) {
String s = HelpUtilities.getText(key);
reportMessage(s, false); // tree will be wrong
}
/**
* @throws Error if key is invalid.
*/
private void parsingError(String key, String s) {
String msg = HelpUtilities.getText(key, s);
reportMessage(msg, false); // tree will be wrong
}
/**
* @throws Error if key is invalid.
*/
private void parsingError(String key, String s1, String s2) {
String msg = HelpUtilities.getText(key, s1, s2);
reportMessage(msg, false); // tree will be wrong
}
private void parsingWarning(String key, String s1, String s2) {
String msg = HelpUtilities.getText(key, s1, s2);
reportMessage(msg, true); // warning only
}
} // End of DefaultHelpSetFactory
/**
* HelpSet Presentation class. Contains information concerning a
* presentation in a HelpSet file
* @since 2.0
*/
public static class Presentation {
private String name;
private boolean displayViews;
private boolean displayViewImages;
private Dimension size;
private Point location;
private String title;
private boolean toolbar;
private Vector helpActions;
private Map.ID imageID;
public Presentation (String name,
boolean displayViews,
boolean displayViewImages,
Dimension size,
Point location,
String title,