jerntat
asked on
Intercepting Java application output
I'm just wondering if ther is anyway of writing a software that will be able to java .class file and then intercepting all its output for manipulation and display the manipulated output on the screen in replace of the original ones.
for example if I compile a source file that have one of the line :
System.out.println("Testin g");
and compile it as abc.class
if i run the abc.class, is there anyway of developing a program that can intercept the output and manipulate it from "Testing" to "TESTING" before displaying on the screen?
so that on the screen displayed:
TESTING
instead of the original "Testing"
for example if I compile a source file that have one of the line :
System.out.println("Testin
and compile it as abc.class
if i run the abc.class, is there anyway of developing a program that can intercept the output and manipulate it from "Testing" to "TESTING" before displaying on the screen?
so that on the screen displayed:
TESTING
instead of the original "Testing"
Certainly, you just need an app that reads from stdout.
Just need to pipe output to your other app:
java abc | myapp
java abc | myapp
ASKER
what if I'm using some GUI components, such as
Label = new JLanel("Testing");
text = new JTextField("Testing 2", 20);
button = new JButton("Testing 3");
and I want the look and feel of the GUI to be the same but changing only the text being displayed.
Label = new JLanel("Testing");
text = new JTextField("Testing 2", 20);
button = new JButton("Testing 3");
and I want the look and feel of the GUI to be the same but changing only the text being displayed.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
In fact, as far as I know, there is a project using BCEL to implement aspects... :-)
> and I want the look and feel of the GUI to be the same
> but changing only the text being displayed.
Thats an entirely different issue than the question (I thought) you asked.
DO you want to modify your class file, or manipulate stdout coming from your app?
> but changing only the text being displayed.
Thats an entirely different issue than the question (I thought) you asked.
DO you want to modify your class file, or manipulate stdout coming from your app?
ASKER
My main problem is that I have a application class file that would generate some sort of GUI and provide certain function and I wanted to change the text into another language in the GUI components but let the function of the application to remain the same.
I thought if there is a way to manipulate the stdout like System.out.println, I could also use the same method to manipulate the text used on GUI components
I thought if there is a way to manipulate the stdout like System.out.println, I could also use the same method to manipulate the text used on GUI components
Different things really.
Easiest way would be to go thru the code replacing strings preferably with getProperty() calls so you can modify the text via property files.
Have a read up on i18n which is basically what you're trying to do. In fact I think Sun has a tool for going thru code looking for strings which may be exactly what you're after.
Good luck :)
Easiest way would be to go thru the code replacing strings preferably with getProperty() calls so you can modify the text via property files.
Have a read up on i18n which is basically what you're trying to do. In fact I think Sun has a tool for going thru code looking for strings which may be exactly what you're after.
Good luck :)
Use ResourceBundle.
Read the javadoc about java.util.ResourceBundle. This class is exactly for this type of thing you need.
ASKER
but i dont have the source file...
Legal issues aside, you could simply decompile it.
You have the documentation in the docs subdirectory, if you installed the api docs, and the source code is in src.jar. But this is a different question.
ASKER
I try not to decompile, doesnt seems right to me. Working on the bytecode seems to be a bit better alternative :)
technically still the same i suppose....
technically still the same i suppose....
ASKER
i mean i dont have the source code to the application class file whoose output i wanted to alter.
Why? Using ResourceBundle is the standard way of implementing multi-language applications. I wouldn't use BCEL or AspectJ to implement multi-language.
Ah, I understand, you have an other application and you need to replace its strings...
> I try not to decompile...
Good to hear.
> technically still the same i suppose....
Certainly is :)
Good to hear.
> technically still the same i suppose....
Certainly is :)
You could use Mocha, a Java decompiler, replace the strings by hand and recompile your class again:
http://www.brouhaha.com/~eric/computers/mocha.html
There are other decompilers, too. Go to a good search machine and give "Java" and "Decompiler" as keywords.
If you need to change the strings during runtime, the best bet is to learn BCEL and use it.
http://www.brouhaha.com/~eric/computers/mocha.html
There are other decompilers, too. Go to a good search machine and give "Java" and "Decompiler" as keywords.
If you need to change the strings during runtime, the best bet is to learn BCEL and use it.
ASKER
i mean i dont have the source code to the application class file whoose output i wanted to alter.
I am sorry, I just discovered that I duplicated a post from objects, but this thread went a little too fast... (advice about decompiling the class)
ASKER
is ther any other way?...for example going really low level, by intercepting the windows messages and changing the text on the fly or probably build my own bytecode interpter so as to leave the application class alone.
ASKER
is ther any other way?...for example going really low level, by intercepting the windows messages and changing the text on the fly or probably build my own bytecode interpter so as to leave the application class alone.
> for example going really low level...
Re-engineering the entire app sounds easier :-)
Re-engineering the entire app sounds easier :-)
Have you considered asking the original author permission to i18n the code?
> I am sorry, I just discovered that I duplicated a post from objects
No worries, it happens.
No worries, it happens.
Maybe AspectJ does some of the work (own bytecode interpreter) to implement the aspects. Your aspect is "putting strings to Swing". This aspect can be cross-cut with the replacement of the strings.
But even with this, it would be a lot easier to get the permission to internationalize the application, as objects suggested.
But even with this, it would be a lot easier to get the permission to internationalize the application, as objects suggested.
ASKER
Thank You very much for all your help guys. I guess its easier to get the permission.
But I have been using a chinese viewer software that is capable of translating all the windows menubars from english to chinese, Did they do that by manipulating on the window messages or is there some window libraries that can be change to do that?
But I have been using a chinese viewer software that is capable of translating all the windows menubars from english to chinese, Did they do that by manipulating on the window messages or is there some window libraries that can be change to do that?
Don't know much about Windows, so I couldn't tell you.
Does the viewer work with any Windows application?
Does the viewer work with any Windows application?
ASKER
Thank You very much for all your help guys. I guess its easier to get the permission.
But I have been using a chinese viewer software that is capable of translating all the windows menubars from english to chinese, Did they do that by manipulating on the window messages or is there some window libraries that can be change to do that?
But I have been using a chinese viewer software that is capable of translating all the windows menubars from english to chinese, Did they do that by manipulating on the window messages or is there some window libraries that can be change to do that?
ASKER
Yes it works witn any windows application.
Windows may have a facility for that, I know that strings etc are often kept in resource files similiar to Java.
ASKER
Thanks alot guys, I should think through all the options that you guys have provided.Both of you have been a great help! :)
Thank you very much for the points. In the future, however, if you find that you want to split the points, there's the possibility to ask Community Support to do this.
Cheers!
Cheers!