forrest-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From je...@apache.org
Subject cvs commit: xml-forrest/src/resources/library/xslt filterlinks-html.xsl linkutils.xsl filterlinks.xsl
Date Tue, 10 Dec 2002 11:56:20 GMT
jefft       2002/12/10 03:56:20

  Modified:    .        build.xml status.xml
               src/resources/conf sitemap.xmap
               src/resources/forrest-shbat forrest.build.xml
               src/resources/fresh-site/src/documentation/content/xdocs
                        sample.xml
               src/resources/library/xslt filterlinks.xsl
  Added:       src/resources/forrest-shbat/tasks/org/apache/forrest
                        UncopiedFileSelector.java
               src/resources/fresh-site/src/documentation/content hello.pdf
               src/resources/library/xslt filterlinks-html.xsl
                        linkutils.xsl
  Log:
  Add special handling of links that start with 'file:'.
  These links are:
   1) Not passed on to Cocoon (see filterlinks.xsl)
   2) The 'file:' prefix is stripped from the HTML (see filterlinks-html.xsl)
   3) All file: links encountered during crawling are recorded in a file,
   'unprocessed-files.txt' (see filterlinks.xsl and linkutils.xsl)
   4) After running Cocoon, forrest.build.xml copies all files listed in
   unprocessed-files.txt to build/site/ manually.  This is achieved with a custom
   selector, UncopiedFileSelector.java
  
  Revision  Changes    Path
  1.52      +25 -2     xml-forrest/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/xml-forrest/build.xml,v
  retrieving revision 1.51
  retrieving revision 1.52
  diff -u -r1.51 -r1.52
  --- build.xml	3 Dec 2002 11:44:46 -0000	1.51
  +++ build.xml	10 Dec 2002 11:56:20 -0000	1.52
  @@ -66,6 +66,7 @@
       <path id="classpath">
         <fileset dir="src/scratchpad/lib" includes="**/*.jar"/>
         <fileset dir="lib" includes="**/*.jar"/>
  +      <fileset dir="tools/ant/lib" includes="*.jar"/>
         <pathelement location="${tools.jar}"/>
       </path>
   
  @@ -330,8 +331,27 @@
     <!-- =================================================================== -->
     <!-- Make the shell-bat distribution                                     -->
     <!-- =================================================================== -->
  +
  +  <target name="compile-shbat" depends="init">
  +    <mkdir dir="${build.dir}/shbat/tasks-classes"/>
  +    <javac srcdir=   "src/resources/forrest-shbat/tasks"
  +      destdir=       "${build.dir}/shbat/tasks-classes"
  +      debug=         "${build.compiler.debug}"
  +      optimize=      "${build.compiler.optimize}"
  +      deprecation=   "${build.compiler.deprecation}"
  +      nowarn=        "${build.compiler.nowarn}"
  +      classpathref=  "classpath">
  +    </javac>
  +  </target>
  +
  +  <target name="jar-shbat" depends="compile-shbat">
  +    <jar destfile="${build.dir}/shbat/forrest-shbat-tasks.jar"
  +      basedir="${build.dir}/shbat/tasks-classes"/>
  +  </target>
  + 
  +
     <target name="dist-shbat" 
  -    depends="init, validate-config, fresh-site-zip, webapp-webinf, bare-context-dir" >
  +    depends="init, validate-config, fresh-site-zip, webapp-webinf, bare-context-dir, jar-shbat"
>
       <!-- TODO: decide on a better place to read/set this prop from/to -->
   
       <!-- fresh drop-off location for the distribution -->
  @@ -345,8 +365,11 @@
   
       <!-- copy the prepared and wrapper stuff for the distribution -->
       <copy todir="${dist-shbat.dir}">
  -      <fileset dir="./src/resources/forrest-shbat" />
  +      <fileset dir="./src/resources/forrest-shbat">
  +        <exclude name="tasks/**"/>
  +      </fileset>
       </copy>
  +    <copy file="${build.dir}/shbat/forrest-shbat-tasks.jar" todir="${dist-shbat.dir}/WEB-INF/lib"
