Solved

Printing in IE4 and Netscape4

Posted on 1998-05-04
2
150 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 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

726 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