• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java filter

 
Negru Ionut Valentin
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to do a filter that will change the way the text is displayed in a page(html or jsp)... In the pages I want to check for tags like '<pre>' in the page and if found then to make some words red(like 'integer', 'string' - from programming languages). Also i want to make the code comments in italic and the tabs converted in spaces ' ' ...

I tried looking for some tutorials how to implement an filter but no luck ...

Some basic examples(working ones so i can see how it really works) would be great ...
Also if you know any links with tutorials for something like this also would be great
 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why dont your use javascript instead?

I found this in the internet http://codemirror.net/1/story.html

I know that this is a good solution because tons of foruns/blogs use something like this. =D
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65516
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hebert Coelho wrote:Why dont your use javascript instead?

Because JavaScript can be disabled, and cleansing the output is a security measure that can't be left to client side code that may or may not run.

Sounds like perfect job for a custom tag.
 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
Hebert Coelho wrote:Why dont your use javascript instead?

Because JavaScript can be disabled, and cleansing the output is a security measure that can't be left to client side code that may or may not run.

Sounds like perfect job for a custom tag.


Ok! Custom tag it is! \o/
 
Negru Ionut Valentin
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isn't there an easy way to implement an filter to do this ?

The problem is that i didn't found anything useful about this ... mainly i found how to implement a filter for authentication ...

Also I will check those custom tags you recommended but I would like to do it with a filter ... from what I've read about Java Filters this should be done rather easy ... but I can't seem to figure it out at this moment ...
 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Negru Ionut Valentin wrote:from what I've read about Java Filters this should be done rather easy ...


Where you read this?
 
Negru Ionut Valentin
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I mean from the definition of an Filter, that's what I understood ... was I wrong ? They are not used for this kind of task ?

Also with those custom tags would I be able to manipulate the html tags so i can reformat them like I want(change color, style, indexing <<tabs>>) ?

PS: I found this example(He converts all output to uppercase) but I couldn't make it work ... http://www.java2s.com/Tutorial/Java/0400__Servlet/Filterthatusesaresponsewrappertoconvertalloutputtouppercase.htm
Is there something wrong with this example or I don't know how to make it work ... If it works can please explain how to implement it ? I use NetBeans7(if it helps) ...

I'm thinking I'm needing to implement something like that but to add the option to look inside the code for those tags and format only specific portions of text ....

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65516
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you could use a filter -- but it's not what I would call exactly "easy".

You'd need to implement a response wrapper so that you could capture and change the text of the response.

The term to search for is "response wrapper"
 
Paul Clapham
Sheriff
Posts: 21862
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the sample code you posted that link to is indeed a response wrapper. Unfortunately changing all of the text in the response (that example) to upper-case is trivially simple whereas parsing the HTML in the text and modifying it (your requirement) is far from trivial.

So, as you can see, it is indeed easy to implement a filter. That doesn't automatically make it easy to implement every possible thing you might want that filter to do.
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To me, it sounds like a time to use CSS and perhaps something like sitemesh http://www.sitemesh.org/overview.html
 
Negru Ionut Valentin
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you guys know any good example how I can create those custom tags ? I've read the info from the sitemesh website but didn't found any useful information about manipulating some specific tags ...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!