cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stef...@hyperreal.org
Subject cvs commit: xml-cocoon/samples/xsp sample.xml sample.xsl snoop.xml view-source.xml page.xml README
Date Sat, 20 Nov 1999 01:18:44 GMT
stefano     99/11/19 17:18:44

  Modified:    samples/xsp page.xml
  Added:       samples/xsp sample.xml sample.xsl snoop.xml view-source.xml
  Removed:     samples/xsp README
  Log:
  Added other XSP examples now that XSP is on its way
  
  Revision  Changes    Path
  1.2       +3 -4      xml-cocoon/samples/xsp/page.xml
  
  Index: page.xml
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/samples/xsp/page.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- page.xml	1999/11/09 01:51:35	1.1
  +++ page.xml	1999/11/20 01:18:38	1.2
  @@ -3,19 +3,18 @@
   <?cocoon-process type="xslt"?>
   
   <page>
  - <title>First Page</title>
  + <title>First XSP Page</title>
    <author>
     <name>Stefano Mazzocchi</name>
     <address>stefano@apache.org</address>
    </author>
  - <version>$Id: page.xml,v 1.1 1999/11/09 01:51:35 stefano Exp $</version>
  + <version>$Id: page.xml,v 1.2 1999/11/20 01:18:38 stefano Exp $</version>
   
    <p>Hi, I'm the <em>first XSP page ever</em>.</p>
    
    <p>This page is an example of usage for XSP technology which is being 
       designed to add dynamic XML capabilities to the Cocoon publishing 
  -    framework. <em>Note:</em> Cocoon will not be able to work with XSP pages
  -    until its second generation, starting from Cocoon 2.0</p>
  +    framework.</p>
       
    <p>In this page, the content is automatically generated by translating this
       template page into some source code (Java in this case) and then executed
  
  
  
  1.1                  xml-cocoon/samples/xsp/sample.xml
  
  Index: sample.xml
  ===================================================================
  <?xml version="1.0"?>
  
  <?cocoon-process type="xsp"?>
  
  <?cocoon-process type="xslt"?>
  <?xml-stylesheet href="sample.xsl" type="text/xsl"?>
  
  <xsp:page
    language="java"
    xmlns:util="http://www.plenix.com/xsp/util"
    xmlns:xsp="http://apache.org/DTD/XSP/Layer1"
  >
  
    <page>
     <title>A Simple XSP Page</title>
  
     <p>
      Hi, I've been hit <util:counter/> times.
     </p>
  
     <p>
       <a href="view-source.xml?filename=sample.xml">Source Code</a>
     </p>
    </page>
  </xsp:page>
  
  
  
  1.1                  xml-cocoon/samples/xsp/sample.xsl
  
  Index: sample.xsl
  ===================================================================
  <?xml version="1.0"?>
  
  <xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0">
  
    <xsl:template match="/">
      <xsl:apply-templates/>
    </xsl:template>
  
    <xsl:template match="page">
      <html>
        <head>
          <title><xsl:value-of select="title"/></title>
        </head>
        <body>
          <h3 style="color: navy; text-align: center">
  	  <xsl:value-of select="title"/>
  	</h3>
  	<xsl:apply-templates/>
        </body>
      </html>
    </xsl:template>
  
    <xsl:template match="*|@*|text()">
      <xsl:copy>
        <xsl:apply-templates select="*|@*|text()"/>
      </xsl:copy>
    </xsl:template>
  
  </xsl:stylesheet>
  
  
  
  1.1                  xml-cocoon/samples/xsp/snoop.xml
  
  Index: snoop.xml
  ===================================================================
  <?xml version="1.0"?>
  
  <?cocoon-process type="xsp"?>
  
  <?cocoon-process type="xslt"?>
  <?xml-stylesheet href="sample.xsl" type="text/xsl"?>
  
  <xsp:page
    language="java"
    xmlns:xsp="http://apache.org/DTD/XSP/Layer1"
  >
  
    <page>
      <title>
        Snoop XSP Page
      </title>
  
  
      <ul>
        <li>
          <p>Parameter values (try your own!)</p>
      
          <table border="1" align="center">
            <tr>
              <th>Name</th>
              <th>Value(s)</th>
            </tr>
      
            <xsp:logic>
              Enumeration enum = request.getParameterNames();
              while (enum.hasMoreElements()) {
                String parameterName = (String) enum.nextElement();
                String[] parameterValues =
  	        request.getParameterValues(parameterName);
      
                <xsp:content>
                  <tr>
                    <td valign="top">
                      <xsp:expr>parameterName</xsp:expr>
                    </td>
      
                    <td>
                    <xsp:logic>
                      for (int i = 0; i &lt; parameterValues.length; i++) {
                        <xsp:content>
                          <xsp:expr>parameterValues[i]</xsp:expr>
                          <br/>
                        </xsp:content>
                      }
                    </xsp:logic>
                    </td>
                  </tr>
                </xsp:content>
              }
            </xsp:logic>
          </table>
        </li>
  
        <li>
          <p>Request Attributes:</p>
  
          <table border="1" align="center">
            <tr>
              <td>Protocol</td>
              <td><xsp:expr>request.getProtocol()</xsp:expr></td>
            </tr>
            <tr>
              <td>Scheme</td>
              <td><xsp:expr>request.getScheme()</xsp:expr></td>
            </tr>
            <tr>
              <td>Server Name</td>
              <td><xsp:expr>request.getServerName()</xsp:expr></td>
            </tr>
            <tr>
              <td>Server Port</td>
              <td><xsp:expr>request.getServerPort()</xsp:expr></td>
            </tr>
            <tr>
              <td>Remote Address</td>
              <td><xsp:expr>request.getRemoteAddr()</xsp:expr></td>
            </tr>
            <tr>
              <td>Remote Host</td>
              <td><xsp:expr>request.getRemoteHost()</xsp:expr>&#160;</td>
            </tr>
            <tr>
              <td>Character Encoding</td>
              <td><xsp:expr>request.getCharacterEncoding()</xsp:expr>&#160;</td>
            </tr>
            <tr>
              <td>Content Length</td>
              <td><xsp:expr>request.getContentLength()</xsp:expr>&#160;</td>
            </tr>
            <tr>
              <td>Content Type</td>
              <td><xsp:expr>request.getContentType()</xsp:expr>&#160;</td>
            </tr>
            <tr>
              <td>Servlet Path</td>
              <td><xsp:expr>request.getServletPath()</xsp:expr>&#160;</td>
            </tr>
            <tr>
              <td>Request URI</td>
              <td><xsp:expr>request.getRequestURI()</xsp:expr>&#160;</td>
            </tr>
            <tr>
              <td>Path Translated</td>
              <td><xsp:expr>request.getPathTranslated()</xsp:expr>&#160;</td>
            </tr>
            <tr>
              <td>Path Info</td>
              <td><xsp:expr>request.getPathInfo()</xsp:expr>&#160;</td>
            </tr>
          </table>
  	<br/>
        </li>
      </ul>
  
      <p>
        <a href="view-source.xml?filename=snoop.xml">Source Code</a>
      </p>
  
    </page>
  </xsp:page>
  
  
  
  1.1                  xml-cocoon/samples/xsp/view-source.xml
  
  Index: view-source.xml
  ===================================================================
  <?xml version="1.0"?>
  
  <?cocoon-process type="xsp"?>
  
  <xsp:page
    language="java"
    xmlns:xsp="http://apache.org/DTD/XSP/Layer1"
  >
    <!-- A quick'n'dirty XML colorizer -->
    <xsp:logic>
      private static final String ATTR_NAME_COLOR = "brown";
      private static final String ATTR_VALUE_COLOR = "magenta";
      private static final String COMMENT_COLOR = "gray";
      private static final String DELIMITER_COLOR = "green";
      private static final String ELEMENT_COLOR = "darkBrown";
      private static final String ENTITY_REF_COLOR = "navy";
      private static final String PI_DATA_COLOR = "lightBlue";
      private static final String TEXT_COLOR = "black";
      private static final String CUSTOM_ELEMENT_COLOR = "purple";
      private static final String XSL_ELEMENT_COLOR = "navy";
      private static final String XSP_ELEMENT_COLOR = "red";
      private static final String XSP_TEXT_COLOR = "blue";
  
      protected Element colorize(Node node, Document factory) {
        Element element = factory.createElement("pre");
        DocumentFragment fragment = factory.createDocumentFragment();
  
        element.appendChild(doColorize(node, factory, 0));
        return element;
      }
  
      protected static DocumentFragment
        doColorize(Node node, Document factory, int level)
      {
        Element result = null;
        DocumentFragment fragment = factory.createDocumentFragment();
  
        switch (node.getNodeType()) {
          case Node.CDATA_SECTION_NODE:
            result = factory.createElement("font");
            result.setAttribute("color", DELIMITER_COLOR);
            result.appendChild(factory.createTextNode("&lt;"));
            fragment.appendChild(result);
  
            result = factory.createElement("font");
            result.setAttribute("color", ELEMENT_COLOR);
            result.appendChild(factory.createTextNode("![CDATA["));
            fragment.appendChild(result);
  
            result = factory.createElement("font");
            result.setAttribute("color", ATTR_VALUE_COLOR);
            result.appendChild(factory.createTextNode(node.getNodeValue()));
            fragment.appendChild(result);
  
  
            result = factory.createElement("font");
            result.setAttribute("color", ELEMENT_COLOR);
            result.appendChild(factory.createTextNode("]]"));
            fragment.appendChild(result);
  
            result = factory.createElement("font");
            result.setAttribute("color", DELIMITER_COLOR);
            result.appendChild(factory.createTextNode("&lt;"));
            fragment.appendChild(result);
  
            break;
          case Node.ELEMENT_NODE: {
            Element element = (Element) node;
    
            result = factory.createElement("font");
            result.setAttribute("color", DELIMITER_COLOR);
            result.appendChild(factory.createTextNode("&lt;"));
            fragment.appendChild(result);
  
            String tagColor = ELEMENT_COLOR;
            String tagName = element.getTagName();
  
            if (tagName.startsWith("xsp:")) {
              tagColor = XSP_ELEMENT_COLOR;
            }
            else if (tagName.startsWith("xsl:")) {
              tagColor = XSL_ELEMENT_COLOR;
            }
            else if (tagName.indexOf(':') &gt;= 0) {
              tagColor = CUSTOM_ELEMENT_COLOR;
            }
  
            result = factory.createElement("font");
            result.setAttribute("color", tagColor);
            result.appendChild(factory.createTextNode(tagName));
            fragment.appendChild(result);
  
            NamedNodeMap attributes = element.getAttributes();
            int attributeCount = attributes.getLength();
    
            for (int i = 0; i &lt; attributeCount; i++) {
              Attr attribute = (Attr) attributes.item(i);
    
              result = factory.createElement("font");
              result.setAttribute("color", ATTR_NAME_COLOR);
              result.appendChild(
                factory.createTextNode(" " + attribute.getName() + "=")
              );
              fragment.appendChild(result);
  
              result = factory.createElement("font");
              result.setAttribute("color", ATTR_VALUE_COLOR);
              result.appendChild(
                factory.createTextNode("\"" + attribute.getValue() + "\"")
              );
              fragment.appendChild(result);
            }
    
            NodeList nodeList = element.getChildNodes();
            int childCount = nodeList.getLength();
    
            result = factory.createElement("font");
            result.setAttribute("color", DELIMITER_COLOR);
            result.appendChild(factory.createTextNode((childCount == 0 ? "/" : "") + "&gt;"));
            fragment.appendChild(result);
  
            String textColor = TEXT_COLOR;
            if (tagName.startsWith("xsp:")) {
              textColor = XSP_TEXT_COLOR;
            }
            result = factory.createElement("font");
            result.setAttribute("color", textColor);
  
            for (int i = 0; i &lt; childCount; i++) {
              result.appendChild(
                doColorize(nodeList.item(i), factory, level + 1)
              );
            }
            fragment.appendChild(result);
  
            if (childCount &gt; 0) {
              result = factory.createElement("font");
              result.setAttribute("color", DELIMITER_COLOR);
              result.appendChild(factory.createTextNode("&lt;/"));
              fragment.appendChild(result);
  
              result = factory.createElement("font");
              result.setAttribute("color", tagColor);
              result.appendChild(factory.createTextNode(tagName));
              fragment.appendChild(result);
  
              result = factory.createElement("font");
              result.setAttribute("color", DELIMITER_COLOR);
              result.appendChild(factory.createTextNode("&gt;"));
              fragment.appendChild(result);
            }
    
            break;
          }
          case Node.DOCUMENT_NODE:
          case Node.DOCUMENT_FRAGMENT_NODE: {
            NodeList nodeList = node.getChildNodes();
            int childCount = nodeList.getLength();
    
            for (int i = 0; i &lt; childCount; i++) {
              fragment.appendChild(
                doColorize(nodeList.item(i), factory, level + 1)
              );
            }
    
            break;
          }
          case Node.COMMENT_NODE:
            result = factory.createElement("font");
            result.setAttribute("color", COMMENT_COLOR);
  
            result.appendChild(
              factory.createTextNode(
                "&lt;!-- " +
                node.getNodeValue() +
                " --&gt;"
              )
            );
  
            fragment.appendChild(result);
  
            break;
          case Node.PROCESSING_INSTRUCTION_NODE:
            ProcessingInstruction pi = (ProcessingInstruction) node;
  
            result = factory.createElement("font");
            result.setAttribute("color", DELIMITER_COLOR);
            result.appendChild(factory.createTextNode("&lt;?"));
            fragment.appendChild(result);
    
            result = factory.createElement("font");
            result.setAttribute("color", ATTR_NAME_COLOR);
            result.appendChild(factory.createTextNode(pi.getTarget()));
            fragment.appendChild(result);
    
            result = factory.createElement("font");
            result.setAttribute("color", PI_DATA_COLOR);
            result.appendChild(factory.createTextNode(" " + pi.getData()));
            fragment.appendChild(result);
    
            result = factory.createElement("font");
            result.setAttribute("color", DELIMITER_COLOR);
            result.appendChild(factory.createTextNode("?&gt;\n"));
            fragment.appendChild(result);
  
            break;
          case Node.ENTITY_REFERENCE_NODE:
            result = factory.createElement("font");
            result.setAttribute("color", ENTITY_REF_COLOR);
            result.appendChild(factory.createTextNode("&lt;" + node.getNodeValue() + ";"));
            fragment.appendChild(result);
  
            break;
          case Node.TEXT_NODE:
            fragment.appendChild(factory.createTextNode(node.getNodeValue()));
            break;
          default:
            break;
        }
  
        return fragment;
      }
    </xsp:logic>
  
    <html>
      <head>
        <title>Source Code</title>
      </head>
  
      <!-- Let's do it -->
      <body>
        <xsp:logic>
          String filename = request.getParameter("filename");
        </xsp:logic>
    
        <h3 style="color:navy; text-align: center">
          <xsp:expr>filename</xsp:expr>
        </h3>
    
        <xsp:expr>
          this.colorize(
              this.xspParser.parse (
                new FileReader(XSPUtil.relativeFilename(filename, request)),
                filename
              ),
            document
          )
        </xsp:expr>
        <!-- That's all folks -->
      </body>
    </html>
  </xsp:page>
  
  
  

Mime
View raw message