Re: nl2br taglib

2003-03-20 Thread Arron Bates
Nice piece of work, it looks familiar...

  http://www.mail-archive.com/[EMAIL PROTECTED]/msg63442.html

...never thought feedback on the solution would be like this, but each to
their own. For those interested, the link contains code which can be used for
any such filter operation.


Arron.


 I truly believe that nl2br would be a most excellent taglib.
 Already my web developer has thanked me 10 times for making this tag
 for him.  Here is why.  Often times the jsp developer needs to
 include a large about of descriptive text with paragraph breaks.
 Normally he/she would have to flood the document with br / tags to
 get the formatting (or p tags or whatever).  By using this tag,
 the jsp developer can just type
 
 filter:nl2brThis is a lot of text
 But I need to have breaks in the text
 But I want to just copy from the text editor
 
 and not have to do further work./filter:nl2br
 
 I am thinking the filter could do other things, such as wordwrap,
 perhaps nl2p for p tags around the line break sections, and a
 horde of other options.
 
 Any one think a filter taglib set would be a good idea?  If we are
 out to save the jsp developers time, this seems like a viable
 solution to me.
 
 I will post the code if anyone is interested, but it wanted that
 complex.
 
 Dan
 
 -- 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 Daniel Allen, [EMAIL PROTECTED]
 http://www.mojavelinux.com/
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 Real programmers just hate to get up in the morning, and 
 contrary to Ordinary People, they're in better shape as 
 it gets closer to nighttime.
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]





-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: nl2br taglib

2003-03-20 Thread Dan Allen
Arron Bates ([EMAIL PROTECTED]) wrote:

 Nice piece of work, it looks familiar...
 
   http://www.mail-archive.com/[EMAIL PROTECTED]/msg63442.html
 
 ...never thought feedback on the solution would be like this, but each to
 their own. For those interested, the link contains code which can be used for
 any such filter operation.
Yep, I took your advice, I had just lost the reference to who had
originally suggested it.  I would have attached the code last time
but my stupid mail client is giving me an error and I have just too
flooded to play with configurations right now.  Here it is.

package net.creativerge.taglib.filter;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.tagext.BodyTagSupport;


