cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lgaw...@apache.org
Subject svn commit: r439321 - in /cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin: ./ src/main/java/org/apache/cocoon/maven/deployer/ src/main/java/org/apache/cocoon/maven/deployer/monolithic/
Date Fri, 01 Sep 2006 13:48:18 GMT
Author: lgawron
Date: Fri Sep  1 06:48:17 2006
New Revision: 439321

URL: http://svn.apache.org/viewvc?rev=439321&view=rev
Log:
initial XPatch support (needs lots of quality fixes)
when in block development mode META-INF/xpatch/*.xweb are applied to WEB-INF/web.xml
todo: - apply also .xwebs from local development block
      - xpatch profiles
      - main sitemap patching
      - refactoring, clean up, exception handling

Added:
    cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/PatchCachingOutputStream.java   (with props)
    cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/XPatchDeployer.java   (with props)
Modified:
    cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/pom.xml
    cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/AbstractDeployMojo.java
    cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/MonolithicCocoonDeployer.java
    cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/SingleFileDeployer.java

Modified: cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/pom.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/pom.xml?rev=439321&r1=439320&r2=439321&view=diff
==============================================================================
--- cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/pom.xml (original)
+++ cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/pom.xml Fri Sep  1 06:48:17 2006
@@ -80,6 +80,17 @@
       <artifactId>maven-war-plugin</artifactId>
       <version>2.0-beta-2</version>
     </dependency>
+    <!-- Xalan neccessary for XPath operations -->
+    <dependency>
+      <groupId>xalan</groupId>
+      <artifactId>xalan</artifactId>
+      <version>2.7.0</version>
+    </dependency>
+    <dependency>
+      <groupId>xml-apis</groupId>
+      <artifactId>xml-apis</artifactId>
+      <version>1.3.02</version>
+    </dependency>
     <!-- test libs -->
     <dependency>
       <groupId>junit</groupId>

Modified: cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/AbstractDeployMojo.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/AbstractDeployMojo.java?rev=439321&r1=439320&r2=439321&view=diff
==============================================================================
--- cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/AbstractDeployMojo.java (original)
+++ cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/AbstractDeployMojo.java Fri Sep  1 06:48:17 2006
@@ -46,7 +46,7 @@
 
 /**
  * Create a Cocoon web application based on a block deployment descriptor.
- *
+ * 
  * @version $Id$
  */
 abstract class AbstractDeployMojo extends AbstractWarMojo {
@@ -56,71 +56,75 @@
     private static final String COCOON_LIB = "cocoon" + File.separator + "lib";
 
     /**
-     * Artifact factory, needed to download source jars for inclusion in classpath.
-     *
+     * Artifact factory, needed to download source jars for inclusion in
+     * classpath.
+     * 
      * @component role="org.apache.maven.artifact.factory.ArtifactFactory"
      * @required
      * @readonly
      */
-    private ArtifactFactory artifactFactory;	
+    private ArtifactFactory artifactFactory;
 
     /**
-     * Artifact resolver, needed to download source jars for inclusion in classpath.
-     *
+     * Artifact resolver, needed to download source jars for inclusion in
+     * classpath.
+     * 
      * @component role="org.apache.maven.artifact.resolver.ArtifactResolver"
      * @required
      * @readonly
      */
-    private ArtifactResolver artifactResolver;   
+    private ArtifactResolver artifactResolver;
 
     /**
-     * Artifact resolver, needed to download source jars for inclusion in classpath.
-     *
+     * Artifact resolver, needed to download source jars for inclusion in
+     * classpath.
+     * 
      * @component role="org.apache.maven.artifact.metadata.ArtifactMetadataSource"
      * @required
      * @readonly
      */
-    private MavenMetadataSource metadataSource;    
+    private MavenMetadataSource metadataSource;
 
     /**
      * Local maven repository.
-     *
+     * 
      * @parameter expression="${localRepository}"
      * @required
      * @readonly
      */
-    private ArtifactRepository localRepository;    
+    private ArtifactRepository localRepository;
 
     /**
      * Remote repositories which will be searched for blocks.
-     *
+     * 
      * @parameter expression="${project.remoteArtifactRepositories}"
      * @required
      * @readonly
      */
-    private List remoteArtifactRepositories;  
+    private List remoteArtifactRepositories;
 
     /**
      * The deploy descriptor
      * 
      * @parameter expression="${basedir}/cocoon-deploy.xml"
      */
-    private File deploymentDescriptor;     
+    private File deploymentDescriptor;
 
     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-    // set properties: necessary because DeployMojo is not in the same package as AbstractWarMojo
+    // set properties: necessary because DeployMojo is not in the same package
+    // as AbstractWarMojo
 
     /**
      * The project whose project files to create.
-     *
+     * 
      * @parameter expression="${project}"
      * @required
      */
-    private MavenProject project;	    
+    private MavenProject project;
 
     /**
      * The directory containing generated classes.
-     *
+     * 
      * @parameter expression="${project.build.outputDirectory}"
      * @required
      * @readonly
@@ -129,7 +133,7 @@
 
     /**
      * The directory where the webapp is built.
-     *
+     * 
      * @parameter expression="${project.build.directory}/${project.build.finalName}"
      * @required
      */
@@ -137,7 +141,7 @@
 
     /**
      * Single directory for extra files to include in the WAR.
-     *
+     * 
      * @parameter expression="${basedir}/src/main/webapp"
      * @required
      */
@@ -145,63 +149,65 @@
 
     /**
      * The path to the web.xml file to use.
-     *
+     * 
      * @parameter expression="${maven.war.webxml}"
      */
     private String webXml;
 
     /**
      * Use shielded classloading
-     *
+     * 
      * @parameter expression="${maven.war.shieldingclassloader}"
      */
     private boolean useShieldingClassloader = true;
 
     /**
      * Move jars for shielded classloading
-     *
+     * 
      * @parameter expression="${maven.war.shieldingrepository}"
      */
     private boolean useShieldingRepository = true;
 
     /**
-	 * Deploy a monolithic Cocoon web application. This means it doesn't use
-	 * the features that the blocks-fw offers.
-	 */
-	protected void deployMonolithicCocoonAppAsWebapp(final String blocksdir)  throws MojoExecutionException {
-    	File webappDirectory_ = getWebappDirectory();
+     * Deploy a monolithic Cocoon web application. This means it doesn't use the
+     * features that the blocks-fw offers.
+     */
+    protected void deployMonolithicCocoonAppAsWebapp(final String blocksdir) throws MojoExecutionException {
+        File webappDirectory_ = getWebappDirectory();
 
-    	// build the web application
+        // build the web application
         this.buildExplodedWebapp(webappDirectory_);
-        MonolithicCocoonDeployer deployer = new MonolithicCocoonDeployer(this.getLog());        
-        deployer.deploy(getBlockArtifactsAsMap(null), webappDirectory_, 
-                blocksdir, new DevelopmentBlock[0], new DevelopmentProperty[0]);
+        MonolithicCocoonDeployer deployer = new MonolithicCocoonDeployer(this.getLog());
+        deployer.deploy(getBlockArtifactsAsMap(null), webappDirectory_, blocksdir, new DevelopmentBlock[0],
+                new DevelopmentProperty[0]);
 
-        // make sure that all configuration files available in the webapp override block configuration files
+        // make sure that all configuration files available in the webapp
+        // override block configuration files
         try {
-            copyResources( getWarSourceDirectory(), webappDirectory_, getWebXml() );
+            copyResources(getWarSourceDirectory(), webappDirectory_, getWebXml());
         } catch (IOException e) {
             throw new MojoExecutionException("A problem occurred while copying webapp resources.", e);
         }
 
         // take care of paranoid classloading
-        if ( this.useShieldingClassloader ) {
+        if (this.useShieldingClassloader) {
             shieldCocoonWebapp();
         }
-	}
+    }
 
     /**
      * Deploy a particular block at development time.
      */
-    protected void blockDeploymentMonolithicCocoon(final String blocksdir, final DevelopmentBlock[] blocks, 
+    protected void blockDeploymentMonolithicCocoon(final String blocksdir, final DevelopmentBlock[] blocks,
             final DevelopmentProperty[] properties) throws MojoExecutionException {
-        File webappDirectory_ = getWebappDirectory();        
+        File webappDirectory_ = getWebappDirectory();
 
         File webinfDir = new File(webappDirectory_, WEB_INF);
         webinfDir.mkdirs();
 
         // add current block to the development blocks
-        // it is important that the current block is put at the end of the array - the 
+        // it is important that the current block is put at the end of the array
+        // - the
         // MonotlithicCocoonDeployer expects this
         DevelopmentBlock curBlock = new DevelopmentBlock();
         curBlock.artifactId = this.getProject().getArtifactId();
@@ -217,20 +223,21 @@
 
         // deploy all blocks
         MonolithicCocoonDeployer deployer = new MonolithicCocoonDeployer(this.getLog());
-        deployer.deploy(getBlockArtifactsAsMap(blocks), webappDirectory_, 
-                blocksdir, extBlocks, properties);
+        deployer.deploy(getBlockArtifactsAsMap(blocks), webappDirectory_, blocksdir, extBlocks, properties);
 
-        // deploy all libraries to WEB-INF/cocoon/lib and cocoon-bootstrap to WEB-INF/lib
-        copyLibs();        
-    }   
+        // deploy all libraries to WEB-INF/cocoon/lib and cocoon-bootstrap to
+        // WEB-INF/lib
+        copyLibs();
+    }
 
     /**
-     * Create a <code>Map</code> of <code>java.io.File</code> objects pointing to artifacts.
+     * Create a <code>Map</code> of <code>java.io.File</code> objects
+     * pointing to artifacts.
      */
     private Map getBlockArtifactsAsMap(DevelopmentBlock[] excludedBlocks) throws MojoExecutionException {
         // loop over all artifacts and deploy them correctly
         Map files = new HashMap();
-        for(Iterator it = this.getProject().getArtifacts().iterator(); it.hasNext(); ) {
+        for (Iterator it = this.getProject().getArtifacts().iterator(); it.hasNext();) {
             Artifact artifact = (Artifact) it.next();
             String id = artifact.getArtifactId();
             if (files.containsKey(id)) {
@@ -239,14 +246,14 @@
                 msg.append(id);
                 msg.append("':");
                 msg.append(SystemUtils.LINE_SEPARATOR);
-                for(Iterator ai = this.getProject().getArtifacts().iterator(); ai.hasNext(); ) {
+                for (Iterator ai = this.getProject().getArtifacts().iterator(); ai.hasNext();) {
                     final Artifact current = (Artifact) ai.next();
-                    if ( current.getArtifactId().equals(id) ) {
+                    if (current.getArtifactId().equals(id)) {
                         msg.append(artifact);
                         msg.append(SystemUtils.LINE_SEPARATOR);
                         final List l = current.getDependencyTrail();
                         final Iterator i = l.iterator();
-                        while ( i.hasNext() ) {
+                        while (i.hasNext()) {
                             msg.append("    ");
                             msg.append(i.next().toString());
                             msg.append(SystemUtils.LINE_SEPARATOR);
@@ -259,11 +266,11 @@
                 this.getLog().debug("Skipping " + artifact);
             } else {
                 files.put(id, artifact.getFile());
-                if ( this.getLog().isDebugEnabled() ) {
+                if (this.getLog().isDebugEnabled()) {
                     StringBuffer msg = new StringBuffer("Deploying " + artifact);
                     final List l = artifact.getDependencyTrail();
                     final Iterator i = l.iterator();
-                    while ( i.hasNext() ) {
+                    while (i.hasNext()) {
                         msg.append("    ");
                         msg.append(i.next().toString());
                         msg.append(SystemUtils.LINE_SEPARATOR);
@@ -273,15 +280,16 @@
             }
         }
         return files;
-    }     
+    }
 
     /**
-     * @return true if the DevelopmentBlock array contains a block with the passed artifactId and groupId
+     * @return true if the DevelopmentBlock array contains a block with the
+     *         passed artifactId and groupId
      */
     private boolean containsArtifact(DevelopmentBlock[] blocks, String artifactId, String groupId) {
-        if(blocks != null) {
-            for(int i = 0; i < blocks.length; i++) {
-                if(blocks[i].artifactId.equals(artifactId) && blocks[i].groupId.equals(groupId)) {
+        if (blocks != null) {
+            for (int i = 0; i < blocks.length; i++) {
+                if (blocks[i].artifactId.equals(artifactId) && blocks[i].groupId.equals(groupId)) {
                     return true;
                 }
             }
@@ -291,23 +299,25 @@
 
     // ~~~~~~~~~~ utility methods ~~~~~~~~~~~
     /**
-     * Make a Cocoon webapp using the ShieldingClassloader. This method rewrites the web.xml and moves
-     * all libs from WEB-INF/lib to WEB-INF/cocoon/lib, except cocoon-bootstrap which remains in WEB-INF/lib.
+     * Make a Cocoon webapp using the ShieldingClassloader. This method rewrites
+     * the web.xml and moves all libs from WEB-INF/lib to WEB-INF/cocoon/lib,
+     * except cocoon-bootstrap which remains in WEB-INF/lib.
      */
     private void shieldCocoonWebapp() throws MojoExecutionException {
         File webappDirectory_ = getWebappDirectory();
         String webXmlLocation = this.getWebXml();
-        if ( webXmlLocation == null ) {
-            webXmlLocation = getWarSourceDirectory().getAbsolutePath() + File.separatorChar + "WEB-INF" + File.separatorChar + "web.xml";
+        if (webXmlLocation == null) {
+            webXmlLocation = getWarSourceDirectory().getAbsolutePath() + File.separatorChar + "WEB-INF"
+                    + File.separatorChar + "web.xml";
         }
-        if( ! new File(webXmlLocation).exists())
-        {
+        if (!new File(webXmlLocation).exists()) {
             this.getLog().info("No web.xml supplied. Will install default web.xml");
             final String webXml = "WEB-INF" + File.separatorChar + "web.xml";
-            File outFile = org.apache.cocoon.maven.deployer.utils.FileUtils.createDirectory(new File(webappDirectory_, webXml));
+            File outFile = org.apache.cocoon.maven.deployer.utils.FileUtils.createDirectory(new File(webappDirectory_,
+                    webXml));
             try {
                 IOUtils.copy(readResourceFromClassloader(webXml), new FileOutputStream(outFile));
-            } catch(IOException ioex) {
+            } catch (IOException ioex) {
                 throw new MojoExecutionException("cannot read resource " + webXml, ioex);
             }
             webXmlLocation = webappDirectory_.getAbsolutePath() + File.separatorChar + webXml;
@@ -317,46 +327,47 @@
         try {
             final Document webAppDoc = XMLUtils.parseXml(new FileInputStream(new File(webXmlLocation)));
             WebApplicationRewriter.rewrite(webAppDoc);
-            final String dest = webappDirectory_.getAbsolutePath() + File.separatorChar + "WEB-INF" + File.separatorChar + "web.xml";
+            final String dest = webappDirectory_.getAbsolutePath() + File.separatorChar + "WEB-INF"
+                    + File.separatorChar + "web.xml";
             this.getLog().debug("Writing web.xml: " + dest);
             XMLUtils.write(webAppDoc, new FileOutputStream(dest));
         } catch (Exception e) {
             throw new MojoExecutionException("Unable to read web.xml from " + webXmlLocation, e);
         }
-        if ( this.useShieldingRepository ) {
+        if (this.useShieldingRepository) {
             this.getLog().info("Moving classes and libs to shielded location.");
             final String webInfDir = webappDirectory_.getAbsolutePath() + File.separatorChar + "WEB-INF";
             this.move(webInfDir, "lib", COCOON_LIB);
             this.move(webInfDir, "classes", COCOON_CLASSES);
         }
-    }  
+    }
 
     private InputStream readResourceFromClassloader(String fileName) {
-        return MonolithicCocoonDeployer.class.getClassLoader().
-            getResourceAsStream("org/apache/cocoon/maven/deployer/monolithic/" + fileName);
+        return MonolithicCocoonDeployer.class.getClassLoader().getResourceAsStream(
+                "org/apache/cocoon/maven/deployer/monolithic/" + fileName);
     }
 
     /**
-     * Copy all libs that don't have the scope provided or system to WEB-INF/cocoon/lib, except
-     * cocoon-bootstrap, which is copied to WEB-INF/lib
+     * Copy all libs that don't have the scope provided or system to
+     * WEB-INF/cocoon/lib, except cocoon-bootstrap, which is copied to
+     * WEB-INF/lib
      */
     private void copyLibs() throws MojoExecutionException {
         File webappDirectory_ = this.getWebappDirectory();
-        for ( Iterator iter = this.getProject().getArtifacts().iterator(); iter.hasNext(); ) {
+        for (Iterator iter = this.getProject().getArtifacts().iterator(); iter.hasNext();) {
             Artifact artifact = (Artifact) iter.next();
             // Include runtime and compile time libraries
             if (!Artifact.SCOPE_PROVIDED.equals(artifact.getScope())
-                    && !Artifact.SCOPE_TEST.equals(artifact.getScope()) 
-                    && "jar".equals(artifact.getType())) {
+                    && !Artifact.SCOPE_TEST.equals(artifact.getScope()) && "jar".equals(artifact.getType())) {
                 try {
                     if (artifact.getArtifactId().equals("cocoon-bootstrap")) {
-                        FileUtils.copyFileToDirectory(artifact.getFile(), new File(webappDirectory_, "WEB-INF/lib"));       
-                        this.getLog().info("Deploying artifact to WEB-INF/lib/" + artifact.getFile().getName());                       
+                        FileUtils.copyFileToDirectory(artifact.getFile(), new File(webappDirectory_, "WEB-INF/lib"));
+                        this.getLog().info("Deploying artifact to WEB-INF/lib/" + artifact.getFile().getName());
                     } else {
                         FileUtils.copyFileToDirectory(artifact.getFile(), new File(webappDirectory_, "WEB-INF/"
-                            + COCOON_LIB));
-                        this.getLog().info("Deploying artifact to WEB-INF/" + COCOON_LIB + "/" + 
-                            artifact.getFile().getName());                        
+                                + COCOON_LIB));
+                        this.getLog().info(
+                                "Deploying artifact to WEB-INF/" + COCOON_LIB + "/" + artifact.getFile().getName());
                     }
                 } catch (IOException e) {
                     throw new MojoExecutionException("Can't copy artifact '" + artifact.getArtifactId()
@@ -364,21 +375,22 @@
                 }
             }
         }
-    }       
+    }
 
     /**
-     * Move all libs from one directory (WEB-INF/lib) to another (WEB-INF/cocoon/lib).
+     * Move all libs from one directory (WEB-INF/lib) to another
+     * (WEB-INF/cocoon/lib).
      */
     private void move(String parentDir, String srcDir, String destDir) {
         final File srcDirectory = new File(parentDir, srcDir);
         if (srcDirectory.exists() && srcDirectory.isDirectory()) {
             File destDirectory = new File(parentDir, destDir);
-            if ( this.getLog().isDebugEnabled() ) {
+            if (this.getLog().isDebugEnabled()) {
                 this.getLog().debug("Deleting directory " + destDirectory);
             }
             org.apache.cocoon.maven.deployer.utils.FileUtils.deleteDirRecursivly(destDirectory);
             destDirectory = new File(parentDir, destDir);
-            if ( this.getLog().isDebugEnabled() ) {
+            if (this.getLog().isDebugEnabled()) {
                 this.getLog().debug("Recreating directory " + destDirectory);
             }
             destDirectory.mkdirs();
@@ -390,12 +402,12 @@
                     boolean exclude = false;
                     if ("lib".equals(srcDir) && files[i].getName().startsWith("cocoon-bootstrap")) {
                         exclude = true;
-                        if ( this.getLog().isDebugEnabled() ) {
+                        if (this.getLog().isDebugEnabled()) {
                             this.getLog().debug("Excluding " + files[i] + " from moving.");
                         }
                     }
                     if (!exclude) {
-                        if ( this.getLog().isDebugEnabled() ) {
+                        if (this.getLog().isDebugEnabled()) {
                             this.getLog().debug("Moving " + files[i] + " to " + destDirectory);
                         }
                         files[i].renameTo(new File(destDirectory, files[i].getName()));
@@ -403,5 +415,5 @@
                 }
             }
         }
-    }    
+    }
 }

Modified: cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/MonolithicCocoonDeployer.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/MonolithicCocoonDeployer.java?rev=439321&r1=439320&r2=439321&view=diff
==============================================================================
--- cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/MonolithicCocoonDeployer.java (original)
+++ cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/MonolithicCocoonDeployer.java Fri Sep  1 06:48:17 2006
@@ -31,124 +31,133 @@
 import org.apache.maven.plugin.logging.Log;
 
 /**
- * Deploy blocks to a monolithic Cocoon web application. The files contained by a block are copied to the right places.
- * based on rules.
- *
- * @version $Id$
+ * Deploy blocks to a monolithic Cocoon web application. The files contained by
+ * a block are copied to the right places. based on rules.
+ * 
+ * @version $Id: MonolithicCocoonDeployer.java 438198 2006-08-29 20:38:09Z
+ *          lgawron $
  */
 public class MonolithicCocoonDeployer {
 
-	private Log logger;
+    private Log logger;
 
-	public MonolithicCocoonDeployer(Log logger) {
-		this.logger = logger;
-	}
-
-	public void deploy(final Map libraries, final File basedir, final String blocksdir,
-		final DevelopmentBlock[] developmentBlocks, DevelopmentProperty[] developmentProperties)
-		throws DeploymentException {
-
-		// iterate over all blocks that need to be installed into a J2EE web application
-        for(Iterator it = libraries.entrySet().iterator(); it.hasNext();) {
-            final Map.Entry entry = (Map.Entry)it.next();
-        	final Object id = entry.getKey();
-        	File lib = (File) entry.getValue();
-        	try {
+    public MonolithicCocoonDeployer(Log logger) {
+        this.logger = logger;
+    }
+
+    public void deploy(final Map libraries, final File basedir, final String blocksdir,
+            final DevelopmentBlock[] developmentBlocks, DevelopmentProperty[] developmentProperties)
+            throws DeploymentException {
+
+        XPatchDeployer xpatchDeployer = new XPatchDeployer("WEB-INF");
+
+        // iterate over all blocks that need to be installed into a J2EE web
+        // application
+        for (Iterator it = libraries.entrySet().iterator(); it.hasNext();) {
+            final Map.Entry entry = (Map.Entry) it.next();
+            final Object id = entry.getKey();
+            File lib = (File) entry.getValue();
+            try {
                 this.logger.info("Deploying " + id);
-        		MonolithicServer22 zipExtractor = new MonolithicServer22(basedir, logger);
+                MonolithicServer22 zipExtractor = new MonolithicServer22(basedir, logger);
                 zipExtractor.addRule("META-INF/legacy/cocoon.xconf", new SingleFileDeployer("WEB-INF/cocoon"));
                 zipExtractor.addRule("META-INF/legacy/xconf/**", new SingleFileDeployer("WEB-INF/cocoon/xconf"));
-                zipExtractor.addRule("META-INF/legacy/sitemap-additions/**", new SingleFileDeployer("WEB-INF/cocoon/sitemap-additions"));
+                zipExtractor.addRule("META-INF/legacy/sitemap-additions/**", new SingleFileDeployer(
+                        "WEB-INF/cocoon/sitemap-additions"));
                 zipExtractor.addRule("META-INF/spring/**", new SingleFileDeployer("WEB-INF/cocoon/spring"));
                 zipExtractor.addRule("META-INF/properties/**", new SingleFileDeployer("WEB-INF/cocoon/properties"));
                 zipExtractor.addRule("WEB-INF/classes/**", new SingleFileDeployer("WEB-INF/classes"));
                 zipExtractor.addRule("WEB-INF/db/**", new SingleFileDeployer("WEB-INF/db"));
                 zipExtractor.addRule("COB-INF**", new SingleFileDeployer(blocksdir + "/" + (String) id, true));
-        		// extract all configurations files
-				zipExtractor.extract(lib);
-			} catch (IOException e) {
-				throw new DeploymentException("Can't deploy '" + lib.getAbsolutePath() + "'.", e);
-			}
+                zipExtractor.addRule("META-INF/xpatch/*.xweb", xpatchDeployer);
+                // extract all configurations files
+                zipExtractor.extract(lib);
+            } catch (IOException e) {
+                throw new DeploymentException("Can't deploy '" + lib.getAbsolutePath() + "'.", e);
+            }
         }
 
-        // deploy all blocks that are under development by adding their src/main/java (--> <map:classpath>),
-        // src/main/resources/COB-INF (--> <map:mount>), and src/main/resources/META-INF/*
+        // deploy all blocks that are under development by adding their
+        // src/main/java (--> <map:classpath>),
+        // src/main/resources/COB-INF (--> <map:mount>), and
+        // src/main/resources/META-INF/*
         // (--> <map:include>) to the root sitemap.
-        if(developmentBlocks != null && developmentBlocks.length > 0) {
-	        Map templateObjects = new HashMap();
-	        templateObjects.put("devblocks", developmentBlocks);
+        if (developmentBlocks != null && developmentBlocks.length > 0) {
+            Map templateObjects = new HashMap();
+            templateObjects.put("devblocks", developmentBlocks);
             templateObjects.put("curblock", developmentBlocks[developmentBlocks.length - 1]);
-	        writeStringTemplateToFile(basedir, "sitemap.xmap", templateObjects);
-	        writeStringTemplateToFile(basedir, "WEB-INF/cocoon/cocoon.xconf", templateObjects);
+            writeStringTemplateToFile(basedir, "sitemap.xmap", templateObjects);
+            writeStringTemplateToFile(basedir, "WEB-INF/cocoon/cocoon.xconf", templateObjects);
 
             copyFile(basedir, "blocks/sitemap.xmap");
-			copyFile(basedir, "WEB-INF/cocoon/log4j.xconf");
-	        copyFile(basedir, "WEB-INF/web.xml");
-	        copyFile(basedir, "WEB-INF/applicationContext.xml");
-	        copyFile(basedir, "WEB-INF/cocoon/properties/core.properties");
+            copyFile(basedir, "WEB-INF/cocoon/log4j.xconf");
+            // copyFile(basedir, "WEB-INF/web.xml");
+            xpatchDeployer.applyPatches(basedir, "WEB-INF/web.xml");
+            copyFile(basedir, "WEB-INF/applicationContext.xml");
+            copyFile(basedir, "WEB-INF/cocoon/properties/core.properties");
         }
 
         // write properties
-        if(developmentProperties != null && developmentProperties.length > 0) {
-        	Properties properties = new Properties();
-        	for(int i = 0; i < developmentProperties.length; i++) {
-        		properties.setProperty(developmentProperties[0].name, developmentProperties[0].value);
-        	}
-        	writeProperties(basedir, "WEB-INF/cocoon/properties/dev/core.properties", properties);
-        }
-	}
-
-	private void writeProperties(final File basedir, final String propertiesFile, final Properties properties) {
-    	try {
-    		File outFile = new File(basedir, propertiesFile);
-			properties.save(new FileOutputStream(FileUtils.createDirectory(outFile)), null);
-			this.logger.info("Deploying dev properties to " + propertiesFile);
-		} catch (IOException e) {
-			throw new DeploymentException("Can't save properties to " + propertiesFile, e);
-		}
-	}
-
-	private void copyFile(final File basedir, final String fileName) {
-		try {
-			File outFile = FileUtils.createDirectory(new File(basedir, fileName));
-			IOUtils.copy(readResourceFromClassloader(fileName), new FileOutputStream(outFile));
-			this.logger.info("Deploying resource file to " + fileName);
-		} catch (FileNotFoundException e) {
-			throw new DeploymentException("Can't copy to " + fileName, e);
-		} catch (IOException e) {
-			throw new DeploymentException("Can't copy to " + fileName, e);
-		}
-	}
+        if (developmentProperties != null && developmentProperties.length > 0) {
+            Properties properties = new Properties();
+            for (int i = 0; i < developmentProperties.length; i++) {
+                properties.setProperty(developmentProperties[0].name, developmentProperties[0].value);
+            }
+            writeProperties(basedir, "WEB-INF/cocoon/properties/dev/core.properties", properties);
+        }
+    }
 
-	private void writeStringTemplateToFile(final File basedir, final String fileName, final Map templateObjects) {
-		FileOutputStream fos = null;
+    private void writeProperties(final File basedir, final String propertiesFile, final Properties properties) {
         try {
-        	File outFile = FileUtils.createDirectory(new File(basedir, fileName));
-        	fos = new FileOutputStream(outFile);
-			InputStream fileIs = readResourceFromClassloader(fileName);
-			StringTemplate stringTemplate = new StringTemplate(IOUtils.toString(fileIs));
-			for(Iterator templateObjectsIt = templateObjects.keySet().iterator(); templateObjectsIt.hasNext();) {
-				Object key = templateObjectsIt.next();
-				stringTemplate.setAttribute((String) key, templateObjects.get(key));
-			}
-			IOUtils.write(stringTemplate.toString(), fos);
-			this.logger.info("Deploying string-template to " + fileName);
-		} catch (FileNotFoundException e) {
-			throw new DeploymentException(fileName + " not found.", e);
-		} catch (IOException e) {
-			throw new DeploymentException("Error while reading or writing.", e);
-		} finally {
-			try {
-				fos.close();
-			} catch (IOException e) {
-				throw new DeploymentException("Error while closing the output stream.", e);
-			}
-		}
-	}
-
-	private InputStream readResourceFromClassloader(String fileName) {
-		return MonolithicCocoonDeployer.class.getClassLoader().
-			getResourceAsStream("org/apache/cocoon/maven/deployer/monolithic/" + fileName);
-	}
+            File outFile = new File(basedir, propertiesFile);
+            properties.store(new FileOutputStream(FileUtils.createDirectory(outFile)), null);
+            this.logger.info("Deploying dev properties to " + propertiesFile);
+        } catch (IOException e) {
+            throw new DeploymentException("Can't save properties to " + propertiesFile, e);
+        }
+    }
+
+    private void copyFile(final File basedir, final String fileName) {
+        try {
+            File outFile = FileUtils.createDirectory(new File(basedir, fileName));
+            IOUtils.copy(readResourceFromClassloader(fileName), new FileOutputStream(outFile));
+            this.logger.info("Deploying resource file to " + fileName);
+        } catch (FileNotFoundException e) {
+            throw new DeploymentException("Can't copy to " + fileName, e);
+        } catch (IOException e) {
+            throw new DeploymentException("Can't copy to " + fileName, e);
+        }
+    }
+
+    private void writeStringTemplateToFile(final File basedir, final String fileName, final Map templateObjects) {
+        FileOutputStream fos = null;
+        try {
+            File outFile = FileUtils.createDirectory(new File(basedir, fileName));
+            fos = new FileOutputStream(outFile);
+            InputStream fileIs = readResourceFromClassloader(fileName);
+            StringTemplate stringTemplate = new StringTemplate(IOUtils.toString(fileIs));
+            for (Iterator templateObjectsIt = templateObjects.keySet().iterator(); templateObjectsIt.hasNext();) {
+                Object key = templateObjectsIt.next();
+                stringTemplate.setAttribute((String) key, templateObjects.get(key));
+            }
+            IOUtils.write(stringTemplate.toString(), fos);
+            this.logger.info("Deploying string-template to " + fileName);
+        } catch (FileNotFoundException e) {
+            throw new DeploymentException(fileName + " not found.", e);
+        } catch (IOException e) {
+            throw new DeploymentException("Error while reading or writing.", e);
+        } finally {
+            try {
+                fos.close();
+            } catch (IOException e) {
+                throw new DeploymentException("Error while closing the output stream.", e);
+            }
+        }
+    }
+
+    private InputStream readResourceFromClassloader(String fileName) {
+        return MonolithicCocoonDeployer.class.getClassLoader().getResourceAsStream(
+                "org/apache/cocoon/maven/deployer/monolithic/" + fileName);
+    }
 
 }

Added: cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/PatchCachingOutputStream.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/PatchCachingOutputStream.java?rev=439321&view=auto
==============================================================================
--- cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/PatchCachingOutputStream.java (added)
+++ cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/PatchCachingOutputStream.java Fri Sep  1 06:48:17 2006
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.maven.deployer.monolithic;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+
+public class PatchCachingOutputStream extends OutputStream {
+	private ByteArrayOutputStream bout = new ByteArrayOutputStream();
+	
+	public void write(int b) throws IOException {
+		bout.write(b);
+	}
+
+	public Document getPatch() throws SAXException, IOException, ParserConfigurationException {
+		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+		factory.setValidating(false);
+		factory.setExpandEntityReferences(false);
+		factory.setNamespaceAware(false);
+		factory
+				.setAttribute(
+						"http://apache.org/xml/features/nonvalidating/load-external-dtd",
+						Boolean.FALSE);
+		
+		DocumentBuilder builder = factory.newDocumentBuilder();
+		
+		return builder.parse(new ByteArrayInputStream(bout.toByteArray()));
+	}
+}

Propchange: cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/PatchCachingOutputStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/PatchCachingOutputStream.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/SingleFileDeployer.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/SingleFileDeployer.java?rev=439321&r1=439320&r2=439321&view=diff
==============================================================================
--- cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/SingleFileDeployer.java (original)
+++ cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/SingleFileDeployer.java Fri Sep  1 06:48:17 2006
@@ -26,89 +26,88 @@
 import org.apache.maven.plugin.logging.Log;
 
 /**
- * Deploy a single file. 
+ * Deploy a single file.
  * 
  * @version $Id$
  */
 public class SingleFileDeployer implements FileDeployer {
-
-	private File basedir;
-	private Log logger;
-	private String outputDir;
-	private boolean skipRootDirectory;
-	private Set alreadyDeployedFilesSet;
-	
-	public SingleFileDeployer(final String outputDir, final boolean skipRootDirectory) {
-		Validate.notNull(outputDir, "An outputDir has to be set.");
-		this.outputDir = outputDir;
-		this.skipRootDirectory = skipRootDirectory;
-	}
-
-	public SingleFileDeployer(final String outputDir) {
-		this(outputDir, false);
-	}	
-	
-	public void setBasedir(final File basedir) {
-		this.basedir = basedir;
-	}
-
-	protected File getBasedir() {
-		return this.basedir;
-	}
-
-	public void setLogger(final Log logger) {
-		this.logger = logger;
-	}
-	
-	protected Log getLogger() {
-		return this.logger;
-	}
-	
-	public void setAlreadyDeployedFilesSet(Set alreadyDeployedFilesSet) {
-		this.alreadyDeployedFilesSet = alreadyDeployedFilesSet;
-	}	
-	
-	protected String getFileName(final String documentName) { 
-		return documentName.substring(documentName.lastIndexOf('/') + 1);
-	}
-
-	protected String getOutputDir() {
-		return this.outputDir;
-	}
-	
-	public OutputStream writeResource(final String documentName) throws IOException {	
-		File outDir = new File(this.getBasedir(), getOutputDir());
-		if(!outDir.exists()) {
-			outDir.mkdirs();
-		}
-		
-		String outputDocumentName = documentName;
-		// if the root directory is has to be skipped, the remaining path will be used
-		if(this.skipRootDirectory) {
-			outputDocumentName = removeRootDirectory(documentName);
-			this.logger.debug("Changing output document name from '" + documentName + "', to '" + outputDocumentName + "'.");			
-		} 
-		// only take the filename
-		else {
-			outputDocumentName = this.getFileName(documentName);
-		}
-		
-		File targetFile = FileUtils.createDirectory(new File(outDir, outputDocumentName));
-		
-		if(this.alreadyDeployedFilesSet.contains(targetFile.getCanonicalFile())) {
-			throw new FileAlreadyDeployedException("File '" + targetFile + "' already exists!");
-		}
-		
-		this.alreadyDeployedFilesSet.add(targetFile.getCanonicalFile());
-		
-		this.logger.debug("Deploying block resource to " + getOutputDir() + "/" + outputDocumentName);
-		
-		return new FileOutputStream(FileUtils.createDirectory(targetFile));
-	}
-	
-	protected String removeRootDirectory(final String documentName) {
-		return documentName.substring(documentName.indexOf('/') + 1);
-	}
-
-
+    private File basedir;
+    private Log logger;
+    private String outputDir;
+    private boolean skipRootDirectory;
+    private Set alreadyDeployedFilesSet;
+
+    public SingleFileDeployer(final String outputDir, final boolean skipRootDirectory) {
+        Validate.notNull(outputDir, "An outputDir has to be set.");
+        this.outputDir = outputDir;
+        this.skipRootDirectory = skipRootDirectory;
+    }
+
+    public SingleFileDeployer(final String outputDir) {
+        this(outputDir, false);
+    }
+
+    public void setBasedir(final File basedir) {
+        this.basedir = basedir;
+    }
+
+    protected File getBasedir() {
+        return this.basedir;
+    }
+
+    public void setLogger(final Log logger) {
+        this.logger = logger;
+    }
+
+    protected Log getLogger() {
+        return this.logger;
+    }
+
+    public void setAlreadyDeployedFilesSet(Set alreadyDeployedFilesSet) {
+        this.alreadyDeployedFilesSet = alreadyDeployedFilesSet;
+    }
+
+    protected String getFileName(final String documentName) {
+        return documentName.substring(documentName.lastIndexOf('/') + 1);
+    }
+
+    protected String getOutputDir() {
+        return this.outputDir;
+    }
+
+    public OutputStream writeResource(final String documentName) throws IOException {
+        File outDir = new File(this.getBasedir(), getOutputDir());
+        if (!outDir.exists()) {
+            outDir.mkdirs();
+        }
+
+        String outputDocumentName = documentName;
+        // if the root directory is has to be skipped, the remaining path will
+        // be used
+        if (this.skipRootDirectory) {
+            outputDocumentName = removeRootDirectory(documentName);
+            this.logger.debug("Changing output document name from '" + documentName + "', to '" + outputDocumentName
+                    + "'.");
+        }
+        // only take the filename
+        else {
+            outputDocumentName = this.getFileName(documentName);
+        }
+
+        File targetFile = FileUtils.createDirectory(new File(outDir, outputDocumentName));
+
+        if (this.alreadyDeployedFilesSet.contains(targetFile.getCanonicalFile())) {
+            throw new FileAlreadyDeployedException("File '" + targetFile + "' already exists!");
+        }
+
+        this.alreadyDeployedFilesSet.add(targetFile.getCanonicalFile());
+
+        this.logger.debug("Deploying block resource to " + getOutputDir() + "/" + outputDocumentName);
+
+        return new FileOutputStream(FileUtils.createDirectory(targetFile));
+    }
+
+    protected String removeRootDirectory(final String documentName) {
+        return documentName.substring(documentName.indexOf('/') + 1);
+    }
 }

Added: cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/XPatchDeployer.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/XPatchDeployer.java?rev=439321&view=auto
==============================================================================
--- cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/XPatchDeployer.java (added)
+++ cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/XPatchDeployer.java Fri Sep  1 06:48:17 2006
@@ -0,0 +1,215 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.maven.deployer.monolithic;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Vector;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.apache.cocoon.maven.deployer.utils.FileUtils;
+import org.apache.xpath.XPathAPI;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+// TODO should this extend SingleFileDeployer at all?
+public class XPatchDeployer extends SingleFileDeployer {
+    final List patches = new Vector();
+
+    public XPatchDeployer(String outputDir) {
+        super(outputDir, false);
+    }
+
+    public OutputStream writeResource(String documentName) throws IOException {
+        getLogger().debug("catching patch: " + documentName);
+        PatchCachingOutputStream out = new PatchCachingOutputStream();
+        patches.add(out);
+        return out;
+    }
+
+    public void applyPatches(final File basedir, final String fileName) {
+        if (patches.size() == 0) {
+            // TODO should just copy the file without any transform
+        }
+        try {
+            getLogger().info("Applying patches to: " + fileName);
+            File outFile = FileUtils.createDirectory(new File(basedir, fileName));
+
+            // TODO code duplication
+            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+            factory.setValidating(false);
+            factory.setExpandEntityReferences(false);
+            factory.setNamespaceAware(false);
+            factory.setAttribute("http://apache.org/xml/features/nonvalidating/load-external-dtd", Boolean.FALSE);
+
+            DocumentBuilder builder = factory.newDocumentBuilder();
+            InputStream is = readResourceFromClassloader(fileName);
+            Document original = builder.parse(is);
+
+            Iterator it = patches.iterator();
+            while (it.hasNext()) {
+                Document component = ((PatchCachingOutputStream) it.next()).getPatch();
+
+                Element elem = component.getDocumentElement();
+                if (elem.getTagName().equals("xweb")) {
+                    String replacePropertiesStr = elem.getAttribute("replace-properties");
+
+                    boolean replaceProperties = !("no".equalsIgnoreCase(replacePropertiesStr) || "false"
+                            .equalsIgnoreCase(replacePropertiesStr));
+
+                    String xpath = elem.getAttribute("xpath");
+                    if (xpath != null) {
+
+                        NodeList nodes = XPathAPI.selectNodeList(original, xpath);
+
+                        if (nodes.getLength() == 1) {
+                            Node root = nodes.item(0);
+                            // Test that 'root' node satisfies 'component'
+                            // insertion criteria
+                            String testPath = elem.getAttribute("unless-path");
+                            if (testPath == null || testPath.length() == 0) {
+                                // only look for old "unless" attr if
+                                // unless-path is not present
+                                testPath = elem.getAttribute("unless");
+                            }
+
+                            if (!(testPath != null && testPath.length() > 0 && XPathAPI.eval(root, testPath).bool())) {
+                                // Test if component wants us to remove
+                                // a list of nodes first
+                                xpath = elem.getAttribute("remove");
+                                if (xpath != null && xpath.length() > 0) {
+                                    nodes = XPathAPI.selectNodeList(original, xpath);
+                                    for (int i = 0, length = nodes.getLength(); i < length; i++) {
+                                        Node node = nodes.item(i);
+                                        Node parent = node.getParentNode();
+                                        parent.removeChild(node);
+                                    }
+                                }
+                                // Test for an attribute that needs to be
+                                // added to an element
+                                String name = elem.getAttribute("add-attribute");
+                                String value = elem.getAttribute("value");
+
+                                if (name != null && name.length() > 0 && value != null && root instanceof Element) {
+                                    ((Element) root).setAttribute(name, value);
+                                }
+
+                                // Allow multiple attributes to be added or
+                                // modified
+                                if (root instanceof Element) {
+                                    NamedNodeMap attrMap = elem.getAttributes();
+                                    for (int i = 0; i < attrMap.getLength(); ++i) {
+                                        Attr attr = (Attr) attrMap.item(i);
+                                        final String addAttr = "add-attribute-";
+                                        if (attr.getName().startsWith(addAttr)) {
+                                            String key = attr.getName().substring(addAttr.length());
+                                            ((Element) root).setAttribute(key, attr.getValue());
+                                        }
+                                    }
+                                }
+
+                                // Test if 'component' provides desired
+                                // insertion point
+                                xpath = elem.getAttribute("insert-before");
+                                Node before = null;
+
+                                if (xpath != null && xpath.length() > 0) {
+                                    nodes = XPathAPI.selectNodeList(root, xpath);
+                                    if (nodes.getLength() != 0) {
+                                        before = nodes.item(0);
+                                    }
+                                } else {
+                                    xpath = elem.getAttribute("insert-after");
+                                    if (xpath != null && xpath.length() > 0) {
+                                        nodes = XPathAPI.selectNodeList(root, xpath);
+                                        if (nodes.getLength() != 0) {
+                                            before = nodes.item(nodes.getLength() - 1).getNextSibling();
+                                        }
+                                    }
+                                }
+
+                                NodeList componentNodes = component.getDocumentElement().getChildNodes();
+
+                                for (int i = 0; i < componentNodes.getLength(); i++) {
+                                    Node node = original.importNode(componentNodes.item(i), true);
+
+                                    if (before == null) {
+                                        root.appendChild(node);
+                                    } else {
+                                        root.insertBefore(node, before);
+                                    }
+                                }
+                            } else {
+                                // no test path or 'unless' condition is
+                                // satisfied
+                            }
+                        } else {
+                            // no matches or too many matches
+                        }
+                    } else {
+                        // no xpath parameter
+                        // TODO raise exception
+                    }
+                } else {
+                    // not a valid xpatch file
+                    // TODO raise exception
+                }
+            }
+
+            TransformerFactory tFactory = TransformerFactory.newInstance();
+            Transformer transformer = tFactory.newTransformer();
+            transformer.transform(new DOMSource(original), new StreamResult(new FileOutputStream(outFile)));
+            getLogger().debug("Deploying resource file to " + fileName);
+        } catch (FileNotFoundException e) {
+            throw new DeploymentException("Can't write to nonexistant file " + fileName, e);
+        } catch (IOException e) {
+            throw new DeploymentException("Can't write to " + fileName, e);
+        } catch (ParserConfigurationException e) {
+            throw new DeploymentException("Unable to configure parser " + fileName, e);
+        } catch (SAXException e) {
+            throw new DeploymentException("Unable to parse XML " + fileName, e);
+        } catch (TransformerConfigurationException e) {
+            throw new DeploymentException("Unable to configure transformer " + fileName, e);
+        } catch (TransformerException e) {
+            throw new DeploymentException("Unable to transform XML " + fileName, e);
+        }
+    }
+
+    private InputStream readResourceFromClassloader(String fileName) {
+        return XPatchDeployer.class.getClassLoader().getResourceAsStream(
+                "org/apache/cocoon/maven/deployer/monolithic/" + fileName);
+    }
+}

Propchange: cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/XPatchDeployer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/XPatchDeployer.java
------------------------------------------------------------------------------
    svn:keywords = Id



Mime
View raw message