473,387 Members | 1,388 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Create OutputStream based on ContentHandler

Hi,

Is there a wrapper class, or combination of classes, that will allow me
to do the following:

class Wrapper extends java.io.OutputStream {
public void setContentHandler(org.xml.sax.ContentHandler handler);
...
}

Or is there some reason why this won't work?

BEA appear to have something like this, with a
"weblogic.xml.stream.XMLOutputStream", but I'm wondering if it's
possible to create this with standard SAX components.

Cheers,

Barney

Mar 23 '06 #1
7 1837
ba******@iname.com wrote:
class Wrapper extends java.io.OutputStream {
public void setContentHandler(org.xml.sax.ContentHandler handler);
...
}

BEA appear to have something like this, with a
"weblogic.xml.stream.XMLOutputStream", but I'm wondering if it's
possible to create this with standard SAX components.


Sounds like what you're looking for is a SAX handler that implements a
serializer. Most SAX systems come with one, and they're commonly
available. They aren't generally implemented as subclassing
OutputStream; instead they point to an OutputStream.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Mar 23 '06 #2

I think the handlers that contain an output stream write their content
to this stream - what I'm after is a way to stream data *into* a
content handler. For example, with a serializer which converts an
object to XML:

interface XMLSerializer() {
static void serialize(Object o, OutputStream os);
}

wrapper = new Wrapper(...);
wrapper.setContentHandler(handler);
XMLSerializer.serialize(object, wrapper);

and let the content handler process the XML produced in exactly the
same way in which the XMLReader.parse() method does, but by pushing the
streaming data in rather than pulling it via the parse method.

Sorry - should probably have been more specific in the first post.

Cheers,
Barney
--
baarney
------------------------------------------------------------------------
baarney's Profile: http://techiegroups.com/member.php?userid=84
View this thread: http://www.techiegroups.com/showthread.php?t=105008

Mar 23 '06 #3
baarney wrote:
what I'm after is a way to stream data *into* a
content handler.


Huh? That's known as a parser...

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Mar 24 '06 #4
Joe Kesselman wrote:
what I'm after is a way to stream data *into* a
content handler.


Huh? That's known as a parser...


Clarification: If your problem is that you want to feed the data via an
OutputStream, whereas parsers normally want an InputStream, then what
you need is a simple adapter which has a buffer in the middle and some
handshaking so that when the buffer fills the source pauses in writing
to it, and as it empties the source is allowed to fill it up again.
Typically that's done by running the data source and the parser-driven
process in separate threads and using a queue or ringbuffer between them.

I'm sure such out-to-in stream adapters are available as an
off-the-shelf item; do a bit of websearching.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Mar 24 '06 #5

That's pretty much exactly much what I was looking for :-)

Rather than separate threads, I was hoping for something that monitored
the state of the internal buffer during the OutputStream.write() calls,
and fired off the appropriate ContentHandler methods when it had
received enough data to form a valid call, blocking the write until the
event returned - like once a "<" character is seen, monitor the input
until the corresponding ">" character is found and then fire the
handler's startElement(...) method.

It's obviously going to be quite a bit more involved that this, which
is why I was hoping someone had already written it, but the basic idea
seems like it ought to work.
I'm sure such out-to-in stream adapters are available as an
off-the-shelf item; do a bit of websearching.


So was I, so I did :-)

There's a bunch of generic stream adapters, but I couldn't find
anything which actually parsed the input stream into XML. I know
there's a bunch of projects that must do this (Cocoon springs to mind),
but I didn't find any likely candidate classes. Posting here was the
next step in my web searching.

If I don;t find anything then I may have a go at writing one, there's
plenty of parser code out there to base it on.

Cheers,
Barney
--
baarney
------------------------------------------------------------------------
baarney's Profile: http://techiegroups.com/member.php?userid=84
View this thread: http://www.techiegroups.com/showthread.php?t=105008

Mar 24 '06 #6
baarney wrote:
There's a bunch of generic stream adapters, but I couldn't find
anything which actually parsed the input stream into XML.


Adapt the stream from push to pull, feed it into a parser that accepts a
stream, done. No need to modify the parser to achieve this.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Mar 24 '06 #7
baarney wrote:
It's obviously going to be quite a bit more involved that this, which
is why I was hoping someone had already written it, but the basic idea
seems like it ought to work.


The problem is one of retaining state. EVERYONE wants to be the inner
loop, because that means they don't get interrupted, and therefore they
don't have to deal with saving their state partway through processing
and then restoring it and proceeding next time they're called.

Coroutines are the real way to solve this, but most languages don't have
coroutines. Building a coroutine-like system out of threads is an
adequate answer.

Trying to write a full XML parser which can really be driven by pushing
data into it rather than having it pull data as needed is nontrivial.
Feel free to take a crack at it, of course.
--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Mar 24 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Nicholas Then | last post by:
I am writing an ASP.NET application and I have a class that I have written to create a vCard...it just returns a string with all the necessarry info... Anyway...is there a way that I can create a...
1
by: Neil Woodvine | last post by:
***Scenario ... I have a DataList with a hyperlink WebControl in the Item Template. I want to display a 64x64 image in the Hyperlink and set the NavigateURL to the full size image. ***Source...
0
by: brrrdog | last post by:
Whenever I write to Response.Outputstream after doing a plain response.write, I get a delimiter between the two writes that is made up of three extended ascii chars (decimal equivalents 239,...
2
by: Jeff Calico | last post by:
Hello all. I am implementing a SAX filter to strip a bunch of unneeded elements out of a large XML file. I found a book "Java & XML" by Brett McLaughlin, and an interesting article by him wich...
1
by: Federico | last post by:
Hi I want to create a Web Services where I receive a Template DOT word a file XML and with these I create a Document that a I'll Send as Dime Attachment. <WebMethod()> _ Public Function...
0
by: Federico | last post by:
Hi I want to create a Web Services where I receive a Template DOT word a file XML and with these I create a Document that a I'll Send as Dime Attachment. <WebMethod()> _ Public Function...
0
by: Federico | last post by:
Hi I want to create a Web Services where I receive a Template DOT word a file XML and with these I create a Document that a I'll Send as Dime Attachment. <WebMethod()> _ Public Function...
1
by: rushikesh.joshi | last post by:
Hi All, I want some charting functionality in my ASP.NET application. I want to show a multiple bar on my web page. It's based on down time of different servers. like server1: down betn 4 AM...
2
by: ken | last post by:
Hi, i have a class: class LogHandler(ContentHandler): # a reference to a file open by some other function/class outputFile; def endElement(self, name): doSomething(self,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.