?
Solved

Printing in IE4 and Netscape4

Posted on 1998-05-04
2
Medium Priority
?
164 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 5

Accepted Solution

by:
msmolyak earned 150 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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

649 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