WOText Conversion to HTML On The Fly
WOText Conversion to HTML On The Fly
- Subject: WOText Conversion to HTML On The Fly
- From: Dan Faber <email@hidden>
- Date: Sun, 29 Jun 2003 21:25:00 -0600
I do a lot of presenting text from Strings. I paste the string (or text
from a word processing document) into a WOTextBox and then can
immediately show the text as HTML. In my case, I am currently doing
some processing of the text before going to HTML, in this case taking
xml text and creating java objects which then present their text on the
web page.
By far the easiest way I have found to do this is:
1. create another component ("Message component" or MC) and place it in
the webobjects builder page where you want the HTML text to appear as a
"custom web object", the last icon on the bar to the right.
2. strip the MC of the HTML tags, and put in "append to response" code,
which adds the text to the response. Here is an example:
import com.webobjects.foundation.*;
import com.webobjects.appserver.*;
import com.webobjects.eocontrol.*;
import com.webobjects.eoaccess.*;
public class DisplayNote extends WOComponent {
protected WOComponent returnPage;
public DisplayNote(WOContext context) {
super(context);
}
public void appendToResponse (WOResponse aResponse, WOContext
aContext) {
//we need to add the note text at the bottom
TPStringToHTML stringConverter = new TPStringToHTML();
if (parent() instanceof EditMessageText) {
textToDisplay = ((EditMessageText)parent()).inputText();
}
//use other checks here to reuse this component for other parent
components...
aResponse.appendContentData(stringConverter.convertTextToHTML(currString
));
aResponse.appendContentString("<br>");
}
}
TPStringToHTML is simply a formatter I wrote to convert all the '\r'
characters to <br> tags. It takes a string as input, and outputs NSData
with the changes made.
This seems to be working real well for me, and I am using it in several
places. Hope this helps.
Dan
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.