You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2007/02/09 10:58:24 UTC

svn commit: r505235 - /xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/servlets.xml

Author: jeremias
Date: Fri Feb  9 01:58:24 2007
New Revision: 505235

URL: http://svn.apache.org/viewvc?view=rev&rev=505235
Log:
Document the usage of the ServletContextURIResolver.

Modified:
    xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/servlets.xml

Modified: xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/servlets.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/servlets.xml?view=diff&rev=505235&r1=505234&r2=505235
==============================================================================
--- xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/servlets.xml (original)
+++ xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/servlets.xml Fri Feb  9 01:58:24 2007
@@ -177,6 +177,71 @@
           apply here, too.
         </p>
       </section>
+      <section id="uriresolver">
+        <title>Accessing resources in your web application</title>
+        <p>
+          Often, you will want to use resources (stylesheets, images etc.) which are bundled with
+          your web application. FOP provides a URIResolver implementation that lets you access
+          files via the Servlet's ServletContext. The class is called 
+          <code>org.apache.fop.servlet.ServletContextURIResolver</code>.
+        </p>
+        <p>
+          Here's how to set it up in your servlet. Instantiate a new instance in the servlet's 
+          init() method:
+        </p>
+        <source><![CDATA[
+    /** URIResolver for use by this servlet */
+    protected URIResolver uriResolver; 
+
+    public void init() throws ServletException {
+        this.uriResolver = new ServletContextURIResolver(getServletContext());
+        [..]
+    }]]></source>
+        <p>
+          The ServletContextURIResolver reacts on URIs beginning with "servlet-context:". If you
+          want to access an image in a subdirectory of your web application, you could, for
+          example, use: "servlet-context:/images/myimage.png". Don't forget the leading slash
+          after the colon!
+        </p>
+        <p>
+          Further down, you can use the URIResolver for various things:
+        </p>
+        <ul>
+          <li>
+            With the Transformer (JAXP/XSLT) so things like document() functions can resolver 
+            "servlet-context:" URIs.
+          </li>
+          <li>
+            With the FopFactory so every resource FOP loads can be loaded using a "servlet-context:"
+            URI.
+          </li>
+          <li>
+            You can the ServletContextURIResolver yourself in your servlet code to access
+            stylesheets or XML files bundled with your web application.
+          </li>
+        </ul>
+        <p>
+          Here are some example snippets:
+        </p>
+        <source><![CDATA[
+//Setting up the JAXP TransformerFactory
+this.transFactory = TransformerFactory.newInstance();
+this.transFactory.setURIResolver(this.uriResolver);
+
+[..]
+
+//Setting up the FOP factory
+this.fopFactory = FopFactory.newInstance();
+this.fopFactory.setURIResolver(this.uriResolver);
+
+[..]
+
+//The stylesheet for the JAXP Transfomer
+Source xsltSrc = this.uriResolver.resolve(
+    "servlet-context:/xslt/mystylesheet.xsl", null);
+Transformer transformer = this.transFactory.newTransformer(xsltSrc);
+transformer.setURIResolver(this.uriResolver);]]></source>
+      </section>
     </section>
     <section id="ie">
       <title>Notes on Microsoft Internet Explorer</title>



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org