/>
   
       <!-- copy licenses -->
       <copy todir="${dist-shbat.dir}/legal">
  
  
  
  1.78      +6 -0      xml-forrest/status.xml
  
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/xml-forrest/status.xml,v
  retrieving revision 1.77
  retrieving revision 1.78
  diff -u -r1.77 -r1.78
  --- status.xml	7 Dec 2002 17:30:00 -0000	1.77
  +++ status.xml	10 Dec 2002 11:56:20 -0000	1.78
  @@ -24,6 +24,12 @@
   
     <changes>
       <release version="0.3-dev" date="unreleased">
  +      <action dev="JT" type="update" context="shbat">
  +        Add the ability to link to files not generated by Cocoon, with a
  +        <code>file:</code> link prefix. Eg, a static file
  +        <code>src/documentation/content/report.pdf</code> can be linked to
with
  +        &lt;link href="file:report.pdf&gt;
  +      </action> 
         <action dev="NKB" type="update" context="skins">
           Added rss capability to changes generation.
         </action> 
  
  
  
  1.43      +6 -3      xml-forrest/src/resources/conf/sitemap.xmap
  
  Index: sitemap.xmap
  ===================================================================
  RCS file: /home/cvs/xml-forrest/src/resources/conf/sitemap.xmap,v
  retrieving revision 1.42
  retrieving revision 1.43
  diff -u -r1.42 -r1.43
  --- sitemap.xmap	7 Dec 2002 17:49:06 -0000	1.42
  +++ sitemap.xmap	10 Dec 2002 11:56:20 -0000	1.43
  @@ -122,15 +122,17 @@
      <map:serialize type="xml"/>
     </map:view>
   
  -  <map:view name="links" from-position="last">
  -   <map:transform src="library/xslt/filterlinks.xsl"/>
  +  <map:view name="links" from-label="links">
  +   <map:transform src="library/xslt/filterlinks.xsl">
  +    <map:parameter name="linkdir" value="{system-property:java.io.tmpdir}"/>
  +   </map:transform>
      <map:serialize type="links"/>
     </map:view>
    </map:views>
   
    <map:resources>
     <map:resource name="skinit">
  -   <map:transform src="skins/{forrest:skin}/xslt/html/{type}.xsl">
  +    <map:transform src="skins/{forrest:skin}/xslt/html/{type}.xsl" label="links">
        <map:parameter name="isfaq" value="{isfaq}"/>
        <map:parameter name="nopdf" value="{nopdf}"/>
        <map:parameter name="path" value="{path}"/>
  @@ -138,6 +140,7 @@
        <map:parameter name="config-file" value="../../../../skinconf.xml"/>
        -->
      </map:transform>
  +   <map:transform src="library/xslt/filterlinks-html.xsl"/>
      <map:serialize/>
     </map:resource>
   
  
  
  
  1.30      +24 -0     xml-forrest/src/resources/forrest-shbat/forrest.build.xml
  
  Index: forrest.build.xml
  ===================================================================
  RCS file: /home/cvs/xml-forrest/src/resources/forrest-shbat/forrest.build.xml,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- forrest.build.xml	1 Dec 2002 12:20:47 -0000	1.29
  +++ forrest.build.xml	10 Dec 2002 11:56:20 -0000	1.30
  @@ -564,6 +564,7 @@
         <arg value="${project.start-uri}"/>              <!-- starting page -->
         <arg value="-V" />                          <!-- be verbose -->
       </java>
  +    <antcall target="copy-files"/>
       <echo>
   ------------------------------
   Static site generated at:
  @@ -576,6 +577,27 @@
       </echo>
     </target>
   
  +  <target name="check-uncopied-files">
  +    <available property="uncopied-files" type="file" file="${java.io.tmpdir}/unprocessed-files.txt"/>
  +  </target>
  +
  +  <!-- ===============================================================
  +       Copies any files that Cocoon didn't crawl. These are written by a
  +       stylesheet to /tmp/unprocessed-files.txt during the Cocoon run, and must
  +       now be copied
  +       =============================================================== -->
  +  <target name="copy-files" if="uncopied-files" depends="check-uncopied-files, -prepare-classpath">
  +    <echo>Copying files not handled by Cocoon..</echo>
  +    <copy todir="${project.site-dir}">
  +      <fileset dir="${project.ctxt-dir}/content" includes="**/*">
  +        <custom classname="org.apache.forrest.UncopiedFileSelector"
  +          classpathref="forrest.cp">
  +          <param name="config" value="${java.io.tmpdir}/unprocessed-files.txt"/>
  +        </custom>
  +      </fileset>
  +    </copy>
  +    <delete file="${java.io.tmpdir}/unprocessed-files.txt"/>
  +  </target>
   
     <target name="project.webapp.defined" unless="project.webapp">
       <fail>
  @@ -585,6 +607,8 @@
         ------------------------------------------------
       </fail>
     </target>
  +
  +
   
     <!-- ===============================================================
          Builds a cocoon webapp for your project.
  
  
  
  1.1                  xml-forrest/src/resources/forrest-shbat/tasks/org/apache/forrest/UncopiedFileSelector.java
  
  Index: UncopiedFileSelector.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Ant", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.forrest;
  
  import org.apache.tools.ant.types.selectors.*;
  import java.io.*;
  import java.util.Set;
  import java.util.HashSet;
  import org.apache.tools.ant.Project;
  import org.apache.tools.ant.BuildException;
  import org.apache.tools.ant.types.Parameter;
  
  /**
   * Ant selector that selects files listed in an external text file.  
   * In the context of Forrest, the external text file lists "uncopied files"
   * from the Cocoon run, hence the name.
   *
   * @author Jeff Turner
   */
  public class UncopiedFileSelector extends BaseExtendSelector {
  
    public final static String CONFIG_KEY = "config";
  
    /** File listing files to copy. Typically /tmp/unprocessed-files.txt. */
    private String configFile = null;
    private boolean configRead = false;
    /** Processed list of files read from <code>configFile</code>. */
    private Set goodFiles = new HashSet();
  
  
    public UncopiedFileSelector() {
    }
  
    public String toString() {
      StringBuffer buf = new StringBuffer("{uncopiedfileselector config: ");
      buf.append(configFile);
      buf.append("}");
      return buf.toString();
    }
  
    public void setConfigFile(String conf) {
      this.configFile = conf;
    }
  
    /** Process the config file, creating a Set of file names */
    private void readConfig() throws BuildException {
      if (configRead) return;
  
      verifySettings();
      File confFile = new File(this.configFile);
      try {
        BufferedReader br = new BufferedReader(new FileReader(confFile));
        String line=null;
        while ( (line = br.readLine()) != null) {
          // Ignore odd lines.  Xalan has an annoying habit of writing XML
          // declarations in the middle of the file.
          if (! (line.charAt(0) == ' ' || line.charAt(0) == '<') ) {
            if (! goodFiles.contains(line)) {
              goodFiles.add(line);
            }
          }
        }
      } catch (FileNotFoundException e) {
        throw new BuildException("Couldn't find config file "+this.configFile);
      } catch (IOException ioe) {
        throw new BuildException("Error reading config file "+this.configFile);
      }
      configRead = true;
    }
  
    /**
     * When using this as a custom selector, this method will be called.
     * It translates each parameter into the appropriate setXXX() call.
     *
     * @param parameters the complete set of parameters for this selector
     */
    public void setParameters(Parameter[] parameters) {
      super.setParameters(parameters);
      if (parameters != null) {
        for (int i = 0; i < parameters.length; i++) {
          String paramname = parameters[i].getName();
          if (CONFIG_KEY.equalsIgnoreCase(paramname)) {
            setConfigFile(parameters[i].getValue());
          }
          else {
            setError("Invalid parameter " + paramname);
          }
        }
      }
    }
  
    /**
     * Checks to make sure all settings are kosher. In this case, it
     * means that the name attribute has been set.
     *
     */
    public void verifySettings() {
      if (configFile == null) {
        setError("The "+this.CONFIG_KEY+" attribute is required");
      }
    }
  
    /**
     * The heart of the matter. This is where the selector gets to decide
     * on the inclusion of a file in a particular fileset.  Here we just check if
     * the file is listed in <code>goodFiles</code>.
     *
     * @param basedir the base directory the scan is being done from
     * @param filename is the name of the file to check
     * @param file is a java.io.File object the selector can use
     * @return whether the file should be selected or not
     */
    public boolean isSelected(File basedir, String filename, File file) {
      validate();
      readConfig();
      return goodFiles.contains(filename);
    }
  }
  
  
  
  1.1                  xml-forrest/src/resources/fresh-site/src/documentation/content/hello.pdf
  
  	<<Binary file>>
  
  
  1.3       +9 -0      xml-forrest/src/resources/fresh-site/src/documentation/content/xdocs/sample.xml
  
  Index: sample.xml
  ===================================================================
  RCS file: /home/cvs/xml-forrest/src/resources/fresh-site/src/documentation/content/xdocs/sample.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- sample.xml	30 Oct 2002 15:15:35 -0000	1.2
  +++ sample.xml	10 Dec 2002 11:56:20 -0000	1.3
  @@ -50,6 +50,15 @@
              the new document in the same browser window.
             </dd> 
   
  +          <dt><code>&lt;link href="file:hello.pdf"&gt;</code></dt>

  +          <dd>Use the <code>file:</code> prefix to
  +            <link href="file:hello.pdf" title="Example of a document not
  +              generated by Cocoon">link</link>
  +            to an existing file not generated by Cocoon.
  +            <code>file:</code>-referenced files should be placed in
  +            <code>src/documentation/content</code>
  +          </dd> 
  +
             <dt><code>&lt;jump href="sample.html"&gt;</code></dt>

             <dd>Use this to
               <jump href="sample.html" title="Example of a document via jump">jump</jump>
  
  
  
  1.3       +23 -7     xml-forrest/src/resources/library/xslt/filterlinks.xsl
  
  Index: filterlinks.xsl
  ===================================================================
  RCS file: /home/cvs/xml-forrest/src/resources/library/xslt/filterlinks.xsl,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- filterlinks.xsl	7 Jun 2002 04:17:32 -0000	1.2
  +++ filterlinks.xsl	10 Dec 2002 11:56:20 -0000	1.3
  @@ -1,19 +1,35 @@
   <?xml version="1.0"?>
   
   <!--
  -This stylesheet filters all references to the javadocs
  -and the samples.
  +This stylesheet filters all references to the javadocs, the samples and any
  +protocols (file:, java:) that Cocoon shouldn't handle.  This stylesheet is
  +applied while rendering the 'links' View.
   -->
   <xsl:stylesheet
       xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
       version="1.0">
  +  <xsl:include href="linkutils.xsl"/>
  +
  +  <!-- Directory in which to write unprocessed-<protocol>s.txt files. Any
  +  protocol'ed link that is deliberately stripped before being passed to Cocoon
  +  should be recorded in a file. -->
  +  <xsl:param name="linkdir"/>
   
     <xsl:template match="@src|@href|@background">
  -    <xsl:if test="not(contains(.,'apidocs')) and not(starts-with(., 'samples/'))">
  -      <xsl:copy>
  -        <xsl:apply-templates select="."/>
  -      </xsl:copy>
  -    </xsl:if>
  +    <xsl:choose>
  +      <xsl:when test="not(contains(.,'apidocs')) and not(starts-with(.,
  +        'samples/')) and not(starts-with(., 'file:'))">
  +        <xsl:copy>
  +          <xsl:apply-templates select="."/>
  +        </xsl:copy>
  +      </xsl:when>
  +      <xsl:when test="starts-with(., 'file:')">
  +        <xsl:call-template name="record-link">
  +          <xsl:with-param name="href" select="." /> 
  +          <xsl:with-param name="linkdir" select="$linkdir" /> 
  +        </xsl:call-template>
  +      </xsl:when>
  +    </xsl:choose>
     </xsl:template>
   
     <!-- This is a hack which makes the javascript images work -->
  
  
  
  1.1                  xml-forrest/src/resources/library/xslt/filterlinks-html.xsl
  
  Index: filterlinks-html.xsl
  ===================================================================
  <?xml version="1.0"?>
  
  <!--
  This stylesheet strips the 'file:' prefix from HTML links.
  It should be applied after document2html.xsl.
  This stripping cannot be done in document2html.xsl, because the 'links' view is
  based on the unstripped document2html output.
  -->
  
  <xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
  
    <xsl:template match="@src|@href|@background">
      <xsl:choose>
        <xsl:when test="starts-with(., 'file:')">
          <xsl:attribute name="{name()}">
            <xsl:value-of select="substring(., 6)"/>
          </xsl:attribute>
        </xsl:when>
        <xsl:otherwise>
          <xsl:copy>
            <xsl:apply-templates select="."/>
          </xsl:copy>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:template>
  
    <xsl:template match="@*|node()">
     <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
     </xsl:copy>
    </xsl:template>
  
  
  </xsl:stylesheet>
  
  
  
  1.1                  xml-forrest/src/resources/library/xslt/linkutils.xsl
  
  Index: linkutils.xsl
  ===================================================================
  <!--
  Named templates related to link handling.
  
  Currently requires Xalan.  Yes, XSLT 2.0's xsl:redirect-document and Saxon's
  saxon:output are no good because they don't allow doc appending.  This current
  stylesheet-based method for recording protocol'ed links is therefore a
  temporary hack.
  -->
  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:redirect="http://xml.apache.org/xalan/redirect"
    xmlns:saxon="http://icl.com/saxon"
    extension-element-prefixes="redirect saxon">
  
    <xsl:template name="record-link">
      <xsl:param name="href" />
      <xsl:param name="linkdir" select="'.'"/>
      <xsl:variable name="protocol" select="substring-before($href, ':')"/>
      <xsl:if test="not($protocol = '' or $protocol='http' or $protocol='https')">
        <xsl:message>###  Protocol is <xsl:value-of select="$protocol"/></xsl:message>
        <xsl:variable name="filename" select="concat(concat(concat($linkdir, '/unprocessed-'),
