vgritsenko 02/03/10 09:15:46 Modified: src/scratchpad/src/org/apache/cocoon/sunshine sunshine-int.xpipe src/webapp sitemap.xmap tools/src XConfToolTask.java Log: Add support for the insert-before attribute in the xconf files Remove empty pipelines (they are not valid) Revision Changes Path 1.2 +4 -2 xml-cocoon2/src/scratchpad/src/org/apache/cocoon/sunshine/sunshine-int.xpipe Index: sunshine-int.xpipe =================================================================== RCS file: /home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/sunshine/sunshine-int.xpipe,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- sunshine-int.xpipe 9 Mar 2002 06:40:35 -0000 1.1 +++ sunshine-int.xpipe 10 Mar 2002 17:15:46 -0000 1.2 @@ -1,8 +1,10 @@ <?xml version="1.0"?> -<xmap xpath="/sitemap/pipelines/pipeline[@id='optional-internal']" +<xmap xpath="/sitemap/pipelines" + insert-before="pipeline[@id='optional']" unless="match[@pattern='sunspotdemoresource-sunrise-*']"> + <map:pipeline internal-only="true"> <!-- ======================= SunShine =========================== --> <!-- This is the sunSpot Cocoon Demo Portal Pipeline --> <map:match pattern="sunspotdemoresource-sunrise-*"> @@ -32,5 +34,5 @@ <map:serialize type="xml"/> </map:match> </map:match> - + </map:pipeline> </xmap> 1.40 +9 -13 xml-cocoon2/src/webapp/sitemap.xmap Index: sitemap.xmap =================================================================== RCS file: /home/cvs/xml-cocoon2/src/webapp/sitemap.xmap,v retrieving revision 1.39 retrieving revision 1.40 diff -u -r1.39 -r1.40 --- sitemap.xmap 10 Mar 2002 03:09:17 -0000 1.39 +++ sitemap.xmap 10 Mar 2002 17:15:46 -0000 1.40 @@ -486,13 +486,18 @@ </map:pipeline> <map:pipeline id="optional"> - <!-- Below goes entries added by Cocoon build system --> - </map:pipeline> + <!-- Utility for viewing source xml or html --> + <!-- sample use of regexp equivalent to "**.source" using wildcard + this also shows the '\{' notation to escape sitemap values substitution --> + <map:match pattern="(.*)\.s\{1}ource" type="regexp"> + <map:generate src="cocoon:/{1}" /> + <map:transform src="stylesheets/simple-xml2html.xsl"/> + <map:serialize/> + </map:match> - <map:pipeline internal-only="true" id="optional-internal"> <!-- Below goes entries added by Cocoon build system --> </map:pipeline> - + <!-- "automount" setup This causes directories added under "mount" (even with Cocoon already running) to be activated automagically @@ -511,15 +516,6 @@ <!-- pipeline mounting samples sitemaps --> <map:pipeline> - <!-- Utility for viewing source xml or html --> - <!-- sample use of regexp equivalent to "**.source" using wildcard - this also shows the '\{' notation to escape sitemap values substitution --> - <map:match pattern="(.*)\.s\{1}ource" type="regexp"> - <map:generate src="cocoon:/{1}" /> - <map:transform src="stylesheets/simple-xml2html.xsl"/> - <map:serialize/> - </map:match> - <!-- protected webapp example pipeline --> <map:match pattern="protected/**"> <map:mount uri-prefix="protected" src="protected/" check-reload="yes"/> 1.3 +30 -10 xml-cocoon2/tools/src/XConfToolTask.java Index: XConfToolTask.java =================================================================== RCS file: /home/cvs/xml-cocoon2/tools/src/XConfToolTask.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- XConfToolTask.java 9 Mar 2002 06:27:16 -0000 1.2 +++ XConfToolTask.java 10 Mar 2002 17:15:46 -0000 1.3 @@ -37,7 +37,7 @@ * * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> * @author <a href="mailto:[EMAIL PROTECTED]">Vadim Gritsenko</a> - * @version CVS $Revision: 1.2 $ $Date: 2002/03/09 06:27:16 $ + * @version CVS $Revision: 1.3 $ $Date: 2002/03/10 17:15:46 $ */ public final class XConfToolTask extends Task { @@ -115,6 +115,7 @@ } else if (files[i].getName().endsWith("." + ext)) { String file = files[i].getCanonicalPath(); try { + // Adds configuration snippet from the file to the configuration hasChanged |= add(configuration, builder.parse(file), file); } catch (SAXException e) { System.out.println("Ignoring: " + file + "\n(not a valid XML)"); @@ -133,27 +134,46 @@ String file) throws TransformerException, IOException { - // Get Node + // Get 'root' node were 'component' will be inserted into String xpath = component.getDocumentElement().getAttribute("xpath"); - NodeList configurationNodes = XPathAPI.selectNodeList(configuration, xpath); - if (configurationNodes.getLength() != 1) { + NodeList nodes = XPathAPI.selectNodeList(configuration, xpath); + if (nodes.getLength() != 1) { + System.out.println("Error in: " + file); throw new IOException("XPath (" + xpath + ") returned not one node, but " - + configurationNodes.getLength() + " nodes"); + + nodes.getLength() + " nodes"); } - Node configurationNode = configurationNodes.item(0); + Node root = nodes.item(0); - // Test + // Test that 'root' node satisfies 'component' insertion criteria String test = component.getDocumentElement().getAttribute("unless"); if (test != null && test.length() > 0 && - XPathAPI.selectNodeList(configurationNode, test).getLength() != 0) { + XPathAPI.selectNodeList(root, test).getLength() != 0) { System.out.println("Skipping: " + file); return false; } else { - // Apply + // Test if 'component' provides desired insertion point + xpath = component.getDocumentElement().getAttribute("insert-before"); + Node before = null; + if (xpath != null && xpath.length() > 0) { + nodes = XPathAPI.selectNodeList(root, xpath); + if (nodes.getLength() != 1) { + System.out.println("Error in: " + file); + throw new IOException("XPath (" + xpath + ") returned not one node, but " + + nodes.getLength() + " nodes"); + } + before = nodes.item(0); + } + + // Add 'component' data into 'root' node 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)); + Node node = configuration.importNode(componentNodes.item(i), true); + if (before == null) { + root.appendChild(node); + } else { + root.insertBefore(node, before); + } } return true; }
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]