View Javadoc

1   /*
2    * $Id: AllBodyIncElementsRule.java,v 1.2 2004/07/01 11:07:59 nw Exp $
3    * 
4    * Created on 28-Nov-2003 by Paul Harrison (pah@jb.man.ac.uk)
5    *
6    * Copyright 2003 AstroGrid. All rights reserved.
7    *
8    * This software is published under the terms of the AstroGrid 
9    * Software License version 1.2, a copy of which has been included 
10   * with this distribution in the LICENSE.txt file.  
11   *
12   */
13  
14  package org.astrogrid.applications.commandline.digester;
15  
16  import org.apache.axis.utils.XMLUtils;
17  import org.apache.commons.digester.BeanPropertySetterRule;
18  import org.w3c.dom.Element;
19  import org.w3c.dom.Node;
20  
21  /***
22      * A rule that incorporates all of the enclosed elements into a property
23      * @author Paul Harrison (pah@jb.man.ac.uk)
24      * @version $Name:  $
25      * @since iteration4
26      */
27  class AllBodyIncElementsRule extends BeanPropertySetterRule {
28     private static StringBuffer contents;
29     private boolean needinner;
30  
31     public AllBodyIncElementsRule(String propName, boolean inner) {
32        super(propName);
33        needinner = inner;
34     }
35  
36     /* (non-Javadoc)
37      * @see org.apache.commons.digester.Rule#end(java.lang.String, java.lang.String)
38      */
39     public void end(String namespace, String name) throws Exception {
40        //set the bodytext to the collected contents as this is what the end usually sets
41        Object o = getDigester().peek();
42        if (o instanceof Node) {
43           String s;
44  
45           if (needinner) {
46              s = XMLUtils.getInnerXMLString((Element)o);
47           }
48           else
49           {
50              s= XMLUtils.ElementToString((Element)o);
51           }
52           getDigester().pop(); // remove Node from the Digester stack.
53           bodyText = s;
54        }
55        
56        super.end(namespace, name);
57  
58     }
59  
60  }