aspose file tools*
The moose likes Servlets and the fly likes how to handle the text which is copied from doc file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to handle the text which is copied from doc file" Watch "how to handle the text which is copied from doc file" New topic
Author

how to handle the text which is copied from doc file

saikrishna cinux
Ranch Hand

Joined: Apr 16, 2005
Posts: 689
hi, here is a strange problem with special characters which are copied from the microsoft document file to a textarea .

yes, there is a difference in copying from word file and direclty typing the text into the text area

for example if we copy single quote and double quote from a word file into text area and if we insert the text into datbase table and if we retrieve back from the datbase file it will be different.


that means the text which (contains single quotes and double quotes)is copied from the word file will be treated as unknown characters by the textarea.

so there is a problem with text area.

there might be some solution for this.
can any one please help me


A = HARDWORK B = LUCK/FATE If C=(A+B) then C=SUCCESSFUL IN LIFE else C=FAILURE IN LIFE
SCJP 1.4
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12822
    
    5
If your data is already in one or more strings, one possibility would be the String replace( oldchar, newchar ) method repeated for each of those ghastly "smart" characters that Word uses.
Remember that replace creates a new String if any match is found.
Bill
saikrishna cinux
Ranch Hand

Joined: Apr 16, 2005
Posts: 689
YES,YES,YES you are perfectly correct
i have used the same technique for this issue

greate suggestion

but unfortunatley this leads to performance degrading in big applications and when ever user needs to handle huge text(data) as input from the end user

here is the complete code which takes the input from a jsp page(textarea) and inserts into datbase and then retrieve back from the the databse and displays in th jsp page

please take some time to view my code because this is really Very IMPORTANT issue for all the people who is going to copy the text from word file and paste it into textarea .







but unfortunatley this code is also not going to help all the developers becasue the scan codes which i have got is different from my friends system (they are not independent)

i got 145,146,147,148 fro single quotes and double quotes but in my frnds system some otehr numbers i got

so, with this i can say that by just using replace method we cannot obtain the solution

there must be soem other way for this problem

if anybody know about this problem or overcome this problem please let me know the solution

thanks for your help in advance

regards
saikrishna
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12822
    
    5
I know of no way around it, you have to find out every single one of the possible oddball codes and their replacements and handle them one at a time. You might be able to speed things up by checking for more than one character at a time - take a look at the source for the String.replace method for inspiration.

Please note that the slowest thing in the code you show is probably the getting a separate database connection for each request. In production code you would certainly use a connection pool.

Dont assume you have a performance problem until you have run tests. How big are these chunks of text anyway?

Bill
Richard Green
Ranch Hand

Joined: Aug 25, 2005
Posts: 536
i dont understand the question - tell me what you get when you try to save this string to the database and bring it back.

the quic'k bro"wn fox


MCSD, SCJP, SCWCD, SCBCD, SCJD (in progress - URLybird 1.2.1)
saikrishna cinux
Ranch Hand

Joined: Apr 16, 2005
Posts: 689
Originally posted by Lynette Dawson:
i dont understand the question - tell me what you get when you try to save this string to the database and bring it back.

the quic'k bro"wn fox


some inverted question marks in the jsp page
saikrishna cinux
Ranch Hand

Joined: Apr 16, 2005
Posts: 689
Originally posted by William Brogden:
I know of no way around it, you have to find out every single one of the possible oddball codes and their replacements and handle them one at a time. You might be able to speed things up by checking for more than one character at a time - take a look at the source for the String.replace method for inspiration.

Please note that the slowest thing in the code you show is probably the getting a separate database connection for each request. In production code you would certainly use a connection pool.

Dont assume you have a performance problem until you have run tests. How big are these chunks of text anyway?

Bill


hey, the textarea has got lot of data 1000's of characters
so i need to apply this logic to all the text fields and textarea of all the jsp pages
nearly hundereds of fields

so is ther any otherway to overcome this problem
Marcus Howarth
Ranch Hand

Joined: Jan 04, 2002
Posts: 37
Hi,

just quick idea - I'm not sure I understand the "pasting from word to textarea" part - but it does sound like a character set / special characters issue

In your oracle driver config, have you set the charset to use UTF8 ?? if not that might be part of your problem

HTH


Marcus<br /> <br />SCJP, March '02
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12822
    
    5
so is ther any otherway to overcome this problem

If this was my problem I would create a method

String fixDumbSmartChars( String )

Which would:


Bill
Shilpi M Ag
Ranch Hand

Joined: May 07, 2004
Posts: 40
cant you use regex to replace in string?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to handle the text which is copied from doc file