cziegeler 01/11/23 01:26:56 Modified: bin/anttasks SitemapTool.class bin/src SitemapTool.java Log: Minor cosmetics to the SitemapTool Revision Changes Path 1.3 +20 -20 xml-cocoon2/bin/anttasks/SitemapTool.class <<Binary file>> 1.3 +34 -21 xml-cocoon2/bin/src/SitemapTool.java Index: SitemapTool.java =================================================================== RCS file: /home/cvs/xml-cocoon2/bin/src/SitemapTool.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- SitemapTool.java 2001/11/22 15:55:21 1.2 +++ SitemapTool.java 2001/11/23 09:26:56 1.3 @@ -7,7 +7,6 @@ *****************************************************************************/ import java.io.*; import java.util.*; -import java.util.zip.*; import org.apache.tools.ant.*; import org.apache.tools.ant.taskdefs.*; import org.apache.tools.ant.types.*; @@ -15,7 +14,8 @@ /** * Add components to the sitemap * - * @author Carsten Ziegeler <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> + * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> + * @version CVS $Revision: 1.3 $ $Date: 2001/11/23 09:26:56 $ */ public final class SitemapTool extends Task { @@ -50,7 +50,7 @@ try { // process recursive - this.process(new File(this.directory), this.extension); + this.process(new File(this.directory), this.extension, this.sitemap); } catch (IOException ioe) { throw new BuildException("IOException: " + ioe); } @@ -59,19 +59,28 @@ /** * Scan recursive */ - private void process(final File directory, - final String extension) + private void process(final File directoryFile, + final String ext, + final String sitemapLocation) throws IOException, BuildException { - final File[] files = directory.listFiles(); + + final File[] files = directoryFile.listFiles(); + for(int i = 0; i < files.length; i++) { + if (files[i].isDirectory() == true) { - this.process(files[i], extension); + this.process(files[i], ext, sitemapLocation); } else { - if (files[i].getName().endsWith("."+extension)) { + + if (files[i].getName().endsWith("."+ext) == true) { System.out.println("Reading: " + files[i].getAbsolutePath()); final String data = this.load(files[i].getAbsolutePath()); + + // separate the data by lines final StringTokenizer st = new StringTokenizer(data); while (st.hasMoreElements() == true) { + + // now get the properties of a line. These are separated by a "|" final String line = (String)st.nextElement(); final StringTokenizer prop = new StringTokenizer(line, "|"); String category = null; @@ -93,6 +102,8 @@ else if (propName.equals("mimeType")) mimeType = propVal; else throw new BuildException("Unknown property " + propName + " in file " + files[i].getAbsolutePath()); } + + // Test for required values if (category == null) { throw new BuildException("category property is required in file " + files[i].getAbsolutePath(), location); } @@ -102,7 +113,9 @@ if (className == null) { throw new BuildException("componentClass property is required in file " + files[i].getAbsolutePath(), location); } - this.add(category, + + this.add(sitemapLocation, + category, componentName, className, configuration, @@ -117,14 +130,15 @@ /** * Add entry to sitemap */ - private void add(String category, - String componentName, - String className, - String configuration, - String label, - String mimeType) + private void add(final String sitemapLocation, + final String category, + final String componentName, + final String className, + final String configuration, + final String label, + final String mimeType) throws IOException { - final String data = load( this.sitemap ); + final String data = load( sitemapLocation ); final String searchString = new StringBuffer( "</map:" ) .append( category ) @@ -164,18 +178,17 @@ buffer.append( "/>\n" ); } buffer.append( data.substring( pos ) ).toString(); - this.save( this.sitemap, buffer.toString() ); + this.save( sitemapLocation, buffer.toString() ); } } } /** - * Load the sitemap + * Load a file and return the content as a string. */ public String load( String filename ) - throws IOException - { + throws IOException { FileInputStream fis; fis = new FileInputStream( filename ); @@ -205,7 +218,7 @@ } /** - * Save the sitemap + * Save the string to a file */ public void save( String filename, String data ) throws IOException
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]