Has anybody taken a look at this?  At least I've seen no replies...

On Sun, 2002-04-21 at 14:19, Ville Skytt� wrote:

> Attached is a patch and a CSS file for making JXR's DirectoryIndexer
> output valid XHTML 1.0 Strict and use CSS for layout.
> 
> I could not include jxr.css in the patch, since I don't have cvs write
> access and this could not "cvs add" it.  It should be added to
> src/dvsl/xdocs.
> 
> I also have a similar patch for CodeTransform in progress, I'll post it
> shortly.
> 
> Executive summary of the patch:
> - Added (optional) cssFile attribute to the jxr task.
>   If not present, no file will be copied nor any <link rel="stylesheet">
>   tag will be created.
> - Deprecated old constructors in DirectoryIndexer in favor of the new
>   one that has the css_file parameter.
> - Moved the [parent directory] link to be the first item in the list of 
>   dirs and files instead of showing it separately.
> - Miscellaneous cleanups and doc updates.
> 
> Cheers,
> -- 
> Ville Skytt�
> [EMAIL PROTECTED]
> ----
> 

> Index: src/templates/build/build-docs.xml
> ===================================================================
> RCS file: /home/cvspublic/jakarta-turbine-maven/src/templates/build/build-docs.xml,v
> retrieving revision 1.54
> diff -a -u -r1.54 build-docs.xml
> --- src/templates/build/build-docs.xml        20 Apr 2002 05:19:48 -0000      1.54
> +++ src/templates/build/build-docs.xml        21 Apr 2002 10:59:59 -0000
> @@ -71,10 +71,11 @@
>        destDir="${jxr.destdir}"
>        javadocDir="${javadoc.destdir}"
>        imageFolder="${maven.home}/images/folder.gif"
> -      imageFile="${maven.home}/images/file.gif">
> +      imageFile="${maven.home}/images/file.gif"
> +      cssFile="${maven.home}/stylesheets/jxr.css">
>      </jxr>
>  
> -    <!-- The last two parameters don't really matter but the
> +    <!-- The last three parameters don't really matter but the
>           task craps out if they aren't there. -->
>  
>    </target>
> Index: src/java/org/apache/maven/Jxr.java
> ===================================================================
> RCS file: /home/cvspublic/jakarta-turbine-maven/src/java/org/apache/maven/Jxr.java,v
> retrieving revision 1.3
> diff -a -u -r1.3 Jxr.java
> --- src/java/org/apache/maven/Jxr.java        19 Apr 2002 04:35:18 -0000      1.3
> +++ src/java/org/apache/maven/Jxr.java        21 Apr 2002 11:00:00 -0000
> @@ -107,6 +107,11 @@
>       */
>      private String imageFile;
>  
> +    /**
> +     * The location of the jxr.css
> +     */
> +    private String cssFile;
> +
>  
>      /**
>       * Starts the cross-referencing and indexing.
> @@ -155,7 +160,7 @@
>          try
>          {
>              new DirectoryIndexer(destDir, destDir, imageFolder, imageFile,
> -                                 DirectoryIndexer.MODE_JAVA);
> +                                 cssFile, DirectoryIndexer.MODE_JAVA);
>          }
>          catch (IOException ioe)
>          {
> @@ -225,7 +230,9 @@
>      }
>      
>      /**
> -     * Sets the imageFile attribute of the JxrTask object
> +     * Sets the location of the file image.
> +     *
> +     * @param imageFile the file image location
>       */
>      public void setImageFile(String imageFile)
>      {
> @@ -233,11 +240,23 @@
>      }
>  
>      /**
> -     * Sets the imageFolder attribute of the JxrTask object
> +     * Sets the location of the folder image.
> +     *
> +     * @param imageFolder the folder image location
>       */
>      public void setImageFolder(String imageFolder)
>      {
>          this.imageFolder = imageFolder;
> +    }
> +
> +    /**
> +     * Sets the location of the CSS file.
> +     *
> +     * @param cssFile the css file location
> +     */
> +    public void setCssFile(String cssFile)
> +    {
> +        this.cssFile = cssFile;
>      }
>  
>      /**
> Index: src/java/org/apache/maven/jxr/DirectoryIndexer.java
> ===================================================================
> RCS file: 
>/home/cvspublic/jakarta-turbine-maven/src/java/org/apache/maven/jxr/DirectoryIndexer.java,v
> retrieving revision 1.10
> diff -a -u -r1.10 DirectoryIndexer.java
> --- src/java/org/apache/maven/jxr/DirectoryIndexer.java       19 Apr 2002 04:35:35 
>-0000      1.10
> +++ src/java/org/apache/maven/jxr/DirectoryIndexer.java       21 Apr 2002 11:00:01 
>-0000
> @@ -79,47 +79,55 @@
>  {
>  
>      /**
> -     * Description of the Field
> +     * Constant for full mode.
>       */
>      public final static int MODE_FULL = 1;
>      
>      /**
> -     * Description of the Field
> +     * Constant for Java mode.
>       */
>      public final static int MODE_JAVA = 2;
>      
>      /**
> -     * Description of the Field
> +     * Constant for default (Java) mode.
>       */
>      public final static int MODE_DEFAULT = MODE_JAVA;
>  
>      /**
> -     * Description of the Field
> +     * Name of the index HTML file.
>       */
>      public final static String INDEX = "index.html";
>  
>      /**
> -     * Description of the Field
> +     * Name of the folder image file.
>       */
> -    public final static String IMAGE_FOLDER = "./folder.gif";
> +    public final static String IMAGE_FOLDER = "folder.gif";
>      
>      /**
> -     * Description of the Field
> +     * Name of the file image file.
>       */
> -    
> -    public final static String IMAGE_FILE = "./file.gif";
> +    public final static String IMAGE_FILE = "file.gif";
> +
>      /**
> -     * Description of the Field
> +     * Width of the file and folder image files, in pixels.
>       */
> -    
>      public final static int IMAGE_WIDTH = 15;
>  
> +    /**
> +     * Path to the CSS file.
> +     */
> +    private static final String CSS_FILE = "jxr.css";
> +
>      private File directory = null;
>  
>      private String image_folder = "";
>  
>      private String image_file = "";
>  
> +    private String css_file = "";
> +
> +    private static final String FSEP = System.getProperty("file.separator");
> +
>      /**
>       * Optionally specify the global root for a DirectoryIndexer.
>       */
> @@ -135,11 +143,7 @@
>  
>  
>      /**
> -     * @see DirectoryIndexer
> -     * @param directory
> -     * @param image_folder
> -     * @param image_file
> -     * @exception IOException
> +     * @deprecated Use <code>{@link 
>#DirectoryIndexer(String,String,String,String,String,int) 
>DirectoryIndexer}(null,directory,image_folder,image_file,null,DirectoryIndexer.MODE_JAVA)</code>
> instead.
>       */
>      public DirectoryIndexer(String directory,
>                              String image_folder,
> @@ -147,18 +151,12 @@
>          throws IOException
>      {
>  
> -        this(directory, image_folder, image_file, MODE_JAVA);
> +        this(null, directory, image_folder, image_file, null, MODE_JAVA);
>  
>      }
>  
>      /**
> -     * Create a given DirectoryIndexer with the given dir, images, etc
> -     *
> -     * @param directory
> -     * @param image_folder
> -     * @param image_file
> -     * @param mode
> -     * @exception IOException
> +     * @deprecated Use <code>{@link 
>#DirectoryIndexer(String,String,String,String,String,int) 
>DirectoryIndexer}(null,directory,image_folder,image_file,null,mode)</code> instead.
>       */
>      public DirectoryIndexer(String directory,
>                              String image_folder,
> @@ -167,55 +165,75 @@
>          throws IOException
>      {
>  
> -        this(null, directory, image_folder, image_file, mode);
> +        this(null, directory, image_folder, image_file, null, mode);
>  
>      }
>  
>      /**
> -     * Constructor for the DirectoryIndexer object
> +     * @deprecated Use <code>{@link 
>#DirectoryIndexer(String,String,String,String,String,int) 
>DirectoryIndexer}(root,directory,image_folder,image_file,null,mode)</code> instead.
> +     */
> +    public DirectoryIndexer(String root,
> +                            String directory,
> +                            String image_folder,
> +                            String image_file,
> +                            int mode)
> +        throws IOException
> +    {
> +        this(root, directory, image_folder, image_file, null, mode);
> +    }
> +
> +
> +    /**
> +     * Constructor for the DirectoryIndexer object.
>       *
>       * @param root
>       * @param directory
> -     * @param image_folder
> -     * @param image_file
> +     * @param image_folder path to the folder image
> +     * @param image_file path to the file image
> +     * @param css_file path to the CSS file
>       * @param mode
> -     * @exception IOException
> +     * @throws IOException
>       */
>      public DirectoryIndexer(String root,
>                              String directory,
>                              String image_folder,
>                              String image_file,
> +                            String css_file,
>                              int mode)
>          throws IOException
>      {
>  
>          this.root = root;
>  
> -        this.directory = new File(new File(directory).getCanonicalPath());
> +        this.directory    = new File(new File(directory).getCanonicalPath());
>          this.image_folder = image_folder;
> -        this.image_file = image_file;
> +        this.image_file   = image_file;
> +        this.css_file     = css_file;
>  
>          // copy image files to the root directory only, or
>          // to each subdirectory if no root is specified
>          if ((root != null &&
> -            new File(root).getCanonicalPath()
> +             new File(root).getCanonicalPath()
>               .equals(this.directory.getCanonicalPath())) ||
>              root == null)
>          {
> -            copy(image_folder,
> -                 directory + System.getProperty("file.separator") + 
> -                 DirectoryIndexer.IMAGE_FOLDER);
> +            copy(image_folder, directory + FSEP + IMAGE_FOLDER);
>          
> -            copy(image_file,
> -                 directory + System.getProperty("file.separator") + 
> -                 DirectoryIndexer.IMAGE_FILE);
> +            copy(image_file,   directory + FSEP + IMAGE_FILE);
> +
> +            if (css_file != null) {
> +                copy(css_file, directory + FSEP + CSS_FILE);
> +            }
>          }
>  
>          this.process();
>      }
>  
> +
>      /**
> -     * Process the directory
> +     * Process the directory.
> +     *
> +     * @throws IOException
>       */
>      private final void process()
>          throws IOException
> @@ -226,24 +244,19 @@
>              throw new IOException("Not a directory");
>          }
>  
> -        String index = directory.getAbsolutePath() +
> -            System.getProperty("file.separator") +
> -            INDEX;
> +        String index = directory.getAbsolutePath() + FSEP + INDEX;
>  
>          PrintWriter out = new PrintWriter(new FileOutputStream(index));
>  
> -        //write the dirs first...
> -
> -        out.println("<html>");
> -        out.println("<body bgcolor=\"white\">");
> +        String dir        = this.getDirectory();
> +        String title      = dir;
> +        StringBuffer pkgs = null;
>  
>          //if the mode is MODE_JAVA then provide a package header for this dir.
>          if (this.getMode() == MODE_JAVA &&
>              this.getRoot() != null)
>          {
>  
> -            String dir = this.getDirectory();
> -
>              String root = this.getRoot();
>  
>              int start = dir.indexOf(root) + root.length() + 1;
> @@ -253,50 +266,80 @@
>                  end != -1 &&
>                  start < end)
>              {
> +
> +                pkgs = new StringBuffer();
>                  rootLink.append("../");
>                  
>                  String pkg = dir.substring(start, end);
> +                StringTokenizer toke = new StringTokenizer(pkg, FSEP);
> +                StringBuffer spkg = new StringBuffer();
>  
> -                out.print("<br><p><b>Package:  ");
> -                StringTokenizer toke = new StringTokenizer(pkg, 
>System.getProperty("file.separator"));
>                  while (toke.hasMoreElements())
>                  {
>                      String subpkg = (String) toke.nextElement();
>                      if (toke.hasMoreTokens())
>                      {
> -                        out.print("<a href=\"");
> +                        pkgs.append("<a href=\"");
>                          rootLink.append("../");
>  
> +                        if (spkg.length() != 0) spkg.append('.');
> +                        spkg.append(subpkg);
> +
>                          for (int i = 0; i < toke.countTokens(); i++)
>                          {
> -                            out.print("../");
> +                            pkgs.append("../");
>                          }
> -                        out.print(INDEX + "\">" + subpkg + "</a>.");
> +                        pkgs.append(INDEX + "\" ")
> +                            .append("title=\"").append("Package ")
> +                            .append(spkg).append("\">").append(subpkg)
> +                            .append("</a>.");
>                      }
>                      else
>                      {
> -                        out.print(subpkg);
> +                        pkgs.append(subpkg);
>                      }
>                  }
>  
> -                pkg = Strings.replace(pkg, System.getProperty("file.separator"), 
>".");
> -
> -                out.println("</b></p>");
> -
> +                title = Strings.replace(pkg, FSEP, ".");
>              }
>  
>          }
> -        
> -        out.println("<a href=\"../" + INDEX + "\">[parent]</a>");
> -        out.println("<hr>");
> +
> +        out.println("<!DOCTYPE html PUBLIC " +
> +                    "\"-//W3C//DTD XHTML 1.0 Strict//EN\" " +
> +                    "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\";>");
> +        out.println("<html xmlns=\"http://www.w3.org/1999/xhtml\"; " +
> +                    "xml:lang=\"en\">");
> +        out.println("<head>");
> +        out.print("<title>");
> +        out.print(title);
> +        out.println("</title>");
> +        if (css_file != null) {
> +            out.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"" +
> +                        rootLink + DirectoryIndexer.CSS_FILE + "\" />");
> +        }
> +        out.println("<meta name=\"Generator\" content=\"" +
> +                    JXR.NOTICE + "\" />");
> +        out.println("</head>");
> +        out.println("<body>");
> +
> +        if (pkgs != null) {
> +            out.print("<p><b>Package: ");
> +            out.print(pkgs);
> +            out.println("</b></p>");
> +        }
> +
> +        out.println("<hr />");
>          out.println("<table width=\"100%\">");
>  
>          out.println("<tr>");
> -        out.println("<td><b>Name</b></td>");
> -        out.println("<td><b>Size</b></td>");
> -        out.println("<td><b>Last Modified</b></td>");
> +        out.println("<th>Name</th>");
> +        out.println("<th>Size (in bytes)</th>");
> +        out.println("<th>Last Modified</th>");
>          out.println("</tr>");
>  
> +        out.println(getItem(new File("..")));
> +
>          String[] items;
>  
>          items = this.getDirs();
> @@ -308,10 +351,11 @@
>  
>              out.println(getItem(new File(directory)));
>              new DirectoryIndexer(this.getRoot(),
> -                directory,
> -                image_folder,
> -                image_file,
> -                this.getMode());
> +                                 directory,
> +                                 image_folder,
> +                                 image_file,
> +                                 css_file,
> +                                 this.getMode());
>  
>          }
>  
> @@ -323,8 +367,8 @@
>          }
>  
>          out.println("</table>");
> -        out.println("<hr>");
> -        out.println("<center>" + JXR.NOTICE + "</center>");
> +        out.println("<hr />");
> +        out.println("<div class=\"footer\">" + JXR.NOTICE + "</div>");
>          out.println("</body>");
>          out.println("</html>");
>  
> @@ -334,27 +378,33 @@
>      }
>  
>      /**
> -     * Make an href for a file
> +     * Make an href for a file.
> +     *
> +     * @param item the file
> +     * @return
>       */
>      private final String getItem(File item)
>      {
>  
> -        String image = IMAGE_FILE;
> -        String href = item.getName();
> -        String name = item.getName();
> +        String image  = IMAGE_FILE;
> +        String href   = item.getName();
> +        String name   = item.getName();
> +        String alt    = "";
>  
>          if (item.isDirectory())
>          {
> -
> -            href = item.getName() + "/" + INDEX;
> -
> +            href  = item.getName() + "/" + INDEX;
>              image = rootLink + IMAGE_FOLDER;
> +            // &nbsp; for nice layout in Lynx (same length as [file])
> +            alt   = "[dir]&nbsp;";
> +            if ("..".equals(name)) {
> +                name = "[parent&nbsp;directory]";
> +            }
>          }
>  
> -        //potentially rip off.html links on names
> +        // potentially rip off.html links on names
>          if (item.isFile())
>          {
> -
>              int start = 0;
>              int end = item.getName().indexOf(".html");
>  
> @@ -364,18 +414,22 @@
>              }
>  
>              image = rootLink + IMAGE_FILE;
> +            alt   = "[file]";
>          }
>  
> -        //"<td width=\"" + IMAGE_WIDTH + "\"><img src=\"" + image + "\" 
>border=\"0\"></td>" +
> -        return "<tr valign=\"middle\">" +
> -            "<td valign=\"middle\" NOWRAP><img src=\"" + image + "\" 
>valign=\"middle\" border=\"0\">&nbsp;<a href=\"" + href + "\">" + name + "</a></td>" +
> -            "<td valign=\"middle\" NOWRAP>" + item.length() + " (in bytes) </td>" +
> -            "<td valign=\"middle\" NOWRAP>" + 
>DateFormat.getDateInstance().format(new Date(item.lastModified())) + "</td>" +
> -            "</tr>";
> +        //"<td width=\"" + IMAGE_WIDTH + "\"><img src=\"" + image + "\" /></td>" +
> +        return "<tr><td><img src=\"" + image + "\" alt=\"" + alt +
> +            "\" />&nbsp;<a href=\"" + href + "\">" + name + "</a></td>" +
> +            "<td>" + item.length() + "</td><td>" +
> +            DateFormat.getDateInstance().format(new Date(item.lastModified()))+
> +            "</td></tr>";
>      }
>  
>      /**
> -     * Get the directories
> +     * Get the directories.
> +     *
> +     * @return
> +     * @throws IOException
>       */
>      private final String[] getDirs()
>          throws IOException
> @@ -388,9 +442,7 @@
>          for (int i = 0; i < list.length; ++i)
>          {
>  
> -            String item = directory.getAbsolutePath() +
> -                System.getProperty("file.separator") +
> -                list[i];
> +            String item = directory.getAbsolutePath() + FSEP + list[i];
>  
>              if (new File(item).isDirectory())
>              {
> @@ -406,7 +458,10 @@
>      }
>  
>      /**
> -     * Get the files
> +     * Get the files.
> +     *
> +     * @return
> +     * @throws IOException
>       */
>      private final String[] getFiles()
>          throws IOException
> @@ -418,9 +473,7 @@
>          for (int i = 0; i < list.length; ++i)
>          {
>  
> -            String item = directory.getAbsolutePath() +
> -                System.getProperty("file.separator") +
> -                list[i];
> +            String item = directory.getAbsolutePath() + FSEP + list[i];
>  
>              //don't process the index file
>              if (list[i].equals(INDEX))
> @@ -440,9 +493,10 @@
>  
>              }
>              else if (this.getMode() == MODE_DEFAULT &&
> -                filename.equals(INDEX) == false &&
> -                filename.equals(new File(IMAGE_FOLDER).getName()) == false &&
> -                filename.equals(new File(IMAGE_FILE).getName()) == false &&
> +                ! filename.equals(INDEX) &&
> +                ! filename.equals(new File(IMAGE_FOLDER).getName()) &&
> +                ! filename.equals(new File(IMAGE_FILE).getName()) &&
> +                ! filename.equals(new File(CSS_FILE).getName()) &&
>                  new File(item).isFile())
>              {
>  
> @@ -460,7 +514,11 @@
>  
>  
>      /**
> -     * Copy one file to another file
> +     * Copy one file to another file.
> +     *
> +     * @param source path of the source file
> +     * @param dest path of the destination file
> +     * @throws IOException if the copying fails
>       */
>      public void copy(String source, String dest)
>          throws IOException
> @@ -484,10 +542,12 @@
>      }
>  
>      /**
> -     * Return the mode that DirectoryIndexer is operating in
> +     * Return the mode that DirectoryIndexer is operating in.
>       *
> -     * @see MODE_DEFAULT
> -     * @see MODE_JAVA
> +     * @see #MODE_DEFAULT
> +     * @see #MODE_JAVA
> +     * @see #MODE_FULL
> +     * @return the mode
>       */
>      public int getMode()
>      {
> @@ -496,6 +556,8 @@
>  
>      /**
>       * Get the root dir for directory indexing.
> +     *
> +     * @return the root dir
>       */
>      public String getRoot()
>      {
> @@ -503,7 +565,9 @@
>      }
>  
>      /**
> -     * Get the directory
> +     * Get the directory.
> +     *
> +     * @return the directory
>       */
>      public String getDirectory()
>      {
> ----
> 

> body, * {
>   background-color: white;
> }
> 
> th, td {
>   text-align: left;
>   white-space: nowrap;
> }
> 
> th {
>   font-weight: bold;
> }
> 
> tr, th, td {
>   vertical-align: middle;
> }
> 
> img {
>   border: none;
>   vertical-align: middle;
> }
> 
> .footer {
>   text-align: center;
> }

-- 
Ville Skytt�
[EMAIL PROTECTED]

Reply via email to