$protocol), 's.txt')"/>
  
  <!--
  No good because there is no 'append' option :(
  
        <saxon:output href="{$filename}" method="text">
          <xsl:value-of select="substring-after($href, concat($protocol, ':'))"/>
          <xsl:text>
          </xsl:text>
          <xsl:fallback>
            <xsl:message>saxon:output not available!</xsl:message>
          </xsl:fallback>
        </saxon:output>
        -->
  
        <redirect:write file="{$filename}" append="true">
          <xsl:value-of select="substring-after($href, concat($protocol, ':'))"/>
          <xsl:text>
          </xsl:text>
          <!--
          <xsl:fallback>
            <xsl:message>Xalan's redirect:write not available!</xsl:message>
          </xsl:fallback>
          -->
        </redirect:write>
      </xsl:if>
    </xsl:template>
  
  <!--
  Uncomment this to test.
  Usage: saxon linkutils.xsl linkutils.xsl link=file:hello.pdf
  
  <xsl:param name="link" select="'file:hello.pdf'"/>
  <xsl:param name="linkdir" select="'.'"/>
  <xsl:template match="/">
    <xsl:message>
      link= <xsl:value-of select="$link"/>
      <xsl:call-template name="record-link">
        <xsl:with-param name="href" select="$link"/>
        <xsl:with-param name="linkdir" select="$linkdir"/>
      </xsl:call-template>
    </xsl:message>
  </xsl:template>
  -->
  
  
  </xsl:stylesheet>
  
  
  

Mime
View raw message