Return-Path: Delivered-To: apmail-xml-cocoon-cvs-archive@xml.apache.org Received: (qmail 44874 invoked by uid 500); 9 Mar 2002 06:27:18 -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 44865 invoked by uid 500); 9 Mar 2002 06:27:17 -0000 Delivered-To: apmail-xml-cocoon2-cvs@apache.org Date: 9 Mar 2002 06:27:16 -0000 Message-ID: <20020309062716.18503.qmail@icarus.apache.org> From: vgritsenko@apache.org To: xml-cocoon2-cvs@apache.org Subject: cvs commit: xml-cocoon2/tools/src XConfToolTask.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N vgritsenko 02/03/08 22:27:16 Modified: . build.xml src/java/org/apache/cocoon/components/deli deli.xconf src/java/org/apache/cocoon/components/hsqldb hsqldb.xconf src/java/org/apache/cocoon/components/resolver resolver.xconf src/java/org/apache/cocoon/components/search lucene.xconf src/java/org/apache/cocoon/components/store jisp.xconf src/java/org/apache/cocoon/generation xmldb.xconf src/webapp cocoon.xconf sitemap.xmap tools/src XConfToolTask.java Added: src/java/org/apache/cocoon/components/search lucene.xpipe src/java/org/apache/cocoon/components/source xmldb.xpipe src/java/org/apache/cocoon/generation bsf.xmap php.xmap servlet.xmap tidy.xmap velocity.xmap xindice.xmap xmldb-generators.xpipe src/java/org/apache/cocoon/reading servlet.xmap src/java/org/apache/cocoon/samples/parentcm naming.xmap naming.xpipe src/java/org/apache/cocoon/transformation naming.xmap xt.xmap Removed: src/java/org/apache/cocoon/generation bsf.sitemap php.sitemap servlet.sitemap tidy.sitemap velocity.sitemap xindice.pipeline xindice.sitemap xmldb.pipeline src/java/org/apache/cocoon/reading servlet.sitemap src/java/org/apache/cocoon/samples/parentcm naming.pipeline naming.sitemap src/java/org/apache/cocoon/serialization HSSFSerializer.xconf fop.sitemap jfor.sitemap svg.sitemap src/java/org/apache/cocoon/transformation naming.sitemap xt.sitemap Log: rewrite xconf tool Revision Changes Path 1.180 +71 -85 xml-cocoon2/build.xml Index: build.xml =================================================================== RCS file: /home/cvs/xml-cocoon2/build.xml,v retrieving revision 1.179 retrieving revision 1.180 diff -u -r1.179 -r1.180 --- build.xml 7 Mar 2002 15:49:55 -0000 1.179 +++ build.xml 9 Mar 2002 06:27:15 -0000 1.180 @@ -385,10 +385,6 @@ property="servlet.present" classname="javax.servlet.http.HttpServlet"/> - - @@ -742,43 +738,43 @@ - + - - + + - - - + + + - - + + - - + + - + - + - - - + + + - - + + @@ -786,12 +782,12 @@ - + - + @@ -799,38 +795,33 @@ - - - - - - - - - - - - - + + + + + + + + + - - + + - - + - + - + - - + + @@ -881,7 +872,6 @@ - @@ -904,7 +894,6 @@ - @@ -945,7 +934,6 @@ - @@ -971,15 +959,17 @@ - + + + + - - + + - - + @@ -1028,7 +1018,6 @@ - @@ -1043,6 +1032,12 @@ + + + + + + @@ -1050,6 +1045,7 @@ + @@ -1071,52 +1067,46 @@ - - - - - - - - + extension="xmap" + configuration="${build.war}/sitemap.xmap"/> + + + - - - - + extension="xmap" + configuration="${build.war}/sitemap.xmap"/> + + + @@ -1156,14 +1146,6 @@ - - - - - - - - @@ -1193,6 +1175,10 @@ + + + 1.8 +6 -0 xml-cocoon2/src/java/org/apache/cocoon/components/deli/deli.xconf Index: deli.xconf =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/deli/deli.xconf,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- deli.xconf 7 Mar 2002 14:05:30 -0000 1.7 +++ deli.xconf 9 Mar 2002 06:27:15 -0000 1.8 @@ -1,6 +1,12 @@ + + + + + 1.2 +6 -1 xml-cocoon2/src/java/org/apache/cocoon/components/hsqldb/hsqldb.xconf Index: hsqldb.xconf =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/hsqldb/hsqldb.xconf,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- hsqldb.xconf 16 Jan 2002 10:39:22 -0000 1.1 +++ hsqldb.xconf 9 Mar 2002 06:27:15 -0000 1.2 @@ -1,4 +1,8 @@ - 1.1 xml-cocoon2/src/java/org/apache/cocoon/components/source/xmldb.xpipe Index: xmldb.xpipe =================================================================== 1.2 +6 -0 xml-cocoon2/src/java/org/apache/cocoon/components/store/jisp.xconf Index: jisp.xconf =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/store/jisp.xconf,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- jisp.xconf 7 Feb 2002 04:17:46 -0000 1.1 +++ jisp.xconf 9 Mar 2002 06:27:15 -0000 1.2 @@ -1,3 +1,8 @@ + + + + + 1.4 +4 -9 xml-cocoon2/src/java/org/apache/cocoon/generation/xmldb.xconf Index: xmldb.xconf =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/generation/xmldb.xconf,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- xmldb.xconf 23 Feb 2002 16:47:39 -0000 1.3 +++ xmldb.xconf 9 Mar 2002 06:27:15 -0000 1.4 @@ -1,11 +1,6 @@ - - - - + + + @@ -13,4 +8,4 @@ - + 1.1 xml-cocoon2/src/java/org/apache/cocoon/generation/bsf.xmap Index: bsf.xmap =================================================================== 1.1 xml-cocoon2/src/java/org/apache/cocoon/generation/php.xmap Index: php.xmap =================================================================== 1.1 xml-cocoon2/src/java/org/apache/cocoon/generation/servlet.xmap Index: servlet.xmap =================================================================== 1.1 xml-cocoon2/src/java/org/apache/cocoon/generation/tidy.xmap Index: tidy.xmap =================================================================== 1.1 xml-cocoon2/src/java/org/apache/cocoon/generation/velocity.xmap Index: velocity.xmap =================================================================== 1.1 xml-cocoon2/src/java/org/apache/cocoon/generation/xindice.xmap Index: xindice.xmap =================================================================== org.apache.xindice.client.xmldb.DatabaseImpl xmldb:xindice:///db/ org.apache.xindice.client.xmldb.DatabaseImpl xmldb:xindice:///db/ 1.1 xml-cocoon2/src/java/org/apache/cocoon/generation/xmldb-generators.xpipe Index: xmldb-generators.xpipe =================================================================== 1.1 xml-cocoon2/src/java/org/apache/cocoon/reading/servlet.xmap Index: servlet.xmap =================================================================== 1.1 xml-cocoon2/src/java/org/apache/cocoon/samples/parentcm/naming.xmap Index: naming.xmap =================================================================== 1.1 xml-cocoon2/src/java/org/apache/cocoon/samples/parentcm/naming.xpipe Index: naming.xpipe =================================================================== 1.1 xml-cocoon2/src/java/org/apache/cocoon/transformation/naming.xmap Index: naming.xmap =================================================================== 1.1 xml-cocoon2/src/java/org/apache/cocoon/transformation/xt.xmap Index: xt.xmap =================================================================== 1.36 +11 -1 xml-cocoon2/src/webapp/cocoon.xconf Index: cocoon.xconf =================================================================== RCS file: /home/cvs/xml-cocoon2/src/webapp/cocoon.xconf,v retrieving revision 1.35 retrieving revision 1.36 diff -u -r1.35 -r1.36 --- cocoon.xconf 5 Mar 2002 13:11:54 -0000 1.35 +++ cocoon.xconf 9 Mar 2002 06:27:16 -0000 1.36 @@ -160,6 +160,17 @@ + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + - - - - - + + + + + - - - - - - - - - - - + + + - - - + Since pipelines work on a first match basis, the above wins the + request although the match below would match as well. + --> + + + + + + - - - - - + + + + + + @@ -542,10 +509,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + 1.2 +94 -91 xml-cocoon2/tools/src/XConfToolTask.java Index: XConfToolTask.java =================================================================== RCS file: /home/cvs/xml-cocoon2/tools/src/XConfToolTask.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- XConfToolTask.java 25 Jan 2002 02:31:53 -0000 1.1 +++ XConfToolTask.java 9 Mar 2002 06:27:16 -0000 1.2 @@ -6,18 +6,38 @@ * the LICENSE file. * *****************************************************************************/ -import java.io.*; -import java.util.*; -import org.apache.tools.ant.*; -import org.apache.tools.ant.taskdefs.*; -import org.apache.tools.ant.types.*; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Task; +import org.apache.xpath.XPathAPI; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; +import org.w3c.dom.Node; +import org.xml.sax.SAXException; + +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.sax.SAXTransformerFactory; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.Transformer; +import javax.xml.transform.Source; +import javax.xml.transform.Result; +import javax.xml.transform.TransformerException; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; /** - * Add components to the cocoon.xconf - * This is only a ugly first shot + * Add components to the cocoon.xconf. + * This is an ugly second shot. * * @author Carsten Ziegeler - * @version CVS $Revision: 1.1 $ $Date: 2002/01/25 02:31:53 $ + * @author Vadim Gritsenko + * @version CVS $Revision: 1.2 $ $Date: 2002/03/09 06:27:16 $ */ public final class XConfToolTask extends Task { @@ -39,10 +59,10 @@ } public void execute() throws BuildException { + if (this.configuration == null) { throw new BuildException("configuration attribute is required", location); } - if (this.extension == null) { throw new BuildException("extension attribute is required", location); } @@ -51,8 +71,28 @@ } try { + final DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + final Transformer transformer = TransformerFactory.newInstance().newTransformer(); + final String file = new File(this.configuration).getCanonicalPath(); + + // load xml + System.out.println("Reading: " + file); + final Document configuration = builder.parse(file); + // process recursive - this.process(new File(this.directory), this.extension, this.configuration); + if (process(builder, configuration, new File(this.directory), this.extension)) { + // save xml + System.out.println("Writing: " + file); + transformer.transform(new DOMSource(configuration), new StreamResult(file)); + } else { + System.out.println("No Changes: " + file); + } + } catch (TransformerException e) { + throw new BuildException("TransformerException: " + e); + } catch (SAXException e) { + throw new BuildException("SAXException: " + e); + } catch (ParserConfigurationException e) { + throw new BuildException("ParserConfigurationException: " + e); } catch (IOException ioe) { throw new BuildException("IOException: " + ioe); } @@ -61,98 +101,61 @@ /** * Scan recursive */ - private void process(final File directoryFile, - final String ext, - final String configurationLocation) - throws IOException, BuildException { + private boolean process(final DocumentBuilder builder, + final Document configuration, + final File directoryFile, + final String ext) + throws IOException, BuildException, ParserConfigurationException, TransformerException, SAXException { + boolean hasChanged = false; final File[] files = directoryFile.listFiles(); - for(int i = 0; i < files.length; i++) { - - if (files[i].isDirectory() == true) { - this.process(files[i], ext, configurationLocation); - } else { - - if (files[i].getName().endsWith("."+ext) == true) { - System.out.println("Reading: " + files[i].getAbsolutePath()); - final String newComponent = this.load(files[i].getAbsolutePath()); - - this.add(configurationLocation, - newComponent); - } - } - } - } - - /** - * Add entry to sitemap - */ - private void add(final String configurationLocation, - final String newComponent) - throws IOException { - final String data = load( configurationLocation ); - - // first search if component already present: - if ( data.indexOf( newComponent ) == -1 ) { - int pos = data.indexOf( "", pos); - - if (pos != -1) { - StringBuffer buffer = new StringBuffer( data.substring( 0, pos+1 ) ) - .append( "\n\n" ) - .append( newComponent ) - .append( data.substring( pos+1 ) ); - this.save( configurationLocation, buffer.toString() ); + if (files[i].isDirectory()) { + hasChanged |= process(builder, configuration, files[i], ext); + } else if (files[i].getName().endsWith("." + ext)) { + String file = files[i].getCanonicalPath(); + try { + hasChanged |= add(configuration, builder.parse(file), file); + } catch (SAXException e) { + System.out.println("Ignoring: " + file + "\n(not a valid XML)"); } } } + return hasChanged; } /** - * Load a file and return the content as a string. + * Add entry to cocoon.xconf */ - 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 string to a file - */ - public void save( String filename, String data ) - throws IOException + private boolean add(final Document configuration, + final Document component, + String file) + throws TransformerException, IOException { - FileWriter fw = new FileWriter( filename ); - fw.write( data ); - fw.close(); + // Get Node + String xpath = component.getDocumentElement().getAttribute("xpath"); + NodeList configurationNodes = XPathAPI.selectNodeList(configuration, xpath); + if (configurationNodes.getLength() != 1) { + throw new IOException("XPath (" + xpath + ") returned not one node, but " + + configurationNodes.getLength() + " nodes"); + } + Node configurationNode = configurationNodes.item(0); + + // Test + String test = component.getDocumentElement().getAttribute("unless"); + if (test != null && test.length() > 0 && + XPathAPI.selectNodeList(configurationNode, test).getLength() != 0) { + System.out.println("Skipping: " + file); + return false; + } else { + // Apply + System.out.println("Processing: " + file); + NodeList componentNodes = component.getDocumentElement().getChildNodes(); + for (int i = 0; i < componentNodes.getLength(); i++ ){ + configurationNode.appendChild(configuration.importNode(componentNodes.item(i), true)); + } + return true; + } } - } ---------------------------------------------------------------------- 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