cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From upayav...@apache.org
Subject cvs commit: cocoon-2.1/src/java/org/apache/cocoon/bean/helpers BeanConfigurator.java
Date Sat, 11 Oct 2003 05:44:07 GMT
upayavira    2003/10/10 22:44:07

  Modified:    src/java/org/apache/cocoon/bean/helpers
                        BeanConfigurator.java
  Log:
  More Ant task preparations (allowing nodes to be attributes - Ant cannot use variable substitution
within nodes, only attributes)
  Fixing <uri>index.html</uri> processing, as some people expect it for legacy
reasons.
  
  Revision  Changes    Path
  1.2       +67 -17    cocoon-2.1/src/java/org/apache/cocoon/bean/helpers/BeanConfigurator.java
  
  Index: BeanConfigurator.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/bean/helpers/BeanConfigurator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BeanConfigurator.java	8 Oct 2003 23:22:01 -0000	1.1
  +++ BeanConfigurator.java	11 Oct 2003 05:44:07 -0000	1.2
  @@ -86,6 +86,14 @@
       private static final String NODE_URI_FILE = "uri-file";
       private static final String NODE_CHECKSUMS_URI = "checksums-uri";
    
  +    // context-dir is needed by ant task
  +    public static final String ATTR_CONTEXT_DIR = "context-dir";
  +    private static final String ATTR_DEST_DIR = "dest-dir";
  +    private static final String ATTR_WORK_DIR = "work-dir";
  +    private static final String ATTR_CONFIG_FILE = "config-file";
  +    private static final String ATTR_URI_FILE = "uri-file";
  +    private static final String ATTR_CHECKSUMS_URI = "checksums-uri";
  + 
       private static final String NODE_BROKEN_LINKS = "broken-links";
       private static final String ATTR_BROKEN_LINK_REPORT_TYPE = "type";
       private static final String ATTR_BROKEN_LINK_REPORT_FILE = "file";
  @@ -117,7 +125,8 @@
       private static final String NODE_URIS = "uris";
       private static final String ATTR_NAME = "name";
       
  -    public static String configure(Document xconf, CocoonBean cocoon, String destDir, String
uriGroup, OutputStreamListener listener) {
  +    public static String configure(Document xconf, CocoonBean cocoon, String destDir, String
uriGroup, OutputStreamListener listener) 
  +        throws IllegalArgumentException {
   
           Node root = xconf.getDocumentElement();
           if (!NODE_ROOT.equals(root.getNodeName())) {
  @@ -136,10 +145,30 @@
           if (hasAttribute(root, ATTR_CONFIRM_EXTENSIONS)) {
               cocoon.setConfirmExtensions(getBooleanAttributeValue(root, ATTR_CONFIRM_EXTENSIONS));
           }
  +        if (hasAttribute(root, ATTR_CONTEXT_DIR)) {
  +            cocoon.setContextDir(getAttributeValue(root, ATTR_CONTEXT_DIR));
  +        }
  +        if (hasAttribute(root, ATTR_DEST_DIR)) {
  +            destDir = getAttributeValue(root, ATTR_CONFIRM_EXTENSIONS);
  +        }
  +        if (hasAttribute(root, ATTR_WORK_DIR)) {
  +            cocoon.setWorkDir(getAttributeValue(root, ATTR_WORK_DIR));
  +        }
  +        if (hasAttribute(root, ATTR_CONFIG_FILE)) {
  +            cocoon.setWorkDir(getAttributeValue(root, ATTR_WORK_DIR));
  +        }
  +        if (hasAttribute(root, ATTR_URI_FILE)) {
  +            cocoon.addTargets(processURIFile(getAttributeValue(root, ATTR_URI_FILE)), destDir);
  +        }
  +        if (hasAttribute(root, ATTR_CHECKSUMS_URI)) {
  +            cocoon.setChecksumURI(getAttributeValue(root, ATTR_CHECKSUMS_URI));
  +        }
  +        
  +
           if (destDir == null || destDir.length() == 0) {
               destDir = getNodeValue(root, NODE_DEST_DIR);
           }
  -
  + 
           NodeList nodes = root.getChildNodes();
           for (int i = 0; i < nodes.getLength(); i++) {
               Node node = nodes.item(i);
  @@ -155,27 +184,43 @@
                       parseLoggingNode(cocoon, node);
   
                   } else if (nodeName.equals(NODE_CONTEXT_DIR)) {
  -                    cocoon.setContextDir(getNodeValue(node));
  +                    if (hasAttribute(root, ATTR_CONTEXT_DIR)) {
  +                        throw new IllegalArgumentException("Cannot have "+NODE_CONTEXT_DIR+"
as both element and attribute");
  +                    } else {
  +                        cocoon.setContextDir(getNodeValue(node));
  +                    }
   
                   } else if (nodeName.equals(NODE_CONFIG_FILE)) {
  -                    cocoon.setConfigFile(getNodeValue(node));
  -
  +                    if (hasAttribute(root, ATTR_CONFIG_FILE)) {
  +                        throw new IllegalArgumentException("Cannot have "+NODE_CONFIG_FILE+"
as both element and attribute");
  +                    } else {
  +                        cocoon.setConfigFile(getNodeValue(node));
  +                    }
                   } else if (nodeName.equals(NODE_DEST_DIR)) {
                       // Ignore
   
                   } else if (nodeName.equals(NODE_WORK_DIR)) {
  -                    cocoon.setWorkDir(getNodeValue(node));
  -
  +                    if (hasAttribute(root, ATTR_WORK_DIR)) {
  +                        throw new IllegalArgumentException("Cannot have "+NODE_WORK_DIR+"
as both element and attribute");
  +                    } else {
  +                        cocoon.setWorkDir(getNodeValue(node));
  +                    }
                   } else if (nodeName.equals(NODE_CHECKSUMS_URI)) {
  -                    cocoon.setChecksumURI(getNodeValue(node));
  -                    
  +                    if (hasAttribute(root, ATTR_CHECKSUMS_URI)) {
  +                        throw new IllegalArgumentException("Cannot have "+NODE_CHECKSUMS_URI+"
as both element and attribute");
  +                    } else {
  +                        cocoon.setChecksumURI(getNodeValue(node));
  +                    }                
                   } else if (nodeName.equals(NODE_AGENT)) {
  +                    //@TODO@ Move this to be attributes too
                       cocoon.setAgentOptions(getNodeValue(node));
   
                   } else if (nodeName.equals(NODE_ACCEPT)) {
  +                    //@TODO@ Move this to be attributes too
                       cocoon.setAcceptOptions(getNodeValue(node));
   
                   } else if (nodeName.equals(NODE_DEFAULT_FILENAME)) {
  +                    //@TODO@ Move this to be attributes too
                       cocoon.setDefaultFilename(getNodeValue(node));
   
                   } else if (nodeName.equals(NODE_INCLUDE)) {
  @@ -196,8 +241,11 @@
                       parseURIsNode(cocoon, node, destDir, uriGroup);
   
                   } else if (nodeName.equals(NODE_URI_FILE)) {
  -                    cocoon.addTargets(processURIFile(getNodeValue(node)), destDir);
  -
  +                    if (hasAttribute(root, ATTR_URI_FILE)) {
  +                        throw new IllegalArgumentException("Cannot have "+NODE_URI_FILE+"
as both element and attribute");
  +                    } else {
  +                        cocoon.addTargets(processURIFile(getNodeValue(node)), destDir);
  +                    }
                   } else {
                       throw new IllegalArgumentException("Unknown element: <" + nodeName
+ ">");
                   }
  @@ -332,13 +380,11 @@
           
       private static void parseURINode(CocoonBean cocoon, Node node, String destDir) throws
IllegalArgumentException {
           NodeList nodes = node.getChildNodes();
  -        if (nodes.getLength() != 0) {
  -            throw new IllegalArgumentException("Unexpected children of <" + NODE_URI
+ "> node");
  -        }
   
  -        if (node.getAttributes().getLength() == 0) {
  +        if (node.getAttributes().getLength() == 0 && nodes.getLength() != 0) {
               cocoon.addTarget(getNodeValue(node), destDir);
  -        } else {
  +        } else if (node.getAttributes().getLength() !=0 && nodes.getLength() ==0){
  +
               String src = getAttributeValue(node, ATTR_URI_SOURCEURI);
   
               String type = null;
  @@ -363,6 +409,10 @@
               } else {
                   cocoon.addTarget(src, destDir);
               }
  +        } else if (node.getAttributes().getLength() !=0 && nodes.getLength() !=
0) {
  +            throw new IllegalArgumentException("Unexpected children of <" + NODE_URI
+ "> node");
  +        } else {
  +            throw new IllegalArgumentException("Not enough information for <"+ NODE_URI
+ "> node");
           }
       }
   
  
  
  

Mime
View raw message