You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by jo...@apache.org on 2003/10/24 12:58:49 UTC

cvs commit: cocoon-2.1/src/webapp/samples/common view-source.xsp

joerg       2003/10/24 03:58:49

  Modified:    src/webapp/samples/xsp/java resolver.xsp
               src/webapp/samples/common view-source.xsp
  Log:
  replaced deprecated code in view-source.xsp,
  made resolver.xsp working again (paths were no longer correct)
  
  Revision  Changes    Path
  1.2       +31 -38    cocoon-2.1/src/webapp/samples/xsp/java/resolver.xsp
  
  Index: resolver.xsp
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/webapp/samples/xsp/java/resolver.xsp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- resolver.xsp	7 Sep 2003 06:09:10 -0000	1.1
  +++ resolver.xsp	24 Oct 2003 10:58:48 -0000	1.2
  @@ -1,42 +1,35 @@
   <?xml version="1.0" encoding="ISO-8859-1"?>
  -<xsp:page language="java"
  -  xmlns:xsp="http://apache.org/xsp"
  -  xmlns:util="http://apache.org/xsp/util/2.0"
  -  xmlns:xsp-request="http://apache.org/xsp/request/2.0"
  ->
  -  
  -  <page>
  -   <title>An XSP Page using a source</title>
  -   <content>
  -<!-- obtain an InputStream -->
  -	  <p>
  -		this is the colorized source code of this page, included as text:
  -	  </p>
  -	  <table align="center" width="90%" bgcolor="#d0FFFF" border="1">
  -		<tr>
  -		  <td>
  -			  <pre>
  -			  <util:get-source>
  -			    <util:param name="uri">cocoon://samples/view-source?filename=/samples/docs/samples/<xsp-request:get-sitemap-uri/>.xsp</util:param>
  -			  </util:get-source>
  -			  </pre>		  
  -		  </td>
  -		</tr>
  -	  </table>
  -
  -<!-- obtain an InputSource instead of an InputStream -->
  -	  <p>
  -		this is the colorized source code of this page, included as XML:
  -	  </p>
  -	  <table align="center" width="90%" bgcolor="#d0FFFF" border="1">
  -		<tr>
  -		  <td>
  -			  <util:include-source><util:param name="uri">cocoon://samples/view-source?filename=/samples/docs/samples/<xsp-request:get-sitemap-uri/>.xsp&amp;cocoon-view=content</util:param></util:include-source>
  -		  </td>
  -		</tr>
  -	  </table>
  +<xsp:page language="java" xmlns:xsp="http://apache.org/xsp"
  +                          xmlns:util="http://apache.org/xsp/util/2.0"
  +                          xmlns:xsp-request="http://apache.org/xsp/request/2.0">
   
  -      
  -   </content>
  +  <page>
  +    <title>An XSP Page using a source</title>
  +    <content>
  +      <!-- obtain an InputStream -->
  +      <p>this is the colorized source code of this page, included as text:</p>
  +      <table align="center" width="90%" bgcolor="#d0FFFF" border="1">
  +        <tr>
  +          <td>
  +            <pre>
  +              <util:get-source>
  +                <util:param name="uri">cocoon://samples/view-source?filename=<xsp-request:get-servlet-path/>.xsp</util:param>
  +              </util:get-source>
  +            </pre>		  
  +          </td>
  +        </tr>
  +      </table>
  +      <!-- obtain an InputSource instead of an InputStream -->
  +      <p>this is the colorized source code of this page, included as XML:</p>
  +      <table align="center" width="90%" bgcolor="#d0FFFF" border="1">
  +        <tr>
  +          <td>
  +            <util:include-source>
  +              <util:param name="uri">cocoon://samples/view-source?filename=<xsp-request:get-servlet-path/>.xsp&amp;cocoon-view=content</util:param>
  +            </util:include-source>
  +          </td>
  +        </tr>
  +      </table>
  +    </content>
     </page>
   </xsp:page>
  
  
  
  1.2       +28 -33    cocoon-2.1/src/webapp/samples/common/view-source.xsp
  
  Index: view-source.xsp
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/webapp/samples/common/view-source.xsp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- view-source.xsp	26 Mar 2003 21:21:46 -0000	1.1
  +++ view-source.xsp	24 Oct 2003 10:58:49 -0000	1.2
  @@ -2,21 +2,14 @@
   <!-- Written by Ricardo Rocha <rr...@plenix.org> -->
   <!-- Fixed for version 2.0 by Davanum Srinivas <di...@yahoo.com> -->
   
  -<!-- A quick'n'dirty XML colorizer -->
  -
  -
  -<xsp:page
  -          language="java"
  -          xmlns:xsp="http://apache.org/xsp"
  ->
  +<xsp:page language="java" xmlns:xsp="http://apache.org/xsp">
   
     <xsp:structure>
  -   <xsp:include>java.net.*</xsp:include>
  -   <xsp:include>org.w3c.dom.*</xsp:include>
  -   <xsp:include>org.apache.cocoon.xml.dom.DOMStreamer</xsp:include>
  -   <xsp:include>org.apache.cocoon.xml.dom.DOMBuilder</xsp:include>
  -   <xsp:include>org.apache.cocoon.components.parser.Parser</xsp:include>
  -   <xsp:include>org.apache.cocoon.components.url.URLFactory</xsp:include>
  +    <xsp:include>org.w3c.dom.*</xsp:include>
  +    <xsp:include>org.apache.cocoon.components.source.SourceUtil</xsp:include>
  +    <xsp:include>org.apache.cocoon.xml.dom.DOMStreamer</xsp:include>
  +    <xsp:include>org.apache.excalibur.xml.dom.DOMParser</xsp:include>
  +    <xsp:include>org.apache.excalibur.source.Source</xsp:include>
     </xsp:structure>
   
     <xsp:logic><![CDATA[
  @@ -33,11 +26,11 @@
       private static final String XSP_ELEMENT_COLOR = "green";
       private static final String XSP_TEXT_COLOR = "red";
   
  -    protected void colorize(Node node, Document factory, org.xml.sax.ContentHandler contentHandler) throws SAXException {
  +    protected void colorize(Node node, Document factory) throws SAXException {
         Element element = factory.createElement("pre");
         DocumentFragment fragment = factory.createDocumentFragment();
         element.appendChild(doColorize(node, factory, 0, TEXT_COLOR));
  -      DOMStreamer ds = new DOMStreamer (contentHandler);
  +      DOMStreamer ds = new DOMStreamer (this.contentHandler);
         ds.stream (element);
       }
   
  @@ -61,7 +54,7 @@
   
             result = factory.createElement("font");
             result.setAttribute("color", DELIMITER_COLOR);
  -          // I know the thing below is ugly, but man, nexted CDATA are a pain in the ass!
  +          // I know the thing below is ugly, but man, nested CDATA are a pain in the ass!
             result.appendChild(factory.createTextNode("]]]]>&gt;<![CDATA["));
             fragment.appendChild(result);
   
  @@ -175,7 +168,7 @@
   
             result.appendChild(
               factory.createTextNode(
  -              "<!-- " + node.getNodeValue() + " -->\n"
  +              "<!-- " + node.getNodeValue() + " -->"
               )
             );
   
  @@ -238,22 +231,18 @@
               <xsp:expr>filename</xsp:expr>
             </h3>
           
  -          Parser newParser = null;
  -          URLFactory factory = null;
  +          DOMParser parser = null;
  +          Source source = null;
   
             try {
  -              newParser = (Parser) this.manager.lookup(Parser.ROLE);
  -              factory = (URLFactory) this.manager.lookup(URLFactory.ROLE);
  -              Document document = newParser.newDocument();
  -
  -              DOMBuilder builder = new DOMBuilder(newParser);
  -              newParser.setContentHandler(builder);
  -              newParser.setLexicalHandler(builder);
  -              URL url = factory.getURL(filename);
  -              InputSource is = new InputSource(url.openStream());
  -              newParser.parse(is);
  +              parser = (DOMParser)manager.lookup(DOMParser.ROLE);
  +              Document outputDocument = parser.createDocument();
  +
  +              source = super.resolver.resolveURI("context://" + filename);
   
  -              this.colorize(builder.getDocument(), document, this.contentHandler);    
  +              Document sourceDocument = parser.parseDocument(SourceUtil.getInputSource(source));
  +
  +              this.colorize(sourceDocument, outputDocument);    
             } catch (SAXException e){
                 getLogger().debug("SAXException in colorize", e);
                 throw e;
  @@ -262,9 +251,16 @@
                 throw e;
             } catch (Exception e) {
                 getLogger().error("Could not include page", e);
  +              <p style="color: red; font-weight: bold;">
  +                Could not include page:
  +                <xsp:expr>e</xsp:expr>
  +              </p>
             } finally {
  -              this.manager.release((Component) factory);
  -              this.manager.release((Component) newParser);
  +              this.manager.release((Component) parser);
  +              if (source != null) {
  +                  super.resolver.release(source);
  +                  source = null;
  +              }
             }
           } else {
             <h3 style="color:navy; text-align: center">
  @@ -275,4 +271,3 @@
       </body>
     </html>
   </xsp:page>
  -