public class Nl2brTag extends BodyTagSupport
{
public int doStartTag() throws JspException
{
return EVAL_BODY_BUFFERED;
}

public int doAfterBody() throws JspException
{
BodyContent bodyContent = getBodyContent();

if (bodyContent != null) {
String body = bodyContent.getString();
if (body != null)
{
body = body.replaceAll(\n, br /);
try
{
bodyContent.getEnclosingWriter().println(body);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}

return EVAL_PAGE;
}
}


-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Daniel Allen, [EMAIL PROTECTED]
http://www.mojavelinux.com/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
It is not enough to succeed.  Others must fail.  
 -- Gore Vidal
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: nl2br taglib

2003-03-15 Thread Anil Amarakoon
No such thing exists. May be you are already doing this on jsp. here we
go..
%
 myString.replace(\n,br);
pageContext.setAttribute(anyName,myString);
%

bean:write name=anyName filter=false

.anil


Dan Allen wrote:

 Are there any taglibs that have an attribute similar to
 filter=true for the bean:write that would do nl2br=true

 Users enter non-html text and when I display it I want to replace
 endline characters with html line break markups so that it preserves
 the whitespace.

 If not, I guess I will be learning how to do a custom taglib today.

 Dan

 --
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 Daniel Allen, [EMAIL PROTECTED]
 http://www.mojavelinux.com/
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 Windows: where do you want your data to disappear to today?
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: nl2br taglib

2003-03-15 Thread Dan Allen
Anil Amarakoon ([EMAIL PROTECTED]) wrote:

 No such thing exists. May be you are already doing this on jsp. here we
 go..
 %
  myString.replace(\n,br);
 pageContext.setAttribute(anyName,myString);
 %
 
 bean:write name=anyName filter=false
 
 .anil

Fine, I'll write a custom taglib, because there is absolutely no
reason that this should be a scriplet.  This is exactly equivalence
in importance in tablib terms as html tag escaping.

Dan

-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Daniel Allen, [EMAIL PROTECTED]
http://www.mojavelinux.com/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
I'm old enough to know better, but still too young to care.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: nl2br taglib

2003-03-15 Thread Dan Allen
Attached is a hacked version of WriteTag.java from the struts
library to include a nl2br attribute which will convert \n to br
/ in the output.  It was a pretty simple hack and you can just
update your .tld file to include the java class
net.creativerge.struts.taglib.bean.WriteTag and change your .tld
definition to include the nl2br attribute (just like the filter
attribute) and you will be there.

Someone can feel free to add this to bugzilla, but I have way too
much on my plate right now to put up a fight.

Dan

-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Daniel Allen, [EMAIL PROTECTED]
http://www.mojavelinux.com/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
This is a test of the Emergency Broadcast System.  If this had 
been an actual emergency, do you really think we'd stick around 
to tell you?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: nl2br taglib

2003-03-15 Thread Dan Allen
...see, I'm fading here...trial #2

Dan

[WriteTag.java]

package net.creativerge.struts.taglib.bean;

import javax.servlet.jsp.JspException;

import org.apache.struts.util.RequestUtils;
import org.apache.struts.util.ResponseUtils;

public class WriteTag extends org.apache.struts.taglib.bean.WriteTag
{
protected boolean nl2br = false;

public boolean getNl2br()
{
return nl2br;
}

public void setNl2br(boolean nl2br)
{
this.nl2br = nl2br;
}

public int doStartTag() throws JspException
{
// Look up the requested bean and skip if ignoring and it does not 
exist
if (ignore  (RequestUtils.lookup(pageContext, name, scope) == null))
{
return (SKIP_BODY);
}

// Look up the requested property value
Object value =  RequestUtils.lookup(pageContext, name, property, 
scope);
if (value == null)
{
return (SKIP_BODY);
}

// Convert value to the String with some formatting
String output = formatValue(value);

// filter xml characters if requested
if (filter)
{
output = ResponseUtils.filter(output);
}

// convert endlines to br / tags if requested
if (nl2br)
{
output = output.replaceAll(\n, br /);
}

// Print this property value to our output writer
ResponseUtils.write(pageContext, output);

// Continue processing this page
return (SKIP_BODY);
}
}

-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Daniel Allen, [EMAIL PROTECTED]
http://www.mojavelinux.com/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
There is no such thing as a casual knowledge of xslt, either 
you know everything about it or you are sitting in the creek.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: nl2br taglib

2003-03-15 Thread Arron Bates
Dan,

I think that you may have better luck in a tag that doesn't actually extend or
particularly work around the write tag, but simply filters the results of body
content. That way your not just restricted to filering the content of a bean
property. Markup would be like...


mylib:nl2br whatever nested:write property=something //mylib:nl2br


...And in this would could get the advantages of nested tags or whatever form
you wanted. It also means you don't have to worry about blocking/supporting
the logic of any underlying tag.


The tag class itself would look like...

// import whatever

public class NL2BR extends BodyTagSupport {
  
  public int doAfterBody() throws JspException {
if (bodyContent != null) {
  String filteredContent = bodyContent.getString();
  
  // filter here...

  ResponseUtils.writePrevious(pageContext, filteredContent);
  bodyContent.clearBody();
}
  }
}


...this should, in theory, do the trick. No properties or anything, simply
filter whatever comes through in the body content.


Arron.


PS: get my mail the other day?...
  email client plays funny buggers at times,
  so I don't know what's sent and what's not.



 ...see, I'm fading here...trial #2
 
 Dan
 
 [WriteTag.java]
 
 package net.creativerge.struts.taglib.bean;
 
 import javax.servlet.jsp.JspException;
 
 import org.apache.struts.util.RequestUtils;
 import org.apache.struts.util.ResponseUtils;
 
 public class WriteTag extends org.apache.struts.taglib.bean.WriteTag
 {
   protected boolean nl2br = false;
 
   public boolean getNl2br()
   {
   return nl2br;
   }
 
   public void setNl2br(boolean nl2br)
   {
   this.nl2br = nl2br;
   }
 
   public int doStartTag() throws JspException
   {
   // Look up the requested bean and skip if ignoring and it does not 
 exist if (ignore  (RequestUtils.lookup(pageContext, name, scope) 
 == null)) {   return (SKIP_BODY); }
 
   // Look up the requested property value
   Object value =  RequestUtils.lookup(pageContext, name, property,
  scope);  if (value == null)  {   return 
 (SKIP_BODY); }
 
   // Convert value to the String with some formatting
   String output = formatValue(value);
 
   // filter xml characters if requested
   if (filter)
   {
   output = ResponseUtils.filter(output);
   }
 
   // convert endlines to br / tags if requested
   if (nl2br)
   {
   output = output.replaceAll(\n, br /);
   }
 
   // Print this property value to our output writer
   ResponseUtils.write(pageContext, output);
 
   // Continue processing this page
   return (SKIP_BODY);
   }
 }
 
 -- 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 Daniel Allen, [EMAIL PROTECTED]
 http://www.mojavelinux.com/
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 There is no such thing as a casual knowledge of xslt, either 
 you know everything about it or you are sitting in the creek.
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]