Return-Path: Delivered-To: apmail-xml-cocoon-cvs-archive@xml.apache.org Received: (qmail 28318 invoked by uid 500); 22 Nov 2001 15:46:24 -0000 Mailing-List: contact cocoon-cvs-help@xml.apache.org; run by ezmlm Precedence: bulk Reply-To: cocoon-dev@xml.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list cocoon-cvs@xml.apache.org Received: (qmail 28304 invoked by uid 500); 22 Nov 2001 15:46:24 -0000 Delivered-To: apmail-xml-cocoon2-cvs@apache.org Date: 22 Nov 2001 15:30:54 -0000 Message-ID: <20011122153054.11218.qmail@icarus.apache.org> From: cziegeler@apache.org To: xml-cocoon2-cvs@apache.org Subject: cvs commit: xml-cocoon2/src/org/apache/cocoon/serialization fop.sitemap X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N cziegeler 01/11/22 07:30:54 Modified: . build.xml Added: bin/anttasks SitemapTool.class bin/src SitemapTool.java src/org/apache/cocoon/generation tidy.sitemap src/org/apache/cocoon/serialization fop.sitemap Log: A new SitemapTool which replaces st.java. The SitemapTool is an ant task which can recursivly crawl through a directory tree and process all files with a given extension (I use the ending .sitemap). Each file can contain definitions which are then added to the sitemap, like: label:content|category:generators|componentName:html|componentClass:org.apache.cocoon.generation.HTMLGenerator With the use of the additional compilation (copying of java source code and .sitemap files) this makes the maintaining of the build system much easier. The next step will be to completly use this for all optional packages. Currently as a demonstration this is only done for tidy and fop. Revision Changes Path 1.98 +13 -41 xml-cocoon2/build.xml Index: build.xml =================================================================== RCS file: /home/cvs/xml-cocoon2/build.xml,v retrieving revision 1.97 retrieving revision 1.98 diff -u -r1.97 -r1.98 --- build.xml 2001/11/22 12:59:13 1.97 +++ build.xml 2001/11/22 15:30:54 1.98 @@ -140,8 +140,11 @@ + + + - - - - - - - - - - - - - - - - - - - - - - - - @@ -829,18 +810,6 @@ - - - - - - - - - - - - @@ -881,8 +850,11 @@ - - + + + 1.1 xml-cocoon2/bin/anttasks/SitemapTool.class <> 1.1 xml-cocoon2/bin/src/SitemapTool.java Index: SitemapTool.java =================================================================== /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * * ------------------------------------------------------------------------- * * This software is published under the terms of the Apache Software License * * version 1.1, a copy of which has been included with this distribution in * * the LICENSE file. * *****************************************************************************/ 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.*; /** * Add components to the sitemap * * @author Carsten Ziegeler cziegeler@apache.org */ public final class SitemapTool extends Task { private String sitemap; private String directory; private String label; private String mimeType; private String componentClass; private String category; private String componentName; private String configuration; private String extension; public void setSitemap(String sitemap) { this.sitemap = sitemap; } public void setDirectory(String directory) { this.directory = directory; } public void setExtension(String extension) { this.extension = extension; } public void setLabel(String label) { this.label = label; } public void setMimeType(String mimeType) { this.mimeType = mimeType; } public void setComponentClass(String componentClass) { this.componentClass = componentClass; } public void setCategory(String category) { this.category = category; } public void setComponentName(String componentName) { this.componentName = componentName; } public void setConfiguration(String configuration) { // optional this.configuration = configuration; } public void execute() throws BuildException { if (this.sitemap == null) { throw new BuildException("sitemap attribute is required", location); } if (this.directory != null && this.extension == null) { throw new BuildException("extension attribute is required", location); } if (this.directory == null && this.extension != null) { throw new BuildException("directory attribute is required", location); } try { if (this.directory != null && this.extension != null) { // process recursive this.process(new File(this.directory), this.extension); } else { if (this.category == null) { throw new BuildException("category attribute is required", location); } if (this.componentName == null) { throw new BuildException("componentName attribute is required", location); } if (this.componentClass == null) { throw new BuildException("componentClass attribute is required", location); } this.add(this.category, this.componentName, this.componentClass, this.configuration, this.label, this.mimeType); } } catch (IOException ioe) { throw new BuildException("IOException: " + ioe); } } /** * Scan recursive */ private void process(final File directory, final String extension) throws IOException, BuildException { final File[] files = directory.listFiles(); for(int i = 0; i < files.length; i++) { if (files[i].isDirectory() == true) { this.process(files[i], extension); } else { if (files[i].getName().endsWith("."+extension)) { System.out.println("Reading: " + files[i].getAbsolutePath()); final String data = this.load(files[i].getAbsolutePath()); final StringTokenizer st = new StringTokenizer(data); while (st.hasMoreElements() == true) { final String line = (String)st.nextElement(); final StringTokenizer prop = new StringTokenizer(line, "|"); String category = null; String componentName = null; String className = null; String configuration = null; String label = null; String mimeType = null; while (prop.hasMoreElements() == true) { final String property = (String)prop.nextElement(); final int pos = property.indexOf(":"); final String propName = property.substring(0, pos); final String propVal = property.substring(pos+1); if (propName.equals("category")) category = propVal; else if (propName.equals("componentName")) componentName = propVal; else if (propName.equals("componentClass")) className = propVal; else if (propName.equals("configuration")) configuration = propVal; else if (propName.equals("label")) label = propVal; else if (propName.equals("mimeType")) mimeType = propVal; else throw new BuildException("Unknown property " + propName + " in file " + files[i].getAbsolutePath()); } if (category == null) { throw new BuildException("category property is required in file " + files[i].getAbsolutePath(), location); } if (componentName == null) { throw new BuildException("componentName property is required in file " + files[i].getAbsolutePath(), location); } if (className == null) { throw new BuildException("componentClass property is required in file " + files[i].getAbsolutePath(), location); } this.add(category, componentName, className, configuration, label, mimeType); } } } } } /** * Add entry to sitemap */ private void add(String category, String componentName, String className, String configuration, String label, String mimeType) throws IOException { final String data = load( this.sitemap ); final String searchString = new StringBuffer( "" ).toString(); final int pos = data.indexOf( searchString ); int categoryStartPos = data.indexOf(new StringBuffer( "" ).toString() ); if ( categoryStartPos == -1 ) categoryStartPos = data.indexOf(new StringBuffer( " 0) { buffer.append( " mime-type=\"" ).append( mimeType ).append( "\"" ); } if ( null != label && label.length() > 0) { buffer.append( " label=\"" ).append( label ).append( "\"" ); } if ( null != configuration ) { buffer.append( ">\n" ).append( configuration ).append( "\n" ) .append( "\n" ); } else { buffer.append( "/>\n" ); } buffer.append( data.substring( pos ) ).toString(); this.save( this.sitemap, buffer.toString() ); } } } /** * Load the sitemap */ public String load( String filename ) throws IOException { FileInputStream fis; fis = new FileInputStream( filename ); int available; byte[] data = null; byte[] tempData; byte[] copyData; do { available = 1024; tempData = new byte[available]; available = fis.read( tempData, 0, available ); if ( available > 0 ) { copyData = new byte[( data == null ? 0 : data.length ) + available]; if ( data != null ) { System.arraycopy( data, 0, copyData, 0, data.length ); } System.arraycopy( tempData, 0, copyData, ( data == null ? 0 : data.length ), available ); data = copyData; } } while ( available > 0 ); fis.close(); return ( data != null ? new String( data ) : "" ); } /** * Save the sitemap */ public void save( String filename, String data ) throws IOException { FileWriter fw = new FileWriter( filename ); fw.write( data ); fw.close(); } } 1.1 xml-cocoon2/src/org/apache/cocoon/generation/tidy.sitemap Index: tidy.sitemap =================================================================== label:content|category:generators|componentName:html|componentClass:org.apache.cocoon.generation.HTMLGenerator 1.1 xml-cocoon2/src/org/apache/cocoon/serialization/fop.sitemap Index: fop.sitemap =================================================================== mimeType:application/pdf|category:serializers|componentName:fo2pdf|componentClass:org.apache.cocoon.serialization.FOPSerializer mimeType:application/postscript|category:serializers|componentName:fo2ps|componentClass:org.apache.cocoon.serialization.FOPSerializer mimeType:application/vnd.hp-PCL|category:serializers|componentName:fo2pcl|componentClass:org.apache.cocoon.serialization.FOPSerializer ---------------------------------------------------------------------- In case of troubles, e-mail: webmaster@xml.apache.org To unsubscribe, e-mail: cocoon-cvs-unsubscribe@xml.apache.org For additional commands, e-mail: cocoon-cvs-help@xml.apache.org