ilene 2003/02/20 10:49:17
Modified: java/xdocs/sources/xalan samples.xml readme.xml
usagepatterns.xml
Log:
Committing Christine Li's ([EMAIL PROTECTED]) patch to the servlet sample
documentation.
Bugzilla #17136
Revision Changes Path
1.51 +29 -28 xml-xalan/java/xdocs/sources/xalan/samples.xml
Index: samples.xml
===================================================================
RCS file: /home/cvs/xml-xalan/java/xdocs/sources/xalan/samples.xml,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -r1.50 -r1.51
--- samples.xml 4 Feb 2003 20:36:17 -0000 1.50
+++ samples.xml 20 Feb 2003 18:49:17 -0000 1.51
@@ -208,11 +208,13 @@
</s2><anchor name="servlet"/>
<s2 title="servlet">
<p>For a general introduction, see <link idref="usagepatterns"
anchor="servlet">Using &xslt4j; in a servlet</link>.</p>
- <p>The servlet subdirectory contains four sample servlets that use &xslt4j; to
perform transformations. These servlets
- are in a package named servlet and are compiled in xalanservlet.jar. To run
these samples, you must place
- xalanservlet.jar, and any XML and XSL files you want to use on a web server
with a servlet engine, place
- xalanservlet.jar, xalan.jar, and &xml4j-jar; on the servlet engine class path,
and configure the servlet engine to
- locate the XML and XSL files, and the properties file used by ApplyXSL.</p>
+ <p>The servlet subdirectory contains four sample servlets and one JSP that use
&xslt4j; to perform transformations. The sample
+ code is compiled and packed in xalanservlet.war. To run these samples, you must
place
+ xalanservlet.war on a web server with a servlet engine. For example, using
<jump href="http://jakarta.apache.org/tomcat/index.html">jakarta-tomcat 4.1.18</jump>.
+ Copy the xalanservlet.war to %Tomcat_Home%/webapps. For more detail about
deploying
+ servlet on Tomcat, please refer to <jump
href="http://jakarta.apache.org/tomcat/tomcat-4.1-doc/appdev/deployment.html">Deployment
Organization</jump>.</p>
+ <note>Dependency on Tomcat version. If encountering "java.lang.VerifyError:
Cannot inherit from final class" error,
+ replace XercesImpl.jar under %Tomcat_Home%/common/endorsed with the one
included with &xslt4j; .</note>
<p><link anchor="simplexsltservlet">servlet.SimpleXSLTServlet</link> applies a
particular stylesheet to a particular
XML document.</p>
<p><link
anchor="usestylesheetparamservlet">servlet.UseStylesheetParamServlet</link> sets a
stylesheet parameter
@@ -227,12 +229,11 @@
stylesheet to apply based on the identity of the client browser/device.</p>
<anchor name="simplexsltservlet"/>
<s3 title="servlet.SimpleXSLTServlet">
- <p>What it does: servlet.SimpleXSLTServlet applies the spec.xsl stylesheet to
trax.xml (see the <link anchor="get-trax">
- get-trax applet</link>) and returns the transformation result to the HTTP
client.</p>
- <p>To run this servlet: place spec.xsl and trax.xml (from the
samples/AppletXMLtoHTML directory) in the directory where your servlet engine
- looks for HTTP documents, place xalanservlet.jar on the servlet engine
classpath, and set up an HTML page to call the servlet as
+ <p>What it does: servlet.SimpleXSLTServlet applies the birds.xsl stylesheet to
birds.xml
+ and returns the transformation result to the HTTP client.</p>
+ <p>To run this servlet: set up an HTML page to call the servlet as
follows:</p>
-<gloss><label>http://localhost/servlethome/servlet.SimpleXSLTServlet</label></gloss>
+<gloss><label>http://localhost:port/xalanservlet/SimpleXSLTServlet</label></gloss>
</s3><anchor name="usestylesheetparamservlet"/>
<s3 title="servlet.UseStylesheetParamServlet">
<note>Paul Campbell <[EMAIL PROTECTED]> wrote this servlet and the
following explanatory text.
@@ -240,15 +241,11 @@
<p>What it does: The client (perhaps an HTML form ) specifies an XML document,
a stylesheet, and a value to be passed
to the stylesheet for a stylesheet parameter named "param1". The servlet
performs the transformation and returns
the output to the client. The client must specify which stylesheet
(containing a "param1" stylesheet parameter")
- and XML file are to be used.</p>
- <p>How to run it: Configure your application server (Tomcat, Websphere or
JServ, for example)
- so it can find servlet.UseStylesheetParamServlet (in xalanservlet.jar) as well
as the XML document
- and XSL stylesheet. For example, you can copy fooparam.xml and fooparam.xsl
from samples/servlet to the application
- server root directory for documents.</p>
- <p>Then you can set up an HTML client to call the servlet with arguments along
the lines of</p>
- <gloss><label>http://localhost/servlethome/servlet.UseStylesheetParamServlet?
+ and XML file are to be used or use sample files fooparam.xml and
fooparam.xsl</p>
+ <p>How to run it: set up an HTML client to call the servlet with arguments
along the lines of</p>
+ <gloss><label>http://localhost:port/xalanservlet/UseStylesheetParamServlet?
XML=fooparam.xml&XSL=fooparam.xsl&PVAL=GoodBye</label></gloss>
- <p>In the doGet() method, the servlet obtains the PVAL value "GoodBye") from
the servlet request and passes it to the
+ <p>In the doGet() method, the servlet obtains the PVAL value "GoodBye" from
the servlet request and passes it to the
stylesheet as the paramValue argument in a Transformer setParameter() call:</p>
<p><code>String paramValue =
httpServletRequest.getParameter("PVAL");</code><br/>
<code>...</code><br/>
@@ -261,29 +258,33 @@
<p>This Java Server Page performs essentially the same operation as
<link
anchor="usestylesheetparamservlet">servlet.UseStylesheetParamServlet</link>. It
applies a stylesheet parameter
to a stylesheet (fooparam.xsl), applies the stylesheet to an XML source
document (fooparam.xml), and returns the
- result.</p>
+ result.</p>
+ <p>Call JSP as follows:</p>
+ <gloss><label>http://localhost:port/xalanservlet/jspSample.jsp?
+ XML=fooparam.xml&XSL=fooparam.xsl&PMA=GoodBye</label></gloss>
+ <p>The JSP obtains the PMA value "GoodBye" from the http request and passes
it to the stylesheet as the
+ paramValue argument in a Transformer setParameter() call.</p>
</s3><anchor name="xsltservletwithparams"/>
<s3 title="servlet.XSLTServletWithParams">
<p>What it does: servlet.XSLTServletWithParams takes parameters in the request
-- a URL parameter for
the XML input document URL and an xslURL parameter for the stylesheet URL.</p>
<p>To use XSLTServletWithParams to perform the same transformation as
SimplestServlet:
- place spec.xsl and trax.xml in the directory where your servlet engine looks
for HTTP documents, place
- xalanservlet.jar on the servlet engine classpath, and set up an HTML page to
call the servlet as follows:</p>
-<gloss><label>http://localhost/servlethome/servlet.XSLTServletWithParams?URL=file:trax.xml&
-xslURL=file:spec.xsl</label></gloss>
+ use birds.xsl and birds.xml as examples. Set up an HTML page to call the
servlet as follows:</p>
+<gloss><label>http://localhost:port/xalanservlet/XSLTServletWithParams?URL=birds.xml&
+xslURL=birds.xsl</label></gloss>
<p>If the XML document contains an associated stylesheet (a stylesheet
Processing Instruction) that you want to use, simply omit the
xslURL parameter.</p>
- <p>If the stylesheet takes stylesheet parameters, you can include them in the
URL. For example to set set the param1
+ <p>If the stylesheet takes stylesheet parameters, you can include them in the
URL. For example to set the param1
stylesheet parameter to foo, include param1=foo in the URL.</p>
</s3><anchor name="applyxslt"/>
<s3 title="servlet.ApplyXSLT">
<p>What it does: The client (which you must set up) specifies an XML document
and a stylesheet. The servlet
performs the transformation and returns the output to the client. You can use
media.properties to specify
which stylesheet is to be used depending on the client browser/device.</p>
- <note>The source files for this servlet include ApplyXSLT.java,
ApplyXSLTProperties.java, DefaultApplyXSLTProperties.java,
- ApplyXSLTListener.java, and ApplyXSLTException.java.</note>
- <p>To run the servlet: put xalanservlet.jar on the servlet engine classpath,
configure your servlet engine so it can find the
- stylesheets and properties file in the servlet subdirectory (and in
xalanservlet.jar), and set up an HTML page to call
+ <note>The source files for this servlet, including ApplyXSLT.java,
ApplyXSLTProperties.java, DefaultApplyXSLTProperties.java,
+ ApplyXSLTListener.java, ApplyXSLTException.java. booklist1.xsl, booklist2.xsl
and catalog.xml,
+ are provided for testing.</note>
+ <p>To run the servlet: set system property server.root=server root. Set up an
HTML page to call
servlet.ApplyXSLT with arguments as illustrated below.</p>
<p>The files foo.xml and foo.xsl used in the following example are created by
the user. Good
examples for these files are birds.xml/birds.xsl and foo.xml/foo.xsl under the
SimpleTransform
1.88 +1 -1 xml-xalan/java/xdocs/sources/xalan/readme.xml
Index: readme.xml
===================================================================
RCS file: /home/cvs/xml-xalan/java/xdocs/sources/xalan/readme.xml,v
retrieving revision 1.87
retrieving revision 1.88
diff -u -r1.87 -r1.88
--- readme.xml 27 Jan 2003 18:45:36 -0000 1.87
+++ readme.xml 20 Feb 2003 18:49:17 -0000 1.88
@@ -335,7 +335,7 @@
<tr><td>compile</td><td>compiles &xslt4j; in build/classes.</td></tr>
<tr><td>jar (the default)</td><td>creates xalan.jar in the build
directory</td></tr>
<tr><td>samples</td><td>compiles and jars the sample apps in
build/xalansamples.jar</td></tr>
- <tr><td>servlet</td><td>compiles and jars the sample servlet in
build/xalanservlet.jar</td></tr>
+ <tr><td>servlet</td><td>compiles and jars the sample servlet in
build/xalanservlet.war</td></tr>
<tr><td>docs</td><td>creates the HTML User's Guide in build/docs</td></tr>
<tr><td>javadocs</td><td>generates the API documentation in
./build/docs/apidocs</td></tr>
<tr><td>dist</td><td>generates a complete distribution tree with zip and
tar.gz distribution files in build</td></tr>
1.52 +6 -3 xml-xalan/java/xdocs/sources/xalan/usagepatterns.xml
Index: usagepatterns.xml
===================================================================
RCS file: /home/cvs/xml-xalan/java/xdocs/sources/xalan/usagepatterns.xml,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -r1.51 -r1.52
--- usagepatterns.xml 27 Jan 2003 18:45:36 -0000 1.51
+++ usagepatterns.xml 20 Feb 2003 18:49:17 -0000 1.52
@@ -415,7 +415,8 @@
<p>You can set up a servlet to use &xslt4j; to respond to requests for XML
documents by transforming those documents into HTML and serving them to web browsers.
To respond to HTTP GET requests, all you need to do is overwrite the HttpServlet
doGet() method with a procedure that instantiates a Transformer and uses it to perform
a transformation. As the following example shows, you can generate a ResultStream that
a PrintWriter writes to the HttpResponse OutputStream, returning the transformation
output to the web browser.</p>
<source>
public class SampleXSLTServlet extends javax.servlet.http.HttpServlet {
-
+
+ public final static String FS = System.getProperty("file.separator");
// Respond to HTTP GET requests from browsers.
public void doGet (javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
@@ -429,14 +430,16 @@
{
javax.xml.transform.TransformerFactory tFactory =
javax.xml.transform.TransformerFactory.newInstance();
+ //get the real path for xml and xsl files.
+ String ctx = getServletContext().getRealPath("") + FS;
// Get the XML input document and the stylesheet, both in the servlet
// engine document directory.
javax.xml.transform.Source xmlSource =
new javax.xml.transform.stream.StreamSource
- (new java.net.URL("file:foo.xml").openStream());
+ (new java.net.URL("file", "",
ctx+"foo.xml").openStream());
javax.xml.transform.Source xslSource =
new javax.xml.transform.stream.StreamSource
- (new java.net.URL("file:foo.xsl").openStream());
+ (new java.net.URL("file", "",
ctx+"foo.xsl").openStream());
// Generate the transformer.
javax.xml.transform.Transformer transformer =
tFactory.newTransformer(xslSource);
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]