Solved

Printing in IE4 and Netscape4

Posted on 1998-05-04
2
144 Views
Last Modified: 2010-04-16
Netscape defines a set of classes to grant applets permissions to do specific things.  I use the PrivilegeManager.enablePrivilege method to request permissions for my signed applet.  Including these calls in my code causes IE4 to toss exceptions because it can't find the Netscape classes.  Java doesn't give me conditional complitation, and I don't want to maintain 2 sets of sources, one for each browser.

BTW, the Capablities API works fine with Netscape 4.05.

I can detect which browser my applet is running under.

Is there any way to use the Netscape classes from code that can be run without exceptions under IE4?
0
Comment
Question by:gerry99
2 Comments
 
LVL 5

Accepted Solution

by:
msmolyak earned 50 total points
ID: 1220527
There is no conditional compilation but you have dynamic object instantiation through

Class.forName("myPackage.myClass").newInstance();

Put all the logic to request a privilege in a constractor of some class and look for  InstantiationException. If you are running in Netscape, the class will be instantiated and code to request privilege executed.  If the exception gets thrown which means the class could not be instantiated (e.g it could not find Netscape's classes), then simply continue processing.

Hope that helps.
0
 
LVL 1

Author Comment

by:gerry99
ID: 1220528
This answer works, and it deserves to be called the "hack of all ages".  I'm not sure how the language specification should be changed, but as long as applets must make use of libraries that exist in some browsers, but not in others, some form of conditional compilation is required.  Notice that with this technique *all* the work must be done in a constructor, because if you wanted to call a method on this class, it would have to be loaded and verified on both platforms and would toss exceptions on the one that does not contain some of the classes that it uses.

Thanks,
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now