cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject cvs commit: cocoon-2.2/tools/src/anttasks XConfToolTask.java
Date Wed, 17 Mar 2004 20:53:58 GMT
cziegeler    2004/03/17 12:53:58

  Modified:    src/webapp/samples sitemap.xmap
               src/java/org/apache/cocoon/components/cprocessor
                        TreeProcessor.java
               tools/src/anttasks XConfToolTask.java
  Added:       src/webapp/samples/stylesheets sort-samples.xsl
  Log:
  Disabling new internal redirect handling
  Sync XConfTask
  Add sorting stylesheet for block samples
  
  Revision  Changes    Path
  1.1                  cocoon-2.2/src/webapp/samples/stylesheets/sort-samples.xsl
  
  Index: sort-samples.xsl
  ===================================================================
  <?xml version="1.0"?>
  <!--
    Copyright 1999-2004 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.
  -->
  
  <!--+
      | Sort groups in alphabetical order.
      |
      | CVS $Id: sort-samples.xsl,v 1.1 2004/03/17 20:53:58 cziegeler Exp $
      +-->
  
  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  
    <xsl:template match="samples">
      <samples>
        <xsl:apply-templates select="group[@name='Back']"/>
        <xsl:for-each select="group[not(@name='Back')]">
          <xsl:sort select="@name"/>
          <xsl:apply-templates select="."/>
        </xsl:for-each>
      </samples>
    </xsl:template>
    <xsl:template match="@*|node()">
      <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
      </xsl:copy>
    </xsl:template>
  
    <xsl:template match="text()">
      <xsl:value-of select="."/>
    </xsl:template>
  </xsl:stylesheet>
  
  
  
  1.21      +2 -1      cocoon-2.2/src/webapp/samples/sitemap.xmap
  
  Index: sitemap.xmap
  ===================================================================
  RCS file: /home/cvs/cocoon-2.2/src/webapp/samples/sitemap.xmap,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- sitemap.xmap	10 Mar 2004 16:26:19 -0000	1.20
  +++ sitemap.xmap	17 Mar 2004 20:53:58 -0000	1.21
  @@ -95,6 +95,7 @@
   
      <map:match pattern="blocks">
       <map:generate src="block-samples.xml"/>
  +    <map:transform src="stylesheets/sort-samples.xsl"/>
       <map:transform src="context://samples/common/style/xsl/html/simple-samples2html.xsl">
          <map:parameter name="contextPath" value="{request:contextPath}"/>
       </map:transform>
  
  
  
  1.25      +1 -1      cocoon-2.2/src/java/org/apache/cocoon/components/cprocessor/TreeProcessor.java
  
  Index: TreeProcessor.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.2/src/java/org/apache/cocoon/components/cprocessor/TreeProcessor.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- TreeProcessor.java	17 Mar 2004 12:33:34 -0000	1.24
  +++ TreeProcessor.java	17 Mar 2004 20:53:58 -0000	1.25
  @@ -391,7 +391,7 @@
           }
           
           Environment newEnv = new ForwardEnvironmentWrapper(environment, m_manager, uri,
getLogger());
  -        ((ForwardEnvironmentWrapper)newEnv).setExternal(true);
  +        //((ForwardEnvironmentWrapper)newEnv).setExternal(true);
           
           if (facade != null) {
               // Change the facade delegate
  
  
  
  1.12      +94 -34    cocoon-2.2/tools/src/anttasks/XConfToolTask.java
  
  Index: XConfToolTask.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.2/tools/src/anttasks/XConfToolTask.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- XConfToolTask.java	10 Mar 2004 09:08:25 -0000	1.11
  +++ XConfToolTask.java	17 Mar 2004 20:53:58 -0000	1.12
  @@ -41,6 +41,10 @@
   import java.io.File;
   import java.io.IOException;
   import java.net.UnknownHostException;
  +import java.util.ArrayList;
  +import java.util.HashMap;
  +import java.util.Iterator;
  +import java.util.Map;
   
   /**
    * Ant task to patch xmlfiles.
  @@ -68,12 +72,18 @@
   
       private static final String NL=System.getProperty("line.separator");
       private static final String FSEP=System.getProperty("file.separator");
  +    
  +    /** Cache the read configuration files (Documents) */
  +    private static Map fileCache = new HashMap();
  +    
       private File file;
       //private File directory;
       private File srcdir;
       private boolean addComments;
       /** for resolving entities such as dtds */
       private XMLCatalog xmlCatalog = new XMLCatalog();
  +    private DocumentBuilder builder;
  +    private Transformer transformer;
   
       /**
        * Set file, which should be patched.
  @@ -115,7 +125,22 @@
        */
       public void init() throws BuildException {
         super.init();
  -      xmlCatalog.setProject(project);
  +        try {
  +            xmlCatalog.setProject(project);
  +            DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
  +            builderFactory.setValidating(false);
  +            builderFactory.setExpandEntityReferences(false);
  +            builderFactory.setNamespaceAware(false);
  +            builderFactory.setAttribute(
  +               "http://apache.org/xml/features/nonvalidating/load-external-dtd",
  +               Boolean.FALSE);
  +            builder = builderFactory.newDocumentBuilder();
  +            transformer = TransformerFactory.newInstance().newTransformer();
  +        } catch (TransformerException e) {
  +            throw new BuildException("TransformerException: "+e);
  +        } catch (ParserConfigurationException e) {
  +            throw new BuildException("ParserConfigurationException: "+e);
  +        }
       }
   
       /**
  @@ -126,19 +151,17 @@
               throw new BuildException("file attribute is required", location);
           }
           try {
  -            final DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
  -            builderFactory.setValidating(false);
  -            builderFactory.setExpandEntityReferences(false);
  -            builderFactory.setNamespaceAware(false);
  -            builderFactory.setAttribute(
  -                "http://apache.org/xml/features/nonvalidating/load-external-dtd",
  -                Boolean.FALSE);
  -            final DocumentBuilder builder = builderFactory.newDocumentBuilder();
  -            final Transformer transformer = TransformerFactory.newInstance().newTransformer();
  +            final String fileName = this.file.toURL().toExternalForm();
  +            Document document = (Document)this.fileCache.get(fileName);
  +            if ( document != null ) {
  +                log("Using file from cache: " + this.file, Project.MSG_DEBUG);
  +                this.fileCache.remove(fileName);
  +            } else {
   
               // load xml
               log("Reading: " + this.file, Project.MSG_DEBUG);
  -            final Document document = builder.parse(this.file.toURL().toExternalForm());
  +                document = builder.parse(fileName);
  +            }
   
               if (this.srcdir == null) {
                   this.srcdir = project.resolveFile(".");
  @@ -146,22 +169,58 @@
   
               DirectoryScanner scanner = getDirectoryScanner(this.srcdir);
               String[] list = scanner.getIncludedFiles();
  -            boolean hasChanged = false;
  +            boolean modified = false;
               // process recursive
               File patchfile;
  +            ArrayList suspended = new ArrayList();
  +            boolean hasChanged = false;
               for (int i = 0; i < list.length; i++) {
                   patchfile = new File(this.srcdir, list[i]);
                   try {
                       // Adds configuration snippet from the file to the configuration
  -                    hasChanged |= patch(document,
  -                                        builder.parse(patchfile.toURL().toExternalForm()),
  -                                        patchfile.toString());
  +                    boolean changed = patch(document, patchfile);
  +                    hasChanged |= changed;
  +                    if (!changed) {
  +                        suspended.add(patchfile);
  +                    }
                   } catch (SAXException e) {
                       log("Ignoring: "+patchfile+"\n(not a valid XML)");
                   }
               }
  +            modified = hasChanged;
  +
  +            if (hasChanged && !suspended.isEmpty()) {
  +                log("Try to apply suspended patch files", Project.MSG_DEBUG);
  +            }
  +
  +            ArrayList newSuspended = new ArrayList();
  +            while (hasChanged && !suspended.isEmpty()) {
  +                hasChanged = false;
  +                for(Iterator i=suspended.iterator(); i.hasNext();) {
  +                    patchfile = (File)i.next();
  +                    try {
  +                         // Adds configuration snippet from the file to the configuration
  +                        boolean changed = patch(document, patchfile);
  +                        hasChanged |= changed;
  +                        if (!changed) {
  +                            newSuspended.add(patchfile);
  +                        }
  +                    } catch (SAXException e) {
  +                        log("Ignoring: "+patchfile+"\n(not a valid XML)");
  +                    }
  +                }
  +                suspended = newSuspended;
  +                newSuspended = new ArrayList();
  +            }
  +
  +            if (!suspended.isEmpty()) {
  +                for(Iterator i=suspended.iterator(); i.hasNext();) {
  +                    patchfile = (File)i.next();
  +                    log("Dismiss: "+patchfile.toString(), Project.MSG_DEBUG);
  +                }
  +            }
   
  -            if (hasChanged) {
  +            if (modified) {
                   log("Writing: " + this.file);
                   // Set the DOCTYPE output option on the transformer 
                   // if we have any DOCTYPE declaration in the input xml document
  @@ -175,14 +234,13 @@
               } else {
                   log("No Changes: " + this.file, Project.MSG_DEBUG);
               }
  +            this.fileCache.put(fileName, document);
           } catch (TransformerException e) {
               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) {
               throw new BuildException("UnknownHostException.  Probable cause: The parser
is " +
                   "trying to resolve a dtd from the internet and no connection exists.\n"
+
  @@ -203,17 +261,20 @@
        * @return True, if the document was successfully patched
        */
       private boolean patch(final Document configuration,
  -                          final Document component,
  -                          String file)
  -                          throws TransformerException, IOException, DOMException {
  +                          final File file)
  +                          throws TransformerException, IOException, DOMException, SAXException
{
  +
  +        Document component = builder.parse(file.toURL().toExternalForm());
  +        String filename = file.toString();
  +                            
           // Check to see if Document is an xconf-tool document
           Element elem = component.getDocumentElement();
   
  -        String extension = file.lastIndexOf(".")>0?file.substring(file.lastIndexOf(".")+1):"";
  -        String basename = basename(file);
  +        String extension = filename.lastIndexOf(".")>0?filename.substring(filename.lastIndexOf(".")+1):"";
  +        String basename = basename(filename);
   
           if (!elem.getTagName().equals(extension)) {
  -            log("Skipping non xconf-tool file: "+file);
  +            log("Skipping non xconf-tool file: "+filename);
               return false;
           }
   
  @@ -227,11 +288,10 @@
   
           NodeList nodes = XPathAPI.selectNodeList(configuration, xpath);
   
  +        // Suspend, because the xpath returned not one node
           if (nodes.getLength() !=1 ) {
  -            log("Error in: "+file);
  -            throw new IOException("XPath (" + xpath +
  -                                  ") returned not one node, but "+
  -                                  nodes.getLength() + " nodes");
  +            log("Suspending: "+filename, Project.MSG_DEBUG);
  +            return false;
           }
           Node root = nodes.item(0);
   
  @@ -249,11 +309,11 @@
           }
   
           if (ifProp != null && ifProp.length() > 0 && !ifValue ) {
  -            log("Skipping: " + file, Project.MSG_DEBUG);
  +            log("Skipping: " + filename, Project.MSG_DEBUG);
               return false;
           } else if (testPath != null && testPath.length() > 0 &&
               XPathAPI.selectNodeList(root, testPath).getLength() != 0) {
  -            log("Skipping: " + file, Project.MSG_DEBUG);
  +            log("Skipping: " + filename, Project.MSG_DEBUG);
               return false;
           } else {
               // Test if component wants us to remove a list of nodes first
  @@ -292,7 +352,7 @@
               if (xpath != null && xpath.length() > 0) {
                   nodes = XPathAPI.selectNodeList(root, xpath);
                   if (nodes.getLength() == 0) {
  -                    log("Error in: "+file);
  +                    log("Error in: "+filename);
                       throw new IOException("XPath ("+xpath+") returned zero nodes");
                   }
                   before = nodes.item(0);
  @@ -301,7 +361,7 @@
                   if (xpath != null && xpath.length() > 0) {
                       nodes = XPathAPI.selectNodeList(root, xpath);
                       if (nodes.getLength() == 0) {
  -                        log("Error in: "+file);
  +                        log("Error in: "+filename);
                           throw new IOException("XPath ("+xpath+") zero nodes.");
                       }
                       before = nodes.item(nodes.getLength()-1).getNextSibling();
  @@ -309,7 +369,7 @@
               }
   
               // Add 'component' data into 'root' node
  -            log("Processing: "+file);
  +            log("Processing: "+filename);
               NodeList componentNodes = component.getDocumentElement().getChildNodes();
   
               if (this.addComments) {
  
  
  

Mime
View raw message