[Home]  [List]  [News]  [Docs]  [FAQ]  [Downloads]  [Resources]  [About]
Search :
/Home /List

list4xt : Mailing list for the XT users community.

[list4xt] String2RTF.

Subject: [list4xt] String2RTF.

User: Website

From: Paul Tchistopolskii (pault12@pacbell.net)
Date: 22/06/2000 - 08:18


Hello.

Here comes trivial 'missing link' for those who don't like
( or don't want) accurate coding of SAX events, but still want
to turn some string into node-set on the fly.

This is continuation of Eric's work published at 4xt.org,
in which he demonstrated how to get RTF out of Java
function. I'm just adding one more step into the chain,
because ... I don't know .... XSLT lacks String->Nodeset
conversion, but I can not live without it in Ux.

Here we go.

------------------------- com.pault.pxsl.Str2RTF.java

package com.pault.pxsl;

import org.xml.sax.*;
import java.io.ByteArrayInputStream;
import com.jclark.xsl.sax.ResultTreeFragment;

import org.xml.sax.DocumentHandler;
import org.xml.sax.SAXException;
import org.xml.sax.InputSource;

/**
 * Creation date: (6/2/00 4:40:39 PM)
 * @author: Paul Tchistopolskii
 */
public class Str2RTF implements com.jclark.xsl.sax.ResultTreeFragment {
 private String s;

 public Str2RTF(String s){ this.s = s; }

 public static ResultTreeFragment convert(String s) {
  // System.out.println(s);
  ResultTreeFragment rtf = new Str2RTF(s);
  return rtf;
 }

public void emit(DocumentHandler handler) throws SAXException {
 Parser parser = new com.jclark.xml.sax.CommentDriver();
 parser.setDocumentHandler( handler );
 try {
  parser.parse( new InputSource(new ByteArrayInputStream( s.getBytes() ) ));
 } catch ( Exception e ) {
  throw new SAXException( e.toString() );
 }
}
}

---------------- session.xsl

<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:s2r="http://www.jclark.com/xt/java/com.pault.pxsl.Str2RTF"
  xmlns:ux="http://www.jclark.com/xt/java/UxServlet"
  xmlns:xt="http://www.jclark.com/xt"
  version="1.0">

<xsl:param name="UX-SERVLET-REQUEST"/>

<!-- Data to XML string -->

<xsl:variable name="_session"
 select="ux:dump_session_variables($UX-SERVLET-REQUEST)"/>

<!-- String to RTF -->

<xsl:variable name="_rtf">
 <xsl:copy-of select="s2r:convert($_session)"/>
</xsl:variable>

<!-- RTF to nodeset -->

<xsl:variable name="UX-SESSION" select="xt:node-set($_rtf)"/>

</xsl:stylesheet>

Java function dump_session_variables() returns the *string*
which is:

"<SESSION><SOME>DATA</SOME><HERE>AGAIN</HERE><SESSION>"

$UX-SERVLET-REQUEST is provided by Ux framework,
but this is not related to the basic functionality.

Rgds.Paul.

PS. Ux now has UNIX-alike sessions and file permissions, including
setuid. This is all XML + XSLT + a few java primitives, like
Str2RTF - and this all works. Life is beautiful and thank you, Eric for
publishing Java - > RTF step!

I first was thinking about changing the contents of your document, but
then I decided that it may be better to ship this snippet in the form
of letter, because anyway I think you'l do much better with this stuff,
than I can do.

I mean, I think maybe you'l extend the document with this example,
somehow ? Even my addition looks trivial when comparing it to the
work done by you, maybe it is worth publishing?

If yes, I may also add :

 /*
 This is 'cleaner' way of Str2RTF ( not to fire start/endDocument events).

 However, because it already works - let's not use Proxy for now.

 public class Proxy extends org.xml.sax.HandlerBase {

  private DocumentHandler h_to_pass = null;

  Proxy( DocumentHandler htopass ) { super(); h_to_pass = htopass; }

  public void startElement(String name, org.xml.sax.AttributeList attrs) throws
SAXException
   { h_to_pass.startElement(name,attrs); }

  public void endElement(String name ) throws SAXException
   { h_to_pass.endElement(name); }

  public void characters(char[] ch, int start, int length) throws SAXException
   { h_to_pass.characters(ch, start, length); }

*/

To use this fellow:

parser.setDocumentHandler( handler );

Should be changed to:

parser.setDocumentHandler( new Proxy(handler) );

Just for the sake of event filtering ;-)

Rgds.Paul.

--
(mailto:list4xt-request@4xt.org?Subject=unsubscribe to unsubscribe)



Archive générée par hypermail 2b28 le 06/11/2001 - 11:46 CET

webmaster@4xt.org