You use an input stream doc object (illustrated in Lesson 6) when you want a Print Job to print the contents of a local file. What about documents located anywhere on the Internet? Yet another kind of doc flavor lets you print any document available at a Uniform Resource Locator (URL) address.
Below is an example code fragment
that prints the Internet Engineering Task Force's (IETF's) home page,
whose URL is "http://www.ietf.org/index.html".
Lines 36-43 construct a
URLDoc object.
The three parameters are the document's URL address,
the MIME type of the data in the document,
and an attribute set containing document level printing attributes.
The IETF's home page is a Hypertext Markup Language (HTML) document,
not a plain text document.
So the MIME type is "text/html",
not "text/plain".
This doc object then undergoes the standard printing process.
To get this code to compile,
lines 84-88 add an exception handler
for the checked exception java.net.MalformedURLException.
This exception will be thrown
by the URL() constructor on line 38
if, for example, if the URL address string had bad syntax.
Class
URLDoc's
doc flavor uses a representation class of "java.net.URL",
rather than a representation class of "java.io.InputStream"
as in the previous example.
This causes the Jini Print Service instance to behave differently
when told to print the doc object.
Instead of obtaining an input stream from the doc object
and reading bytes from the input stream,
this time the Jini Print Service instance obtains a URL from the doc object.
To obtain the actual print data,
the printer goes straight to the URL address on the Internet
and downloads the document directly,
bypassing the client.
For this reason,
use a URL doc object
only for a document whose URL the printer can access directly.
If the printer cannot access the URL directly but the client can, instead of a URL doc object use an input stream doc object constructed like this:
InputStreamDoc theDoc =
new InputStreamDoc
(new BufferedInputStream
(new URL ("http://www.ietf.org/index.html").openStream()),
"text/html",
new HashDocAttributeSet
(new DocumentName
("IETF Home Page",
Locale.getDefault())));
With an input stream doc object constructed this way,
the client opens an input stream on the URL,
and the doc object passes that input stream
to the Jini Print Service instance
when the Jini Print Service instance
asks the doc object for the print data.
When the Jini Print Service instance reads the input stream,
it will go through the client to get the print data
rather than going directly to the URL to get the print data.
This example requires a considerably different printer capability
from the previous examples.
Lesson 6
used a doc object
that provided plain text via an input stream
to the Jini Print Service instance --
a doc flavor of
(MIME type = "text/plain",
print data representation class = "java.io.InputStream").
This example uses a doc object
that provides HTML text via a URL
to the Jini Print Service instance --
a doc flavor of
(MIME type = "text/html",
print data representation class = "java.net.URL").
To support the latter doc flavor,
the Jini Print Service instance
must be able to access URLs directly
and must be able to render HTML documents.
In other words, the Jini Print Service instance
has to do pretty much everything a web browser does.
Suppose the print service lookup
couldn't find any printers with that capability --
is there any way the client can get its job printed?
That will be the topic of Lesson TBD.
DRAFT STANDARD VERSION 1.0 (23-MAY-2000)