cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rica...@locus.apache.org
Subject cvs commit: xml-cocoon/src/org/apache/cocoon/processor/xsp/library/java util.xsl
Date Sun, 09 Jan 2000 02:47:27 GMT
ricardo     00/01/08 18:47:27

  Modified:    src/org/apache/cocoon/processor/xsp/library/java util.xsl
  Log:
  Moved inlined logic to XSPUtil. Extended parameter passing. Cleaned up tag names
  
  Revision  Changes    Path
  1.7       +72 -66    xml-cocoon/src/org/apache/cocoon/processor/xsp/library/java/util.xsl
  
  Index: util.xsl
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/processor/xsp/library/java/util.xsl,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- util.xsl	2000/01/08 07:20:07	1.6
  +++ util.xsl	2000/01/09 02:47:27	1.7
  @@ -70,80 +70,88 @@
           <xsp:include>java.text.SimpleDateFormat</xsp:include>
         </xsp:structure>
   
  -      <xsp:logic>
  -        /* Util Class Level */
  -
  -        private static int count = 0;
  -        private static synchronized int getCount() {
  -          return ++count;
  -        }
  -        private static synchronized int getSessionCount(HttpSession session) {
  -          Integer integer = (Integer) session.getValue("util.counter");
  -          if (integer == null) {
  -            integer = new Integer(0);
  -          }
  -          int cnt = integer.intValue() + 1;
  -          session.putValue("util.counter", new Integer(cnt));
  -          return cnt;
  -        }
  -        private static String formatDate(Date date, String pattern) {
  -          if (pattern == null || pattern.length() == 0) {
  -            pattern = "yyyy/MM/dd hh:mm:ss aa";
  -          }
  -          return (new SimpleDateFormat(pattern)).format(date);
  -        }
  -      </xsp:logic>
  -
         <xsl:apply-templates/>
       </xsp:page>
     </xsl:template>
   
  -  <xsl:template match="util:embed">
  -    <xsl:variable name="uri">
  +  <!-- Include URL contents as DOM -->
  +  <xsl:template match="util:include-uri">
  +    <xsl:variable name="href">
         <xsl:choose>
  -        <xsl:when test="@uri">"<xsl:value-of select="@uri"/>"</xsl:when>
  -        <xsl:when test="util:uri">
  +        <xsl:when test="@href">"<xsl:value-of select="@href"/>"</xsl:when>
  +        <xsl:when test="util:href">
             <xsl:call-template name="get-nested-content">
  -            <xsl:with-param name="content" select="util:uri"/>
  +            <xsl:with-param name="content" select="util:href"/>
             </xsl:call-template>
           </xsl:when>
         </xsl:choose>
       </xsl:variable>
   
  +    <!-- This should be an <xsp:expr> yielding Node... -->
       <xsp:logic> {
  -      String embedURI = String.valueOf(<xsl:copy-of select="$uri"/>);
  +      String __name = String.valueOf(<xsl:copy-of select="$href"/>);
   
         try {
  -        URL url = new URL(embedURI);
  -        InputSource is = new InputSource(url.openStream());
  -        is.setSystemId(url.toExternalForm());
  +        URL __url = new URL(__name);
  +        InputSource __is = new InputSource(__url.openStream());
  +        __is.setSystemId(__url.toString());
   
           xspCurrentNode.appendChild(
             XSPUtil.cloneNode(
  -            this.xspParser.parse(is).getDocumentElement(),
  +            this.xspParser.parse(__is).getDocumentElement(),
               document
             )
           );
         } catch (Exception e) {
           xspCurrentNode.appendChild(
             document.createTextNode(
  -            "{" +
  -              "Unable to embed: " +
  -              embedURI +
  -            "}"
  +            "{Unable to include: '" + __name + "'}"
             )
           );
         }
       } </xsp:logic>
     </xsl:template>
   
  +  <!-- Include file contents as DOM -->
  +  <xsl:template match="util:include-file">
  +    <xsl:variable name="name">
  +      <xsl:choose>
  +        <xsl:when test="@name">"<xsl:value-of select="@name"/>"</xsl:when>
  +        <xsl:when test="util:name">
  +          <xsl:call-template name="get-nested-content">
  +            <xsl:with-param name="content" select="util:name"/>
  +          </xsl:call-template>
  +        </xsl:when>
  +      </xsl:choose>
  +    </xsl:variable>
  +
  +    <xsp:logic>
  +      xspCurrentNode.appendChild(
  +        XSPUtil.cloneNode(
  +          this.xspParser.parse(
  +            new InputSource(
  +              new FileReader(
  +                XSPUtil.relativeFilename(
  +                  <xsl:copy-of select="$name"/>,
  +                  request
  +                )
  +              )
  +            )
  +          ).getDocumentElement(),
  +          document
  +        )
  +      );
  +    </xsp:logic>
  +  </xsl:template>
  +
  +  <!-- Include file contents as text -->
     <xsl:template match="util:get-file-contents">
  -    <xsl:variable name="filename">
  +    <xsl:variable name="name">
         <xsl:choose>
  -        <xsl:when test="@filename">"<xsl:value-of select="@filename"/>"</xsl:when>
  -        <xsl:when test="util:filename">
  +        <xsl:when test="@name">"<xsl:value-of select="@name"/>"</xsl:when>
  +        <xsl:when test="util:name">
             <xsl:call-template name="get-nested-content">
  -            <xsl:with-param name="content" select="util:filename"/>
  +            <xsl:with-param name="content" select="util:name"/>
             </xsl:call-template>
           </xsl:when>
         </xsl:choose>
  @@ -152,50 +160,48 @@
       <xsp:expr>
         XSPUtil.getFileContents(
   	XSPUtil.relativeFilename(
  -          String.valueOf(<xsl:copy-of select="$filename"/>),
  +          String.valueOf(<xsl:copy-of select="$name"/>),
   	  request
   	)
         )
       </xsp:expr>
     </xsl:template>
   
  +
  +  <!-- Counters -->
     <xsl:template match="util:counter">
       <xsl:choose>
         <xsl:when test="@scope = 'session'">
  -        <xsp:expr>getSessionCount(session)</xsp:expr>
  +        <xsp:expr>XSPUtil.getSessionCount(session)</xsp:expr>
         </xsl:when>
         <xsl:otherwise>
  -        <xsp:expr>getCount()</xsp:expr>
  +        <xsp:expr>XSPUtil.getCount()</xsp:expr>
         </xsl:otherwise>
       </xsl:choose>
     </xsl:template>
   
  +  <!-- Date -->
     <xsl:template match="util:time">
  +    <xsl:variable name="format">
  +      <xsl:choose>
  +        <xsl:when test="@format">"<xsl:value-of select="@format"/>"</xsl:when>
  +        <xsl:when test="util:format">
  +          <xsl:call-template name="get-nested-content">
  +            <xsl:with-param name="content" select="util:format"/>
  +          </xsl:call-template>
  +        </xsl:when>
  +      </xsl:choose>
  +    </xsl:variable>
  +
       <xsp:expr>
  -      formatDate(new Date(), "<xsl:value-of select="@format"/>")
  +      XSPUtil.formatDate(
  +        new Date(),
  +	String.valueOf(<xsl:copy-of select="$format"/>).trim()
  +      )
       </xsp:expr>
     </xsl:template>
  -
  -  <xsl:template match="util:include">
  -    <xsp:logic>
  -      xspCurrentNode.appendChild(
  -        XSPUtil.cloneNode(
  -          this.xspParser.parse(
  -            new InputSource(
  -              new FileReader(
  -                XSPUtil.relativeFilename(
  -                  "<xsl:value-of select="@file"/>",
  -                  request
  -                )
  -              )
  -            )
  -          ).getDocumentElement(),
  -          document
  -        )
  -      );
  -    </xsp:logic>
  -  </xsl:template>
   
  +  <!-- Standard Templates -->
     <xsl:template name="get-nested-content">
       <xsl:param name="content"/>
       <xsl:choose>
  
  
  

Mime
View raw message