You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by up...@apache.org on 2003/11/17 16:40:34 UTC

cvs commit: cocoon-2.1/src/confpatch mount-table.xmap

upayavira    2003/11/17 07:40:34

  Modified:    .        build.properties
               src/webapp sitemap.xmap
               tools/src/anttasks XConfToolTask.java
  Added:       src/confpatch mount-table.xmap
  Log:
  Fixing the xconf task so that it can resolve properties (with replace-properties attribute set to true in patch file)
  Adding a patch to /src/confpatch to patch the mount-table matcher into the sitemap, using the ${build.mounttable} variable from build.properties.
  
  Revision  Changes    Path
  1.28      +1 -0      cocoon-2.1/build.properties
  
  Index: build.properties
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/build.properties,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- build.properties	5 Sep 2003 06:13:11 -0000	1.27
  +++ build.properties	17 Nov 2003 15:40:33 -0000	1.28
  @@ -57,6 +57,7 @@
   build.deprecated=${build}/deprecated
   build.samples=${build}/samples
   build.temp=${build}/temp
  +build.mounttable=../../mount-table.xml
   
   build.docs.loglevel=ERROR
   build.docs.printer.loglevel=ERROR
  
  
  
  1.41      +1 -9      cocoon-2.1/src/webapp/sitemap.xmap
  
  Index: sitemap.xmap
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/webapp/sitemap.xmap,v
  retrieving revision 1.40
  retrieving revision 1.41
  diff -u -r1.40 -r1.41
  --- sitemap.xmap	13 Nov 2003 18:10:03 -0000	1.40
  +++ sitemap.xmap	17 Nov 2003 15:40:33 -0000	1.41
  @@ -559,14 +559,6 @@
       </map:match>
   
       <!--+
  -        | Find a match in the "mount-table.xml" file, if present. It allows to mount other
  -        | directories without touching this main sitemap (and thus loosing changes on rebuild).
  -        +-->
  -    <map:match type="mount-table" pattern="../../mount-table.xml">
  -      <map:mount src="{src}" uri-prefix="{uri-prefix}"/>
  -    </map:match>
  -
  -    <!--+
           | Mount everything else by calling the sitemap.xmap file located
           | in the requested folder.
           +-->
  
  
  
  1.9       +46 -2     cocoon-2.1/tools/src/anttasks/XConfToolTask.java
  
  Index: XConfToolTask.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/tools/src/anttasks/XConfToolTask.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- XConfToolTask.java	21 Jun 2003 06:53:55 -0000	1.8
  +++ XConfToolTask.java	17 Nov 2003 15:40:33 -0000	1.9
  @@ -58,7 +58,9 @@
   import org.apache.xpath.XPathAPI;
   import org.w3c.dom.Document;
   import org.w3c.dom.DocumentType;
  +import org.w3c.dom.DOMException;
   import org.w3c.dom.Element;
  +import org.w3c.dom.NamedNodeMap;
   import org.w3c.dom.NodeList;
   import org.w3c.dom.Node;
   import org.xml.sax.SAXException;
  @@ -212,6 +214,8 @@
               throw new BuildException("TransformerException: "+e);
           } catch (SAXException e) {
               throw new BuildException("SAXException: "+e);
  +        } catch (DOMException e) {
  +            throw new BuildException("DOMException:" +e);           
           } catch (ParserConfigurationException e) {
               throw new BuildException("ParserConfigurationException: "+e);
           } catch (UnknownHostException e) {
  @@ -233,7 +237,7 @@
       private boolean patch(final Document configuration,
                             final Document component,
                             String file)
  -                          throws TransformerException, IOException {
  +                          throws TransformerException, IOException, DOMException {
           // Check to see if Document is an xconf-tool document
           Element elem = component.getDocumentElement();
   
  @@ -337,6 +341,11 @@
               log("Processing: "+file);
               NodeList componentNodes = component.getDocumentElement().getChildNodes();
   
  +            String replacePropertiesStr = component.getDocumentElement().getAttribute("replace-properties");
  +
  +            boolean replaceProperties = "yes".equalsIgnoreCase(replacePropertiesStr) ||
  +                                        "true".equalsIgnoreCase(replacePropertiesStr);
  +
               if (this.addComments) {
                   root.appendChild(configuration.createComment("..... Start configuration from '"+basename+"' "));
                   root.appendChild(configuration.createTextNode(NL));
  @@ -345,6 +354,9 @@
                   Node node = configuration.importNode(componentNodes.item(i),
                                                        true);
   
  +                if (replaceProperties) {
  +                    replaceProperties(node);
  +                }
                   if (before==null) {
                       root.appendChild(node);
                   } else {
  @@ -356,6 +368,38 @@
                   root.appendChild(configuration.createTextNode(NL));
               }
               return true;
  +        }
  +    }
  +
  +    private void replaceProperties(Node n) throws DOMException {
  +        
  +        NamedNodeMap attrs = n.getAttributes();
  +        if (attrs!=null) {
  +            for (int i = 0; i< attrs.getLength(); i++) {
  +                Node attr = attrs.item(i);
  +                attr.setNodeValue(getProject().replaceProperties(attr.getNodeValue()));     
  +            } 
  +        }
  +        switch (n.getNodeType()) {
  +            case Node.ATTRIBUTE_NODE:
  +            case Node.CDATA_SECTION_NODE:
  +            case Node.TEXT_NODE: {
  +                n.setNodeValue(getProject().replaceProperties(n.getNodeValue()));
  +                break;
  +            }
  +            case Node.DOCUMENT_NODE:
  +            case Node.DOCUMENT_FRAGMENT_NODE:
  +            case Node.ELEMENT_NODE: {
  +                Node child = n.getFirstChild();
  +                while (child != null) {
  +                    replaceProperties(child);
  +                    child = child.getNextSibling();
  +                }
  +                break;
  +            }
  +            default: {
  +                // ignore all other node types
  +            }
           }
       }
   
  
  
  
  1.1                  cocoon-2.1/src/confpatch/mount-table.xmap
  
  Index: mount-table.xmap
  ===================================================================
  <xmap xpath="/sitemap/pipelines/pipeline"
        insert-after="match[contains(@pattern,'api')]" 
        replace-properties="true">
  
      <!--+
          | Find a match in the "mount-table.xml" file, if present. It allows to mount other
          | directories without touching this main sitemap (and thus loosing changes on rebuild).
          +-->
      <map:match type="mount-table" pattern="${build.mounttable}">
        <map:mount src="{src}" uri-prefix="{uri-prefix}"/>
      </map:match>
  </xmap>