Brad --

Just a thought.  Have you tried sw.close() before your
System.err.println in addPage?

Gary

> -----Original Message-----
> From: Brad Cox [mailto:[EMAIL PROTECTED] 
> Sent: Sunday, February 03, 2002 1:03 PM
> To: [EMAIL PROTECTED]
> Cc: Brad Cox
> Subject: Re: xalan extensions, cont'd.
> 
> 
> 
> On Sunday, February 3, 2002, at 03:29 PM, Frank E. Weiss wrote:
> > Good to hear that you've gotten to that point. You may wind up
> > there again. I think Gary explained why the alternative
> > String parameter wasn't working.
> 
> Yes. At least I know where the problem is now. The solution 
> should follow. But I'm not quite there yet.
> 
> > Coding a new treewalk? I hope not! (BTW I couldn't find
> > anything about XSLT/Xalan multiple output documents - that's the
> > only approach I know of that would be entirely within XSLT.) If 
> > you dig into org.apache.xalan.serialize.SerializerToHTML
> > you might find some way to give it the RTF you got in addPage 
> > and make it spit out HTML. You'll also have to dump the
> > stream into a String or buffer of some kind so you can hand it 
> > off to the Page constructer. Maybe
> > java.io.ByteArrayOutputStream.
> 
> See latest try at the bottom. First try dies with "can't find 
> workingDirectory/HTMLEntites.res", even though xalan.jar's in my 
> WEB-INF/lib. Extracted a copy into workingDirectory got past 
> that. Where I am now is that the sw variable winds up empty so 
> I"m still stuck
> 
> > But what does the Page constructor ultimately do with the body
> > string? I'm just thinking that if it saves it to a file
> > or streams it out a network port, there's not point in 
> > converting the RTF into a string first. Just point the 
> > serializer
> > to the output stream or file. Yikes! It looks like a nasty 
> > plumbing job.
> 
> Saves it as a string, indexed by pagnumber, in a HashMap. 
> Ultimately feeds that to Velocity as if it were an input file.
> 
> The whole point is to cache the time-consuming parsing steps so 
> that velocity gets its input from the HashMap instead of having 
> to parse XML on the fly.
> 
> > As a last resort a two-pass (actually 1+N transforms) approach
> > would have a greater likelihood of working. First pass
> > gets the index information. Second pass iterates over the index 
> > from the first pass and repeatedly runs a transform with
> > a parameter passed in to select which page to transform. I've 
> > used a similar technique where the first pass creates an
> > Ant build file with a number of Style tasks. I can tell you 
> > more about that if you like.
> 
> I'll take all the help I can get at this point. Never imagined 
> this would be so hard.
> 
> 
> public Page getPage(IntegerField pageNumber) throws Fault
>       {
>               System.err.println("pages:"+pages);
>               System.err.println("lastModified"+
>                       " xml:"+ (lastModified-xmlFile.lastModified())+
>                       " xsl:"+ (lastModified-xslFile.lastModified())
>               );
>               if (pages == null ||
>                       xmlFile.lastModified() > lastModified ||
>                       xslFile.lastModified() > lastModified)
>               {
>                       if (!xmlFile.exists()) throw new Fault(this + " 
> can't find:"+xmlFile, null);
>                       if (!xslFile.exists()) throw new Fault(this + " 
> can't find:"+xslFile, null);
>                       try
>                       {
>                               
> System.err.println("transforming:"+ xmlFile + " with " + xslFile);
>                               TransformerFactory tFactory = 
> TransformerFactory.newInstance();
>                               Transformer transformer = 
> tFactory.newTransformer(
>                                       new 
> StreamSource(xslFile.toString())
>                               );
>                               transformer.setParameter("task", this);
>                               StringWriter sw = new StringWriter();
>                               transformer.transform(
>                                       new 
> StreamSource(xmlFile.toString()),
>                                       new StreamResult(sw)
>                               );
>                               System.err.println("discarded 
> text:"+sw);
>                               this.lastModified = 
> System.currentTimeMillis();
>                       }
>                       catch (Exception e)
>                       {
>                               throw new Fault("Exception 
> transforming:"+xmlFile+ " with:"+xslFile, e);
>                       }
>               }
>               else System.err.println("reusing cached page");
>               return (Page)pages.get(pageNumber.getInt());
>       }
>       public void addPage( String ident, org.w3c.dom.Node body)
>       {
>               try
>               {
>                       StringWriter sw = new StringWriter();
>                       Serializer serializer = 
> SerializerFactory.getSerializer
>                               
> (OutputProperties.getDefaultMethodProperties("html"));
>                       serializer.setWriter(sw);
>                       serializer.asDOMSerializer().serialize(body);
>                       System.err.println("addPage:"+sw);
>                       pages.add(new Page(this, ident, 
> "<h2>sw</h2>"+sw, 
> new IntegerField(pages.size())));
>               }
>               catch (IOException e)
>               {
>                       System.err.println("IOException:" + ident);
>                       e.printStackTrace();
>               }
>       }
> 

Reply via email to